mmtestenv/mmtesttools/Build/mmbuild.pl
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     1 # Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 use strict;
       
    17 use Env qw(EPOCROOT);
       
    18 
       
    19 # literals
       
    20 my $icl_param  =  "-i";
       
    21 my $misc_param =  "-c";
       
    22 my $mmf_param  =  "-m";
       
    23 my $all_param  =  "-f";
       
    24 my $test_param =  "-t";
       
    25 my $testBuild_param = "-b";
       
    26 my $extra_param = "-x";
       
    27 my $keep_param =  "-k";
       
    28 my $gccxml_param = "-g";
       
    29 my $skipMake_param = "-s";
       
    30 
       
    31 my $setup_comm = "setup";
       
    32 my $clean_comm = "clean";
       
    33 my $build_comm = "build";
       
    34 
       
    35 my @known_targets = ("wins", "winscw", "arm4", "armi","armv5", "gccxml", "thumb", "mcot", "misa", "mint");
       
    36 
       
    37 my @Cedar_targets = ("winscw", "armv5");    # gccxml must be added explicitly with -g and even then only build gccxml on main code
       
    38 my @Beech_targets = ("wins", "winscw", "thumb", "mcot");
       
    39 
       
    40 my @default_targets = @Cedar_targets;
       
    41 
       
    42 my @physical_targets = ("mcot", "misa", "mint"); # those we just re-build sound drivers for
       
    43 my $gccxml_target = "gccxml";
       
    44 my $x86gcc_target = "x86gcc";
       
    45 my @stages = ("export", "makefile", "library", "resource", "target", "final");
       
    46 my @tbstages = ("test export", "test makefile", "test library", "test resource", "test target", "test final");
       
    47 my @stagesTakingTarget = ("makefile", "library", "resource", "target", "final",
       
    48                           "test makefile", "test library", "test resource", "test target", "test final");
       
    49 my $eka2IdentifyFile  = "$ENV{EPOCROOT}epoc32\\release\\winscw\\udeb\\winsgui.dll"; # if file present, is EKA2 build
       
    50 my $x86gccIdentifyFile  = "$ENV{EPOCROOT}epoc32\\release\\x86gcc\\udeb\\euser.dll"; # if dir present, x86 environment present
       
    51 
       
    52 my @targets;
       
    53 my $component = ""; # default added later
       
    54 my $extras = "";
       
    55 my $test = "";
       
    56 my $testBuild = "";
       
    57 my $command = "";
       
    58 my $keep = "";
       
    59 my $use_gccxml = "";
       
    60 my $skipMake = "";
       
    61 
       
    62 my $main_mbc = "__main.mbc";
       
    63 my $test_mbc = "__test.mbc";
       
    64 my $testBuild_mbc = "__testBuild.mbc";
       
    65 my $phys_mbc = "__phys.mbc";
       
    66 my $metabld = "metabld";
       
    67 
       
    68 my $targetToolsDir = "..\\..\\..\\..\\..\\TargetTools\\Build";
       
    69 my $TargetToolsExists = 0;
       
    70 if (-d $targetToolsDir)
       
    71 	{
       
    72 	$TargetToolsExists = 1;
       
    73 	print "TargetTools directory exists: $targetToolsDir\n"
       
    74 	}
       
    75 
       
    76 # main:
       
    77 	{
       
    78 	# Process command-line
       
    79 
       
    80 	unless (@ARGV)
       
    81 		{
       
    82 		&Usage();
       
    83 		}
       
    84 
       
    85 	&ReadArgs();
       
    86 
       
    87 	die "EPOCROOT is not set" unless ($EPOCROOT ne "");
       
    88 
       
    89 	$| = 1; # autoflush stdout.
       
    90 
       
    91 	if ($command eq $setup_comm)
       
    92 		{
       
    93 		&Setup();
       
    94 		}
       
    95 	elsif ($command eq $clean_comm)
       
    96 		{
       
    97 		&Clean();
       
    98 		}
       
    99 	elsif ($command eq $build_comm)
       
   100 		{
       
   101 		&Build();
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		die "Unknown command";
       
   106 		}
       
   107 	exit 0;
       
   108 	}
       
   109 
       
   110 #
       
   111 # Subroutines
       
   112 #
       
   113 
       
   114 sub ReadArgs()
       
   115 	{
       
   116 	while (@ARGV)
       
   117 		{
       
   118 		my $param = @ARGV[0]; shift @ARGV; # grab first param and shift along
       
   119 		
       
   120 		if ($param eq "") # ignore blank parameters
       
   121 			{
       
   122 			next;
       
   123 			}
       
   124 
       
   125 		if ($param eq $icl_param || $param eq $misc_param ||
       
   126 		    $param eq $mmf_param || $param eq $all_param)
       
   127 			{
       
   128 			$component = $param;
       
   129 			}
       
   130 		elsif ($param eq $test_param)
       
   131 			{
       
   132 			$test = $param;
       
   133 			}
       
   134 		elsif ($param eq $testBuild_param)
       
   135 			{
       
   136 			$testBuild = $param;
       
   137 			}
       
   138 		elsif ($param eq $extra_param)
       
   139 			{
       
   140 			$extras = $param;
       
   141 			}
       
   142 		elsif ($param eq $keep_param)
       
   143 			{
       
   144 			$keep = $param;
       
   145 			}
       
   146 		elsif ($param eq $gccxml_param)
       
   147 			{
       
   148 			$use_gccxml = $param;
       
   149 			}
       
   150 		elsif ($param eq $skipMake_param)
       
   151 			{
       
   152 			$skipMake = $param;
       
   153 			}
       
   154 		elsif ($param eq $setup_comm || $param eq $clean_comm ||
       
   155 		       $param eq $build_comm)
       
   156 			{
       
   157 			if ($command ne "")
       
   158 				{
       
   159 				&Usage; # scream if we try to state more than one command
       
   160 				}
       
   161 			$command = $param;
       
   162 			}
       
   163 		elsif ($command eq $build_comm)
       
   164 			{
       
   165 			# see if the parameter is one of the list of arguments
       
   166 			my $match = 0;
       
   167 			foreach my $target (@known_targets)
       
   168 				{
       
   169 				if ($target eq $param)
       
   170 					{
       
   171 					$match = 1;
       
   172 					last; # exit loop
       
   173 					}
       
   174 				}
       
   175 			if ($match != 0)
       
   176 				{
       
   177 				$targets[++$#targets] = $param; # append
       
   178 				}
       
   179 			else
       
   180 				{
       
   181 				# was not a valid target
       
   182 				Usage();
       
   183 				}
       
   184 			}
       
   185 		else
       
   186 			{
       
   187 			# unknown setting
       
   188 			&Usage();
       
   189 			}
       
   190 		}
       
   191 	&CheckArgs();
       
   192 	}
       
   193 
       
   194 sub CheckArgs()
       
   195 	{
       
   196 	# check that the arguments make sense
       
   197 	if ($command eq $clean_comm || $command eq $build_comm)
       
   198 		{
       
   199 		# for build and cleanup, can't set the required module
       
   200 		if ($component ne "" || $extras ne "")
       
   201 			{
       
   202 			&Usage;
       
   203 			}
       
   204 		}
       
   205 	# for setup, check -t has not been given
       
   206 	if ($command eq $setup_comm)
       
   207 		{
       
   208 		if ($test ne "")
       
   209 			{
       
   210 			&Usage;
       
   211 			}
       
   212 		}
       
   213 	if ($command eq "")
       
   214 		{
       
   215 		# need to state some command
       
   216 		&Usage;
       
   217 		}
       
   218 	}
       
   219 
       
   220 sub Setup
       
   221 	{
       
   222 	# default settings
       
   223 	if ($component eq "")
       
   224 		{
       
   225 		$component = $all_param;
       
   226 		}
       
   227 	# some boolean values
       
   228 	my $want_mmf = $component eq $mmf_param | $component eq $all_param;
       
   229 	my $want_icl = $component eq $icl_param | $component eq $all_param;
       
   230 	my $want_misc = $component eq $misc_param | $component eq $all_param;
       
   231 	my $want_extra = $extras ne "";
       
   232 	# generate .mbc files and then do bldmake
       
   233 	open(OUTFILE, ">".$main_mbc) or die "Can't create file: $!";
       
   234 	print OUTFILE "//\n//Auto-generated - do not edit!!\n//\n\n";
       
   235 	print OUTFILE "#include \"mmf.mbc\"\n" if ($want_mmf);
       
   236 	print OUTFILE "#include \"icl.mbc\"\n" if ($want_icl);
       
   237 	print OUTFILE "#include \"Misc.mbc\"\n" if ($want_misc);
       
   238 	print OUTFILE "#include \"mmfOpt.mbc\"\n" if ($want_mmf && $want_extra);
       
   239 	print OUTFILE "#include \"iclOpt.mbc\"\n" if ($want_icl && $want_extra);
       
   240 	print OUTFILE "#include \"MiscOpt.mbc\"\n" if ($want_misc && $want_extra);
       
   241 	close OUTFILE;
       
   242 
       
   243 	if ($want_mmf)
       
   244 		{
       
   245 		open(OUTFILE, ">".$phys_mbc) or die "Can't create file: $!";
       
   246 		print OUTFILE "//\n//Auto-generated - do not edit!!\n//\n\n";
       
   247 		print OUTFILE "#include \"mmfPhys.mbc\"\n";
       
   248 		print OUTFILE "#include \"mmfOptPhys.mbc\"\n" if ($want_extra);
       
   249 		close OUTFILE;
       
   250 		}
       
   251 	else
       
   252 		{
       
   253 		# only applicable for mmf - otherwise just delete the file
       
   254 		if (-f $phys_mbc)
       
   255 			{
       
   256 			unlink $phys_mbc or die "Couldn't delete $phys_mbc";
       
   257 			}
       
   258 		}
       
   259 
       
   260 	open(OUTFILE, ">".$test_mbc) or die "Can't create file: $!";
       
   261 	print OUTFILE "//\n//Auto-generated - do not edit!!\n//\n\n";
       
   262 	print OUTFILE "#include \"AllTests.mbc\"\n";
       
   263 	print OUTFILE "#include \"TestFrameworkTest.mbc\"\n";
       
   264 	print OUTFILE "#include \"mmfTest.mbc\"\n" if ($want_mmf);
       
   265 	print OUTFILE "#include \"mmfNotOptTest.mbc\"\n" if ($want_mmf && !$want_extra);
       
   266 	print OUTFILE "#include \"iclTest.mbc\"\n" if ($want_icl);
       
   267 	print OUTFILE "#include \"MiscTest.mbc\"\n" if ($want_misc);
       
   268 	print OUTFILE "#include \"mmfOptTest.mbc\"\n" if ($want_mmf && $want_extra);
       
   269 	print OUTFILE "#include \"iclOptTest.mbc\"\n" if ($want_icl && $want_extra);
       
   270 	print OUTFILE "#include \"MiscOptTest.mbc\"\n" if ($want_misc && $want_extra);
       
   271 	if ($TargetToolsExists)
       
   272 		{
       
   273 		print OUTFILE "#include \"TargetTools.mbc\"\n";
       
   274 		}
       
   275 	close OUTFILE;
       
   276 
       
   277 	open(OUTFILE, ">".$testBuild_mbc) or die "Can't create file: $!";
       
   278 	print OUTFILE "//\n//Auto-generated - do not edit!!\n//\n\n";
       
   279 	print OUTFILE "#include \"mmfTestBuild.mbc\"\n" if ($want_mmf);
       
   280 	print OUTFILE "#include \"iclTestBuild.mbc\"\n" if ($want_icl);
       
   281 	print OUTFILE "#include \"MiscTestBuild.mbc\"\n" if ($want_misc);
       
   282 	print OUTFILE "#include \"mmfOptTestBuild.mbc\"\n" if ($want_mmf && $want_extra);
       
   283 	print OUTFILE "#include \"iclOptTestBuild.mbc\"\n" if ($want_icl && $want_extra);
       
   284 	print OUTFILE "#include \"MiscOptTestBuild.mbc\"\n" if ($want_misc && $want_extra);
       
   285 	close OUTFILE;
       
   286 
       
   287 	# first getmake does bldmake on the main entries
       
   288 	my $sysComm = $metabld . " " . $main_mbc . " bldmake " . $keep . " bldfiles";
       
   289 	my $result = system($sysComm);
       
   290 	if ($result != 0 && $keep eq "")
       
   291 		{
       
   292 		print "Error '$sysComm' failed: $result\n";
       
   293 		exit ($result);
       
   294 		}
       
   295 	my $error = $result;
       
   296 	# second metabld goes through physical
       
   297 	if (-f $phys_mbc)
       
   298 		{
       
   299 		$sysComm = $metabld . " " . $phys_mbc . " bldmake " . $keep . " bldfiles";
       
   300 		$result = system($sysComm);
       
   301 		if ($result != 0 && $keep eq "")
       
   302 			{
       
   303 			print "Error '$sysComm' failed: $result\n";
       
   304 			exit ($result);
       
   305 			}
       
   306 		$error |= $result;
       
   307 		}
       
   308 	# third metabld goes through tests
       
   309 	$sysComm = $metabld . " " . $test_mbc . " bldmake " . $keep . " bldfiles";
       
   310 	$result = system($sysComm);
       
   311 	if ($result != 0 && $keep eq "")
       
   312 		{
       
   313 		print "Error '$sysComm' failed: $result\n";
       
   314 		exit ($result);
       
   315 		}
       
   316 	$error |= $result;
       
   317 	# fourth metabld goes through test build tests - ignore any dups with the above. Does not make any difference
       
   318 	$sysComm = $metabld . " " . $testBuild_mbc . " bldmake " . $keep . " bldfiles";
       
   319 	$result = system($sysComm);
       
   320 	if ($result != 0 && $keep eq "")
       
   321 		{
       
   322 		print "Error '$sysComm' failed: $result\n";
       
   323 		exit ($result);
       
   324 		}
       
   325 	$error |= $result;
       
   326 	if ($error)
       
   327 		{
       
   328   		print "Errors found during run\n";
       
   329 		exit ($error)
       
   330 		}
       
   331 	}
       
   332 
       
   333 sub Clean
       
   334 	{
       
   335 	# first getmake does makefiles on the main entries
       
   336 	# note we generally ignore any errors on this
       
   337 	my $sysComm = $metabld . " " . $main_mbc . " abld " . $keep . " makefile";
       
   338 	system($sysComm);
       
   339 	if (-f $phys_mbc)
       
   340 		{
       
   341 		my $sysComm = $metabld . " " . $phys_mbc . " abld " . $keep . " makefile";
       
   342 		system($sysComm);
       
   343 		}
       
   344 	if ($test eq $test_param)
       
   345 		{
       
   346 		# also do for test files
       
   347 		$sysComm = $metabld . " " . $test_mbc . " abld " . $keep . " makefile";
       
   348 		system($sysComm);
       
   349 		$sysComm = $metabld . " " . $testBuild_mbc . " abld " . $keep . " test makefile";
       
   350 		system($sysComm);
       
   351 		}
       
   352 	my $sysComm = $metabld . " " . $main_mbc . " abld " . $keep . " reallyclean";
       
   353 	system($sysComm);
       
   354 	if (-f $phys_mbc)
       
   355 		{
       
   356 		my $sysComm = $metabld . " " . $phys_mbc . " abld " . $keep . " reallyclean";
       
   357 		system($sysComm);
       
   358 		}
       
   359 	if ($test eq $test_param)
       
   360 		{
       
   361 		# also do for test file
       
   362 		$sysComm = $metabld . " " . $test_mbc . " abld " . $keep . " reallyclean";
       
   363 		system($sysComm);
       
   364 		$sysComm = $metabld . " " . $testBuild_mbc . " abld " . $keep . " test reallyclean";
       
   365 		system($sysComm);
       
   366 		}
       
   367 
       
   368 	}
       
   369 
       
   370 sub Build
       
   371 	{
       
   372 	# defaults
       
   373 	if (!(-f $eka2IdentifyFile)) 
       
   374 	    {
       
   375 		@default_targets = @Beech_targets;
       
   376 	    }
       
   377 
       
   378 	if (@targets == 0)
       
   379 		{
       
   380 		@targets = @default_targets;
       
   381 		}
       
   382 	if ($use_gccxml ne "")
       
   383 		{
       
   384 		$targets[++$#targets] = $gccxml_target; # append		
       
   385 		}
       
   386 	if ((-f $x86gccIdentifyFile)) 
       
   387 	        {
       
   388 		$targets[++$#targets] = $x86gcc_target; # append x86gcc target since Build env present.
       
   389 		}	
       
   390 	# for each target we need to go through each stage
       
   391 	# if -k was given, we make all calls and give error at the end
       
   392 	my $error = 0;
       
   393 	foreach my $target (@targets)
       
   394 		{
       
   395 		# work out which .mbc files to use. Key is as follows
       
   396 		#    in physical targets and not test, __test.mbc
       
   397 		#    in physical targets and test, skip - not currently supported
       
   398 		#    not in physical targets and not test, __main.mbc
       
   399 		#    not in physical targets and test, __test.mbc
       
   400 		my $build_test = $test ne ""; # -t has been given
       
   401 		my $build_testBuild = $test ne "" && $testBuild ne ""; # -t and -b has been given
       
   402 		my $physical_target = 0;
       
   403 		foreach my $phys (@physical_targets)
       
   404 			{
       
   405 			if ($phys eq $target)
       
   406 				{
       
   407 				$physical_target = 1;
       
   408 				last; # exit loop
       
   409 				}
       
   410 			}
       
   411 		my $mbc;
       
   412 		if ($physical_target && !$test)
       
   413 			{
       
   414 			if (-f $phys_mbc)
       
   415 				{
       
   416 				$mbc = $phys_mbc;
       
   417 				}
       
   418 			else
       
   419 				{
       
   420 				# we don't want to do anything - skip to next target
       
   421 				next; 
       
   422 				}
       
   423 			}
       
   424 		elsif ($physical_target && $test)
       
   425 			{
       
   426 			next; # skip to next target
       
   427 			}
       
   428 		elsif (($target eq "gccxml") && $test) # Build GCCXML on the production code only
       
   429 			{
       
   430 			next; # skip to next target
       
   431 			}
       
   432 		elsif (!$physical_target && !$test)
       
   433 			{
       
   434 			$mbc = $main_mbc;
       
   435 			}		
       
   436 		elsif ($test ne "")
       
   437 			{
       
   438 			if (!$testBuild)
       
   439 				{
       
   440 				$mbc = $test_mbc;
       
   441 				}
       
   442 			else
       
   443 				{
       
   444 				$mbc = $testBuild_mbc;
       
   445 				}
       
   446 			}
       
   447 			
       
   448 		# if the target is "wins", then check to see if wins is installed and otherwise just do export
       
   449 		# this is intended to get around Cedar builds not having wins. Really out to check for VC++ too,
       
   450 		# but not clear how
       
   451 		my @reqStages = @stages;
       
   452 		@reqStages = @tbstages if $build_testBuild;
       
   453 		if ($target eq "wins")
       
   454 			{
       
   455 			my $euser_lib = $EPOCROOT . "epoc32\\release\\wins\\udeb\\euser.lib";
       
   456 			if (! -f $euser_lib)
       
   457 				{
       
   458 				print "no WINS installation found - just export\n";
       
   459 				@reqStages = ( "export" );
       
   460 				}
       
   461 			}
       
   462 
       
   463 
       
   464 			
       
   465 		# now the main loop
       
   466 		foreach my $stage (@reqStages)
       
   467 			{
       
   468 			# export does not take target as parameter, others do
       
   469 			my $takesTarget = 0;
       
   470 			foreach my $stage2 (@stagesTakingTarget)
       
   471 				{
       
   472 				if ($stage eq $stage2)
       
   473 					{
       
   474 					$takesTarget = 1;
       
   475 					last; # exit loop
       
   476 					}
       
   477 				}
       
   478 			if (($stage eq "makefile" || $stage eq "test makefile") && $skipMake ne "")
       
   479 				{
       
   480 				print "Skip makefile\n"; 
       
   481 				next; # skip the makefile stage
       
   482 				}
       
   483 			# the command - metabld xxx.mbc command
       
   484 			my $sysComm = $metabld . " " . $mbc .
       
   485 			    " abld " . $keep . " " . $stage;
       
   486 			if ($takesTarget)
       
   487 				{
       
   488 				$sysComm .= " " . $target;
       
   489 				}
       
   490 			my $result = system($sysComm);
       
   491 			if ($result != 0)
       
   492 				{
       
   493 				if ($keep ne "")
       
   494 					{
       
   495 					# remember error and keep going
       
   496 					$error |= $result;
       
   497 					}
       
   498 				else
       
   499 					{
       
   500 					print "Error '$sysComm' failed: $result\n";
       
   501 					exit ($result);
       
   502 					}
       
   503 				}
       
   504 			}
       
   505 		}
       
   506 	if ($error)
       
   507 		{
       
   508   		print "Errors found during run\n";
       
   509 		exit ($error)
       
   510 		}
       
   511 	}
       
   512 
       
   513 sub Usage
       
   514 	{
       
   515 	# print usage statement and exit
       
   516 	print <<ENDHERESTRING;
       
   517 usage:
       
   518 	mmbuild {-i|-e|-m|-f} [-x] [-k] setup
       
   519 	mmbuild [-t] [-k] clean
       
   520 	mmbuild [-t [-b]] [-k] [-g] [-s] build [targets]
       
   521 
       
   522 mmbuild is intended to do a full build of the Multimedia source area, both for
       
   523 use in test builds and by team engineers. The effect will be similar to that
       
   524 achieved for overnight builds, although the mechanism is slight different.
       
   525 
       
   526 In typical usage, the various forms of the command - as given above - are used
       
   527 in turn. "setup" equates roughly to "bldmake bldfiles". It is called to setup
       
   528 the various files prior to the build proper. The parameters are as follows:
       
   529 
       
   530 -i) Build ICL only
       
   531 -m) Build MMF only
       
   532 -c) Build Misc only (other than ICL or MMF)
       
   533 -f) Build all Multimedia components (default)
       
   534 
       
   535 -x) Additionally build any optional components - default is non-optional only
       
   536 
       
   537 "clean" effectively does a reallyclean operation.
       
   538 
       
   539 -t) Clean test code, *as well as* main code - default is to clean main code only
       
   540 
       
   541 "build" does a build operation. Optional parameters give the target list - the
       
   542 default is "wins", "winscw", "arm4" and "mcot". For physical targets, like mcot,
       
   543 only the SoundDev mmf folder is built.
       
   544 
       
   545 -t) Build test code (including testframework), *instead of* main code - default
       
   546 is to build main code only
       
   547 
       
   548 -t) Build test code (including testframework), *instead of* main code 
       
   549     Note: without -b this is test code built via "abld build"
       
   550 
       
   551 -b) When given with -t, build test code that is built via "abld test build"
       
   552 
       
   553 -g) Build code additionally for gccxml. Null operation when used with -t. 
       
   554 
       
   555 -s) Skip the make stage. Use with care - should not be used if any include, 
       
   556 source list or library list have been changed, and never on the first time 
       
   557 called. However, it can save time on a subsequent call.
       
   558 
       
   559 A typical usage sequence would be:
       
   560 	mmbuild setup
       
   561 	mmbuild -t clean
       
   562 	mmbuild build
       
   563 	mmbuild -t build
       
   564 	mmbuild -t -b build
       
   565 
       
   566 which would do a reallyclean and rebuild of the whole Multimedia sub-system,
       
   567 except the mcot sound drivers on EKA1.
       
   568 
       
   569 For each command, the -k flag will try and keep going as much as possible -
       
   570 setup and build, by default, will stop with the first error.
       
   571 ENDHERESTRING
       
   572 	exit 1;
       
   573 	}
       
   574