imgtools/buildrom/tools/buildrom.pm
changeset 607 378360dbbdba
parent 590 360bd6b35136
parent 606 30b30f9da0b7
child 609 f76e0f94b7ab
--- a/imgtools/buildrom/tools/buildrom.pm	Wed Jun 23 17:27:59 2010 +0800
+++ b/imgtools/buildrom/tools/buildrom.pm	Wed Jun 30 11:35:58 2010 +0800
@@ -65,7 +65,7 @@
 my $enforceFeatureManager = 0; # Flag to make Feature Manager mandatory if SYMBIAN_FEATURE_MANAGER macro is defined. 
 
 my $BuildromMajorVersion = 3 ;
-my $BuildromMinorVersion = 24;
+my $BuildromMinorVersion = 26;
 my $BuildromPatchVersion = 0;
 
 
@@ -150,7 +150,7 @@
    -I<directory>                    -- Use <directory> for the referenced IBY/OBY files
    -argfile=xxx                     -- specify argument-file name containing list of command-line arguments to buildrom   
    -lowmem                          -- use memory-mapped file for image build to reduce physical memory consumption   
-   -chechcase                       -- check character case of path/name in oby/iby files, 
+   -checkcase                       -- check character case of path/name in oby/iby files, 
                                     the result will be checkcase.log, this option is only valid on windows.
    -workdir=xxx                     -- specify a directory to contain generated files.   
 
@@ -226,7 +226,7 @@
 my $thisdir=cwd;
 $thisdir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
 $thisdir.= "\/" unless $thisdir =~ /\/$/;
-$thisdir=~s-^(.:)?\/--o;		    # remove drive letter and leading backslash
+$thisdir =~ s-\/-\\-g if (&is_windows);
 
 my $rominclude = $epocroot."epoc32\/rom\/include\/";
 $rominclude = &get_epocdrive().$rominclude unless $rominclude =~ /^.:/;
@@ -341,7 +341,7 @@
 my $checkcase = 0;
 my $checkcase_platform = "";
 my $checkcase_test = 0;
-my $invokecmddir = "";
+my $opt_workdir = 0;
 
 sub match_obyfile
 {
@@ -354,7 +354,6 @@
 
 	# search for the oby file in the list of include directories
 	my @otherDirs = ($rominclude);
-	push (@otherDirs, $invokecmddir) if ($invokecmddir ne "");
 
 	if ($featureVariant{'VALID'})
 	{
@@ -762,28 +761,7 @@
 		if ( $arg =~ /^-k$/i || $arg =~ /^-keepgoing$/i )
 	  {
 			$opt_k = 1;		
-			next;
-	  }elsif ($arg =~ /^-workdir=(.*)/)
-		{
-			my $workdir=$1;
-			if( $workdir =~ m/ / )
-			{
-				print "* Warning: $workdir contains whitespace, hence the files will be created in default location \n";
-				$workdir = "";
-			}
-			if ($workdir ne "")
-			{
-				$invokecmddir = cwd;
-				$invokecmddir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
-				$invokecmddir.= "\/" unless $invokecmddir =~ /\/$/;
-				$workdir =~ s-\\-\/-g;
-				chdir "$workdir" or die "cannot change to directory $workdir\n";
-				$thisdir=cwd;
-				$thisdir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
-				$thisdir.= "\/" unless $thisdir =~ /\/$/;
-				$thisdir=~s-^(.:)?\/--o;		    # remove drive letter and leading backslash
-			}
-			next;	
+  		last;	
 		}
 	}
 	foreach my $arg (@argList)
@@ -1023,6 +1001,22 @@
 		}
 		if ($arg =~ /^-workdir=(.*)/)
 		{
+			my $workdir = $1;
+			if (!-d $workdir)
+			{
+				die "directory $workdir does not exist\n";
+			}
+			my $currentdir = cwd;
+			chdir "$workdir" or die "cannot change to directory $workdir\n";
+			$thisdir=cwd;
+			$thisdir=~s-\\-\/-go;		    # separator from Perl 5.005_02+ is forward slash
+			$thisdir.= "\/" unless $thisdir =~ /\/$/;
+			if(&is_windows)
+			{
+				$thisdir =~ s-\/-\\-g;
+			}
+			$opt_workdir = 1;
+			chdir "$currentdir";
 			next;	
 		}
         if($arg =~/^-c(.*)/)
