sbsv1/abld/e32util/featurevariantmap.pm
author Zheng Shen <zheng.shen@nokia.com>
Thu, 09 Sep 2010 19:09:10 +0800
changeset 633 a4eca1f021ac
parent 599 fa7a3cc6effd
permissions -rw-r--r--
ROMTools-13.1.0.2 Bug 3415 - SBS failing to build open C libraries
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2007-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
# modified start: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
use Cwd;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
# modified end: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
use Digest::MD5;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
use File::Basename;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
package featurevariantmap;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
our $verbose = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
my $featureListDir = "$ENV{EPOCROOT}epoc32\\include\\variant\\featurelists";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
sub LoadFeatureList
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	my %featurehash;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
	# Try and find the feature master list folder
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
	if (!opendir DIR, $featureListDir)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
		print "\nERROR: Failed to open feature list directory $featureListDir: $!";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
		return \%featurehash;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
	# Load the list of features from each file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
	foreach my $file ( grep(/\.txt$/i, readdir DIR) )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
		$file = "$featureListDir\\$file";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
		print "Reading feature list from $file\n" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
		if (!open IN, $file)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
			print "\nERROR: Failed to read feature list $file: $!";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
		else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
			while(my $line = <IN>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
				$line =~ s/\/\/.+$//; # Get rid of c++ style comments
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
				if ($line =~ /(\S+)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
					$featurehash{$1} = $file;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
			close IN;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
			
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	closedir DIR;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
	return \%featurehash;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
sub ValidFeature
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
	our $featurelist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	my $name = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
	$featurelist = LoadFeatureList() if !$featurelist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
	return exists $featurelist->{$name};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
# modified start: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
sub GetVariantListFromVmap
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	my $obj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	my $vmapfile = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
	if(open(VMAP, "<$vmapfile"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
		my @varlist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
		while(<VMAP>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
			if(/^\w{32}\s+(\w+)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
				push @varlist, $1;
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
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
		close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
		return @varlist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
	close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
	return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
sub CheckOldVmapFile
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
	my $vmapfile = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
	my $varRef = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
	my $buildincludes = $$varRef{BUILD_INCLUDES};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
	my $parents = $$varRef{PARENTS};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
	my $children = $$varRef{CHILDREN};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
	my $varianthrh = $$varRef{VARIANT_HRH};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
	my %variantMacrolist;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
	my $Options = "-dM -undef -nostdinc -+";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
	my $Drive = $1 if (Cwd->cwd =~ /^(.:)/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
	if($buildincludes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
		foreach (@$buildincludes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
			$Options .= " -I \"".$Drive.$_."\"";
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
	if($varianthrh)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
		$Options .= " \"".$Drive.$varianthrh."\"";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
	if(open(CPP, "cpp $Options 2>&1 |"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
		while(<CPP>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
			my ( $key, $value );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
			if (/^#define (\w+(?:\([^\)]*\))?)(?:\s(\S.*?))?\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
				my $tmpKey = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
				my $tmpValue = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
				$tmpValue =~ s/,/\\,/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
				($key, $value ) = ( $tmpKey, $tmpValue ? "\'$tmpValue\'" : 'defined' );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			if ($key && ValidFeature($key))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
				$variantMacrolist{$key} = $value;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
		if(!close(CPP))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
			print "Incomplete pre-precess of $varianthrh \n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
	my $findReusedKey = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
	my %vmapfeatureinfo;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
	my $keyhash;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
	my $macroList;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
	if(open(VMAP, "<$vmapfile"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
		while(<VMAP>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
			if(/^\w{32}\s+(\w+)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
				$findReusedKey = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
				s/(^\w{32})\s+\w+\s+//;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
				$keyhash = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
				my @feature = split(/(?<=[^\\]),/, $_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
				foreach my $value (@feature)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
					if($value =~ /([^\s]*)\s*=\s*(.*)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
						$vmapfeatureinfo{$1} = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
				foreach my $key (sort keys %vmapfeatureinfo)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
					
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
					if(($vmapfeatureinfo{$key} eq "undefined") && (not(exists($variantMacrolist{$key}))))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
						$findReusedKey = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
					elsif($vmapfeatureinfo{$key} eq $variantMacrolist{$key})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
						$findReusedKey = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
					}else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
						$findReusedKey = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
						last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
				if( $findReusedKey == 1)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
					$macroList = $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
					last;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
				undef(%vmapfeatureinfor);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
				undef($keyhash);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
	if($findReusedKey == 1)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
    	return ($keyhash, $macroList);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
	else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
# modified end: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
# Usage:	featurevariantmap->Hash(\@sources, \%var)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
# Generate a hash value from the source files for a target using the
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
# given feature variant data.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
# \@sources	- list of source files (full path)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
# \%var		- variant data (from featurevariantparser->GetVariant)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
# returns the hash value, or "" if an error occurs.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
sub Hash
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
	my @result = $thisObj->HashAndFeatures(@_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
	return $result[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
# Usage:	featurevariantmap->HashAndFeatures(\@sources, \%var)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
# Generate a hash value from the source files for a target using the
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
# given feature variant data.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
# \@sources	- list of source files (full path)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
# \%var		- variant data (from featurevariantparser->GetVariant)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
# returns a list of two entries [0] the hash value, or "" if an error occurs [1] A string of macros tested or affecting the code
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
sub HashAndFeatures
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
	my $srcRef = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
	my $varRef = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
	return "" if (!$srcRef || !$varRef);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
	return "" if (!$$varRef{'VALID'});
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
	# get the pre-processing options
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
	my $pre = $$varRef{'PREINCLUDE'};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
	my $inc = $$varRef{'BUILD_INCLUDES'};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
	my $mac = $$varRef{'MACROS'};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
	# Pass -dU option to get list of macros affecting the code
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
	my $options = "-dU -undef -nostdinc -+";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
	if ($pre)	# pre-include file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
		$options .= " -include \"$pre\"";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
	if ($inc)	# include directories
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
		foreach (@$inc)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
			$options .= " -I \"$_\"";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
	if ($mac)	# macro definitions
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
		foreach (@$mac)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
			$options .= " -D$_";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   262
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   263
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   264
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   265
	my %testedMacrosHash;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   266
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   267
	# Macros that affect the mmp file also affect the variant - so add them to the list
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   268
	foreach my $key ( keys %{ $$varRef{MMPTESTED} } )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   269
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   270
		$testedMacrosHash{$key} = $$varRef{MMPTESTED}->{$key} if (ValidFeature($key));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   271
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   272
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   273
	foreach my $src (@$srcRef)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   274
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   275
		my $options = "-I " . File::Basename::dirname($src) . " $options";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   276
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   277
		print "cpp $options $src\n" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   278
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   279
		if (open(CPP, "cpp $options $src 2>&1 |"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   280
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   281
			while (<CPP>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   282
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   283
				print $_ if ($verbose && /No such file/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   284
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   285
				# Scan for #define or #undef generated for -dU
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   286
				my ( $key, $value );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   287
				if (/^#define (\w+(?:\([^\)]*\))?)(?:\s(\S.*?))?\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   288
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   289
# modified start: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   290
					my $tmpKey = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   291
					my $tmpValue = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   292
					$tmpValue =~ s/,/\\,/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   293
					( $key, $value ) = ( $tmpKey, $tmpValue ? "\'$tmpValue\'" : 'defined' );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   294
# modified end: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   295
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   296
				elsif (/^#undef (.+)$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   297
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   298
					( $key, $value ) = ( $1, 'undefined' );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   299
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   300
				
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   301
				if ($key && ValidFeature($key))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   302
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   303
					# Warn the user if a macro appears to have changed value - shouldn't really happen
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   304
					# Feature macros should only be set in platform HRH files and not in the code
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   305
					if (exists $testedMacrosHash{$key} && $testedMacrosHash{$key} ne $value)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   306
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   307
						print "WARNING: Feature macro $key redefined from $testedMacrosHash{$key} to $value\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   308
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   309
					
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   310
					# Store the macro details
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   311
					$testedMacrosHash{$key} = $value;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   312
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   313
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   314
			if (!close(CPP))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   315
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   316
				# this probably means that a rsg file was included
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   317
				# that hasn't been generated yet.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   318
				print "Incomplete pre-process of $src\n" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   319
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   320
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   321
		else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   322
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   323
			print "ERROR: Could not pre-process $src\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   324
			return "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   325
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   326
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   327
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   328
	# Now generate the tested macros string
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   329
	my $testedMacros = '';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   330
	foreach my $key ( sort keys %testedMacrosHash )
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   331
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   332
		$testedMacros .= ',' if $testedMacros;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   333
		$testedMacros .= "$key=$testedMacrosHash{$key}";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   334
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   335
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   336
	print "Tested feature list: $testedMacros\n" if $verbose;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   337
	return ( Digest::MD5::md5_hex($testedMacros), $testedMacros );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   338
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   339
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   340
# Usage:	featurevariantmap->Save("my.dll", "1234", "myvar", \@hints)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   341
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   342
# Write a hash value for a target into the target.vmap file along
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   343
# with some optional hints data.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   344
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   345
# "my.dll"	- the target (full path)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   346
# "1234"	- the hash value (32 character hex number)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   347
# "myvar"	- the feature variant name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   348
# \@hints	- optional list of extra strings (eg. "FEATUREVARIANT")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   349
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   350
# returns 0 if OK and non-zero if an error occurs.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   351
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   352
sub Save
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   353
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   354
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   355
	my $binName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   356
	my $keyValue = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   357
	my $varName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   358
	my $features = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   359
	my $hintRef = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   360
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   361
	# read the current data first if the .vmap file already exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   362
# modified by SV start: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   363
	my $vmapFile = "$binName.$varName.vmap";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   364
	my @lines;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   365
	my $tmpinfo = "$keyValue $varName";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   366
	$tmpinfo .= " $features" if $features;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   367
	if (open(VMAP, $vmapFile))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   368
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   369
		my @tmp=<VMAP>;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   370
		if (grep (/$tmpinfo/, @tmp)){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   371
			close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   372
			return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   373
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   374
		else {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   375
			foreach  (@tmp)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   376
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   377
				if (/^\w{32}\s+(\w+)/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   378
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   379
					push(@lines, $_) unless (uc($1) eq uc($varName));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   380
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   381
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   382
			close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   383
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   384
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   385
# modified by SV end: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   386
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   387
	# write the new data to the .vmap file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   388
	if (!open(VMAP, ">$vmapFile"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   389
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   390
		print "ERROR: Could not write VMAP to $vmapFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   391
		return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   392
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   393
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   394
	# put the hints at the beginning
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   395
	if ($hintRef)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   396
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   397
		foreach (@$hintRef)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   398
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   399
			print VMAP "$_\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   400
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   401
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   402
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   403
	# then the "key var" pairs
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   404
	foreach (@lines)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   405
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   406
		print VMAP $_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   407
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   408
	print VMAP "$keyValue $varName";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   409
	print VMAP " $features" if $features;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   410
	print VMAP "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   411
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   412
	close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   413
	return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   414
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   415
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   416
# Usage:    featurevariantmap->Find("my.dll", "myvar")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   417
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   418
# Look for a binary using its "final" name. We will use the feature
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   419
# variant map and the feature variant name to deduce the "variant"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   420
# binary name and test for its existence.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   421
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   422
# "my.dll"	- the final target (full path)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   423
# "myvar"	- the feature variant name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   424
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   425
# returns the file name if found, or "" otherwise.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   426
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   427
sub Find
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   428
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   429
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   430
	my $binName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   431
	my $varName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   432
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   433
	# look for the vmap file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   434
# modified by SV start: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   435
	my $vmapFile = "$binName.$varName.vmap";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   436
# modified by SV end: makefile improvement 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   437
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   438
	if (-e $vmapFile)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   439
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   440
		my $key = $thisObj->GetKeyFromVMAP($varName, $vmapFile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   441
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   442
		if ($key)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   443
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   444
			$binName =~ /^(.*)\.([^\.]*)$/;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   445
			$binName = "$1.$key.$2";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   446
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   447
		else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   448
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   449
			print "ERROR: No \'$varName\' variant for $binName in $vmapFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   450
			return "";	# file not found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   451
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   452
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   453
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   454
	# check that the actual binary exists
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   455
	if (-e $binName)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   456
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   457
		return $binName;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   458
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   459
	return "";	# file not found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   460
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   461
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   462
# internal functions
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   463
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   464
sub GetKeyFromVMAP
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   465
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   466
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   467
	my @res = $thisObj->GetDataFromVMAP(@_);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   468
	return $res[0];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   469
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   470
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   471
# Usage:    featurevariantmap->GetDataFromVMAP("myvar", "mydll.vmap")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   472
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   473
# Opens the vmap file indicated and returns the data for the requested variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   474
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   475
# "myvar"	- the feature variant name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   476
# "my.vmap"	- the final target vmap file (full path)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   477
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   478
# Returns a list ( hash, features ) for the variant in the vmap or undef if not found
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   479
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   480
sub GetDataFromVMAP
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   481
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   482
	my $thisObj = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   483
	my $varName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   484
	my $fileName = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   485
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   486
	if (!open(VMAP, $fileName))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   487
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   488
		print "ERROR: Could not read VMAP from $fileName\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   489
		return "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   490
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   491
	while (<VMAP>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   492
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   493
		chomp;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   494
		if (/(\w{32})\s+$varName\s+(.*)$/i or /(\w{32})\s+$varName$/i)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   495
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   496
			my ( $hash, $features ) = ( $1, $2 ? $2 : '' );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   497
			close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   498
			return ( $hash, $features );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   499
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   500
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   501
	close(VMAP);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   502
	return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   503
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   504
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   505
1;