# # Developed by Stéphane Lenclud # Copyright (c) Stéphane Lenclud. All rights reserved. # Visist http://slion.net for update and more. # # Syntax: # perl -S bimerger.pl # #Usage examples: #perl -S bimerger.pl C:\Symbian\9.1\S60_3rd_MR\S60Ex\OpenGLEx C:\Symbian\9.1\S60_3rd_MR\S60Ex\OpenGLEx\all\group #perl -S bimerger.pl C:\Symbian\9.1\S60_3rd_MR\S60Ex\OpenGLEx C:\Symbian\9.1\S60_3rd_MR\S60Ex\OpenGLEx\all\group > C:\Symbian\9.1\S60_3rd_MR\S60Ex\OpenGLEx\all\group\bld.inf #The resulting bld.inf file is printed to STDOUT. # use File::Spec; use Cwd 'abs_path'; use strict; use warnings; my %bldinfSections=( 'prj_exports' => 1, 'prj_mmpfiles' => 2, 'prj_platforms' => 3, 'prj_testexports' => 4, 'prj_testmmpfiles' => 5 ); my $scanDir=$ARGV[0]; #The directory to scan for blf.inf to merge my $newDir=$ARGV[1]; #The directory path for the concatenated bld.inf (to be created) my $templateProjectName; my $newProjectName; $scanDir = File::Spec->rel2abs($scanDir); $newDir = File::Spec->rel2abs($newDir); ($scanDir, $newDir)=File::Spec->no_upwards($scanDir, $newDir); #What's that? Left over I think... #print $scanDir; #print $newDir; my $projectRoot=CommonPath($scanDir,$newDir); die "No common path!!" unless defined $projectRoot; print STDERR "Common path: $projectRoot\n"; #make sure the directory exists unless (-e $scanDir && -d $scanDir) { die "$scanDir does not exists or is not a directory\n"; } my @prjExports=(); my @prjMmpFiles=(); #print "dir $scanDir\\bld.inf /A /S /B"; ### For each bldinf in scan dir my @bldinfs = `dir $scanDir\\bld.inf /A /S /B`; #print @bldinfs; my $file; my @mergedlines=(); foreach $file(@bldinfs) { push(@prjExports,"\n//from $file\n"); push(@prjMmpFiles,"\n//from $file\n"); my $inputFile=$file; die "Can't find base dir!?!" unless $file=~/(.*?)bld.inf$/; my $baseDir=$1; print STDERR "BLD.INF: $file\n"; print STDERR "BASEDIR: $baseDir\n"; #open INPUT, "< $inputFile" or die "Can't read $inputFile\n"; #my @lines = ; #close INPUT; #Use cpp to strip out the comments my @lines = `cpp.exe -undef -nostdinc $inputFile`; #PRJ_MMPFILES #PRJ_EXPORTS my $currentSection=0; #for each file in the current bld.inf foreach my $line(@lines) { #$line=~s/[^\s]*.mmp/../../i; #Check if we are entering a new section if ($line=~/^\s*(PRJ_[a-z]+).*/i) { my $section=lc($1); print STDERR "SECTION: $section\n"; if (defined $bldinfSections{$section}) { $currentSection=$bldinfSections{$section}; } else { die "Undefined section: $section!!!"; $currentSection=0; } } elsif ($currentSection==1) #prj_exports { if ($line=~/\s*([^\s]+)\s*([^\s]+)\s*/) { #export line with specified destination my $source=$1; my $destination=$2; print STDERR "OLD SOURCE: $source\n"; #now convert the source to be relative to the new derictory $source = File::Spec->rel2abs($source,$baseDir); $source = File::Spec->abs2rel($source,$newDir); #destination remains the same #get ride of the drive $source=substr($source,2) if (substr($source,1,1) eq ":"); print STDERR "NEW SOURCE: $source\n"; print STDERR "DESTINATION: $destination\n"; #Add to our export push (@prjExports,"$source $destination\n"); } } elsif ($currentSection==2) #prj_mmpfiles { #We look for mmp if ($line=~/\s*([^\s]+.mmp)\s*/) { #export line with specified destination my $mmp=$1; print STDERR "OLD MMP: $mmp\n"; #now convert the source to be relative to the new derictory $mmp = File::Spec->rel2abs($mmp,$baseDir); $mmp = File::Spec->abs2rel($mmp,$newDir); #get ride of the drive if any $mmp=substr($mmp,2) if (substr($mmp,1,1) eq ":"); print STDERR "NEW MMP: $mmp\n"; #Add to our mmp files push (@prjMmpFiles,"$mmp\n"); } #We look for mk elsif ($line=~/\s*([^\s]+)\s+([^\s]+.mk)\s*/) { my $prefix=$1; my $mk=$2; print STDERR "OLD MK: $mk\n"; #now convert the source to be relative to the new derictory $mk = File::Spec->rel2abs($mk,$baseDir); $mk = File::Spec->abs2rel($mk,$newDir); #destination remains the same #get ride of the drive $mk=substr($mk,2) if (substr($mk,1,1) eq ":"); print STDERR "NEW MK: $mk\n"; #Add to our mmp files push (@prjMmpFiles,"$prefix $mk\n"); } } } #print "$inputFile\n"; #print "$outputFile\n"; } push(@mergedlines,"PRJ_EXPORTS\n"); push(@mergedlines,@prjExports); push(@mergedlines,"PRJ_MMPFILES\n"); push(@mergedlines,@prjMmpFiles); print @mergedlines; exit 0; #################################################################################### # # Determine and return the common part of two paths # If no common part it returns undef # sub CommonPath { my $dir1=$_[0]; my $dir2=$_[1]; my ($volume1,$directories1,$file1) = File::Spec->splitpath( $dir1 ); my ($volume2,$directories2,$file2) = File::Spec->splitpath( $dir2 ); #if not on the same volume nothing in common return undef unless ($volume1 eq $volume2); #debug #print "File: $file1\n"; #print "File: $file2\n"; my @directories1 = File::Spec->splitdir($directories1); my @directories2 = File::Spec->splitdir($directories2); my @commonDirectories =(); #workaround File::Spec behavior push @directories1, $file1; #print @directories1; push @directories2, $file2; #Very ugly workaround to sanitize our arrays of directories (removes empty entries) #obtain a clean array 1 my @dirs1=(); my $i=0; foreach my $dir(@directories1) { unless (!(defined $dir) || ($dir eq "")) { #print "fuck1\n"; #delete $directories1[$i]; push @dirs1, $dir; } $i++; } #obtain a clean array 2 my @dirs2=(); $i=0; foreach my $dir(@directories2) { unless (!(defined $dir) || ($dir eq "")) { #print "fuck2\n"; #delete $directories2[$i]; push @dirs2, $dir; } $i++; } $i=0; foreach my $dir1(@dirs1) { last unless (defined $dirs2[$i]); #stop the loop if ($dir1 eq $dirs2[$i]) { #print "push $dir1\n"; push @commonDirectories, $dir1; } else { #debug #my $tmp=$dirs2[$i]; #print "$dir1 eq $tmp\n"; } $i++; } my $commonDirectories = File::Spec->catdir(@commonDirectories); my $result = File::Spec->catpath($volume1,$commonDirectories); return $result; }