sbsv1/abld/genutil/prepfile.pm
author jascui
Wed, 17 Nov 2010 13:45:48 +0800
changeset 689 b70d8ea6cf75
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Updating release text and product version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 1997-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
# module for preprocessing makmake-style project files
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
package Prepfile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
require Exporter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
@ISA=qw(Exporter);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
@EXPORT=qw(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
	Prepfile_SetVerbose Prepfile_SetUpperCase Prepfile_ProcessL Prepfile_SetCmdOptions
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
use Checkgcc;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
use Pathutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
use Preprocessor;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
my %Mode=(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
	Verbose=>0,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
	UpperCase=>0,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
        CmdOptions=>''
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
sub Prepfile_SetVerbose () {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
	$Mode{Verbose}=1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
sub Prepfile_SetUpperCase () {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
	$Mode{UpperCase}=1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
sub Prepfile_SetCmdOptions ($) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
        $Mode{CmdOptions} = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
        $Mode{CmdOptions} .= ' ' if $Mode{CmdOptions};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
sub Prepfile_ProcessL ($$;$@) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
# use the C++ preprocessor to process a file.  The function fills the data structure specified
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
# by the first argument, an array reference, according to the contents of the second argument -
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
# a filehandle.  Any other arguments are assumed to be MACROS and are defined for preprocessing.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	my ($ArrayRef,$FILE,$VariantHRHFile,@Macros)=@_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
	die "\nERROR: Project File \"$FILE\" not found\n" unless -e $FILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
	my $exe = &PreprocessorToUseExe();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
 	my $cpp = "$exe.EXE $Mode{CmdOptions}-undef -nostdinc -+ ";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
	my @CppCall;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
 	push @CppCall, $cpp;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
	push @CppCall, join '',	"-I ",&Path_PrefixWithDriveAndQuote("$ENV{EPOCROOT}epoc32\\include"),
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
							" -I .",
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
							" -I ",&Path_PrefixWithDriveAndQuote(&Path_Split('Path',$FILE));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	my $Macro;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
	# add CL macros to the CPP call for preprocessing of the file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
	foreach $Macro (@Macros) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
		$Macro=uc $Macro;					 # add the underscores so we can tell what has been
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
		push @CppCall, "-D $Macro=_____$Macro"; # expanded and remove the space CPP puts in most of the time
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	#if a variant file is used
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	if(defined($VariantHRHFile)){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
        my $variantFilePath = Path_Split('Path',$VariantHRHFile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	chop( $variantFilePath );
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
        push @CppCall, " -I " . &Path_PrefixWithDriveAndQuote($variantFilePath) . " -include " . &Path_PrefixWithDriveAndQuote($VariantHRHFile); 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
	# all macros made upper case and suppress user-expansion of macros for nefarious purposes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
	push @CppCall, &Path_PrefixWithDriveAndQuote($FILE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	if ($Mode{'Verbose'}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
		print "@CppCall\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
	my $CPPPIPE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
	open CPPPIPE,"@CppCall |" or die "ERROR: Can't invoke CPP.EXE\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
	# read the processed output
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
	#--------------------------
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
	my $LineNum=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
	my $FileName;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
	while (<CPPPIPE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
		# skip blank lines
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
		if (/^\s*$/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
			$LineNum++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
		my @Tmp=();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
	    # Process the file information lines that cpp inserts.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
		# (note that we don't currently do anything with the
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
		# number cpp sometimes puts out after the filename -
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
		# it's something to do with inclusion nesting levels)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
		if (/^# (\d+) "(.*)"( \d+)?/o) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
			$LineNum = scalar $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
			my $CurFile=$2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
			$CurFile=~s-\\\\-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
			$CurFile=~s-\\\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
			$CurFile=~s-\/\\-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
			$CurFile=~s-\/\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
			$CurFile=~s-\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
			$CurFile=~s-(.:)--go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
			$CurFile=&Path_AbsToWork($CurFile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
			@Tmp=('#', $CurFile);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
			push @{$ArrayRef}, [ @Tmp ];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
		# Process file data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
		push @Tmp, $LineNum;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
		# get rid of the space that cpp puts in most of the time after macro expansion (CPP help doesn't say exactly when!)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
		# don't upper case everything until you've done this.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
		foreach $Macro (@Macros) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			s/\/ _____$Macro /\/$Macro/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			s/_____$Macro /$Macro/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
			s/_____$Macro/$Macro/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
		if(/^macro/i)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
			#Parse and Store the mmp file statement by retaining double quotes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
			while (/("([^\t\n\r\f]+)"|([^ \t\n\r\f]+))/go) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
			        my $Flag = $2 ? $2 : $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
				if($Flag =~ m/\\\"/) { 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
					$Flag =~ s/\"\\/\\/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
					$Flag =~ s/\""/\"/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
				push @Tmp, $Flag;
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
		else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
			#Parse and Store the mmp file statement by removing double quotes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
			while (/("([^"\t\n\r\f]+)"|([^ "\t\n\r\f]+))/go) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
				push @Tmp, $2 ? $2 : $3;
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
		push @{$ArrayRef}, [ @Tmp ];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
		$LineNum++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
	}		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
	if ($Mode{UpperCase}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
#		upper-case all the data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
		my $Line;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
		my $Item;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
		foreach $Line (@{$ArrayRef}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
			foreach $Item (@$Line) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
				$Item=uc $Item;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
	close CPPPIPE or die $! ? "ERROR: Error closing $exe.exe pipe ($!)\n\t@CppCall\n"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
 				: "ERROR: $exe.exe returned non-zero exit status ($?)\n\t@CppCall\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
1;