bldsystemtools/commonbldutils/InstallDevKit.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 #!perl
       
     2 
       
     3 # InstallDevKit.pl - Source Code Integration Script
       
     4 
       
     5 # Copyright (c) 1997-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 # Versions:
       
    19 # 1.0  Initial 
       
    20 # 
       
    21 #
       
    22 
       
    23 
       
    24 use strict;
       
    25 use Win32::Registry;
       
    26 use Getopt::Long;
       
    27 use File::Path;
       
    28 use File::Glob;
       
    29 
       
    30 my $Platform = "";
       
    31 
       
    32 
       
    33 # ------------------------------------- Global variables -----------------------------------
       
    34 
       
    35 # main array.  Each element contains:	display text for this option
       
    36 #					list of DevKit packages to be installed by this option
       
    37 
       
    38 
       
    39 my @AllTheOptions=(
       
    40 	["GT source",
       
    41 				["com.symbian.src.GT-general",
       
    42 				"com.symbian.src.GT-restricted-part1",
       
    43 				"com.symbian.src.GT-restricted-part2",
       
    44 				"com.symbian.src.GT-restricted-part3",
       
    45 				"com.symbian.src.GT-restricted-part4",
       
    46 				"com.symbian.src.GT-restricted-part5",
       
    47 				"com.symbian.src.GT-restricted-part6"],
       
    48 				
       
    49 				["com.symbian.src.confidential",
       
    50 				"com.symbian.src.GT-confidential-networking"] ],	
       
    51 
       
    52 				
       
    53 	["UI source",
       
    54 				["com.symbian.src.TechView-restricted",
       
    55 				"com.symbian.src.TechView-general"],
       
    56 				 
       
    57 				["com.symbian.src.TechView-confidential-networking"] ],	
       
    58 
       
    59 
       
    60 	["GT WINS binaries",
       
    61 				["com.symbian.api.GT-restricted",
       
    62 				"com.symbian.api.GT-shared",
       
    63 				"com.symbian.api.GT-wins",
       
    64 				"com.symbian.api.StrongCrypto",
       
    65 
       
    66 				"com.symbian.bin.GT-restricted",
       
    67 				"com.symbian.bin.GT-restricted-data",
       
    68 
       
    69 				"com.symbian.bin.GT-shared",
       
    70 				"com.symbian.bin.GT-shared-data",
       
    71 				
       
    72 				"com.symbian.bin.GT-wins-shared",
       
    73 				"com.symbian.bin.GT-wins-udeb",
       
    74 				"com.symbian.bin.GT-wins-urel",
       
    75 
       
    76 				"com.symbian.bin.StrongCrypto-wins-udeb",
       
    77 				"com.symbian.bin.StrongCrypto-wins-urel",
       
    78 
       
    79 				"com.symbian.debug.GT-wins",
       
    80 				
       
    81 				"com.symbian.tools.cpp",
       
    82 				"com.symbian.tools.cpp-custom",
       
    83 				"com.symbian.tools.java",
       
    84 				"com.symbian.tools.libraries",
       
    85 				"com.symbian.tools.shared",
       
    86 				"com.symbian.tools.shared-custom",
       
    87 				"com.symbian.tools.wins"],
       
    88 				 
       
    89 				["com.symbian.bin.GT-confidential",
       
    90 				"com.symbian.bin.TechView-confidential"] ], 
       
    91 
       
    92 
       
    93 	["GT WINSCW binaries",
       
    94 				["com.symbian.api.GT-restricted",
       
    95 				"com.symbian.api.GT-winscw",
       
    96 				"com.symbian.api.GT-shared",
       
    97 				"com.symbian.api.StrongCrypto",
       
    98 				
       
    99 				"com.symbian.bin.GT-winscw-shared",
       
   100 				"com.symbian.bin.GT-winscw-udeb",
       
   101 				"com.symbian.bin.GT-winscw-urel",
       
   102 
       
   103 				"com.symbian.bin.StrongCrypto-winscw-udeb",
       
   104 				"com.symbian.bin.StrongCrypto-winscw-urel",
       
   105 				
       
   106 				"com.symbian.bin.GT-restricted",
       
   107 				"com.symbian.bin.GT-restricted-data",
       
   108 				
       
   109 				"com.symbian.bin.GT-shared",
       
   110 				"com.symbian.bin.GT-shared-data",
       
   111 				
       
   112 				"com.symbian.debug.GT-winscw",
       
   113 				
       
   114 				"com.symbian.tools.cpp",
       
   115 				"com.symbian.tools.cpp-custom",
       
   116 				"com.symbian.tools.java",
       
   117 				"com.symbian.tools.libraries",
       
   118 				"com.symbian.tools.shared",
       
   119 				"com.symbian.tools.shared-custom",
       
   120 				"com.symbian.tools.winscw"],
       
   121 				 
       
   122 				["com.symbian.bin.GT-confidential",
       
   123 				"com.symbian.bin.TechView-confidential"] ], 
       
   124 
       
   125 	["GT ARM binaries",
       
   126 				["com.symbian.api.GT-restricted",
       
   127 				"com.symbian.api.GT-arm", 
       
   128 				"com.symbian.api.GT-shared",
       
   129 				"com.symbian.api.StrongCrypto",
       
   130 				
       
   131 				"com.symbian.bin.GT-arm",
       
   132 				"com.symbian.bin.GT-arm-data",
       
   133 				
       
   134 				"com.symbian.bin.StrongCrypto-arm",
       
   135 
       
   136 				"com.symbian.bin.GT-restricted",
       
   137 				"com.symbian.bin.GT-restricted-data",
       
   138 				
       
   139 				"com.symbian.bin.GT-shared",
       
   140 				"com.symbian.bin.GT-shared-data",
       
   141 
       
   142 				"com.symbian.bin.GT-romimages",
       
   143 				
       
   144 				"com.symbian.tools.boardsupport",
       
   145 				"com.symbian.tools.cpp",
       
   146 				"com.symbian.tools.cpp-custom",
       
   147 				"com.symbian.tools.java",
       
   148 				"com.symbian.tools.libraries",
       
   149 				"com.symbian.tools.shared",
       
   150 				"com.symbian.tools.shared-custom",
       
   151 				"com.symbian.tools.arm"],
       
   152 				 
       
   153 				["com.symbian.bin.GT-confidential",
       
   154 				"com.symbian.bin.TechView-confidential"] ], 
       
   155 
       
   156 
       
   157 	["UI WINS binaries (needs GT to run)",
       
   158 				["com.symbian.api.TechView-restricted",
       
   159 				"com.symbian.api.TechView-shared",
       
   160 				"com.symbian.api.TechView-wins",
       
   161 
       
   162 				"com.symbian.debug.TechView-wins",
       
   163 
       
   164 				"com.symbian.bin.TechView-wins-shared",
       
   165 				"com.symbian.bin.TechView-wins-udeb",
       
   166 				"com.symbian.bin.TechView-wins-urel",
       
   167 
       
   168 				"com.symbian.bin.Techview-restricted",
       
   169 				"com.symbian.bin.Techview-restricted-data",
       
   170 				"com.symbian.bin.Techview-shared",
       
   171 				"com.symbian.bin.Techview-shared-data",
       
   172 				
       
   173 				"com.symbian.tools.cpp",
       
   174 				"com.symbian.tools.cpp-custom",
       
   175 				"com.symbian.tools.java",
       
   176 				"com.symbian.tools.libraries",
       
   177 				"com.symbian.tools.shared",
       
   178 				"com.symbian.tools.shared-custom",
       
   179 				"com.symbian.tools.wins"],
       
   180 				 
       
   181 				[] ],
       
   182 
       
   183 
       
   184 	["UI WINSCW binaries (needs GT to run)",
       
   185 				["com.symbian.api.TechView-restricted",
       
   186 				"com.symbian.api.TechView-shared",
       
   187 				
       
   188 				"com.symbian.debug.TechView-winscw",
       
   189 				"com.symbian.api.TechView-winscw",
       
   190 
       
   191 				"com.symbian.bin.TechView-winscw-shared",
       
   192 				"com.symbian.bin.TechView-winscw-udeb",
       
   193 				"com.symbian.bin.TechView-winscw-urel",
       
   194 
       
   195 				"com.symbian.bin.Techview-restricted",
       
   196 				"com.symbian.bin.Techview-restricted-data",
       
   197 				"com.symbian.bin.Techview-shared",
       
   198 				"com.symbian.bin.Techview-shared-data",
       
   199 				
       
   200 				"com.symbian.tools.cpp",
       
   201 				"com.symbian.tools.cpp-custom",
       
   202 				"com.symbian.tools.java",
       
   203 				"com.symbian.tools.libraries",
       
   204 				"com.symbian.tools.shared",
       
   205 				"com.symbian.tools.shared-custom",
       
   206 				"com.symbian.tools.winscw"],
       
   207 				 
       
   208 				[] ],
       
   209 
       
   210 
       
   211 	["UI ARM binaries (needs GT to run)",
       
   212 				["com.symbian.api.TechView-arm",
       
   213 				"com.symbian.api.TechView-restricted",
       
   214 				"com.symbian.api.TechView-shared",
       
   215 
       
   216 				"com.symbian.bin.Techview-arm",
       
   217 				"com.symbian.bin.Techview-arm-data",
       
   218 
       
   219 				"com.symbian.bin.Techview-restricted",
       
   220 				"com.symbian.bin.Techview-restricted-data",
       
   221 				"com.symbian.bin.Techview-shared",
       
   222 				"com.symbian.bin.Techview-shared-data",
       
   223 
       
   224 				"com.symbian.bin.Techview-romimages",
       
   225 
       
   226 				"com.symbian.tools.arm",
       
   227 				"com.symbian.tools.boardsupport",
       
   228 				"com.symbian.tools.cpp",
       
   229 				"com.symbian.tools.cpp-custom",
       
   230 
       
   231 				"com.symbian.tools.java",
       
   232 				"com.symbian.tools.libraries",
       
   233 				"com.symbian.tools.shared",
       
   234 				"com.symbian.tools.shared-custom"],
       
   235 				 
       
   236 				[] ],
       
   237 				
       
   238 				
       
   239 				
       
   240 	["Documentation (html, examples, tool and source)",
       
   241 				["com.symbian.doc.intro-pages",
       
   242 				"com.symbian.doc.sdl-connect-examples",
       
   243 				"com.symbian.doc.sdl-core",
       
   244 				"com.symbian.doc.sdl",
       
   245 				"com.symbian.doc.sdl-cpp-examples",
       
   246 				"com.symbian.doc.sdl-java-examples",
       
   247 				"com.symbian.doc.sdl-shared-examples",
       
   248                                 "com.symbian.doc.system"],
       
   249 				 
       
   250 				["com.symbian.src.sdl",
       
   251 				"com.symbian.tools.xbuild"] ]
       
   252 
       
   253 
       
   254 			
       
   255 				 );
       
   256 
       
   257 
       
   258 # Holds list of packages already installed
       
   259 my %InstalledOptions=();
       
   260 
       
   261 
       
   262 my $UserChoices = "";
       
   263 my $DevKitPackagesDirectory = "";
       
   264 my $CustKitPackagesDirectory = "";
       
   265 my $TargetDirectory = "";
       
   266 my $InstallCustKit = "";
       
   267 my $BuildFromClean = 0;
       
   268 
       
   269 # start the program
       
   270 main();
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 # --------------------------------- Start of Main() ----------------------------------------
       
   276 sub main()
       
   277 {
       
   278 	if (@ARGV)
       
   279 	{
       
   280 		CommandLineInterface();
       
   281 	}
       
   282 	else
       
   283 	{
       
   284 		UserInterface();
       
   285 	}
       
   286 
       
   287 
       
   288 	# create target directory (copes with multiple-levels, not possible with unzip)
       
   289 	if ( ! (-e $TargetDirectory) )
       
   290 	{
       
   291 		mkpath ($TargetDirectory);
       
   292 	}
       
   293 
       
   294 
       
   295 	# get user's options & sort numerically
       
   296 	my @ListOfUserChoices = sort { $a <=> $b } split(/ */, $UserChoices);
       
   297 
       
   298 	# install options, ignoring duplicates
       
   299 	for (my $index = 0; $index < scalar(@ListOfUserChoices); $index++ )
       
   300 	{
       
   301 		my $UserChoice = (@ListOfUserChoices)[$index];
       
   302 		
       
   303 		if ( ($index > 0) && ($UserChoice eq (@ListOfUserChoices)[$index-1]) )
       
   304 		{
       
   305 			next;		# duplicate option and already dealt with it
       
   306 		}
       
   307 	
       
   308 		elsif ($UserChoice !~ /\d/)
       
   309 		{
       
   310 			print "\n\nIgnoring unrecognised option '$UserChoice' at index $index.\n";
       
   311 			next;		#invalid option - ignore
       
   312 		}
       
   313 		
       
   314 		
       
   315 		# install the option
       
   316 		print "\n\nInstalling option $UserChoice ($AllTheOptions[$UserChoice]->[0])\n";
       
   317 		InstallOption($UserChoice);
       
   318 	
       
   319 		
       
   320 	}
       
   321 		
       
   322 	
       
   323 
       
   324 	system("rd /q /s $TargetDirectory\\[sdkroot]") if (-e "$TargetDirectory\\[sdkroot]");
       
   325         
       
   326 	
       
   327 	CheckBuildPrerequisites();
       
   328     CheckKSA();
       
   329     CheckSupplementary();
       
   330 
       
   331         #remove target directory at end of Devkit Install
       
   332         print "\n\Removing target directory\n";
       
   333         system("rd /q /s $TargetDirectory");
       
   334         
       
   335         
       
   336 
       
   337 }
       
   338 
       
   339 # --------------------------------- Start of CheckSupplementary() ----------------------------------------
       
   340 
       
   341 
       
   342 sub CheckSupplementary() 
       
   343 {#Call InstallSupplementaryKit.pl to test supplementary packages
       
   344     my $scriptFileSupplementaryKits = "$ENV{ProductPath}\\SupplementaryProducts\\InstallSupplementaryKit.pl";    
       
   345     my $JarFileDir = "$ENV{ProductPath}\\SupplementaryProducts";    
       
   346     my $SuppTargetDirectory = "$TargetDirectory\\SuppKit";
       
   347     
       
   348     if (-e $JarFileDir )  {
       
   349         my @JarFiles = <$JarFileDir\\*.jar>;
       
   350         if ( scalar(@JarFiles) > 0 ) {
       
   351             foreach my $JarFile (@JarFiles) {
       
   352                 system("perl $scriptFileSupplementaryKits -p $Platform -t $SuppTargetDirectory -j $JarFile");
       
   353             }
       
   354         } else {
       
   355             print "Warning: No Supplementary Kits Packages exists in $JarFileDir \n";
       
   356         }
       
   357     } else {
       
   358         print "Warning: Supplementary Kits Path: $JarFileDir do not exist! \n";
       
   359     }
       
   360 }
       
   361 
       
   362 
       
   363 # --------------------------------- Start of CheckKSA() ----------------------------------------
       
   364 
       
   365 
       
   366 sub CheckKSA()
       
   367 {#KSA files added in BuildKit::addKSA(); Only check the existence of Setup.exe
       
   368     my $KSAFile="$DevKitPackagesDirectory\\Setup.exe";
       
   369 	if ( ! ( -e $KSAFile ) ) 
       
   370 	{
       
   371 		print "\n ERROR: KSA files does not exist: $KSAFile\n";
       
   372 		die "ERROR: KSA files does not exist: $KSAFile \n"; 
       
   373 	}
       
   374 }
       
   375 
       
   376 # --------------------------------- Start of CheckBuildPrerequisites() ----------------------------------------
       
   377 
       
   378 
       
   379 sub CheckBuildPrerequisites()
       
   380 # checks target system for:
       
   381 #	Perl 5
       
   382 #	Java
       
   383 #	path environment variables:
       
   384 #		gcc/bin
       
   385 #		epoc32/tools
       
   386 #      	vcvars having been executed (path to link.exe)
       
   387 
       
   388 {
       
   389 	my $DisplayString = "";
       
   390 	
       
   391 	my $RegObj = 0;
       
   392 	my $Value = '';
       
   393 	my $Type = 0;
       
   394 	
       
   395 	my $REG_ACTIVE_PERL = "SOFTWARE\\ActiveState\\ActivePerl";
       
   396 	my $REG_PERL_DIRECTORY = "SOFTWARE\\Perl";
       
   397 	
       
   398 	my $REG_JAVA_RUNTIME	= "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.3";   # look for 1.3
       
   399 	my $REG_JAVA_RUNTIME_HOME = "JavaHome";
       
   400 	my $path = $ENV{"Path"};
       
   401 
       
   402 	
       
   403 	# Check Perl key - should be able to assume it's installed as this is a Perl script!
       
   404 	
       
   405 	# look for directory entry first
       
   406 	if ( ( $HKEY_LOCAL_MACHINE->Open("$REG_PERL_DIRECTORY", $RegObj) ) && ( $RegObj->QueryValueEx("", $Type, $Value) ) )
       
   407 	{
       
   408 		if (! -e $Value)	# { print "  The Perl directory listed in the registry at $Value does not exist\n";  }
       
   409 		{
       
   410 			$DisplayString = $DisplayString . "  Perl installation required\n";
       
   411 		}
       
   412 	}
       
   413 	else
       
   414 	{
       
   415 		$DisplayString = $DisplayString . "  Perl installation required\n";
       
   416 	}
       
   417 	$RegObj->Close(); 
       
   418 
       
   419 
       
   420 	# Check Java key
       
   421 	if ( (! $HKEY_LOCAL_MACHINE->Open("$REG_JAVA_RUNTIME", $RegObj) ) || (! $RegObj->QueryValueEx($REG_JAVA_RUNTIME_HOME, $Type, $Value) ) )
       
   422 	{
       
   423 		$DisplayString = $DisplayString . "  Java 1.3 installation required\n";
       
   424 	}
       
   425 	$RegObj->Close(); 
       
   426 	
       
   427 
       
   428 	
       
   429 	# check whether vcvars has been run (can link.exe be found on path?)
       
   430 	my $success = 0; #FALSE
       
   431 	foreach my $Directory (split(/;/, $path))
       
   432 	{
       
   433 		if ( ( $Directory =~ m/bin/i ) && (-e "$Directory\\link.exe") )
       
   434 		{
       
   435 			$success = 1; #TRUE
       
   436 		}
       
   437 	}
       
   438 	if (!$success) 
       
   439 	{
       
   440 		$DisplayString = $DisplayString . "Run vcvars.bat\n"; 
       
   441 	}
       
   442 	
       
   443 	# print info if anything to show
       
   444 	if ( $DisplayString ne "" )
       
   445 	{
       
   446 		print "\n\nBuild requirements:\n$DisplayString\n";
       
   447 	}
       
   448 
       
   449 
       
   450 
       
   451 
       
   452 }
       
   453 
       
   454 # --------------------------------- Start ofCommandLineInterface() ----------------------------------------
       
   455 
       
   456 
       
   457 sub CommandLineInterface()
       
   458 {
       
   459 	my $help;
       
   460 	if ( (GetOptions( "options|o=s" => \$UserChoices,
       
   461 			  "custkit|c=s" => \$CustKitPackagesDirectory,
       
   462 			  "devkit|d=s" => \$DevKitPackagesDirectory,
       
   463 			  "target|t=s" => \$TargetDirectory,
       
   464 			  "help|h|?" => \$help,
       
   465 			  "buildfromclean|b" => \$BuildFromClean,
       
   466 			  "platform|p=s" => \$Platform ) == 0 ) || ($help == 1) )
       
   467 	{
       
   468 		Usage();
       
   469 		exit; 
       
   470 	}
       
   471 
       
   472 	# check values received
       
   473 	
       
   474 	# user options - exit if not numeric or letter A
       
   475 	if ( $UserChoices !~ m/^[Aa0-8]+$/) 
       
   476 	{
       
   477 		print "\n ERROR: Non-valid option(s) supplied: $UserChoices\n";
       
   478 		die "ERROR: Non-valid option(s) supplied: $UserChoices\n"; 
       
   479 	}
       
   480 	
       
   481 
       
   482 	# check that DevKit is in stated directory, exit if not found
       
   483 	my @Packages = <$DevKitPackagesDirectory//com.symbian.devkit.*.sdkpkg>;
       
   484 	if ( scalar(@Packages) == 0 )
       
   485 	{
       
   486 		print "\n ERROR: DevKit packages not found in directory: $DevKitPackagesDirectory\n";	
       
   487 		die "ERROR: DevKit packages not found in directory: $DevKitPackagesDirectory\n";
       
   488 	}
       
   489 	
       
   490 		
       
   491 
       
   492 	# check that target location to write extracted files to is empty or non-existant
       
   493 
       
   494 	while ( (substr($TargetDirectory, -1, 1) eq '\\') || (substr($TargetDirectory, -1, 1) eq '/') )
       
   495 	{
       
   496 		chop($TargetDirectory); 		# remove final backslashes
       
   497 	}
       
   498 		
       
   499 	my @contents = <$TargetDirectory/*.*>;
       
   500 	if ( ( (-e $TargetDirectory) && (scalar(@contents) > 0) ) || ($TargetDirectory eq "" ) )
       
   501 	{
       
   502 			print "\n ERROR: Non-empty or unspecified target location: $TargetDirectory\n";
       
   503 			die "ERROR: Non-empty or unspecified target location: $TargetDirectory\n";
       
   504 	}
       
   505 	
       
   506 
       
   507 	if ( ($Platform eq "") && ($ENV{'Platform'} eq "") )
       
   508 	{
       
   509 		Usage();
       
   510 		print "\nN.B. -platform required\n";
       
   511 		exit; 
       
   512 	}
       
   513 	elsif ( ($Platform eq "") )
       
   514 	{
       
   515 		$Platform = $ENV{'Platform'} ;
       
   516 	}
       
   517 
       
   518 
       
   519 
       
   520 	
       
   521 	# print values for clarification/logging
       
   522 	print "  Installing options:      $UserChoices \n";
       
   523 	print "  DevKit in directory:     $DevKitPackagesDirectory \n";
       
   524 	print "  Installing to directory: $TargetDirectory \n";
       
   525 
       
   526 
       
   527 	# convert A in user options to numbers(after displaying)
       
   528 	$UserChoices =~ s/[aA]/012345678/g;
       
   529 
       
   530 }
       
   531 
       
   532 
       
   533 # --------------------------------- Start of UserInterface() ----------------------------------------
       
   534 
       
   535 
       
   536 sub UserInterface()
       
   537 {
       
   538 	print "\n------------------------------------------------------\n\n";
       
   539 	my $index = 0;
       
   540 	while ($index < scalar(@AllTheOptions))
       
   541 	{
       
   542 		# display option number and text for this option
       
   543 		print $index . ".  ".$AllTheOptions[$index]->[0]."\n";
       
   544 		$index++;
       
   545 	}
       
   546 
       
   547 	print "\n------------------------------------------------------\n\n";
       
   548 	
       
   549 	# get user's choice - must be numeric or 'A' for all
       
   550 	do
       
   551 	{
       
   552 		print "Enter option numbers to install (no separator) or A for [A]ll: ";
       
   553 		chomp($UserChoices = <STDIN>);
       
   554 		if ($UserChoices =~ m/[aA]/)
       
   555 		{
       
   556 			$UserChoices = "012345678";
       
   557 		}
       
   558 	} while ($UserChoices =~ m/[^\d]/)	;
       
   559 			
       
   560 	
       
   561 	# check that Kit is in this directory
       
   562 	my @Packages = <com.symbian.devkit.*.sdkpkg>;
       
   563 	while ( scalar(@Packages) == 0 )
       
   564 	{
       
   565 		# if not, get location of the packages
       
   566 		print "Enter path to the DevKit's packages (*.sdkpkg files) : ";
       
   567 		chomp( $DevKitPackagesDirectory = <STDIN> );
       
   568 		@Packages = <$DevKitPackagesDirectory//com.symbian.devkit.*.sdkpkg>
       
   569 	}
       
   570 	
       
   571 	
       
   572 	
       
   573 
       
   574 	# get location to write extracted files to
       
   575 	print "Enter directory to extract files to (must be new or empty): ";
       
   576 
       
   577 	my $invalid = 1; #TRUE
       
   578 
       
   579 	do	# ensure directory doesn't exist or is empty
       
   580 	{
       
   581 		chomp( $TargetDirectory = <STDIN> );
       
   582 		while ( (substr($TargetDirectory, -1, 1) eq '\\') || (substr($TargetDirectory, -1, 1) eq '/') )
       
   583 		{
       
   584 			chop($TargetDirectory); 		# remove final backslashes
       
   585 		}
       
   586 		
       
   587 		my @contents = <$TargetDirectory/*.*>;
       
   588 		if ( $invalid = ( (-e $TargetDirectory) && (scalar(@contents) > 0) ) || ($TargetDirectory eq "" ) )
       
   589 		{
       
   590 			print "Invalid selection - enter the name of an empty or new directory : ";
       
   591 		}
       
   592 	} while ( $invalid ) ;
       
   593 
       
   594 
       
   595 	# get Platform name - try environment, else ask user
       
   596 	if ($ENV{'Platform'} eq "")
       
   597 	{
       
   598 		print "Enter platform name  : ";
       
   599 		chomp( $Platform = <STDIN> );
       
   600 	}
       
   601 	else
       
   602 	{
       
   603 		$Platform = $ENV{'Platform'} ;
       
   604 	}
       
   605 	
       
   606 	
       
   607 	print "\n------------------------------------------------------\n\n";
       
   608 
       
   609 }
       
   610 
       
   611 
       
   612 # --------------------------------- Start of InstallOption() ----------------------------------------
       
   613 
       
   614 sub InstallOption()
       
   615 {
       
   616 	my $Option = $_[0] ;
       
   617 	
       
   618 	# get array of DevKit packages for this option
       
   619 	my $Entry = $AllTheOptions[$Option]->[1];
       
   620 	
       
   621 	
       
   622 	# for each package, call InstallPackage() to install the files
       
   623 	foreach my $Package (@$Entry)
       
   624 	{
       
   625 		if (! $InstalledOptions{$Package})
       
   626 		{
       
   627 			$InstalledOptions{$Package} = $Option ;
       
   628 			print "  Installing  $Package\n";
       
   629 			InstallPackage ( $Option, $Package, );
       
   630 		}
       
   631 		else
       
   632 		{
       
   633 			print "  Already got $Package\n";
       
   634 		}
       
   635 	}
       
   636 }
       
   637 
       
   638 
       
   639 # --------------------------------- Start of InstallPackage() ----------------------------------------
       
   640 
       
   641 sub InstallPackage()
       
   642 {
       
   643 	my $Option = $_[0] ;
       
   644 	my $Package = $_[1] ;
       
   645 	
       
   646 	# ensure package exists & is uniquely identified
       
   647 	
       
   648 	# try in DevKit directory first
       
   649 	my $PackageName = $DevKitPackagesDirectory."\\".$Package."_*sdkpkg";
       
   650 	my @Packages = glob($PackageName);
       
   651 	
       
   652 	# ensure the package exists
       
   653 	if ( scalar(@Packages) == 0 )
       
   654 	{
       
   655 		# not found, so try the CustKit directory
       
   656 		$PackageName = $CustKitPackagesDirectory."\\".$Package."_*sdkpkg";
       
   657 		@Packages = glob($PackageName);
       
   658 		if ( scalar(@Packages) == 0 )
       
   659 		{
       
   660 			print "\n ERROR: Package $Package not found. \n";
       
   661 			die "    ERROR: Package $Package not found. \n";	
       
   662 		}
       
   663 		elsif ( scalar(@Packages) > 1 )
       
   664 		{
       
   665 			print "\n ERROR: Package $Package name matched duplicate CustKit files \n";
       
   666 			die "    ERROR: Package $Package name matched duplicate CustKit files \n";	
       
   667 		}
       
   668 	}
       
   669 	elsif ( scalar(@Packages) > 1 )
       
   670 	{
       
   671 		print "\n ERROR: Package $Package name matched duplicate files \n";
       
   672 		die "    ERROR: Package $Package name matched duplicate files \n";	
       
   673 	}
       
   674 
       
   675 	
       
   676 	# now able to start reading package & copying files
       
   677 	
       
   678 	if (-e $Packages[0]) 
       
   679 	{
       
   680      
       
   681 		system("unzip -q -o $Packages[0] -x package.xml -d \"$TargetDirectory\"");
       
   682                 
       
   683 	}
       
   684 
       
   685 }	
       
   686 	
       
   687 	
       
   688 
       
   689 
       
   690 
       
   691 
       
   692 
       
   693 
       
   694 # -------------------------- Start of makepath() ------------------------------
       
   695 
       
   696 sub makepath($)
       
   697 	{
       
   698 	my ($path) = @_;
       
   699 
       
   700 	if (-d $path)
       
   701 		{
       
   702 		return -1;
       
   703 		}
       
   704 	else
       
   705 		{
       
   706 		return mkpath($path);
       
   707 		}
       
   708 	}
       
   709 
       
   710 
       
   711 # --------------------------------- Start of Usage() ----------------------------------------
       
   712 
       
   713 sub Usage()
       
   714 {
       
   715 	print <<ENDOFUSAGETEXT;
       
   716 	
       
   717 INSTALLCUSTKIT.PL    Version 1.3    Copyright (c) 2002, 2003 Symbian Ltd
       
   718                                     All rights reserved
       
   719                                   
       
   720 Usage:
       
   721   perl InstallCustKit.pl  [options]
       
   722  
       
   723 where options are:
       
   724   -b[uildfromclean]       combine unpacked files into build from clean location
       
   725   -c[ustkit] <path>       path to directory containing CustKit packages
       
   726   -d[evkit] <path>        path to directory containing DevKit packages
       
   727   -o[ptions] 012345678A   functionality options (A selects all)
       
   728   -p[latform] <platform>  build platform - used to create binaries installation directory path
       
   729   -t[arget] <path>        path to directory to unpack Kit into
       
   730    
       
   731 ENDOFUSAGETEXT
       
   732 }