sbsv1/abld/platform/e32variant.pm
author kelvzhu
Mon, 13 Sep 2010 13:11:19 +0800
changeset 640 ac0bbc1e5d79
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Merge sysdeftools's addtion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
package E32Variant;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
require Exporter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
@ISA = qw(Exporter);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
@EXPORT = qw(Variant_GetMacroList Variant_GetMacroHRHFile Variant_GetMacro);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
use Pathutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
# using $FindBin::Bin to figure out the location of the epoc32\tools directory as 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
# IDE doesn't understand env{EPOCROOT}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
my $PerlBinPath;	# fully qualified pathname of the directory containing this script
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
BEGIN {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
	require 5.005_03;		# check user has a version of perl that will cope
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
	$PerlBinPath = $FindBin::Bin;	# X:/epoc32/tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
	$PerlBinPath =~ s/\//\\/g;	# X:\epoc32\tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
# get epocroot if it is set
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
my $epocroot = $ENV{EPOCROOT};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
my $toolspath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
#if epocroot is not set figure it out
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
if(!$epocroot){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
    $epocroot = $PerlBinPath . "\\..\\..\\" ; #infer epocroot
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
    $toolspath = $PerlBinPath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
}else{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
    $toolspath = $epocroot . "epoc32\\tools\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
$epocroot=~s/^(.:)//io;    # remove drive letter
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
$epocroot=&Path_Strip($epocroot); # collapse
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
my $cfgFile =  $toolspath . "variant\\variant.cfg"; # default location
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
$cfgFile =~ /^(.:)/i; # match the drive
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
my $MacroHRHLocation_Drive = lc($1); # save the drive 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
sub Variant_GetMacroHRHFile{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
    my $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
    if(-e $cfgFile){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
	open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
	while (<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
	    # strip comments
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	    s/^([^#]*)#.*$/$1/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
	    # skip blank lines
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
	    if (/^\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
		next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
	    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
	    # get the hrh file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
	    if($_ =~ /\.hrh/xi){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
		$file = $_; 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
		last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
	    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
	close FILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	die "\nERROR: No variant file specified in $cfgFile!\n" unless $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	$file =~ s/\s+//g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	$file=~s/^(.:)//io;    # remove drive letter
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	my $paths_drive = lc($1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
	$file = Path_MakeEAbs($epocroot."EPOC32\\", $epocroot, $file); # assume relative to EPOCROOT
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
	if($paths_drive){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
	    die "\nERROR: Variant file specified in $cfgFile is not on the same drive as \\epoc32\\\n" 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
		unless ($paths_drive eq $MacroHRHLocation_Drive);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
	if(!(-e $file)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
	    die "\nERROR: $cfgFile specifies $file which doesn't exist!\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
	# make sure it is in dos syntax
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
	$file=~ s/\//\\/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
    return $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
# returns the variant specific macro definitions as a list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
sub Variant_GetMacroList{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
    my @macros = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
    my $vfile = Variant_GetMacroHRHFile();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
    
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
    if($vfile)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
    {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
	my $VariantFilePath = Path_Split('Path',$vfile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
	chop( $VariantFilePath );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
	$VariantFilePath = &Path_PrefixWithDriveAndQuote($VariantFilePath);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
	$vfile = &Path_PrefixWithDriveAndQuote($vfile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
	my $e32Path = &Path_PrefixWithDriveAndQuote($epocroot."epoc32\\include");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
	open CPPPIPE,"cpp -I $e32Path -I $VariantFilePath -undef -dM $vfile |" or die "ERROR: Can't invoke CPP.EXE\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
	while(<CPPPIPE>){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
	    if($_ =~ /(\#define)(\s+)(.+)/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
		push @macros, $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
	    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
	close CPPPIPE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
    return @macros;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
sub Variant_GetMacro{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
    my $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
    if(-e $cfgFile){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
	open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
	while (<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
	    # strip comments
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
	    s/^([^#]*)#.*$/$1/o;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
	    # skip blank lines
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
	    if (/^\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
		next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
	    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
	    # get the hrh file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
	    if($_ =~ /^ENABLE_ABIV2_MODE$/xi){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
		close FILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
		return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
	    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
	close FILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
    }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
    return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156