sbsv1_os/e32toolp/platform/e32variant.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2004-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 package E32Variant;
       
    17 
       
    18 require Exporter;
       
    19 
       
    20 @ISA = qw(Exporter);
       
    21 
       
    22 @EXPORT = qw(Variant_GetMacroList Variant_GetMacroHRHFile Variant_GetMacro);
       
    23 
       
    24 use strict;
       
    25 use Pathutl;
       
    26 
       
    27 # using $FindBin::Bin to figure out the location of the epoc32\tools directory as 
       
    28 # IDE doesn't understand env{EPOCROOT}
       
    29 
       
    30 my $PerlBinPath;	# fully qualified pathname of the directory containing this script
       
    31 
       
    32 BEGIN {
       
    33 	require 5.005_03;		# check user has a version of perl that will cope
       
    34 	$PerlBinPath = $FindBin::Bin;	# X:/epoc32/tools
       
    35 	$PerlBinPath =~ s/\//\\/g;	# X:\epoc32\tools
       
    36 }
       
    37 
       
    38 # get epocroot if it is set
       
    39 my $epocroot = $ENV{EPOCROOT};
       
    40 my $toolspath;
       
    41 
       
    42 #if epocroot is not set figure it out
       
    43 if(!$epocroot){
       
    44     $epocroot = $PerlBinPath . "\\..\\..\\" ; #infer epocroot
       
    45     $toolspath = $PerlBinPath;
       
    46 }else{
       
    47     $toolspath = $epocroot . "epoc32\\tools\\";
       
    48 }
       
    49 
       
    50 $epocroot=~s/^(.:)//io;    # remove drive letter
       
    51 $epocroot=&Path_Strip($epocroot); # collapse
       
    52 
       
    53 my $cfgFile =  $toolspath . "variant\\variant.cfg"; # default location
       
    54 $cfgFile =~ /^(.:)/i; # match the drive
       
    55 my $MacroHRHLocation_Drive = lc($1); # save the drive 
       
    56 
       
    57 sub Variant_GetMacroHRHFile{
       
    58     my $file;
       
    59     if(-e $cfgFile){
       
    60 	open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n";
       
    61 	while (<FILE>) {
       
    62 	    # strip comments
       
    63 	    s/^([^#]*)#.*$/$1/o;
       
    64 	    # skip blank lines
       
    65 	    if (/^\s*$/o) {
       
    66 		next;
       
    67 	    }
       
    68 	    # get the hrh file
       
    69 	    if($_ =~ /\.hrh/xi){
       
    70 		$file = $_; 
       
    71 		last;
       
    72 	    }
       
    73 	}
       
    74 	close FILE;
       
    75 	die "\nERROR: No variant file specified in $cfgFile!\n" unless $file;
       
    76 	$file =~ s/\s+//g;
       
    77 	$file=~s/^(.:)//io;    # remove drive letter
       
    78 	my $paths_drive = lc($1);
       
    79 
       
    80 	$file = Path_MakeEAbs($epocroot."EPOC32\\", $epocroot, $file); # assume relative to EPOCROOT
       
    81 
       
    82 	if($paths_drive){
       
    83 	    die "\nERROR: Variant file specified in $cfgFile is not on the same drive as \\epoc32\\\n" 
       
    84 		unless ($paths_drive eq $MacroHRHLocation_Drive);
       
    85 	}
       
    86 	if(!(-e $file)) {
       
    87 	    die "\nERROR: $cfgFile specifies $file which doesn't exist!\n";
       
    88 	}
       
    89 
       
    90 	# make sure it is in dos syntax
       
    91 	$file=~ s/\//\\/g;
       
    92     }
       
    93     return $file;
       
    94 }
       
    95 
       
    96 
       
    97 # returns the variant specific macro definitions as a list
       
    98 sub Variant_GetMacroList{
       
    99 
       
   100     my @macros = ();
       
   101     my $vfile = Variant_GetMacroHRHFile();
       
   102     
       
   103     if($vfile)
       
   104     {
       
   105 	my $VariantFilePath = Path_Split('Path',$vfile);
       
   106 	chop( $VariantFilePath );
       
   107 	$VariantFilePath = &Path_PrefixWithDriveAndQuote($VariantFilePath);
       
   108 	$vfile = &Path_PrefixWithDriveAndQuote($vfile);
       
   109 	my $e32Path = &Path_PrefixWithDriveAndQuote($epocroot."epoc32\\include");
       
   110 	
       
   111 	open CPPPIPE,"cpp -I $e32Path -I $VariantFilePath -undef -dM $vfile |" or die "ERROR: Can't invoke CPP.EXE\n";
       
   112 	while(<CPPPIPE>){
       
   113 	    if($_ =~ /(\#define)(\s+)(.+)/){
       
   114 		push @macros, $3;
       
   115 	    }
       
   116 	}
       
   117 	close CPPPIPE;
       
   118     }
       
   119     return @macros;
       
   120 }
       
   121 
       
   122 sub Variant_GetMacro{
       
   123 
       
   124     my $file;
       
   125     if(-e $cfgFile){
       
   126 	open(FILE, $cfgFile) || die "\nCould not open: " . $cfgFile ."\n";
       
   127 	while (<FILE>) {
       
   128 	    # strip comments
       
   129 	    s/^([^#]*)#.*$/$1/o;
       
   130 	    # skip blank lines
       
   131 	    if (/^\s*$/o) {
       
   132 		next;
       
   133 	    }
       
   134 	    # get the hrh file
       
   135 	    if($_ =~ /^ENABLE_ABIV2_MODE$/xi){
       
   136 		close FILE;
       
   137 		return 1;
       
   138 	    }
       
   139 	}
       
   140 	close FILE;
       
   141     }
       
   142     return 0;
       
   143 }
       
   144 
       
   145 1;
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 
       
   157