imgtools/buildrom/tools/buildrom.pm
changeset 629 541af5ee3ed9
parent 626 ac03b93ca9c4
child 633 a4eca1f021ac
equal deleted inserted replaced
628:7c4a911dc066 629:541af5ee3ed9
     1 #
     1 #
     2 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 # Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 # All rights reserved.
     3 # All rights reserved.
     4 # This component and the accompanying materials are made available
     4 # This component and the accompanying materials are made available
     5 # under the terms of the License "Eclipse Public License v1.0"
     5 # under the terms of the License "Eclipse Public License v1.0"
     6 # which accompanies this distribution, and is available
     6 # which accompanies this distribution, and is available
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
    54 	getObyCommand
    54 	getObyCommand
    55 	process_dlldata
    55 	process_dlldata
    56 	featurefile_creation_phase
    56 	featurefile_creation_phase
    57 	processData
    57 	processData
    58 	create_smrimage
    58 	create_smrimage
       
    59 	getWorkdir
    59 );
    60 );
    60 
    61 
       
    62 my $useinterpretsis = 1;
       
    63 if ($^O !~ /^MSWin32$/i){
       
    64 	$useinterpretsis = 0;
       
    65 }
    61 my $enforceFeatureManager = 0; # Flag to make Feature Manager mandatory if SYMBIAN_FEATURE_MANAGER macro is defined. 
    66 my $enforceFeatureManager = 0; # Flag to make Feature Manager mandatory if SYMBIAN_FEATURE_MANAGER macro is defined. 
    62 
    67 
    63 my $BuildromMajorVersion = 3 ;
    68 my $BuildromMajorVersion = 3 ;
    64 my $BuildromMinorVersion = 17;
    69 my $BuildromMinorVersion = 27;
    65 my $BuildromPatchVersion = 0;
    70 my $BuildromPatchVersion = 2;
       
    71 
    66 
    72 
    67 sub print_usage
    73 sub print_usage
    68 {
    74 {
    69 
    75 
    70 	# Option "-fm" will be supported instead of option "-f|fr" if SYMBIAN_FEATURE_MANAGER macro is defined.
    76 	# Option "-fm" will be supported instead of option "-f|fr" if SYMBIAN_FEATURE_MANAGER macro is defined.
    92 and subsequently adjusted by statements in the ROM specification language.
    98 and subsequently adjusted by statements in the ROM specification language.
    93 The final specification is in the subset of the specification language
    99 The final specification is in the subset of the specification language
    94 which is understood directly by ROMBUILD.
   100 which is understood directly by ROMBUILD.
    95 
   101 
    96 Each obyfile parameter specifies a file via a search path: if the
   102 Each obyfile parameter specifies a file via a search path: if the
    97 filename is not matched then buildrom will look in \\epoc32\\rom\\include.
   103 filename is not matched then buildrom will look in \/epoc32\/rom\/include.
    98 
   104 
    99 Buildrom invokes ROMBUILD to generate the ROM image, and produces a
   105 Buildrom invokes ROMBUILD to generate the ROM image, and produces a
   100 number of related files such as the ROM symbol file. The name of the
   106 number of related files such as the ROM symbol file. The name of the
   101 image file is specified directly by the -o option, or determined by 
   107 image file is specified directly by the -o option, or determined by 
   102 scanning the final specification for the "romname" keyword. If there is 
   108 scanning the final specification for the "romname" keyword. If there is 
   120    -ccomprmethod                    -- compression method: none|inflate|bytepair
   126    -ccomprmethod                    -- compression method: none|inflate|bytepair
   121    -geninc                          -- generate INC file
   127    -geninc                          -- generate INC file
   122    -gendep                          -- generate dependence graph for rom image
   128    -gendep                          -- generate dependence graph for rom image
   123    -nosymbols                       -- disable creation of symbol file
   129    -nosymbols                       -- disable creation of symbol file
   124    -noimage                         -- disable creation of ROM/ROFS/DataDrive Image
   130    -noimage                         -- disable creation of ROM/ROFS/DataDrive Image
   125    -fastcompress                    -- compress files with faster bytepair and tradeoff of compress ratio
       
   126    -j<digit>                        -- do the main job with <digit> threads
   131    -j<digit>                        -- do the main job with <digit> threads
       
   132    -cache                           -- allow the ROFSBUILD to reuse/generate cached executable files
       
   133    -nocache                         -- force the ROFSBUILD not to reuse/generate cached executable files
       
   134    -cleancache                      -- permanently remove all cached executable files
       
   135    -oby-charset=<charset>	        -- used character set in which OBY was written
   127    -loglevel<level>                 -- Level of information logging where loglevel is 0,1,2
   136    -loglevel<level>                 -- Level of information logging where loglevel is 0,1,2
   128                                        0 default level of information
   137                                        0 default level of information
   129                                        1 host/ROM filenames, file size and the hidden attribute along with level0 log
   138                                        1 host/ROM filenames, file size and the hidden attribute along with level0 log
   130                                        2 E32 file header attributes along with level1 log
   139                                        2 E32 file header attributes along with level1 log
   131    -z=xxx or -zdrivepath=xxx        -- specify a location to create Z drive directory. 
   140    -z=xxx or -zdrivepath=xxx        -- specify a location to create Z drive directory. 
   132    -d=xxx or -datadrivepath=xxx     -- specify a location to create data drive directory.
   141    -d=xxx or -datadrivepath=xxx     -- specify a location to create data drive directory.
   133    -k or -keepgoing                 -- enable keepgoing,continue to create the data drive image even
   142    -k or -keepgoing                 -- enable keepgoing,continue to create the data drive image even
   134                                     if the non-sis, sis or zdrive image file(s) are missing or corrupt.
   143                                     if the non-sis, sis or zdrive image file(s) are missing or corrupt; create rom/rofs
       
   144 									image even some oby files missing and/or duplicated definitions in oby files .
   135    -r or -retainfolder              -- enable retainfolder,would retain pre-existence of z & data drive folder. 
   145    -r or -retainfolder              -- enable retainfolder,would retain pre-existence of z & data drive folder. 
   136    -zdriveimage=xxx                 -- specify Z drive image (ROM, CORE, ROFS or Ext-ROFS image).
   146    -zdriveimage=xxx                 -- specify Z drive image (ROM, CORE, ROFS or Ext-ROFS image).
   137    -pfile=xxx                       -- specify a parameter file for interpretsis to take additional parameters.
   147    -pfile=xxx                       -- specify a parameter file for interpretsis to take additional parameters.
   138    -argforinterpretsis=xxx          -- specify command line argument(s) for interpretsis which will override the 
   148    -argforinterpretsis=xxx          -- specify command line argument(s) for interpretsis which will override the 
   139                                     parameter file contents.
   149                                     parameter file contents.
   140    -l=xxx or -logimagecontents=xxx  -- extract all stub-sis and SWI certificate store file(s) only 
   150    -l=xxx or -logimagecontents=xxx  -- extract all stub-sis and SWI certificate store file(s) only 
   141                                     and log all the file(s) that are part of the Z drive image on to a log file.  
   151                                     and log all the file(s) that are part of the Z drive image on to a log file.  
   142    -I<directory>                    -- Use <directory> for the referenced IBY/OBY files
   152    -I<directory>                    -- Use <directory> for the referenced IBY/OBY files
   143    -argfile=xxx                     -- specify argument-file name containing list of command-line arguments to buildrom   
   153    -argfile=xxx                     -- specify argument-file name containing list of command-line arguments to buildrom   
   144    -lowmem                          -- use memory-mapped file for image build to reduce physical memory consumption   
   154    -lowmem                          -- use memory-mapped file for image build to reduce physical memory consumption   
   145 
   155    -checkcase                       -- check character case of path/name in oby/iby files, 
       
   156                                     the result will be checkcase.log, this option is only valid on windows.
       
   157    -workdir=xxx                     -- specify a directory to contain generated files. 
       
   158    -prependepocroot                 -- if there is no EPOCROOT## before /epoc32/, prepend EPOCROOT## to epoc32.
       
   159    -stdcpp                          -- ignore symbian customized cpp and try to find another cpp in the PATH.(for Windows only)
       
   160    -cpp=xxx                         -- specify a CPP preprocessor used by Buildrom.
       
   161    
   146 Popular -D defines to use include
   162 Popular -D defines to use include
   147 
   163 
   148    -D_DEBUG         -- select debug versions of some files
   164    -D_DEBUG         -- select debug versions of some files
   149    -D_FULL_DEBUG    -- select debug versions of all files
   165    -D_FULL_DEBUG    -- select debug versions of all files
   150    -D_ARM4          -- specify the target platform
   166    -D_ARM4          -- specify the target platform
   151 
   167 
   152    -D_EABI=xxxx     -- specify target for all files (e.g. ARMV5)
   168    -D_EABI=xxxx     -- specify target for all files (e.g. armv5)
   153    -D_KABI=xxxx     -- specify the target platform for the Kernel (e.g. ARMV5)
   169    -D_KABI=xxxx     -- specify the target platform for the Kernel (e.g. armv5)
   154 
   170 
   155 Other defines may be useful for particular OBY files.
   171 Other defines may be useful for particular OBY files.
   156 
   172 
   157 USAGE_EOF
   173 USAGE_EOF
   158 }
   174 }
   159 
   175 
   160 use strict;
   176 use strict;
   161 my $PerlLibPath;    # fully qualified pathname of the directory containing our Perl modules
   177 use romutl;
   162 # establish the path to the Perl libraries
   178 use romosvariant;
   163 $PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
   179 
   164 $PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
   180 my $PerlEPOCPath = &get_epocroot()."epoc32\/tools\/";   # fully qualified pathname of the directory containing EPOC Perl modules
   165 $PerlLibPath .= "\\";
   181 
   166 sub ExportDirs ($);
   182 sub ExportDirs ($);
   167 
       
   168 use BPABIutl; # for BPABIutl::BPABIutl_Plat_List
       
   169 
   183 
   170 my $xmlrequired = 0; # assume xml required is false. Used to determine if xml
   184 my $xmlrequired = 0; # assume xml required is false. Used to determine if xml
   171                      # modules should be loaded.
   185                      # modules should be loaded.
   172 
   186 
   173 use Modload;	     # To load modules dynamically
   187 use flexmodload;	     # To load modules dynamically
   174 
   188 
   175 # Work out the relative path to the epoc32 directory
   189 # Work out the relative path to the epoc32 directory
   176 use spitool qw(&createSpi);
   190 use spitool qw(&createSpi);
   177 use Cwd;
   191 use Cwd;
   178 use Pathutl;
       
   179 use E32Variant;
       
   180 use E32Plat;
       
   181 use Genutl;
       
   182 use BPABIutl;		# for BPABIutl::BPABIutl_Plat_List
       
   183 use externaltools; 	#To invoke External Tools
   192 use externaltools; 	#To invoke External Tools
       
   193 use File::Basename;
   184 
   194 
   185 my @tempfiles;  	
   195 my @tempfiles;  	
   186 my $preserve = 0; 	#flag to indicate if temporary files should be preserved
   196 my $preserve = 0; 	#flag to indicate if temporary files should be preserved
   187 my $uppath="x";	    	# will be initialised when first needed
   197 my $uppath="x";	    	# will be initialised when first needed
   188 
   198 
   189 my $epocroot = $ENV{EPOCROOT};
   199 my $epocroot = &get_epocroot;
   190 die "ERROR: Must set the EPOCROOT environment variable\n" if (!defined($epocroot));
       
   191 $epocroot =~ s-/-\\-go;	# for those working with UNIX shells
       
   192 die "ERROR: EPOCROOT must not include a drive letter\n" if ($epocroot =~ /^.:/);
       
   193 die "ERROR: EPOCROOT must be an absolute path without a drive letter\n" if ($epocroot !~ /^\\/);
       
   194 die "ERROR: EPOCROOT must not be a UNC path\n" if ($epocroot =~ /^\\\\/);
       
   195 die "ERROR: EPOCROOT must end with a backslash\n" if ($epocroot !~ /\\$/);
       
   196 die "ERROR: EPOCROOT must specify an existing directory\n" if (!-d $epocroot);
       
   197 
       
   198 my $epoc32 = relative_path("${epocroot}epoc32");
       
   199 $epoc32 =~ s-\\-/-go;
       
   200 
   200 
   201 my @obyfiles;
   201 my @obyfiles;
   202 my $cppargs = "-nostdinc -undef";
   202 my $cppargs = "-nostdinc -undef";
   203 my $opt_v = 0;
   203 my $opt_v = 0;
   204 my $opt_o = "";
   204 my $opt_o = "";
   221 use constant ALLSECTIONS    => 1;        # Indicates both paged section and unpaged section will be compressed.
   221 use constant ALLSECTIONS    => 1;        # Indicates both paged section and unpaged section will be compressed.
   222 use constant PAGEDSECTION   => 2;        # Indicates only paged section will be compressed.
   222 use constant PAGEDSECTION   => 2;        # Indicates only paged section will be compressed.
   223 use constant UNPAGEDSECTION => 3;        # Indicates only unpaged section will be compressed.
   223 use constant UNPAGEDSECTION => 3;        # Indicates only unpaged section will be compressed.
   224 my $opt_compression_type = UNCOMPRESSED; # Leave the ROM image uncompressed by default.
   224 my $opt_compression_type = UNCOMPRESSED; # Leave the ROM image uncompressed by default.
   225 
   225 
       
   226 #Variables to store cache command line options
       
   227 my $opt_cache      = 0;
       
   228 my $opt_nocache    = 0;
       
   229 my $opt_cleancache = 0;
       
   230 
   226 my $thisdir=cwd;
   231 my $thisdir=cwd;
   227 $thisdir=~s-/-\\-go;		    # separator from Perl 5.005_02+ is forward slash
   232 $thisdir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
   228 $thisdir=~s-^(.*[^\\])$-$1\\-o;	    # ensure path ends with a backslash
   233 $thisdir.= "\/" unless $thisdir =~ /\/$/;
   229 $thisdir=~s-^.:\\--o;		    # remove drive letter and leading backslash
   234 $thisdir =~ s-\/-\\-g if (&is_windows);
   230 
   235 
   231 my $rominclude = "$epoc32/rom/include";
   236 my $rominclude = $epocroot."epoc32\/rom\/include\/";
       
   237 $rominclude = &get_epocdrive().$rominclude unless $rominclude =~ /^.:/;
       
   238 $rominclude =~s-\\-\/-g;
       
   239 
   232 my %plugintypes; #hash of plugin types and their SPI files' destinations in ROM
   240 my %plugintypes; #hash of plugin types and their SPI files' destinations in ROM
   233 $plugintypes{"ECOM"} = "\\private\\10009d8f\\"; #ECOM SPI files' destination in ROM image
   241 $plugintypes{"ECOM"} = "\/private\/10009d8f\/"; #ECOM SPI files' destination in ROM image
   234 
   242 
   235 my @obydata;
   243 my @obydata;
   236 my @newobydata;
   244 my @newobydata;
   237 my %substitutionData;
   245 my %substitutionData;
   238 my @substitutionOrder;
   246 my @substitutionOrder;
   239 my %languageCodes;
   247 my %languageCodes;
   240 my $defaultLanguageCode;
   248 my $defaultLanguageCode;
   241 my %multiLinguifyAlias;  # to by-pass the 'mustbesysbin' option for multilinguify 'alias'es. 
   249 my %multiLinguifyAlias;  # to by-pass the 'mustbesysbin' option for multilinguify 'alias'es. 
   242 my $abiDowngrade;
   250 my $abiDowngrade = "";
   243 my @binarySelectionOrder;
   251 my @binarySelectionOrder;
   244 my $fromDIR;
   252 my $fromDIR;
   245 my %rombuildOptions = ("-type-safe-link" => 1 );
   253 my %rombuildOptions = ("-type-safe-link" => 1 );
   246 my $enforceSysBin = 0;
   254 my $enforceSysBin = 0;
   247 
   255 
   250 my @romimage;
   258 my @romimage;
   251 my $rombasename;
   259 my $rombasename;
   252 
   260 
   253 my $sourcefile;
   261 my $sourcefile;
   254 my $sourceline;
   262 my $sourceline;
   255 my ($line);
   263 #my $line;
   256 my %romfiles;
   264 my %romfiles;
   257 
   265 
   258 # To handle BINARY_SELECTION_ORDER macro.
   266 # To handle BINARY_SELECTION_ORDER macro.
   259 my $firstDIR;
   267 my $firstDIR;
   260 my $binarySelectionOrderFlag = 0;
   268 my $binarySelectionOrderFlag = 0;
   274 my $geninc = "";
   282 my $geninc = "";
   275 my $gendep = "";
   283 my $gendep = "";
   276 my $nosymbols = "";
   284 my $nosymbols = "";
   277 my $noimage = "";
   285 my $noimage = "";
   278 my $customizedPlat = undef;
   286 my $customizedPlat = undef;
   279 my $opt_fastcompress = "";
       
   280 my $opt_jobs= "";
   287 my $opt_jobs= "";
   281 
   288 
   282 #Summary of files(both executables and data files) currently includes 
   289 #Summary of files(both executables and data files) currently includes 
   283 #	host and ROM file names, 
   290 #	host and ROM file names, 
   284 #	size of the file in ROM
   291 #	size of the file in ROM
   289 
   296 
   290 # This option is used to pass -lowmem argument to rombuild/rofsbuild tools
   297 # This option is used to pass -lowmem argument to rombuild/rofsbuild tools
   291 my $lowMem="";
   298 my $lowMem="";
   292 
   299 
   293 # Feature Variation modules and data
   300 # Feature Variation modules and data
   294 use featurevariantparser;
       
   295 use featurevariantmap;
       
   296 my %featureVariant;
   301 my %featureVariant;
   297 
   302 
   298 # global variables specific to data drive image generation. 
   303 # global variables specific to data drive image generation. 
   299 use File::Path;					# Module to provide functions to remove or create directories in a convenient way.
   304 use File::Path;					# Module to provide functions to remove or create directories in a convenient way.
   300 use File::Copy;					# Module to provide functions to copy file(s) from source to destination.
   305 use File::Copy;					# Module to provide functions to copy file(s) from source to destination.
   336 my %smrPartitions;
   341 my %smrPartitions;
   337 my %smrNameInfo;
   342 my %smrNameInfo;
   338 my @obeyFileList;
   343 my @obeyFileList;
   339 my $smrNoImageName = 0;
   344 my $smrNoImageName = 0;
   340 my $onlysmrimage = 1;
   345 my $onlysmrimage = 1;
       
   346 my $checkcase = 0;
       
   347 my $checkcase_platform = "";
       
   348 my $checkcase_test = 0;
       
   349 my $opt_workdir = 0;
       
   350 my $prependepocroot = 0;
       
   351 my $stdcpp = 0;
       
   352 my $obycharset;
       
   353 my $cppoption = 0;
       
   354 my $preprocessor = "cpp";
   341 
   355 
   342 sub match_obyfile
   356 sub match_obyfile
   343 {
   357 {
   344 	my ($obyfile) = @_;
   358 	my ($obyfile) = @_;
   345 	if (-f $obyfile)
   359 	if (-f $obyfile)
   357 
   371 
   358 		@otherDirs = @$dirRef if ($dirRef);
   372 		@otherDirs = @$dirRef if ($dirRef);
   359 	}
   373 	}
   360 	foreach my $dir (@otherDirs)
   374 	foreach my $dir (@otherDirs)
   361 	{
   375 	{
       
   376 		print "$dir/$obyfile\n" if ($opt_v);
   362 		if (-f "$dir/$obyfile")
   377 		if (-f "$dir/$obyfile")
   363 		{
   378 		{
   364 		    push @obyfiles, "$dir/$obyfile";
   379 		    push @obyfiles, "$dir/$obyfile";
   365 		    return 1;
   380 		    return 1;
   366 		}
   381 		}
   430 		if($retVal)
   445 		if($retVal)
   431 		{
   446 		{
   432 			&datadriveimage::reportError("* Warning could not delete $ZDirloc",$opt_k);
   447 			&datadriveimage::reportError("* Warning could not delete $ZDirloc",$opt_k);
   433 		}
   448 		}
   434 		# delete data drive directory if and only if preserve(-p) option is disabled.
   449 		# delete data drive directory if and only if preserve(-p) option is disabled.
   435 		my $retVal = &deleteDirectory($DataDriveDirloc,$opt_v)if(!($preserve));
   450 		$retVal = &deleteDirectory($DataDriveDirloc,$opt_v)if(!($preserve));
   436 		if($retVal)
   451 		if($retVal)
   437 		{
   452 		{
   438 			&datadriveimage::reportError("* Warning could not delete $DataDriveDirloc",$opt_k);
   453 			&datadriveimage::reportError("* Warning could not delete $DataDriveDirloc",$opt_k);
   439 		}
   454 		}
   440 		# reset image count to zero.
   455 		# reset image count to zero.
   451 	
   466 	
   452 	if (!$preserve)
   467 	if (!$preserve)
   453 	{
   468 	{
   454 	    foreach my $tempfiles (@tempfiles)
   469 	    foreach my $tempfiles (@tempfiles)
   455 	    {
   470 	    {
       
   471 	    print "remove $tempfiles\n" if ($opt_v);
   456 			unlink "$tempfiles";
   472 			unlink "$tempfiles";
   457 	    }
   473 	    }
   458 	}
   474 	}
   459 	if($rombasename)
   475 	if($rombasename)
   460 	{
   476 	{
   487 {
   503 {
   488 	if($dataImageCount)
   504 	if($dataImageCount)
   489 	{
   505 	{
   490 		# set the default path for Z drive and Data drive directory,
   506 		# set the default path for Z drive and Data drive directory,
   491 		# if and only if, path is not specified by the user. 
   507 		# if and only if, path is not specified by the user. 
   492 		$ZDirloc = &datadriveimage::setPath("zdrive") unless ($ZDirloc);
   508 		$ZDirloc = $thisdir."zdrive" unless ($ZDirloc);
   493 		$DataDriveDirloc = &datadriveimage::setPath("datadrive") unless ($DataDriveDirloc);
   509 		$DataDriveDirloc = $thisdir."datadrive" unless ($DataDriveDirloc);
   494 		#delete any existing Z drive directory.
   510 		#delete any existing Z drive directory.
   495 		my $retVal = &datadriveimage::deleteDirectory($ZDirloc,$opt_v)if(!$opt_r);
   511 		my $retVal = &datadriveimage::deleteDirectory($ZDirloc,$opt_v)if(!$opt_r);
   496 		if($retVal)
   512 		if($retVal)
   497 		{
   513 		{
   498 			exit(1) if(!$opt_k);
   514 			exit(1) if(!$opt_k);
   499 		}
   515 		}
   500 		# delete pre-existence of data drive folder, if and only if -r option is not enabled.
   516 		# delete pre-existence of data drive folder, if and only if -r option is not enabled.
   501 		my $retVal = &datadriveimage::deleteDirectory($DataDriveDirloc,$opt_v) if(!$opt_r);
   517 		$retVal = &datadriveimage::deleteDirectory($DataDriveDirloc,$opt_v) if(!$opt_r);
   502 		if($retVal)
   518 		if($retVal)
   503 		{
   519 		{
   504 			exit(1) if(!$opt_k);
   520 			exit(1) if(!$opt_k);
   505 		}
   521 		}
   506 		if($opt_logFile)
   522 		if($opt_logFile)
   507 		{
   523 		{
   508 			# clean any pre-existance of log file.
   524 			# clean any pre-existance of log file.
   509 			unlink($ZDirloc."\\".$imageEntryLogFile);
   525 			unlink($ZDirloc."\/".$imageEntryLogFile);
   510 		}
   526 		}
   511 		
   527 		
   512 		for (my $datadriveidx=0; $datadriveidx < $dataImageCount; $datadriveidx++)
   528 		for (my $datadriveidx=0; $datadriveidx < $dataImageCount; $datadriveidx++)
   513 		{
   529 		{
   514 			my $driveIndex = $dataIndexHash{$datadriveidx};
   530 			my $driveIndex = $dataIndexHash{$datadriveidx};
   525 					# final location of prototype data drive.
   541 					# final location of prototype data drive.
   526 					my $proDataDriveDirloc;
   542 					my $proDataDriveDirloc;
   527 					# Location of stub-sis file(s) inside Z Drive folder.
   543 					# Location of stub-sis file(s) inside Z Drive folder.
   528 					my $zDriveSisFileLoc;
   544 					my $zDriveSisFileLoc;
   529 					# check if more than one data drive image needs to be generated. 
   545 					# check if more than one data drive image needs to be generated. 
       
   546 					if ($datadrivename =~ /.*[\\\/]([^\\\/]+)$/)
       
   547 					{
       
   548 						$datadrivename = $1;
       
   549 					}
   530 					if( $dataImageCount > 1 )
   550 					if( $dataImageCount > 1 )
   531 					{
   551 					{
   532 						# if yes, then set the location of prototype data drive folder as 
   552 						# if yes, then set the location of prototype data drive folder as 
   533 						# DataDriveDirloc + datadrivename
   553 						# DataDriveDirloc + datadrivename
   534 						$proDataDriveDirloc = $DataDriveDirloc."\\".$datadrivename;
   554 						$proDataDriveDirloc = $DataDriveDirloc."\/".$datadrivename;
   535 					}
   555 					}
   536 					else
   556 					else
   537 					{
   557 					{
   538 						# else, then set the location of prototype data drive folder as DataDriveDirloc 
   558 						# else, then set the location of prototype data drive folder as DataDriveDirloc 
   539 						$proDataDriveDirloc = $DataDriveDirloc;
   559 						$proDataDriveDirloc = $DataDriveDirloc;
   554 						{
   574 						{
   555 							# find out size of the array
   575 							# find out size of the array
   556 							my $arraysize = scalar(@zDriveImageList);
   576 							my $arraysize = scalar(@zDriveImageList);
   557 							for( my $i=0; $i < $arraysize; $i++ )
   577 							for( my $i=0; $i < $arraysize; $i++ )
   558 							{
   578 							{
   559 								$zDriveSisFileLoc =  $ZDirloc."\\".$datadrivename;
   579 								$zDriveSisFileLoc =  $ZDirloc."\/".$datadrivename;
   560 								&datadriveimage::invokeReadImage(pop(@zDriveImageList),$zDriveSisFileLoc,$opt_v,$imageEntryLogFile,$opt_k);
   580 								&datadriveimage::invokeReadImage(pop(@zDriveImageList),$zDriveSisFileLoc,$opt_v,$imageEntryLogFile,$opt_k);
   561 							}
   581 							}
   562 						}
   582 						}
   563 						else
   583 						else
   564 						{
   584 						{
   590 									}
   610 									}
   591 								}
   611 								}
   592 							}
   612 							}
   593 						}
   613 						}
   594 						# invoke INTERPRETSIS tool with z drive folder location.
   614 						# invoke INTERPRETSIS tool with z drive folder location.
   595 						&datadriveimage::invokeInterpretsis( \@sisfilelist,$proDataDriveDirloc,$opt_v,$zDriveSisFileLoc,$paraFile,$opt_k,\@interpretsisOptList)if($sisfilepresent);
   615 						if ($useinterpretsis)
       
   616 						{
       
   617 							&datadriveimage::invokeInterpretsis( \@sisfilelist,$proDataDriveDirloc,$opt_v,$zDriveSisFileLoc,$paraFile,$opt_k,\@interpretsisOptList,$thisdir)if($sisfilepresent);
       
   618 						}else
       
   619 						{
       
   620 							print "Warning: interpretsis is not ready on linux.\n";
       
   621 						}	
   596 					}
   622 					}
   597 
   623 
   598 					# create an oby file by traversing through upated prototype data drive directory.
   624 					# create an oby file by traversing through upated prototype data drive directory.
   599 					&datadriveimage::dumpDatadriveObydata( $proDataDriveDirloc,$datadriveobyfile,$size,\@nonsisFilelist,
   625 					&datadriveimage::dumpDatadriveObydata( $proDataDriveDirloc,$datadriveobyfile,$size,\@nonsisFilelist,
   600 										\@renameList,\@aliaslist,\@hideList,\@sisobydata,\@datadrivedata,$opt_k,$opt_v );
   626 										\@renameList,\@aliaslist,\@hideList,\@sisobydata,\@datadrivedata,$opt_k,$opt_v );
   727 	}
   753 	}
   728 
   754 
   729 	if (!defined $paramFileFlag) 
   755 	if (!defined $paramFileFlag) 
   730 	{
   756 	{
   731 		# Enforce Feature Manager if macro SYMBIAN_FEATURE_MANAGER is defined in the HRH file.
   757 		# Enforce Feature Manager if macro SYMBIAN_FEATURE_MANAGER is defined in the HRH file.
   732 		my @hrhMacros = &Variant_GetMacroList;	
   758 		my @hrhMacros = &get_variantmacrolist;	
   733 		if (grep /^SYMBIAN_FEATURE_MANAGER\s*$/, @hrhMacros)
   759 		if (grep /^SYMBIAN_FEATURE_MANAGER\s*$/, @hrhMacros)
   734 		{
   760 		{
   735 			$enforceFeatureManager = 1;
   761 			$enforceFeatureManager = 1;
   736 		}
   762 		}
   737 		
   763 		
   742 			{
   768 			{
   743 				&parameterFileProcessor($1);				
   769 				&parameterFileProcessor($1);				
   744 			}
   770 			}
   745 		}
   771 		}
   746 	}
   772 	}
   747 
   773 	# first searching argList for keepgoing option
       
   774 	foreach my $arg (@argList) {
       
   775 		if ( $arg =~ /^-k$/i || $arg =~ /^-keepgoing$/i )
       
   776 	  {
       
   777 			$opt_k = 1;		
       
   778   		next;	
       
   779 		}
       
   780 		if ($arg =~ /^-workdir=(.*)/)
       
   781 		{
       
   782 			my $workdir = $1;
       
   783 			if (!-d $workdir)
       
   784 			{
       
   785 				die "directory $workdir does not exist\n";
       
   786 			}
       
   787 			my $currentdir = cwd;
       
   788 			chdir "$workdir" or die "cannot change to directory $workdir\n";
       
   789 			$thisdir=cwd;
       
   790 			$thisdir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
       
   791 			$thisdir.= "\/" unless $thisdir =~ /\/$/;
       
   792 			if(&is_windows)
       
   793 			{
       
   794 				$thisdir =~ s-\/-\\-g;
       
   795 			}
       
   796 			$opt_workdir = 1;
       
   797 			chdir "$currentdir";
       
   798 			next;	
       
   799 		}
       
   800 	}
   748 	foreach my $arg (@argList)
   801 	foreach my $arg (@argList)
   749 	{
   802 	{
   750 	    if ($arg =~ /^-argfile=(.*)/) 
   803 	    if ($arg =~ /^-argfile=(.*)/) 
   751 		{
   804 		{
   752 			&parameterFileProcessor($1) if (defined $paramFileFlag);						
   805 			&parameterFileProcessor($1) if (defined $paramFileFlag);						
   771 			my $varname = $1;
   824 			my $varname = $1;
   772 			
   825 			
   773 			if ($varname =~ /^\.(.*)$/)
   826 			if ($varname =~ /^\.(.*)$/)
   774 			{
   827 			{
   775 				# for testing, locate the VAR file in the current directory
   828 				# for testing, locate the VAR file in the current directory
   776 				%featureVariant = featurevariantparser->GetVariant($1, ".");
   829 				%featureVariant = get_variant($1, ".");
   777 			}
   830 			}
   778 			else
   831 			else
   779 			{
   832 			{
   780 				%featureVariant = featurevariantparser->GetVariant($varname);
   833 				%featureVariant = get_variant($varname);
   781 			}
   834 			}
   782 			if (!$featureVariant{'VALID'})
   835 			if (!$featureVariant{'VALID'})
   783 			{
   836 			{
   784 			    print "FEATUREVARIANT $varname is not VALID\n";
   837 			    print "FEATUREVARIANT $varname is not VALID\n";
   785 				$errors++;
   838 				$errors++;
   791 			}
   844 			}
   792 			addDrivesToFeatureVariantPaths();
   845 			addDrivesToFeatureVariantPaths();
   793 		}
   846 		}
   794 		next;
   847 		next;
   795 	    }
   848 	    }
   796 	    if ($arg =~ /^-o(.*)/i)
   849 	    if ($arg =~/^-oby-charset=(.*)$/i)
       
   850 	    {
       
   851 		$obycharset = $1;
       
   852 		next;
       
   853 	    }
       
   854 	    if (($arg =~ /^-o(.*)/i) && ($arg !~ /^-oby-charset/i))
   797 	    {
   855 	    {
   798 		$opt_o = $1;
   856 		$opt_o = $1;
   799 		next;
   857 		next;
   800 	    }
       
   801 	    if ($arg =~ /^-fastcompress$/i)
       
   802 	    {
       
   803 		    $opt_fastcompress = "-fastcompress";
       
   804 		    next;
       
   805 	    }
   858 	    }
   806 	    if ($arg =~ /^-j(\d+)$/i)
   859 	    if ($arg =~ /^-j(\d+)$/i)
   807 	    {
   860 	    {
   808 		    $opt_jobs = "-j".$1;
   861 		    $opt_jobs = "-j".$1;
   809 		    next;
   862 		    next;
   869 			{
   922 			{
   870 				print "Error: No filename specified with \"-fm=\" option.\n";
   923 				print "Error: No filename specified with \"-fm=\" option.\n";
   871 			}			
   924 			}			
   872 			next;
   925 			next;
   873 	    }
   926 	    }
       
   927 		#Process Cache command line options.
       
   928 		if($arg =~ /^-cache/)
       
   929 		{
       
   930 			$opt_cache = 1;
       
   931 			next;
       
   932 		}
       
   933 		if($arg =~ /^-nocache/)
       
   934 		{
       
   935 			$opt_nocache = 1;
       
   936 			next;
       
   937 		}
       
   938 		if($arg =~ /^-cleancache/)
       
   939 		{
       
   940 			$opt_cleancache = 1;
       
   941 			next;
       
   942 		}
       
   943 
   874 	    #Process ROM image compression type if it's specified through command line option.
   944 	    #Process ROM image compression type if it's specified through command line option.
   875 	    if($arg =~ /^-compress(.*)/)
   945 	    if($arg =~ /^-compress(.*)/)
   876 	    {
   946 	    {
   877 	    	if($1 eq '')
   947 	    	if($1 eq '')
   878 	    	{
   948 	    	{
   956 		if($arg =~ /^-gendep$/)
  1026 		if($arg =~ /^-gendep$/)
   957 		{
  1027 		{
   958 			$gendep=1;
  1028 			$gendep=1;
   959 			next;
  1029 			next;
   960 		}
  1030 		}
   961         if($arg =~/^-c(.*)/)
  1031 		if ($arg =~ /^-checkcase$/)
       
  1032 		{
       
  1033 			$checkcase=1;
       
  1034 			next;	
       
  1035 		}
       
  1036 		if ($arg =~ /^-checkcase_test$/)
       
  1037 		{
       
  1038 			$checkcase_test=1;
       
  1039 			next;	
       
  1040 		}
       
  1041 		if ($arg =~ /^-workdir=(.*)/)
       
  1042 		{
       
  1043 			next;
       
  1044 		}
       
  1045 		if ($arg =~ /^-stdcpp$/)
       
  1046 		{
       
  1047 			if (&is_linux)
       
  1048 			{
       
  1049 				print "Warning: option -stdcpp only apply for Windows\n";
       
  1050 				next;
       
  1051 			}
       
  1052 			if ($cppoption)
       
  1053 			{
       
  1054 				die "Error: -stdcpp option and -cpp=xxx option cannot be used at the same time.\n";
       
  1055 			}
       
  1056 			$stdcpp = 1;
       
  1057 			next;
       
  1058 		}
       
  1059 		if ($arg =~ /^-cpp=(.*)/)
       
  1060 		{
       
  1061 			if ($stdcpp)
       
  1062 			{
       
  1063 				die "Error: -stdcpp option and -cpp=xxx option cannot be used at the same time.\n";
       
  1064 			}
       
  1065 			if ($cppoption)
       
  1066 			{
       
  1067 				print "Warning: -cpp option has been set before. The previous configuration will be overwritten!\n";
       
  1068 			}
       
  1069 			$cppoption = 1;
       
  1070 			$preprocessor = $1;
       
  1071 			$preprocessor =~ s-\\-\/-g;
       
  1072 			$preprocessor =~ s-EPOCROOT##\/?-$epocroot-g;
       
  1073 			if (-d $preprocessor)
       
  1074 			{
       
  1075 				$preprocessor .= "\/" unless $preprocessor =~ /\/$/;
       
  1076 				$preprocessor .= "cpp";
       
  1077 			}
       
  1078 			next;
       
  1079 		}
       
  1080 
       
  1081 		if ($arg =~ /^-prependepocroot$/)
       
  1082 		{
       
  1083 			$prependepocroot = 1;
       
  1084 			next;
       
  1085 		}
       
  1086 		    if($arg =~/^-c(.*)/)
   962         {
  1087         {
   963           if($1 eq 'none' )
  1088           if($1 eq 'none' )
   964           {
  1089           {
   965               $opt_compression = " -compressionmethod none";
  1090               $opt_compression = " -compressionmethod none";
   966           }
  1091           }
   996 				next;
  1121 				next;
   997 			}
  1122 			}
   998 			else
  1123 			else
   999 			{
  1124 			{
  1000 				$ZDirloc  = $1;
  1125 				$ZDirloc  = $1;
  1001 				if( $ZDirloc !~ m/\\(\Z)/)
  1126 				$ZDirloc =~ s-\\-\/-g;
       
  1127 				if( $ZDirloc !~ m/\/(\Z)/)
  1002 				{ 
  1128 				{ 
  1003 					$ZDirloc .= "\\"; 
  1129 					$ZDirloc .= "\/"; 
  1004 				}
  1130 				}
  1005 				if( $ZDirloc !~ m/:/)
  1131 				if( $ZDirloc !~ m/:/)
  1006 				{
  1132 				{
  1007 					print "drive letter not specified\n";
  1133 					print "drive letter not specified\n";
  1008 					$ZDirloc = &datadriveimage::setPath($ZDirloc);
  1134 					$ZDirloc = $thisdir.$ZDirloc;
  1009 				}
  1135 				}
  1010 				print "Z Drive directory location = $ZDirloc\n";
  1136 				print "Z Drive directory location = $ZDirloc\n";
  1011 				#set the location of Z Drive directory.
  1137 				#set the location of Z Drive directory.
  1012 				$ZDirloc .= "zdrive";
  1138 				$ZDirloc .= "zdrive";
  1013 			}
  1139 			}
  1025 				next;
  1151 				next;
  1026 			}
  1152 			}
  1027 			else
  1153 			else
  1028 			{
  1154 			{
  1029 				$DataDriveDirloc = $1;
  1155 				$DataDriveDirloc = $1;
  1030 				if( $DataDriveDirloc !~ m/\\(\Z)/)
  1156 				$DataDriveDirloc =~ s-\\-\/-g;
       
  1157 				if( $DataDriveDirloc !~ m/\/(\Z)/)
  1031 				{ 
  1158 				{ 
  1032 					$DataDriveDirloc .= "\\"; 
  1159 					$DataDriveDirloc .= "\/"; 
  1033 				}
  1160 				}
  1034 				if( $DataDriveDirloc !~ m/:/)
  1161 				if( $DataDriveDirloc !~ m/:/)
  1035 				{
  1162 				{
  1036 					print "drive not specified\n";
  1163 					print "drive not specified\n";
  1037 					$DataDriveDirloc = &datadriveimage::setPath($DataDriveDirloc);
  1164 					$DataDriveDirloc = $thisdir.$DataDriveDirloc;
  1038 				}
  1165 				}
  1039 				print "Data Drive directory location = $DataDriveDirloc\n";
  1166 				print "Data Drive directory location = $DataDriveDirloc\n";
  1040 				#set the location of Data Drive directory.
  1167 				#set the location of Data Drive directory.
  1041 				$DataDriveDirloc .= "datadrive";
  1168 				$DataDriveDirloc .= "datadrive";
  1042 			}
  1169 			}
  1086 			$paraFile = $1;
  1213 			$paraFile = $1;
  1087 			next;
  1214 			next;
  1088 	    }
  1215 	    }
  1089 		if ( $arg =~ /^-l=(.*)/i || $arg =~ /^-logimageentry=(.*)/i )
  1216 		if ( $arg =~ /^-l=(.*)/i || $arg =~ /^-logimageentry=(.*)/i )
  1090 	    {
  1217 	    {
  1091 			if( $1 =~/\\/ || $1 =~ m/:/)
  1218 			if( $1 =~/[\/\\]/ || $1 =~ m/:/)
  1092 			{
  1219 			{
  1093 				print "* Warning: Invalid log file extension try filename.txt\n";
  1220 				print "* Warning: Invalid log file extension try filename.txt\n";
  1094 				next;
  1221 				next;
  1095 			}
  1222 			}
  1096 			else
  1223 			else
  1114 	    # It's an OBY file
  1241 	    # It's an OBY file
  1115 	    next if (match_obyfile($arg));
  1242 	    next if (match_obyfile($arg));
  1116 	    next if (match_obyfile("$arg.oby"));
  1243 	    next if (match_obyfile("$arg.oby"));
  1117 
  1244 
  1118 	    print "Cannot find oby file: $arg\n";
  1245 	    print "Cannot find oby file: $arg\n";
  1119 	    $errors++;
  1246 	    $errors++ if(!$opt_k);
  1120 	}
  1247 	}
  1121 
  1248 
  1122 	if (defined $paramFileFlag) 
  1249 	if (defined $paramFileFlag) 
  1123 	{
  1250 	{
  1124 		return;
  1251 		return;
  1125 	}
  1252 	}
  1126 	
  1253 	
  1127 	if (@obyfiles<1)
  1254 	if (@obyfiles<1)
  1128 	{
  1255 	{
  1129 	    print "Missing obyfile argument\n";
  1256 	    print "Missing obyfile argument\n";
  1130 	    $errors++;
  1257 	    $errors++ if(!$opt_k);
       
  1258 	}
       
  1259 	if(defined($obycharset))
       
  1260 	{
       
  1261 		unless($obycharset =~ /utf-?8/i)
       
  1262 		{
       
  1263 			print "Warning: Ignoring not supportted charset $obycharset, local charset will be used as default!\n";
       
  1264 		}
  1131 	}
  1265 	}
  1132 
  1266 
  1133 	if ($errors)
  1267 	if ($errors)
  1134 	{
  1268 	{
  1135 	    print_usage();
  1269 	    print_usage();
  1144 
  1278 
  1145 	# Adding variant specific macros by including a HRH file
  1279 	# Adding variant specific macros by including a HRH file
  1146 	# (only required if no Feature Variant is used)
  1280 	# (only required if no Feature Variant is used)
  1147 	if (!$featureVariant{'VALID'})
  1281 	if (!$featureVariant{'VALID'})
  1148 	{
  1282 	{
  1149 	    my $variantMacroHRHFile = Variant_GetMacroHRHFile();
  1283 	    my $variantMacroHRHFile = get_variantmacroHRHfile();
  1150 	    if($variantMacroHRHFile){
  1284 	    if($variantMacroHRHFile){
  1151 
  1285 	        my $variantFilePath = split_path('Path',$variantMacroHRHFile);
  1152 	        my $variantFilePath = Path_Split('Path',$variantMacroHRHFile);
  1286 	        $cppargs .= " -I " . &append_driveandquote($variantFilePath) . " -include " . &append_driveandquote($variantMacroHRHFile); 
  1153 	        $cppargs .= " -I \"" . &Path_RltToWork($variantFilePath) . "\" -include \"" . &Path_RltToWork($variantMacroHRHFile) . "\""; 
  1287 	        print "in cmd process $cppargs\n" if ($opt_v);
  1154 	    }
  1288 	    }
  1155 	}
  1289 	}
  1156 	# load the required modules if xml is required
  1290 	# load the required modules if xml is required
  1157 	if ($xmlrequired == 1)
  1291 	if ($xmlrequired == 1)
  1158 	{
  1292 	{
  1159 	    my $epocToolsPath = $ENV{EPOCROOT}."epoc32\\tools\\";
       
  1160 	    Load_SetModulePath($epocToolsPath);
       
  1161 	    if (defined ($featureXml))
  1293 	    if (defined ($featureXml))
  1162 	    {
  1294 	    {
  1163 			load_featuresutil();
  1295 			load_featuresutil();
  1164 	    }
  1296 	    }
  1165 	
  1297 	
  1166 	    if ($image_content)
  1298 	    if ($image_content)
  1167 	    {
  1299 	    {
  1168 	    	&Load_ModuleL("ImageContentHandler");
  1300 	    	&FlexLoad_ModuleL("ImageContentHandler");
  1169 	    	# some variables for ImageContentHandler may have been setup
  1301 	    	# some variables for ImageContentHandler may have been setup
  1170 	    	my ($key, $value);
  1302 	    	my ($key, $value);
  1171 	    	&ImageContentHandler::SetBldRomOpts; # Defaults to ARMV5 platform
  1303 	    	&ImageContentHandler::SetBldRomOpts; # Defaults to armv5 platform
  1172 	    	while (($key,$value) = each %tmpBldRomOpts)
  1304 	    	while (($key,$value) = each %tmpBldRomOpts)
  1173 	    	{
  1305 	    	{
  1174 			&ImageContentHandler::SetBldRomOpts($key, $value);
  1306 			&ImageContentHandler::SetBldRomOpts($key, $value);
  1175 	    	}
  1307 	    	}
  1176 	    }
  1308 	    }
  1184 # Concatentate the specified .oby files and pass them through cpp
  1316 # Concatentate the specified .oby files and pass them through cpp
  1185 # to get the raw ROM specification in tmp1.oby
  1317 # to get the raw ROM specification in tmp1.oby
  1186 
  1318 
  1187 sub preprocessing_phase
  1319 sub preprocessing_phase
  1188 {
  1320 {
  1189 	unlink "tmp1.oby";
  1321 	my $temp1OBYFile = $thisdir."tmp1.oby";
       
  1322 	unlink "$temp1OBYFile";
  1190 
  1323 
  1191 #	Macro "ROM_FEATURE_MANAGEMENT" is defined when "-f|fr" or "-fm" is used
  1324 #	Macro "ROM_FEATURE_MANAGEMENT" is defined when "-f|fr" or "-fm" is used
  1192 	if (defined ($featureXml))
  1325 	if (defined ($featureXml))
  1193 	{
  1326 	{
  1194 		$cppargs .= " -DROM_FEATURE_MANAGEMENT ";
  1327 		$cppargs .= " -DROM_FEATURE_MANAGEMENT ";
  1213 		}
  1346 		}
  1214 	}
  1347 	}
  1215 	else
  1348 	else
  1216 	{
  1349 	{
  1217 		# no feature variant so use the standard includes
  1350 		# no feature variant so use the standard includes
  1218 		$cppargs .= " -I. -I$rominclude";
  1351 		$cppargs .= " -I. -I \"$rominclude\"";
  1219 	}
  1352 	}
  1220 
  1353 
  1221 	print "* cpp -o tmp1.oby $cppargs\n" if ($opt_v);
  1354 	if ($stdcpp)
       
  1355 	{
       
  1356 		$preprocessor = find_stdcpp();
       
  1357 	}
       
  1358 	print "* $preprocessor -Wno-endif-labels -o $temp1OBYFile $cppargs\n" if ($opt_v);
  1222 	
  1359 	
       
  1360 	is_existinpath("$preprocessor", romutl::DIE_NOT_FOUND);
  1223 	$errors = 0;
  1361 	$errors = 0;
  1224 	open CPP, "| cpp -o tmp1.oby $cppargs" or die "* Can't execute cpp";
  1362 	open CPP, "| $preprocessor -Wno-endif-labels -o $temp1OBYFile $cppargs" or die "* Can't execute cpp";
  1225 	foreach my $arg (@obyfiles)
  1363 	foreach my $arg (@obyfiles)
  1226 	{
  1364 	{
  1227 		print CPP "\n#line 1 \"$arg\"\n";
  1365 		print CPP "\n#line 1 \"$arg\"\n";
  1228 	
  1366 	
  1229 		open OBY, $arg or die "* Can't open $arg";
  1367 		if(open(OBY, $arg)) {
  1230 		print "* reading $arg\n" if ($opt_v);
  1368 			print "* reading $arg\n" if ($opt_v);
  1231 		while ($line=<OBY>)
  1369 			while ($line=<OBY>) {
  1232 		{
  1370 				print CPP $line;
  1233 			print CPP $line;
  1371 			}
  1234 		}
  1372 			close OBY;
  1235 		close OBY;
  1373 		}
       
  1374 		else {
       
  1375 			print STDERR "* Can't open $arg\n";
       
  1376 			if(!$opt_k){			
       
  1377 				close CPP;
       
  1378 				exit(1);
       
  1379 			}
       
  1380 		}
  1236 	}
  1381 	}
  1237 	close CPP;
  1382 	close CPP;
  1238 	my $cpp_status = $?;
  1383 	my $cpp_status = $?;
  1239 	die "* cpp failed\n" if ($cpp_status != 0 || !-f "tmp1.oby");
  1384 	die "* cpp failed\n" if ($cpp_status != 0 || !-f "$temp1OBYFile");
  1240 
  1385 
  1241 	my $temp1OBYFile = "tmp1.oby";
       
  1242 	if( defined ($image_content))
  1386 	if( defined ($image_content))
  1243 	{
  1387 	{
  1244 		#Read the OBY file that was generated by the pre-processor
  1388 		#Read the OBY file that was generated by the pre-processor
  1245 		&ReadPreprocessedFile($temp1OBYFile);
  1389 		&ReadPreprocessedFile($temp1OBYFile);
  1246 
  1390 
  1251 		&ImageContentHandler::GenObyFile($temp1OBYFile);
  1395 		&ImageContentHandler::GenObyFile($temp1OBYFile);
  1252 	}
  1396 	}
  1253 
  1397 
  1254 	# Setup default rom configuration
  1398 	# Setup default rom configuration
  1255 	$romimage[0] = {xip=>1, compress=>0, extension=>0, composite=>"none",uncompress=>0 };
  1399 	$romimage[0] = {xip=>1, compress=>0, extension=>0, composite=>"none",uncompress=>0 };
       
  1400 	if($obycharset =~ /utf-?8/i)
       
  1401 	{
       
  1402 		my $utf8file = $thisdir."tmp1utf8.oby";
       
  1403 		open INFILE, "<$temp1OBYFile" or die "* Can't open file $temp1OBYFile";
       
  1404 		open CHARSETTRAN, "| charsettran -to=hostcharset > $utf8file" or die "* Can't execute charsetran";
       
  1405 		while(<INFILE>)
       
  1406 		{
       
  1407 			print CHARSETTRAN $_;
       
  1408 		}
       
  1409 		close CHARSETTRAN;
       
  1410 		close INFILE;	
       
  1411 		unlink $temp1OBYFile  or die "* Can't remove file $temp1OBYFile";
       
  1412 		rename 	$utf8file, $temp1OBYFile or die "* Can't rename file $utf8file to file $temp1OBYFile";
       
  1413 	}
  1256 }
  1414 }
  1257 
  1415 
  1258 sub ReadPreprocessedFile
  1416 sub ReadPreprocessedFile
  1259 {
  1417 {
  1260 #	Read the OBY file that was generated by the pre-processor. This OBY is a conglomeration of all the OBYs
  1418 #	Read the OBY file that was generated by the pre-processor. This OBY is a conglomeration of all the OBYs
  1273 	while($tmpline =<OBYFH>) {
  1431 	while($tmpline =<OBYFH>) {
  1274 		if ($tmpline=~/(\S+)\s*=\s*(\S+)\s+(\S+)/) {#Get the first parameter (source File path) from oby line
  1432 		if ($tmpline=~/(\S+)\s*=\s*(\S+)\s+(\S+)/) {#Get the first parameter (source File path) from oby line
  1275 			$srcFilePath = $2;
  1433 			$srcFilePath = $2;
  1276 			$dstFilePath = $3;
  1434 			$dstFilePath = $3;
  1277 
  1435 
  1278 			if ($srcFilePath=~/.*\\(\S+)/) {
  1436 			if ($srcFilePath=~/.*[\/\\](\S+)/) {
  1279 				$srcFileName = $1;
  1437 				$srcFileName = $1;
  1280 			}
  1438 			}
  1281 			if ($dstFilePath=~/.*\\(\S+)/) {
  1439 			if ($dstFilePath=~/.*[\/\\](\S+)/) {
  1282 				$dstFileName = $1;
  1440 				$dstFileName = $1;
  1283 			}
  1441 			}
  1284 			my $binaryInfoRef = &cdfparser::GetBinaryInfo($dstFileName);
  1442 			my $binaryInfoRef = &cdfparser::GetBinaryInfo($dstFileName);
  1285 
  1443 
  1286 			if(defined($binaryInfoRef)) 
  1444 			if(defined($binaryInfoRef)) 
  1322 		$substitutionData{"RIGHT_NOW"} = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mday, $mon+1, $year+1900, $hour, $min, $sec);
  1480 		$substitutionData{"RIGHT_NOW"} = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $mday, $mon+1, $year+1900, $hour, $min, $sec);
  1323 		$substitutionData{"EPOCROOT"} = $epocroot;
  1481 		$substitutionData{"EPOCROOT"} = $epocroot;
  1324 		@substitutionOrder = ("TODAY", "RIGHT_NOW", "EPOCROOT");
  1482 		@substitutionOrder = ("TODAY", "RIGHT_NOW", "EPOCROOT");
  1325 	}
  1483 	}
  1326 
  1484 
       
  1485 	my $temp1OBYFile = $thisdir."tmp1.oby";
  1327 	
  1486 	
  1328 	open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
  1487 	open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
  1329 	while ($line=<TMP1>)
  1488 	while ($line=<TMP1>)
  1330 	{
  1489 	{
  1331 
       
  1332 		if(($line =~ /^\s*romsize\s*=/i) || ( $line=~ /^\s*rom_image/i) || ($line =~ /^\s*data_image/i))
  1490 		if(($line =~ /^\s*romsize\s*=/i) || ( $line=~ /^\s*rom_image/i) || ($line =~ /^\s*data_image/i))
  1333 		{
  1491 		{
  1334 			$onlysmrimage = 0;
  1492 			$onlysmrimage = 0;
  1335 			last;
  1493 			last;
  1336 		}
  1494 		}
  1337 	}
  1495 	}
  1338 	close TMP1;	
  1496 	close TMP1;	
  1339 	if ($enforceFeatureManager && (!$featuremanager) && (!$noFeatureManager) )
  1497 	if ($enforceFeatureManager && (!$featuremanager) && (!$noFeatureManager) )
  1340 	{
  1498 	{
  1341 		my $defaultFeatureDbFlag = 0;
  1499 		my $defaultFeatureDbFlag = 0;
  1342 		open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
  1500 		open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
  1343 		while ($line=<TMP1>)
  1501 		while ($line=<TMP1>)
  1344 		{
  1502 		{
  1345 			if ($line=~/^\s*defaultfeaturedb\s*=?\s*(\S+)/i)
  1503 			if ($line=~/^\s*defaultfeaturedb\s*=?\s*(\S+)/i)
  1346 			{	
  1504 			{	
  1347 				# Get the default value for featuredatabasefile
  1505 				# Get the default value for featuredatabasefile
  1348                 
  1506                 
  1349 				$featureXml = "$epocroot$1";
  1507 				$featureXml = "$epocroot$1";
       
  1508 				$featureXml =~ s-\\-\/-g;
  1350 				$featuremanager = 1;				
  1509 				$featuremanager = 1;				
  1351 				$defaultFeatureDbFlag = 1;
  1510 				$defaultFeatureDbFlag = 1;
  1352 				load_featuresutil();				
  1511 				load_featuresutil();				
  1353 				last;
  1512 				last;
  1354 			}
  1513 			}
  1360 			print "Error: Neither option \"-fm|-nofm\" nor default value for featuredatabase file is provided.\n";
  1519 			print "Error: Neither option \"-fm|-nofm\" nor default value for featuredatabase file is provided.\n";
  1361 			exit(1);			
  1520 			exit(1);			
  1362 		}
  1521 		}
  1363 	}
  1522 	}
  1364 
  1523 
  1365 	open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
  1524 	open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
  1366 	while ($line=<TMP1>)
  1525 	while ($line=<TMP1>)
  1367 	{
  1526 	{
  1368 		track_source($line);
  1527 		track_source($line);
       
  1528 		$line =~ s-\\-\/-g;
       
  1529 
       
  1530 		if ($prependepocroot)
       
  1531 		{
       
  1532 			my $tempstring = $epocroot."epoc32\/";
       
  1533 			if(($line !~ /^\s*\#/) && ($line =~ /\/epoc32\//i) 
       
  1534 			 && ($line !~ /EPOCROOT##\/?epoc32\//i) && ($line !~ /$tempstring/i))
       
  1535 			{
       
  1536 				print "add EPOCROOT for line: $line\n" if ($opt_v);
       
  1537 		  	$line =~ s-\/epoc32-EPOCROOT##epoc32-ig;
       
  1538 			}
       
  1539 		}
  1369 		#
  1540 		#
  1370 		# Recognise keywords in lines that we process before substitution
  1541 		# Recognise keywords in lines that we process before substitution
  1371 		#
  1542 		#
  1372 		# # lineno "file" flagno
  1543 		# # lineno "file" flagno
  1373 		# DEFINE name replacement-with-0-spaces
  1544 		# DEFINE name replacement-with-0-spaces
  1690 		push @obydata, $line;
  1861 		push @obydata, $line;
  1691 	}
  1862 	}
  1692 
  1863 
  1693 	close TMP1;
  1864 	close TMP1;
  1694 	exit(1) if ($errors);
  1865 	exit(1) if ($errors);
  1695 	
       
  1696 	dump_obydata("tmp2.oby", "result of substitution phase") if ($opt_v);
  1866 	dump_obydata("tmp2.oby", "result of substitution phase") if ($opt_v);
  1697 }
  1867 }
  1698 
  1868 
  1699 sub check_romimage
  1869 sub check_romimage
  1700 {
  1870 {
  1723 }
  1893 }
  1724 
  1894 
  1725 sub dump_obydata
  1895 sub dump_obydata
  1726 {
  1896 {
  1727 	my ($dumpfile, $comment) = @_;
  1897 	my ($dumpfile, $comment) = @_;
       
  1898 	$dumpfile = $thisdir.$dumpfile;
  1728 	unlink($dumpfile);
  1899 	unlink($dumpfile);
  1729 	open DUMPFILE, ">$dumpfile" or die("* Can't create $dumpfile\n");
  1900 	open DUMPFILE, ">$dumpfile" or die("* Can't create $dumpfile\n");
  1730 	print "* Writing $dumpfile - $comment\n";
  1901 	print "* Writing $dumpfile - $comment\n";
  1731 	my $line;
  1902 	my $line;
  1732 	foreach $line (@obydata)
  1903 	foreach $line (@obydata)
  1741 	my ($line) = @_;
  1912 	my ($line) = @_;
  1742 	if ($line=~/^# (\d+) "(.*)"/)
  1913 	if ($line=~/^# (\d+) "(.*)"/)
  1743 	{
  1914 	{
  1744 		$sourceline=$1-1;
  1915 		$sourceline=$1-1;
  1745 		$sourcefile=$2;
  1916 		$sourcefile=$2;
  1746 		$sourcefile=~ s/\//\\/g;
       
  1747 		$sourcefile=~ s/\\\\/\\/g;
  1917 		$sourcefile=~ s/\\\\/\\/g;
       
  1918 		$sourcefile=~ s/\\/\//g;
  1748 		return;
  1919 		return;
  1749 	}
  1920 	}
  1750 	$sourceline++;
  1921 	$sourceline++;
  1751 }
  1922 }
  1752 
  1923 
  2033 				push @linesArray, $modifiedLine;
  2204 				push @linesArray, $modifiedLine;
  2034 				$line = "REM handled $line";
  2205 				$line = "REM handled $line";
  2035 			}
  2206 			}
  2036 			elsif($smrImageStartRegion && !$smrImageEndRegion)
  2207 			elsif($smrImageStartRegion && !$smrImageEndRegion)
  2037 			{
  2208 			{
  2038 				if($line =~ /^\s*IMAGENAME\s*=\s*(\S+)/i)
  2209 				if($line =~ /^(\s*IMAGENAME\s*=\s*)(\S+)/i)
  2039 				{
  2210 				{
  2040 					my $smrimagename = $1;
  2211 					my $front = $1;
       
  2212 					my $smrimagename = $2;
       
  2213 					if ($smrimagename !~ /^.:/ && $smrimagename !~ /^[\\\/]/)
       
  2214 					{
       
  2215 						$smrimagename = $thisdir.$smrimagename;
       
  2216 					}
  2041 					$smrimagename =~s/(\.img)//i;
  2217 					$smrimagename =~s/(\.img)//i;
  2042 					if(exists($smrNameInfo{$smrimagename}))
  2218 					if(exists($smrNameInfo{$smrimagename}))
  2043 					{
  2219 					{
  2044 						$smrNameInfo{$smrimagename}++;
  2220 						$smrNameInfo{$smrimagename}++;
  2045 					}
  2221 					}
  2046 					else
  2222 					else
  2047 					{
  2223 					{
  2048 						$smrNameInfo{$smrimagename} = 1;
  2224 						$smrNameInfo{$smrimagename} = 1;
  2049 					}
  2225 					}
  2050 					$line =~s/(\.img)//i;
  2226 					push @linesArray, "$front$smrimagename\n";
  2051 				}
  2227 				}else
  2052 				push @linesArray, $line;
  2228 				{
       
  2229 					push @linesArray, $line;
       
  2230 				}
  2053 				$line = "REM handled $line";
  2231 				$line = "REM handled $line";
  2054 			}
  2232 			}
  2055 		}
  2233 		}
  2056 		elsif (scalar @currentpartition)
  2234 		elsif (scalar @currentpartition)
  2057 		{
  2235 		{
  2065 					print ("Warning: SPI creation/placement flag not enabled. Ignoring SPI_POSITION\n" ) if ($opt_v);
  2243 					print ("Warning: SPI creation/placement flag not enabled. Ignoring SPI_POSITION\n" ) if ($opt_v);
  2066 				}
  2244 				}
  2067 			}
  2245 			}
  2068 			# a partition is specified
  2246 			# a partition is specified
  2069 			# push this line into the currently selected partition
  2247 			# push this line into the currently selected partition
  2070 			my $partition=@currentpartition[-1];
  2248 			my $partition=$currentpartition[-1];
  2071 			push @$partition, $modifiedLine;
  2249 			push @$partition, $modifiedLine;
  2072 			$line="REM handled $line";
  2250 			$line="REM handled $line";
  2073 		}
  2251 		}
  2074 		elsif ($line =~ /^\s*SPI_POSITION/i)
  2252 		elsif ($line =~ /^\s*SPI_POSITION/i)
  2075 		{
  2253 		{
  2216 		      $errors++ if ($strict);
  2394 		      $errors++ if ($strict);
  2217 		    }
  2395 		    }
  2218 
  2396 
  2219 		    if ($spidatahide)
  2397 		    if ($spidatahide)
  2220 		    {
  2398 		    {
  2221 			push @newobydata, "hide=$fileRomDir\\$pluginFileName\n";
  2399 			push @newobydata, "hide=$fileRomDir\/$pluginFileName\n";
  2222 		    }
  2400 		    }
  2223 		    else
  2401 		    else
  2224 		    {
  2402 		    {
  2225 		    	push @newobydata, "file=$emulatorDir\\$pluginFileName $fileRomDir\\$pluginFileName $paged_data\n";
  2403 		    	push @newobydata, "file=$emulatorDir\/$pluginFileName $fileRomDir\/$pluginFileName $paged_data\n";
  2226 		    }
  2404 		    }
  2227 
  2405 
  2228 		    if($createspi) {
  2406 		    if($createspi) {
  2229 		    	    if ($spidatahide)
  2407 		    	    if ($spidatahide)
  2230 			    {
  2408 			    {
  2231 			    	push @newobydata, "spidatahide=MULTI_LINGUIFY(RSC $dataz_\\$resourceDir\\$pluginResourceName $resourceDir\\$pluginResourceName) " . lc($plugintype) . "\.spi " . $plugintypes{$plugintype} . "\n";      
  2409 			    	push @newobydata, "spidatahide=MULTI_LINGUIFY(RSC $dataz_\/$resourceDir\/$pluginResourceName $resourceDir\/$pluginResourceName) " . lc($plugintype) . "\.spi " . $plugintypes{$plugintype} . "\n";      
  2232 			    }
  2410 			    }
  2233 			    else
  2411 			    else
  2234 			    {
  2412 			    {
  2235 			    	push @newobydata, "spidata=MULTI_LINGUIFY(RSC $dataz_\\$resourceDir\\$pluginResourceName $resourceDir\\$pluginResourceName) " . lc($plugintype) . "\.spi " . $plugintypes{$plugintype} . "\n";      
  2413 			    	push @newobydata, "spidata=MULTI_LINGUIFY(RSC $dataz_\/$resourceDir\/$pluginResourceName $resourceDir\/$pluginResourceName) " . lc($plugintype) . "\.spi " . $plugintypes{$plugintype} . "\n";      
  2236 			    }
  2414 			    }
  2237 		  	} else {
  2415 		  	} else {
  2238 		    	    if ($spidatahide)
  2416 		    	    if ($spidatahide)
  2239 			    {
  2417 			    {
  2240 			    	push @newobydata, "hide=MULTI_LINGUIFY(RSC $dataz_\\$resourceDir\\$pluginResourceName $resourceDir\\$pluginResourceName)\n";
  2418 			    	push @newobydata, "hide=MULTI_LINGUIFY(RSC $dataz_\/$resourceDir\/$pluginResourceName $resourceDir\/$pluginResourceName)\n";
  2241 			    }
  2419 			    }
  2242 			    else
  2420 			    else
  2243 			    {
  2421 			    {
  2244 			    	push @newobydata, "data=MULTI_LINGUIFY(RSC $dataz_\\$resourceDir\\$pluginResourceName $resourceDir\\$pluginResourceName)\n";
  2422 			    	push @newobydata, "data=MULTI_LINGUIFY(RSC $dataz_\/$resourceDir\/$pluginResourceName $resourceDir\/$pluginResourceName)\n";
  2245 			    }
  2423 			    }
  2246 			}
  2424 			}
  2247 				return 1; #successful match
  2425 				return 1; #successful match
  2248 	   }
  2426 	   }
  2249      }
  2427      }
  2273 			# ignore REM statements, to avoid processing "REM data=xxx yyy"
  2451 			# ignore REM statements, to avoid processing "REM data=xxx yyy"
  2274 		}
  2452 		}
  2275 		elsif ($line=~/^(.*?)\bMULTI_LINGUIFY\s*\(\s*(\S+)\s+(\S+)\s+(\S+)\s*\)(.*)$/i)
  2453 		elsif ($line=~/^(.*?)\bMULTI_LINGUIFY\s*\(\s*(\S+)\s+(\S+)\s+(\S+)\s*\)(.*)$/i)
  2276 		{
  2454 		{
  2277 			my $initialStuff=$1;
  2455 			my $initialStuff=$1;
       
  2456 			$initialStuff = lc ($initialStuff);# if ($enableLowercaseTransfer);
  2278 			my $defaultFileNameExtension=$2;
  2457 			my $defaultFileNameExtension=$2;
       
  2458 			$defaultFileNameExtension = lc ($defaultFileNameExtension);# if ($enableLowercaseTransfer);
  2279 			my $sourceFileNameWithoutExtension=$3;
  2459 			my $sourceFileNameWithoutExtension=$3;
       
  2460 			$sourceFileNameWithoutExtension = ($sourceFileNameWithoutExtension);# if ($enableLowercaseTransfer);
  2280 			my $targetFileNameWithoutExtension=$4;
  2461 			my $targetFileNameWithoutExtension=$4;
  2281 			my $finalStuff=$5;
  2462 			my $finalStuff=$5;
  2282 			my $spidataflag = 0;
  2463 			my $spidataflag = 0;
  2283 			my $spidatahide = 0;
  2464 			my $spidatahide = 0;
  2284 			my $datahide = 0;
  2465 			my $datahide = 0;
  2309 # ecom.spi should contain the .RSC files
  2490 # ecom.spi should contain the .RSC files
  2310 			if ($spidataflag)
  2491 			if ($spidataflag)
  2311 			{
  2492 			{
  2312 				my $sourceFileNameExtension = $defaultFileNameExtension;
  2493 				my $sourceFileNameExtension = $defaultFileNameExtension;
  2313 				my $targetFileNameExtension = $defaultFileNameExtension;
  2494 				my $targetFileNameExtension = $defaultFileNameExtension;
  2314 				if (-e "$sourceFileNameWithoutExtension.$sourceFileNameExtension")
  2495 				if (-e ("$sourceFileNameWithoutExtension.$sourceFileNameExtension"))
  2315 				{
  2496 				{
  2316 					if ($spidatahide)
  2497 					if ($spidatahide)
  2317 					{
  2498 					{
  2318 						push @newobydata, "$initialStuff$sourceFileNameWithoutExtension.$sourceFileNameExtension$finalStuff\n";
  2499 						push @newobydata, "$initialStuff$sourceFileNameWithoutExtension.$sourceFileNameExtension$finalStuff\n";
  2319 					}
  2500 					}
  2325 			}
  2506 			}
  2326 			my $useDefaultFileNameExtension=1;
  2507 			my $useDefaultFileNameExtension=1;
  2327 			foreach my $languageCode (keys %languageCodes) {
  2508 			foreach my $languageCode (keys %languageCodes) {
  2328 				my $sourceFileNameExtension=$defaultFileNameExtension;
  2509 				my $sourceFileNameExtension=$defaultFileNameExtension;
  2329 				$sourceFileNameExtension=~s/^(.*).{2}$/$1$languageCode/;
  2510 				$sourceFileNameExtension=~s/^(.*).{2}$/$1$languageCode/;
  2330 				if (! -e "$sourceFileNameWithoutExtension.$sourceFileNameExtension")
  2511 				if (! -e ("$sourceFileNameWithoutExtension.$sourceFileNameExtension"))
  2331 				{
  2512 				{
  2332 					if (!$spidataflag)
  2513 					if (!$spidataflag)
  2333 					{
  2514 					{
  2334 						next if (!$useDefaultFileNameExtension);
  2515 						next if (!$useDefaultFileNameExtension);
  2335 						next if (defined $defaultLanguageCode and !($languageCode eq $defaultLanguageCode));
  2516 						next if (defined $defaultLanguageCode and !($languageCode eq $defaultLanguageCode));
  2375 				{
  2556 				{
  2376 					push @newobydata, "$initialStuff$sourceFileNameWithoutExtension.$sourceFileNameExtension $targetFileNameWithoutExtension.$sourceFileNameExtension$modifiedfinalStuff\n";
  2557 					push @newobydata, "$initialStuff$sourceFileNameWithoutExtension.$sourceFileNameExtension $targetFileNameWithoutExtension.$sourceFileNameExtension$modifiedfinalStuff\n";
  2377 					if(!($sourceFileNameExtension eq $targetFileNameExtension))
  2558 					if(!($sourceFileNameExtension eq $targetFileNameExtension))
  2378 					{
  2559 					{
  2379 						push @newobydata, "alias $targetFileNameWithoutExtension.$sourceFileNameExtension $targetFileNameWithoutExtension.$targetFileNameExtension $modifiedfinalStuff\n";
  2560 						push @newobydata, "alias $targetFileNameWithoutExtension.$sourceFileNameExtension $targetFileNameWithoutExtension.$targetFileNameExtension $modifiedfinalStuff\n";
       
  2561 						$targetFileNameWithoutExtension =~ s-\\-\/-g;
  2380 						$multiLinguifyAlias{"$targetFileNameWithoutExtension.$sourceFileNameExtension"} = 1;
  2562 						$multiLinguifyAlias{"$targetFileNameWithoutExtension.$sourceFileNameExtension"} = 1;
  2381 					}
  2563 					}
  2382 				}
  2564 				}
  2383 			}
  2565 			}
  2384 			$line = reassert_sourceline();
  2566 			$line = reassert_sourceline();
  2453 			{
  2635 			{
  2454 				push @hidedatainspi, $hidedatafiles[$j]{data}; #push name of data file to be hidden onto array if correct romimage and spi type
  2636 				push @hidedatainspi, $hidedatafiles[$j]{data}; #push name of data file to be hidden onto array if correct romimage and spi type
  2455 			}
  2637 			}
  2456 		}
  2638 		}
  2457 		my @spiargs; #arguments passed to createSpi
  2639 		my @spiargs; #arguments passed to createSpi
  2458 		push @spiargs, ("-t$targetspi", "-d\\$thisdir", "-hide@hidedatainspi");
  2640 		push @spiargs, ("-t$targetspi", "-d$thisdir", "-hide@hidedatainspi");
  2459 		if($existingspi ne "") { push @spiargs, $existingspi; }
  2641 		if($existingspi ne "") { push @spiargs, $existingspi; }
  2460 		&spitool::createSpi(@spiargs, @dataforspi); # external call to 
  2642 		&spitool::createSpi(@spiargs, @dataforspi); # external call to 
  2461 	}
  2643 	}
  2462 }
  2644 }
  2463 
  2645 
  2619                                         next if (!$spipositionflag{$imageIdx});#This spi has already been entered into OBY.
  2801                                         next if (!$spipositionflag{$imageIdx});#This spi has already been entered into OBY.
  2620                                         my $spiIdx=0;
  2802                                         my $spiIdx=0;
  2621                                         while(defined $spiarray[$imageIdx][$spiIdx]) {
  2803                                         while(defined $spiarray[$imageIdx][$spiIdx]) {
  2622                                                 if($spiarray[$imageIdx][$spiIdx]{spifile} =~ /(.+)\.(.*)$/) {
  2804                                                 if($spiarray[$imageIdx][$spiIdx]{spifile} =~ /(.+)\.(.*)$/) {
  2623                                                         my $targetspi="$1-$imageIdx-$spiIdx\.$2";
  2805                                                         my $targetspi="$1-$imageIdx-$spiIdx\.$2";
  2624                                                         push @newobydata, "data=" . "\\$thisdir" . $targetspi . " \"" . $spiarray[$imageIdx][$spiIdx]{spi} . "\"\n";
  2806                                                         push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[$imageIdx][$spiIdx]{spi} . "\"\n";
  2625                                                 }
  2807                                                 }
  2626                                                 $spiIdx++;
  2808                                                 $spiIdx++;
  2627                                         }
  2809                                         }
  2628                                         if($spiIdx == 0){
  2810                                         if($spiIdx == 0){
  2629                                                 # If there is no plugin in this image, the SPI_POSITION statement is ignore.
  2811                                                 # If there is no plugin in this image, the SPI_POSITION statement is ignore.
  2646 					$flag=0;
  2828 					$flag=0;
  2647 					my $k=0;
  2829 					my $k=0;
  2648 					while(defined $spiarray[0][$k]) {
  2830 					while(defined $spiarray[0][$k]) {
  2649 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2831 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2650 							my $targetspi="$1-0-$k\.$2";
  2832 							my $targetspi="$1-0-$k\.$2";
  2651 							push @newobydata, "data=" . "\\$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi .  "\"\n";
  2833 							push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi .  "\"\n";
  2652 						}
  2834 						}
  2653 						$k++;
  2835 						$k++;
  2654 					}
  2836 					}
  2655 				}
  2837 				}
  2656 				my $j=0;
  2838 				my $j=0;
  2657 				push @newobydata, "\n" . $line . "\n";			
  2839 				push @newobydata, "\n" . $line . "\n";			
  2658 				while(defined $spiarray[$romimage][$j]) { #put in SPI files for current ROM_IMAGE
  2840 				while(defined $spiarray[$romimage][$j]) { #put in SPI files for current ROM_IMAGE
  2659 					if($spiarray[$romimage][$j]{spifile} =~ /(.+)\.(.*)$/) {
  2841 					if($spiarray[$romimage][$j]{spifile} =~ /(.+)\.(.*)$/) {
  2660 						my $targetspi="$1-$romimage-$j\.$2";
  2842 						my $targetspi="$1-$romimage-$j\.$2";
  2661 						push @newobydata, "data=" . "\\$thisdir" . $targetspi . " \"" . $spiarray[$romimage][$j]{spidir} . $targetspi .  "\"\n";
  2843 						push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[$romimage][$j]{spidir} . $targetspi .  "\"\n";
  2662 					}
  2844 					}
  2663 					$j++;
  2845 					$j++;
  2664 				}
  2846 				}
  2665 			} elsif($line =~ /^\s*extensionrom/i) {
  2847 			} elsif($line =~ /^\s*extensionrom/i) {
  2666 				if($flag) { #put in SPI files
  2848 				if($flag) { #put in SPI files
  2667 					my $k=0;
  2849 					my $k=0;
  2668 					while(defined $spiarray[0][$k]) {
  2850 					while(defined $spiarray[0][$k]) {
  2669 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2851 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2670 							my $targetspi="$1-0-$k\.$2";
  2852 							my $targetspi="$1-0-$k\.$2";
  2671 							push @newobydata, "data=" . "\\$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
  2853 							push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
  2672 						}
  2854 						}
  2673 						$k++;
  2855 						$k++;
  2674 					}
  2856 					}
  2675 					$flag = 0;
  2857 					$flag = 0;
  2676 				}
  2858 				}
  2683 		if($flag) { #put in SPI files for ROM_IMAGE[0] if it is the only ROM_IMAGE
  2865 		if($flag) { #put in SPI files for ROM_IMAGE[0] if it is the only ROM_IMAGE
  2684 			my $k=0;
  2866 			my $k=0;
  2685 			while(defined $spiarray[0][$k]) {
  2867 			while(defined $spiarray[0][$k]) {
  2686 				if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2868 				if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
  2687 					my $targetspi="$1-0-$k\.$2";
  2869 					my $targetspi="$1-0-$k\.$2";
  2688 					push @newobydata, "data=" . "\\$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
  2870 					push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
  2689 				}
  2871 				}
  2690 				$k++;
  2872 				$k++;
  2691 			}
  2873 			}
  2692 		}
  2874 		}
  2693 		@obydata=@newobydata;
  2875 		@obydata=@newobydata;
  2695 	dump_obydata("tmp6.oby", "result of SPI stage") if ($opt_v);
  2877 	dump_obydata("tmp6.oby", "result of SPI stage") if ($opt_v);
  2696 }
  2878 }
  2697 
  2879 
  2698 sub load_featuresutil
  2880 sub load_featuresutil
  2699 {
  2881 {
  2700 	&Load_ModuleL("featuresutil");
  2882 	&FlexLoad_ModuleL("featuresutil");
  2701 			
  2883 			
  2702 	# Parse the feature database XML file
  2884 	# Parse the feature database XML file
  2703 	if(!&featuresutil::parseXMLDatabase($featureXml, $featuremanager, $strict))
  2885 	if(!&featuresutil::parseXMLDatabase($featureXml, $featuremanager, $strict))
  2704 	{
  2886 	{
  2705 		$featureXml = undef;
  2887 		$featureXml = undef;
  2721 	}
  2903 	}
  2722 	# Set the name and Rom Image location of feature file.
  2904 	# Set the name and Rom Image location of feature file.
  2723 	if ($enforceFeatureManager) 
  2905 	if ($enforceFeatureManager) 
  2724 	{
  2906 	{
  2725 		# features data file location
  2907 		# features data file location
  2726 		$dir = "private\\10205054\\";
  2908 		$dir = "private\/10205054\/";
  2727 		$featurefilename = "features.dat";
  2909 		$featurefilename = "features.dat";
  2728 	}
  2910 	}
  2729 	else
  2911 	else
  2730 	{
  2912 	{
  2731 		# feature registry configuration file location
  2913 		# feature registry configuration file location
  2732 		$dir = "private\\102744CA\\"; 
  2914 		$dir = "private\/102744CA\/"; 
  2733 		$featurefilename = "featreg.cfg";
  2915 		$featurefilename = "featreg.cfg";
  2734 	}		
  2916 	}		
  2735 	if (defined ($featureXml)) 
  2917 	if (defined ($featureXml)) 
  2736 	{
  2918 	{
  2737 		my $featurefilecount=0;
  2919 		my $featurefilecount=0;
  2857 		for(my $i=0;$i<scalar @featurefilearray;$i++)
  3039 		for(my $i=0;$i<scalar @featurefilearray;$i++)
  2858 		{
  3040 		{
  2859 			my $j=0;
  3041 			my $j=0;
  2860 			while(defined $featurefilearray[$i][$j])
  3042 			while(defined $featurefilearray[$i][$j])
  2861 			{
  3043 			{
  2862 				my $targetfeaturefile = $featurefilearray[$i][$j]{cfgfile};
  3044 				my $targetfeaturefile = $thisdir.$featurefilearray[$i][$j]{cfgfile};
  2863 				if (!(&featuresutil::createFeatureFile($i,$j,$targetfeaturefile,\@featureslist,$featuremanager))) 
  3045 				if (!(&featuresutil::createFeatureFile($i,$j,$targetfeaturefile,\@featureslist,$featuremanager))) 
  2864 				{
  3046 				{
  2865 					$featurefilearray[$i][$j]{cfgfile}= undef;
  3047 					$featurefilearray[$i][$j]{cfgfile}= undef;
  2866 					exit(1) if($strict);					
  3048 					exit(1) if($strict);					
  2867 				}
  3049 				}
  2888 					while(defined $featurefilearray[0][$k])
  3070 					while(defined $featurefilearray[0][$k])
  2889 					{
  3071 					{
  2890 						my $targetfeaturefile=$featurefilearray[0][$k]{cfgfile};
  3072 						my $targetfeaturefile=$featurefilearray[0][$k]{cfgfile};
  2891 						if (defined $targetfeaturefile) 
  3073 						if (defined $targetfeaturefile) 
  2892 						{
  3074 						{
  2893 							push @newobydata, "data=" . "\\$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile .  "\"\n";							
  3075 							push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile .  "\"\n";							
  2894 						}
  3076 						}
  2895 						$k++;
  3077 						$k++;
  2896 					}
  3078 					}
  2897 				}
  3079 				}
  2898 				push @newobydata, "\n" . $line . "\n";			
  3080 				push @newobydata, "\n" . $line . "\n";			
  2911 					# list with mangled names. Hence, mangled name for feature files should not be put in ROM_IMAGE.
  3093 					# list with mangled names. Hence, mangled name for feature files should not be put in ROM_IMAGE.
  2912 					my $exattribute = "exattrib=U";
  3094 					my $exattribute = "exattrib=U";
  2913 
  3095 
  2914 					if (defined $targetfeaturefile)
  3096 					if (defined $targetfeaturefile)
  2915 					{
  3097 					{
  2916 						push @newobydata, "data=" . "\\$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[$romimage][$j]{cfgdir} . $destinationfeaturefile .  "\"\t\t" . $exattribute . "\n";
  3098 						push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[$romimage][$j]{cfgdir} . $destinationfeaturefile .  "\"\t\t" . $exattribute . "\n";
  2917 					}
  3099 					}
  2918 					$j++;
  3100 					$j++;
  2919 				}
  3101 				}
  2920 			}
  3102 			}
  2921 			elsif($line !~ /^\s*(FEATURE)\s*/i && $line !~ /^\s*(EXCLUDE_FEATURE)\s*/i)
  3103 			elsif($line !~ /^\s*(FEATURE)\s*/i && $line !~ /^\s*(EXCLUDE_FEATURE)\s*/i)
  2932 			while(defined $featurefilearray[0][$k])
  3114 			while(defined $featurefilearray[0][$k])
  2933 			{
  3115 			{
  2934 				my $targetfeaturefile = $featurefilearray[0][$k]{cfgfile};
  3116 				my $targetfeaturefile = $featurefilearray[0][$k]{cfgfile};
  2935 				if (defined $targetfeaturefile)
  3117 				if (defined $targetfeaturefile)
  2936 				{
  3118 				{
  2937 					push @newobydata, "data=" . "\\$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile . "\"\n";
  3119 					push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile . "\"\n";
  2938 				}
  3120 				}
  2939 				$k++;
  3121 				$k++;
  2940 			}
  3122 			}
  2941 		}
  3123 		}
  2942 		@obydata=@newobydata;
  3124 		@obydata=@newobydata;
  2974 	elsif ($enforceFeatureManager)
  3156 	elsif ($enforceFeatureManager)
  2975 	{
  3157 	{
  2976 	    print "Error: no feature data file or pre-built feature data file is provided!";
  3158 	    print "Error: no feature data file or pre-built feature data file is provided!";
  2977 	    exit(1);
  3159 	    exit(1);
  2978 	}
  3160 	}
       
  3161 	
       
  3162 	checkcase() if ($checkcase);
  2979 }
  3163 }
  2980 my ($fromABI,$toABI) = split / /,$abiDowngrade;
  3164 my ($fromABI,$toABI) = split / /,$abiDowngrade;
  2981 
  3165 
  2982 #----------------------------------------------------------------------------------
  3166 #----------------------------------------------------------------------------------
  2983 # Problem suppression phase
  3167 # Problem suppression phase
  2989 # correct source binary name using the VMAP file mechanism.
  3173 # correct source binary name using the VMAP file mechanism.
  2990 
  3174 
  2991 sub suppress_phase
  3175 sub suppress_phase
  2992 {
  3176 {
  2993 	undef @newobydata;
  3177 	undef @newobydata;
  2994 	Plat_Init($PerlLibPath);
  3178 
       
  3179 	init_plat($PerlEPOCPath);
  2995 
  3180 
  2996 	# use the "default" feature variant by default.
  3181 	# use the "default" feature variant by default.
  2997 	my $varname = $featureVariant{'VALID'} ? $featureVariant{'NAME'} : "default";
  3182 	my $varname = $featureVariant{'VALID'} ? $featureVariant{'NAME'} : "default";
  2998 
  3183 
  2999 	foreach $line (@obydata)
  3184 	foreach $line (@obydata)
  3000 	{
  3185 	{
  3001 		track_source($line);
  3186 		track_source($line);
  3002 		if ($line =~ /^\s*REM/i)
  3187 		if ($line =~ /^\s*REM/i || $line =~ /^\s*TIME\s*=\s*/i)
  3003 		{
  3188 		{
  3004 			# ignore REM statements, to avoid processing "REM data=xxx yyy"
  3189 			# ignore REM statements, to avoid processing "REM data=xxx yyy"
  3005 		}
  3190 		}
  3006 		# 
  3191 		# 
  3007 		# thing=some\file 
  3192 		# thing=some\file 
  3008 		#
  3193 		#
  3009 		elsif ($line =~ /(\S+)\s*=\s*"?(\S+\\\S+)"?/)
  3194 		elsif ($line =~ /(\S+)\s*=\s*"?(\S+[\/\\]\S+)"?/)
  3010 		{
  3195 		{
  3011 			my $what = $1;
  3196 			my $what = $1;
  3012 			my $filename = $2;
  3197 			my $filename = $2;
  3013 			if ($line =~ /(\S+)\s*=\s*"([^"]+)"/)
  3198 			if ($line =~ /(\S+)\s*=\s*"([^"]+)"/)
  3014 			{
  3199 			{
  3015 				$filename = $2;
  3200 				$filename = $2;
  3016 			}
  3201 			}
  3017 			my $normedFilename = &Genutl_NormaliseVersionedName($filename);
  3202 			my $normedFilename = &get_versionedname($filename);
  3018 
  3203 
  3019 			# find all the alternative file locations
  3204 			# find all the alternative file locations
  3020 			my @alternatives = fallback($normedFilename);
  3205 			my @alternatives = fallback($normedFilename);
  3021 			# test the original location first
  3206 			# test the original location first
  3022 			unshift(@alternatives, $normedFilename);
  3207 			unshift(@alternatives, $normedFilename);
  3025 			my $fileExists = 0;
  3210 			my $fileExists = 0;
  3026 			foreach my $altFile (@alternatives)
  3211 			foreach my $altFile (@alternatives)
  3027 			{
  3212 			{
  3028 			    my $tmpPath;
  3213 			    my $tmpPath;
  3029 			    my $tmpFile;
  3214 			    my $tmpFile;
  3030 				if($altFile =~ /"?(.*\\arm\w+_?\w+)\\([^"]+)/i)
  3215 				if($altFile =~ /"?(.*[\/\\]arm\w+_?\w+)[\/\\]([^"]+)/i)
  3031 				{
  3216 				{
  3032 					$tmpPath = $1;
  3217 					$tmpPath = $1;
  3033 					$tmpFile = $2;
  3218 					$tmpFile = $2;
  3034 				}
  3219 				}
  3035 				$tmpPath .= "\.$varname";
  3220 				$tmpPath .= "\.$varname";
  3036 				if (-d $tmpPath){
  3221 				
  3037 				  if (-e $tmpPath ."\\$tmpFile"){
  3222 				if (-e $tmpPath ."\/$tmpFile"){
  3038 				   $fileExists = $tmpPath . "\\$tmpFile";
  3223                   # SBSv2 variant binary exists
  3039 				  }
  3224 				  $fileExists = $tmpPath . "\/$tmpFile";
  3040 				  elsif (-e $altFile){
       
  3041 				   $fileExists = $altFile;
       
  3042 				  }
       
  3043 				}
  3225 				}
  3044 				else {
  3226 				else {
  3045 				  $fileExists = featurevariantmap->Find($altFile, $varname);
  3227                   # SBSv1 variant binary or invariant binary
       
  3228 				  $fileExists = get_BVbinname($altFile, $varname);
  3046 				}
  3229 				}
  3047 				last if $fileExists;
  3230 				last if $fileExists;
  3048 			}
  3231 			}
  3049 
  3232 			
  3050 			# edit the OBY line to use the actual file name which we found.
  3233 			# edit the OBY line to use the actual file name which we found.
  3051 			# (maybe) warn if an alternative to the original was selected.
  3234 			# (maybe) warn if an alternative to the original was selected.
  3052 			if ($fileExists)
  3235 			if ($fileExists)
  3053 			{
  3236 			{
  3054 				my $from = $filename;
  3237 				my $from = $filename;
  3055 				$from =~ s/\\/\\\\/g;		# need to escape backslashes
  3238 				$from =~ s/\\/\\\\/g;	
       
  3239 				$from =~ s/\//\\\//g;		# need to escape backslashes
  3056 				$from =~ s/(\[|\])/\\$1/g;	# need to escape square brackets for file names like "featreg.cfg[x-y]",etc.
  3240 				$from =~ s/(\[|\])/\\$1/g;	# need to escape square brackets for file names like "featreg.cfg[x-y]",etc.
  3057 				my $into = $fileExists;
  3241 				my $into = $fileExists;
  3058 
  3242 
  3059  				$line =~ s/$from/$into/;
  3243  				$line =~ s/$from/$into/i;
  3060 
  3244 
  3061  				if ($warnSelection && ($fileExists ne $normedFilename))
  3245  				if ($warnSelection && ($fileExists ne $normedFilename))
  3062 				{
  3246 				{
  3063 			    	print "replaced $filename with $fileExists\n";
  3247 			    	print "replaced $filename with $fileExists\n";
  3064 				}
  3248 				}
  3067 			{
  3251 			{
  3068    				# No suitable alternative was found, so comment out the line unless
  3252    				# No suitable alternative was found, so comment out the line unless
  3069 				# it is a manatory ROMBUILD keyword, in which case it is better
  3253 				# it is a manatory ROMBUILD keyword, in which case it is better
  3070 				# to let ROMBUILD report the missing file rather than report the
  3254 				# to let ROMBUILD report the missing file rather than report the
  3071 				# missing keyword.
  3255 				# missing keyword.
  3072    				if ($what !~ /^bootbinary|variant|primary|secondary|hide/i)
  3256    				if ($what !~ /^bootbinary|variant|primary|secondary|hide|dir|imagename/i)
  3073 				{
  3257 				{
  3074    					$line = "REM MISSING " . $line;
  3258    					$line = "REM MISSING " . $line;
  3075    					print_source_error("Missing file: '$filename' in statement '$what='");
  3259    					print_source_error("Missing file: '$filename' in statement '$what='");
  3076 					print "\ttried @alternatives\n"  if ($opt_v && @alternatives > 1);
  3260 					print "\ttried @alternatives\n"  if ($opt_v && @alternatives > 1);
  3077    					# treat as an error if the strict option is selected.
  3261    					# treat as an error if the strict option is selected.
  3091 
  3275 
  3092 				if($aSrcfile =~ /"?([^"]+)/){
  3276 				if($aSrcfile =~ /"?([^"]+)/){
  3093 				$aSrcfile = $1;
  3277 				$aSrcfile = $1;
  3094 				}
  3278 				}
  3095 
  3279 
  3096 				$aSrcfile = &Genutl_NormaliseVersionedName($aSrcfile);
  3280 				$aSrcfile = &get_versionedname($aSrcfile);
  3097 				if($dstFile =~ /"?(.*)\\([^"]+)/)
  3281 				if($dstFile =~ /"?(.*)[\/\\]([^"]+)/)
  3098 				{
  3282 				{
  3099 					$dstPath = $1;
  3283 					$dstPath = $1;
  3100 					$dstFile = $2;
  3284 					$dstFile = $2;
  3101 				}
  3285 				}
  3102 				my $dllMapKey = lc ($dstFile);
  3286 				my $dllMapKey = lc ($dstFile);
  3108 			}
  3292 			}
  3109 
  3293 
  3110 		}
  3294 		}
  3111 		push @newobydata, $line;
  3295 		push @newobydata, $line;
  3112 	}
  3296 	}
       
  3297 	
  3113 	@obydata = @newobydata;
  3298 	@obydata = @newobydata;
  3114 	dump_obydata("tmp7.oby", "result of problem-suppression phase") if ($opt_v);
  3299 	dump_obydata("tmp7.oby", "result of problem-suppression phase") if ($opt_v);
  3115 	die "ERROR: $errors missing file(s) detected\n" if ($strict && $errors );
  3300 	die "ERROR: $errors missing file(s) detected\n" if ($strict && $errors );
  3116 }
  3301 }
  3117 
  3302 
  3134  
  3319  
  3135  	# If BINARY_SELECTION_ORDER macro is specified in the oby file
  3320  	# If BINARY_SELECTION_ORDER macro is specified in the oby file
  3136  	if ($binarySelectionOrderFlag)
  3321  	if ($binarySelectionOrderFlag)
  3137    	{
  3322    	{
  3138  		# Search in the specified binary order 
  3323  		# Search in the specified binary order 
  3139  		if(!defined(@Global_PlatList))
  3324  		if(scalar(@Global_PlatList) == 0)
  3140 		{
  3325 		{
  3141 			@Global_PlatList = Plat_List();
  3326 			@Global_PlatList = get_platlist();
  3142 		}
  3327 		}
  3143  		my $b;
  3328  		my $b;
  3144  		my $e;
  3329  		my $e;
  3145  		foreach my $plat (@Global_PlatList) 
  3330  		foreach my $plat (@Global_PlatList) 
  3146   		{
  3331   		{
  3147   			if ($file =~ /^(.*)\\$plat\\(.*)$/i) 
  3332   			if ($file =~ /^(.*)[\/\\]$plat[\/\\](.*)$/i) 
  3148   			{
  3333   			{
  3149   				$b = $1;
  3334   				$b = $1;
  3150   				$e = $2;
  3335   				$e = $2;
  3151  				last;
  3336  				last;
  3152  			}
  3337  			}
  3153  		}
  3338  		}
  3154  		push(@alternatives, "$b\\$firstDIR\\$e");
  3339  		push(@alternatives, "$b\/$firstDIR\/$e");
  3155  			
  3340  			
  3156  		foreach my $toDIR (@binarySelectionOrder)
  3341  		foreach my $toDIR (@binarySelectionOrder)
  3157    		{
  3342    		{
  3158  			push(@alternatives, "$b\\$toDIR\\$e");
  3343  			push(@alternatives, "$b\/$toDIR\/$e");
  3159    		}
  3344    		}
  3160    	}
  3345    	}
  3161   	
  3346   	
  3162  	# If the file is not found in the specified ABIV2 platform, then select from ARMV5 directory.
  3347  	# If the file is not found in the specified ABIV2 platform, then select from armv5 directory.
  3163  	# This is necessary as some of the runtime DLLs will be present only in ARMV5 directory. 
  3348  	# This is necessary as some of the runtime DLLs will be present only in armv5 directory. 
  3164 	# Add the BPABI Platforms to be added
  3349 	# Add the BPABI Platforms to be added
  3165 	if(!defined(@Global_BPABIPlats))
  3350 	if(scalar(@Global_BPABIPlats) == 0)
  3166 	{
  3351 	{
  3167 		@Global_BPABIPlats = &BPABIutl_Plat_List;
  3352 		@Global_BPABIPlats = &get_bpabiplatlist;
  3168 	}
  3353 	}
  3169 
  3354 
  3170  	foreach my $BpabiPlat (@Global_BPABIPlats)
  3355  	foreach my $BpabiPlat (@Global_BPABIPlats)
  3171  	{
  3356  	{
  3172  		if ($fromABI eq "" && $file =~ /^(.*)\\$BpabiPlat\\(.*)$/)
  3357  		if ($fromABI eq "" && $file =~ /^(.*)[\/\\]$BpabiPlat[\/\\](.*)$/i)
  3173    		{
  3358    		{
  3174  			push(@alternatives, "$1\\armv5\\$2");
  3359  			push(@alternatives, "$1\/armv5\/$2");
  3175    		}
  3360    		}
  3176    	}
  3361    	}
  3177 
  3362 
  3178 	if ($customizedPlat && $fromABI eq "" && $file =~ /^(.*)\\$customizedPlat\\(.*)$/)
  3363 	if ($customizedPlat && $fromABI eq "" && $file =~ /^(.*)[\/\\]$customizedPlat[\/\\](.*)$/i)
  3179 	{
  3364 	{
  3180 		my $b = $1;
  3365 		my $b = $1;
  3181 		my $e = $2;
  3366 		my $e = $2;
  3182 		# if platform customization 
  3367 		# if platform customization 
  3183 		my $rootPlat = Plat_Root($customizedPlat);		
  3368 		my $rootPlat = get_platroot($customizedPlat);		
  3184         
  3369         
  3185    		#Check in ARMV7 folder for binaries in case GCCEV7 is used [DEF128457 ]
  3370    		#Check in ARMV7 folder for binaries in case GCCEV7 is used [DEF128457 ]
  3186    		if($customizedPlat == "GCCEV7")
  3371    		if($customizedPlat == "GCCEV7")
  3187    		{
  3372    		{
  3188    			push(@alternatives,"$b\\armv7\\$e");
  3373    			push(@alternatives,"$b\/armv7\/$e");
  3189    		}
  3374    		}
  3190 
  3375 
  3191 		if( grep /$rootPlat/, @Global_BPABIPlats)
  3376 		if( grep /$rootPlat/, @Global_BPABIPlats)
  3192 		{
  3377 		{
  3193  			push(@alternatives, "$b\\armv5\\$e");
  3378  			push(@alternatives, "$b\/armv5\/$e");
  3194 		}
  3379 		}
  3195 	}
  3380 	}
  3196 
  3381 
  3197 	if ($fromABI eq "" && $file =~ /^(.*)\\ARMV5_ABIV1\\(.*)$/i)
  3382 	if ($fromABI eq "" && $file =~ /^(.*)[\/\\]armv5_abiv1[\/\\](.*)$/i)
  3198    	{
  3383    	{
  3199  		push(@alternatives, "$1\\armv5\\$2");
  3384  		push(@alternatives, "$1\/armv5\/$2");
  3200    	}
  3385    	}
  3201   		
  3386   		
  3202    	if ($fromABI ne "" && $file =~ /^(.*)\\$fromABI\\(.*)$/)
  3387    	if ($fromABI ne "" && $file =~ /^(.*)[\/\\]$fromABI[\/\\](.*)$/)
  3203 	{
  3388 	{
  3204  		push(@alternatives, "$1\\$toABI\\$2");
  3389  		push(@alternatives, "$1\/$toABI\/$2");
  3205 	}
  3390 	}
  3206    
  3391    
  3207    	return @alternatives;
  3392    	return @alternatives;
  3208 }
  3393 }
  3209 
  3394 
  3213 {
  3398 {
  3214  	my $file = shift;
  3399  	my $file = shift;
  3215  	my @alternatives;
  3400  	my @alternatives;
  3216 	$customizedPlat = undef;	# global (used in feedback)
  3401 	$customizedPlat = undef;	# global (used in feedback)
  3217 
  3402 
  3218  	if(!defined(@Global_PlatList))
  3403  	if(scalar(@Global_PlatList) == 0)
  3219 	{
  3404 	{
  3220 		@Global_PlatList = Plat_List();
  3405 		@Global_PlatList = get_platlist();
  3221 	}
  3406 	}
  3222  	foreach my $plat (@Global_PlatList) 
  3407  	foreach my $plat (@Global_PlatList) 
  3223 	{
  3408 	{
  3224  		if ($file =~ /^(.*)\\$plat\\(.*)$/i) 
  3409  		if ($file =~ /^(.*)[\/\\]$plat[\/\\](.*)$/i) 
  3225 		{
  3410 		{
  3226  			my $b = $1;
  3411  			my $b = $1;
  3227  			my $e = $2;
  3412  			my $e = $2;
  3228  			my $root = Plat_Customizes($plat);
  3413  			my $root = get_platcustomizes($plat);
  3229  			if ($root) 
  3414  			if ($root) 
  3230 			{
  3415 			{
  3231 				# Preserve the plat that is customized
  3416 				# Preserve the plat that is customized
  3232 				$customizedPlat = $plat;
  3417 				$customizedPlat = $plat;
  3233 
  3418 
  3234 				# If a BSF platform customizes another BSF platform (i.e. a
  3419 				# If a BSF platform customizes another BSF platform (i.e. a
  3235 				# BSF hierarchy exists), look for the file starting from the
  3420 				# BSF hierarchy exists), look for the file starting from the
  3236 				# child BSF platform and working back to the root BSF platform
  3421 				# child BSF platform and working back to the root BSF platform
  3237 				while ($root)
  3422 				while ($root)
  3238 				{
  3423 				{
  3239 					push(@alternatives, "$b\\$root\\$e");
  3424 					push(@alternatives, "$b\/$root\/$e");
  3240 
  3425 
  3241 					# Temporary special case for ARMV5_ABIV1 and ARMV5_ABIV2
  3426 					# Temporary special case for armv5_abiv1 and armv5_abiv2
  3242 					if ($root =~ /^armv5_abiv[12]$/i)
  3427 					if ($root =~ /^armv5_abiv[12]$/i)
  3243 					{
  3428 					{
  3244 						push(@alternatives, "$b\\armv5\\$e");
  3429 						push(@alternatives, "$b\/armv5\/$e");
  3245  					}
  3430  					}
  3246 
  3431 
  3247 					$root = Plat_Customizes($root);
  3432 					$root = get_platcustomizes($root);
  3248 				}
  3433 				}
  3249  			}
  3434  			}
  3250 			return @alternatives;
  3435 			return @alternatives;
  3251  		}
  3436  		}
  3252  	}
  3437  	}
  3309 		# bitmap=source dest 
  3494 		# bitmap=source dest 
  3310 		#
  3495 		#
  3311 		if ($line =~ /^\s*bitmap=\s*"?(\S+)"?\s+"?(\S+)"?/i)
  3496 		if ($line =~ /^\s*bitmap=\s*"?(\S+)"?\s+"?(\S+)"?/i)
  3312 		{
  3497 		{
  3313 			my $mbm = $1;
  3498 			my $mbm = $1;
  3314 			my $dest = $2;
  3499 			my $dest = $2;            
  3315 			my $rom_mbm = "$1_rom";
  3500 			my $rom_mbm = "$1_rom";
  3316 			if ($is_xip eq 0)
  3501 			if ($is_xip eq 0)
  3317 			{
  3502 			{
  3318 				# non-XIP rom - just include the mbm file
  3503 				# non-XIP rom - just include the mbm file
  3319 				$line = "data=\"$mbm\"\t\"$dest\"\n";
  3504 				$line = "data=\"$mbm\"\t\"$dest\"\n";
  3320 			}
  3505 			}
  3321 			else
  3506 			else
  3322 			{	
  3507 			{	
  3323 		        if (! -e $rom_mbm || -M $rom_mbm >= -M $mbm)
  3508 		        if (! -e $rom_mbm || -M $rom_mbm >= -M $mbm)
  3324 			    {
  3509 			    {
  3325 				    system "bmconv /q /r $rom_mbm /m$mbm";
  3510 					is_existinpath("bmconv", romutl::DIE_NOT_FOUND);
  3326 				    my $bmconv_status = $?;
  3511                     
       
  3512                     my $rom_mbm_tmp = $rom_mbm;
       
  3513                     my $mbm_tmp = $mbm;
       
  3514                     if ($^O =~ /^MSWIN32$/i){
       
  3515                         $mbm_tmp =~ s-\/-\\-g;
       
  3516                         $rom_mbm_tmp =~ s-\/-\\-g;
       
  3517                     }
       
  3518                     
       
  3519 				    system "bmconv -q -r $rom_mbm_tmp -m$mbm_tmp";
       
  3520 	  		    my $bmconv_status = $?;
  3327 				    die "* bmconv failed\n" if ($bmconv_status != 0 || !-f $rom_mbm);
  3521 				    die "* bmconv failed\n" if ($bmconv_status != 0 || !-f $rom_mbm);
  3328 			    }
  3522 			    }
  3329 				$line = "data=\"$rom_mbm\"\t\"$dest\"\n";
  3523 				$line = "data=\"$rom_mbm\"\t\"$dest\"\n";
  3330 				push @tempfiles, $rom_mbm;
  3524 				push @tempfiles, $rom_mbm;
  3331 			}
  3525 			}
  3335 		#
  3529 		#
  3336 		# if file is a compressed ROM image file
  3530 		# if file is a compressed ROM image file
  3337 		elsif ($line =~ /^\s*compressed-bitmap=\s*"?(\S+)"?\s+"?(\S+)"?/i)
  3531 		elsif ($line =~ /^\s*compressed-bitmap=\s*"?(\S+)"?\s+"?(\S+)"?/i)
  3338 		{
  3532 		{
  3339 			my $mbm = $1;
  3533 			my $mbm = $1;
  3340 			my $dest = $2;
  3534 			my $dest = $2;            
  3341 			my $cmprssd_rom_mbm = "$1_rom";
  3535 			my $cmprssd_rom_mbm = "$1_rom";
  3342 			if ($is_xip eq 0)
  3536 			if ($is_xip eq 0)
  3343 			{
  3537 			{
  3344 				# non-XIP rom - just include the mbm file
  3538 				# non-XIP rom - just include the mbm file
  3345 				$line = "data=\"$mbm\"\t\"$dest\"\n";
  3539 				$line = "data=\"$mbm\"\t\"$dest\"\n";
  3346 			}
  3540 			}
  3347 			else
  3541 			else
  3348 			{
  3542 			{
  3349 				if (! -e $cmprssd_rom_mbm || -M $cmprssd_rom_mbm >= -M $mbm)
  3543 				if (! -e $cmprssd_rom_mbm || -M $cmprssd_rom_mbm >= -M $mbm)
  3350 			    {
  3544 			    {
  3351 				    system "bmconv /q /s $cmprssd_rom_mbm /m$mbm";
  3545 					is_existinpath("bmconv", romutl::DIE_NOT_FOUND);
       
  3546                     
       
  3547                     my $cmprssd_rom_mbm_tmp = $cmprssd_rom_mbm;
       
  3548                     my $mbm_tmp = $mbm;
       
  3549                     if ($^O =~ /^MSWIN32$/i){
       
  3550                         $mbm_tmp =~ s-\/-\\-g;
       
  3551                         $cmprssd_rom_mbm_tmp =~ s-\/-\\-g;
       
  3552                     }
       
  3553                     
       
  3554 				    system "bmconv -q -s $cmprssd_rom_mbm_tmp -m$mbm_tmp";
  3352 				    my $bmconv_status = $?;
  3555 				    my $bmconv_status = $?;
  3353 				    die "* bmconv failed\n" if ($bmconv_status != 0 || !-f $cmprssd_rom_mbm);
  3556 				    die "* bmconv failed\n" if ($bmconv_status != 0 || !-f $cmprssd_rom_mbm);
  3354 				}
  3557 				}
  3355 				$line = "data=\"$cmprssd_rom_mbm\"\t\"$dest\"\n";
  3558 				$line = "data=\"$cmprssd_rom_mbm\"\t\"$dest\"\n";
  3356 				push @tempfiles, $cmprssd_rom_mbm;			    
  3559 				push @tempfiles, $cmprssd_rom_mbm;			    
  3377 	# data=\epoc32\wins\C\System\Alarms\churchbell.snd    "System\Alarms\Church bell"
  3580 	# data=\epoc32\wins\C\System\Alarms\churchbell.snd    "System\Alarms\Church bell"
  3378 	# file[0x07060001]=\epoc32\release\MAWD\urel\cAkyb1.dll          System\Libs\EKeyb.dll
  3581 	# file[0x07060001]=\epoc32\release\MAWD\urel\cAkyb1.dll          System\Libs\EKeyb.dll
  3379 	# file=\epoc32\release\marm\urel\eikcore.dll 			System\Libs\Eikcore.dll
  3582 	# file=\epoc32\release\marm\urel\eikcore.dll 			System\Libs\Eikcore.dll
  3380 	# alias \System\Bin\DRTRVCT2_2.dll 			\System\Bin\DRTRVCT2_1.dll
  3583 	# alias \System\Bin\DRTRVCT2_2.dll 			\System\Bin\DRTRVCT2_1.dll
  3381 	#
  3584 	#
       
  3585 	$line =~ s-\\-\/-g;
  3382 	if ($line =~ /^\s*TIME\s*=\s*/i)
  3586 	if ($line =~ /^\s*TIME\s*=\s*/i)
  3383 	{
  3587 	{
  3384 		return $line;
  3588 		return $line;
  3385 	}
  3589 	}
  3386   	elsif($line =~ /^\s*volume\s*=.*/i)
  3590   	elsif($line =~ /^\s*volume\s*=.*/i)
  3389   	}
  3593   	}
  3390 	elsif($line =~ /^\s*kerneltrace\s*=.*/i)
  3594 	elsif($line =~ /^\s*kerneltrace\s*=.*/i)
  3391 	{
  3595 	{
  3392 		return $line;
  3596 		return $line;
  3393 	}
  3597 	}
  3394 	if ($line =~ /^\s*(\S+)\s*=\s*(\S+)\s+"\\?(.*)"(.*)$/)
  3598 	elsif($line =~ /^\s*dir\s*=.*/i)
       
  3599 	{
       
  3600 		return $line;
       
  3601 	}
       
  3602 	elsif($line =~ /^\s*bootbinary\s*=(.*)/i)
       
  3603 	{
       
  3604 	}
       
  3605 	if ($line =~ /^\s*(\S+)\s*=\s*(\S+)\s+"\/?(.*)"(.*)$/)
  3395 	{
  3606 	{
  3396 		$type = $1;
  3607 		$type = $1;
  3397 		$variant = "";
  3608 		$variant = "";
  3398 		$pcfile = $2;
  3609 		$pcfile = $2;
  3399 		$romfile = $3;
  3610 		$romfile = $3;
  3400 		$tail = $4;
  3611 		$tail = $4;
  3401 	}
  3612 	}
  3402 	elsif ($line =~ /^\s*(\S+)(\[\S+\])\s*=\s*(\S+)\s+\\?(\S+)(.*)$/)
  3613 	elsif ($line =~ /^\s*(\S+)(\[\S+\])\s*=\s*(\S+)\s+\/?(\S+)(.*)$/)
  3403 	{
  3614 	{
  3404 		$type = $1;
  3615 		$type = $1;
  3405 		$variant = $2;
  3616 		$variant = $2;
  3406 		$pcfile = $3;
  3617 		$pcfile = $3;
  3407 		$romfile = $4;
  3618 		$romfile = $4;
  3408 		$tail = $5;
  3619 		$tail = $5;
  3409 	}
  3620 	}
  3410 	elsif ($line =~ /(\S+)\s*=\s*"([^"]+)"\s+"\\?(.*)"(.*)$/)
  3621 	elsif ($line =~ /(\S+)\s*=\s*"([^"]+)"\s+"\/?(.*)"(.*)$/ 
       
  3622 			|| $line =~ /(\S+)\s*=\s*"([^"]+)"\s+\/?(\S+)(.*)$/)
  3411 	{
  3623 	{
  3412 		if ($line !~ /^REM MISSING/i)
  3624 		if ($line !~ /^REM MISSING/i)
  3413 		{
  3625 		{
  3414 			$type = $1;
  3626 			$type = $1;
  3415 			$variant = "";
  3627 			$variant = "";
  3419 		}
  3631 		}
  3420 		else{
  3632 		else{
  3421 			return $line;
  3633 			return $line;
  3422 		}
  3634 		}
  3423 	}
  3635 	}
  3424 	elsif ($line =~ /^\s*(\S+)\s*=\s*(\S+)\s+\\?(\S+)(.*)$/)
  3636 	elsif ($line =~ /^\s*(\S+)\s*=\s*(\S+)\s+\/?(\S+)(.*)$/)
  3425 	{
  3637 	{
  3426 		$type = $1;
  3638 		$type = $1;
  3427 		$variant = "";
  3639 		$variant = "";
  3428 		$pcfile = $2;
  3640 		$pcfile = $2;
  3429 		$romfile = $3;
  3641 		$romfile = $3;
  3449 		if ($enforceSysBin)
  3661 		if ($enforceSysBin)
  3450 		{
  3662 		{
  3451 			if ($DllDataMap{$patchdlldatamap_key}->{dstpath} !~ /^sys\\bin/i 
  3663 			if ($DllDataMap{$patchdlldatamap_key}->{dstpath} !~ /^sys\\bin/i 
  3452 			 && $DllDataMap{$patchdlldatamap_key}->{dstpath} !~ /^sys\/bin/i)
  3664 			 && $DllDataMap{$patchdlldatamap_key}->{dstpath} !~ /^sys\/bin/i)
  3453 			{
  3665 			{
  3454 				$DllDataMap{$patchdlldatamap_key}->{dstpath} = "sys\\bin";
  3666 				$DllDataMap{$patchdlldatamap_key}->{dstpath} = "sys\/bin";
  3455 			}
  3667 			}
  3456 		}
  3668 		}
  3457 		
  3669 		
  3458 		my $dllfile = $DllDataMap{$patchdlldatamap_key}->{dstpath} . "\\". $romfilename;
  3670 		my $dllfile = $DllDataMap{$patchdlldatamap_key}->{dstpath} . "\/". $romfilename;
  3459 		
  3671 		
  3460 		$line = "$1  ";
  3672 		$line = "$1  ";
  3461 		$line .= "$dllfile ";
  3673 		$line .= "$dllfile ";
  3462  
  3674  
  3463 		# Convert value into decimal (used to be done in AddDllDataInfo, but that limited us to
  3675 		# Convert value into decimal (used to be done in AddDllDataInfo, but that limited us to
  3554 		
  3766 		
  3555 		$line .= "$scalarSize $value\n";
  3767 		$line .= "$scalarSize $value\n";
  3556 
  3768 
  3557 		return $line;
  3769 		return $line;
  3558 	}
  3770 	}
  3559 	elsif ($line =~ /^\s*(\S+)\s*(\S+)\s+\\?(\S+)(.*)$/)
  3771 	elsif ($line =~ /^\s*(\S+)\s*(\S+)\s+\/?(\S+)(.*)$/)
  3560 	{
  3772 	{
  3561 		$type = $1;
  3773 		$type = $1;
  3562 		$variant = "";
  3774 		$variant = "";
  3563 		$pcfile = $2;
  3775 		$pcfile = $2;
  3564 		$romfile = $3;
  3776 		$romfile = $3;
  3586  	# Buildrom should generate warning when destination path provided for a file 
  3798  	# Buildrom should generate warning when destination path provided for a file 
  3587  	# is not a standard path(as per platsec) and "PlatSecEnforceSysBin" is turned off. 
  3799  	# is not a standard path(as per platsec) and "PlatSecEnforceSysBin" is turned off. 
  3588  	my $warnFlag = 1;
  3800  	my $warnFlag = 1;
  3589 	my $mustBeSysBin = $enforceSysBin;
  3801 	my $mustBeSysBin = $enforceSysBin;
  3590 	if ($type =~ /^(data|compress|nocompress)$/i
  3802 	if ($type =~ /^(data|compress|nocompress)$/i
  3591 		&& $romfile !~ /^system\\(bin|libs|programs)\\/i)
  3803 		&& $romfile !~ /^system\/(bin|libs|programs)\//i)
  3592 	{
  3804 	{
  3593 		$mustBeSysBin = 0;
  3805 		$mustBeSysBin = 0;
  3594  		$warnFlag = 0;
  3806  		$warnFlag = 0;
  3595 	}
  3807 	}
  3596 	
  3808 	
  3603 			# for multilinguify 'alias'es (generally resource files) 'MustBeSysBin' should not be enforced.
  3815 			# for multilinguify 'alias'es (generally resource files) 'MustBeSysBin' should not be enforced.
  3604 			if(defined($multiLinguifyAlias{$pcfile})) {
  3816 			if(defined($multiLinguifyAlias{$pcfile})) {
  3605 				return $line;  
  3817 				return $line;  
  3606 			}
  3818 			}
  3607 
  3819 
  3608 			my $filename = "\\$romfile";	# in case no path is specified
  3820 			my $filename = "\/$romfile";	# in case no path is specified
  3609 			$filename = substr $filename, rindex($filename, "\\");
  3821 			$filename = substr $filename, rindex($filename, "\/");
  3610 			$romfile = "sys\\bin".$filename;
  3822 			$romfile = "sys\/bin".$filename;
  3611 
  3823 
  3612 			if ($pcfile !~ /^sys\\bin\\/i
  3824 			if ($pcfile !~ /^sys\\bin\\/i
  3613 			    && $pcfile !~ /^sys\/bin/i)
  3825 			    && $pcfile !~ /^sys\/bin/i)
  3614 			{
  3826 			{
  3615 				my $pcfilename = "\\$pcfile";	# in case no path is specified
  3827 				my $pcfilename = "\/$pcfile";	# in case no path is specified
  3616 				$pcfilename = substr $pcfilename, rindex($pcfilename, "\\");
  3828 				$pcfilename = substr $pcfilename, rindex($pcfilename, "\/");
  3617 				$pcfile = "sys\\bin".$pcfilename;
  3829 				$pcfile = "sys\/bin".$pcfilename;
  3618 			}
  3830 			}
  3619 			return "$type$variant $pcfile \t$romfile$tail\n";
  3831 			return "$type$variant $pcfile \t$romfile$tail\n";
  3620 		}
  3832 		}
  3621 
  3833 
  3622 		if ($romfile !~ /^sys\\bin\\/i
  3834 		if ($romfile !~ /^sys\\bin\\/i
  3623 		    && $romfile !~ /^sys\/bin/i)
  3835 		    && $romfile !~ /^sys\/bin/i)
  3624 		{
  3836 		{
  3625 			my $filename = "\\$romfile";	# in case no path is specified
  3837 			my $filename = "\/$romfile";	# in case no path is specified
  3626 			$filename = substr $filename, rindex($filename, "\\");
  3838 			$filename = substr $filename, rindex($filename, "\/");
  3627 			$romfile = "sys\\bin".$filename;
  3839 			$romfile = "sys\/bin".$filename;
  3628 		}
  3840 		}
  3629 	}
  3841 	}
  3630 	else
  3842 	else
  3631 	{
  3843 	{
  3632  		if ($warnFlag && $romfile !~ /^sys\\bin\\/i && $romfile !~ /^sys\/bin/i)
  3844  		if ($warnFlag && $romfile !~ /^sys\\bin\\/i && $romfile !~ /^sys\/bin/i)
  3694 	my $skippingBlanks=0;
  3906 	my $skippingBlanks=0;
  3695 	undef @newobydata;
  3907 	undef @newobydata;
  3696 	
  3908 	
  3697     if($opt_v)
  3909     if($opt_v)
  3698     {
  3910     {
  3699 	  my $logWin = "logwin.oby";
  3911 	  my $logWin = $thisdir."logwin.oby";
  3700 	  my $logLinux = "loglinux.oby";
  3912 	  my $logLinux = $thisdir."loglinux.oby";
  3701 	  unlink($logWin);
  3913 	  unlink($logWin);
  3702 	  unlink($logLinux);
  3914 	  unlink($logLinux);
  3703 	  open LOGWIN, ">$logWin" or die("* Can't create $logWin\n");
  3915 	  open LOGWIN, ">$logWin" or die("* Can't create $logWin\n");
  3704 	  open LOGLINUX, ">$logLinux" or die("* Can't create $logLinux\n");
  3916 	  open LOGLINUX, ">$logLinux" or die("* Can't create $logLinux\n");
  3705     }	
  3917     }	
  3731 			$skippingBlanks=0;
  3943 			$skippingBlanks=0;
  3732 		}
  3944 		}
  3733 		#
  3945 		#
  3734 		# Track ROMNAME, allowing overrides
  3946 		# Track ROMNAME, allowing overrides
  3735 		#
  3947 		#
  3736 		if ($line=~/romname\s*=\s*"?(\S+)\.(\S+)"?\s*/i)
  3948 		if ($line=~/romname\s*[=\s]\s*"?(\S+)\.(\S+)"?\s*/i)
  3737 		{
  3949 		{
  3738 			if ($romname ne "" && $opt_o eq "")
  3950 			if ($romname ne "" && $opt_o eq "")
  3739 			{
  3951 			{
  3740 				print_source_error("Overrides previous ROM name $romname");
  3952 				print_source_error("Overrides previous ROM name $romname");
  3741 			}
  3953 			}
  3742 			$rombasename = $1;
  3954 			$rombasename = $1;
  3743 			$romname = "$1.$2";
  3955 			$romname = "$1.$2";
       
  3956 			if ($opt_workdir)
       
  3957 			{
       
  3958 				$rombasename = $thisdir.$rombasename;
       
  3959 				$romname = $thisdir.$romname;
       
  3960 			}
  3744 			next;
  3961 			next;
  3745 		}
  3962 		}
  3746 		#
  3963 		#
  3747 		# ROM directory listing
  3964 		# ROM directory listing
  3748 		#
  3965 		#
  3750 	    if( ($newline !~ /^\s*TIME\s*=\s*/i)
  3967 	    if( ($newline !~ /^\s*TIME\s*=\s*/i)
  3751   	      &&($newline !~ /^\s*volume\s*=.*/i)
  3968   	      &&($newline !~ /^\s*volume\s*=.*/i)
  3752 	      &&($newline !~ /^\s*kerneltrace\s*=.*/i))
  3969 	      &&($newline !~ /^\s*kerneltrace\s*=.*/i))
  3753 	    {
  3970 	    {
  3754 	        my $tmpline = $newline;
  3971 	        my $tmpline = $newline;
  3755 	        if($^O =~ /^MSWin32$/i)
  3972 	        if(&is_windows)
  3756 	        {
  3973 	        {
  3757 	          $newline =~ s-\/-\\-go;
  3974 	          $newline =~ s-\/-\\-go;
  3758 	          if($opt_v)
  3975 	          if($opt_v)
  3759 	          {
  3976 	          {
  3760                 print LOGWIN $newline;
  3977                 print LOGWIN $newline;
  3780 	  close LOGWIN;
  3997 	  close LOGWIN;
  3781 	  close LOGLINUX;
  3998 	  close LOGLINUX;
  3782 	}
  3999 	}
  3783 	
  4000 	
  3784 	exit(1) if($errors && $strict);
  4001 	exit(1) if($errors && $strict);
  3785 
       
  3786 	# Handle ROMNAME and possible -o override
  4002 	# Handle ROMNAME and possible -o override
  3787 	if ($opt_o ne "")
  4003 	if ($opt_o ne "")
  3788 	{
  4004 	{
       
  4005 		if ($opt_workdir && $opt_o !~ /^[\\\/]/ && $opt_o !~ /^.:/)
       
  4006 		{
       
  4007 			$opt_o = $thisdir.$opt_o;
       
  4008 		}
       
  4009 		if (&is_windows)
       
  4010 		{
       
  4011 			$opt_o =~ s-\/-\\-g;
       
  4012 		}else
       
  4013 		{
       
  4014 			$opt_o =~ s-\\-\/-g;
       
  4015 		}
  3789 		$romname=$opt_o;
  4016 		$romname=$opt_o;
  3790 		if ($opt_o=~/(\S+)\.(\S+)/)
  4017 		if ($opt_o=~/(\S+)\.(\S+)/)
  3791 		{
  4018 		{
  3792 			$rombasename=$1;
  4019 			$rombasename=$1;
  3793 		}
  4020 		}
  3963 		# write data drive oby file.
  4190 		# write data drive oby file.
  3964 		elsif ($line =~ /^\s*REM DATA_IMAGE\[(\d+)\]\s+(.*)$/i)
  4191 		elsif ($line =~ /^\s*REM DATA_IMAGE\[(\d+)\]\s+(.*)$/i)
  3965 		{
  4192 		{
  3966 				my $dataimageidx=$1;
  4193 				my $dataimageidx=$1;
  3967 				close DUMPFILE;
  4194 				close DUMPFILE;
       
  4195 				my $name = $datadriveimage[$dataimageidx]{name};
       
  4196 				if ($name !~ /^.:/ && $name !~ /^[\\\/]/)
       
  4197 				{
       
  4198 					$datadriveimage[$dataimageidx]{name} = $thisdir.$name;
       
  4199 				}
  3968 				$dumpfile="$datadriveimage[$dataimageidx]{name}";
  4200 				$dumpfile="$datadriveimage[$dataimageidx]{name}";
  3969 				$datadriveimage[$dataimageidx]{obeyfile}=$dumpfile;
  4201 				$datadriveimage[$dataimageidx]{obeyfile}=$dumpfile;
  3970 				$dumpfile .= ".oby";
  4202 				$dumpfile .= ".oby";
  3971 				open DUMPFILE, ">$dumpfile" or die("* Can't create $dumpfile\n");		
  4203 				open DUMPFILE, ">$dumpfile" or die("* Can't create $dumpfile\n");		
  3972 				print "* Writing $dumpfile - intermediate OBY file\n";
  4204 				print "* Writing $dumpfile - intermediate OBY file\n";
  4006 	
  4238 	
  4007 		my $file;
  4239 		my $file;
  4008 		my $prevdir = "";
  4240 		my $prevdir = "";
  4009 		foreach $file (sort {uc($a) cmp uc($b)} keys %romfiles)
  4241 		foreach $file (sort {uc($a) cmp uc($b)} keys %romfiles)
  4010 		{
  4242 		{
  4011 			my $dir = substr $file,0,rindex($file, "\\");
  4243 			my $dir = substr $file,0,rindex($file, "\/");
  4012 			if (uc $dir ne uc $prevdir)
  4244 			if (uc $dir ne uc $prevdir)
  4013 			{
  4245 			{
  4014 				$prevdir = $dir;
  4246 				$prevdir = $dir;
  4015 				print DIRFILE "\n";
  4247 				print DIRFILE "\n";
  4016 			}
  4248 			}
  4045 #
  4277 #
  4046 
  4278 
  4047 sub run_rombuilder
  4279 sub run_rombuilder
  4048 {
  4280 {
  4049 	my ($command, $obeyfile, $logfile) = @_;
  4281 	my ($command, $obeyfile, $logfile) = @_;
  4050 	$command .= " $obeyfile.oby";
  4282 	$command .= " -logfile=$logfile $obeyfile.oby";
  4051 	#CR1258 test cases are depending on the following output.
  4283 	#CR1258 test cases are depending on the following output.
  4052 	print "* Executing $command\n" if ($opt_v);
  4284 	print "* Executing $command\n" if ($opt_v);
  4053 
  4285 
  4054 	open DATA, "$command 2>&1 |"   or die "Couldn't execute command: $command";
  4286 	open DATA, "$command 2>&1 |"   or die "Couldn't execute command: $command";
  4055 	while ( defined( my $line = <DATA> ) ) {
  4287 	while ( defined( my $line = <DATA> ) ) {
  4097 	}
  4329 	}
  4098 	else
  4330 	else
  4099 	{
  4331 	{
  4100 		$rom_compression_type = "";
  4332 		$rom_compression_type = "";
  4101 	}
  4333 	}
       
  4334 
       
  4335 	#Compose command line options for Cache.
       
  4336 	my $cache_options;
       
  4337 	if($opt_cache == 1)
       
  4338 	{
       
  4339 		$cache_options = "-cache ";
       
  4340 	}
       
  4341 	if($opt_nocache == 1)
       
  4342 	{
       
  4343 		$cache_options .= "-nocache ";
       
  4344 	}
       
  4345 	if($opt_cleancache == 1)
       
  4346 	{
       
  4347 		$cache_options .= "-cleancache";
       
  4348 	}
  4102 	
  4349 	
  4103 	my $rombuild;
  4350 	my $rombuild;
  4104 	if(!$geninc)
  4351 	if(!$geninc)
  4105 	{
  4352 	{
  4106 		$rombuild = "rombuild -slog $rom_compression_type $logLevel $lowMem $opt_fastcompress $opt_jobs";
  4353 		$rombuild = "rombuild -slog $rom_compression_type $logLevel $lowMem $opt_jobs";
  4107 	}
  4354 	}
  4108 	else
  4355 	else
  4109 	{
  4356 	{
  4110 		$rombuild = "rombuild -slog $rom_compression_type -geninc $logLevel $lowMem $opt_fastcompress $opt_jobs";
  4357 		$rombuild = "rombuild -slog $rom_compression_type -geninc $logLevel $lowMem $opt_jobs";
  4111 	}
  4358 	}
  4112 	if($gendep)
  4359 	if($gendep)
  4113 	{
  4360 	{
  4114 		$rombuild .= " -gendep";
  4361 		$rombuild .= " -gendep";
  4115 	}
  4362 	}
  4116 	my $rofsbuild = "rofsbuild -slog $logLevel $lowMem $opt_fastcompress $opt_jobs";
  4363 	$rombuild .= " -k" if($opt_k);
       
  4364 	my $rofsbuild = "rofsbuild -slog $logLevel $lowMem $opt_jobs $cache_options";
  4117 	foreach my $arg (keys %rombuildOptions)
  4365 	foreach my $arg (keys %rombuildOptions)
  4118 	{
  4366 	{
  4119 		$rombuild .= " $arg";
  4367 		$rombuild .= " $arg";
  4120 	}
  4368 	}
  4121 	        
  4369 	$rofsbuild .= " -k" if($opt_k);        
  4122 	for (my $romidx=0; $romidx<8; $romidx++)
  4370 	for (my $romidx=0; $romidx<8; $romidx++)
  4123 	{
  4371 	{
  4124 		my $obeyfile=$romimage[$romidx]{obeyfile};
  4372 		my $obeyfile=$romimage[$romidx]{obeyfile};
  4125 		my $xip=$romimage[$romidx]{xip};
  4373 		my $xip=$romimage[$romidx]{xip};
  4126 		my $compress=$romimage[$romidx]{compress};
  4374 		my $compress=$romimage[$romidx]{compress};
  4148 				$compress =~m/\s-(compression)(method)\s(none|inflate|bytepair)/;
  4396 				$compress =~m/\s-(compression)(method)\s(none|inflate|bytepair)/;
  4149 				print "* ".$1." ".$2.": ".$3;
  4397 				print "* ".$1." ".$2.": ".$3;
  4150 			}                        
  4398 			}                        
  4151 			if ($xip)
  4399 			if ($xip)
  4152 			{
  4400 			{
  4153 				run_rombuilder($rombuild.$compress, $obeyfile, "ROMBUILD.LOG");
  4401 				is_existinpath("rombuild", romutl::DIE_NOT_FOUND);
  4154 				if(!$nosymbols){
  4402 				$rombuild .= " -symbols" unless($nosymbols) ;
  4155 				print "* Writing $obeyfile.symbol - ROM symbol file\n";
  4403 				run_rombuilder($rombuild.$compress, $obeyfile, $thisdir."ROMBUILD.LOG");
  4156 				print "* Executing maksym $obeyfile.log $obeyfile.symbol\n" if ($opt_v);
       
  4157 				system("maksym $obeyfile.log $obeyfile.symbol >maksym.out");
       
  4158 				exit(1) if (!-e "$obeyfile.symbol");
       
  4159 				}
       
  4160 			}
  4404 			}
  4161 			else
  4405 			else
  4162 			{
  4406 			{
  4163 				# efficient_rom_paging.pm can move everything to core rom.
  4407 				# efficient_rom_paging.pm can move everything to core rom.
  4164 				# If that is the case, don't run rofsbuild at all to avoid errors.
  4408 				# If that is the case, don't run rofsbuild at all to avoid errors.
  4165 				use constant TRUE => 1;
  4409 			#	use constant TRUE => 1;
  4166 				use constant FALSE => 0;
  4410 			#	use constant FALSE => 0;
  4167 				my $run_rofs_build = FALSE;
  4411 				my $run_rofs_build = 0;
  4168 				
  4412 				
  4169 				open OBYFILE, "$obeyfile.oby";
  4413 				open OBYFILE, "$obeyfile.oby";
  4170 				for (<OBYFILE>)
  4414 				for (<OBYFILE>)
  4171 				{
  4415 				{
  4172 					if (is_oby_statement($_))
  4416 					if (is_oby_statement($_))
  4173 					{
  4417 					{
  4174 						$run_rofs_build = TRUE;
  4418 						$run_rofs_build = 1;
  4175 						last;
  4419 						last;
  4176 					}
  4420 					}
  4177 				}
  4421 				}
  4178 				close OBYFILE;
  4422 				close OBYFILE;
  4179 				if ($run_rofs_build)
  4423 				if ($run_rofs_build)
  4180 				{
  4424 				{
  4181 					run_rombuilder($rofsbuild.$compress, $obeyfile, "ROFSBUILD.LOG");
  4425 					is_existinpath("rofsbuild", romutl::DIE_NOT_FOUND);
  4182 					if(!$nosymbols){
  4426 					if(!$nosymbols)
  4183 					print "* Writing $obeyfile.symbol - ROFS symbol file\n";
  4427 					{
  4184 					print "* Executing maksymrofs $obeyfile.log $obeyfile.symbol\n" if ($opt_v);
  4428 						$rofsbuild .= " -symbols";
  4185 					system("maksymrofs $obeyfile.log $obeyfile.symbol >maksym.out");
       
  4186 					exit(1) if (!-e "$obeyfile.symbol" );
       
  4187 					}			
  4429 					}			
       
  4430 					run_rombuilder($rofsbuild.$compress, $obeyfile, $thisdir."ROFSBUILD.LOG");
  4188 				}
  4431 				}
  4189 			}
  4432 			}
  4190 			unlink "rombuild.log";
  4433 			unlink "rombuild.log";
  4191 			unlink "maksym.out";
  4434 			unlink "maksym.out";
  4192 		}
  4435 		}
  4212 #
  4455 #
  4213 
  4456 
  4214 sub relative_path
  4457 sub relative_path
  4215 {
  4458 {
  4216     my ($arg) = @_;
  4459     my ($arg) = @_;
  4217     return $arg if ($arg !~ /^\\/);	# not an absolute path
  4460     return $arg if ($arg !~ /^\//);	# not an absolute path
  4218     if ($uppath eq "x")
  4461     if ($uppath eq "x")
  4219 	{
  4462 	{
  4220 		$uppath=cwd;
  4463 		$uppath=cwd;
  4221 		$uppath=~s-/-\\-go;		    # separator from Perl 5.005_02+ is forward slash
  4464 		$uppath=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
  4222 		$uppath=~s-^(.*[^\\])$-$1\\-o;	    # ensure path ends with a backslash
  4465 		$uppath=~s-^(.*[^\/])$-$1\/-o;	    # ensure path ends with a backslash
  4223 		$uppath=~s-\\([^\\]+)-\\..-og;	    # convert directories into ..
  4466 		$uppath=~s-\/([^\/]+)-\/..-og;	    # convert directories into ..
  4224 		$uppath=~s-^.:\\--o;		    # remove drive letter and leading backslash
  4467 		$uppath=~s-^.:\/--o;		    # remove drive letter and leading backslash
  4225 	}
  4468 	}
  4226     $arg=~s-^\\--o;	# remove leading backslash from original path
  4469     $arg=~s-^\/--o;	# remove leading backslash from original path
  4227     return "$uppath$arg";
  4470     return "$uppath$arg";
  4228 }
  4471 }
  4229 
  4472 
  4230 # Returns the global @obydata reference to support external tool invocation.
  4473 # Returns the global @obydata reference to support external tool invocation.
  4231 sub getOBYDataRef{
  4474 sub getOBYDataRef{
  4451 		my $aDllFile = $DllMapRef->{srcfile};
  4694 		my $aDllFile = $DllMapRef->{srcfile};
  4452 		my $SymbolCount = scalar ( keys %{$DllMapRef}) - 2; #The map has 'srcfile' and 'dstpath' special keys besides the symbols.
  4695 		my $SymbolCount = scalar ( keys %{$DllMapRef}) - 2; #The map has 'srcfile' and 'dstpath' special keys besides the symbols.
  4453 
  4696 
  4454 		my $DllSymMapRef;
  4697 		my $DllSymMapRef;
  4455 
  4698 
  4456 		my @BPABIPlats = &BPABIutl_Plat_List;
  4699 		my @BPABIPlats = &get_bpabiplatlist;
  4457 		my $matchedSymbols = 0;
  4700 		my $matchedSymbols = 0;
  4458 		my $globalSyms = 0;
  4701 		my $globalSyms = 0;
  4459 		my @platlist = &Plat_List();
  4702 		my @platlist = &get_platlist;
  4460 		my $platName;
  4703 		my $platName;
  4461 		my $rootPlatName;
  4704 		my $rootPlatName;
  4462 		my $plat = "ARMV5";				
  4705 		my $plat = "armv5";				
  4463 		$plat = &Variant_GetMacro() ? $plat."_ABIV1" : $plat."_ABIV2";		
  4706 		$plat = &get_abiv2mode() ? $plat."_abiv1" : $plat."_abiv2";		
  4464 
  4707 
  4465 		foreach my $plat(@platlist) 
  4708 		foreach my $plat(@platlist) 
  4466 		{
  4709 		{
  4467 			if(($aDllFile =~ /\\($plat)\\/i) or ($aDllFile =~ /\\($plat\.\w+)\\/i ))
  4710 			if(($aDllFile =~ /[\/\\]($plat)[\/\\]/i) or ($aDllFile =~ /[\/\\]($plat\.\w+)[\/\\]/i ))
  4468 			{
  4711 			{
  4469 				$platName = $1;
  4712 				$platName = $1;
  4470 				last;
  4713 				last;
  4471 			}
  4714 			}
  4472 		}		
  4715 		}		
  4473 		$rootPlatName =	&Plat_Customizes($platName) ? &Plat_Root($platName) : $platName;
  4716 		$rootPlatName =	&get_platcustomizes($platName) ? &get_platroot($platName) : $platName;
  4474 		
  4717 		
  4475 		# Map files will be referred for all ARM platforms, 
  4718 		# Map files will be referred for all ARM platforms, 
  4476 		# and for BSF platforms which cutomizes ARM platforms.
  4719 		# and for BSF platforms which cutomizes ARM platforms.
  4477 		if($rootPlatName =~ /^ARMV5|$plat$/i){
  4720 		if($rootPlatName =~ /^armv5|$plat$/i){
  4478 			my $mapfile = "${aDllFile}.map";
  4721 			my $mapfile = "${aDllFile}.map";
  4479 			
  4722 			
  4480 			open MAPFILE, "$mapfile" or die "Can't open $mapfile\n";
  4723 			open MAPFILE, "$mapfile" or die "Can't open $mapfile\n";
  4481 			while(<MAPFILE>){
  4724 			while(<MAPFILE>){
  4482 			my $line = $_;
  4725 			my $line = $_;
  4516 					
  4759 					
  4517 					# Record the address and the size of the symbol.
  4760 					# Record the address and the size of the symbol.
  4518 					$DllSymMapRef->{dataAddr} = $symbolValue;
  4761 					$DllSymMapRef->{dataAddr} = $symbolValue;
  4519 					$DllSymMapRef->{size} = $symbolSz;
  4762 					$DllSymMapRef->{size} = $symbolSz;
  4520 
  4763 
       
  4764 
  4521 					$matchedSymbols++;
  4765 					$matchedSymbols++;
  4522 					if( $matchedSymbols >= $SymbolCount){
  4766 					if( $matchedSymbols >= $SymbolCount){
  4523 						last;
  4767 						last;
  4524 					}
  4768 					}
  4525 				}
  4769 				}
  4542 				$errors++ if($strict);
  4786 				$errors++ if($strict);
  4543 				next; #go to the next patch dll data statement
  4787 				next; #go to the next patch dll data statement
  4544 			}
  4788 			}
  4545 			if( $aDllFile =~ /(.*)\.[^.]+$/ ){
  4789 			if( $aDllFile =~ /(.*)\.[^.]+$/ ){
  4546 				my $proxydsofile = "$1.dso";
  4790 				my $proxydsofile = "$1.dso";
  4547 				$proxydsofile =~ s/$abiDir\\(.*)\\/ARMV5\\LIB\\/ig;
  4791 				$proxydsofile =~ s-$abiDir\/(.*)\/-armv5\/lib\/-ig;
  4548 				open PIPE, "getexports -d $proxydsofile|" or die "Can't open file $proxydsofile\n";
  4792 				open PIPE, "getexports -d $proxydsofile|" or die "Can't open file $proxydsofile\n";
  4549 				while (<PIPE>){
  4793 				while (<PIPE>){
  4550 					my $line = $_;
  4794 					my $line = $_;
  4551 					if($line =~ /\s*(\S+)\s+(\d+)\s+((\S+)\s+(\d+))?/){
  4795 					if($line =~ /\s*(\S+)\s+(\d+)\s+((\S+)\s+(\d+))?/){
  4552 						my $symbol = $1;
  4796 						my $symbol = $1;
  4585 # absolute paths starting with slashes.
  4829 # absolute paths starting with slashes.
  4586 sub addDrivesToFeatureVariantPaths
  4830 sub addDrivesToFeatureVariantPaths
  4587 {
  4831 {
  4588 	return unless $featureVariant{'VALID'};
  4832 	return unless $featureVariant{'VALID'};
  4589 
  4833 
  4590 	my $current = cwd();
  4834 	my $current = &get_epocdrive;
  4591 	my $drive = $1 if ($current =~ /^(.:)/);
  4835 	my $drive = $1 if ($current =~ /^(.:)/);
  4592 
  4836 
  4593 	# pre-include file
  4837 	# pre-include file
  4594 	my $HRH = $featureVariant{'VARIANT_HRH'};
  4838 	my $HRH = $featureVariant{'VARIANT_HRH'};
  4595 	$featureVariant{'VARIANT_HRH'} = $drive . $HRH if ($HRH =~ /^[\\\/]/);
  4839 	$featureVariant{'VARIANT_HRH'} = $drive . $HRH if ($HRH =~ /^[\\\/]/);
  4609 {
  4853 {
  4610 	if($needSmrImage)
  4854 	if($needSmrImage)
  4611 	{
  4855 	{
  4612 		foreach my $oby (@obeyFileList)
  4856 		foreach my $oby (@obeyFileList)
  4613 		{
  4857 		{
       
  4858 			is_existinpath("rofsbuild", romutl::ERROR_NOT_FOUND);
  4614 			my $command = "rofsbuild -slog -smr=$oby.oby";
  4859 			my $command = "rofsbuild -slog -smr=$oby.oby";
  4615 			print "* Executing $command\n" if($opt_v);
  4860 			print "* Executing $command\n" if($opt_v);
  4616 			system($command);
  4861 			system($command);
  4617 			if($? != 0)
  4862 			if($? != 0)
  4618 			{
  4863 			{
  4649 	{
  4894 	{
  4650 		print "\n SMR image creating error for empty image name!\n";
  4895 		print "\n SMR image creating error for empty image name!\n";
  4651 	}
  4896 	}
  4652 }
  4897 }
  4653 
  4898 
       
  4899 sub getWorkdir
       
  4900 {
       
  4901 	return $thisdir;
       
  4902 }
       
  4903 
       
  4904 sub find_stdcpp
       
  4905 {
       
  4906     return "cpp" if (!$stdcpp);
       
  4907     return "cpp" if (&is_linux);
       
  4908     
       
  4909     my $delimiter = &env_delimiter;
       
  4910 		$ENV{PATH}="${epocroot}epoc32\/gcc_mingw\/bin$delimiter".$ENV{PATH};
       
  4911     my @paths;
       
  4912  		@paths = split(/$delimiter/, $ENV{PATH});
       
  4913     unshift @paths, "\.";
       
  4914     
       
  4915     foreach my $path (@paths)
       
  4916     {
       
  4917         next if ($path =~ /^\s*$/);
       
  4918         chomp $path;
       
  4919         $path =~ s/\\/\//g;
       
  4920         $path .= "\/" unless ($path =~ /\/$/);
       
  4921         $path = $path."cpp.exe";
       
  4922         if (-e $path)
       
  4923         {
       
  4924 		        $path = "\"$path\"";
       
  4925         		my $command = "$path --version 2>&1";
       
  4926 						open DATA, "$command |"   or die "Couldn't execute command: $command\n";
       
  4927 						my $line = <DATA>;
       
  4928 						chomp($line);
       
  4929 						print "$line\n" if($opt_v);
       
  4930 						if ($line =~ /cpp\.exe \(GCC\) .* \(mingw special\)/)
       
  4931 						{
       
  4932 							print "found stdcpp in $path\n" if($opt_v);
       
  4933 							close DATA;
       
  4934 							return $path;
       
  4935 						}
       
  4936 						close DATA;
       
  4937         }
       
  4938     }
       
  4939     die "Error: Cannot found standard cpp.exe in the PATH.\n";
       
  4940 } 
       
  4941 
       
  4942 sub checkcase()
       
  4943 {
       
  4944 	if (&is_windows)
       
  4945 	{
       
  4946 		my @checkcase_obydatatemp = @obydata;
       
  4947 
       
  4948 		# call the phase without external tools.
       
  4949 		plugin_phase();
       
  4950 		multlinguify_phase();
       
  4951 		#spi_creation_phase(); #spi creation phase will delete some lines, so do not call this phase
       
  4952 		suppress_phase();
       
  4953 		process_dlldata();
       
  4954 		bitmap_aif_converison_phase();
       
  4955 
       
  4956 		my $checkcase_log = "checkcase.log";
       
  4957 		unlink $checkcase_log;
       
  4958 		
       
  4959 		open CHECKCASELOG, ">$checkcase_log" or die("* Can't create $checkcase_log\n");
       
  4960 		my @checkcase_lines = @obydata;
       
  4961 		my %checkcase_macro;
       
  4962 		my @checkcase_macrodir;
       
  4963 		my $checkcase_line;
       
  4964 		print CHECKCASELOG "======================Macro check part:======================\n";
       
  4965 		foreach $checkcase_line (@checkcase_lines)
       
  4966 		{
       
  4967 			track_source($checkcase_line);
       
  4968 			$checkcase_line =~ s-\/-\\-g;
       
  4969 			$checkcase_line =~ s-\\\\-\\-g;
       
  4970 			if ($checkcase_line =~ /^\s*REM\s*(re)?defined\s*(\w*)\s*as\s*(\S+)/)
       
  4971 			{
       
  4972 				my $checkcase_macrocontent = $3;
       
  4973 				my $checkcase_macroname = $2;
       
  4974 				if ($checkcase_macrocontent =~ /[a-zA-Z]/)
       
  4975 				{
       
  4976 					$checkcase_macro{$checkcase_macroname} = $checkcase_macrocontent;
       
  4977 					checkcase_macro(\@checkcase_macrodir, $checkcase_macroname, $checkcase_macrocontent);
       
  4978 				}
       
  4979 			}
       
  4980 		}
       
  4981 		print CHECKCASELOG "======================Macro check part end======================\n\n";
       
  4982 		print CHECKCASELOG "======================File check part:======================\n";
       
  4983 		foreach $checkcase_line (@checkcase_lines)
       
  4984 		{
       
  4985 			if ($checkcase_line =~ /^\s*REM\s*.*/)
       
  4986 			{
       
  4987 				next;
       
  4988 			}
       
  4989 			if ($checkcase_line =~ /^\s*#\s*\d+\s*\"(\S+)\"\s*\d*\s*$/) #oby filename
       
  4990 			{
       
  4991 				my $checkcase_whichfile = $1;
       
  4992 				checkcase_obyfilename($checkcase_whichfile);
       
  4993 				track_source($checkcase_line);
       
  4994 			}elsif ($checkcase_line =~ /^\s*\S+\s*=\s*"([^"]+)"\s+\S*\s*/ 
       
  4995 					 || $checkcase_line =~ /^\s*\S+\s*=\s*(\S+)\s+\S*\s*/) #oby content file name
       
  4996 			{
       
  4997 				my $checkcase_pcsidefile = $1;
       
  4998 				checkcase_pcsidefilename(\@checkcase_macrodir, $checkcase_pcsidefile);
       
  4999 			}
       
  5000 		}
       
  5001 		print CHECKCASELOG "======================File check part end======================\n";
       
  5002 		close CHECKCASELOG;
       
  5003 		
       
  5004 		@obydata = @checkcase_obydatatemp;
       
  5005 	}else
       
  5006 	{
       
  5007 		print "WARNING: checkcase option is only valid on windows.\n";
       
  5008 	}
       
  5009 }
       
  5010 
       
  5011 sub checkcase_macro()
       
  5012 {
       
  5013 	my $macrodir = shift;
       
  5014 	my $name = shift;
       
  5015 	my $content = shift;
       
  5016 	
       
  5017 	if ($content =~ /epoc32/i && (-d $content))
       
  5018 	{
       
  5019 		my $realdir = `directory.bat $content`;
       
  5020 		$realdir =~ s/\s+$//g;
       
  5021 		$realdir =~ s/^\s*\w://g if ($content !~ /^\w:/);
       
  5022 		$realdir =~ s/\\$//g if ($content !~ /\\$/);
       
  5023 		$realdir .= "\\" if ($content =~ /\\$/ && $realdir !~ /\\$/);
       
  5024 		$sourcefile =~ s/\//\\/g;
       
  5025 		$sourcefile =~ s/\\\\/\\/g;
       
  5026 		if ($realdir ne $content)
       
  5027 		{
       
  5028 			print CHECKCASELOG "check case: macro name is $name\n";
       
  5029 			print CHECKCASELOG "WARNING: macro case is not equal to real.\n";
       
  5030 			print CHECKCASELOG "file name is $sourcefile\n";
       
  5031 			print CHECKCASELOG "current is $content\n";
       
  5032 			print CHECKCASELOG "expect  is $realdir\n\n";
       
  5033 			checkcase_convert($sourcefile, $content, $realdir);
       
  5034 		}
       
  5035 		$content =~ s-\\-\\\\-g;
       
  5036 		push @$macrodir, $content;
       
  5037 	}else
       
  5038 	{
       
  5039 		if($name eq "PLATFORM_NAME")
       
  5040 		{
       
  5041 			$content =~ s-\\-\\\\-g;
       
  5042 			$content =~ s-\.-\\\.-g;
       
  5043 			$checkcase_platform = $content;
       
  5044 		}
       
  5045 	}
       
  5046 }
       
  5047 
       
  5048 sub checkcase_obyfilename()
       
  5049 {
       
  5050 	my $checkfile = shift;
       
  5051 	if (-e $checkfile)
       
  5052 	{
       
  5053 		while ($checkfile=~s-[\\](?!\.{2}\\)[^\\]*\\\.{2}(?=\\)--go){};
       
  5054 		$sourcefile =~ s/\//\\/g;
       
  5055 		if ($checkfile eq $sourcefile)
       
  5056 		{
       
  5057 			return;		
       
  5058 		}
       
  5059 		my($filename, $dir, $suffix) = fileparse($checkfile);
       
  5060 		
       
  5061 		my $realdir = `directory.bat $dir`;
       
  5062 		$realdir =~ s/\s+$//g;
       
  5063 		$realdir .= "\\" if ($realdir !~ /\\$/);
       
  5064 		if ($realdir ne $dir)
       
  5065 		{
       
  5066 			print CHECKCASELOG "check case: oby file name is $checkfile\n";
       
  5067 			print CHECKCASELOG "WARNING: dir case is not equal to real.\n";
       
  5068 			my $tempsrcfile = $sourcefile;
       
  5069 			$tempsrcfile =~ s/\\\\/\\/g;
       
  5070 			print CHECKCASELOG "file name is $tempsrcfile\n";
       
  5071 			print CHECKCASELOG "current is $dir\n";
       
  5072 			print CHECKCASELOG "expect  is $realdir\n\n";
       
  5073 			checkcase_convert($sourcefile, $dir, $realdir);
       
  5074 		}
       
  5075 		
       
  5076 		my $currentdir = cwd;
       
  5077 		chdir "$dir";
       
  5078 		my @realfile = `dir "$filename" 2>&1`;
       
  5079 		my $line;
       
  5080 		foreach $line (@realfile)
       
  5081 		{
       
  5082 			if ($line =~ /^\s*(\S+)\s+(\d{2}:\d{2})\s+(PM|AM)?\s+([\d\,])+\s+([\S]+)\s*/)
       
  5083 			{
       
  5084 				my $realfilename = $5;
       
  5085 				my $filetemp = lc $filename;
       
  5086 				my $realtemp = lc $realfilename;
       
  5087 				if ($filetemp eq $realtemp && $realfilename ne $filename)
       
  5088 				{
       
  5089 					print CHECKCASELOG "check case: oby file name is $checkfile\n";
       
  5090 					print CHECKCASELOG "WARNING: filename case is not equal to real.\n";
       
  5091 					my $tempsrcfile = $sourcefile;
       
  5092 					$tempsrcfile =~ s/\\\\/\\/g;
       
  5093 					print CHECKCASELOG "file name is $tempsrcfile\n";
       
  5094 					print CHECKCASELOG "current is $filename\n";
       
  5095 					print CHECKCASELOG "expect  is $realfilename\n\n";
       
  5096 					checkcase_convert($sourcefile, $filename, $realfilename);
       
  5097 				}
       
  5098 			}
       
  5099 		}
       
  5100 		chdir "$currentdir";
       
  5101 	}
       
  5102 }
       
  5103 
       
  5104 sub checkcase_pcsidefilename()
       
  5105 {
       
  5106 	my $macrodirs = shift;
       
  5107 	my $checkfile = shift;
       
  5108 	$checkfile =~ s/^\"//g;
       
  5109 	$checkfile =~ s/\"$//g;
       
  5110 	if (-e $checkfile)
       
  5111 	{
       
  5112 		while ($checkfile=~s-[\\](?!\.{2}\\)[^\\]*\\\.{2}(?=\\)--go){};
       
  5113 		$sourcefile =~ s/\//\\/g;
       
  5114 		my($filename, $dir, $suffix) = fileparse($checkfile);
       
  5115 		if ($dir eq "\.\\")
       
  5116 		{
       
  5117 			$dir = cwd;
       
  5118 			$dir =~ s/\//\\/g;
       
  5119 			$dir .= "\\" if ($dir !~ /\\$/);
       
  5120 		}
       
  5121 		
       
  5122 		my $realdir = `directory.bat $dir`;
       
  5123 		$realdir =~ s/\s+$//g;
       
  5124 		$realdir =~ s/^\s*\w://g if ($dir !~ /^\w:/);
       
  5125 		$realdir .= "\\" if ($realdir !~ /\\$/);
       
  5126 		my $dirtemp = $dir;
       
  5127 		if ($checkcase_test)
       
  5128 		{
       
  5129 			my $macrodirtemp = "";
       
  5130 			foreach my $macrodir (@$macrodirs)
       
  5131 			{
       
  5132 				if ($dirtemp =~ /^$macrodir(.*)$/)
       
  5133 				{
       
  5134 					$macrodirtemp = $macrodir if (length($macrodirtemp) < length($macrodir));
       
  5135 				}
       
  5136 			}
       
  5137 			if ($macrodirtemp ne "")
       
  5138 			{
       
  5139 				$dirtemp =~ s/^$macrodirtemp//g;
       
  5140 				$realdir =~ s/^$macrodirtemp//ig;
       
  5141 			}
       
  5142 		}
       
  5143 		if ($realdir ne $dirtemp)
       
  5144 		{
       
  5145 			print CHECKCASELOG "check case: pc side file name is $checkfile\n";
       
  5146 			print CHECKCASELOG "WARNING: dir case is not equal to real.\n";
       
  5147 			my $tempsrcfile = $sourcefile;
       
  5148 			$tempsrcfile =~ s/\\\\/\\/g;
       
  5149 			print CHECKCASELOG "file name is $tempsrcfile\n";
       
  5150 			print CHECKCASELOG "current is $dirtemp\n";
       
  5151 			print CHECKCASELOG "expect  is $realdir\n\n";
       
  5152 			checkcase_convert($sourcefile, $dirtemp, $realdir);
       
  5153 		}
       
  5154 		
       
  5155 		my $currentdir = cwd;
       
  5156 		chdir "$dir";
       
  5157 		my @realfile = `dir "$filename" 2>&1`;
       
  5158 		my $line;
       
  5159 		foreach $line (@realfile)
       
  5160 		{
       
  5161 			if ($line =~ /^\s*(\S+)\s+(\d{2}:\d{2})\s+(PM|AM)?\s+([\d\,])+\s+(.+)\s*/)
       
  5162 			{
       
  5163 				my $realfilename = $5;
       
  5164 				my $filetemp = lc $filename;
       
  5165 				my $realtemp = lc $realfilename;
       
  5166 				if ($filetemp eq $realtemp && $realfilename ne $filename)
       
  5167 				{
       
  5168 					print CHECKCASELOG "check case: pc side file name is $checkfile\n";
       
  5169 					print CHECKCASELOG "WARNING: filename case is not equal to real.\n";
       
  5170 					my $tempsrcfile = $sourcefile;
       
  5171 					$tempsrcfile =~ s/\\\\/\\/g;
       
  5172 					print CHECKCASELOG "file name is $tempsrcfile\n";
       
  5173 					print CHECKCASELOG "current is $filename\n";
       
  5174 					print CHECKCASELOG "expect  is $realfilename\n\n";
       
  5175 					checkcase_convert($sourcefile, $filename, $realfilename);
       
  5176 				}
       
  5177 			}
       
  5178 		}
       
  5179 		chdir "$currentdir";
       
  5180 	}
       
  5181 }
       
  5182 
       
  5183 sub checkcase_convert()
       
  5184 {
       
  5185 	return if (!$checkcase_test);
       
  5186 	
       
  5187 	my $file = shift;
       
  5188 	my $origin = shift;
       
  5189 	my $real = shift;
       
  5190 	
       
  5191 	my @realfile = `dir "$file"  2>&1`;
       
  5192 	my $line;
       
  5193 	foreach $line (@realfile)
       
  5194 	{
       
  5195 		if ($line =~ /^\s*(\S+)\s+(\d{2}:\d{2})\s+(PM|AM)?\s+([\d\,])+\s+([\S]+)\s*/)
       
  5196 		{
       
  5197 			my $realfilename = $5;
       
  5198 			$realfilename =~ s-\.-\\\.-g;
       
  5199 			$file =~ s-$realfilename$--ig;
       
  5200 			$realfilename =~ s-\\\.-\.-g;
       
  5201 			$file .= $realfilename;
       
  5202 		}
       
  5203 	}
       
  5204 
       
  5205 	my $tempfile = $file.".temp";
       
  5206 	my $usemultimacro = 0;
       
  5207 	my $uses60macro_aifrsc = 0;
       
  5208 	my $uses60macro_exe = 0;
       
  5209 	my $uses60macro_aificon = 0;
       
  5210 	my $uses60macro_resource = 0;
       
  5211 	my $originwithoutext = $origin;
       
  5212 	my $realwithoutext = $real;
       
  5213 	if ($origin =~ /epoc32/i)
       
  5214 	{
       
  5215 		my $tempepocroot = $ENV{EPOCROOT};
       
  5216 		$tempepocroot =~ s-\\-\\\\-g;
       
  5217 		$origin =~ s/^$tempepocroot//g;
       
  5218 		$real =~ s/^$tempepocroot//g;
       
  5219 	}elsif ($checkcase_platform ne "" && $origin =~ /^_$checkcase_platform\_(.*)/)
       
  5220 	{
       
  5221 		$origin =~ s/^_$checkcase_platform\_/_PLATFORM_NAME_/g;
       
  5222 		$real =~ s/^_$checkcase_platform\_/_PLATFORM_NAME_/g;
       
  5223 	}elsif ($origin =~ /\S+\_reg\.rsc$/)
       
  5224 	{
       
  5225 		$originwithoutext =~ s/\_reg\.rsc$//g;
       
  5226 		$realwithoutext =~ s/\_reg\.rsc$//ig;
       
  5227 		$uses60macro_aifrsc = 1;
       
  5228 	}elsif ($origin =~ /\S+\.rsc$/)
       
  5229 	{
       
  5230 		$originwithoutext =~ s/\.rsc$//g;
       
  5231 		$realwithoutext =~ s/\.rsc$//ig;
       
  5232 		$usemultimacro = 1;
       
  5233 		$uses60macro_resource = 1;
       
  5234 	}elsif ($origin =~ /\S+\.r01$/)
       
  5235 	{
       
  5236 		$originwithoutext =~ s/\.r01$//g;
       
  5237 		$realwithoutext =~ s/\.r01$//ig;
       
  5238 		$usemultimacro = 1;
       
  5239 	}elsif ($origin =~ /\S+\.exe$/)
       
  5240 	{
       
  5241 		$originwithoutext =~ s/\.exe$//g;
       
  5242 		$realwithoutext =~ s/\.exe$//ig;
       
  5243 		$uses60macro_exe = 1;
       
  5244 	}elsif ($origin =~ /\S+\_aif\.mif$/)
       
  5245 	{
       
  5246 		$originwithoutext =~ s/\_aif\.mif$//g;
       
  5247 		$realwithoutext =~ s/\_aif\.mif$//ig;
       
  5248 		$uses60macro_aificon = 1;
       
  5249 	}elsif ($origin =~ /\S+\.mif$/)
       
  5250 	{
       
  5251 		$originwithoutext =~ s/\.mif$//g;
       
  5252 		$realwithoutext =~ s/\.mif$//ig;
       
  5253 		$uses60macro_aificon = 1;
       
  5254 	}
       
  5255 	$origin =~ s-\\-\\\\-g;
       
  5256 	$origin =~ s-\.-\\\.-g;
       
  5257 	
       
  5258 	open (SRC, "<$file");
       
  5259 	open (DST, ">$tempfile");
       
  5260 	my $line;
       
  5261 	while($line = <SRC>)
       
  5262 	{
       
  5263 		my $flag = 0;
       
  5264 
       
  5265 		if ($line =~ /$origin/)
       
  5266 		{
       
  5267 			$originwithoutext = $origin;
       
  5268 			$realwithoutext = $real;
       
  5269 			$flag = 1;
       
  5270 		}elsif ($usemultimacro)
       
  5271 		{
       
  5272 			if ($line =~ /^.*=\s*MULTI_LINGUIFY\s*\(.*$originwithoutext/)
       
  5273 			{
       
  5274 				$flag = 1;
       
  5275 			}elsif ($line =~ /^\s*S60_APP_RESOURCE\s*\(\s*$originwithoutext\s*\)/ && $uses60macro_resource)
       
  5276 			{
       
  5277 				$flag = 1;
       
  5278 			}
       
  5279 		}elsif ($uses60macro_exe)
       
  5280 		{
       
  5281 			if ($line =~ /^\s*S60_APP_EXE\s*\(\s*$originwithoutext\s*\)/)
       
  5282 			{
       
  5283 				$flag = 1;
       
  5284 			}
       
  5285 		}elsif ($uses60macro_aificon)
       
  5286 		{
       
  5287 			if ($line =~ /^\s*S60_APP_AIF_ICONS\s*\(\s*$originwithoutext\s*\)/)
       
  5288 			{
       
  5289 				$flag = 1;
       
  5290 			}elsif ($line =~ /^\s*SCALABLE_IMAGE\s*\(.*$originwithoutext\s*\)/)
       
  5291 			{
       
  5292 				$flag = 1;
       
  5293 			}elsif ($line =~ /^\s*S60_APP_BITMAP\s*\(\s*$originwithoutext\s*\)/)
       
  5294 			{
       
  5295 				$flag = 1;
       
  5296 			}
       
  5297 		}elsif ($uses60macro_aifrsc)
       
  5298 		{
       
  5299 			if ($line =~ /^\s*S60_APP_AIF_RSC\s*\(\s*$originwithoutext\s*\)/)
       
  5300 			{
       
  5301 				$flag = 1;
       
  5302 			}elsif ($line =~ /^\s*S60_UPGRADABLE_APP_REG_RSC\s*\(\s*$originwithoutext\s*\)/)
       
  5303 			{
       
  5304 				$flag = 1;
       
  5305 			}
       
  5306 		}
       
  5307 		if ($flag)
       
  5308 		{
       
  5309 			print CHECKCASELOG "it has been converted automatically\n";
       
  5310 			print CHECKCASELOG "original  line is $line";
       
  5311 			$line =~ s-$originwithoutext-$realwithoutext-;
       
  5312 			print CHECKCASELOG "converted line is $line\n";
       
  5313 		}
       
  5314 		print DST $line;
       
  5315 	}
       
  5316 	close SRC;
       
  5317 	close DST;
       
  5318 	
       
  5319   unlink "$file";
       
  5320   rename ("$file.temp", "$file");
       
  5321 }
       
  5322 
  4654 1;
  5323 1;