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