sbsv1/abld/bldmake/wrappermakefile.pm
changeset 599 fa7a3cc6effd
equal deleted inserted replaced
596:9f25be3da657 599:fa7a3cc6effd
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 
       
    17 package		wrappermakefile;
       
    18 require Exporter;
       
    19 @wrappermakefile::ISA=qw(Exporter);
       
    20 @wrappermakefile::EXPORT=qw(
       
    21 	GenerateWrapper
       
    22 );
       
    23 
       
    24 use Output;
       
    25 
       
    26 my (@ExtensionUsedBefore);
       
    27 my $ExtTemplatesPath="$ENV{EPOCROOT}epoc32/tools/makefile_templates/";
       
    28 $ExtTemplatesPath=~ s/\\/\//g;  # convert win32 slashes to unix slashes
       
    29 my $DieRef;
       
    30 our $ExtMakefileMissing = 0;
       
    31 
       
    32 # Add prototyes to avoid -w warnings
       
    33 sub GenerateWrapper($$$$@);  
       
    34 sub ReadMetaFile($$$$);
       
    35 
       
    36 
       
    37 sub GenerateWrapper($$$$@) {	
       
    38 	my ($Plat,$OutDir, $ErrorString, $dieRef, @ExtensionBlockData) = @_;
       
    39 	$DieRef = $dieRef;
       
    40 	
       
    41 #	Generates a makefile which contains the settings for each invocation of an extension and calls
       
    42 #	through to the extension template makefile in /epoc32/tools/makefile_templates.
       
    43 #	@ExtensionBlockData holds the settings (makefile MACROs) defined within the start..end block in the bld.inf.
       
    44 
       
    45 	my $ExtHeader = shift(@ExtensionBlockData);
       
    46 
       
    47 	if (uc $ExtHeader->[0] ne "EXTENSION") {
       
    48 		&main::FatalError("$ErrorString : Extension Template blocks must contain the 'extension' keyword.\n");
       
    49 	}
       
    50 	if ($ExtHeader->[1] eq "") {
       
    51 		&main::FatalError("$ErrorString : The 'extension' does not have a name, the correct format is: 'start extension <name>'.\n");
       
    52 	}
       
    53 	my $ExtName = $ExtHeader->[1];
       
    54 
       
    55 #	Ensure that each extension invocation is uniquely identified by means of the global array 
       
    56 #	ExtensionUsedBefore.
       
    57 	my $Count=0;
       
    58 	push @ExtensionUsedBefore, $ExtName.$Plat;
       
    59 	foreach my $item(@ExtensionUsedBefore) {
       
    60 		if ($item eq $ExtName.$Plat) {
       
    61 			$Count = $Count + 1;
       
    62 		}
       
    63 	}
       
    64 
       
    65 #	Process the meta information for this extension template.
       
    66 	my %Data;
       
    67 	my %WrapperMakefileData = ReadMetaFile($ExtName, $ErrorString, \$Data{Makefile},$dieRef);
       
    68 	if ($ExtMakefileMissing)
       
    69 	{
       
    70 		main::ExtensionMakefileMissing($ExtMakefileMissing);
       
    71 		return;
       
    72 	}
       
    73 	$Data{Ext}='.MK';
       
    74 	$Data{Base}=$ExtName."_".$Plat."_".$Count;
       
    75 	$Data{Path}=$OutDir."wrappermakefiles/";
       
    76 
       
    77 #	Process ExtensionBlockData
       
    78 	foreach my $ExtBlockStatement (@ExtensionBlockData) {
       
    79 		my $Key = shift(@$ExtBlockStatement);
       
    80 		$WrapperMakefileData{$Key}=$ExtBlockStatement;
       
    81 	}
       
    82 
       
    83 #	CreateWrapperMakefile
       
    84 	&Output("# Bldmake generated wrapper makefile\n\n");
       
    85 	foreach my $Key (keys (%WrapperMakefileData))
       
    86 	{
       
    87 			&Output("$Key = "); 
       
    88 			foreach my $item(@{$WrapperMakefileData{$Key}}) {
       
    89 				&Output(" $item");
       
    90 			}
       
    91 			&Output("\n");
       
    92 	}
       
    93 	my $Filename = lc("$ExtName$Data{Ext}");
       
    94 	&Output("\ninclude $ExtTemplatesPath$Filename"); 
       
    95 	my $Path = lc("$Data{Path}");
       
    96 	&main::WriteOutFileL(lc ($Path.$ExtName."_".$Plat."_".$Count.$Data{Ext}));
       
    97 	%WrapperMakefileData = ();
       
    98 	return %Data;  
       
    99 }
       
   100 
       
   101 #  Read extension meta file data
       
   102 sub ReadMetaFile($$$$) {
       
   103 	my ($ExtName, $ErrorString, $Makefile,$dieRef) = @_;
       
   104 
       
   105 #	Parse the .meta file (found via $ExtName) for this extension template and return a hash 
       
   106 #	containing the default values (makefile MACROs) for this template.
       
   107 #	$Makefile is updated to indicate whether this a gnumake or nmake makefile.
       
   108 
       
   109 	my %MetaData;
       
   110 	my $Filename = lc("$ExtName");
       
   111 	$ExtMakefileMissing=0;
       
   112 	if (!open(METAFILE,"$ExtTemplatesPath$Filename.meta"))
       
   113 	{
       
   114 		&main::WarnOrDie($dieRef, "$ErrorString : Extension: $ExtName - cannot open META file: $ExtTemplatesPath$Filename.meta\n");
       
   115 		$ExtMakefileMissing = 1;
       
   116 		return;
       
   117 	}
       
   118 	LINE: while (<METAFILE>) {
       
   119 		chomp;		
       
   120 		my @Elements = split(/\s*\s\s*/);		
       
   121 		my $Keyword = uc shift(@Elements);
       
   122 
       
   123 		if ((! $Keyword) or ($Keyword =~ m/^#/)) {
       
   124 			next LINE;
       
   125 		}
       
   126 
       
   127 		if ($Keyword eq "MAKEFILE") {	
       
   128 			my $Makefiletype = uc shift(@Elements);		
       
   129 			if ($Makefiletype eq "GNUMAKE") {
       
   130 				$$Makefile=1;
       
   131 			}
       
   132 			if ($Makefiletype eq "NMAKE") {
       
   133 				$$Makefile=2;
       
   134 			}
       
   135 		}
       
   136 		elsif ($Keyword eq "OPTION") {
       
   137 			my $Key = shift(@Elements);
       
   138 			if ((! $Key) or (! $Elements[0])) {
       
   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>'");
       
   140 				}
       
   141 			my @Values = @Elements;
       
   142 			$MetaData{$Key}=\@Values;
       
   143 		} 
       
   144 		elsif (($Keyword eq "TECHSTREAM") or ($Keyword eq "PLATFORM")) {
       
   145 			# not used
       
   146 		}
       
   147 		else {
       
   148 			&main::FatalError("$ErrorString : There is a syntax error in the META file ($ExtTemplatesPath$Filename.meta) for this extension ($ExtName) - unrecognised keyword:$Keyword");	
       
   149 		}
       
   150 	}
       
   151 	if (! $$Makefile) {
       
   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]");
       
   153 	}
       
   154 	close(METAFILE) or &main::FatalError("$ErrorString : Extension: $ExtName - cannot close Meta File:$ExtTemplatesPath$ExtName.meta\n");
       
   155 	return %MetaData;
       
   156 }
       
   157 
       
   158 1;