2 |
|
# |
3 |
|
# Interface |
4 |
|
# --------- |
5 |
< |
# new(ConfigArea) |
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->{toolbox}=$self->{area}->toolbox(); |
30 |
< |
$self->{localtop}=$self->{area}->location(); |
31 |
< |
# -- set RELEASTOP |
32 |
< |
my $rarea=$self->{area}->linkarea(); |
33 |
< |
if ( ! defined $rarea ) { |
34 |
< |
$self->{releasetop}=$self->{localtop}; |
35 |
< |
} |
36 |
< |
else { |
37 |
< |
$self->{releasetop}=$rarea->location(); |
38 |
< |
} |
39 |
< |
$self->{releasetop}=$self->{area}->location(); |
24 |
> |
$self->{toolbox}=shift; |
25 |
|
$self->{Arch}=1; |
26 |
|
push @{$self->{ARCHBLOCK}}, $self->{Arch}; |
27 |
|
return $self; |
28 |
|
} |
29 |
|
|
45 |
– |
sub buildfile { |
46 |
– |
my $self=shift; |
47 |
– |
if ( @_ ) { |
48 |
– |
$self->{buildfile}=shift; |
49 |
– |
} |
50 |
– |
return $self->{buildfile}; |
51 |
– |
} |
52 |
– |
|
53 |
– |
sub makefile { |
54 |
– |
my $self=shift; |
55 |
– |
if ( @_ ) { |
56 |
– |
$self->{makefile}=shift; |
57 |
– |
} |
58 |
– |
return $self->{makefile}; |
59 |
– |
} |
60 |
– |
|
61 |
– |
sub blockparse { |
62 |
– |
my $self=shift; |
63 |
– |
$self->{block}=shift; |
64 |
– |
|
65 |
– |
$self->{switch}=$self->_initswitcher(); |
66 |
– |
$self->_initblockparse($self->{switch}); |
67 |
– |
} |
68 |
– |
|
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, |
48 |
|
\&Bin_start,$self, |
49 |
|
\&OutToScreen, $self, |
50 |
|
"", $self); |
51 |
< |
$switch->addtag($parse,"ProductStore", |
52 |
< |
\&Store_start,$self, |
53 |
< |
"", $self, |
54 |
< |
"", $self); |
51 |
> |
$switch->addtag($parse,"ProductStore", |
52 |
> |
\&Store_start,$self, |
53 |
> |
"", $self, |
54 |
> |
"", $self); |
55 |
|
$switch->addtag($parse,"LibType", |
56 |
|
\&LibType_Start,$self, |
57 |
|
\&LibType_text, $self, |
79 |
|
return $switch; |
80 |
|
} |
81 |
|
|
121 |
– |
sub _initblockparse { |
122 |
– |
my $self=shift; |
123 |
– |
my $switch=shift; |
124 |
– |
|
125 |
– |
my $parse="block"; |
126 |
– |
$switch->newparse($parse); |
127 |
– |
$switch->addignoretags($parse); |
128 |
– |
$switch->addtag($parse,"DropDown", |
129 |
– |
\&DropDown_start,$self, |
130 |
– |
"", $self, |
131 |
– |
"", $self); |
132 |
– |
$switch->addtag($parse,"Build", \&Build_start, $self); |
133 |
– |
} |
134 |
– |
|
82 |
|
sub _commontags { |
83 |
|
my $self=shift; |
84 |
|
my $switch=shift; |
111 |
|
return $switch; |
112 |
|
} |
113 |
|
|
167 |
– |
sub GenerateMakefile { |
168 |
– |
my $self=shift; |
169 |
– |
my $infile=shift; |
170 |
– |
my $outfile=shift; |
171 |
– |
|
172 |
– |
$self->{switch}=$self->_initswitcher(); |
173 |
– |
$self->{switch}->filetoparse($infile); |
174 |
– |
|
175 |
– |
# open a temporary gnumakefile to store output. |
176 |
– |
my $fh=FileHandle->new(); |
177 |
– |
open ( $fh, ">$outfile") or die "Unable to open $outfile for output ". |
178 |
– |
"$!\n"; |
179 |
– |
@{$self->{filehandlestack}}=($fh); |
180 |
– |
|
181 |
– |
# -- make an alias |
182 |
– |
*GNUmakefile=$fh; |
183 |
– |
if ( -e $ENV{LatestBuildFile} ) { |
184 |
– |
print GNUmakefile "include $ENV{LatestBuildFile}\n"; |
185 |
– |
} |
186 |
– |
$self->{switch}->parse("makebuild"); # sort out supported tags |
187 |
– |
close GNUmakefile; |
188 |
– |
return $outfile; |
189 |
– |
} |
190 |
– |
|
114 |
|
sub ParseBuildFile { |
115 |
|
my $self=shift; |
116 |
|
my $base=shift; |
128 |
|
$numbins=0; |
129 |
|
$self->{envnum}=0; |
130 |
|
$self->{envlevel}=0; |
131 |
< |
$self->{makefile}="$self->{localtop}/$ENV{INTwork}/$self->{path}/". |
131 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/". |
132 |
|
"BuildFile.mk"; |
210 |
– |
$self->{currentenv}=$self->{makefile}; |
133 |
|
$self->{switch}=$self->_initswitcher(); |
134 |
|
$self->{switch}->filetoparse($fullfilename); |
135 |
|
|
136 |
|
# $self->{switch}->{Strict_no_cr}='no'; |
137 |
|
#open a temporary gnumakefile to store output. |
138 |
|
use Utilities::AddDir; |
139 |
< |
AddDir::adddir("$self->{localtop}/$ENV{INTwork}/$self->{path}"); |
140 |
< |
$ENV{LatestBuildFile}=$self->GenerateMakefile($fullfilename, |
141 |
< |
$self->{localtop}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk"); |
142 |
< |
} |
143 |
< |
|
144 |
< |
sub classname { |
145 |
< |
my $self=shift; |
146 |
< |
if ( @_ ) { |
147 |
< |
$self->{classname}=shift; |
139 |
> |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}"); |
140 |
> |
my $fh=FileHandle->new(); |
141 |
> |
open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk" |
142 |
> |
) or die "Unable to open /$ENV{INTwork}/".$self->{path}."/BuildFile.mk $!\n"; |
143 |
> |
@{$self->{filehandlestack}}=($fh); |
144 |
> |
# make an alias |
145 |
> |
*GNUmakefile=$fh; |
146 |
> |
if ( -e $ENV{LatestBuildFile} ) { |
147 |
> |
print GNUmakefile "include $ENV{LatestBuildFile}\n"; |
148 |
> |
} |
149 |
> |
# print "writing to :\n". |
150 |
> |
# "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/BuildFile.mk\n"; |
151 |
> |
$ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk"; |
152 |
> |
$self->{switch}->parse("makebuild"); # sort out supported tags |
153 |
> |
if ( $numbins > 0 ) { |
154 |
> |
print GNUmakefile <<ENDTEXT; |
155 |
> |
ifndef BINMODE |
156 |
> |
help:: |
157 |
> |
\t\@echo Generic Binary targets |
158 |
> |
\t\@echo ---------------------- |
159 |
> |
endif |
160 |
> |
ENDTEXT |
161 |
> |
foreach $target ( keys %$targettypes ) { |
162 |
> |
print GNUmakefile <<ENDTEXT; |
163 |
> |
ifndef BINMODE |
164 |
> |
help:: |
165 |
> |
\t\@echo $target |
166 |
> |
endif |
167 |
> |
ENDTEXT |
168 |
> |
} |
169 |
|
} |
170 |
< |
return $self->{classname}; |
170 |
> |
close GNUmakefile; |
171 |
|
} |
172 |
|
|
173 |
|
sub ParseBuildFile_Export { |
174 |
|
my $self=shift; |
175 |
|
my $filename=shift; |
176 |
< |
my $bf=BuildSystem::BuildFile->new($self->{area}); |
176 |
> |
my $bf=BuildSystem::BuildFile->new($self->{toolbox}); |
177 |
|
if ( defined $self->{remoteproject} ) { |
178 |
|
$bf->{remoteproject}=$self->{remoteproject}; |
179 |
|
} |
249 |
|
|
250 |
|
if ( $self->{Arch} ) { |
251 |
|
if ( defined $$hashref{'type'} ) { |
252 |
< |
$self->classname($$hashref{'type'}); |
252 |
> |
$ClassName=$$hashref{'type'}; |
253 |
|
} |
254 |
|
} |
255 |
|
} |
275 |
|
my $hashref=shift; |
276 |
|
|
277 |
|
$self->{switch}->checktag($name,$hashref,'class'); |
335 |
– |
$self->{switch}->checktag($name,$hashref,'id'); |
278 |
|
if ( $self->{Arch} ) { |
279 |
|
|
280 |
|
# -- determine the build products name |
322 |
|
# -- create a new directory for each type |
323 |
|
push @targets, $pattern; |
324 |
|
my $dirname=$$hashref{'class'}."_".$type."_".$name; |
325 |
< |
my $here="$self->{localtop}/$ENV{INTwork}/".$self->{path}."/".$dirname; |
325 |
> |
my $here="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/".$dirname; |
326 |
|
my $makefile=$here."/BuildFile.mk"; |
327 |
|
# AddDir::adddir($here); |
328 |
|
|
345 |
|
print $fh "\t cd $dirname; \\\n"; |
346 |
|
print $fh "\t echo include ".$self->{currentenv}." > ". |
347 |
|
"$makefile; \\\n"; |
348 |
< |
print $fh "\t echo VPATH+=$self->{localtop}/".$self->{path}. |
348 |
> |
print $fh "\t echo VPATH+=$ENV{LOCALTOP}/".$self->{path}. |
349 |
|
" >> $makefile; \\\n"; |
350 |
|
print $fh "\t echo buildname=$name >> $makefile;\\\n"; |
351 |
|
print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n"; |
411 |
|
|
412 |
|
# Create a new directory for each binary target |
413 |
|
my $dirname="bin_".$$hashref{name}; |
414 |
< |
AddDir::adddir("$self->{localtop}/$ENV{INTwork}/".$self->{path}."/$dirname"); |
414 |
> |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/$dirname"); |
415 |
|
open (binGNUmakefile, |
416 |
< |
">$self->{localtop}/$ENV{INTwork}/".$self->{path}."/$dirname/BuildFile.mk") or die "Unable to make $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname/". |
416 |
> |
">$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/$dirname/BuildFile.mk") or die "Unable to make $ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname/". |
417 |
|
"BuildFile.mk $!\n"; |
418 |
|
|
419 |
|
# Create the link targets |
429 |
|
ifndef BINMODE |
430 |
|
|
431 |
|
define stepdown_$$hashref{'name'} |
432 |
< |
if [ -d "$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\ |
433 |
< |
cd $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname; \\ |
434 |
< |
\$(MAKE) BINMODE=true LatestBuildFile=$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \\ |
432 |
> |
if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\ |
433 |
> |
cd $ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname; \\ |
434 |
> |
\$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \\ |
435 |
|
fi |
436 |
|
endef |
437 |
|
|
438 |
|
define stepdown2_$$hashref{'name'} |
439 |
< |
if [ -d "$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\ |
440 |
< |
cd $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname; \\ |
441 |
< |
\$(MAKE) BINMODE=true LatestBuildFile=$self->{localtop}/$ENV{INTwork}/$self{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\*; \\ |
439 |
> |
if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\ |
440 |
> |
cd $ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/$dirname; \\ |
441 |
> |
\$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/$self{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\*; \\ |
442 |
|
fi |
443 |
|
|
444 |
|
endef |
462 |
|
|
463 |
|
# the binary specifics makefile |
464 |
|
print binGNUmakefile "include ".$self->{currentenv}."\n"; |
465 |
< |
print binGNUmakefile "VPATH+=".$self->{localtop}."/$self{path}\n"; |
465 |
> |
print binGNUmakefile "VPATH+=$ENV{LOCALTOP}/$self{path}\n"; |
466 |
|
|
467 |
|
# alias for bin_Insure |
468 |
|
print binGNUmakefile <<ENDTEXT; |
657 |
|
} |
658 |
|
} |
659 |
|
|
660 |
+ |
sub CheckBuildFile { |
661 |
+ |
my $self=shift; |
662 |
+ |
my $classdir=shift; |
663 |
+ |
my $ClassName=""; |
664 |
+ |
my $thisfile="$classdir/$buildfile"; |
665 |
+ |
|
666 |
+ |
if ( -e $ENV{LOCALTOP}."/".$thisfile ) { |
667 |
+ |
$DefaultBuildfile="$ENV{LOCALTOP}/$thisfile"; |
668 |
+ |
$self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile); |
669 |
+ |
} |
670 |
+ |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) { |
671 |
+ |
$DefaultBuildfile="$ENV{RELEASETOP}/$thisfile"; |
672 |
+ |
$self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile); |
673 |
+ |
} |
674 |
+ |
return $ClassName; |
675 |
+ |
} |
676 |
+ |
|
677 |
|
# List association groups between <AssociateGroup> tags |
678 |
|
# seperated by newlines or spaces |
679 |
|
sub AssociateGroup { |
869 |
|
$self->{envnum}++; |
870 |
|
|
871 |
|
# open a new Environment File |
872 |
< |
my $envfile="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_". |
872 |
> |
my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_". |
873 |
|
$self->{envnum}.".mk"; |
874 |
|
use FileHandle; |
875 |
|
my $fh=FileHandle->new(); |
879 |
|
|
880 |
|
# include the approprate environment file |
881 |
|
if ( $self->{envlevel} == 0 ) { |
882 |
< |
print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/". |
882 |
> |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/". |
883 |
|
$self->{path}."/BuildFile.mk\n"; |
884 |
|
} |
885 |
|
else { |
886 |
< |
print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/". |
886 |
> |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/". |
887 |
|
$self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n"; |
888 |
|
} |
889 |
|
$self->{envlevel}++; |
890 |
|
$self->{Envlevels}[$self->{envlevel}]=$self->{envnum}; |
891 |
< |
$self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk"; |
891 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk"; |
892 |
|
} |
893 |
|
} |
894 |
|
|
908 |
|
close $fd; |
909 |
|
*GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}]; |
910 |
|
if ( $self->{envlevel} < 1 ) { |
911 |
< |
$self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/". |
911 |
> |
$self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/". |
912 |
|
"BuildFile.mk"; |
913 |
|
} |
914 |
|
else { |
915 |
|
$self->{currentenv}= |
916 |
< |
$self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_". |
916 |
> |
"$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_". |
917 |
|
$self->{Envlevels}[$self->{envlevel}]; |
918 |
|
} |
919 |
|
} |
920 |
|
} |
921 |
|
|
922 |
|
sub Store_start { |
923 |
< |
my $self=shift; |
924 |
< |
my $name=shift; |
923 |
> |
my $self=shift; |
924 |
> |
my $name=shift; |
925 |
|
my $hashref=shift; |
926 |
|
|
927 |
< |
if ( $self->{Arch} ) { |
928 |
< |
$self->{switch}->checktag( $name, $hashref, 'name' ); |
927 |
> |
if ( $self->{Arch} ) { |
928 |
> |
$self->{switch}->checktag( $name, $hashref, 'name' ); |
929 |
|
|
930 |
< |
# -- store creation |
931 |
< |
my $dir=$$hashref{'name'}; |
932 |
< |
AddDir::adddir($self->{area}->location()."/".$dir); |
933 |
< |
if ( exists $$hashref{'type'} ) { |
934 |
< |
# -- architecture specific store |
935 |
< |
if ( $$hashref{'type'}=~/^arch/i ) { |
936 |
< |
$dir=$dir."/".$ENV{SCRAM_ARCH}; |
937 |
< |
AddDir::adddir($self->{area}->location()."/".$dir); |
938 |
< |
} |
939 |
< |
else { |
940 |
< |
$self->parseerror("Unknown type in <$name> tag"); |
941 |
< |
} |
942 |
< |
} |
943 |
< |
|
944 |
< |
# -- set make variables for the store |
945 |
< |
print GNUmakefile "SCRAMSTORENAME_".$$hashref{'name'}.":=".$dir."\n"; |
946 |
< |
print GNUmakefile "SCRAMSTORE_".$$hashref{'name'}.":=". |
947 |
< |
$self->{localtop}."/".$dir."\n"; |
948 |
< |
print GNUmakefile "VPATH+=".$self->{localtop} |
949 |
< |
."/".$dir.":".$self->{releasetop}."/".$dir."\n"; |
950 |
< |
} |
930 |
> |
# -- store creation |
931 |
> |
my $dir=$$hashref{'name'}; |
932 |
> |
AddDir::adddir($ENV{LOCALTOP}."/".$dir); |
933 |
> |
if ( exists $$hashref{'type'} ) { |
934 |
> |
# -- architecture specific store |
935 |
> |
if ( $$hashref{'type'}=~/^arch/i ) { |
936 |
> |
$dir=$dir."/".$ENV{SCRAM_ARCH}; |
937 |
> |
AddDir::adddir($ENV{LOCALTOP}."/".$dir); |
938 |
> |
} |
939 |
> |
else { |
940 |
> |
$self->parseerror("Unknown type in <$name> tag"); |
941 |
> |
} |
942 |
> |
} |
943 |
> |
|
944 |
> |
# -- set make variables for the store |
945 |
> |
print GNUmakefile "SCRAMSTORENAME_".$$hashref{'name'}.":=".$dir."\n"; |
946 |
> |
print GNUmakefile "SCRAMSTORE_".$$hashref{'name'}.":=". |
947 |
> |
$ENV{LOCALTOP}."/".$dir."\n"; |
948 |
> |
print GNUmakefile "VPATH+=".$ENV{LOCALTOP} |
949 |
> |
."/".$dir.":".$ENV{RELEASETOP}."/".$dir."\n"; |
950 |
> |
} |
951 |
|
} |
952 |
|
|
994 |
– |
sub DropDown { |
995 |
– |
my $self=shift; |
996 |
– |
my $name=shift; |
997 |
– |
my $hashref=shift; |
998 |
– |
|
999 |
– |
if ( $self->{Arch} ) { |
1000 |
– |
# - default values must always be specified |
1001 |
– |
$self->{switch}->checktag( $name, $hashref, 'defaults' ); |
1002 |
– |
my @blockdirs=split /,/ , $$hashref{'defaults'}; |
1003 |
– |
$self->{block}->defaultblocks(@blockdirs); |
1004 |
– |
} |
1005 |
– |
} |