2 |
|
# |
3 |
|
# Interface |
4 |
|
# --------- |
5 |
< |
# new(ConfigArea,Builder) |
5 |
> |
# new(toolbox) |
6 |
|
# ParseBuildFile($base,$path,$file) |
7 |
|
# ParseBuildFileExport(filename) |
8 |
– |
# BlockParse(Block) : perform a parse to modify the block |
8 |
|
# BlockClassPath() : Return the class path |
9 |
|
# ignore() : return 1 if directory should be ignored 0 otherwise |
11 |
– |
# classname() : get/set the associated class |
12 |
– |
# buildfile() : get/set BuildFile location |
13 |
– |
# makefile() : get the generated makefile |
10 |
|
|
11 |
|
package BuildSystem::BuildFile; |
12 |
|
use ActiveDoc::SimpleDoc; |
21 |
|
my $class=shift; |
22 |
|
my $self={}; |
23 |
|
bless $self, $class; |
24 |
< |
$self->{area}=shift; |
29 |
< |
$self->{Builder}=shift; |
30 |
< |
$self->{toolbox}=$self->{area}->toolbox(); |
31 |
< |
$self->{localtop}=$self->{area}->location(); |
32 |
< |
# -- set RELEASTOP |
33 |
< |
my $rarea=$self->{area}->linkarea(); |
34 |
< |
if ( ! defined $rarea ) { |
35 |
< |
$self->{releasetop}=$self->{localtop}; |
36 |
< |
} |
37 |
< |
else { |
38 |
< |
$self->{releasetop}=$rarea->location(); |
39 |
< |
} |
40 |
< |
$self->{releasetop}=$self->{area}->location(); |
24 |
> |
$self->{toolbox}=shift; |
25 |
|
$self->{Arch}=1; |
26 |
|
push @{$self->{ARCHBLOCK}}, $self->{Arch}; |
27 |
|
return $self; |
28 |
|
} |
29 |
|
|
46 |
– |
sub buildfile { |
47 |
– |
my $self=shift; |
48 |
– |
if ( @_ ) { |
49 |
– |
$self->{buildfile}=shift; |
50 |
– |
} |
51 |
– |
return $self->{buildfile}; |
52 |
– |
} |
53 |
– |
|
54 |
– |
sub makefile { |
55 |
– |
my $self=shift; |
56 |
– |
if ( @_ ) { |
57 |
– |
$self->{makefile}=shift; |
58 |
– |
} |
59 |
– |
return $self->{makefile}; |
60 |
– |
} |
61 |
– |
|
62 |
– |
sub BlockParse { |
63 |
– |
my $self=shift; |
64 |
– |
$self->{block}=shift; |
65 |
– |
|
66 |
– |
# -- set up the block parse |
67 |
– |
my $switch=$self->_initswitcher(); |
68 |
– |
my $parse="block"; |
69 |
– |
$switch->newparse($parse); |
70 |
– |
$switch->addignoretags($parse); |
71 |
– |
$switch->addtag($parse,"BuildParam", \&BuildBlock_start, $self); |
72 |
– |
$switch->filetoparse($self->buildfile()); |
73 |
– |
|
74 |
– |
# -- parse away |
75 |
– |
$self->{switch}=$switch; |
76 |
– |
$switch->parse("block"); |
77 |
– |
} |
78 |
– |
|
79 |
– |
sub Parsetofh { |
80 |
– |
my $self=shift; |
81 |
– |
my $fh=shift; |
82 |
– |
$self->{buildblock}=shift; |
83 |
– |
|
84 |
– |
# -- set up for parse |
85 |
– |
@{$self->{filehandlestack}}=($fh); |
86 |
– |
$self->{switch}->filetoparse($self->buildfile()); |
87 |
– |
*GNUmakefile=$fh; |
88 |
– |
|
89 |
– |
# -- generate makefile |
90 |
– |
$self->{switch}->parse("makebuild"); # sort out supported tags |
91 |
– |
|
92 |
– |
# -- Clean up |
93 |
– |
close GNUmakefile; |
94 |
– |
} |
95 |
– |
|
30 |
|
sub ignore { |
31 |
|
my $self=shift; |
32 |
|
return (defined $self->{ignore})?$self->{ignore}:0; |
39 |
|
$switch->newparse($parse); |
40 |
|
$switch->addignoretags($parse); |
41 |
|
$self->_commontags($switch,$parse); |
42 |
< |
#$switch->addtag($parse,"Build", \&Build_start, $self); |
42 |
> |
$switch->addtag($parse,"Build", \&Build_start, $self); |
43 |
|
$switch->addtag($parse,"none", |
44 |
|
\&OutToMakefile,$self, |
45 |
|
\&OutToMakefile, $self, |
111 |
|
return $switch; |
112 |
|
} |
113 |
|
|
180 |
– |
sub GenerateMakefile { |
181 |
– |
my $self=shift; |
182 |
– |
my $infile=shift; |
183 |
– |
my $outfile=shift; |
184 |
– |
|
185 |
– |
$self->{switch}=$self->_initswitcher(); |
186 |
– |
$self->{switch}->filetoparse($infile); |
187 |
– |
|
188 |
– |
# open a temporary gnumakefile to store output. |
189 |
– |
my $fh=FileHandle->new(); |
190 |
– |
open ( $fh, ">$outfile") or die "Unable to open $outfile for output ". |
191 |
– |
"$!\n"; |
192 |
– |
@{$self->{filehandlestack}}=($fh); |
193 |
– |
|
194 |
– |
# -- make an alias |
195 |
– |
*GNUmakefile=$fh; |
196 |
– |
if ( -e $ENV{LatestBuildFile} ) { |
197 |
– |
print GNUmakefile "include $ENV{LatestBuildFile}\n"; |
198 |
– |
} |
199 |
– |
$self->{switch}->parse("makebuild"); # sort out supported tags |
200 |
– |
close GNUmakefile; |
201 |
– |
return $outfile; |
202 |
– |
} |
203 |
– |
|
114 |
|
sub ParseBuildFile { |
115 |
|
my $self=shift; |
116 |
|
my $base=shift; |
124 |
|
$fullfilename=$filename; |
125 |
|
} |
126 |
|
$self->{path}=$path; |
217 |
– |
#print "Processing $fullfilename\n"; |
127 |
|
$numbins=0; |
128 |
|
$self->{envnum}=0; |
129 |
|
$self->{envlevel}=0; |
130 |
< |
$self->{makefile}="$self->{localtop}/$ENV{INTwork}/$self->{path}/". |
131 |
< |
"BuildFile.mk"; |
223 |
< |
$self->{currentenv}=$self->{makefile}; |
130 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/". |
131 |
> |
"BuildFile.mk"; |
132 |
|
$self->{switch}=$self->_initswitcher(); |
133 |
|
$self->{switch}->filetoparse($fullfilename); |
134 |
|
|
135 |
< |
# $self->{switch}->{Strict_no_cr}='no'; |
228 |
< |
#open a temporary gnumakefile to store output. |
135 |
> |
# open a temporary gnumakefile to store output. |
136 |
|
use Utilities::AddDir; |
137 |
< |
AddDir::adddir("$self->{localtop}/$ENV{INTwork}/$self->{path}"); |
138 |
< |
$ENV{LatestBuildFile}=$self->GenerateMakefile($fullfilename, |
139 |
< |
$self->{localtop}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk"); |
140 |
< |
} |
137 |
> |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}"); |
138 |
> |
my $fh=FileHandle->new(); |
139 |
> |
open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk" |
140 |
> |
) or die "Unable to open /$ENV{INTwork}/".$self->{path}."/BuildFile.mk $!\n"; |
141 |
> |
@{$self->{filehandlestack}}=($fh); |
142 |
> |
# make an alias |
143 |
> |
*GNUmakefile=$fh; |
144 |
> |
if ( -e $ENV{LatestBuildFile} ) { |
145 |
> |
print GNUmakefile "include $ENV{LatestBuildFile}\n"; |
146 |
> |
} |
147 |
|
|
148 |
< |
sub classname { |
149 |
< |
my $self=shift; |
150 |
< |
if ( @_ ) { |
151 |
< |
$self->{classname}=shift; |
152 |
< |
} |
153 |
< |
return $self->{classname}; |
148 |
> |
$ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk"; |
149 |
> |
$self->{switch}->parse("makebuild"); # sort out supported tags |
150 |
> |
if ( $numbins > 0 ) { |
151 |
> |
print GNUmakefile <<ENDTEXT; |
152 |
> |
ifndef BINMODE |
153 |
> |
help:: |
154 |
> |
\t\@echo Generic Binary targets |
155 |
> |
\t\@echo ---------------------- |
156 |
> |
endif |
157 |
> |
ENDTEXT |
158 |
> |
foreach $target ( keys %$targettypes ) { |
159 |
> |
print GNUmakefile <<ENDTEXT; |
160 |
> |
ifndef BINMODE |
161 |
> |
help:: |
162 |
> |
\t\@echo $target |
163 |
> |
endif |
164 |
> |
ENDTEXT |
165 |
> |
} |
166 |
> |
} |
167 |
> |
close GNUmakefile; |
168 |
|
} |
169 |
|
|
170 |
|
sub ParseBuildFile_Export { |
171 |
|
my $self=shift; |
172 |
|
my $filename=shift; |
173 |
< |
my $bf=BuildSystem::BuildFile->new($self->{area},$self->{Builder}); |
173 |
> |
my $bf=BuildSystem::BuildFile->new($self->{toolbox}); |
174 |
|
if ( defined $self->{remoteproject} ) { |
175 |
|
$bf->{remoteproject}=$self->{remoteproject}; |
176 |
|
} |
199 |
|
\&export_end_export,$self); |
200 |
|
$self->_commontags($switchex,"export"); |
201 |
|
$switchex->allowgroup("__export","export"); |
275 |
– |
# $switchex->{Strict_no_cr}='no'; |
202 |
|
$self->{switch}=$switchex; |
203 |
|
$switchex->parse("export"); # sort out supported tags |
204 |
|
} |
245 |
|
|
246 |
|
if ( $self->{Arch} ) { |
247 |
|
if ( defined $$hashref{'type'} ) { |
248 |
< |
$self->classname($$hashref{'type'}); |
248 |
> |
$ClassName=$$hashref{'type'}; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
263 |
|
} |
264 |
|
|
265 |
|
# |
266 |
< |
# --- <Build class=> tag |
341 |
< |
# |
342 |
< |
|
266 |
> |
# generic build tag |
267 |
|
# |
344 |
– |
# Parameter collection |
345 |
– |
# |
346 |
– |
sub BuildBlock_start { |
347 |
– |
my $self=shift; |
348 |
– |
my $name=shift; |
349 |
– |
my $hashref=shift; |
350 |
– |
|
351 |
– |
|
352 |
– |
my $blockobjid=$self->__blockobjid($hashref); |
353 |
– |
|
354 |
– |
if ( $self->{Arch} ) { |
355 |
– |
|
356 |
– |
# -- get any objects that match |
357 |
– |
my $inheritobj=$self->{block}->getobj($blockobjid); |
358 |
– |
|
359 |
– |
# -- create an object with inherited properties |
360 |
– |
my $obj; |
361 |
– |
if ( ! defined $inheritobj ) { |
362 |
– |
# -- check we have a lookup for the class type |
363 |
– |
my $mapper=$self->_toolmapper(); |
364 |
– |
if ( ! $mapper->exists($$hashref{'class'}) ) { |
365 |
– |
$self->{switch}->parseerror("Unknown class : ". |
366 |
– |
$$hashref{'class'}); |
367 |
– |
} |
368 |
– |
$obj=BuildSystem::BuildClass->new(); |
369 |
– |
} |
370 |
– |
else { |
371 |
– |
# -- inherit the properties from class with the same id class |
372 |
– |
$obj=$inheritobj->child(); |
373 |
– |
} |
374 |
– |
|
375 |
– |
# -- add changes from our tag |
376 |
– |
$obj->paramupdate($hashref); |
377 |
– |
|
378 |
– |
# -- store the new object in the block |
379 |
– |
$self->{block}->setobj($obj,$blockobjid); |
380 |
– |
} |
381 |
– |
} |
382 |
– |
|
383 |
– |
sub BuilderClass_buildmakefile { |
384 |
– |
my $self=shift; |
385 |
– |
my $name=shift; |
386 |
– |
my $hashref=shift; |
387 |
– |
|
388 |
– |
my $blockobjid=$self->__blockobjid($hashref); |
389 |
– |
|
390 |
– |
if ( $self->{Arch} ) { |
391 |
– |
# -- get the matching block object |
392 |
– |
my $blockobj=$self->{buildblock}->getobj($blockobjid); |
393 |
– |
|
394 |
– |
# -- top level buildfile |
395 |
– |
my $fh=$self->{filehandlestack}[0]; |
396 |
– |
|
397 |
– |
# -- var initialisation |
398 |
– |
my @deftypes=(); |
399 |
– |
my $buildname=""; |
400 |
– |
my @types=$self->_toolmapper()->types($$hashref{'class'}); |
401 |
– |
|
402 |
– |
# -- error checking |
403 |
– |
if ( ! defined $blockobj->param("default") ) { |
404 |
– |
$self->error("No default build parameter defined for ". |
405 |
– |
$$hashref{'class'}." ".$$hashref{'id'}); |
406 |
– |
} |
407 |
– |
if ( ! defined $blockobj->param("name") ) { |
408 |
– |
$self->error("\"name\" parameter defined for ". |
409 |
– |
$$hashref{'class'}." ".$$hashref{'id'}); |
410 |
– |
} |
411 |
– |
|
412 |
– |
|
413 |
– |
foreach $param ( $blockobj->paramlist() ) { |
414 |
– |
# -- check for params that need special handling |
415 |
– |
if ( $param eq "default" ) { |
416 |
– |
@deftypes=split /,/, $param; |
417 |
– |
} |
418 |
– |
elsif ( $param eq "name" ) { |
419 |
– |
$buildname=$blockobj->param($param); |
420 |
– |
} |
421 |
– |
else { |
422 |
– |
# -- simple transfer of block object parameters to makefile |
423 |
– |
print $fh $param.":=".$blockobj->param($param)."\n"; |
424 |
– |
} |
425 |
– |
} |
426 |
– |
|
427 |
– |
# -- construct the targets in the top makefile |
428 |
– |
$self->_generatedefaulttargets($fh,$$hashref{'class'},@deftypes); |
429 |
– |
$self->_generatetypetargets($fh,$$hashref{'class'},$buildname,@types); |
430 |
– |
} |
431 |
– |
} |
432 |
– |
|
433 |
– |
sub _blockobjid { |
434 |
– |
my $self=shift; |
435 |
– |
my $hashref=shift; |
436 |
– |
|
437 |
– |
$self->{switch}->checktag($name,$hashref,'class'); |
438 |
– |
$self->{switch}->checktag($name,$hashref,'id'); |
439 |
– |
my $blockobjid="bc_".$$hashref{'class'},"_".$$hashref{'id'}; |
440 |
– |
|
441 |
– |
return $blockobjid; |
442 |
– |
} |
443 |
– |
|
268 |
|
sub Build_start { |
269 |
|
my $self=shift; |
270 |
|
my $name=shift; |
271 |
|
my $hashref=shift; |
272 |
|
|
273 |
|
$self->{switch}->checktag($name,$hashref,'class'); |
450 |
– |
$self->{switch}->checktag($name,$hashref,'id'); |
274 |
|
if ( $self->{Arch} ) { |
275 |
|
|
276 |
|
# -- determine the build products name |
280 |
|
} |
281 |
|
else { |
282 |
|
$self->{switch}->parseerror("No name specified for build product"); |
460 |
– |
#$name="\$(buildname)"; |
283 |
|
} |
284 |
|
|
285 |
|
# -- check we have a lookup for the class type |
319 |
|
my $dirname=$$hashref{'class'}."_".$type."_".$name; |
320 |
|
my $here="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/".$dirname; |
321 |
|
my $makefile=$here."/BuildFile.mk"; |
500 |
– |
# AddDir::adddir($here); |
322 |
|
|
323 |
|
# -- create link targets to the directory |
324 |
|
push @targets, $dirname; |
350 |
|
} |
351 |
|
print $fh "\tfi\n"; |
352 |
|
print $fh "\n"; |
532 |
– |
# print $typefile "$name :\n"; |
533 |
– |
# print $typefile "\t\$(_quietbuild_)"; |
534 |
– |
# print $typefile $mapper->template($$hashref{'class'},$type)."\n"; |
535 |
– |
# print $typefile "\t\$(_quietstamp_)"; |
536 |
– |
# print $typefile "\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n"; |
353 |
|
|
354 |
|
# -- cleaning targets |
355 |
|
push @targets, "clean_$dirname"; |
630 |
|
if ( ! defined $self->{remoteproject} ) { |
631 |
|
$filename=SCRAMUtils::checkfile( |
632 |
|
"/$ENV{INTsrc}/$$hashref{name}/BuildFile"); |
817 |
– |
# -- force a dependency check if local |
818 |
– |
if ( $filename=~/^$self->{localtop}/ ) { |
819 |
– |
$self->{Builder}->BuildDir($ENV{INTsrc}."/".$$hashref{'name'}); |
820 |
– |
} |
633 |
|
} |
634 |
|
else { |
635 |
|
$filename=$self->{remoteproject}."/$$hashref{name}/BuildFile"; |
646 |
|
} |
647 |
|
} |
648 |
|
|
649 |
+ |
sub CheckBuildFile { |
650 |
+ |
my $self=shift; |
651 |
+ |
my $classdir=shift; |
652 |
+ |
my $ClassName=""; |
653 |
+ |
my $thisfile="$classdir/$buildfile"; |
654 |
+ |
|
655 |
+ |
if ( -e $ENV{LOCALTOP}."/".$thisfile ) { |
656 |
+ |
$DefaultBuildfile="$ENV{LOCALTOP}/$thisfile"; |
657 |
+ |
$self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile); |
658 |
+ |
} |
659 |
+ |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) { |
660 |
+ |
$DefaultBuildfile="$ENV{RELEASETOP}/$thisfile"; |
661 |
+ |
$self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile); |
662 |
+ |
} |
663 |
+ |
return $ClassName; |
664 |
+ |
} |
665 |
+ |
|
666 |
|
# List association groups between <AssociateGroup> tags |
667 |
|
# seperated by newlines or spaces |
668 |
|
sub AssociateGroup { |
858 |
|
$self->{envnum}++; |
859 |
|
|
860 |
|
# open a new Environment File |
861 |
< |
my $envfile=$self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_". |
861 |
> |
my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_". |
862 |
|
$self->{envnum}.".mk"; |
863 |
|
use FileHandle; |
864 |
|
my $fh=FileHandle->new(); |
868 |
|
|
869 |
|
# include the approprate environment file |
870 |
|
if ( $self->{envlevel} == 0 ) { |
871 |
< |
print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/". |
871 |
> |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/". |
872 |
|
$self->{path}."/BuildFile.mk\n"; |
873 |
|
} |
874 |
|
else { |
875 |
< |
print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/". |
875 |
> |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/". |
876 |
|
$self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n"; |
877 |
|
} |
878 |
|
$self->{envlevel}++; |
879 |
|
$self->{Envlevels}[$self->{envlevel}]=$self->{envnum}; |
880 |
< |
$self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk"; |
880 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk"; |
881 |
|
} |
882 |
|
} |
883 |
|
|
897 |
|
close $fd; |
898 |
|
*GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}]; |
899 |
|
if ( $self->{envlevel} < 1 ) { |
900 |
< |
$self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/". |
900 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/". |
901 |
|
"BuildFile.mk"; |
902 |
|
} |
903 |
|
else { |
904 |
|
$self->{currentenv}= |
905 |
< |
$self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_". |
905 |
> |
"$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_". |
906 |
|
$self->{Envlevels}[$self->{envlevel}]; |
907 |
|
} |
908 |
|
} |
918 |
|
|
919 |
|
# -- store creation |
920 |
|
my $dir=$$hashref{'name'}; |
921 |
< |
AddDir::adddir($self->{localtop}."/".$dir); |
921 |
> |
AddDir::adddir($ENV{LOCALTOP}."/".$dir); |
922 |
|
if ( exists $$hashref{'type'} ) { |
923 |
|
# -- architecture specific store |
924 |
|
if ( $$hashref{'type'}=~/^arch/i ) { |
925 |
|
$dir=$dir."/".$ENV{SCRAM_ARCH}; |
926 |
< |
AddDir::adddir($self->{localtop}."/".$dir); |
926 |
> |
AddDir::adddir($ENV{LOCALTOP}."/".$dir); |
927 |
|
} |
928 |
|
else { |
929 |
|
$self->parseerror("Unknown type in <$name> tag"); |
933 |
|
# -- set make variables for the store |
934 |
|
print GNUmakefile "SCRAMSTORENAME_".$$hashref{'name'}.":=".$dir."\n"; |
935 |
|
print GNUmakefile "SCRAMSTORE_".$$hashref{'name'}.":=". |
936 |
< |
$self->{localtop}."/".$dir."\n"; |
937 |
< |
print GNUmakefile "VPATH+=".$self->{localtop} |
938 |
< |
."/".$dir.":".$self->{releasetop}."/".$dir."\n"; |
936 |
> |
$ENV{LOCALTOP}."/".$dir."\n"; |
937 |
> |
print GNUmakefile "VPATH+=".$ENV{LOCALTOP} |
938 |
> |
."/".$dir.":".$ENV{RELEASETOP}."/".$dir."\n"; |
939 |
|
} |
940 |
|
} |
941 |
|
|