|
1 # Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Wrapper to support the EPOC extended makefile Compiler |
|
15 # |
|
16 # |
|
17 |
|
18 use Cwd; # for cwd |
|
19 use FindBin; # for FindBin::Bin |
|
20 use File::Copy; # for copy() |
|
21 |
|
22 my $uppath="x"; # will be initialised when first needed |
|
23 my $PerlBinPath; # fully qualified pathname of the directory containing this script |
|
24 |
|
25 my $epocroot = $ENV{EPOCROOT}; |
|
26 die "ERROR: Must set the EPOCROOT environment variable\n" if (!defined($epocroot)); |
|
27 $epocroot =~ s-/-\\-go; # for those working with UNIX shells |
|
28 die "ERROR: EPOCROOT must not include a drive letter\n" if ($epocroot =~ /^.:/); |
|
29 die "ERROR: EPOCROOT must be an absolute path without a drive letter\n" if ($epocroot !~ /^\\/); |
|
30 die "ERROR: EPOCROOT must not be a UNC path\n" if ($epocroot =~ /^\\\\/); |
|
31 die "ERROR: EPOCROOT must end with a backslash\n" if ($epocroot !~ /\\$/); |
|
32 die "ERROR: EPOCROOT must specify an existing directory\n" if (!-d $epocroot); |
|
33 |
|
34 $epocroot=~ s-\\$--; # chop trailing \\ |
|
35 |
|
36 # establish the path to the Perl binaries |
|
37 BEGIN { |
|
38 require 5.005_03; # check user has a version of perl that will cope |
|
39 $PerlBinPath = $FindBin::Bin; # X:/epoc32/tools |
|
40 $PerlBinPath =~ s/\//\\/g; # X:\epoc32\tools |
|
41 } |
|
42 use lib $PerlBinPath; |
|
43 use lockit_info; |
|
44 |
|
45 sub print_usage |
|
46 { |
|
47 #........1.........2.........3.........4.........5.........6.........7..... |
|
48 print <<USAGE_EOF; |
|
49 |
|
50 Usage: |
|
51 epoccnf [options] sourcefile -c outputfile |
|
52 |
|
53 Compile a CNF resource file. |
|
54 |
|
55 The available options are |
|
56 |
|
57 -t[Temporary directory] -- temporary directory |
|
58 -l[Target directory:Working directory] -- if specified, captures all source to \\epoc32\\localisation\\... |
|
59 -v -- verbose |
|
60 |
|
61 The resource file is first passed through the C++ preprocessor, using any |
|
62 specified preprocessor arguments, and then compiled with RCOMP.EXE to |
|
63 generate a compiled resource, it is then compiled with CNFTOOL.EXE to produce |
|
64 a .cnf file. |
|
65 |
|
66 All intermediate files are generated into a temporary directory. |
|
67 |
|
68 USAGE_EOF |
|
69 } |
|
70 |
|
71 #------------------------------------------------------- |
|
72 # Process commandline arguments |
|
73 # |
|
74 # Can't use the Getopt package because it doesn't like the -D and -I style options |
|
75 # |
|
76 my $sourcefile=""; |
|
77 my $opt_l=""; |
|
78 my $tmpdir=""; |
|
79 my $opt_v=0; |
|
80 my $outputfile=""; |
|
81 |
|
82 my $cpp_spec= "cpp -undef -C "; # preserve comments |
|
83 |
|
84 my $errors = 0; |
|
85 while (@ARGV) |
|
86 { |
|
87 my $arg = shift @ARGV; |
|
88 if ($arg =~ /^-v$/) |
|
89 { |
|
90 $opt_v =1; |
|
91 next; |
|
92 } |
|
93 if ($arg =~ /^-t(.*)\\?$/) |
|
94 { |
|
95 $tmpdir ="$1\\"; |
|
96 next; |
|
97 } |
|
98 if ($arg =~ /^-l(.*)$/) |
|
99 { |
|
100 $opt_l =$1; |
|
101 next; |
|
102 } |
|
103 if ($arg =~ /^-c(.*)$/) |
|
104 { |
|
105 $outputfile =$1; |
|
106 next; |
|
107 } |
|
108 if ($arg =~ /^-/) |
|
109 { |
|
110 print "Unknown arg: $arg\n"; |
|
111 $errors++; |
|
112 next; |
|
113 } |
|
114 $sourcefile=$arg; |
|
115 } |
|
116 |
|
117 if ($errors || $sourcefile eq "") |
|
118 { |
|
119 print_usage(); |
|
120 exit 1; |
|
121 } |
|
122 |
|
123 use File::Basename; |
|
124 my $rss_base = basename($sourcefile); |
|
125 my ($rssfile) = split(/\./, $rss_base); # remove extension |
|
126 my $rpp_name = $tmpdir . $rssfile . ".rpp"; |
|
127 |
|
128 if ($opt_v) |
|
129 { |
|
130 print "* Source file\t\t: $sourcefile\n"; |
|
131 print "* Temp. .RPP file\t: $rpp_name\n"; |
|
132 print "* .CNF location\t\t: $outputfile\n"; |
|
133 print "* localisation dets.\t: $opt_l\n"; |
|
134 print "* Temp. directory\t: $tmpdir\n"; |
|
135 } |
|
136 |
|
137 #------------------------------------------------------- |
|
138 # Run the preprocessor |
|
139 # |
|
140 ## Creates the .rpp file |
|
141 |
|
142 $cpp_spec .= "-I $PerlBinPath\\..\\include "; # path to support shared tools |
|
143 $cpp_spec .= "-D_UNICODE "; |
|
144 $cpp_spec .= "<\"$sourcefile\""; |
|
145 |
|
146 open RPP, ">$rpp_name" or die "* Can't write to $rpp_name"; |
|
147 open CPP, "$cpp_spec |" or die "* Can't execute cpp"; |
|
148 my $line; |
|
149 |
|
150 while ($line=<CPP>) |
|
151 { |
|
152 print RPP $line; |
|
153 } |
|
154 close RPP; |
|
155 close CPP; |
|
156 |
|
157 my $cpp_status = $?; |
|
158 die "* cpp failed\n" if ($cpp_status != 0); |
|
159 |
|
160 #------------------------------------------------------- |
|
161 # Copy .rpp and .rss file to epoc32\localisation |
|
162 # |
|
163 |
|
164 if ($opt_l ne "") |
|
165 { |
|
166 &Lockit_SrcFile($rssfile, $rpp_name, $opt_l, "CNF", ""); |
|
167 } |
|
168 |
|
169 #------------------------------------------------------- |
|
170 # Run first pass of the resource compiler to get the UID out of the first 4 bytes of the resource |
|
171 # |
|
172 |
|
173 my $rcomp_spec = "rcomp "; |
|
174 $rcomp_spec .= "-:$tmpdir\\_dump_of_resource_ "; # causes Rcomp to dump each resource (uncompressed and unpadded) in $tmpdir\\_dump_of_resource_1, $tmpdir\\_dump_of_resource_2, etc |
|
175 $rcomp_spec .= "-u -o$tmpdir\\_output_from_first_pass -s\"$rpp_name\" -i\"$sourcefile\""; |
|
176 |
|
177 if ($opt_v) |
|
178 { |
|
179 print "\n* extracting UID from rsc file\n" if ($opt_v); |
|
180 print "*** $rcomp_spec\n" if ($opt_v); |
|
181 } |
|
182 system($rcomp_spec); |
|
183 if ($? != 0) |
|
184 { |
|
185 print "* RCOMP failed - deleting output files\n"; |
|
186 unlink $rpp_name; |
|
187 unlink("$tmpdir\\_dump_of_resource_*"); |
|
188 exit 1; |
|
189 } |
|
190 print "* deleting $tmpdir\\_output_from_first_pass\n" if ($opt_v); |
|
191 unlink "$tmpdir\\_output_from_first_pass"; |
|
192 |
|
193 |
|
194 #------------------------------------------------------- |
|
195 # Get the from UID from the first four bytes of "$tmpdir\\_dump_of_resource_1" |
|
196 # |
|
197 |
|
198 open(DUMP_OF_RESOURCE_1, "< $tmpdir\\_dump_of_resource_1") or die("* Can't open dump file\n"); |
|
199 binmode(DUMP_OF_RESOURCE_1); |
|
200 my $data; |
|
201 my $numberOfBytesRead=read(DUMP_OF_RESOURCE_1, $data, 4); |
|
202 defined($numberOfBytesRead) or die("* Can't read from dump file\n"); |
|
203 ($numberOfBytesRead>=4) or die("* Dump file too short\n"); |
|
204 my $uid=(unpack('V', $data))[0]; |
|
205 undef($data); |
|
206 undef($numberOfBytesRead); |
|
207 close(DUMP_OF_RESOURCE_1) or die("* Can't close dump file\n"); |
|
208 unlink("$tmpdir\\_dump_of_resource_*"); |
|
209 |
|
210 |
|
211 #------------------------------------------------------- |
|
212 # Run second pass of the resource compiler to get the UID out of the first 4 bytes of the resource |
|
213 # |
|
214 |
|
215 $rcomp_spec = "rcomp "; |
|
216 $rcomp_spec .= "-{0x10000c62,".sprintf('0x%08x', $uid)."} "; # passes Rcomp the correct 2nd and 3rd UIDs |
|
217 $rcomp_spec .= "-u -o\"$outputfile\" -s\"$rpp_name\" -i\"$sourcefile\""; |
|
218 |
|
219 if ($opt_v) |
|
220 { |
|
221 print "\n* generating rsc file\n" if ($opt_v); |
|
222 print "*** $rcomp_spec\n" if ($opt_v); |
|
223 } |
|
224 system($rcomp_spec); |
|
225 if ($? != 0) |
|
226 { |
|
227 print "* RCOMP failed - deleting output files\n"; |
|
228 unlink $rpp_name; |
|
229 exit 1; |
|
230 } |
|
231 print "* deleting $rpp_name\n" if ($opt_v); |
|
232 unlink $rpp_name; |
|
233 exit 0; |
|
234 |
|
235 |
|
236 #------------------------------------------------------- |
|
237 # Subroutine: convert possibly absolute path into relative path |
|
238 # |
|
239 |
|
240 sub quoted_relative_path |
|
241 { |
|
242 my ($arg) = @_; |
|
243 return "\"$arg\"" if ($arg !~ /^\\/); # not an absolute path |
|
244 if ($uppath eq "x") |
|
245 { |
|
246 $uppath=cwd; |
|
247 $uppath=~s-/-\\-go; # separator from Perl 5.005_02+ is forward slash |
|
248 $uppath=~s-^(.*[^\\])$-$1\\-o; # ensure path ends with a backslash |
|
249 $uppath=~s-\\([^\\]+)-\\..-og; # convert directories into .. |
|
250 $uppath=~s-^.:\\--o; # remove drive letter and leading backslash |
|
251 } |
|
252 $arg=~s-^\\--o; # remove leading backslash from original path |
|
253 return "\"$uppath$arg\""; |
|
254 } |