@@ -1253,7 +1247,8 @@
 
 sub preprocessing_phase
 {
-	unlink "tmp1.oby";
+	my $temp1OBYFile = $thisdir."tmp1.oby";
+	unlink "$temp1OBYFile";
 
 #	Macro "ROM_FEATURE_MANAGEMENT" is defined when "-f|fr" or "-fm" is used
 	if (defined ($featureXml))
@@ -1283,14 +1278,13 @@
 	{
 		# no feature variant so use the standard includes
 		$cppargs .= " -I. -I \"$rominclude\"";
-		$cppargs .= " -I \"$invokecmddir\"" if ($invokecmddir ne "");
 	}
 
-	print "* cpp -Wno-endif-labels -o tmp1.oby $cppargs\n" if ($opt_v);
+	print "* cpp -Wno-endif-labels -o $temp1OBYFile $cppargs\n" if ($opt_v);
 	
 	is_existinpath("cpp", romutl::DIE_NOT_FOUND);
 	$errors = 0;
-	open CPP, "| cpp -Wno-endif-labels -o tmp1.oby $cppargs" or die "* Can't execute cpp";
+	open CPP, "| cpp -Wno-endif-labels -o $temp1OBYFile $cppargs" or die "* Can't execute cpp";
 	foreach my $arg (@obyfiles)
 	{
 		print CPP "\n#line 1 \"$arg\"\n";
@@ -1312,9 +1306,8 @@
 	}
 	close CPP;
 	my $cpp_status = $?;
-	die "* cpp failed\n" if ($cpp_status != 0 || !-f "tmp1.oby");
-
-	my $temp1OBYFile = "tmp1.oby";
+	die "* cpp failed\n" if ($cpp_status != 0 || !-f "$temp1OBYFile");
+
 	if( defined ($image_content))
 	{
 		#Read the OBY file that was generated by the pre-processor
@@ -1400,11 +1393,11 @@
 		@substitutionOrder = ("TODAY", "RIGHT_NOW", "EPOCROOT");
 	}
 
+	my $temp1OBYFile = $thisdir."tmp1.oby";
 	
-	open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
+	open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
 	while ($line=<TMP1>)
 	{
-
 		if(($line =~ /^\s*romsize\s*=/i) || ( $line=~ /^\s*rom_image/i) || ($line =~ /^\s*data_image/i))
 		{
 			$onlysmrimage = 0;
@@ -1415,7 +1408,7 @@
 	if ($enforceFeatureManager && (!$featuremanager) && (!$noFeatureManager) )
 	{
 		my $defaultFeatureDbFlag = 0;
-		open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
+		open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
 		while ($line=<TMP1>)
 		{
 			if ($line=~/^\s*defaultfeaturedb\s*=?\s*(\S+)/i)
@@ -1439,11 +1432,20 @@
 		}
 	}
 
-	open TMP1, "tmp1.oby" or die("* Can't open tmp1.oby\n");
+	open TMP1, "$temp1OBYFile" or die("* Can't open $temp1OBYFile\n");
 	while ($line=<TMP1>)
 	{
 		track_source($line);
 		$line =~ s-\\-\/-g;
+
+		my $tempstring = $epocroot."epoc32";
+		if(($line !~ /^\s*\#/) && ($line =~ /\/epoc32/i) 
+		 && ($line !~ /EPOCROOT##\/?epoc32/i) && ($line !~ /$tempstring/i))
+		{
+			print "add EPOCROOT for line: $line\n" if ($opt_v);
+	  	$line =~ s-\/epoc32-EPOCROOT##epoc32-ig;
+		}
+
 		#
 		# Recognise keywords in lines that we process before substitution
 		#
@@ -1802,6 +1804,7 @@
 sub dump_obydata
 {
 	my ($dumpfile, $comment) = @_;
+	$dumpfile = $thisdir.$dumpfile;
 	unlink($dumpfile);
 	open DUMPFILE, ">$dumpfile" or die("* Can't create $dumpfile\n");
 	print "* Writing $dumpfile - $comment\n";
@@ -2536,7 +2539,7 @@
 			}
 		}
 		my @spiargs; #arguments passed to createSpi
-		push @spiargs, ("-t$targetspi", "-d\/$thisdir", "-hide@hidedatainspi");
+		push @spiargs, ("-t$targetspi", "-d$thisdir", "-hide@hidedatainspi");
 		if($existingspi ne "") { push @spiargs, $existingspi; }
 		&spitool::createSpi(@spiargs, @dataforspi); # external call to 
 	}
@@ -2702,7 +2705,7 @@
                                         while(defined $spiarray[$imageIdx][$spiIdx]) {
                                                 if($spiarray[$imageIdx][$spiIdx]{spifile} =~ /(.+)\.(.*)$/) {
                                                         my $targetspi="$1-$imageIdx-$spiIdx\.$2";
-                                                        push @newobydata, "data=" . "\/$thisdir" . $targetspi . " \"" . $spiarray[$imageIdx][$spiIdx]{spi} . "\"\n";
+                                                        push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[$imageIdx][$spiIdx]{spi} . "\"\n";
                                                 }
                                                 $spiIdx++;
                                         }
@@ -2729,7 +2732,7 @@
 					while(defined $spiarray[0][$k]) {
 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
 							my $targetspi="$1-0-$k\.$2";
-							push @newobydata, "data=" . "\/$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi .  "\"\n";
+							push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi .  "\"\n";
 						}
 						$k++;
 					}
@@ -2739,7 +2742,7 @@
 				while(defined $spiarray[$romimage][$j]) { #put in SPI files for current ROM_IMAGE
 					if($spiarray[$romimage][$j]{spifile} =~ /(.+)\.(.*)$/) {
 						my $targetspi="$1-$romimage-$j\.$2";
-						push @newobydata, "data=" . "\/$thisdir" . $targetspi . " \"" . $spiarray[$romimage][$j]{spidir} . $targetspi .  "\"\n";
+						push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[$romimage][$j]{spidir} . $targetspi .  "\"\n";
 					}
 					$j++;
 				}
@@ -2749,7 +2752,7 @@
 					while(defined $spiarray[0][$k]) {
 						if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
 							my $targetspi="$1-0-$k\.$2";
-							push @newobydata, "data=" . "\/$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
+							push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
 						}
 						$k++;
 					}
@@ -2766,7 +2769,7 @@
 			while(defined $spiarray[0][$k]) {
 				if($spiarray[0][$k]{spifile} =~ /(.+)\.(.*)$/) {
 					my $targetspi="$1-0-$k\.$2";
-					push @newobydata, "data=" . "\/$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
+					push @newobydata, "data=" . "$thisdir" . $targetspi . " \"" . $spiarray[0][$k]{spidir} . $targetspi . "\"\n";
 				}
 				$k++;
 			}
@@ -2940,7 +2943,7 @@
 			my $j=0;
 			while(defined $featurefilearray[$i][$j])
 			{
-				my $targetfeaturefile = $featurefilearray[$i][$j]{cfgfile};
+				my $targetfeaturefile = $thisdir.$featurefilearray[$i][$j]{cfgfile};
 				if (!(&featuresutil::createFeatureFile($i,$j,$targetfeaturefile,\@featureslist,$featuremanager))) 
 				{
 					$featurefilearray[$i][$j]{cfgfile}= undef;
@@ -2971,7 +2974,7 @@
 						my $targetfeaturefile=$featurefilearray[0][$k]{cfgfile};
 						if (defined $targetfeaturefile) 
 						{
-							push @newobydata, "data=" . "\/$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile .  "\"\n";							
+							push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile .  "\"\n";							
 						}
 						$k++;
 					}
@@ -2994,7 +2997,7 @@
 
 					if (defined $targetfeaturefile)
 					{
-						push @newobydata, "data=" . "\/$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[$romimage][$j]{cfgdir} . $destinationfeaturefile .  "\"\t\t" . $exattribute . "\n";
+						push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[$romimage][$j]{cfgdir} . $destinationfeaturefile .  "\"\t\t" . $exattribute . "\n";
 					}
 					$j++;
 				}
@@ -3015,7 +3018,7 @@
 				my $targetfeaturefile = $featurefilearray[0][$k]{cfgfile};
 				if (defined $targetfeaturefile)
 				{
-					push @newobydata, "data=" . "\/$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile . "\"\n";
+					push @newobydata, "data=" . "$thisdir" . $targetfeaturefile . " \"" . $featurefilearray[0][$k]{cfgdir} . $targetfeaturefile . "\"\n";
 				}
 				$k++;
 			}
@@ -3128,14 +3131,6 @@
 				}
 				last if $fileExists;
 			}
