ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildFile.pm
Revision: 1.21.2.21
Committed: Tue Oct 12 16:47:13 1999 UTC (25 years, 7 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.21.2.20: +148 -30 lines
Log Message:
Update bin functionality - seperated directories for each bin target

File Contents

# User Rev Content
1 williamc 1.1 package BuildFile;
2 williamc 1.2 require 5.001;
3 williamc 1.1 require Exporter;
4     @ISA = qw(Exporter);
5     @EXPORT = qw(CheckBuildFile ParseBuildFile @BlockClassA $DefaultBuildFile);
6    
7     BEGIN {
8     use ToolBox;
9     $buildfile="BuildFile";
10 williamc 1.4 $toolbox=ToolBox->new();
11 williamc 1.21 $Arch=1;
12     push @ARCHBLOCK, $Arch;
13 williamc 1.1 }
14    
15     #Parse the BuildFile
16     sub ParseBuildFile {
17     my $base=shift;
18 williamc 1.21.2.21 $path=shift;
19 williamc 1.1 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 williamc 1.21.2.21 $numbins=0;
24     $envnum=0;
25     $envlevel=0;
26     $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
27 williamc 1.1 my $SupportedTags={
28     'Use' => \&OutToMakefile,
29     'Use_StartTag' => \&Use_start,
30     'Group' => \&OutToMakefile,
31     'Group_StartTag' => \&Group_start,
32     'External' => \&OutToMakefile,
33     'External_StartTag' => \&External_StartTag,
34     'ConfigurationClass_StartTag' => \&Class_StartTag,
35     'ConfigurationClass' => \&OutToMakefile,
36     'AssociateGroup' => \&AssociateGroup,
37     'none' => \&OutToMakefile,
38 williamc 1.8 'Bin' => 'none',
39 williamc 1.1 'Bin_StartTag' => \&Bin_start,
40     'ClassPath' => \&OutToMakefile,
41 williamc 1.21 'ClassPath_StartTag' => \&setBlockClassPath,
42 williamc 1.21.2.21 'Environment' => \&OutToMakefile,
43     'Environment_StartTag' => \&Environment_start,
44     'Environment_EndTag' => \&Environment_end,
45 williamc 1.21 'lib' => 'none',
46     'lib_StartTag' => \&lib_start,
47 williamc 1.21.2.1 'lib_EndTag' => 'none',
48     'ignore' => 'none',
49     'ignore_EndTag' => \&ignoretag_end,
50     'ignore_StartTag' => \&ignoretag,
51     'Architecture_StartTag' => \&Arch_Start,
52     'Architecture_EndTag' => \&Arch_End,
53 williamc 1.21.2.6 'Architecture' => \&OutToMakefile,
54     'LibType_StartTag' => \&LibType_Start,
55     'LibType_EndTag' => 'none',
56 williamc 1.21.2.15 #'LibType' => \&OutToScreen
57     'LibType' => \&LibType_text
58 williamc 1.1 };
59 williamc 1.2 use Utilities::Switcher;
60 williamc 1.1 $switch=Switcher->new($SupportedTags, $fullfilename);
61     $switch->{Strict_no_cr}='no';
62     #open a temporary gnumakefile to store output.
63 williamc 1.2 use Utilities::AddDir;
64 williamc 1.3 AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}");
65 williamc 1.1 open ( GNUmakefile, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk") or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n';
66     if ( -e $ENV{LatestBuildFile} ) {
67     print GNUmakefile "include $ENV{LatestBuildFile}\n";
68     }
69     # print "writing to :\n".
70     # "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk\n";
71     $ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
72     $switch->parse(); # sort out supported tags
73     close GNUmakefile;
74     }
75    
76 williamc 1.21 sub ParseBuildFile_Export {
77     my $filename=shift;
78     use Tool;
79     # This hash defines which Document Elements we can use
80     my $SupportedTags={
81     'none' => 'none',
82     'export' => \&OutToMakefile,
83     'export_StartTag' => \&export_start,
84     'export_EndTag' => \&export_end,
85     'lib_StartTag' => \&lib_start_export,
86 williamc 1.21.2.12 'External_StartTag' => \&Ext_start_export,
87 williamc 1.21 'lib' => 'none'
88     };
89     use Utilities::Switcher;
90     $switchex=Switcher->new($SupportedTags, $filename);
91     $switchex->{Strict_no_cr}='no';
92     $switchex->parse(); # sort out supported tags
93     }
94    
95 williamc 1.1 sub initialterms() {
96     my $name=shift;
97     my @string=@_;
98    
99     $_=join "", @string;
100     chomp;
101     SWITCH: {
102     last SWITCH if /^#/;
103     if ( /^.*BlockClassPath.*/i ) {
104     s/^.*BlockClassPath *= *//;
105     _CutBlock($_);
106     last SWITCH;
107     }
108     } # end SWITCH
109     }
110    
111     # Tag routines - called by the Switcher when tag found
112    
113    
114    
115     #-- Override a class type with the <ConfigurationClass type=xxx> tag
116     # the type tag will pick up a pre-defined class type from project space.
117    
118     sub Class_StartTag {
119     my $name=shift;
120     my $hashref;
121     my @vars=@_;
122    
123     $hashref=$switch->SetupValueHash(\@vars);
124 williamc 1.21.2.1 if ( $Arch ) {
125 williamc 1.1 if ( defined $$hashref{'type'} ) {
126     $ClassName=$$hashref{'type'};
127     }
128 williamc 1.21.2.1 }
129 williamc 1.1 }
130    
131     sub ClassPath_StartTag {
132     my $name=shift;
133     my @vars=@_;
134     my $hashref;
135    
136     $hashref=$switch->SetupValueHash(\@vars);
137 williamc 1.21.2.1 if ( $Arch ) {
138 williamc 1.1 if ( defined $$hashref{'defaultpath'} ) {
139     }
140 williamc 1.21.2.1 }
141 williamc 1.1 }
142    
143     sub Bin_start {
144     my $name=shift;
145     my @vars=@_;
146     my $hashref;
147     my $fileclass;
148     my @tools;
149     my $tool;
150 williamc 1.12 my $filename;
151     my $objectname;
152 williamc 1.1
153     $hashref=$switch->SetupValueHash(\@vars);
154     $switch->checkparam($hashref, $name, 'file');
155 williamc 1.21.2.1 if ( $Arch ) {
156 williamc 1.1 if ( ! defined $$hashref{name} ) {
157     ($$hashref{name}=$$hashref{file})=~s/\..*//;
158     }
159 williamc 1.4 # This stuff for later
160     #$fileclass=$toolbox->getclass($file);
161     #$toolbox->maketargets("exe",$fileclass, $$hashref{name}, $file );
162 williamc 1.21.2.21
163 williamc 1.12 ($filename=$$hashref{file})=~s/\..*//;
164 williamc 1.21.2.21
165     # Create a new directory for each binary target
166     my $dirname="bin_".$$hashref{name};
167     AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname");
168     open (binGNUmakefile,
169     ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk") or die "Unable to make $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/".
170     "BuildFile.mk $!\n";
171    
172     # Create the link targets
173     $numbins++;
174     print GNUmakefile <<ENDTEXT;
175     ifndef BINMADE
176     bin bin_debug bin_debug_local bin_insure bin_Insure clean $$hashref{'name'}:: dummy
177     #\t\@echo - Invoking binary makefile \$\@
178     \t\@if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname" ]; then \\
179     \tchdir $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname; \\
180     \t\$(MAKE) BINMADE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk \$\@; \\
181     \tfi
182     endif
183    
184     ENDTEXT
185    
186    
187     # the binary specifics makefile
188     # print binGNUmakefile "include $ENV{LatestBuildFile}\n";
189     print binGNUmakefile "include $currentenv\n";
190     # print binGNUmakefile "include \$(TOOL_HOME)/basics.mk\n";
191     print binGNUmakefile "VPATH+=$ENV{LOCALTOP}/${path}\n";
192     # alias for bin_Insure
193     print binGNUmakefile <<ENDTEXT;
194     bin_insure:bin_Insure
195     ifdef MAKETARGET_bin_insure
196     MAKETARGET_$$hashref{name}_Insure=1
197     endif
198     ENDTEXT
199    
200     # Make generic rules for each type
201     $targettypes={
202     "bin" => 'o',
203     "bin_debug" => 'd',
204     "bin_debug_local" => 'l_d',
205     "bin_Insure" => 'Insure'
206     };
207     #
208     foreach $target ( keys %$targettypes ) {
209     print binGNUmakefile <<ENDTEXT;
210    
211     # Type $target specifics
212     ifdef MAKETARGET_$target
213     MAKETARGET_$$hashref{name}_$$targettypes{$target}=1
214     endif
215     $target ::$$hashref{name}_$$targettypes{$target}
216    
217     bintargets+=$$hashref{name}_$$targettypes{$target}
218     clean::
219     \t\@if [ -f \$(binarystore)/$$hashref{name}_$$targettypes{$target} ]; then \\
220     \techo Removing \$(binarystore)/$$hashref{name}; \\
221     \trm \$(binarystore)/$$hashref{name}_$$targettypes{$target}; \\
222     \tfi
223    
224     ENDTEXT
225     ($objectname=$$hashref{file})=~s/\..*/_$$targettypes{$target}\.o/;
226     ${"objectname_$$targettypes{$target}"}=$objectname;
227     print binGNUmakefile "$objectname:$$hashref{name}.dep\n";
228     } # end loop
229    
230     print binGNUmakefile "$$hashref{name}_Insure:.psrc\n";
231     print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
232     print binGNUmakefile "\t\$(CClinkCmdDebug)\n";
233     print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n";
234     print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n";
235     print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
236     print binGNUmakefile "\t\$(CClinkCmdInsure)\n";
237     print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n";
238     print binGNUmakefile "\t\$(CClinkCmd)\n";
239     print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
240     print binGNUmakefile "-include $$hashref{name}.dep\n";
241     print binGNUmakefile <<ENDTEXT;
242     clean::
243     \t\@if [ -f \$(binarystore)/$$hashref{name} ]; then \\
244     \techo Removing \$(binarystore)/$$hashref{name}; \\
245     \trm \$(binarystore)/$$hashref{name}; \\
246     \tfi
247    
248 williamc 1.19 $$hashref{name}_d.exe:\$(libslocal_d)
249 williamc 1.21.2.20 $$hashref{name}_o.exe:\$(libslocal)
250 williamc 1.21.2.4 ifdef MCCABE_DATA_DIR
251 williamc 1.21.2.21 $$hashref{name}_mccabe.exe: \$(libslocal_d) \$(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp
252 williamc 1.21.2.4 endif
253 williamc 1.19 $$hashref{name}_Insure.exe:\$(libslocal_I)
254 williamc 1.17 $$hashref{name}_d:$$hashref{name}_d.exe
255 williamc 1.21.2.7 \@cp $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
256 williamc 1.21.2.19 $$hashref{name}_l_d:$$hashref{name}_l_d.exe
257     \@cp $$hashref{name}_l_d.exe \$(binarystore)/$$hashref{name}
258 williamc 1.17 $$hashref{name}_Insure:$$hashref{name}_Insure.exe
259 williamc 1.21.2.7 \@cp $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure
260 williamc 1.20 $$hashref{name}:$$hashref{name}_d.exe
261     \@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
262 williamc 1.21.2.20 $$hashref{name}_o:$$hashref{name}_o.exe
263     \@mv $$hashref{name}_o.exe \$(binarystore)/$$hashref{name}
264 williamc 1.21.2.4 binfiles+=$$hashref{file}
265 williamc 1.17 ENDTEXT
266 williamc 1.21.2.12 }
267     }
268    
269     sub Ext_start_export {
270     my $name=shift;
271     my @vars=@_;
272     my $hashref;
273    
274     $hashref=$switch->SetupValueHash(\@vars);
275     if ( $Arch ) {
276     if ( $switchex->context('export') ) {
277     $$hashref{'ref'}=~tr[A-Z][a-z];
278     print GNUmakefile $$hashref{'ref'};
279     if ( defined $$hashref{'version'} ) {
280     print GNUmakefile "_V_".$$hashref{'version'};
281     }
282     print GNUmakefile "=true\n";
283     }
284 williamc 1.21.2.1 }
285 williamc 1.1 }
286    
287     sub External_StartTag {
288     my $name=shift;
289     my @vars=@_;
290     my $hashref;
291    
292     $hashref=$switch->SetupValueHash(\@vars);
293 williamc 1.21 if ( $Arch ) {
294 williamc 1.6 $$hashref{'ref'}=~tr[A-Z][a-z];
295 williamc 1.1 print GNUmakefile $$hashref{'ref'};
296     if ( defined $$hashref{'version'} ) {
297     print GNUmakefile "_V_".$$hashref{'version'};
298     }
299     print GNUmakefile "=true\n";
300 williamc 1.21 }
301 williamc 1.1
302     }
303    
304     sub Group_start {
305     my $name=shift;
306     my @vars=@_;
307     my $hashref;
308    
309     $hashref=$switch->SetupValueHash(\@vars);
310     $switch->checkparam($hashref, $name, 'name');
311 williamc 1.21.2.1 if ( $Arch ) {
312 williamc 1.1 print GNUmakefile "GROUP_".$$hashref{'name'};
313     if ( defined $$hashref{'version'} ) {
314     print GNUmakefile "_V_".$$hashref{'version'};
315     }
316     print GNUmakefile "=true\n";
317 williamc 1.21.2.1 }
318 williamc 1.1 }
319    
320     sub External {
321     my $name=shift;
322     my @vars=@_;
323     # Will simply collect string into a seperate buffer for processind
324     # at the tag closure - used for specifying product defaults
325     # --- Oh oh all of string already in external buffer @!
326     }
327    
328     sub External_EndTag {
329     my $name=shift;
330     my @vars=@_;
331    
332     # process buffer and check consistency with product dtd
333     }
334    
335     sub Use_start {
336     my $name=shift;
337     my @vars=@_;
338     my $hashref;
339     my $filename;
340 williamc 1.2 use Utilities::SCRAMUtils;
341 williamc 1.1
342     $hashref=$switch->SetupValueHash(\@vars);
343     $switch->checkparam($hashref, $name, "name");
344 williamc 1.21.2.1 if ( $Arch ) {
345 williamc 1.21 $filename=SCRAMUtils::checkfile(
346     "$ENV{INTsrc}/$$hashref{name}/BuildFile");
347     if ( $filename ne "" ) {
348     ParseBuildFile_Export( $filename );
349 williamc 1.1 }
350 williamc 1.21.2.1 }
351 williamc 1.1 }
352    
353 williamc 1.5 sub CheckBuildFile {
354 williamc 1.1 my $classdir=shift;
355     $ClassName="";
356     $thisfile="$classdir/$buildfile";
357    
358     if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
359     $DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
360     ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
361     }
362     elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
363     $DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
364     ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
365     }
366     return $ClassName;
367     }
368    
369     # List association groups between <AssociateGroup> tags
370     # seperated by newlines or spaces
371     sub AssociateGroup {
372     my $name=shift;
373     my @vars=@_;
374     my $word;
375    
376     foreach $word ( @vars ){
377     chomp $word;
378     next if /^#/;
379     push @groups, $word;
380     }
381 williamc 1.21.2.1 }
382    
383     sub ignoretag {
384     my $name=shift;
385     my @vars=@_;
386    
387     $Arch=0;
388     push @ARCHBLOCK, $Arch;
389     }
390    
391     sub ignoretag_end {
392     my $name=shift;
393     my @vars=@_;
394    
395     pop @ARCHBLOCK;
396     $Arch=$ARCHBLOCK[$#ARCHBLOCK];
397     }
398    
399     sub Arch_Start {
400     my $name=shift;
401     my @vars=@_;
402     my $hashref;
403    
404     $hashref=$toolswitch->SetupValueHash( \@vars );
405     $toolswitch->checkparam($hashref, $name, 'name');
406     #( ($$hashref{name}=~/$ENV{SCRAM_ARCH}/) )?$Arch=1:$Arch=0;
407     ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($Arch=1) : ($Arch=0);
408     push @ARCHBLOCK, $Arch;
409     }
410     sub Arch_End {
411     my $name=shift;
412     my @vars=@_;
413    
414     pop @ARCHBLOCK;
415     $Arch=$ARCHBLOCK[$#ARCHBLOCK];
416 williamc 1.1 }
417    
418     # Split up the Class Block String into a useable array
419 williamc 1.5 sub _CutBlock {
420 williamc 1.1 my $string= shift @_;
421     @BlockClassA = split /\//, $string;
422     }
423    
424     sub OutToMakefile {
425     my $name=shift;
426     my @vars=@_;
427    
428 williamc 1.21.2.15 if ( $Arch ) {
429     print GNUmakefile @vars;
430     }
431 williamc 1.21.2.14 }
432     sub OutToScreen {
433     my $name=shift;
434     my @vars=@_;
435    
436 williamc 1.21.2.15 if ( $Arch ) {
437     print @vars;
438     }
439 williamc 1.1 }
440     sub setBlockClassPath {
441     my $name=shift;
442     my @vars=@_;
443     my $hashref;
444    
445     $hashref=$switch->SetupValueHash(\@vars);
446     $switch->checkparam($hashref, $name, 'path');
447     $BlockClassPath=$BlockClassPath.":".$$hashref{path};
448     _CutBlock($$hashref{path});
449 williamc 1.21 }
450    
451     sub export_start {
452     #Set up a toolfile object
453     $exporttool=Tool->new();
454     }
455    
456     sub export_end {
457     #Write toolfile object to disk
458     $exporttool->envtomake(\*GNUmakefile);
459     }
460    
461     #
462     # Export Mode Lib Tag
463     #
464     sub lib_start_export {
465     my $name=shift;
466     my @vars=@_;
467     my $hashref;
468    
469     $hashref=$switchex->SetupValueHash( \@vars );
470     $switchex->checkparam($hashref, $name, 'name');
471     if ( $Arch ) {
472     if ( $switchex->context('export') ) {
473     #If export mode then add this env to the export tool
474     $exporttool->addenv('lib',$$hashref{name});
475     }
476     }
477     }
478    
479     #
480     # Standard lib tag
481     #
482     sub lib_start {
483     my $name=shift;
484     my @vars=@_;
485     my $hashref;
486    
487     $hashref=$switch->SetupValueHash( \@vars );
488     $switch->checkparam($hashref, $name, 'name');
489     if ( $Arch ) {
490     print GNUmakefile "lib+=$$hashref{name}\n";
491     }
492 williamc 1.21.2.6 }
493    
494     #
495     # libtype specification
496     #
497     sub LibType_Start {
498     my $name=shift;
499     my @vars=@_;
500     my $hashref;
501    
502 williamc 1.21.2.8 if ( $Arch ) {
503 williamc 1.21.2.6 $hashref=$switch->SetupValueHash( \@vars );
504     $switch->checkparam($hashref, $name, 'type');
505    
506     print GNUmakefile "# Specify Library Type\n";
507     print GNUmakefile "DefaultLibsOff=yes\n";
508     if ( $$hashref{'type'}=~/^archive/i ) {
509     print GNUmakefile "LibArchive=true\n";
510     }
511 williamc 1.21.2.11 elsif ($$hashref{'type'}=~/debug_archive/i ) {
512 williamc 1.21.2.6 print GNUmakefile "LibDebugArchive=true\n";
513     }
514 williamc 1.21.2.11 elsif ($$hashref{'type'}=~/debug_shared/i ) {
515     print GNUmakefile "LibDebugShared=true\n";
516     }
517 williamc 1.21.2.6 elsif ($$hashref{'type'}=~/shared/i ) {
518     print GNUmakefile 'LibShared=true'."\n";
519     }
520     print GNUmakefile "\n";
521 williamc 1.21.2.8 }
522 williamc 1.1 }
523 williamc 1.21.2.15 sub LibType_text {
524     my $name=shift;
525     my @vars=@_;
526    
527     if ( $Arch ) {
528 williamc 1.21.2.16 print GNUmakefile "libmsg::\n\t\@echo Library info: ";
529 williamc 1.21.2.15 print GNUmakefile @vars;
530     print GNUmakefile "\n";
531     }
532     }
533    
534 williamc 1.21.2.21 sub Environment_start {
535     my $name=shift;
536     my @vars=@_;
537     my $hashref;
538    
539     if ( $Arch ) {
540     $envnum++;
541     # copy the current GNUmakefile Filehandle
542     use FileHandle;
543     my $fh=FileHandle->new();
544     open ($fh,">&GNUmakefile");
545     push @filehandlestack, $fh;
546    
547     # open up an environment file
548     open ( GNUmakefile,
549     "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk");
550     # include the approprate environment file
551     if ( $envlevel == 0 ) {
552     print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
553     "BuildFile.mk";
554     }
555     else {
556     print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
557     "Env_$Envlevels[$envlevel]";
558     }
559     $envlevel++;
560     $Envlevels[$envlevel]=$envnum;
561     $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk";
562     }
563     }
564    
565     sub Environment_end {
566     my $fd;
567    
568     if ( $Arch ) {
569     $envlevel--;
570     if ( $envlevel < 0 ) {
571     print "Too many </Environent> Tags on $switch->line()\n";
572     exit;
573     }
574     close GNUmakefile;
575     # restore the last filehandle
576     $fd=pop @filehandlestack;
577     open (GNUmakefile, ">&$fd" ) ;
578     close $fd;
579     if ( $envlevel < 1 ) {
580     $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
581     }
582     else {
583     $currentenv=
584     "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$Envlevels[$envlevel]";
585     }
586     }
587     }