1 |
package BuildFile;
|
2 |
require 5.001;
|
3 |
require Exporter;
|
4 |
@ISA = qw(Exporter);
|
5 |
@EXPORT = qw(CheckBuildFile ParseBuildFile @BlockClassA $DefaultBuildFile);
|
6 |
|
7 |
BEGIN {
|
8 |
use ToolBox;
|
9 |
$buildfile="BuildFile";
|
10 |
$toolbox=ToolBox->new();
|
11 |
$Arch=1;
|
12 |
push @ARCHBLOCK, $Arch;
|
13 |
}
|
14 |
|
15 |
#Parse the BuildFile
|
16 |
sub ParseBuildFile {
|
17 |
my $base=shift;
|
18 |
my $path=shift;
|
19 |
my $filename=shift @_;
|
20 |
my $fullfilename="$base/$path/$filename";
|
21 |
#print "Processing $fullfilename\n";
|
22 |
# This hash defines which Document Elements we can use
|
23 |
my $SupportedTags={
|
24 |
'Use' => \&OutToMakefile,
|
25 |
'Use_StartTag' => \&Use_start,
|
26 |
'Group' => \&OutToMakefile,
|
27 |
'Group_StartTag' => \&Group_start,
|
28 |
'External' => \&OutToMakefile,
|
29 |
'External_StartTag' => \&External_StartTag,
|
30 |
'ConfigurationClass_StartTag' => \&Class_StartTag,
|
31 |
'ConfigurationClass' => \&OutToMakefile,
|
32 |
'AssociateGroup' => \&AssociateGroup,
|
33 |
'none' => \&OutToMakefile,
|
34 |
'Bin' => 'none',
|
35 |
'Bin_StartTag' => \&Bin_start,
|
36 |
'ClassPath' => \&OutToMakefile,
|
37 |
'ClassPath_StartTag' => \&setBlockClassPath,
|
38 |
'lib' => 'none',
|
39 |
'lib_StartTag' => \&lib_start,
|
40 |
'lib_EndTag' => 'none',
|
41 |
'ignore' => 'none',
|
42 |
'ignore_EndTag' => \&ignoretag_end,
|
43 |
'ignore_StartTag' => \&ignoretag,
|
44 |
'Architecture_StartTag' => \&Arch_Start,
|
45 |
'Architecture_EndTag' => \&Arch_End,
|
46 |
'Architecture' => \&OutToMakefile
|
47 |
};
|
48 |
use Utilities::Switcher;
|
49 |
$switch=Switcher->new($SupportedTags, $fullfilename);
|
50 |
$switch->{Strict_no_cr}='no';
|
51 |
#open a temporary gnumakefile to store output.
|
52 |
use Utilities::AddDir;
|
53 |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}");
|
54 |
open ( GNUmakefile, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk") or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n';
|
55 |
if ( -e $ENV{LatestBuildFile} ) {
|
56 |
print GNUmakefile "include $ENV{LatestBuildFile}\n";
|
57 |
}
|
58 |
# print "writing to :\n".
|
59 |
# "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk\n";
|
60 |
$ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
|
61 |
$switch->parse(); # sort out supported tags
|
62 |
close GNUmakefile;
|
63 |
}
|
64 |
|
65 |
sub ParseBuildFile_Export {
|
66 |
my $filename=shift;
|
67 |
use Tool;
|
68 |
# This hash defines which Document Elements we can use
|
69 |
my $SupportedTags={
|
70 |
'none' => 'none',
|
71 |
'export' => \&OutToMakefile,
|
72 |
'export_StartTag' => \&export_start,
|
73 |
'export_EndTag' => \&export_end,
|
74 |
'lib_StartTag' => \&lib_start_export,
|
75 |
'lib' => 'none'
|
76 |
};
|
77 |
use Utilities::Switcher;
|
78 |
$switchex=Switcher->new($SupportedTags, $filename);
|
79 |
$switchex->{Strict_no_cr}='no';
|
80 |
$switchex->parse(); # sort out supported tags
|
81 |
}
|
82 |
|
83 |
sub initialterms() {
|
84 |
my $name=shift;
|
85 |
my @string=@_;
|
86 |
|
87 |
$_=join "", @string;
|
88 |
chomp;
|
89 |
SWITCH: {
|
90 |
last SWITCH if /^#/;
|
91 |
if ( /^.*BlockClassPath.*/i ) {
|
92 |
s/^.*BlockClassPath *= *//;
|
93 |
_CutBlock($_);
|
94 |
last SWITCH;
|
95 |
}
|
96 |
} # end SWITCH
|
97 |
}
|
98 |
|
99 |
# Tag routines - called by the Switcher when tag found
|
100 |
|
101 |
|
102 |
|
103 |
#-- Override a class type with the <ConfigurationClass type=xxx> tag
|
104 |
# the type tag will pick up a pre-defined class type from project space.
|
105 |
|
106 |
sub Class_StartTag {
|
107 |
my $name=shift;
|
108 |
my $hashref;
|
109 |
my @vars=@_;
|
110 |
|
111 |
$hashref=$switch->SetupValueHash(\@vars);
|
112 |
if ( $Arch ) {
|
113 |
if ( defined $$hashref{'type'} ) {
|
114 |
$ClassName=$$hashref{'type'};
|
115 |
}
|
116 |
}
|
117 |
}
|
118 |
|
119 |
sub ClassPath_StartTag {
|
120 |
my $name=shift;
|
121 |
my @vars=@_;
|
122 |
my $hashref;
|
123 |
|
124 |
$hashref=$switch->SetupValueHash(\@vars);
|
125 |
if ( $Arch ) {
|
126 |
if ( defined $$hashref{'defaultpath'} ) {
|
127 |
}
|
128 |
}
|
129 |
}
|
130 |
|
131 |
sub Bin_start {
|
132 |
my $name=shift;
|
133 |
my @vars=@_;
|
134 |
my $hashref;
|
135 |
my $fileclass;
|
136 |
my @tools;
|
137 |
my $tool;
|
138 |
my $filename;
|
139 |
my $objectname;
|
140 |
|
141 |
$hashref=$switch->SetupValueHash(\@vars);
|
142 |
$switch->checkparam($hashref, $name, 'file');
|
143 |
if ( $Arch ) {
|
144 |
if ( ! defined $$hashref{name} ) {
|
145 |
($$hashref{name}=$$hashref{file})=~s/\..*//;
|
146 |
}
|
147 |
# This stuff for later
|
148 |
#$fileclass=$toolbox->getclass($file);
|
149 |
#$toolbox->maketargets("exe",$fileclass, $$hashref{name}, $file );
|
150 |
($filename=$$hashref{file})=~s/\..*//;
|
151 |
($objectname=$$hashref{file})=~s/\..*/\.o/;
|
152 |
($objectname_d=$$hashref{file})=~s/\..*/_d\.o/;
|
153 |
($objectname_Insure=$$hashref{file})=~s/\..*/_Insure\.o/;
|
154 |
print GNUmakefile "bin:$$hashref{name}\n";
|
155 |
print GNUmakefile "bin_debug:$$hashref{name}_d\n";
|
156 |
print GNUmakefile "bin_insure:$$hashref{name}_Insure\n";
|
157 |
print GNUmakefile ".INTERMEDIATE::$$hashref{name}_d.exe\n";
|
158 |
print GNUmakefile ".INTERMEDIATE::$$hashref{name}_Insure.exe\n";
|
159 |
print GNUmakefile ".INTERMEDIATE::$$hashref{name}.exe\n";
|
160 |
print GNUmakefile "$$hashref{name}_Insure:.psrc\n";
|
161 |
print GNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
|
162 |
print GNUmakefile "\t\$(CClinkCmdDebug)\n";
|
163 |
print GNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
|
164 |
print GNUmakefile "\t\$(CClinkCmdInsure)\n";
|
165 |
print GNUmakefile "$$hashref{name}.exe:$objectname\n";
|
166 |
print GNUmakefile "\t\$(CClinkCmd)\n";
|
167 |
print GNUmakefile "$objectname:$$hashref{name}.dep\n";
|
168 |
print GNUmakefile "$objectname_d:$$hashref{name}.dep\n";
|
169 |
print GNUmakefile "$objectname_Insure:$$hashref{name}.dep\n";
|
170 |
print GNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
|
171 |
print GNUmakefile "-include $$hashref{name}.dep\n";
|
172 |
# print GNUmakefile "$$hashref{name}:$$hashref{file}\n";
|
173 |
print GNUmakefile <<ENDTEXT;
|
174 |
$$hashref{name}_d.exe:\$(libslocal_d)
|
175 |
$$hashref{name}.exe:\$(libslocal)
|
176 |
$$hashref{name}_Insure.exe:\$(libslocal_I)
|
177 |
$$hashref{name}_d:$$hashref{name}_d.exe
|
178 |
\@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
|
179 |
$$hashref{name}_Insure:$$hashref{name}_Insure.exe
|
180 |
\@mv $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure
|
181 |
$$hashref{name}:$$hashref{name}_d.exe
|
182 |
\@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
|
183 |
$$hashref{name}_o:$$hashref{name}_o.exe
|
184 |
\@mv $$hashref{name}.exe \$(binarystore)/$$hashref{name}
|
185 |
binfiles+=$filename
|
186 |
bintargets+=$$hashref{name} $$hashref{name}_d $$hashref{name}_Insure
|
187 |
ENDTEXT
|
188 |
}
|
189 |
}
|
190 |
|
191 |
sub External_StartTag {
|
192 |
my $name=shift;
|
193 |
my @vars=@_;
|
194 |
my $hashref;
|
195 |
|
196 |
$hashref=$switch->SetupValueHash(\@vars);
|
197 |
if ( $Arch ) {
|
198 |
$$hashref{'ref'}=~tr[A-Z][a-z];
|
199 |
print GNUmakefile $$hashref{'ref'};
|
200 |
if ( defined $$hashref{'version'} ) {
|
201 |
print GNUmakefile "_V_".$$hashref{'version'};
|
202 |
}
|
203 |
print GNUmakefile "=true\n";
|
204 |
}
|
205 |
|
206 |
}
|
207 |
|
208 |
sub Group_start {
|
209 |
my $name=shift;
|
210 |
my @vars=@_;
|
211 |
my $hashref;
|
212 |
|
213 |
$hashref=$switch->SetupValueHash(\@vars);
|
214 |
$switch->checkparam($hashref, $name, 'name');
|
215 |
if ( $Arch ) {
|
216 |
print GNUmakefile "GROUP_".$$hashref{'name'};
|
217 |
if ( defined $$hashref{'version'} ) {
|
218 |
print GNUmakefile "_V_".$$hashref{'version'};
|
219 |
}
|
220 |
print GNUmakefile "=true\n";
|
221 |
}
|
222 |
}
|
223 |
|
224 |
sub External {
|
225 |
my $name=shift;
|
226 |
my @vars=@_;
|
227 |
# Will simply collect string into a seperate buffer for processind
|
228 |
# at the tag closure - used for specifying product defaults
|
229 |
# --- Oh oh all of string already in external buffer @!
|
230 |
}
|
231 |
|
232 |
sub External_EndTag {
|
233 |
my $name=shift;
|
234 |
my @vars=@_;
|
235 |
|
236 |
# process buffer and check consistency with product dtd
|
237 |
}
|
238 |
|
239 |
sub Use_start {
|
240 |
my $name=shift;
|
241 |
my @vars=@_;
|
242 |
my $hashref;
|
243 |
my $filename;
|
244 |
use Utilities::SCRAMUtils;
|
245 |
|
246 |
$hashref=$switch->SetupValueHash(\@vars);
|
247 |
$switch->checkparam($hashref, $name, "name");
|
248 |
if ( $Arch ) {
|
249 |
$filename=SCRAMUtils::checkfile(
|
250 |
"$ENV{INTsrc}/$$hashref{name}/BuildFile");
|
251 |
if ( $filename ne "" ) {
|
252 |
ParseBuildFile_Export( $filename );
|
253 |
}
|
254 |
}
|
255 |
}
|
256 |
|
257 |
sub CheckBuildFile {
|
258 |
my $classdir=shift;
|
259 |
$ClassName="";
|
260 |
$thisfile="$classdir/$buildfile";
|
261 |
|
262 |
if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
|
263 |
$DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
|
264 |
ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
|
265 |
}
|
266 |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
|
267 |
$DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
|
268 |
ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
|
269 |
}
|
270 |
return $ClassName;
|
271 |
}
|
272 |
|
273 |
# List association groups between <AssociateGroup> tags
|
274 |
# seperated by newlines or spaces
|
275 |
sub AssociateGroup {
|
276 |
my $name=shift;
|
277 |
my @vars=@_;
|
278 |
my $word;
|
279 |
|
280 |
foreach $word ( @vars ){
|
281 |
chomp $word;
|
282 |
next if /^#/;
|
283 |
push @groups, $word;
|
284 |
}
|
285 |
}
|
286 |
|
287 |
sub ignoretag {
|
288 |
my $name=shift;
|
289 |
my @vars=@_;
|
290 |
|
291 |
$Arch=0;
|
292 |
push @ARCHBLOCK, $Arch;
|
293 |
}
|
294 |
|
295 |
sub ignoretag_end {
|
296 |
my $name=shift;
|
297 |
my @vars=@_;
|
298 |
|
299 |
pop @ARCHBLOCK;
|
300 |
$Arch=$ARCHBLOCK[$#ARCHBLOCK];
|
301 |
}
|
302 |
|
303 |
sub Arch_Start {
|
304 |
my $name=shift;
|
305 |
my @vars=@_;
|
306 |
my $hashref;
|
307 |
|
308 |
$hashref=$toolswitch->SetupValueHash( \@vars );
|
309 |
$toolswitch->checkparam($hashref, $name, 'name');
|
310 |
#( ($$hashref{name}=~/$ENV{SCRAM_ARCH}/) )?$Arch=1:$Arch=0;
|
311 |
( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($Arch=1) : ($Arch=0);
|
312 |
push @ARCHBLOCK, $Arch;
|
313 |
}
|
314 |
sub Arch_End {
|
315 |
my $name=shift;
|
316 |
my @vars=@_;
|
317 |
|
318 |
pop @ARCHBLOCK;
|
319 |
$Arch=$ARCHBLOCK[$#ARCHBLOCK];
|
320 |
}
|
321 |
|
322 |
# Split up the Class Block String into a useable array
|
323 |
sub _CutBlock {
|
324 |
my $string= shift @_;
|
325 |
@BlockClassA = split /\//, $string;
|
326 |
}
|
327 |
|
328 |
sub OutToMakefile {
|
329 |
my $name=shift;
|
330 |
my @vars=@_;
|
331 |
|
332 |
print GNUmakefile @vars;
|
333 |
}
|
334 |
sub setBlockClassPath {
|
335 |
my $name=shift;
|
336 |
my @vars=@_;
|
337 |
my $hashref;
|
338 |
|
339 |
$hashref=$switch->SetupValueHash(\@vars);
|
340 |
$switch->checkparam($hashref, $name, 'path');
|
341 |
$BlockClassPath=$BlockClassPath.":".$$hashref{path};
|
342 |
_CutBlock($$hashref{path});
|
343 |
}
|
344 |
|
345 |
sub export_start {
|
346 |
#Set up a toolfile object
|
347 |
$exporttool=Tool->new();
|
348 |
}
|
349 |
|
350 |
sub export_end {
|
351 |
#Write toolfile object to disk
|
352 |
$exporttool->envtomake(\*GNUmakefile);
|
353 |
}
|
354 |
|
355 |
#
|
356 |
# Export Mode Lib Tag
|
357 |
#
|
358 |
sub lib_start_export {
|
359 |
my $name=shift;
|
360 |
my @vars=@_;
|
361 |
my $hashref;
|
362 |
|
363 |
$hashref=$switchex->SetupValueHash( \@vars );
|
364 |
$switchex->checkparam($hashref, $name, 'name');
|
365 |
if ( $Arch ) {
|
366 |
if ( $switchex->context('export') ) {
|
367 |
#If export mode then add this env to the export tool
|
368 |
$exporttool->addenv('lib',$$hashref{name});
|
369 |
}
|
370 |
}
|
371 |
}
|
372 |
|
373 |
#
|
374 |
# Standard lib tag
|
375 |
#
|
376 |
sub lib_start {
|
377 |
my $name=shift;
|
378 |
my @vars=@_;
|
379 |
my $hashref;
|
380 |
|
381 |
$hashref=$switch->SetupValueHash( \@vars );
|
382 |
$switch->checkparam($hashref, $name, 'name');
|
383 |
if ( $Arch ) {
|
384 |
print GNUmakefile "lib+=$$hashref{name}\n";
|
385 |
}
|
386 |
}
|