1 |
# BuildFile
|
2 |
#
|
3 |
# Interface
|
4 |
# ---------
|
5 |
# new(toolbox)
|
6 |
# ParseBuildFile($base,$path,$file)
|
7 |
# ParseBuildFileExport(filename)
|
8 |
# BlockClassPath() : Return the class path
|
9 |
# ignore() : return 1 if directory should be ignored 0 otherwise
|
10 |
# CheckBuildFile(dir) : return the BuildFile if it exists
|
11 |
|
12 |
package BuildSystem::BuildFile;
|
13 |
use ActiveDoc::SimpleDoc;
|
14 |
use BuildSystem::ToolBox;
|
15 |
require 5.004;
|
16 |
|
17 |
BEGIN {
|
18 |
$buildfile="BuildFile";
|
19 |
}
|
20 |
|
21 |
sub new {
|
22 |
my $class=shift;
|
23 |
my $self={};
|
24 |
bless $self, $class;
|
25 |
$self->{toolbox}=shift;
|
26 |
$self->{Arch}=1;
|
27 |
push @{$self->{ARCHBLOCK}}, $self->{Arch};
|
28 |
return $self;
|
29 |
}
|
30 |
|
31 |
sub ignore {
|
32 |
my $self=shift;
|
33 |
return (defined $self->{ignore})?$self->{ignore}:0;
|
34 |
}
|
35 |
|
36 |
sub _initswitcher {
|
37 |
my $self=shift;
|
38 |
my $switch=ActiveDoc::SimpleDoc->new();
|
39 |
my $parse="makebuild";
|
40 |
$switch->newparse($parse);
|
41 |
$switch->addignoretags($parse);
|
42 |
$self->_commontags($switch,$parse);
|
43 |
$switch->addtag($parse,"Build", \&Build_start, $self);
|
44 |
$switch->addtag($parse,"none",
|
45 |
\&OutToMakefile,$self,
|
46 |
\&OutToMakefile, $self,
|
47 |
"", $self);
|
48 |
$switch->addtag($parse,"Bin",
|
49 |
\&Bin_start,$self,
|
50 |
\&OutToScreen, $self,
|
51 |
"", $self);
|
52 |
$switch->addtag($parse,"LibType",
|
53 |
\&LibType_Start,$self,
|
54 |
\&LibType_text, $self,
|
55 |
\&LibType_end,$self);
|
56 |
$switch->addtag($parse,"ConfigurationClass",
|
57 |
\&Class_StartTag,$self,
|
58 |
\&OutToMakefile, $self,
|
59 |
"", $self);
|
60 |
$switch->addtag($parse,"ClassPath",
|
61 |
\&setBlockClassPath,$self,
|
62 |
\&OutToMakefile, $self,
|
63 |
"", $self);
|
64 |
$switch->addtag($parse,"AssociateGroup",
|
65 |
"",$self,
|
66 |
\&AssociateGroup,$self,
|
67 |
"", $self);
|
68 |
$switch->addtag($parse,"Environment",
|
69 |
\&Environment_start,$self,
|
70 |
\&OutToMakefile, $self,
|
71 |
\&Environment_end,$self);
|
72 |
$switch->addtag($parse,"Export",
|
73 |
\&export_start,$self,
|
74 |
\&OutToMakefile, $self,
|
75 |
\&export_end,$self);
|
76 |
return $switch;
|
77 |
}
|
78 |
|
79 |
sub _commontags {
|
80 |
my $self=shift;
|
81 |
my $switch=shift;
|
82 |
my $parse=shift;
|
83 |
|
84 |
$switch->grouptag("Export",$parse);
|
85 |
$switch->addtag($parse,"Use",\&Use_start,$self,
|
86 |
\&OutToMakefile, $self,
|
87 |
"", $self);
|
88 |
$switch->addtag($parse,"Group",\&Group_start,$self,
|
89 |
\&OutToMakefile, $self,
|
90 |
"", $self);
|
91 |
$switch->grouptag("Group",$parse);
|
92 |
$switch->addtag($parse,"External",
|
93 |
\&External_StartTag,$self,
|
94 |
\&OutToMakefile, $self,
|
95 |
"", $self);
|
96 |
$switch->addtag($parse,"lib",
|
97 |
\&lib_start,$self,
|
98 |
\&OutToMakefile, $self,
|
99 |
"", $self);
|
100 |
$switch->addtag($parse,"Architecture",
|
101 |
\&Arch_Start,$self,
|
102 |
\&OutToMakefile, $self,
|
103 |
\&Arch_End,$self);
|
104 |
$switch->addtag($parse,"INCLUDE_PATH",
|
105 |
\&IncludePath_Start,$self,
|
106 |
\&OutToMakefile, $self,
|
107 |
"",$self);
|
108 |
return $switch;
|
109 |
}
|
110 |
|
111 |
sub GenerateMakefile {
|
112 |
my $self=shift;
|
113 |
my $infile=shift;
|
114 |
my $outfile=shift;
|
115 |
|
116 |
$self->{switch}=$self->_initswitcher();
|
117 |
$self->{switch}->filetoparse($infile);
|
118 |
|
119 |
# open a temporary gnumakefile to store output.
|
120 |
my $fh=FileHandle->new();
|
121 |
open ( $fh, ">$outfile") or die "Unable to open $outfile for output ".
|
122 |
"$!\n";
|
123 |
@{$self->{filehandlestack}}=($fh);
|
124 |
|
125 |
# -- make an alias
|
126 |
*GNUmakefile=$fh;
|
127 |
if ( -e $ENV{LatestBuildFile} ) {
|
128 |
print GNUmakefile "include $ENV{LatestBuildFile}\n";
|
129 |
}
|
130 |
$ENV{LatestBuildFile}=$outfile;
|
131 |
$self->{switch}->parse("makebuild"); # sort out supported tags
|
132 |
close GNUmakefile;
|
133 |
}
|
134 |
|
135 |
sub ParseBuildFile {
|
136 |
my $self=shift;
|
137 |
my $base=shift;
|
138 |
my $path=shift;
|
139 |
my $filename=shift @_;
|
140 |
my $fullfilename;
|
141 |
if ( $filename!~/^\// ) {
|
142 |
$fullfilename="$base/$path/$filename";
|
143 |
}
|
144 |
else {
|
145 |
$fullfilename=$filename;
|
146 |
}
|
147 |
$self->{path}=$path;
|
148 |
#print "Processing $fullfilename\n";
|
149 |
$numbins=0;
|
150 |
$self->{envnum}=0;
|
151 |
$self->{envlevel}=0;
|
152 |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
|
153 |
"BuildFile.mk";
|
154 |
$ENV{SCRAM_CURRENTENV}=$self->{currentenv};
|
155 |
|
156 |
# open a temporary gnumakefile to store output.
|
157 |
use Utilities::AddDir;
|
158 |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}");
|
159 |
$self->GenerateMakefile($fullfilename,
|
160 |
$ENV{LOCALTOP}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk");
|
161 |
}
|
162 |
|
163 |
sub ParseBuildFile_Export {
|
164 |
my $self=shift;
|
165 |
my $filename=shift;
|
166 |
my $bf=BuildSystem::BuildFile->new($self->{toolbox});
|
167 |
if ( defined $self->{remoteproject} ) {
|
168 |
$bf->{remoteproject}=$self->{remoteproject};
|
169 |
}
|
170 |
$bf->_parseexport($filename);
|
171 |
undef $bf;
|
172 |
}
|
173 |
|
174 |
sub _location {
|
175 |
my $self=shift;
|
176 |
use File::Basename;
|
177 |
|
178 |
return dirname($self->{switch}->filetoparse());
|
179 |
}
|
180 |
|
181 |
sub _parseexport {
|
182 |
my $self=shift;
|
183 |
my $filename=shift;
|
184 |
|
185 |
my $switchex=ActiveDoc::SimpleDoc->new();
|
186 |
$switchex->filetoparse($filename);
|
187 |
$switchex->newparse("export");
|
188 |
$switchex->addignoretags("export");
|
189 |
$switchex->addtag("export","Export",
|
190 |
\&export_start_export,$self,
|
191 |
\&OutToMakefile, $self,
|
192 |
\&export_end_export,$self);
|
193 |
$self->_commontags($switchex,"export");
|
194 |
$switchex->allowgroup("__export","export");
|
195 |
# $switchex->{Strict_no_cr}='no';
|
196 |
$self->{switch}=$switchex;
|
197 |
$switchex->parse("export"); # sort out supported tags
|
198 |
}
|
199 |
|
200 |
sub _pushremoteproject {
|
201 |
my $self=shift;
|
202 |
my $path=shift;
|
203 |
|
204 |
if ( defined $self->{remoteproject} ) {
|
205 |
push @{$self->{rpstack}}, $self->{remoteproject};
|
206 |
}
|
207 |
$self->{remoteproject}=$path;
|
208 |
}
|
209 |
|
210 |
sub _popremoteproject {
|
211 |
my $self=shift;
|
212 |
if ( $#{$self->{rpstack}} >=0 ) {
|
213 |
$self->{remoteproject}=pop @{$self->{rpstack}};
|
214 |
}
|
215 |
else {
|
216 |
undef $self->{remoteproject};
|
217 |
}
|
218 |
}
|
219 |
|
220 |
sub _toolmapper {
|
221 |
my $self=shift;
|
222 |
if ( ! defined $self->{mapper} ) {
|
223 |
require BuildSystem::ToolMapper;
|
224 |
$self->{mapper}=BuildSystem::ToolMapper->new();
|
225 |
}
|
226 |
if ( @_ ) { #if a class is supplied then supply the map directly
|
227 |
my $class=shift;
|
228 |
return $self->{mapper}->getmap($class);
|
229 |
}
|
230 |
return $self->{mapper};
|
231 |
}
|
232 |
|
233 |
|
234 |
# ---- Tag routines
|
235 |
|
236 |
# -- Override a class type with the <ConfigurationClass type=xxx> tag
|
237 |
# the type tag will pick up a pre-defined class type from project space.
|
238 |
|
239 |
sub Class_StartTag {
|
240 |
my $self=shift;
|
241 |
my $name=shift;
|
242 |
my $hashref=shift;
|
243 |
|
244 |
if ( $self->{Arch} ) {
|
245 |
if ( defined $$hashref{'type'} ) {
|
246 |
$ClassName=$$hashref{'type'};
|
247 |
}
|
248 |
}
|
249 |
}
|
250 |
|
251 |
sub IncludePath_Start {
|
252 |
my $self=shift;
|
253 |
my $name=shift;
|
254 |
my $hashref=shift;
|
255 |
|
256 |
$self->{switch}->checktag( $name, $hashref, 'path');
|
257 |
if ( $self->{Arch} ) {
|
258 |
print GNUmakefile "INCLUDE+=".$self->_location()."/".
|
259 |
$$hashref{'path'}."\n";
|
260 |
}
|
261 |
}
|
262 |
|
263 |
#
|
264 |
# generic build tag
|
265 |
#
|
266 |
sub Build_start {
|
267 |
my $self=shift;
|
268 |
my $name=shift;
|
269 |
my $hashref=shift;
|
270 |
|
271 |
|
272 |
$self->{switch}->checktag($name,$hashref,'class');
|
273 |
if ( $self->{Arch} ) {
|
274 |
my $fh=$self->{filehandlestack}[0];
|
275 |
# -- get the mapper object
|
276 |
my $mapper=$self->_toolmapper($$hashref{'class'});
|
277 |
if ( ! defined $mapper ) {
|
278 |
$self->{switch}->parseerror("Unknown class : ".$$hashref{'class'});
|
279 |
}
|
280 |
else {
|
281 |
# -- get default types
|
282 |
my @deftypes;
|
283 |
if ( ! exists $$hashref{'default'} ) {
|
284 |
@deftypes=$mapper->defaulttypes();
|
285 |
}
|
286 |
else {
|
287 |
@deftypes=split /,/, $$hashref{'default'};
|
288 |
}
|
289 |
|
290 |
# -- no src parameter so it must be a default setting tag
|
291 |
if ( ! exists $$hashref{src} ) {
|
292 |
# -- general default setting
|
293 |
$self->{switch}->checktag($name,$hashref,'default');
|
294 |
$mapper->defaulttypes(@deftypes);
|
295 |
$self->_makegenerictargets($fh, $$hashref{'class'},@deftypes);
|
296 |
}
|
297 |
else {
|
298 |
$self->{switch}->checktag($name,$hashref,'src');
|
299 |
$self->{switch}->checktag($name,$hashref,'name');
|
300 |
my $name=$$hashref{'name'};
|
301 |
my @types=$mapper->types();
|
302 |
|
303 |
|
304 |
my @targets=();
|
305 |
|
306 |
# -- generate generic targets
|
307 |
print $fh "ifndef _BuildLink_\n";
|
308 |
push @targets, ($self->_makegenerictargets($fh,$$hashref{'class'},
|
309 |
@deftypes));
|
310 |
print $fh "Sdefault_".$$hashref{'class'}."_".$$hashref{'name'}.
|
311 |
"=\$(addsuffix _".$$hashref{'name'}.",\$(Sdefault_".
|
312 |
$$hashref{'class'}."))\n";
|
313 |
print $fh $$hashref{'class'}."_".$$hashref{'name'}."::\$(".
|
314 |
"Sdefault_".$$hashref{'class'}."_".$$hashref{'name'}.")\n";
|
315 |
push @targets, $$hashref{'class'}."_".$$hashref{'name'};
|
316 |
|
317 |
# -- generate targets for each type
|
318 |
foreach $type ( @types ) {
|
319 |
|
320 |
# -- generic name for each type
|
321 |
my $pattern=$$hashref{'class'}."_".$type;
|
322 |
my $dirname=$$hashref{'class'}."_".$type."_".$name;
|
323 |
print $fh "# ------ $pattern rules ---------------\n";
|
324 |
print $fh $$hashref{'class'}."_".$type."::".$$hashref{'class'}.
|
325 |
"_".$type."_$name\n\n";
|
326 |
|
327 |
# -- create a new directory rule for each type
|
328 |
push @targets, $pattern;
|
329 |
my $here="$ENV{LOCALTOP}/$ENV{INTwork}/\$(THISDIR)/".$dirname;
|
330 |
my $work=$ENV{INTwork}."/\$(THISDIR)/".$dirname;
|
331 |
my $makefile=$here."/BuildFile.mk";
|
332 |
|
333 |
# -- create link targets to the directory
|
334 |
push @targets, $dirname;
|
335 |
print $fh "# -- Link Targets to $type directories\n";
|
336 |
print $fh "$dirname: make_$dirname\n";
|
337 |
print $fh "\t\@cd $here; \\\n";
|
338 |
print $fh "\t\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
|
339 |
" workdir=$work ".
|
340 |
" -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \n\n";
|
341 |
|
342 |
# -- write target to make makefile for each directory
|
343 |
print $fh "# -- Build target directories\n";
|
344 |
print $fh "make_$dirname:\n";
|
345 |
print $fh "\t\@if [ ! -f \"$makefile\" ]; then \\\n";
|
346 |
print $fh "\t if [ ! -d \"$here\" ]; then \\\n";
|
347 |
print $fh "\t mkdir $here; \\\n";
|
348 |
print $fh "\t fi;\\\n";
|
349 |
#print $fh "\t echo include ".$self->{currentenv}." > ".
|
350 |
print $fh "\t echo include \$(SCRAM_CURRENTENV) > ".
|
351 |
"$makefile; \\\n";
|
352 |
print $fh "\t echo VPATH+=$ENV{LOCALTOP}/".${THISPATH}.
|
353 |
" >> $makefile; \\\n";
|
354 |
print $fh "\t echo buildsrcfiles:=".$$hashref{'src'}.
|
355 |
" >> $makefile; \\\n";
|
356 |
print $fh "\t echo buildname=$name >> $makefile;\\\n";
|
357 |
print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n";
|
358 |
print $fh "\t echo ifdef DefaultBuildFile >> $makefile; \\\n";
|
359 |
print $fh "\t echo include \$(DefaultBuildFile) >> $makefile; \\\n";
|
360 |
print $fh "\t echo DefaultBuildFileIn=true >> $makefile; \\\n";
|
361 |
print $fh "\t echo endif >> $makefile; \\\n";
|
362 |
if ( defined (my @file=$mapper->rulesfile($$hashref{'class'})) ) {
|
363 |
foreach $f ( @file ) {
|
364 |
print $fh "\t echo -include $f >> $makefile; \\\n";
|
365 |
}
|
366 |
}
|
367 |
print $fh "\tfi\n";
|
368 |
print $fh "\n";
|
369 |
# print $typefile "$name :\n";
|
370 |
# print $typefile "\t\$(_quietbuild_)";
|
371 |
# print $typefile $mapper->template($$hashref{'class'},$type)."\n";
|
372 |
# print $typefile "\t\$(_quietstamp_)";
|
373 |
# print $typefile "$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
|
374 |
|
375 |
# -- debug targets
|
376 |
print $fh "# -- debug targets\n";
|
377 |
print $fh $dirname."_echo_% : make_$dirname\n";
|
378 |
print $fh "\t\@cd $here; \n";
|
379 |
print $fh "\t\@\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
|
380 |
" workdir=$work ".
|
381 |
" -f \$(TOOL_HOME)/basics.mk ".
|
382 |
"echo_\$(subst ".$dirname."_echo_,,\$\@) ; \n\n";
|
383 |
push @targets, $dirname."_echo_VAR";
|
384 |
|
385 |
# -- cleaning targets
|
386 |
push @targets, "clean_$dirname";
|
387 |
print $fh "# -- cleaning targets\n";
|
388 |
print $fh "clean::clean_$dirname\n";
|
389 |
print $fh "clean_".$dirname."::\n";
|
390 |
print $fh "\t\@if [ -d $here ]; then \\\n";
|
391 |
print $fh "\techo cleaning $dirname; \\\n";
|
392 |
print $fh "\tcd $here; \\\n";
|
393 |
print $fh "\t\$(MAKE) LatestBuildFile=$makefile workdir=".
|
394 |
$work." _BuildLink_=1 -f ".
|
395 |
"\$(TOOL_HOME)/basics.mk clean; \\\n";
|
396 |
print $fh "\tfi\n\n";
|
397 |
|
398 |
|
399 |
}
|
400 |
# -- help targets
|
401 |
print $fh "helpheader::\n";
|
402 |
print $fh "\t\@echo Targets available:\n";
|
403 |
print $fh "\t\@echo ------------------\n\n";
|
404 |
print $fh "help::helpheader\n";
|
405 |
foreach $target ( @targets ) {
|
406 |
print $fh "help::\n";
|
407 |
print $fh "\t\@echo $target\n"
|
408 |
}
|
409 |
print $fh "endif\n";
|
410 |
} # end else
|
411 |
}
|
412 |
}
|
413 |
}
|
414 |
|
415 |
sub _makegenerictargets {
|
416 |
my $self=shift;
|
417 |
my $fh=shift;
|
418 |
my $class=shift;
|
419 |
my @deftypes=@_;
|
420 |
|
421 |
my @targets=();
|
422 |
# -- generate generic targets
|
423 |
print $fh "# -- Generic targets\n";
|
424 |
push @targets, $class;
|
425 |
print $fh "ifndef Sdefault_".$class."\n";
|
426 |
foreach $dtype ( @deftypes ) {
|
427 |
print $fh $class."::".$class."_".$dtype."\n";
|
428 |
print $fh "Sdefault_".$class."+=".$class."_".$dtype."\n";
|
429 |
}
|
430 |
print $fh "\nendif\n";
|
431 |
return @targets;
|
432 |
}
|
433 |
|
434 |
sub Bin_start {
|
435 |
my $self=shift;
|
436 |
my $name=shift;
|
437 |
my $hashref=shift;
|
438 |
|
439 |
my $fileclass;
|
440 |
my @tools;
|
441 |
my $tool;
|
442 |
my $filename;
|
443 |
my $objectname;
|
444 |
|
445 |
$self->{switch}->checktag($name,$hashref,'file');
|
446 |
if ( $self->{Arch} ) {
|
447 |
if ( ! defined $$hashref{name} ) {
|
448 |
($$hashref{name}=$$hashref{file})=~s/\..*//;
|
449 |
}
|
450 |
($filename=$$hashref{file})=~s/^\///; # make sure full paths dont work
|
451 |
$self->Build_start($name,{ "class" => "bin",
|
452 |
"src" => $filename,
|
453 |
"name" => $$hashref{'name'} } );
|
454 |
}
|
455 |
}
|
456 |
|
457 |
sub External_StartTag {
|
458 |
my $self=shift;
|
459 |
my $name=shift;
|
460 |
my $hashref=shift;
|
461 |
|
462 |
my $tool;
|
463 |
if ( $self->{Arch} ) {
|
464 |
$self->{switch}->checktag($name,$hashref,'ref');
|
465 |
|
466 |
# -- oo toolbox stuff
|
467 |
# - get the appropriate tool object
|
468 |
$$hashref{'ref'}=~tr[A-Z][a-z];
|
469 |
if ( ! exists $$hashref{'version'} ) {
|
470 |
$tool=$self->{toolbox}->gettool($$hashref{'ref'});
|
471 |
}
|
472 |
else {
|
473 |
$tool=$self->{toolbox}->gettool($$hashref{'ref'},$$hashref{'version'});
|
474 |
}
|
475 |
if ( ! defined $tool ) {
|
476 |
$self->{switch}->parseerror("Unknown Tool Specified ("
|
477 |
.$$hashref{'ref'}.")");
|
478 |
}
|
479 |
|
480 |
# -- old fashioned GNUmakefile stuff
|
481 |
print GNUmakefile $$hashref{'ref'};
|
482 |
if ( defined $$hashref{'version'} ) {
|
483 |
print GNUmakefile "_V_".$$hashref{'version'};
|
484 |
}
|
485 |
print GNUmakefile "=true\n";
|
486 |
|
487 |
# -- Sub system also specified?
|
488 |
if ( exists $$hashref{'use'} ) {
|
489 |
# -- look for a buildfile
|
490 |
my @paths=$tool->getfeature("INCLUDE");
|
491 |
my $file="";
|
492 |
my ($path,$testfile);
|
493 |
foreach $path ( @paths ) {
|
494 |
$testfile=$path."/".$$hashref{'use'}."/BuildFile" ;
|
495 |
if ( -f $testfile ) {
|
496 |
$file=$testfile;
|
497 |
$self->_pushremoteproject($path);
|
498 |
}
|
499 |
}
|
500 |
if ( $file eq "" ) {
|
501 |
$self->{switch}->parseerror("Unable to find SubSystem $testfile");
|
502 |
}
|
503 |
$self->ParseBuildFile_Export($file);
|
504 |
$self->_popremoteproject();
|
505 |
}
|
506 |
}
|
507 |
}
|
508 |
|
509 |
sub Group_start {
|
510 |
my $self=shift;
|
511 |
my $name=shift;
|
512 |
my $hashref=shift;
|
513 |
|
514 |
$self->{switch}->checktag($name, $hashref, 'name');
|
515 |
if ( $self->{Arch} ) {
|
516 |
print GNUmakefile "GROUP_".$$hashref{'name'};
|
517 |
if ( defined $$hashref{'version'} ) {
|
518 |
print GNUmakefile "_V_".$$hashref{'version'};
|
519 |
}
|
520 |
print GNUmakefile "=true\n";
|
521 |
}
|
522 |
}
|
523 |
|
524 |
sub Use_start {
|
525 |
my $self=shift;
|
526 |
my $name=shift;
|
527 |
my $hashref=shift;
|
528 |
my $filename;
|
529 |
use Utilities::SCRAMUtils;
|
530 |
|
531 |
$self->{switch}->checktag($name, $hashref, "name");
|
532 |
if ( $self->{Arch} ) {
|
533 |
if ( exists $$hashref{'group'} ) {
|
534 |
print GNUmakefile "GROUP_".$$hashref{'group'}."=true\n";
|
535 |
}
|
536 |
if ( ! defined $self->{remoteproject} ) {
|
537 |
$filename=SCRAMUtils::checkfile(
|
538 |
"/$ENV{INTsrc}/$$hashref{name}/BuildFile");
|
539 |
}
|
540 |
else {
|
541 |
$filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
|
542 |
print "trying $filename\n";
|
543 |
if ( ! -f $filename ) { $filename=""; };
|
544 |
}
|
545 |
if ( $filename ne "" ) {
|
546 |
$self->ParseBuildFile_Export( $filename );
|
547 |
}
|
548 |
else {
|
549 |
$self->{switch}->parseerror("Unable to detect Appropriate ".
|
550 |
"decription file for <$name name=".$$hashref{name}.">");
|
551 |
}
|
552 |
}
|
553 |
}
|
554 |
|
555 |
sub CheckBuildFile {
|
556 |
my $self=shift;
|
557 |
my $classdir=shift;
|
558 |
my $ClassName="";
|
559 |
my $thisfile="$classdir/$buildfile";
|
560 |
|
561 |
if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
|
562 |
$DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
|
563 |
$self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
|
564 |
}
|
565 |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
|
566 |
$DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
|
567 |
$self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
|
568 |
}
|
569 |
return $ClassName;
|
570 |
}
|
571 |
|
572 |
# List association groups between <AssociateGroup> tags
|
573 |
# seperated by newlines or spaces
|
574 |
sub AssociateGroup {
|
575 |
my $self=shift;
|
576 |
my $name=shift;
|
577 |
my $string=shift;
|
578 |
my $word;
|
579 |
|
580 |
foreach $word ( (split /\s/, $string) ){
|
581 |
chomp $word;
|
582 |
next if /^#/;
|
583 |
if ( $word=~/none/ ) {
|
584 |
$self->{ignore}=1;
|
585 |
}
|
586 |
}
|
587 |
}
|
588 |
|
589 |
sub Arch_Start {
|
590 |
my $self=shift;
|
591 |
my $name=shift;
|
592 |
my $hashref=shift;
|
593 |
|
594 |
$self->{switch}->checktag($name, $hashref,'name');
|
595 |
( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
|
596 |
: ($self->{Arch}=0);
|
597 |
push @{$self->{ARCHBLOCK}}, $self->{Arch};
|
598 |
}
|
599 |
|
600 |
sub Arch_End {
|
601 |
my $self=shift;
|
602 |
my $name=shift;
|
603 |
|
604 |
pop @{$self->{ARCHBLOCK}};
|
605 |
$self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
|
606 |
}
|
607 |
|
608 |
# Split up the Class Block String into a useable array
|
609 |
sub _CutBlock {
|
610 |
my $self=shift;
|
611 |
my $string= shift @_;
|
612 |
@BlockClassA = split /\//, $string;
|
613 |
}
|
614 |
|
615 |
sub OutToMakefile {
|
616 |
my $self=shift;
|
617 |
my $name=shift;
|
618 |
my @vars=@_;
|
619 |
|
620 |
if ( $self->{Arch} ) {
|
621 |
print GNUmakefile @vars;
|
622 |
}
|
623 |
}
|
624 |
|
625 |
sub OutToScreen {
|
626 |
my $name=shift;
|
627 |
my @vars=@_;
|
628 |
|
629 |
if ( $self->{Arch} ) {
|
630 |
print @vars;
|
631 |
}
|
632 |
}
|
633 |
sub setBlockClassPath {
|
634 |
my $self=shift;
|
635 |
my $name=shift;
|
636 |
my $hashref=shift;
|
637 |
|
638 |
$self->{switch}->checktag($name, $hashref, 'path');
|
639 |
$self->{BlockClassPath}=$self->{BlockClassPath}.":".$$hashref{path};
|
640 |
$self->_CutBlock($$hashref{path});
|
641 |
}
|
642 |
|
643 |
sub BlockClassPath {
|
644 |
my $self=shift;
|
645 |
return $self->{BlockClassPath};
|
646 |
}
|
647 |
|
648 |
sub export_start_export {
|
649 |
my $self=shift;
|
650 |
my $name=shift;
|
651 |
my $hashref=shift;
|
652 |
|
653 |
$self->{switch}->opengroup("__export");
|
654 |
}
|
655 |
|
656 |
sub export_start {
|
657 |
my $self=shift;
|
658 |
my $name=shift;
|
659 |
my $hashref=shift;
|
660 |
|
661 |
$self->{switch}->opengroup("__export");
|
662 |
if ( exists $$hashref{autoexport} ) {
|
663 |
print GNUmakefile "scram_autoexport=".$$hashref{autoexport}."\n";
|
664 |
if ( $$hashref{autoexport}=~/true/ ) {
|
665 |
$self->{switch}->allowgroup("__export","makebuild");
|
666 |
}
|
667 |
else {
|
668 |
$self->{switch}->disallowgroup("__export","makebuild");
|
669 |
}
|
670 |
}
|
671 |
# -- allow default setting from other makefiles
|
672 |
print GNUmakefile "ifeq (\$(scram_autoexport),true)\n";
|
673 |
}
|
674 |
|
675 |
sub export_end_export {
|
676 |
my $self=shift;
|
677 |
$self->{switch}->closegroup("__export");
|
678 |
}
|
679 |
|
680 |
sub export_end {
|
681 |
my $self=shift;
|
682 |
$self->{switch}->closegroup("__export");
|
683 |
print GNUmakefile "endif\n";
|
684 |
}
|
685 |
|
686 |
#
|
687 |
# Standard lib tag
|
688 |
#
|
689 |
sub lib_start {
|
690 |
my $self=shift;
|
691 |
my $name=shift;
|
692 |
my $hashref=shift;
|
693 |
|
694 |
$self->{switch}->checktag($name, $hashref, 'name');
|
695 |
if ( $self->{Arch} ) {
|
696 |
print GNUmakefile "lib+=$$hashref{name}\n";
|
697 |
}
|
698 |
}
|
699 |
|
700 |
#
|
701 |
# libtype specification
|
702 |
#
|
703 |
sub LibType_Start {
|
704 |
my $self=shift;
|
705 |
my $name=shift;
|
706 |
my $hashref=shift;
|
707 |
|
708 |
if ( $self->{Arch} ) {
|
709 |
if ( defined $self->{libtype_conext} ) {
|
710 |
$self->{switch}->parseerror("<$name> tag cannot be specified".
|
711 |
" without a </$name> tag to close previous context");
|
712 |
}
|
713 |
else {
|
714 |
$self->{libtype_conext}=1;
|
715 |
$self->{switch}->checktag($name, $hashref, 'type');
|
716 |
|
717 |
print GNUmakefile "# Specify Library Type\n";
|
718 |
print GNUmakefile "DefaultLibsOff=yes\n";
|
719 |
if ( $$hashref{'type'}=~/^archive/i ) {
|
720 |
print GNUmakefile "LibArchive=true\n";
|
721 |
}
|
722 |
elsif ($$hashref{'type'}=~/debug_archive/i ) {
|
723 |
print GNUmakefile "LibDebugArchive=true\n";
|
724 |
}
|
725 |
elsif ($$hashref{'type'}=~/debug_shared/i ) {
|
726 |
print GNUmakefile "LibDebugShared=true\n";
|
727 |
}
|
728 |
elsif ($$hashref{'type'}=~/shared/i ) {
|
729 |
print GNUmakefile 'LibShared=true'."\n";
|
730 |
}
|
731 |
print GNUmakefile "\n";
|
732 |
}
|
733 |
}
|
734 |
}
|
735 |
|
736 |
sub LibType_text {
|
737 |
my $self=shift;
|
738 |
my $name=shift;
|
739 |
my $string=shift;
|
740 |
|
741 |
if ( $self->{Arch} ) {
|
742 |
$string=~s/\n/ /g;
|
743 |
print GNUmakefile "libmsg::\n\t\@echo Library info: ";
|
744 |
print GNUmakefile $string;
|
745 |
print GNUmakefile "\n";
|
746 |
}
|
747 |
}
|
748 |
|
749 |
sub LibType_end {
|
750 |
my $self=shift;
|
751 |
my $name=shift;
|
752 |
|
753 |
undef $self->{libtype_conext};
|
754 |
}
|
755 |
|
756 |
sub Environment_start {
|
757 |
my $self=shift;
|
758 |
my $name=shift;
|
759 |
my $hashref=shift;
|
760 |
|
761 |
if ( $self->{Arch} ) {
|
762 |
$self->{envnum}++;
|
763 |
|
764 |
# open a new Environment File
|
765 |
my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
|
766 |
$self->{envnum}.".mk";
|
767 |
use FileHandle;
|
768 |
my $fh=FileHandle->new();
|
769 |
open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
|
770 |
push @{$self->{filehandlestack}}, $fh;
|
771 |
*GNUmakefile=$fh;
|
772 |
|
773 |
# include the approprate environment file
|
774 |
if ( $self->{envlevel} == 0 ) {
|
775 |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
|
776 |
$self->{path}."/BuildFile.mk\n";
|
777 |
}
|
778 |
else {
|
779 |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
|
780 |
$self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
|
781 |
}
|
782 |
$self->{envlevel}++;
|
783 |
$self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
|
784 |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
|
785 |
}
|
786 |
$ENV{SCRAM_CURRENTENV}=$self->{currentenv};
|
787 |
}
|
788 |
|
789 |
sub Environment_end {
|
790 |
my $self=shift;
|
791 |
my $fd;
|
792 |
|
793 |
if ( $self->{Arch} ) {
|
794 |
$self->{envlevel}--;
|
795 |
if ( $self->{envlevel} < 0 ) {
|
796 |
print "Too many </Environent> Tags on $self->{switch}->line()\n";
|
797 |
exit 1;
|
798 |
}
|
799 |
close GNUmakefile;
|
800 |
# restore the last filehandle
|
801 |
$fd=pop @{$self->{filehandlestack}};
|
802 |
close $fd;
|
803 |
*GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
|
804 |
if ( $self->{envlevel} < 1 ) {
|
805 |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
|
806 |
"BuildFile.mk";
|
807 |
}
|
808 |
else {
|
809 |
$self->{currentenv}=
|
810 |
"$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
|
811 |
$self->{Envlevels}[$self->{envlevel}];
|
812 |
}
|
813 |
$ENV{SCRAM_CURRENTENV}=$self->{currentenv};
|
814 |
}
|
815 |
}
|