1 # |
|
2 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # Environment Patcher - Patches older S60 SDKs for supporting |
|
16 # tricks in newer platforms |
|
17 # |
|
18 |
|
19 |
|
20 require v5.6.1; |
|
21 |
|
22 use File::Copy; |
|
23 use strict; |
|
24 |
|
25 # check amount of commandline options is valid |
|
26 if (@ARGV != 1) |
|
27 { |
|
28 print "Usage: EnvPatcher <EPOCROOT>\n"; |
|
29 exit 1; |
|
30 } |
|
31 |
|
32 |
|
33 # get epocroot and convert, convert \ -> / |
|
34 (my $epocroot = $ARGV[0]) =~ s{\\}{/}g; |
|
35 |
|
36 # remove any trailing forward slashes |
|
37 $epocroot =~ s/\/$//; |
|
38 |
|
39 |
|
40 # create variables for paths |
|
41 my $e32toolsdir = $epocroot."/epoc32/tools"; |
|
42 my $e32includedir = $epocroot."/epoc32/include"; |
|
43 my $e32includeoemdir = $e32includedir."/oem"; |
|
44 my $platformpathspath = $e32includedir."/platform_paths.hrh"; |
|
45 my $domainplatformpathspath = $e32includedir."/domain/osextensions/platform_paths.hrh"; |
|
46 my $mmppmpath = $e32toolsdir."/mmp.pm"; |
|
47 my $pathutlpmpath = $e32toolsdir."/pathutl.pm"; |
|
48 my $prepfilepmpath = $e32toolsdir."/prepfile.pm"; |
|
49 |
|
50 # variables for hacked content |
|
51 my $dependshack = "\t\t\tif (/^DEPENDS\$/o) {\r\n\t\t\t\tnext LINE; # Ignore DEPENDS keyword, not needed by ABLD\r\n\t\t\t}\r\n"; |
|
52 my $forwardslashhack = "\t\t# EnvPatcher forwardslash hack begins\r\n\t\t\$_=~s{/}{\\\\}g; # convert all forward slashes to backslashes\r\n\t\t# EnvPatcher forwardslash hack ends\r\n\r\n"; |
|
53 my $coreibyexportsupport = "\r\n// Following definition is used for exporting tools and stubs IBY files to\r\n// Core image.\r\n#define CORE_IBY_EXPORT_PATH(path,exported) /epoc32/rom/include/##exported\r\n"; |
|
54 |
|
55 |
|
56 # check epoc32\tools exists |
|
57 unless (-d $e32toolsdir) |
|
58 { |
|
59 print "$e32toolsdir not found, please check valid epocroot has been given!\n"; |
|
60 exit 1; |
|
61 } |
|
62 |
|
63 # check epoc32\include exists |
|
64 unless (-d $e32includedir) |
|
65 { |
|
66 print "$e32includedir not found, please check valid epocroot has been given!\n"; |
|
67 exit 1; |
|
68 } |
|
69 |
|
70 |
|
71 # create epoc32\include\oem if it does not exist |
|
72 unless (-d $e32includeoemdir) |
|
73 { |
|
74 mkdir $e32includeoemdir or die; |
|
75 print "Missing directory $e32includeoemdir created succesfully.\n"; |
|
76 } |
|
77 |
|
78 |
|
79 # check if epoc32\include\domain\osextensions\platform_paths.hrh exists |
|
80 if (-e $domainplatformpathspath) |
|
81 { |
|
82 # show an error if the file does not have any platform macros |
|
83 unless (string_exists_in_file($domainplatformpathspath, "OS_LAYER_SYSTEMINCLUDE")) |
|
84 { |
|
85 print "ERROR: $domainplatformpathspath does not have SF macros.\n"; |
|
86 print "Please check your environment, if you have S60 3.2 OEM or newer, please get the latest version!\n"; |
|
87 exit 2; |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 # check if epoc32\include\platform_paths.hrh exists |
|
93 if (-e $platformpathspath) |
|
94 { |
|
95 print "$platformpathspath already exists, not checking it.\n"; |
|
96 } |
|
97 else |
|
98 { |
|
99 # create the file missing file |
|
100 create_default_platform_paths_hrh(); |
|
101 print "Missing file $platformpathspath created succesfully.\n"; |
|
102 } |
|
103 |
|
104 |
|
105 # check if CORE_IBY_EXPORT_PATH macro exist in the platform_paths.hrh |
|
106 unless (string_exists_in_file($platformpathspath, "CORE_IBY_EXPORT_PATH")) |
|
107 { |
|
108 # read content of the platform_paths.hrh |
|
109 my @filecontent = read_file_to_array($platformpathspath); |
|
110 |
|
111 my $match_found = 0; |
|
112 my $i = 0; |
|
113 my $match_found_pos = 0; |
|
114 |
|
115 # find the position where the include guards start (this should be a safe position) |
|
116 foreach (@filecontent) |
|
117 { |
|
118 if ($_ =~ /#define PLATFORM_PATHS_HRH/) |
|
119 { |
|
120 $match_found = 1; |
|
121 $match_found_pos = $i; |
|
122 last; |
|
123 } |
|
124 |
|
125 $i++; |
|
126 } |
|
127 |
|
128 if ($match_found) |
|
129 { |
|
130 # insert the patched content to the file |
|
131 splice(@filecontent, $match_found_pos+1, 0, $coreibyexportsupport); |
|
132 |
|
133 # write the modified array to the file |
|
134 write_file_from_array($platformpathspath, @filecontent); |
|
135 |
|
136 print "Platform_paths.hrh updated to support CORE_IBY_EXPORT_PATH macro.\n"; |
|
137 } |
|
138 else |
|
139 { |
|
140 print "WARNING: $platformpathspath is corrupted or not supported!\n"; |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 # check if epoc32\tools\mmp.pm exists |
|
146 if (-e $mmppmpath) |
|
147 { |
|
148 # check if DEPENDS keyword already exists in the file |
|
149 if (string_exists_in_file($mmppmpath, "DEPENDS")) |
|
150 { |
|
151 print "The SDK has already been patched with DEPENDS keyword hack.\n"; |
|
152 } |
|
153 else |
|
154 { |
|
155 # read content of the mmp.pm file |
|
156 my @filecontent = read_file_to_array($mmppmpath); |
|
157 |
|
158 my $match_found = 0; |
|
159 my $i = 0; |
|
160 my $match_found_pos = 0; |
|
161 |
|
162 # loop through the array to find the correct place |
|
163 foreach (@filecontent) |
|
164 { |
|
165 if ($_ =~ /Unrecognised Resource Keyword/) |
|
166 { |
|
167 $match_found = 1; |
|
168 $match_found_pos = $i; |
|
169 last; |
|
170 } |
|
171 |
|
172 $i++; |
|
173 } |
|
174 |
|
175 if ($match_found) |
|
176 { |
|
177 # insert the patched content to the file |
|
178 splice(@filecontent, $match_found_pos-1, 0, $dependshack); |
|
179 |
|
180 # write the modified array to the file |
|
181 write_file_from_array($mmppmpath, @filecontent); |
|
182 |
|
183 print "Mmp.pm patched with DEPENDS keyword hack.\n"; |
|
184 } |
|
185 else |
|
186 { |
|
187 print "ERROR: Unable to find correct place from $mmppmpath for patching!\n"; |
|
188 print "Your SDK environment probably is not supported by this script!\n"; |
|
189 exit(2); |
|
190 } |
|
191 } |
|
192 } |
|
193 else |
|
194 { |
|
195 print "WARNING: $mmppmpath not found, this environment is not supported!\n"; |
|
196 } |
|
197 |
|
198 |
|
199 # check if epoc32\tools\pathutl.pm exists |
|
200 if (-e $pathutlpmpath) |
|
201 { |
|
202 # check if "sub Path_Norm" already exists in the pathutil.pm file |
|
203 # if it does not exists, then we need to patch prepfile.pm |
|
204 if (string_exists_in_file($pathutlpmpath, "sub Path_Norm")) |
|
205 { |
|
206 print "The SDK is non Symbian OS 9.1, no need to add forward slash hack.\n"; |
|
207 } |
|
208 else |
|
209 { |
|
210 # check if prepfile.pm has already been patched |
|
211 if (string_exists_in_file($prepfilepmpath, "EnvPatcher forwardslash hack")) |
|
212 { |
|
213 print "The SDK has already been patched with forwardslash hack.\n"; |
|
214 } |
|
215 else |
|
216 { |
|
217 # read content of the prepfile.pm file |
|
218 my @filecontent = read_file_to_array($prepfilepmpath); |
|
219 |
|
220 my $match_found = 0; |
|
221 my $i = 0; |
|
222 my $match_found_pos = 0; |
|
223 |
|
224 # loop through the array to find the correct place |
|
225 foreach (@filecontent) |
|
226 { |
|
227 if ($_ =~ /# skip blank lines/) |
|
228 { |
|
229 $match_found = 1; |
|
230 $match_found_pos = $i; |
|
231 last; |
|
232 } |
|
233 |
|
234 $i++; |
|
235 } |
|
236 |
|
237 if ($match_found) |
|
238 { |
|
239 # insert the patched content to the file |
|
240 splice(@filecontent, $match_found_pos+6, 0, $forwardslashhack); |
|
241 |
|
242 # write the modified array to the file |
|
243 write_file_from_array($prepfilepmpath, @filecontent); |
|
244 |
|
245 print "Prepfile.pm patched with forward slash hack.\n"; |
|
246 } |
|
247 else |
|
248 { |
|
249 print "ERROR: Unable to find correct place from $prepfilepmpath for patching!\n"; |
|
250 print "Your SDK environment probably is not supported by this script!\n"; |
|
251 exit(2); |
|
252 } |
|
253 } |
|
254 } |
|
255 } |
|
256 else |
|
257 { |
|
258 print "WARNING: $pathutlpmpath not found, this environment is not supported!\n"; |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 # checks if string exists in the file |
|
264 sub string_exists_in_file |
|
265 { |
|
266 my $filepath = $_[0]; |
|
267 my $findstring = $_[1]; |
|
268 my $match_found = 0; |
|
269 |
|
270 open(FILE, "<", $filepath) or die "Failed to open $filepath for reading!"; |
|
271 |
|
272 # loop through the file for occurances |
|
273 while (<FILE>) |
|
274 { |
|
275 if ($_ =~ /$findstring/) |
|
276 { |
|
277 $match_found = 1; |
|
278 last; |
|
279 } |
|
280 } |
|
281 |
|
282 close FILE; |
|
283 |
|
284 return $match_found; |
|
285 } |
|
286 |
|
287 |
|
288 # reads lines from a file to an array |
|
289 sub read_file_to_array |
|
290 { |
|
291 my $filepath = $_[0]; |
|
292 |
|
293 open(FILE, "<", $filepath) or die "Failed to open $filepath for reading!"; |
|
294 my @data = <FILE>; |
|
295 close FILE; |
|
296 |
|
297 return(@data); |
|
298 } |
|
299 |
|
300 |
|
301 # writes lines from an array to a file |
|
302 sub write_file_from_array |
|
303 { |
|
304 my ($filepath, @data) = @_; |
|
305 |
|
306 # take a backup of the file |
|
307 copy ($filepath, $filepath."EnvPatcher") or die "Cannot take backup of $filepath to $filepath.EnvPatcher"; |
|
308 |
|
309 open(FILE, ">", $filepath) or die "Failed to open $filepath for writing!"; |
|
310 |
|
311 # write the array to file |
|
312 foreach my $line (@data) |
|
313 { |
|
314 print FILE "$line"; |
|
315 } |
|
316 |
|
317 close FILE; |
|
318 } |
|
319 |
|
320 sub create_default_platform_paths_hrh |
|
321 { |
|
322 # the file does not exist, so create the missing file |
|
323 open(FILE, ">", $platformpathspath) or die "Failed to open $platformpathspath for writing!\n"; |
|
324 |
|
325 print FILE <<ENDOFTHEFILE; |
|
326 #ifndef PLATFORM_PATHS_HRH |
|
327 #define PLATFORM_PATHS_HRH |
|
328 |
|
329 /** |
|
330 * --------------------------------------- |
|
331 * Location, where the applications layer specific public headers should be exported |
|
332 * See usage on top of this hrh-file. |
|
333 * --------------------------------------- |
|
334 */ |
|
335 #define APP_LAYER_SDK_EXPORT_PATH(exported) /epoc32/include/##exported |
|
336 #define APP_LAYER_PUBLIC_EXPORT_PATH(exported) /epoc32/include/##exported |
|
337 |
|
338 /** |
|
339 * --------------------------------------- |
|
340 * Location, where the applications layer specific platform headers should be exported |
|
341 * See usage on top of this hrh-file. |
|
342 * --------------------------------------- |
|
343 */ |
|
344 #define APP_LAYER_DOMAIN_EXPORT_PATH(exported) /epoc32/include/##exported |
|
345 #define APP_LAYER_PLATFORM_EXPORT_PATH(exported) /epoc32/include/##exported |
|
346 |
|
347 /** |
|
348 * --------------------------------------- |
|
349 * Location, where the middleware layer specific public headers should be exported |
|
350 * See usage on top of this hrh-file. |
|
351 * --------------------------------------- |
|
352 */ |
|
353 #define MW_LAYER_SDK_EXPORT_PATH(exported) /epoc32/include/##exported |
|
354 #define MW_LAYER_PUBLIC_EXPORT_PATH(exported) /epoc32/include/##exported |
|
355 |
|
356 /** |
|
357 * --------------------------------------- |
|
358 * Location, where the middleware layer specific platform headers should be exported |
|
359 * --------------------------------------- |
|
360 */ |
|
361 #define MW_LAYER_DOMAIN_EXPORT_PATH(exported) /epoc32/include/##exported |
|
362 #define MW_LAYER_PLATFORM_EXPORT_PATH(exported) /epoc32/include/##exported |
|
363 |
|
364 /** |
|
365 * --------------------------------------- |
|
366 * Location, where the os layer specific public headers should be exported |
|
367 * --------------------------------------- |
|
368 */ |
|
369 #define OSEXT_LAYER_SDK_EXPORT_PATH(exported) /epoc32/include/##exported |
|
370 #define OS_LAYER_PUBLIC_EXPORT_PATH(exported) /epoc32/include/##exported |
|
371 |
|
372 /** |
|
373 * --------------------------------------- |
|
374 * Location, where the os specific platform headers should be exported |
|
375 * --------------------------------------- |
|
376 */ |
|
377 #define OSEXT_LAYER_DOMAIN_EXPORT_PATH(exported) /epoc32/include/##exported |
|
378 #define OS_LAYER_PLATFORM_EXPORT_PATH(exported) /epoc32/include/##exported |
|
379 |
|
380 /** |
|
381 * --------------------------------------- |
|
382 * Location, where the cenrep excel sheets should be exported |
|
383 * Deprecated: should no longer be used. Kept for compability. |
|
384 * --------------------------------------- |
|
385 */ |
|
386 #define CENREP_XLS_EXPORT_PATH(exported) /epoc32/tools/cenrep/data/src/##exported |
|
387 |
|
388 /** |
|
389 * This define statements defines the SYSTEMINCLUDE-line, which is intended to be |
|
390 * used in the mmp-files that are part of the applications-layer. It includes all |
|
391 * the needed directories from the /epoc32/include, that are valid ones for the |
|
392 * application-layer components. |
|
393 * |
|
394 * Applications layer is the last one in the list, since most likely the most of |
|
395 * the headers come from middleware or os-layer => thus they are first. |
|
396 */ |
|
397 #define APP_LAYER_SYSTEMINCLUDE SYSTEMINCLUDE /epoc32/include /epoc32/include/oem |
|
398 |
|
399 /** |
|
400 * This define statements defines the SYSTEMINCLUDE-line, which is intended to be |
|
401 * used in the mmp-files that are part of the middleware-layer. It includes all |
|
402 * the needed directories from the /epoc32/include, that are valid ones for the |
|
403 * middleware-layer components. |
|
404 */ |
|
405 #define MW_LAYER_SYSTEMINCLUDE SYSTEMINCLUDE /epoc32/include /epoc32/include/oem |
|
406 |
|
407 /** |
|
408 * This define statements defines the SYSTEMINCLUDE-line, which is intended to be |
|
409 * used in the mmp-files that are part of the osextensions-layer. It includes all |
|
410 * the needed directories from the /epoc32/include, that are valid ones for the |
|
411 * os-layer components. |
|
412 */ |
|
413 #define OS_LAYER_SYSTEMINCLUDE SYSTEMINCLUDE /epoc32/include /epoc32/include/oem |
|
414 |
|
415 |
|
416 // Below statement is Deprecated and the OS_LAYER_SYSTEMINCLUDE-macro has to be |
|
417 // used. |
|
418 #define OSEXT_LAYER_SYSTEMINCLUDE OS_LAYER_SYSTEMINCLUDE |
|
419 |
|
420 /** |
|
421 * This define statements defines the SYSTEMINCLUDE-line, which is intended to be |
|
422 * used in the mmp-files that are part of the os-layer. This is intended |
|
423 * to be only used by those components which need to use in their mmp-file either |
|
424 * kern_ext.mmh or nkern_ext.mmh. Reason is that those |
|
425 * 2 files already contain the /epoc32/include as system include path. |
|
426 * |
|
427 */ |
|
428 #define OS_LAYER_KERNEL_SYSTEMINCLUDE SYSTEMINCLUDE /epoc32/include/oem |
|
429 |
|
430 |
|
431 // Below statement is Deprecated and the OS_LAYER_KERNEL_SYSTEMINCLUDE-macro |
|
432 // has to be used. |
|
433 #define OSEXT_LAYER_KERNEL_SYSTEMINCLUDE OS_LAYER_KERNEL_SYSTEMINCLUDE |
|
434 |
|
435 /** |
|
436 **************************************************************************** |
|
437 * Definitions that also define the paths to the layer specific source directories. |
|
438 **************************************************************************** |
|
439 */ |
|
440 /** |
|
441 * The below 3 macros define the paths to the layer-specific source dirs. |
|
442 * See usage on top of this hrh-file, these are used the same way as |
|
443 * for instance the OS_LAYER_DOMAIN_EXPORT_PATH |
|
444 * Deprecated: is not allowed to be using in Symbian Foundation |
|
445 */ |
|
446 #define APP_LAYER_SOURCE_PATH(rest) /s60/app/##rest |
|
447 #define MW_LAYER_SOURCE_PATH(rest) /s60/mw/##rest |
|
448 #define OSEXT_LAYER_SOURCE_PATH(rest) /s60/osext/##rest |
|
449 |
|
450 /** |
|
451 **************************************************************************** |
|
452 * Definitions to export IBY files to different folders where they will be taken |
|
453 * to ROM image |
|
454 **************************************************************************** |
|
455 */ |
|
456 // Following definition is used for exporting tools and stubs IBY files to |
|
457 // Core image. |
|
458 #define CORE_IBY_EXPORT_PATH(path,exported) /epoc32/rom/include/##exported |
|
459 |
|
460 /** |
|
461 * --------------------------------------- |
|
462 * Macros for Configuration tool migration. |
|
463 * The below macros define the location under epoc32, where the confml |
|
464 * (Configuration Markup Language) and crml (Central Repository Markup Language) |
|
465 * files should be exported. |
|
466 * --------------------------------------- |
|
467 */ |
|
468 #define CONFML_EXPORT_PATH(file,category) /epoc32/rom/config/confml_data/##category##/##file |
|
469 #define CRML_EXPORT_PATH(file,category) /epoc32/rom/config/confml_data/##category##/##file |
|
470 #define GCFML_EXPORT_PATH(file,category) /epoc32/rom/config/confml_data/##category##/##file |
|
471 #define CONFML_CONFIG_EXPORT_PATH(file,category) /epoc32/rom/config/confml_data/##category##/config/##file |
|
472 |
|
473 #define APP_LAYER_CONFML(exported) CONFML_EXPORT_PATH(exported,s60) |
|
474 #define APP_LAYER_CRML(exported) CRML_EXPORT_PATH(exported,s60) |
|
475 #define APP_LAYER_GCFML(exported) GCFML_EXPORT_PATH(exported,s60) |
|
476 #define APP_LAYER_CONFML_CONFIG(exported) CONFML_CONFIG_EXPORT_PATH(exported,s60) |
|
477 |
|
478 #define MW_LAYER_CONFML(exported) CONFML_EXPORT_PATH(exported,s60) |
|
479 #define MW_LAYER_CRML(exported) CRML_EXPORT_PATH(exported,s60) |
|
480 #define MW_LAYER_GCFML(exported) GCFML_EXPORT_PATH(exported,s60) |
|
481 #define MW_LAYER_CONFML_CONFIG(exported) CONFML_CONFIG_EXPORT_PATH(exported,s60) |
|
482 |
|
483 // Deprecate: Use the OS_LAYER_* macros instead of OSEXT_LAYER_* |
|
484 #define OSEXT_LAYER_CONFML(exported) CONFML_EXPORT_PATH(exported,s60) |
|
485 #define OSEXT_LAYER_CRML(exported) CRML_EXPORT_PATH(exported,s60) |
|
486 #define OSEXT_LAYER_GCFML(exported) GCFML_EXPORT_PATH(exported,s60) |
|
487 #define OSEXT_LAYER_CONFML_CONFIG(exported) CONFML_CONFIG_EXPORT_PATH(exported,s60) |
|
488 #define OS_LAYER_CONFML(exported) CONFML_EXPORT_PATH(exported,s60) |
|
489 #define OS_LAYER_CRML(exported) CRML_EXPORT_PATH(exported,s60) |
|
490 #define OS_LAYER_GCFML(exported) GCFML_EXPORT_PATH(exported,s60) |
|
491 #define OS_LAYER_CONFML_CONFIG(exported) CONFML_CONFIG_EXPORT_PATH(exported,s60) |
|
492 |
|
493 #endif // end of PLATFORM_PATHS_HRH |
|
494 |
|
495 ENDOFTHEFILE |
|
496 |
|
497 close FILE; |
|
498 } |
|