15 |
|
#Parse the BuildFile |
16 |
|
sub ParseBuildFile { |
17 |
|
my $base=shift; |
18 |
< |
my $path=shift; |
18 |
> |
$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 |
+ |
$numbins=0; |
24 |
+ |
$envnum=0; |
25 |
+ |
$envlevel=0; |
26 |
+ |
$currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk"; |
27 |
|
my $SupportedTags={ |
28 |
|
'Use' => \&OutToMakefile, |
29 |
|
'Use_StartTag' => \&Use_start, |
39 |
|
'Bin_StartTag' => \&Bin_start, |
40 |
|
'ClassPath' => \&OutToMakefile, |
41 |
|
'ClassPath_StartTag' => \&setBlockClassPath, |
42 |
+ |
'Environment' => \&OutToMakefile, |
43 |
+ |
'Environment_StartTag' => \&Environment_start, |
44 |
+ |
'Environment_EndTag' => \&Environment_end, |
45 |
|
'lib' => 'none', |
46 |
|
'lib_StartTag' => \&lib_start, |
47 |
|
'lib_EndTag' => 'none', |
53 |
|
'Architecture' => \&OutToMakefile, |
54 |
|
'LibType_StartTag' => \&LibType_Start, |
55 |
|
'LibType_EndTag' => 'none', |
56 |
< |
'LibType' => \&OutToMakefile |
56 |
> |
#'LibType' => \&OutToScreen |
57 |
> |
'LibType' => \&LibType_text |
58 |
|
}; |
59 |
|
use Utilities::Switcher; |
60 |
|
$switch=Switcher->new($SupportedTags, $fullfilename); |
62 |
|
#open a temporary gnumakefile to store output. |
63 |
|
use Utilities::AddDir; |
64 |
|
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}"); |
65 |
< |
open ( GNUmakefile, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk") or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n'; |
65 |
> |
my $fh=FileHandle->new(); |
66 |
> |
open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk" |
67 |
> |
) or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n'; |
68 |
> |
@filehandlestack=($fh); |
69 |
> |
# make an alias |
70 |
> |
# open ( GNUmakefile, ">&=$fh") or die 'Unable to create alias for '. |
71 |
> |
# "Filehandle $!\n"; |
72 |
> |
*GNUmakefile=$fh; |
73 |
|
if ( -e $ENV{LatestBuildFile} ) { |
74 |
|
print GNUmakefile "include $ENV{LatestBuildFile}\n"; |
75 |
|
} |
166 |
|
# This stuff for later |
167 |
|
#$fileclass=$toolbox->getclass($file); |
168 |
|
#$toolbox->maketargets("exe",$fileclass, $$hashref{name}, $file ); |
169 |
+ |
|
170 |
|
($filename=$$hashref{file})=~s/\..*//; |
171 |
< |
($objectname=$$hashref{file})=~s/\..*/\.o/; |
172 |
< |
($objectname_d=$$hashref{file})=~s/\..*/_d\.o/; |
173 |
< |
($objectname_Insure=$$hashref{file})=~s/\..*/_Insure\.o/; |
174 |
< |
print GNUmakefile "bin:$$hashref{name}_o\n"; |
175 |
< |
print GNUmakefile "bin_debug:$$hashref{name}_d\n"; |
176 |
< |
print GNUmakefile "bin_insure:$$hashref{name}_Insure\n"; |
177 |
< |
# print GNUmakefile ".INTERMEDIATE::$$hashref{name}_d.exe\n"; |
178 |
< |
# print GNUmakefile ".INTERMEDIATE::$$hashref{name}_Insure.exe\n"; |
179 |
< |
print GNUmakefile ".INTERMEDIATE::$$hashref{name}.exe\n"; |
180 |
< |
print GNUmakefile "$$hashref{name}_Insure:.psrc\n"; |
181 |
< |
print GNUmakefile "$$hashref{name}_d.exe:$objectname_d\n"; |
182 |
< |
print GNUmakefile "\t\$(CClinkCmdDebug)\n"; |
183 |
< |
print GNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n"; |
184 |
< |
print GNUmakefile "\t\$(CClinkCmdInsure)\n"; |
185 |
< |
print GNUmakefile "$$hashref{name}.exe:$objectname\n"; |
186 |
< |
print GNUmakefile "\t\$(CClinkCmd)\n"; |
187 |
< |
print GNUmakefile "$objectname:$$hashref{name}.dep\n"; |
188 |
< |
print GNUmakefile "$objectname_d:$$hashref{name}.dep\n"; |
189 |
< |
print GNUmakefile "$objectname_Insure:$$hashref{name}.dep\n"; |
190 |
< |
print GNUmakefile "$$hashref{name}.dep:$$hashref{file}\n"; |
191 |
< |
print GNUmakefile "-include $$hashref{name}.dep\n"; |
192 |
< |
# print GNUmakefile "$$hashref{name}:$$hashref{file}\n"; |
193 |
< |
print GNUmakefile <<ENDTEXT; |
171 |
> |
|
172 |
> |
# Create a new directory for each binary target |
173 |
> |
my $dirname="bin_".$$hashref{name}; |
174 |
> |
AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname"); |
175 |
> |
open (binGNUmakefile, |
176 |
> |
">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk") or die "Unable to make $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/". |
177 |
> |
"BuildFile.mk $!\n"; |
178 |
> |
|
179 |
> |
# Create the link targets |
180 |
> |
$numbins++; |
181 |
> |
my $fh=$filehandlestack[0]; |
182 |
> |
print $fh <<ENDTEXT; |
183 |
> |
|
184 |
> |
# Link Targets to binary directories |
185 |
> |
ifndef BINMODE |
186 |
> |
|
187 |
> |
define stepdown_$$hashref{'name'} |
188 |
> |
if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname" ]; then \\ |
189 |
> |
echo - Invoking binary makefile \$\@ for $dirname; \\ |
190 |
> |
cd $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname; \\ |
191 |
> |
\$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk \$\@; \\ |
192 |
> |
fi |
193 |
> |
echo - Finished binary makefile \$\@ |
194 |
> |
endef |
195 |
> |
|
196 |
> |
define stepdown2_$$hashref{'name'} |
197 |
> |
if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname" ]; then \\ |
198 |
> |
echo - Invoking binary makefile \$\@ for $dirname; \\ |
199 |
> |
cd $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname; \\ |
200 |
> |
\$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk \$\*; \\ |
201 |
> |
fi |
202 |
> |
echo - Finished binary makefile \$\@ |
203 |
> |
endef |
204 |
> |
|
205 |
> |
bin_$$hashref{'name'}_%:: dummy |
206 |
> |
\@\$(stepdown2_$$hashref{'name'}) |
207 |
> |
|
208 |
> |
echo_%:: dummy |
209 |
> |
\@\$(stepdown_$$hashref{'name'}) |
210 |
> |
|
211 |
> |
bin bin_debug bin_debug_local bin_insure bin_Insure clean $$hashref{'name'}:: dummy |
212 |
> |
\@\$(stepdown_$$hashref{'name'}) |
213 |
> |
endif |
214 |
> |
|
215 |
> |
ENDTEXT |
216 |
> |
|
217 |
> |
|
218 |
> |
# the binary specifics makefile |
219 |
> |
print binGNUmakefile "include $currentenv\n"; |
220 |
> |
print binGNUmakefile "VPATH+=$ENV{LOCALTOP}/${path}\n"; |
221 |
> |
|
222 |
> |
# alias for bin_Insure |
223 |
> |
print binGNUmakefile <<ENDTEXT; |
224 |
> |
|
225 |
> |
bin_insure:bin_Insure |
226 |
> |
ifdef MAKETARGET_bin_insure |
227 |
> |
MAKETARGET_$$hashref{name}_Insure=1 |
228 |
> |
endif |
229 |
> |
|
230 |
> |
# debuggging target |
231 |
> |
$$hashref{'name'}_echo_% :: echo_% |
232 |
> |
|
233 |
> |
ENDTEXT |
234 |
> |
|
235 |
> |
# Make generic rules for each type |
236 |
> |
$targettypes={ |
237 |
> |
"bin" => 'o', |
238 |
> |
"bin_debug" => 'd', |
239 |
> |
"bin_debug_local" => 'l_d', |
240 |
> |
"bin_Insure" => 'Insure' |
241 |
> |
}; |
242 |
> |
# |
243 |
> |
foreach $target ( keys %$targettypes ) { |
244 |
> |
print binGNUmakefile <<ENDTEXT; |
245 |
> |
|
246 |
> |
# Type $target specifics |
247 |
> |
ifdef MAKETARGET_$target |
248 |
> |
MAKETARGET_$$hashref{name}_$$targettypes{$target}=1 |
249 |
> |
endif |
250 |
> |
$target ::$$hashref{name}_$$targettypes{$target} |
251 |
> |
|
252 |
> |
bintargets+=$$hashref{name}_$$targettypes{$target} |
253 |
> |
clean:: |
254 |
> |
\t\@if [ -f \$(binarystore)/$$hashref{name}_$$targettypes{$target} ]; then \\ |
255 |
> |
\techo Removing \$(binarystore)/$$hashref{name}; \\ |
256 |
> |
\trm \$(binarystore)/$$hashref{name}_$$targettypes{$target}; \\ |
257 |
> |
\tfi |
258 |
> |
|
259 |
> |
ENDTEXT |
260 |
> |
($objectname=$$hashref{file})=~s/\..*/_$$targettypes{$target}\.o/; |
261 |
> |
${"objectname_$$targettypes{$target}"}=$objectname; |
262 |
> |
print binGNUmakefile "$objectname:$$hashref{name}.dep\n"; |
263 |
> |
} # end loop |
264 |
> |
|
265 |
> |
print binGNUmakefile "$$hashref{name}_Insure:.psrc\n"; |
266 |
> |
print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n"; |
267 |
> |
print binGNUmakefile "\t\$(CClinkCmdDebug)\n"; |
268 |
> |
print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n"; |
269 |
> |
print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n"; |
270 |
> |
print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n"; |
271 |
> |
print binGNUmakefile "\t\$(CClinkCmdInsure)\n"; |
272 |
> |
print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n"; |
273 |
> |
print binGNUmakefile "\t\$(CClinkCmd)\n"; |
274 |
> |
print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n"; |
275 |
> |
print binGNUmakefile "-include $$hashref{name}.dep\n"; |
276 |
> |
print binGNUmakefile <<ENDTEXT; |
277 |
> |
clean:: |
278 |
> |
\t\@if [ -f \$(binarystore)/$$hashref{name} ]; then \\ |
279 |
> |
\techo Removing \$(binarystore)/$$hashref{name}; \\ |
280 |
> |
\trm \$(binarystore)/$$hashref{name}; \\ |
281 |
> |
\tfi |
282 |
> |
|
283 |
|
$$hashref{name}_d.exe:\$(libslocal_d) |
284 |
< |
$$hashref{name}.exe:\$(libslocal) |
284 |
> |
$$hashref{name}_o.exe:\$(libslocal) |
285 |
|
ifdef MCCABE_DATA_DIR |
286 |
< |
$$hashref{name}_mccabe.exe: \$(libslocal_d) $(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp |
286 |
> |
$$hashref{name}_mccabe.exe: \$(libslocal_d) \$(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp |
287 |
|
endif |
288 |
|
$$hashref{name}_Insure.exe:\$(libslocal_I) |
289 |
|
$$hashref{name}_d:$$hashref{name}_d.exe |
290 |
|
\@cp $$hashref{name}_d.exe \$(binarystore)/$$hashref{name} |
291 |
+ |
$$hashref{name}_l_d:$$hashref{name}_l_d.exe |
292 |
+ |
\@cp $$hashref{name}_l_d.exe \$(binarystore)/$$hashref{name} |
293 |
|
$$hashref{name}_Insure:$$hashref{name}_Insure.exe |
294 |
|
\@cp $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure |
295 |
|
$$hashref{name}:$$hashref{name}_d.exe |
296 |
|
\@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name} |
297 |
< |
$$hashref{name}_o:$$hashref{name}.exe |
298 |
< |
\@mv $$hashref{name}.exe \$(binarystore)/$$hashref{name} |
297 |
> |
$$hashref{name}_o:$$hashref{name}_o.exe |
298 |
> |
\@mv $$hashref{name}_o.exe \$(binarystore)/$$hashref{name} |
299 |
|
binfiles+=$$hashref{file} |
193 |
– |
bintargets+=$$hashref{name} $$hashref{name}_d $$hashref{name}_Insure |
300 |
|
ENDTEXT |
301 |
|
} |
302 |
+ |
close binGNUmakefile; |
303 |
|
} |
304 |
|
|
305 |
|
sub Ext_start_export { |
461 |
|
my $name=shift; |
462 |
|
my @vars=@_; |
463 |
|
|
464 |
< |
print GNUmakefile @vars; |
464 |
> |
if ( $Arch ) { |
465 |
> |
print GNUmakefile @vars; |
466 |
> |
} |
467 |
> |
} |
468 |
> |
sub OutToScreen { |
469 |
> |
my $name=shift; |
470 |
> |
my @vars=@_; |
471 |
> |
|
472 |
> |
if ( $Arch ) { |
473 |
> |
print @vars; |
474 |
> |
} |
475 |
|
} |
476 |
|
sub setBlockClassPath { |
477 |
|
my $name=shift; |
556 |
|
print GNUmakefile "\n"; |
557 |
|
} |
558 |
|
} |
559 |
+ |
sub LibType_text { |
560 |
+ |
my $name=shift; |
561 |
+ |
my @vars=@_; |
562 |
+ |
|
563 |
+ |
if ( $Arch ) { |
564 |
+ |
print GNUmakefile "libmsg::\n\t\@echo Library info: "; |
565 |
+ |
print GNUmakefile @vars; |
566 |
+ |
print GNUmakefile "\n"; |
567 |
+ |
} |
568 |
+ |
} |
569 |
+ |
|
570 |
+ |
sub Environment_start { |
571 |
+ |
my $name=shift; |
572 |
+ |
my @vars=@_; |
573 |
+ |
my $hashref; |
574 |
+ |
|
575 |
+ |
if ( $Arch ) { |
576 |
+ |
$envnum++; |
577 |
+ |
|
578 |
+ |
# open a new Environment File |
579 |
+ |
my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk"; |
580 |
+ |
use FileHandle; |
581 |
+ |
my $fh=FileHandle->new(); |
582 |
+ |
open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n"; |
583 |
+ |
push @filehandlestack, $fh; |
584 |
+ |
*GNUmakefile=$fh; |
585 |
+ |
|
586 |
+ |
# include the approprate environment file |
587 |
+ |
if ( $envlevel == 0 ) { |
588 |
+ |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/". |
589 |
+ |
"BuildFile.mk\n"; |
590 |
+ |
} |
591 |
+ |
else { |
592 |
+ |
print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/". |
593 |
+ |
"Env_$Envlevels[$envlevel]\.mk\n"; |
594 |
+ |
} |
595 |
+ |
$envlevel++; |
596 |
+ |
$Envlevels[$envlevel]=$envnum; |
597 |
+ |
$currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk"; |
598 |
+ |
} |
599 |
+ |
} |
600 |
+ |
|
601 |
+ |
sub Environment_end { |
602 |
+ |
my $fd; |
603 |
+ |
|
604 |
+ |
if ( $Arch ) { |
605 |
+ |
$envlevel--; |
606 |
+ |
if ( $envlevel < 0 ) { |
607 |
+ |
print "Too many </Environent> Tags on $switch->line()\n"; |
608 |
+ |
exit; |
609 |
+ |
} |
610 |
+ |
close GNUmakefile; |
611 |
+ |
# restore the last filehandle |
612 |
+ |
$fd=pop @filehandlestack; |
613 |
+ |
close $fd; |
614 |
+ |
*GNUmakefile=$filehandlestack[$#filehandlestack]; |
615 |
+ |
if ( $envlevel < 1 ) { |
616 |
+ |
$currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk"; |
617 |
+ |
} |
618 |
+ |
else { |
619 |
+ |
$currentenv= |
620 |
+ |
"$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$Envlevels[$envlevel]"; |
621 |
+ |
} |
622 |
+ |
} |
623 |
+ |
} |