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