|
1 #!perl |
|
2 # fsh-buildsis |
|
3 # |
|
4 # Copyright (c) 2008-2010 Accenture. All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of the "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Accenture - Initial contribution |
|
12 # |
|
13 # Description: |
|
14 # fsh-buildsis - A tool that generates SIS files. |
|
15 |
|
16 use strict; |
|
17 use Cwd; |
|
18 use Getopt::Long; |
|
19 use File::Basename; |
|
20 use File::Copy; |
|
21 use FindBin; |
|
22 use lib "$FindBin::Bin"; |
|
23 use fshu; |
|
24 |
|
25 |
|
26 # |
|
27 # Constants. |
|
28 # |
|
29 |
|
30 # Have to hard-code the old GCC CPP path, because SBS puts the new version in %PATH%, and that breaks our macros. Need to fix properly or fix the actual macros |
|
31 #my $kCpp = "cpp -P -I../../include -I. -include ltk_makesis_defs.iby"; |
|
32 my $kCpp = "\\epoc32\\gcc\\bin\\cpp -P -I../../include -I. -include fsh_makesis_defs.iby"; |
|
33 |
|
34 # |
|
35 # Globals. |
|
36 # |
|
37 |
|
38 my %options = (); |
|
39 |
|
40 |
|
41 # |
|
42 # Main. |
|
43 # |
|
44 |
|
45 BuildSis(ProcessCommandLine()); |
|
46 |
|
47 # |
|
48 # Subs. |
|
49 # |
|
50 |
|
51 sub ProcessCommandLine { |
|
52 my $help; |
|
53 GetOptions('h|help' => \$help, |
|
54 'k|keep-pkg-file' => \$options{keepPkgFile}, |
|
55 'u|keep-unsigned-sis' => \$options{keepUnsignedSis}, |
|
56 'v|verbose' => \$options{verbose}) or DisplayHelp(); |
|
57 DisplayHelp() if ($help); |
|
58 warn "Invalid arguments\n" and DisplayHelp() unless ((@ARGV == 3) or (@ARGV == 5)); |
|
59 return @ARGV; |
|
60 } |
|
61 |
|
62 sub DisplayHelp { |
|
63 require Pod::Text; |
|
64 print "\n"; |
|
65 my $parser = Pod::Text->new(); |
|
66 $parser->parse_from_file($0); |
|
67 exit; |
|
68 } |
|
69 |
|
70 sub BuildSis { |
|
71 my $platform = shift; |
|
72 my $ibyFileName = shift; |
|
73 my $sisFileName = shift; |
|
74 my $certFileName = shift; |
|
75 my $keyFileName = shift; |
|
76 |
|
77 # |
|
78 # 1) Run the pre-processor over the supplied .iby file and capture the output |
|
79 # to a temporary file. |
|
80 my $tempFileName = "$ENV{TEMP}\\ltkbs_temp.pkg"; |
|
81 if (-e $tempFileName) { |
|
82 unlink $tempFileName; |
|
83 } |
|
84 my $ibyDirName = dirname($ibyFileName); |
|
85 $ibyFileName = basename($ibyFileName); |
|
86 my $cwd = cwd(); |
|
87 chdir ($ibyDirName) or die "Error: Couldn't chdir to \"$ibyDirName\": $!\n"; |
|
88 my $command = "$kCpp -D$platform $ibyFileName 2>&1 >$tempFileName |"; |
|
89 print "Running \"$command\"\n" if ($options{verbose}); |
|
90 open (CPP, $command) or die "Error: Couldn't run \"cpp.exe\": $!\n"; |
|
91 my $error = 0; |
|
92 while (my $line = <CPP>) { |
|
93 print STDERR $line; |
|
94 $error = 1; |
|
95 } |
|
96 close (CPP); |
|
97 chdir ($cwd) or die "Error: Couldn't chdir back to \"$cwd\": $!\n"; |
|
98 if ($error) { |
|
99 die "Aborting due to the above error(s)\n"; |
|
100 } |
|
101 |
|
102 # |
|
103 # 2) Change the \n line endings in the temporary file to \r\n (that makesis.exe expects). |
|
104 # Also, substitute some version information. |
|
105 # |
|
106 my $version = fshu::Version(); |
|
107 $version =~ s/[^\d]//g; |
|
108 if ($version =~ /^\s*$/) { |
|
109 $version = 0; |
|
110 } |
|
111 my $timestamp = int ((time() % (24*60*60)) / 4); # Number of seconds since midnight, munged to fit in the buildnum (max 2^16) |
|
112 copy ($tempFileName, "$tempFileName.bak") or die "Error: Couldn't copy \"$tempFileName\" to \"$tempFileName.bak\": $!\n"; |
|
113 open (ORIG, "$tempFileName.bak") or die "Error: Couldn't open \"$tempFileName.bak\" for reading: $!\n"; |
|
114 open (NEW, ">$tempFileName") or die "Error: Couldn't open \"$tempFileName\" for writing: $!\n"; |
|
115 while (my $line = <ORIG>) { |
|
116 $line =~ s/FSHELL_VERSION/$version/; |
|
117 $line =~ s/FSHELL_TIMESTAMP/$timestamp/; |
|
118 print NEW $line; |
|
119 } |
|
120 close (NEW); |
|
121 close (ORIG); |
|
122 unlink "$tempFileName.bak"; |
|
123 |
|
124 # |
|
125 # 3) Run makesis.exe itself. |
|
126 # |
|
127 my $unsignedSisFileName = $sisFileName; |
|
128 $unsignedSisFileName =~ s/\.sis/\.unsigned\.sis/i; |
|
129 fshu::MakePath(dirname($unsignedSisFileName)); |
|
130 $command = "makesis -d$ENV{EPOCROOT} $tempFileName $unsignedSisFileName 2>&1"; |
|
131 print "Running \"$command\"\n" if ($options{verbose}); |
|
132 my $exitcode = system($command) >> 8; |
|
133 print "\n"; # Makesis doesn't do this |
|
134 print "Exit code from makesis: $exitcode\n" if ($options{verbose}); |
|
135 |
|
136 if ($exitcode) { |
|
137 die "Aborting due to the above error(s) - check $tempFileName\n"; |
|
138 } |
|
139 elsif ($options{keepPkgFile}) { |
|
140 print "Kept \"$tempFileName\"\n"; |
|
141 } |
|
142 else { |
|
143 unlink $tempFileName; |
|
144 } |
|
145 |
|
146 # |
|
147 # 4) Run signsis.exe. |
|
148 # |
|
149 if (defined $certFileName and defined $keyFileName) { |
|
150 $command = "signsis $unsignedSisFileName $sisFileName $certFileName $keyFileName"; |
|
151 print "Running \"$command\"\n" if ($options{verbose}); |
|
152 system ($command); |
|
153 } |
|
154 |
|
155 unless ($options{keepUnsignedSis}) { |
|
156 unlink $unsignedSisFileName; |
|
157 } |
|
158 } |
|
159 |
|
160 __END__ |
|
161 |
|
162 =head1 NAME |
|
163 |
|
164 fsh-buildsis - A tool that generates SIS files. |
|
165 |
|
166 =head1 SYNOPSIS |
|
167 |
|
168 fsh-buildsis <platform> <input_iby_file_name> <output_sis_file_name> [<certificate_file_name> <private_key_file_name>] |
|
169 |
|
170 options: |
|
171 |
|
172 -h (--help) Display this help page. |
|
173 -v (--verbose) Verbose output. |
|
174 -k (--keep-pkg-file) Don't delete the generated .pkg file. |
|
175 -u (--keep-unsigned-sis) Keep a copy the .SIS file before it is signed. |
|
176 Appends ".unsigned" to the base file name. |
|
177 |
|
178 =head1 DESCRIPTION |
|
179 |
|
180 FShell uses pre-processor magic to allow its F<.iby> files to be used by both C<BUILDROM> and C<MAKESIS>. Because C<BUILDROM> runs the pre-processor over any files it reads, this arrangement just works when building ROMs. However, C<MAKESIS> doesn't use the pre-processor. This script is responsible for generating a temporary file that contains suitably pre-processed F<.iby> data. It then runs C<MAKESIS> on this temporary file. |
|
181 |
|
182 The <platform> argument must be one of gcce or armv5. |
|
183 |
|
184 =head1 KNOWN BUGS |
|
185 |
|
186 None known. |
|
187 |
|
188 =head1 COPYRIGHT |
|
189 |
|
190 Copyright (c) 2008-2010 Accenture. All rights reserved. |
|
191 |
|
192 =cut |