sbsv1/abld/bldmake/wrappermakefile.pm
author y4jin
Thu, 18 Nov 2010 13:43:06 +0800
changeset 704 0f8b90f18a21
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Fix the illegal word scanned by sfchecksource tools
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
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
package		wrappermakefile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
require Exporter;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
@wrappermakefile::ISA=qw(Exporter);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
@wrappermakefile::EXPORT=qw(
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
	GenerateWrapper
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
use Output;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
my (@ExtensionUsedBefore);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
my $ExtTemplatesPath="$ENV{EPOCROOT}epoc32/tools/makefile_templates/";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
$ExtTemplatesPath=~ s/\\/\//g;  # convert win32 slashes to unix slashes
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
my $DieRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
our $ExtMakefileMissing = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
# Add prototyes to avoid -w warnings
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
sub GenerateWrapper($$$$@);  
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
sub ReadMetaFile($$$$);
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
sub GenerateWrapper($$$$@) {	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
	my ($Plat,$OutDir, $ErrorString, $dieRef, @ExtensionBlockData) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
	$DieRef = $dieRef;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
#	Generates a makefile which contains the settings for each invocation of an extension and calls
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
#	through to the extension template makefile in /epoc32/tools/makefile_templates.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
#	@ExtensionBlockData holds the settings (makefile MACROs) defined within the start..end block in the bld.inf.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
	my $ExtHeader = shift(@ExtensionBlockData);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
	if (uc $ExtHeader->[0] ne "EXTENSION") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
		&main::FatalError("$ErrorString : Extension Template blocks must contain the 'extension' keyword.\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
	if ($ExtHeader->[1] eq "") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
		&main::FatalError("$ErrorString : The 'extension' does not have a name, the correct format is: 'start extension <name>'.\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	my $ExtName = $ExtHeader->[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
#	Ensure that each extension invocation is uniquely identified by means of the global array 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
#	ExtensionUsedBefore.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	my $Count=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
	push @ExtensionUsedBefore, $ExtName.$Plat;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
	foreach my $item(@ExtensionUsedBefore) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
		if ($item eq $ExtName.$Plat) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
			$Count = $Count + 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
#	Process the meta information for this extension template.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
	my %Data;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
	my %WrapperMakefileData = ReadMetaFile($ExtName, $ErrorString, \$Data{Makefile},$dieRef);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
	if ($ExtMakefileMissing)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
		main::ExtensionMakefileMissing($ExtMakefileMissing);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
	$Data{Ext}='.MK';
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	$Data{Base}=$ExtName."_".$Plat."_".$Count;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	$Data{Path}=$OutDir."wrappermakefiles/";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
#	Process ExtensionBlockData
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	foreach my $ExtBlockStatement (@ExtensionBlockData) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
		my $Key = shift(@$ExtBlockStatement);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
		$WrapperMakefileData{$Key}=$ExtBlockStatement;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
#	CreateWrapperMakefile
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	&Output("# Bldmake generated wrapper makefile\n\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
	foreach my $Key (keys (%WrapperMakefileData))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
			&Output("$Key = "); 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
			foreach my $item(@{$WrapperMakefileData{$Key}}) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
				&Output(" $item");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
			&Output("\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
	my $Filename = lc("$ExtName$Data{Ext}");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
	&Output("\ninclude $ExtTemplatesPath$Filename"); 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
	my $Path = lc("$Data{Path}");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
	&main::WriteOutFileL(lc ($Path.$ExtName."_".$Plat."_".$Count.$Data{Ext}));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
	%WrapperMakefileData = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
	return %Data;  
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
#  Read extension meta file data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
sub ReadMetaFile($$$$) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
	my ($ExtName, $ErrorString, $Makefile,$dieRef) = @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
#	Parse the .meta file (found via $ExtName) for this extension template and return a hash 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
#	containing the default values (makefile MACROs) for this template.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
#	$Makefile is updated to indicate whether this a gnumake or nmake makefile.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
	my %MetaData;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
	my $Filename = lc("$ExtName");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
	$ExtMakefileMissing=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
	if (!open(METAFILE,"$ExtTemplatesPath$Filename.meta"))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
		&main::WarnOrDie($dieRef, "$ErrorString : Extension: $ExtName - cannot open META file: $ExtTemplatesPath$Filename.meta\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
		$ExtMakefileMissing = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
	LINE: while (<METAFILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
		chomp;		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
		my @Elements = split(/\s*\s\s*/);		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
		my $Keyword = uc shift(@Elements);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
		if ((! $Keyword) or ($Keyword =~ m/^#/)) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
			next LINE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
		if ($Keyword eq "MAKEFILE") {	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
			my $Makefiletype = uc shift(@Elements);		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
			if ($Makefiletype eq "GNUMAKE") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
				$$Makefile=1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			if ($Makefiletype eq "NMAKE") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
				$$Makefile=2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
		elsif ($Keyword eq "OPTION") {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
			my $Key = shift(@Elements);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
			if ((! $Key) or (! $Elements[0])) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
					&main::FatalError("$ErrorString : There is a syntax error in the META file ($ExtTemplatesPath$Filename.meta) for this extension ($ExtName) - the correct format for default options is: 'option <key> <value>'");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
			my @Values = @Elements;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
			$MetaData{$Key}=\@Values;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
		} 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
		elsif (($Keyword eq "TECHSTREAM") or ($Keyword eq "PLATFORM")) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
			# not used
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
			&main::FatalError("$ErrorString : There is a syntax error in the META file ($ExtTemplatesPath$Filename.meta) for this extension ($ExtName) - unrecognised keyword:$Keyword");	
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
	if (! $$Makefile) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
		&main::FatalError("$ErrorString : There is a syntax error in the META file ($ExtTemplatesPath$Filename.meta) for this extension ($ExtName) - makefile type not specified [gnumake|nmake]");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
	close(METAFILE) or &main::FatalError("$ErrorString : Extension: $ExtName - cannot close Meta File:$ExtTemplatesPath$ExtName.meta\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
	return %MetaData;
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
1;