-			# for -workdir option, to support relative path to the call path
-			if (!$fileExists && ($invokecmddir ne "") && ($filename !~ /^([\\\/]|.:)/))
-			{
-				if (-e $invokecmddir.$filename)
-				{
-					$fileExists = $invokecmddir.$filename;
-				}
-			}
 			
 			# edit the OBY line to use the actual file name which we found.
 			# (maybe) warn if an alternative to the original was selected.
@@ -3160,7 +3155,7 @@
 				# it is a manatory ROMBUILD keyword, in which case it is better
 				# to let ROMBUILD report the missing file rather than report the
 				# missing keyword.
-   				if ($what !~ /^bootbinary|variant|primary|secondary|hide/i)
+   				if ($what !~ /^bootbinary|variant|primary|secondary|hide|dir/i)
 				{
    					$line = "REM MISSING " . $line;
    					print_source_error("Missing file: '$filename' in statement '$what='");
@@ -3502,6 +3497,10 @@
 	{
 		return $line;
 	}
+	elsif($line =~ /^\s*dir\s*=.*/i)
+	{
+		return $line;
+	}
 	elsif($line =~ /^\s*bootbinary\s*=(.*)/i)
 	{
 	}
@@ -3521,7 +3520,8 @@
 		$romfile = $4;
 		$tail = $5;
 	}
