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 |
$self->{switch}->checktag($name,$hashref,'class');
|
272 |
$self->{switch}->checktag($name,$hashref,'src');
|
273 |
if ( $self->{Arch} ) {
|
274 |
|
275 |
# -- determine the build products name
|
276 |
my $name;
|
277 |
if ( exists $$hashref{'name'} ) {
|
278 |
$name=$$hashref{'name'};
|
279 |
}
|
280 |
else {
|
281 |
$self->{switch}->parseerror("No name specified for build product");
|
282 |
#$name="\$(buildname)";
|
283 |
}
|
284 |
|
285 |
# -- check we have a lookup for the class type
|
286 |
my $mapper=$self->_toolmapper($$hashref{'class'});
|
287 |
if ( ! defined $mapper ) {
|
288 |
$self->{switch}->parseerror("Unknown class : ".$$hashref{'class'});
|
289 |
}
|
290 |
else {
|
291 |
my @types=$mapper->types();
|
292 |
|
293 |
# -- get default build rules
|
294 |
my @deftypes;
|
295 |
if ( ! exists $$hashref{'default'} ) {
|
296 |
@deftypes=$mapper->defaulttypes();
|
297 |
}
|
298 |
else {
|
299 |
@deftypes=split /,/, $$hashref{'default'};
|
300 |
}
|
301 |
|
302 |
my $fh=$self->{filehandlestack}[0];
|
303 |
my @targets=();
|
304 |
|
305 |
# -- generate generic targets
|
306 |
print $fh "ifndef _BuildLink_\n";
|
307 |
print $fh "# -- Generic targets\n";
|
308 |
push @targets, $$hashref{'class'};
|
309 |
push @targets, $$hashref{'class'}."_".$$hashref{'name'};
|
310 |
foreach $dtype ( @deftypes ) {
|
311 |
print $fh $$hashref{'class'}."::".$$hashref{'class'}."_".
|
312 |
$dtype."\n";
|
313 |
print $fh $$hashref{'class'}."_".$$hashref{'name'}.
|
314 |
"::".$$hashref{'class'}."_".$dtype."_".
|
315 |
$$hashref{'name'}."\n";
|
316 |
}
|
317 |
print $fh "\n";
|
318 |
|
319 |
# -- generate targets for each type
|
320 |
foreach $type ( @types ) {
|
321 |
|
322 |
# -- generic name for each type
|
323 |
my $pattern=$$hashref{'class'}."_".$type;
|
324 |
my $dirname=$$hashref{'class'}."_".$type."_".$name;
|
325 |
print $fh "# ------ $pattern rules ---------------\n";
|
326 |
print $fh $$hashref{'class'}."_".$type."::".$$hashref{'class'}.
|
327 |
"_".$type."_$name\n\n";
|
328 |
|
329 |
# -- create a new directory rule for each type
|
330 |
push @targets, $pattern;
|
331 |
my $here="$ENV{LOCALTOP}/$ENV{INTwork}/\$(THISDIR)/".$dirname;
|
332 |
my $work=$ENV{INTwork}."/\$(THISDIR)/".$dirname;
|
333 |
my $makefile=$here."/BuildFile.mk";
|
334 |
|
335 |
# -- create link targets to the directory
|
336 |
push @targets, $dirname;
|
337 |
print $fh "# -- Link Targets to $type directories\n";
|
338 |
print $fh "$dirname: make_$dirname\n";
|
339 |
print $fh "\t\@cd $here; \\\n";
|
340 |
print $fh "\t\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
|
341 |
" workdir=$work ".
|
342 |
" -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \n\n";
|
343 |
|
344 |
# -- write target to make makefile for each directory
|
345 |
print $fh "# -- Build target directories\n";
|
346 |
print $fh "make_$dirname:\n";
|
347 |
print $fh "\t\@if [ ! -f \"$makefile\" ]; then \\\n";
|
348 |
print $fh "\t if [ ! -d \"$here\" ]; then \\\n";
|
349 |
print $fh "\t mkdir $here; \\\n";
|
350 |
print $fh "\t fi;\\\n";
|
351 |
#print $fh "\t echo include ".$self->{currentenv}." > ".
|
352 |
print $fh "\t echo include \$(SCRAM_CURRENTENV) > ".
|
353 |
"$makefile; \\\n";
|
354 |
print $fh "\t echo VPATH+=$ENV{LOCALTOP}/".${THISPATH}.
|
355 |
" >> $makefile; \\\n";
|
356 |
print $fh "\t echo buildsrcfiles:=".$$hashref{'src'}.
|
357 |
" >> $makefile; \\\n";
|
358 |
print $fh "\t echo buildname=$name >> $makefile;\\\n";
|
359 |
print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n";
|
360 |
print $fh "\t echo ifdef DefaultBuildFile >> $makefile; \\\n";
|
361 |
print $fh "\t echo include \$(DefaultBuildFile) >> $makefile; \\\n";
|
362 |
print $fh "\t echo DefaultBuildFileIn=true >> $makefile; \\\n";
|
363 |
print $fh "\t echo endif >> $makefile; \\\n";
|
364 |
if ( defined (my @file=$mapper->rulesfile($$hashref{'class'})) ) {
|
365 |
foreach $f ( @file ) {
|
366 |
print $fh "\t echo -include $f >> $makefile; \\\n";
|
367 |
}
|
368 |
}
|
369 |
print $fh "\tfi\n";
|
370 |
print $fh "\n";
|
371 |
# print $typefile "$name :\n";
|
372 |
# print $typefile "\t\$(_quietbuild_)";
|
373 |
# print $typefile $mapper->template($$hashref{'class'},$type)."\n";
|
374 |
# print $typefile "\t\$(_quietstamp_)";
|
375 |
# print $typefile "$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
|
376 |
|
377 |
# -- debug targets
|
378 |
print $fh "# -- debug targets\n";
|
379 |
print $fh $dirname."_echo_% : make_$dirname\n";
|
380 |
print $fh "\t\@cd $here; \n";
|
381 |
print $fh "\t\@\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
|
382 |
" workdir=$work ".
|
383 |
" -f \$(TOOL_HOME)/basics.mk ".
|
384 |
"echo_\$(subst ".$dirname."_echo_,,\$\@) ; \n\n";
|
385 |
push @targets, $dirname."_echo_VAR";
|
386 |
|
387 |
# -- cleaning targets
|
388 |
push @targets, "clean_$dirname";
|
389 |
print $fh "# -- cleaning targets\n";
|
390 |
print $fh "clean::clean_$dirname\n";
|
391 |
print $fh "clean_".$dirname."::\n";
|
392 |
print $fh "\t\@if [ -d $here ]; then \\\n";
|
393 |
print $fh "\techo cleaning $dirname; \\\n";
|
394 |
print $fh "\tcd $here; \\\n";
|
395 |
print $fh "\t\$(MAKE) LatestBuildFile=$makefile workdir=".
|
396 |
$work." _BuildLink_=1 -f ".
|
397 |
"\$(TOOL_HOME)/basics.mk clean; \\\n";
|
398 |
print $fh "\tfi\n\n";
|
399 |
|
400 |
|
401 |
}
|
402 |
# -- help targets
|
403 |
print $fh "helpheader::\n";
|
404 |
print $fh "\t\@echo Targets available:\n";
|
405 |
print $fh "\t\@echo ------------------\n\n";
|
406 |
print $fh "help::helpheader\n";
|
407 |
foreach $target ( @targets ) {
|
408 |
print $fh "help::\n";
|
409 |
print $fh "\t\@echo $target\n"
|
410 |
}
|
411 |
print $fh "endif\n";
|
412 |
} # end else
|
413 |
}
|
414 |
}
|
415 |
|
416 |
sub Bin_start {
|
417 |
my $self=shift;
|
418 |
my $name=shift;
|
419 |
my $hashref=shift;
|
420 |
|
421 |
my $fileclass;
|
422 |
my @tools;
|
423 |
my $tool;
|
424 |
my $filename;
|
425 |
my $objectname;
|
426 |
|
427 |
$self->{switch}->checktag($name,$hashref,'file');
|
428 |
if ( $self->{Arch} ) {
|
429 |
if ( ! defined $$hashref{name} ) {
|
430 |
($$hashref{name}=$$hashref{file})=~s/\..*//;
|
431 |
}
|
432 |
($filename=$$hashref{file})=~s/^\///; # make sure full paths dont work
|
433 |
$self->Build_start($name,{ "class" => "bin",
|
434 |
"src" => $filename,
|
435 |
"name" => $$hashref{'name'} } );
|
436 |
}
|
437 |
}
|
438 |
|
439 |
sub External_StartTag {
|
440 |
my $self=shift;
|
441 |
my $name=shift;
|
442 |
my $hashref=shift;
|
443 |
|
444 |
my $tool;
|
445 |
if ( $self->{Arch} ) {
|
446 |
$self->{switch}->checktag($name,$hashref,'ref');
|
447 |
|
448 |
# -- oo toolbox stuff
|
449 |
# - get the appropriate tool object
|
450 |
$$hashref{'ref'}=~tr[A-Z][a-z];
|
451 |
if ( ! exists $$hashref{'version'} ) {
|
452 |
$tool=$self->{toolbox}->gettool($$hashref{'ref'});
|
453 |
}
|
454 |
else {
|
455 |
$tool=$self->{toolbox}->gettool($$hashref{'ref'},$$hashref{'version'});
|
456 |
}
|
457 |
if ( ! defined $tool ) {
|
458 |
$self->{switch}->parseerror("Unknown Tool Specified ("
|
459 |
.$$hashref{'ref'}.")");
|
460 |
}
|
461 |
|
462 |
# -- old fashioned GNUmakefile stuff
|
463 |
print GNUmakefile $$hashref{'ref'};
|
464 |
if ( defined $$hashref{'version'} ) {
|
465 |
print GNUmakefile "_V_".$$hashref{'version'};
|
466 |
}
|
467 |
print GNUmakefile "=true\n";
|
468 |
|
469 |
# -- Sub system also specified?
|
470 |
if ( exists $$hashref{'use'} ) {
|
471 |
# -- look for a buildfile
|
472 |
my @paths=$tool->getfeature("INCLUDE");
|
473 |
my $file="";
|
474 |
my ($path,$testfile);
|
475 |
foreach $path ( @paths ) {
|
476 |
$testfile=$path."/".$$hashref{'use'}."/BuildFile" ;
|
477 |
if ( -f $testfile ) {
|
478 |
$file=$testfile;
|
479 |
$self->_pushremoteproject($path);
|
480 |
}
|
481 |
}
|
482 |
if ( $file eq "" ) {
|
483 |
$self->{switch}->parseerror("Unable to find SubSystem $testfile");
|
484 |
}
|
485 |
$self->ParseBuildFile_Export($file);
|
486 |
$self->_popremoteproject();
|
487 |
}
|
488 |
}
|
489 |
}
|
490 |
|
491 |
sub Group_start {
|
492 |
my $self=shift;
|
493 |
my $name=shift;
|
494 |
my $hashref=shift;
|
495 |
|
496 |
$self->{switch}->checktag($name, $hashref, 'name');
|
497 |
if ( $self->{Arch} ) {
|
498 |
print GNUmakefile "GROUP_".$$hashref{'name'};
|
499 |
if ( defined $$hashref{'version'} ) {
|
500 |
print GNUmakefile "_V_".$$hashref{'version'};
|
501 |
}
|
502 |
print GNUmakefile "=true\n";
|
503 |
}
|
504 |
}
|
505 |
|
506 |
sub Use_start {
|
507 |
my $self=shift;
|
508 |
my $name=shift;
|
509 |
my $hashref=shift;
|
510 |
my $filename;
|
511 |
use Utilities::SCRAMUtils;
|
512 |
|
513 |
$self->{switch}->checktag($name, $hashref, "name");
|
514 |
if ( $self->{Arch} ) {
|
515 |
if ( exists $$hashref{'group'} ) {
|
516 |
print GNUmakefile "GROUP_".$$hashref{'group'}."=true\n";
|
517 |
}
|
518 |
if ( ! defined $self->{remoteproject} ) {
|
519 |
$filename=SCRAMUtils::checkfile(
|
520 |
"/$ENV{INTsrc}/$$hashref{name}/BuildFile");
|
521 |
}
|
522 |
else {
|
523 |
$filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
|
524 |
print "trying $filename\n";
|
525 |
if ( ! -f $filename ) { $filename=""; };
|
526 |
}
|
527 |
if ( $filename ne "" ) {
|
528 |
$self->ParseBuildFile_Export( $filename );
|
529 |
}
|
530 |
else {
|
531 |
$self->{switch}->parseerror("Unable to detect Appropriate ".
|
532 |
"decription file for <$name name=".$$hashref{name}.">");
|
533 |
}
|
534 |
}
|
535 |
}
|
536 |
|
537 |
sub CheckBuildFile {
|
538 |
my $self=shift;
|
539 |
my $classdir=shift;
|
540 |
my $ClassName="";
|
541 |
my $thisfile="$classdir/$buildfile";
|
542 |
|
543 |
if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
|
544 |
$DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
|
545 |
$self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
|
546 |
}
|
547 |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
|
548 |
$DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
|
549 |
$self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
|
550 |
}
|
551 |
return $ClassName;
|
552 |
}
|
553 |
|
554 |
# List association groups between <AssociateGroup> tags
|
555 |
# seperated by newlines or spaces
|
556 |
sub AssociateGroup {
|
557 |
my $self=shift;
|
558 |
my $name=shift;
|
559 |
my $string=shift;
|
560 |
my $word;
|
561 |
|
562 |
foreach $word ( (split /\s/, $string) ){
|
563 |
chomp $word;
|
564 |
next if /^#/;
|
565 |
if ( $word=~/none/ ) {
|
566 |
$self->{ignore}=1;
|
567 |
}
|
568 |
}
|
569 |
}
|
570 |
|
571 |
sub Arch_Start {
|
572 |
my $self=shift;
|
573 |
my $name=shift;
|
574 |
my $hashref=shift;
|
575 |
|
576 |
$self->{switch}->checktag($name, $hashref,'name');
|
577 |
( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
|
578 |
: ($self->{Arch}=0);
|
579 |
push @{$self->{ARCHBLOCK}}, $self->{Arch};
|
580 |
}
|
581 |
|
582 |
sub Arch_End {
|
583 |
my $self=shift;
|
584 |
my $name=shift;
|
585 |
|
586 |
pop @{$self->{ARCHBLOCK}};
|
587 |
$self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
|
588 |
}
|
589 |
|
590 |
# Split up the Class Block String into a useable array
|
591 |
sub _CutBlock {
|
592 |
my $self=shift;
|
593 |
my $string= shift @_;
|
594 |
@BlockClassA = split /\//, $string;
|
595 |
}
|
596 |
|
597 |
sub OutToMakefile {
|
598 |
my $self=shift;
|
599 |
my $name=shift;
|
600 |
my @vars=@_;
|
601 |
|
602 |
if ( $self->{Arch} ) {
|
603 |
print GNUmakefile @vars;
|
604 |
}
|
605 |
}
|
606 |
|
607 |
sub OutToScreen {
|
608 |
my $name=shift;
|
609 |
my @vars=@_;
|
610 |
|
611 |
if ( $self->{Arch} ) {
|
612 |
print @vars;
|
613 |
}
|
614 |
}
|
615 |
sub setBlockClassPath {
|
616 |
my $self=shift;
|
617 |
my $name=shift;
|
618 |
my $hashref=shift;
|
619 |
|
620 |
$self->{switch}->checktag($name, $hashref, 'path');
|
621 |
$self->{BlockClassPath}=$self->{BlockClassPath}.":".$$hashref{path};
|
622 |
$self->_CutBlock($$hashref{path});
|
623 |
}
|
624 |
|
625 |
sub BlockClassPath {
|
626 |
my $self=shift;
|
627 |
return $self->{BlockClassPath};
|
628 |
}
|
629 |
|
630 |
sub export_start_export {
|
631 |
my $self=shift;
|
632 |
my $name=shift;
|
633 |
my $hashref=shift;
|
634 |
|
635 |
$self->{switch}->opengroup("__export");
|
636 |
}
|
637 |
|
638 |
sub export_start {
|
639 |
my $self=shift;
|
640 |
my $name=shift;
|
641 |
my $hashref=shift;
|
642 |
|
643 |
$self->{switch}->opengroup("__export");
|
644 |
if ( exists $$hashref{autoexport} ) {
|
645 |
print GNUmakefile "scram_autoexport=".$$hashref{autoexport}."\n";
|
646 |
if ( $$hashref{autoexport}=~/true/ ) {
|
647 |
$self->{switch}->allowgroup("__export","makebuild");
|
648 |
}
|
649 |
else {
|
650 |
$self->{switch}->disallowgroup("__export","makebuild");
|
651 |
}
|
652 |
}
|
653 |
# -- allow default setting from other makefiles
|
654 |
print GNUmakefile "ifeq (\$(scram_autoexport),true)\n";
|
655 |
}
|
656 |
|
657 |
sub export_end_export {
|
658 |
my $self=shift;
|
659 |
$self->{switch}->closegroup("__export");
|
660 |
}
|
661 |
|
662 |
sub export_end {
|
663 |
my $self=shift;
|
664 |
$self->{switch}->closegroup("__export");
|
665 |
print GNUmakefile "endif\n";
|
666 |
}
|
667 |
|
668 |
#
|
669 |
# Standard lib tag
|
670 |
#
|
671 |
sub lib_start {
|
672 |
my $self=shift;
|
673 |
my $name=shift;
|
674 |
my $hashref=shift;
|
675 |
|
676 |
$self->{switch}->checktag($name, $hashref, 'name');
|
677 |
if ( $self->{Arch} ) {
|
678 |
print GNUmakefile "lib+=$$hashref{name}\n";
|
679 |
}
|
680 |
}
|
681 |
|
682 |
#
|
683 |
# libtype specification
|
684 |
#
|
685 |
sub LibType_Start {
|
686 |
my $self=shift;
|
687 |
my $name=shift;
|
688 |
my $hashref=shift;
|
689 |
|
690 |
if ( $self->{Arch} ) {
|
691 |
if ( defined $self->{libtype_conext} ) {
|
692 |
$self->{switch}->parseerror("<$name> tag cannot be specified".
|
693 |
" without a </$name> tag to close previous context");
|
694 |
}
|
695 |
else {
|
696 |
$self->{libtype_conext}=1;
|
697 |
$self->{switch}->checktag($name, $hashref, 'type');
|
698 |
|
699 |
print GNUmakefile "# Specify Library Type\n";
|
700 |
print GNUmakefile "DefaultLibsOff=yes\n";
|
701 |
if ( $$hashref{'type'}=~/^archive/i ) {
|
702 |
print GNUmakefile "LibArchive=true\n";
|
703 |
}
|
704 |
elsif ($$hashref{'type'}=~/debug_archive/i ) {
|
705 |
print GNUmakefile "LibDebugArchive=true\n";
|
706 |
}
|
707 |
elsif ($$hashref{'type'}=~/debug_shared/i ) {
|
708 |
print GNUmakefile "LibDebugShared=true\n";
|
709 |
}
|
710 |
elsif ($$hashref{'type'}=~/shared/i ) {
|
711 |
print GNUmakefile 'LibShared=true'."\n";
|
712 |
}
|
713 |
print GNUmakefile "\n";
|
714 |
}
|
715 |
}
|
716 |
}
|
717 |
|
718 |
sub LibType_text {
|
719 |
my $self=shift;
|
720 |
my $name=shift;
|
721 |
my $string=shift;
|
722 |
|
723 |
if ( $self->{Arch} ) {
|
724 |
$string=~s/\n/ /g;
|
725 |
print GNUmakefile "libmsg::\n\t\@echo Library info: ";
|
726 |
print GNUmakefile $string;
|
727 |
print GNUmakefile "\n";
|
728 |
}
|
729 |
}
|
730 |
|
731 |
sub LibType_end {
|
732 |
my $self=shift;
|
733 |
my $name=shift;
|
734 |
|
735 |
undef $self->{libtype_conext};
|
736 |
}
|
737 |
|
738 |
sub Environment_start {
|
739 |
my $self=shift;
|
740 |
my $name=shift;
|
741 |
my $hashref=shift;
|
742 |
|
743 |
if ( $self->{Arch} ) {
|
744 |
$self->{envnum}++;
|
745 |
|
746 |
# open a new Environment File
|
747 |
my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
|
748 |
$self->{envnum}.".mk";
|
749 |
use FileHandle;
|
750 |
my $fh=FileHandle->new();
|
751 |
open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
|
752 |
push @{$self->{filehandlestack}}, $fh;
|
753 |
*GNUmakefile=$fh;
|
754 |
|
755 |
# include the approprate environment file
|
756 |
if ( $self->{envlevel} == 0 ) {
|
757 |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
|
758 |
$self->{path}."/BuildFile.mk\n";
|
759 |
}
|
760 |
else {
|
761 |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
|
762 |
$self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
|
763 |
}
|
764 |
$self->{envlevel}++;
|
765 |
$self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
|
766 |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
|
767 |
}
|
768 |
$ENV{SCRAM_CURRENTENV}=$self->{currentenv};
|
769 |
}
|
770 |
|
771 |
sub Environment_end {
|
772 |
my $self=shift;
|
773 |
my $fd;
|
774 |
|
775 |
if ( $self->{Arch} ) {
|
776 |
$self->{envlevel}--;
|
777 |
if ( $self->{envlevel} < 0 ) {
|
778 |
print "Too many </Environent> Tags on $self->{switch}->line()\n";
|
779 |
exit 1;
|
780 |
}
|
781 |
close GNUmakefile;
|
782 |
# restore the last filehandle
|
783 |
$fd=pop @{$self->{filehandlestack}};
|
784 |
close $fd;
|
785 |
*GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
|
786 |
if ( $self->{envlevel} < 1 ) {
|
787 |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
|
788 |
"BuildFile.mk";
|
789 |
}
|
790 |
else {
|
791 |
$self->{currentenv}=
|
792 |
"$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
|
793 |
$self->{Envlevels}[$self->{envlevel}];
|
794 |
}
|
795 |
$ENV{SCRAM_CURRENTENV}=$self->{currentenv};
|
796 |
}
|
797 |
}
|