os/kernelhwsrv/kernel/eka/rombuild/romlaunch.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/rombuild/romlaunch.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,131 @@
     1.4 +#! usr\bin\perl
     1.5 +# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +# All rights reserved.
     1.7 +# This component and the accompanying materials are made available
     1.8 +# under the terms of the License "Eclipse Public License v1.0"
     1.9 +# which accompanies this distribution, and is available
    1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +#
    1.12 +# Initial Contributors:
    1.13 +# Nokia Corporation - initial contribution.
    1.14 +#
    1.15 +# Contributors:
    1.16 +#
    1.17 +# Description:
    1.18 +#
    1.19 +
    1.20 +my $KFilename = $0;
    1.21 +$KFilename =~ s/\\romlaunch\.pl$/\\rom.pl/i;
    1.22 +my $KEnvironment="perl";
    1.23 +my $KLauncher="rom.bat";
    1.24 +
    1.25 +# Main
    1.26 +	
    1.27 +if (!defined($ENV{EPOCROOT}))
    1.28 +	{
    1.29 +	# Need to set EPOCROOT
    1.30 +	
    1.31 +	my $devicepath=getDevicesPath();
    1.32 +
    1.33 +	if (!defined($devicepath))
    1.34 +		{
    1.35 +		die "Please set EPOCROOT before launching $KLauncher. Alternatively, install\n".
    1.36 +		  "a the coresidency tools (tools stubs) and set a default device.\n";
    1.37 +		}
    1.38 +
    1.39 +	push @INC, $devicepath;
    1.40 +	push @INC, $devicepath."/perllib";
    1.41 +	require CDevicesCLAccessor;
    1.42 +
    1.43 +	$devicepath=~s/[^\/]+\/?$//; # Remove last path element
    1.44 +	my $deviceObject = New CDevicesCLAccessor($devicepath."/devices.xml");
    1.45 +
    1.46 +	my $deviceName;
    1.47 +
    1.48 +	if (defined($ENV{EPOCDEVICE}))
    1.49 +		{
    1.50 +		# Use EPOCDEVICE as default device
    1.51 +		$deviceName = $ENV{EPOCDEVICE};
    1.52 +		}
    1.53 +	elsif (($deviceObject->getDefaultDevice()) ne "")
    1.54 +		{
    1.55 +		# Use main default device
    1.56 +		$deviceName = $deviceObject->getDefaultDevice($deviceObject);
    1.57 +		}
    1.58 +	else
    1.59 +		{
    1.60 +		die "Please set a default device (using 'devices -setdefault') before using\n".
    1.61 +		  "$KLauncher. Alternatively, you can set EPOCROOT yourself.\n";
    1.62 +		}
    1.63 +	
    1.64 +	if ( ($deviceObject->isValidName($deviceName))
    1.65 +	  || ($deviceObject->isValidAlias($deviceName))
    1.66 +	  )
    1.67 +		{
    1.68 +		# Get path to the epoc32 tree from device
    1.69 +		my $epocroot = $deviceObject->getEpocRoot($deviceName);
    1.70 +
    1.71 +		$epocroot =~ s/^[A-Za-z]://; # Remove leading drive letter
    1.72 +
    1.73 +		# Ensure the correct slashes are present
    1.74 +		$epocroot =~ s/\//\\/g;
    1.75 +		if ($epocroot !~ /\\$/)
    1.76 +			{
    1.77 +			$epocroot = $epocroot."\\";
    1.78 +			}
    1.79 +		
    1.80 +		# Set EPOCROOT
    1.81 +		$ENV{EPOCROOT} = $epocroot;
    1.82 +		}
    1.83 +	else
    1.84 +		{
    1.85 +		die "'$deviceName' is not a recognised device name. If EPOCDEVICE is set, ensure\n".
    1.86 +		  "it is set to a valid device name.\n";
    1.87 +		}
    1.88 +	}
    1.89 +
    1.90 +# Enclose arguments in quote marks if needed
    1.91 +
    1.92 +my @args=@ARGV;
    1.93 +my $index=scalar(@args);
    1.94 +
    1.95 +while ($index > 0)
    1.96 +	{
    1.97 +	$index--;
    1.98 +
    1.99 +	if ($args[$index] =~ /\s/)
   1.100 +		{
   1.101 +		$args[$index] = '"'.$args[$index].'"';
   1.102 +		}
   1.103 +	}
   1.104 +
   1.105 +# Call tool with arguments
   1.106 +
   1.107 +system($KEnvironment." ".$KFilename." ".join(" ",@args));
   1.108 +
   1.109 +# getDevicesPath()
   1.110 +#
   1.111 +# Discover the location of the devices API. They are expected to be found in an installed set of coresidency
   1.112 +# stubs, in the path.
   1.113 +#
   1.114 +# Parameters: None
   1.115 +#
   1.116 +# Returns: The path to the devices API (UNIX style path)
   1.117 +# 
   1.118 +# Dies: If no devices API can be found in the path. 
   1.119 +sub getDevicesPath()
   1.120 +	{
   1.121 +	my $devicepath = undef;
   1.122 +	my $paths = $ENV{PATH};
   1.123 +	$paths =~ s/\\/\//g;
   1.124 +	
   1.125 +	foreach my $path (split(";", $paths))
   1.126 +		{
   1.127 +		if (-e "$path/CDevicesCLAccessor.pm")
   1.128 +			{
   1.129 +			$devicepath=$path;
   1.130 +			}
   1.131 +		}
   1.132 +	
   1.133 +	return $devicepath;
   1.134 +	}