-	elsif ($line =~ /(\S+)\s*=\s*"([^"]+)"\s+"\/?(.*)"(.*)$/)
+	elsif ($line =~ /(\S+)\s*=\s*"([^"]+)"\s+"\/?(.*)"(.*)$/ 
+			|| $line =~ /(\S+)\s*=\s*"([^"]+)"\s+\/?(\S+)(.*)$/)
 	{
 		if ($line !~ /^REM MISSING/i)
 		{
@@ -3810,8 +3810,8 @@
 	
     if($opt_v)
     {
-	  my $logWin = "logwin.oby";
-	  my $logLinux = "loglinux.oby";
+	  my $logWin = $thisdir."logwin.oby";
+	  my $logLinux = $thisdir."loglinux.oby";
 	  unlink($logWin);
 	  unlink($logLinux);
 	  open LOGWIN, ">$logWin" or die("* Can't create $logWin\n");
@@ -3847,7 +3847,7 @@
 		#
 		# Track ROMNAME, allowing overrides
 		#
-		if ($line=~/romname\s*=\s*"?(\S+)\.(\S+)"?\s*/i)
+		if ($line=~/romname\s*[=\s]\s*"?(\S+)\.(\S+)"?\s*/i)
 		{
 			if ($romname ne "" && $opt_o eq "")
 			{
@@ -3855,6 +3855,11 @@
 			}
 			$rombasename = $1;
 			$romname = "$1.$2";
+			if ($opt_workdir)
+			{
+				$rombasename = $thisdir.$rombasename;
+				$romname = $thisdir.$romname;
+			}
 			next;
 		}
 		#
@@ -3899,6 +3904,17 @@
 	# Handle ROMNAME and possible -o override
 	if ($opt_o ne "")
 	{
+		if ($opt_workdir && $opt_o !~ /^[\\\/]/ && $opt_o !~ /^.:/)
+		{
+			$opt_o = $thisdir.$opt_o;
+		}
+		if (&is_windows)
+		{
+			$opt_o =~ s-\/-\\-g;
+		}else
+		{
+			$opt_o =~ s-\\-\/-g;
+		}
 		$romname=$opt_o;
 		if ($opt_o=~/(\S+)\.(\S+)/)
 		{
@@ -4669,7 +4685,7 @@
 			}
 			if( $aDllFile =~ /(.*)\.[^.]+$/ ){
 				my $proxydsofile = "$1.dso";
-				$proxydsofile =~ s-$abiDir\/(.*)\/-armv5\/LIB\/-ig;
+				$proxydsofile =~ s-$abiDir\/(.*)\/-armv5\/lib\/-ig;
 				open PIPE, "getexports -d $proxydsofile|" or die "Can't open file $proxydsofile\n";
 				while (<PIPE>){
 					my $line = $_;