imgtools/romtools/rombuild/romnibus.pl
changeset 29 86492ef8d086
parent 27 3a31ca4b29c4
child 31 96678c29f842
equal deleted inserted replaced
28:b8fa7dfeeaa1 29:86492ef8d086
   162 my ($vol,$dirs,$file) = File::Spec->splitpath($cwd);
   162 my ($vol,$dirs,$file) = File::Spec->splitpath($cwd);
   163 my @path_parts = File::Spec->splitdir($dirs);
   163 my @path_parts = File::Spec->splitdir($dirs);
   164 while(@path_parts[-1] ne "sf") {
   164 while(@path_parts[-1] ne "sf") {
   165 	pop(@path_parts);
   165 	pop(@path_parts);
   166 }
   166 }
   167 $e32path = File::Spec->catdir((@path_parts,"os"));
   167 $base_path = File::Spec->catdir((@path_parts,"os"));
   168 $e32path .= ($on_windows ? '\\' : '/');
   168 $rombuildpath = File::Spec->catfile($base_path,"kernelhwsrv","kernel","eka","rombuild");
   169 $base_path = $e32path; # Can't be quite right.
   169 $base_path .= ($on_windows ? '\\' : '/');  
   170 $rombuildpath = File::Spec->catfile($e32path,"kernelhwsrv","kernel","eka","rombuild");
   170 $e32path = ($on_windows ? "\\sf\\os" : "/sf/os"); 
   171 
   171 
   172 use E32Plat;
   172 use E32Plat;
   173 {
   173 {
   174         Plat_Init($toolpath . ($on_windows ? '\\' : '/'));
   174         Plat_Init($toolpath . ($on_windows ? '\\' : '/'));
   175 }
   175 }
   262 	}
   262 	}
   263 } else {
   263 } else {
   264 	$smain=$main;
   264 	$smain=$main;
   265 }
   265 }
   266 
   266 
       
   267 unless ($on_windows) {
       
   268 	$main = lc($main);
       
   269 	$kmain = lc($kmain);
       
   270 }
       
   271 
       
   272 
   267 open(X, "$skel") || die "Can't open type file $skel, $!";
   273 open(X, "$skel") || die "Can't open type file $skel, $!";
   268 open(OUT, "> rom1.tmp") || die "Can't open output file, $!";
   274 open(OUT, "> rom1.tmp") || die "Can't open output file, $!";
   269 
   275 
   270 # First output the ROM name
   276 # First output the ROM name
   271 print OUT "\nromname=$romname\n";
   277 print OUT "\nromname=$romname\n";
   272 while(<X>) {
   278 while(<X>) {
   273 	unless ($on_windows) {
       
   274 		if (m/#include/) {
       
   275 			s|\\|\/|g;
       
   276 		}
       
   277 	}
       
   278 	s/\#\#ASSP\#\#/$opts{'assp'}/;
   279 	s/\#\#ASSP\#\#/$opts{'assp'}/;
   279 	s/\#\#VARIANT\#\#/$opts{'variant'}/;
   280 	s/\#\#VARIANT\#\#/$opts{'variant'}/;
   280 	s/\#\#BUILD\#\#/$opts{'build'}/;
   281 	s/\#\#BUILD\#\#/$opts{'build'}/;
   281 	s/\#\#MAIN\#\#/$main/;
   282 	s/\#\#MAIN\#\#/$main/;
   282 	s/\#\#KMAIN\#\#/$kmain/;
   283 	s/\#\#KMAIN\#\#/$kmain/;
   283 	s/\#\#E32PATH\#\#/$e32path/;
   284 	s/\#\#E32PATH\#\#/$e32path/;
   284 	s/\#\#BASEPATH\#\#/$base_path/;
   285 	s/\#\#BASEPATH\#\#/$base_path/;
   285 	s/\#\#EUSERDIR\#\#/$euserdir/;
   286 	s/\#\#EUSERDIR\#\#/$euserdir/;
   286 	s/\#\#ELOCLDIR\#\#/$elocldir/;
   287 	s/\#\#ELOCLDIR\#\#/$elocldir/;
   287 	s/\#\#KBDIR\#\#/$kbdir/;
   288 	s/\#\#KBDIR\#\#/$kbdir/;
       
   289 	unless ($on_windows) {
       
   290 		if (m/#include/) {
       
   291 			s|\\|\/|g;
       
   292 			lc;
       
   293 		}
       
   294 	}
   288 	print OUT;
   295 	print OUT;
   289 }
   296 }
   290 
   297 
   291 close X;
   298 close X;
   292 close OUT;
   299 close OUT;
   346 $ret = system($cppcmd);
   353 $ret = system($cppcmd);
   347 die "ERROR EXECUTING CPP\n" if $ret;
   354 die "ERROR EXECUTING CPP\n" if $ret;
   348 
   355 
   349 # Purge remarks and blank lines. Complete source filenames and adapt them to host filesystem.
   356 # Purge remarks and blank lines. Complete source filenames and adapt them to host filesystem.
   350 rectify("rom2.tmp", "rom3.tmp", $k);
   357 rectify("rom2.tmp", "rom3.tmp", $k);
   351 
       
   352 
   358 
   353 # scan tmp file and generate auxiliary files, if required
   359 # scan tmp file and generate auxiliary files, if required
   354 open TMP, "rom3.tmp" or die("Can't open rom3.tmp\n");
   360 open TMP, "rom3.tmp" or die("Can't open rom3.tmp\n");
   355 while ($line=<TMP>)
   361 while ($line=<TMP>)
   356 	{
   362 	{
   622 				print OUTPUT_FILE $line;
   628 				print OUTPUT_FILE $line;
   623 			}
   629 			}
   624 		}
   630 		}
   625 		else {
   631 		else {
   626 			# Not blank
   632 			# Not blank
       
   633 			my $epoc32_line = 0;
   627 			$lastblank = 0;
   634 			$lastblank = 0;
   628 			$line =~ s|##||g; # Delete "token-pasting" ops
   635 			$line =~ s|\#\#||g; # Delete "token-pasting" ops
   629 			$line =~ s|//.*$||g; # Delete trailing c++ comments
   636 			$line =~ s|//.*$||g; # Delete trailing c++ comments
   630 			# prefix the epocroot dir to occurrences of 'epoc32' in all "KEYWORD=..." lines.
   637 			# prefix the epocroot dir to occurrences of 'epoc32' in all "KEYWORD=..." lines.
   631 			$line =~ s/(=\s*)[\\\/]epoc32/\1${epocroot}epoc32/i;
   638 			$line =~ s/(=\s*)[\\\/]epoc32/\1${epocroot}epoc32/i;
   632 			if (!defined($1)) { # Not a keyword line.	
   639 			$epoc32_line = defined($1);
       
   640 			if (!$epoc32_line) {
       
   641 				$line =~ /(=.*$epocroot)/i;
       
   642 				$epoc32_line = defined($1);
       
   643 			}
       
   644 			if (!$epoc32_line) {
   633 				if ($k and $line=~/^\s*kerneltrace/i) {
   645 				if ($k and $line=~/^\s*kerneltrace/i) {
   634 					$line = "kerneltrace $k\n";
   646 					$line = "kerneltrace $k\n";
   635 				}
   647 				}
   636 			}
   648 			}
       
   649 			elsif ($on_windows) {
       
   650 				$line =~ s|\/|\\|g;
       
   651 			}
   637 			elsif ($line =~ /^(\s*\S+\s*=\s*)(\S+)(\s*\S*)/) {
   652 			elsif ($line =~ /^(\s*\S+\s*=\s*)(\S+)(\s*\S*)/) {
   638 				if ($on_windows) {
   653 				my $keyword_part = $1;
   639 					$line =~ s|\/|\\|g;
   654 				my $src = $2;
       
   655 				my $dest = $3;
       
   656 				$dest =~ s/^\s+//;
       
   657 				$dest =~ s/\s+$//;
       
   658 				$src =~ s|\\|\/|g;
       
   659 				if ($dest) {
       
   660 					my ($vol,$dir,$leaf) = File::Spec->splitpath($src);
       
   661 					my $lc_leaf = lc($leaf);
       
   662 					my $lc_dir = lc($dir);
       
   663 					$lc_dir =~ s/\/$//;
       
   664 					my $fulldir = $lc_dir;
       
   665 					$fulldir =~ s|//|/|g;
       
   666 					$dest =~ s|\/|\\|g;
       
   667 					$dest = '\\' . $dest, unless ($dest =~ /^\\/);
       
   668 					unless ( -d $fulldir ) {
       
   669 						chomp $line;
       
   670 						# Lower-cased source directory doesn't exist. Give up.
       
   671 						die "Guessed source directory \"$fulldir\" does not exist for line $lineno: \"$line\"\n";
       
   672 					}
       
   673 					if (($leaf eq $lc_leaf) or (-f "$fulldir\/$leaf")) { 
       
   674 						# Using source directory lowercase and source filename as input.
       
   675 						$line = "${keyword_part}${lc_dir}\/${leaf}\t${dest}\n";
       
   676 					}
       
   677 					elsif ( -f "$fulldir\/$lc_leaf") {
       
   678 						# Using source directory source filename both lowercase.
       
   679 						$line = "${keyword_part}${lc_dir}\/${lc_leaf}\t${dest}\n";
       
   680 					}
       
   681 					else { # Harder.
       
   682 						my @dirlist;
       
   683 						my $found = 0;
       
   684 						if (!defined($dir_listings{$fulldir})) {
       
   685 							# Haven't got a cached dir listing for the source directory.
       
   686 							# Make one now.
       
   687 							@dirlist = glob("$fulldir.*");
       
   688 							$dir_listings{$fulldir} = \@dirlist;
       
   689 						}	
       
   690 						@dirlist = @{dir_listings{$fulldir}}; # Get listing of source directory from cache.
       
   691 						foreach my $file (@dirlist) {
       
   692 							# See if any file in the source directory case-insensitively matches the input source file.
       
   693 							if ( (-f "$fulldir\/$file") and (lc($file) eq $lc_leaf)) {
       
   694 								$line = "${keyword_part}${lc_dir}\/${file}\t${dest}\n";
       
   695 								$found = 1;
       
   696 								last;
       
   697 							}
       
   698 						}
       
   699 						unless ($found) {
       
   700 							die "Cannot find any file case-insensitively matching \"$fulldir\/$leaf\" at line $lineno: \"$line\"\n";
       
   701 						}
       
   702 					}
   640 				}
   703 				}
   641 				else {
   704 				else {
   642 					my $keyword_part = $1;
   705 					$line =~ s|\\|\/|g;
   643 					my $src = $2;
   706 				}								
   644 					my $dest = $3;
       
   645 					$src =~ s|\\|\/|g;
       
   646 					if ($dest) {
       
   647 						my ($vol,$dir,$leaf) = File::Spec->splitpath($src);
       
   648 						my $lc_leaf = lc($leaf);
       
   649 						my $lc_dir = lc($dir);
       
   650 						$lc_dir =~ s/\/$//;
       
   651 						my $fulldir = $lc_dir;
       
   652 						$fulldir =~ s|//|/|g;
       
   653 						unless ( -d $fulldir ) {
       
   654 							chomp $line;
       
   655 							# Lower-cased source directory doesn't exist. Give up.
       
   656 							die "Guessed source directory \"$fulldir\" does not exist for line $lineno: \"$line\"\n";
       
   657 						}
       
   658 						if (($leaf eq $lc_leaf) or (-f "$fulldir\/$leaf")) { 
       
   659 							# Using source directory lowercase and source filename as input.
       
   660 							$line = "${keyword_part}${lc_dir}\/${leaf}${dest}\n";
       
   661 						}
       
   662 						elsif ( -f "$fulldir\/$lc_leaf") {
       
   663 							# Using source directory source filename both lowercase.
       
   664 							$line = "${keyword_part}${lc_dir}\/${lc_leaf}${dest}\n";
       
   665 						}
       
   666 						else { # Harder.
       
   667 							my @dirlist;
       
   668 							my $found = 0;
       
   669 							if (!defined($dir_listings{$fulldir})) {
       
   670 								# Haven't got a cached dir listing for the source directory.
       
   671 								# Make one now.
       
   672 								@dirlist = glob("$fulldir.*");
       
   673 								$dir_listings{$fulldir} = \@dirlist;
       
   674 							}	
       
   675 							@dirlist = @{dir_listings{$fulldir}}; # Get listing of source directory from cache.
       
   676 							foreach my $file (@dirlist) {
       
   677 								# See if any file in the source directory case-insensitively matches the input source file.
       
   678 								if ( (-f "$fulldir\/$file") and (lc($file) eq $lc_leaf)) {
       
   679 									$line = "${keyword_part}${lc_dir}\/${file}${dest}\n";
       
   680 									$found = 1;
       
   681 									last;
       
   682 								}
       
   683 							}
       
   684 							unless ($found) {
       
   685 								die "Cannot find any file case-insensitively matching \"$fulldir\/$leaf\" at line $lineno: \"$line\"\n";
       
   686 							}
       
   687 						}
       
   688 					}						
       
   689 				} 
       
   690 			}
   707 			}
   691 			print OUTPUT_FILE $line;
   708 			print OUTPUT_FILE $line;
   692 		}
   709 		}
   693 	}
   710 	}
   694 	close(INPUT_FILE);
   711 	close(INPUT_FILE);
   794 }
   811 }
   795 
   812 
   796 sub lookupSymbolInfo($$)
   813 sub lookupSymbolInfo($$)
   797 {
   814 {
   798 	my ($file, $name) = @_;
   815 	my ($file, $name) = @_;
   799 
       
   800 	open TMP, $file or die "Can't read $file\n";
   816 	open TMP, $file or die "Can't read $file\n";
   801 
   817 
   802 	# ignore local symbols.
   818 	# ignore local symbols.
   803 	while (<TMP>)
   819 	while (<TMP>)
   804 	{
   820 	{