toolsandutils/productionbldtools/BAK/BuildBAK.pl
changeset 0 83f4b4db085c
child 10 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 #!perl
       
     2 
       
     3 # BuildBAK.pl
       
     4 
       
     5 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     6 # All rights reserved.
       
     7 # This component and the accompanying materials are made available
       
     8 # under the terms of "Eclipse Public License v1.0"
       
     9 # which accompanies this distribution, and is available
       
    10 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    11 #
       
    12 # Initial Contributors:
       
    13 # Nokia Corporation - initial contribution.
       
    14 #
       
    15 # Contributors:
       
    16 #
       
    17 # Description:
       
    18 # Version Info:
       
    19 # Version 001: initial version
       
    20 # 
       
    21 #
       
    22 
       
    23 use strict;
       
    24 use File::Copy; 
       
    25 use Getopt::Long;
       
    26 use Cwd;
       
    27 
       
    28 
       
    29 # ------------------------------------- Global variables -----------------------------------
       
    30 
       
    31 
       
    32 my $DevKitPackagesDirectory = "";
       
    33 my $TargetDirectory = "";
       
    34 my $SrcDefFile = "";
       
    35 my $KitBuildID = "";
       
    36 my $Version="";
       
    37 my $oldLayoutIntroPages = 0; # FALSE
       
    38 
       
    39 # start the program
       
    40 main();
       
    41 
       
    42 
       
    43 
       
    44 
       
    45 
       
    46 # --------------------------------- Start of SearchAndReplace() ----------------------------
       
    47 #
       
    48 # Parameters: <search string> <replace string> <old file name> <new file name>
       
    49 sub SearchAndReplace($$$$)
       
    50 {
       
    51 	# read in file
       
    52 	open (FILE, "<$_[2]") or die "Couldn't open file $_[2]";
       
    53 	my @file = <FILE>;
       
    54 	close(FILE);
       
    55 
       
    56 	if ($_[3] eq $_[2])
       
    57 	{
       
    58 		unlink($_[2]);
       
    59 	}
       
    60 		
       
    61 
       
    62 	open (FILE, ">$_[3]") or die "Couldn't create file $_[3]";
       
    63 	
       
    64 	foreach my $line (@file)
       
    65 	{
       
    66 		$line =~ s/$_[0]/$_[1]/gi ;
       
    67     		print FILE $line ;
       
    68 	}
       
    69 	close(FILE);
       
    70 }
       
    71 
       
    72 
       
    73 # --------------------------------- CommandLineInterface() ----------------------------------------
       
    74 
       
    75 
       
    76 sub CommandLineInterface()
       
    77 {
       
    78 	my $help;
       
    79 	if ( (GetOptions( "devkit|d=s" => \$DevKitPackagesDirectory,
       
    80 			  "target|t=s" => \$TargetDirectory,
       
    81 			  "help|h|?" => \$help,
       
    82 			  "srcdef|s=s" => \$SrcDefFile,
       
    83 			  "version|v=s" => \$Version,
       
    84 			  "kitbuildid|k=s" => \$KitBuildID ) == 0 ) || ($help == 1) )
       
    85 	{
       
    86 		Usage();
       
    87 		exit; 
       
    88 	}
       
    89 
       
    90 
       
    91 	# check values received
       
    92 
       
    93 	# check that DevKit is in stated directory, exit if not found
       
    94 	my @Packages = <$DevKitPackagesDirectory/com.symbian.devkit.*.sdkpkg>;
       
    95 	if ( scalar(@Packages) == 0 )
       
    96 	{
       
    97 		die "DevKit packages not found in directory: $DevKitPackagesDirectory\n";
       
    98 	}
       
    99 
       
   100 
       
   101 	# check that target location to write extracted files to exists
       
   102 	while ( (substr($TargetDirectory, -1, 1) eq '\\') || (substr($TargetDirectory, -1, 1) eq '/') )
       
   103 	{
       
   104 		chop($TargetDirectory); 		# remove final backslashes
       
   105 	}	
       
   106 	if (! -e $TargetDirectory) 
       
   107 	{
       
   108 		mkdir $TargetDirectory;
       
   109 	}
       
   110 	
       
   111 	
       
   112 	# check that srcdef (*.srcdef) file exists
       
   113 	if ( ($SrcDefFile ne "") && (! -e $SrcDefFile) )
       
   114 	{
       
   115 		die ".srcdef file not found at: $SrcDefFile\n";
       
   116 	}
       
   117 
       
   118 
       
   119 	# check that version has been specified
       
   120 	if ($Version eq "") 
       
   121 	{
       
   122 		die "Version number undefined\n";
       
   123 	}
       
   124 
       
   125 }
       
   126 
       
   127 # --------------------------------- Usage() ----------------------------------------
       
   128 
       
   129 sub Usage()
       
   130 {
       
   131 	print <<ENDOFUSAGETEXT;
       
   132 	
       
   133 BUILDBAK.PL    Version 1.0    Copyright (c) 2005 Symbian Software Ltd
       
   134                               All rights reserved
       
   135                                   
       
   136 Usage:
       
   137   perl BuildBAK.pl  [options]
       
   138  
       
   139 where options are:
       
   140   -d[evkit] <path>        path to directory containing DevKit packages
       
   141   -k[itbuildID] <ID>      Kit build ID (e.g. 03651b_Symbian_OS_v9.1 or 02407 (v7.0s))
       
   142   -s[rcdef] <path>        full path and file name for the .srcdef file
       
   143   -t[arget] <path>        path to directory to build BAK into
       
   144   -v[ersion] <number>     Symbian OS version number (e.g. 7.0s or 9.1)
       
   145    
       
   146 ENDOFUSAGETEXT
       
   147 }
       
   148 
       
   149 # --------------------------------- Start of CopyPreBuiltPackagesAndInstaller() ----------------------------------------
       
   150 
       
   151 sub CopyPreBuiltPackagesAndInstaller($$)
       
   152 {
       
   153 	# underscore required at end of filenames which may be ambiguous (i.e.  com.symbian.bin.GT-arm_ and  com.symbian.bin.GT-arm-data_)
       
   154 	my @Files=(	"com.symbian.api.GT-arm_",
       
   155 			"com.symbian.api.GT-restricted_",
       
   156 			"com.symbian.api.GT-shared_",
       
   157 			"com.symbian.api.GT-winscw_",
       
   158 			"com.symbian.api.GT-wins_",
       
   159 			"com.symbian.api.TechView-arm_",
       
   160 			"com.symbian.api.TechView-restricted_",
       
   161 			"com.symbian.api.TechView-shared_",
       
   162 			"com.symbian.api.TechView-winscw_",
       
   163 			"com.symbian.api.TechView-wins_",
       
   164 			"com.symbian.bin.GT-arm-data_",
       
   165 			"com.symbian.bin.GT-arm_",
       
   166 			"com.symbian.bin.GT-restricted-data_",
       
   167 			"com.symbian.bin.GT-restricted_",
       
   168 			"com.symbian.bin.GT-shared-data_",
       
   169 			"com.symbian.bin.GT-shared_",
       
   170 			"com.symbian.bin.GT-wins-shared_",
       
   171 			"com.symbian.bin.GT-wins-udeb_",
       
   172 			"com.symbian.bin.GT-wins-urel_",
       
   173 			"com.symbian.bin.GT-winscw-shared_",
       
   174 			"com.symbian.bin.GT-winscw-udeb_",
       
   175 			"com.symbian.bin.GT-winscw-urel_",
       
   176 			"com.symbian.bin.TechView-arm-data_",
       
   177 			"com.symbian.bin.TechView-arm_",
       
   178 			"com.symbian.bin.TechView-restricted-data_",
       
   179 			"com.symbian.bin.TechView-restricted_",
       
   180 			"com.symbian.bin.TechView-shared-data_",
       
   181 			"com.symbian.bin.TechView-shared_",
       
   182 			"com.symbian.bin.TechView-wins-shared_",
       
   183 			"com.symbian.bin.TechView-wins-udeb_",
       
   184 			"com.symbian.bin.TechView-wins-urel_",
       
   185 			"com.symbian.bin.TechView-winscw-shared_",
       
   186 			"com.symbian.bin.TechView-winscw-udeb_",
       
   187 			"com.symbian.bin.TechView-winscw-urel_",
       
   188 			"com.symbian.bin.TechView-winscw_",
       
   189 			"com.symbian.bin.TechView-wins_",
       
   190 			"com.symbian.debug.GT-winscw_",
       
   191 			"com.symbian.debug.GT-wins_",
       
   192 			"com.symbian.debug.TechView-winscw_",
       
   193 			"com.symbian.debug.TechView-wins_",
       
   194 			"com.symbian.doc.intro-pages_",
       
   195 			"com.symbian.doc.sdl-cpp-examples_",
       
   196 			"com.symbian.doc.sdl-java-examples_",
       
   197 			"com.symbian.doc.sdl-shared-examples_",
       
   198 			"com.symbian.src.GT-general_",
       
   199 			"com.symbian.src.open_",
       
   200 			"com.symbian.tools.all-arm_",
       
   201 			"com.symbian.tools.all-shared_",
       
   202 			"com.symbian.tools.all-winscw_",
       
   203 			"com.symbian.tools.all-wins_",
       
   204 			"com.symbian.tools.arm_",
       
   205 			"com.symbian.tools.boardsupport_",
       
   206 			"com.symbian.tools.cpp-custom_",
       
   207 			"com.symbian.tools.cpp_",
       
   208 			"com.symbian.tools.java_",
       
   209 			"com.symbian.tools.libraries_",
       
   210 			"com.symbian.tools.shared-custom_",
       
   211 			"com.symbian.tools.shared_",
       
   212 			"com.symbian.tools.winscw_",
       
   213 			"com.symbian.tools.wins_",
       
   214 	# installer
       
   215 			"autorun.inf",
       
   216 			"data1.cab",
       
   217 			"data1.hdr",
       
   218 			"data2.cab",
       
   219 			"ikernel.ex_",
       
   220 			"layout.bin",
       
   221 			"Setup.exe",
       
   222 			"setup.inx",
       
   223 			"ReadMe.html");
       
   224 
       
   225 	print "Checking to see what files need copying...\n";
       
   226 
       
   227 	foreach my $file (@Files)
       
   228 	{
       
   229 		my @fullfilename = <$DevKitPackagesDirectory\\$file*>;
       
   230 		$fullfilename[0] =~ m/([^\\\/]*)$/i;
       
   231 		my $filename = $1;
       
   232 
       
   233 		if (! -e "$TargetDirectory\\$filename") 
       
   234 		{
       
   235 			copy "$DevKitPackagesDirectory\\$filename",  "$TargetDirectory\\$filename";
       
   236 			print "  copied:  $filename\n";
       
   237 		}
       
   238 	}
       
   239 
       
   240 }
       
   241 
       
   242 
       
   243 # --------------------------------- Start of WriteSetupIni() ----------------------------------------
       
   244 
       
   245 
       
   246 sub WriteSetupIni()
       
   247 {
       
   248 	# write setup.ini with current KitID
       
   249 
       
   250 	print "Writing setup.ini...\n";
       
   251 
       
   252 
       
   253 	open (FILE, ">$TargetDirectory\\setup.ini") or die "Couldn't open file $TargetDirectory\\setup.ini";
       
   254 
       
   255 	print FILE "[Startup]\n";
       
   256 	print FILE "FreeDiskSpace=0\n";
       
   257 	print FILE "AppName=Symbian OS Kit Installer\n";
       
   258 	print FILE "[Languages]\n";
       
   259 	print FILE "Default=0x0009\n";
       
   260 	print FILE "count=1\n";
       
   261 	print FILE "key0=0x0009\n";
       
   262 	print FILE "[Symbian]\n";
       
   263 	print FILE "KitID=$KitBuildID\n";
       
   264 	print FILE "TargetDirectory=Symbian\n";
       
   265 	print FILE "DiskSpaceRequirementMessage=Please note that a full installation of the Kit may require up to 2.0Gb of disk space on an NTFS partition or 2.5Gb on a FAT32 partition, in addition to around 500Mb of space in the system Temporary directory.\n";
       
   266 
       
   267 	close(FILE);
       
   268 }
       
   269 
       
   270 # --------------------------------- BuildChangedPackages() ----------------------------------------
       
   271 sub BuildChangedPackages()
       
   272 {
       
   273 	print "Building new packages...\n";
       
   274 
       
   275 	SearchAndReplace("X.X", $Version, "com.symbian.api.StrongCrypto.template", "com.symbian.api.StrongCrypto.pkgdef");
       
   276 	SearchAndReplace("X.X", $Version, "com.symbian.bak.bin.template", "com.symbian.bak.bin.pkgdef");
       
   277 	SearchAndReplace("X.X", $Version, "com.symbian.bak.doc-old.layout.template", "com.symbian.bak.doc.pkgdef") if ($oldLayoutIntroPages);
       
   278 	SearchAndReplace("X.X", $Version, "com.symbian.bak.doc.template", "com.symbian.bak.doc.pkgdef") if (!$oldLayoutIntroPages);
       
   279 	SearchAndReplace("X.X", $Version, "com.symbian.bak.src.template", "com.symbian.bak.src.pkgdef");
       
   280 	SearchAndReplace("X.X", $Version, "com.symbian.bak.tool.template", "com.symbian.bak.tool.pkgdef");
       
   281 
       
   282 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.api.StrongCrypto.pkgdef");
       
   283 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.bak.bin.pkgdef");
       
   284 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.bak.doc.pkgdef");
       
   285 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.bak.src.pkgdef");
       
   286 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.bak.tool.pkgdef");
       
   287 }
       
   288 
       
   289 
       
   290 # --------------------------------- BuildNewNavigationPages() ----------------------------------------
       
   291 
       
   292 
       
   293 sub BuildNewNavigationPages()
       
   294 {
       
   295 	print "Building new navigation pages...\n";
       
   296 
       
   297 	system ("rd [sdkroot] /s/q");
       
   298 
       
   299 	system ("unzip -q -o $DevKitPackagesDirectory\\com.symbian.doc.intro-pages_0_0* -x package.xml");
       
   300 	system ("copy start.html [sdkroot]\\doc");
       
   301 	system ("copy readme.html [sdkroot]\\doc\\documents") if (($Version !~ /^7\./) && ($Version !~ /^8\./)); # for v9 and later
       
   302 	system ("copy aboutdevkit*.gif [sdkroot]\\doc\\Graphics");
       
   303 	SearchAndReplace("X.X", $Version, "com.symbian.doc.intro-pages.template", "com.symbian.doc.intro-pages.pkgdef");
       
   304 	system ("buildpkg.exe -v -f -b $KitBuildID -k $KitBuildID com.symbian.doc.intro-pages.pkgdef");
       
   305 }
       
   306 
       
   307 
       
   308 
       
   309 # --------------------------------- BuildNewSrcDefFile() ----------------------------------------
       
   310 
       
   311 
       
   312 sub BuildNewSrcDefFile()
       
   313 {
       
   314 	SearchAndReplace("%version%", $KitBuildID, "DevKit.srcdef.template", "$KitBuildID.srcdef");
       
   315 }
       
   316 
       
   317 
       
   318 
       
   319 
       
   320 # --------------------------------- Main() ----------------------------------------
       
   321 
       
   322 sub main()
       
   323 {
       
   324 	# N.B. ensure path contains \epoc32\tools;\epoc32\gcc\bin;
       
   325 
       
   326 	CommandLineInterface();
       
   327 
       
   328 
       
   329 	$oldLayoutIntroPages = 1 if ($Version =~ /^7\./) || ($Version =~ /^8\.0/); # set TRUE for v8.0 and previous
       
   330 
       
   331 
       
   332 	# get required pre-built package definitions and installer
       
   333 	CopyPreBuiltPackagesAndInstaller($DevKitPackagesDirectory, $TargetDirectory);
       
   334 
       
   335 
       
   336 	# write the new setup.ini file
       
   337 	WriteSetupIni();
       
   338 
       
   339 
       
   340 	# build changed packages and move to target directory
       
   341 	BuildChangedPackages();
       
   342 
       
   343 
       
   344 	# build new navigation pages 
       
   345 	BuildNewNavigationPages() if (!$oldLayoutIntroPages);
       
   346 
       
   347 
       
   348 	# move changed packages to target directory
       
   349 	foreach my $sdkpkg (<*.sdkpkg>)
       
   350 	{
       
   351 		if (move ($sdkpkg, $TargetDirectory) == 0)
       
   352 		{	print $!; }
       
   353 	}
       
   354 	unlink <*.pkgdef>;
       
   355 
       
   356 
       
   357 	# build srcdef file for this Kit if necessary
       
   358 	my $SrcDefFilePreExisted = 1;
       
   359 	if ($SrcDefFile eq "") 
       
   360 	{
       
   361 		BuildNewSrcDefFile();
       
   362 		my $dir = cwd;
       
   363 		$SrcDefFile = "$dir\\$KitBuildID.srcdef";
       
   364 		$SrcDefFilePreExisted = 0;
       
   365 	}
       
   366 	
       
   367 
       
   368 	# copy the readme.html file and licence text to root of BAK
       
   369 	system ("copy [sdkroot]\\doc\\documents\\readme.html $TargetDirectory") if (!$oldLayoutIntroPages);
       
   370 	system ("copy [sdkroot]\\doc\\packages\\sdl7.0\\intro_pages\\readme.html $TargetDirectory") if ($oldLayoutIntroPages);
       
   371 	system ("copy licence.txt $TargetDirectory");
       
   372 
       
   373 
       
   374 	# create XML package source file
       
   375 	print "Creating XML source file...\n";
       
   376 	chdir $TargetDirectory;
       
   377 	system("createpkgsrc -s \"$SrcDefFile\"");
       
   378 	unlink $SrcDefFile if ($SrcDefFilePreExisted == 0);
       
   379 
       
   380 }
       
   381 
       
   382