sbsv1/abld/platform/bpabiutl.pm
changeset 607 378360dbbdba
parent 599 fa7a3cc6effd
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 # Copyright (c) 1997-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 # This package  does various ancillary things for BPABI (Base Platform ABI) platforms
       
    15 # 
       
    16 #
       
    17 
       
    18 package BPABIutl;
       
    19 
       
    20 require Exporter;
       
    21 @ISA=qw(Exporter);
       
    22 @EXPORT=qw(
       
    23 	BPABIutl_Plat_List
       
    24 	BPABIutl_Config_Path
       
    25 	BPABIutl_Get_Config_Variables
       
    26 );
       
    27 
       
    28 use E32Variant;
       
    29 require E32Plat;
       
    30 
       
    31 my %ConfigPath;
       
    32 my $variantABIV2Keyword = &Variant_GetMacro();
       
    33 
       
    34 sub BPABIutl_Plat_List {
       
    35 
       
    36 # Identify the BPABI platforms to be supported based on the compiler configuration files
       
    37 # present in the location specified by the environment variable "SYMBIAN_COMPILATION_CONFIG_DIR"
       
    38 # and in the directory $EPOCROOT\epoc32\tools\compilation_config
       
    39 
       
    40 	my @CompilerConfigPath;
       
    41 
       
    42 	if (exists($ENV{'SYMBIAN_COMPILATION_CONFIG_DIR'})) 
       
    43 	{
       
    44 		my $Path = $ENV{SYMBIAN_COMPILATION_CONFIG_DIR};
       
    45 		@CompilerConfigPath = split(/;/, $Path);
       
    46 	}
       
    47 
       
    48 	push @CompilerConfigPath, "$ENV{EPOCROOT}epoc32\\tools\\compilation_config";
       
    49 
       
    50 	my $ConfigDir;
       
    51 	my @BPABIPlats = ();
       
    52 
       
    53 	foreach $ConfigDir (@CompilerConfigPath)
       
    54 	{
       
    55 		opendir DIR, "$ConfigDir";
       
    56 		my @Plats=grep /\.mk$/i, readdir DIR;
       
    57 		my $Plat;
       
    58 		foreach $Plat (@Plats) 
       
    59 		{
       
    60 # The platform name will be same as the name of the configuration file <config.mk>
       
    61 # with the suffix '.mk' removed
       
    62 			$Plat =~ s/\.mk//;
       
    63 			if ($variantABIV2Keyword) {
       
    64 				if ($Plat =~ /^armv5_abiv2$/i) {
       
    65 					$Plat = "ARMV5";
       
    66 				}
       
    67 			}
       
    68 			else {
       
    69 				if ($Plat =~ /^armv5$/i) {
       
    70 					$Plat = "ARMV5_ABIV2";
       
    71 				}
       
    72 			}
       
    73 			unless (grep /$Plat$/i, @BPABIPlats) {
       
    74 				$Plat = uc $Plat;
       
    75 				push @BPABIPlats, $Plat;
       
    76 				if (!$variantABIV2Keyword && $Plat =~ /^ARMV5_ABIV2$/i) {
       
    77 					$ConfigPath{$Plat} = "$ConfigDir\\ARMV5.mk";
       
    78 				}
       
    79 				else {
       
    80 					$ConfigPath{$Plat} = "$ConfigDir\\$Plat.mk";
       
    81 				}
       
    82 			}
       
    83 		}
       
    84 	}
       
    85 	closedir DIR;
       
    86 	return @BPABIPlats;
       
    87 }
       
    88 
       
    89 sub BPABIutl_Config_Path($) {
       
    90 	my ($plat) = @_;
       
    91 # Returns the Path of the compiler configuration file
       
    92 	if (!keys(%ConfigPath))
       
    93 	{
       
    94 	    # Running for first time so initialise ConfigPath
       
    95 	    BPABIutl_Plat_List();
       
    96 	}
       
    97 	if (!$ConfigPath{$plat})
       
    98 	{
       
    99 		# Get the root platform name to support hierarchy of customizations
       
   100 		my $CustomizedPlat =  &E32Plat::Plat_Root($plat);
       
   101 
       
   102 # In default ABIV1 mode, the platform name for v2 mode of ARMV5 is ARMV5_ABIV2
       
   103 		if ( !$variantABIV2Keyword && $CustomizedPlat =~ /^ARMV5$/i ){
       
   104 			$ConfigPath{$plat} = $ConfigPath{ARMV5_ABIV2};
       
   105 		}
       
   106 
       
   107 # In default ABIV2 mode, the platform name for v2 mode of ARMV5 is ARMV5
       
   108 		elsif ( $variantABIV2Keyword && $CustomizedPlat =~ /^ARMV5$/i) {
       
   109 			$ConfigPath{$plat} = $ConfigPath{ARMV5};
       
   110 		}
       
   111 		else{
       
   112 			$ConfigPath{$plat}=$ConfigPath{$CustomizedPlat};
       
   113 		}
       
   114 	}
       
   115 	return "$ConfigPath{$plat}";
       
   116 }
       
   117 
       
   118 # routine to extract a set of variables from the compilation configuration
       
   119 # file. The variables extracted are determined by the extractvars.make file.
       
   120 # The variables are returned in a hash.
       
   121 sub BPABIutl_Get_Config_Variables
       
   122 {
       
   123     my ($plat) = @_;
       
   124     my $configfile = BPABIutl_Config_Path($plat);
       
   125     my $extractvars = "$ENV{EPOCROOT}epoc32\\tools\\compilation_config\\extractvars.make";
       
   126     my $command = "make CONFIG_FILE=$configfile -s -f $extractvars" ;
       
   127     my $result = `$command`;
       
   128     my %vars;
       
   129     my @lines = split('\n', $result);
       
   130     foreach my $line (@lines)
       
   131     {
       
   132 	chomp $line;
       
   133 	if ($line =~ /(\w+)=(.*)/)
       
   134 	{
       
   135 	    $vars{$1} = $2;
       
   136 	}
       
   137     }
       
   138     return %vars;
       
   139 }
       
   140 
       
   141 1;