ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.6
Committed: Fri Sep 15 11:18:21 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.5: +24 -23 lines
Log Message:
updates to setup environment

File Contents

# User Rev Content
1 williamc 1.2 # BuildFile
2 williamc 1.1 #
3     # Interface
4     # ---------
5 williamc 1.3 # new(ConfigArea)
6 williamc 1.2 # 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 williamc 1.6 # classname() : get/set the associated class
11     # buildfile() : get/set BuildFile location
12 williamc 1.1
13     package BuildSystem::BuildFile;
14 williamc 1.2 use ActiveDoc::SimpleDoc;
15     use BuildSystem::ToolBox;
16     require 5.004;
17    
18     BEGIN {
19     $buildfile="BuildFile";
20     }
21    
22     sub new {
23     my $class=shift;
24     my $self={};
25     bless $self, $class;
26 williamc 1.3 $self->{area}=shift;
27     $self->{toolbox}=$self->{area}->toolbox();
28 williamc 1.5 $self->{localtop}=$self->{area}->location();
29 williamc 1.2 $self->{Arch}=1;
30     push @{$self->{ARCHBLOCK}}, $self->{Arch};
31     return $self;
32     }
33    
34 williamc 1.6 sub buildfile {
35     my $self=shift;
36     if ( @_ ) {
37     $self->{buildfile}=shift;
38     }
39     return $self->{buildfile};
40     }
41    
42 williamc 1.2 sub ignore {
43     my $self=shift;
44     return (defined $self->{ignore})?$self->{ignore}:0;
45     }
46    
47     sub _initswitcher {
48     my $self=shift;
49     my $switch=ActiveDoc::SimpleDoc->new();
50     my $parse="makebuild";
51     $switch->newparse($parse);
52     $switch->addignoretags($parse);
53     $self->_commontags($switch,$parse);
54     $switch->addtag($parse,"Build", \&Build_start, $self);
55     $switch->addtag($parse,"none",
56     \&OutToMakefile,$self,
57     \&OutToMakefile, $self,
58     "", $self);
59     $switch->addtag($parse,"Bin",
60     \&Bin_start,$self,
61     \&OutToScreen, $self,
62     "", $self);
63     $switch->addtag($parse,"LibType",
64     \&LibType_Start,$self,
65     \&LibType_text, $self,
66     \&LibType_end,$self);
67     $switch->addtag($parse,"ConfigurationClass",
68     \&Class_StartTag,$self,
69     \&OutToMakefile, $self,
70     "", $self);
71     $switch->addtag($parse,"ClassPath",
72     \&setBlockClassPath,$self,
73     \&OutToMakefile, $self,
74     "", $self);
75     $switch->addtag($parse,"AssociateGroup",
76     "",$self,
77     \&AssociateGroup,$self,
78     "", $self);
79     $switch->addtag($parse,"Environment",
80     \&Environment_start,$self,
81     \&OutToMakefile, $self,
82     \&Environment_end,$self);
83     $switch->addtag($parse,"Export",
84     \&export_start,$self,
85     \&OutToMakefile, $self,
86     \&export_end,$self);
87     return $switch;
88     }
89    
90     sub _commontags {
91     my $self=shift;
92     my $switch=shift;
93     my $parse=shift;
94    
95     $switch->grouptag("Export",$parse);
96     $switch->addtag($parse,"Use",\&Use_start,$self,
97     \&OutToMakefile, $self,
98     "", $self);
99     $switch->addtag($parse,"Group",\&Group_start,$self,
100     \&OutToMakefile, $self,
101     "", $self);
102     $switch->grouptag("Group",$parse);
103     $switch->addtag($parse,"External",
104     \&External_StartTag,$self,
105     \&OutToMakefile, $self,
106     "", $self);
107     $switch->addtag($parse,"lib",
108     \&lib_start,$self,
109     \&OutToMakefile, $self,
110     "", $self);
111     $switch->addtag($parse,"Architecture",
112     \&Arch_Start,$self,
113     \&OutToMakefile, $self,
114     \&Arch_End,$self);
115     $switch->addtag($parse,"INCLUDE_PATH",
116     \&IncludePath_Start,$self,
117     \&OutToMakefile, $self,
118     "",$self);
119     return $switch;
120     }
121    
122 williamc 1.4 sub GenerateMakefile {
123     my $self=shift;
124     my $infile=shift;
125     my $outfile=shift;
126    
127     $self->{switch}=$self->_initswitcher();
128     $self->{switch}->filetoparse($infile);
129    
130     # open a temporary gnumakefile to store output.
131     my $fh=FileHandle->new();
132     open ( $fh, ">$outfile") or die "Unable to open $outfile for output ".
133     "$!\n";
134     @{$self->{filehandlestack}}=($fh);
135    
136     # -- make an alias
137     *GNUmakefile=$fh;
138     if ( -e $ENV{LatestBuildFile} ) {
139     print GNUmakefile "include $ENV{LatestBuildFile}\n";
140     }
141     $ENV{LatestBuildFile}=$outfile;
142     $self->{switch}->parse("makebuild"); # sort out supported tags
143     close GNUmakefile;
144     }
145    
146 williamc 1.2 sub ParseBuildFile {
147     my $self=shift;
148     my $base=shift;
149     my $path=shift;
150     my $filename=shift @_;
151     my $fullfilename;
152     if ( $filename!~/^\// ) {
153     $fullfilename="$base/$path/$filename";
154     }
155     else {
156     $fullfilename=$filename;
157     }
158     $self->{path}=$path;
159     #print "Processing $fullfilename\n";
160     $numbins=0;
161     $self->{envnum}=0;
162     $self->{envlevel}=0;
163 williamc 1.5 $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
164 williamc 1.2 "BuildFile.mk";
165     $self->{switch}=$self->_initswitcher();
166     $self->{switch}->filetoparse($fullfilename);
167    
168     # $self->{switch}->{Strict_no_cr}='no';
169     #open a temporary gnumakefile to store output.
170     use Utilities::AddDir;
171 williamc 1.5 AddDir::adddir("$self->{localtop}/$ENV{INTwork}/$self->{path}");
172 williamc 1.2 my $fh=FileHandle->new();
173 williamc 1.5 open ( $fh, ">$self->{localtop}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk"
174 williamc 1.2 ) or die 'Unable to open /$ENV{INTwork}/".$self->{path}."/BuildFile.mk $!\n';
175     @{$self->{filehandlestack}}=($fh);
176     # make an alias
177     *GNUmakefile=$fh;
178     if ( -e $ENV{LatestBuildFile} ) {
179     print GNUmakefile "include $ENV{LatestBuildFile}\n";
180     }
181     # print "writing to :\n".
182 williamc 1.5 # "$self->{localtop}/$ENV{INTwork}/$self->{path}/BuildFile.mk\n";
183     $ENV{LatestBuildFile}="$self->{localtop}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk";
184 williamc 1.2 $self->{switch}->parse("makebuild"); # sort out supported tags
185     if ( $numbins > 0 ) {
186     print GNUmakefile <<ENDTEXT;
187     ifndef BINMODE
188     help::
189     \t\@echo Generic Binary targets
190     \t\@echo ----------------------
191     endif
192     ENDTEXT
193     foreach $target ( keys %$targettypes ) {
194     print GNUmakefile <<ENDTEXT;
195     ifndef BINMODE
196     help::
197     \t\@echo $target
198     endif
199     ENDTEXT
200     }
201     }
202     close GNUmakefile;
203     }
204 williamc 1.1
205 williamc 1.6 sub classname {
206     my $self=shift;
207     if ( @_ ) {
208     $self->{classname}=shift;
209     }
210     return $self->{classname};
211     }
212    
213 williamc 1.2 sub ParseBuildFile_Export {
214 williamc 1.1 my $self=shift;
215 williamc 1.2 my $filename=shift;
216 williamc 1.3 my $bf=BuildSystem::BuildFile->new($self->{area});
217 williamc 1.2 if ( defined $self->{remoteproject} ) {
218     $bf->{remoteproject}=$self->{remoteproject};
219     }
220     $bf->_parseexport($filename);
221     undef $bf;
222     }
223 williamc 1.1
224 williamc 1.2 sub _location {
225     my $self=shift;
226     use File::Basename;
227 williamc 1.1
228 williamc 1.2 return dirname($self->{switch}->filetoparse());
229 williamc 1.1 }
230    
231 williamc 1.2 sub _parseexport {
232 williamc 1.1 my $self=shift;
233 williamc 1.2 my $filename=shift;
234    
235     my $switchex=ActiveDoc::SimpleDoc->new();
236     $switchex->filetoparse($filename);
237     $switchex->newparse("export");
238     $switchex->addignoretags("export");
239     $switchex->addtag("export","Export",
240     \&export_start_export,$self,
241     \&OutToMakefile, $self,
242     \&export_end_export,$self);
243     $self->_commontags($switchex,"export");
244     $switchex->allowgroup("__export","export");
245     # $switchex->{Strict_no_cr}='no';
246     $self->{switch}=$switchex;
247     $switchex->parse("export"); # sort out supported tags
248     }
249 williamc 1.1
250 williamc 1.2 sub _pushremoteproject {
251     my $self=shift;
252     my $path=shift;
253 williamc 1.1
254 williamc 1.2 if ( defined $self->{remoteproject} ) {
255     push @{$self->{rpstack}}, $self->{remoteproject};
256     }
257     $self->{remoteproject}=$path;
258 williamc 1.1 }
259    
260 williamc 1.2 sub _popremoteproject {
261     my $self=shift;
262     if ( $#{$self->{rpstack}} >=0 ) {
263     $self->{remoteproject}=pop @{$self->{rpstack}};
264     }
265     else {
266     undef $self->{remoteproject};
267     }
268     }
269 williamc 1.1
270 williamc 1.2 sub _toolmapper {
271     my $self=shift;
272     if ( ! defined $self->{mapper} ) {
273     require BuildSystem::ToolMapper;
274     $self->{mapper}=BuildSystem::ToolMapper->new();
275     }
276     return $self->{mapper};
277     }
278    
279    
280     # ---- Tag routines
281    
282     #-- Override a class type with the <ConfigurationClass type=xxx> tag
283     # the type tag will pick up a pre-defined class type from project space.
284    
285     sub Class_StartTag {
286 williamc 1.1 my $self=shift;
287     my $name=shift;
288     my $hashref=shift;
289 williamc 1.2
290     if ( $self->{Arch} ) {
291     if ( defined $$hashref{'type'} ) {
292 williamc 1.6 $self->classname($$hashref{'type'});
293 williamc 1.2 }
294     }
295     }
296    
297     sub IncludePath_Start {
298     my $self=shift;
299     my $name=shift;
300     my $hashref=shift;
301    
302     $self->{switch}->checktag( $name, $hashref, 'path');
303     if ( $self->{Arch} ) {
304     print GNUmakefile "INCLUDE+=".$self->_location()."/".
305     $$hashref{'path'}."\n";
306     }
307     }
308    
309     #
310     # generic build tag
311     #
312     sub Build_start {
313     my $self=shift;
314     my $name=shift;
315     my $hashref=shift;
316    
317     $self->{switch}->checktag($name,$hashref,'class');
318     if ( $self->{Arch} ) {
319    
320     # -- determine the build products name
321     my $name;
322     if ( exists $$hashref{'name'} ) {
323     $name=$$hashref{'name'};
324     }
325     else {
326     $self->{switch}->parseerror("No name specified for build product");
327     #$name="\$(buildname)";
328     }
329    
330     # -- check we have a lookup for the class type
331     my $mapper=$self->_toolmapper();
332     if ( ! $mapper->exists($$hashref{'class'}) ) {
333     $self->{switch}->parseerror("Unknown class : ".$$hashref{'class'});
334     }
335     else {
336     my @types=$self->_toolmapper()->types($$hashref{'class'});
337     my @deftypes=$self->_toolmapper()->defaulttypes($$hashref{'class'});
338    
339     my $fh=$self->{filehandlestack}[0];
340     my @targets=();
341    
342     # -- generate generic targets
343     print $fh "ifndef _BuildLink_\n";
344     print $fh "# -- Generic targets\n";
345     push @targets, $$hashref{'class'};
346     foreach $dtype ( @deftypes ) {
347     print $fh $$hashref{'class'}."::".$$hashref{'class'}."_".
348     $dtype."\n";
349     }
350     print $fh "\n";
351    
352     # -- generate targets for each type
353     foreach $type ( @types ) {
354    
355     # -- generic name for each type
356     my $pattern=$$hashref{'class'}."_".$type;
357     my $dirname=$$hashref{'class'}."_".$type."_".$name;
358     print $fh "# ------ $pattern rules ---------------\n";
359     print $fh $$hashref{'class'}."_".$type."::".$$hashref{'class'}.
360     "_".$type."_$name\n\n";
361    
362     # -- create a new directory for each type
363     push @targets, $pattern;
364     my $dirname=$$hashref{'class'}."_".$type."_".$name;
365 williamc 1.5 my $here="$self->{localtop}/$ENV{INTwork}/".$self->{path}."/".$dirname;
366 williamc 1.2 my $makefile=$here."/BuildFile.mk";
367     # AddDir::adddir($here);
368    
369     # -- create link targets to the directory
370     push @targets, $dirname;
371     print $fh "# -- Link Targets to $type directories\n";
372     print $fh "$dirname: make_$dirname\n";
373     print $fh "\t\@cd $here; \\\n";
374     print $fh "\t\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
375     " workdir=$here ".
376     " -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \n\n";
377    
378     # -- write target to make makefile for each directory
379     print $fh "# -- Build target directories\n";
380     print $fh "make_$dirname:\n";
381     print $fh "\tif [ ! -e \"$makefile\" ]; then \\\n";
382     print $fh "\t if [ ! -d \"$here\" ]; then \\\n";
383     print $fh "\t mkdir $here; \\\n";
384     print $fh "\t fi;\\\n";
385     print $fh "\t cd $dirname; \\\n";
386     print $fh "\t echo include ".$self->{currentenv}." > ".
387     "$makefile; \\\n";
388 williamc 1.5 print $fh "\t echo VPATH+=$self->{localtop}/".$self->{path}.
389 williamc 1.2 " >> $makefile; \\\n";
390     print $fh "\t echo buildname=$name >> $makefile;\\\n";
391     print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n";
392     if ( defined (my @file=$mapper->rulesfile($$hashref{'class'})) ) {
393     foreach $f ( @file ) {
394     print $fh "\t echo -include $f >> $makefile; \\\n";
395     }
396     }
397     print $fh "\tfi\n";
398     print $fh "\n";
399     # print $typefile "$name :\n";
400     # print $typefile "\t\$(_quietbuild_)";
401     # print $typefile $mapper->template($$hashref{'class'},$type)."\n";
402     # print $typefile "\t\$(_quietstamp_)";
403 williamc 1.6 # print $typefile "\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
404 williamc 1.2
405     # -- cleaning targets
406     push @targets, "clean_$dirname";
407     print $fh "# -- cleaning targets\n";
408     print $fh "clean::clean_$dirname\n";
409     print $fh "clean_".$dirname."::\n";
410     print $fh "\t\@echo cleaning $dirname\n";
411     print $fh "\t\@if [ -d $here ]; then \\\n";
412     print $fh "\tcd $here; \\\n";
413     print $fh "\t\$(MAKE) LatestBuildFile=$makefile workdir=".
414     $here." _BuildLink_=1 -f ".
415     "\$(TOOL_HOME)/basics.mk clean; \\\n";
416     print $fh "\tfi\n\n";
417    
418    
419     }
420     # -- help targets
421     print $fh "helpheader::\n";
422     print $fh "\t\@echo Targets available:\n";
423     print $fh "\t\@echo ------------------\n\n";
424     print $fh "help::helpheader\n";
425     foreach $target ( @targets ) {
426     print $fh "help::\n";
427     print $fh "\t\@echo $target\n"
428     }
429     print $fh "endif\n";
430     } # end else
431     }
432     }
433    
434     sub Bin_start {
435     my $self=shift;
436     my $name=shift;
437     my $hashref=shift;
438    
439     my $fileclass;
440     my @tools;
441     my $tool;
442     my $filename;
443     my $objectname;
444    
445     $self->{switch}->checktag($name,$hashref,'file');
446     if ( $self->{Arch} ) {
447     if ( ! defined $$hashref{name} ) {
448     ($$hashref{name}=$$hashref{file})=~s/\..*//;
449     }
450     ($filename=$$hashref{file})=~s/\..*//;
451    
452     # Create a new directory for each binary target
453     my $dirname="bin_".$$hashref{name};
454 williamc 1.5 AddDir::adddir("$self->{localtop}/$ENV{INTwork}/".$self->{path}."/$dirname");
455 williamc 1.2 open (binGNUmakefile,
456 williamc 1.5 ">$self->{localtop}/$ENV{INTwork}/".$self->{path}."/$dirname/BuildFile.mk") or die "Unable to make $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname/".
457 williamc 1.2 "BuildFile.mk $!\n";
458    
459     # Create the link targets
460     $numbins++;
461     my $fh=$self->{filehandlestack}[0];
462     print $fh <<ENDTEXT;
463    
464     # Link Targets to binary directories
465     ifdef BINMODE
466     # We dont want to build a library here
467     override files:=
468     endif
469     ifndef BINMODE
470    
471     define stepdown_$$hashref{'name'}
472 williamc 1.5 if [ -d "$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\
473     cd $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname; \\
474     \$(MAKE) BINMODE=true LatestBuildFile=$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \\
475 williamc 1.2 fi
476     endef
477    
478     define stepdown2_$$hashref{'name'}
479 williamc 1.5 if [ -d "$self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname" ]; then \\
480     cd $self->{localtop}/$ENV{INTwork}/$self->{path}/$dirname; \\
481     \$(MAKE) BINMODE=true LatestBuildFile=$self->{localtop}/$ENV{INTwork}/$self{path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk datestamp \$\*; \\
482 williamc 1.2 fi
483    
484     endef
485    
486     bin_$$hashref{'name'}_%:: dummy
487     \@\$(stepdown2_$$hashref{'name'})
488    
489     $$hashref{'name'}_%:: dummy
490     \@\$(stepdown_$$hashref{'name'})
491    
492     help bin bin_debug bin_debug_local bin_insure bin_Insure clean $$hashref{'name'}:: dummy
493     \@\$(stepdown_$$hashref{'name'})
494    
495     binfiles+=$$hashref{'file'}
496     locbinfiles+=$dirname/$$hashref{'file'}
497     endif
498    
499    
500     ENDTEXT
501    
502    
503     # the binary specifics makefile
504     print binGNUmakefile "include ".$self->{currentenv}."\n";
505 williamc 1.5 print binGNUmakefile "VPATH+=$self->{localtop}/$self{path}\n";
506 williamc 1.2
507     # alias for bin_Insure
508     print binGNUmakefile <<ENDTEXT;
509    
510     bin_insure:bin_Insure
511     ifdef MAKETARGET_bin_insure
512     MAKETARGET_$$hashref{name}_Insure=1
513     endif
514    
515     # debuggging target
516     $$hashref{'name'}_echo_% :: echo_%
517    
518     # help targets
519     help::
520     \t\@echo Targets For $$hashref{'name'}
521     \t\@echo -------------------------------------
522     \t\@echo $$hashref{'name'} - default build
523     \t\@echo bin_$$hashref{'name'}_clean - executable specific cleaning
524     ENDTEXT
525    
526     # Make generic rules for each type
527     $targettypes={
528     "bin" => 'o',
529     "bin_debug" => 'd',
530     "bin_debug_local" => 'l_d',
531     "bin_Insure" => 'Insure'
532     };
533     #
534     foreach $target ( keys %$targettypes ) {
535     print binGNUmakefile <<ENDTEXT;
536    
537     # Type $target specifics
538     ifdef MAKETARGET_$target
539     MAKETARGET_$$hashref{name}_$$targettypes{$target}=1
540     endif
541     $target ::$$hashref{name}_$$targettypes{$target}
542    
543     bintargets+=$$hashref{name}_$$targettypes{$target}
544     help::
545     \t\@echo $$hashref{name}_$$targettypes{$target}
546     clean::
547     \t\@if [ -f \$(binarystore)/$$hashref{name}_$$targettypes{$target} ]; then \\
548     \techo Removing \$(binarystore)/$$hashref{name}; \\
549     \trm \$(binarystore)/$$hashref{name}_$$targettypes{$target}; \\
550     \tfi
551    
552     ENDTEXT
553     ($objectname=$$hashref{file})=~s/\..*/_$$targettypes{$target}\.o/;
554     ${"objectname_$$targettypes{$target}"}=$objectname;
555     print binGNUmakefile "$objectname:$$hashref{name}.dep\n";
556     } # end loop
557    
558     print binGNUmakefile "$$hashref{name}_Insure.exe:.psrc\n";
559     print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
560     print binGNUmakefile "\t\$(CClinkCmdDebug)\n";
561 williamc 1.6 print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
562 williamc 1.2 print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n";
563     print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n";
564 williamc 1.6 print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
565 williamc 1.2 print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
566     print binGNUmakefile "\t\$(CClinkCmdInsure)\n";
567 williamc 1.6 print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
568 williamc 1.2 print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n";
569     print binGNUmakefile "\t\$(CClinkCmd)\n";
570 williamc 1.6 print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
571 williamc 1.2 print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
572     print binGNUmakefile "-include $$hashref{name}.dep\n";
573     print binGNUmakefile <<ENDTEXT;
574     clean::
575     \t\@if [ -f \$(binarystore)/$$hashref{name} ]; then \\
576     \techo Removing \$(binarystore)/$$hashref{name}; \\
577     \trm \$(binarystore)/$$hashref{name}; \\
578     \tfi
579    
580     $$hashref{name}_d.exe:\$(libslocal_d)
581     $$hashref{name}_o.exe:\$(libslocal)
582     ifdef MCCABE_DATA_DIR
583     $$hashref{name}_mccabe.exe: \$(libslocal_d) \$(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp
584     endif
585     $$hashref{name}_Insure.exe:\$(libslocal_I)
586     $$hashref{name}_d:$$hashref{name}_d.exe
587     \@cp $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
588     $$hashref{name}_l_d:$$hashref{name}_l_d.exe
589     \@cp $$hashref{name}_l_d.exe \$(binarystore)/$$hashref{name}
590     $$hashref{name}_Insure:$$hashref{name}_Insure.exe
591     \@cp $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure
592     $$hashref{name}:$$hashref{name}_d.exe
593     \@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
594     $$hashref{name}_o:$$hashref{name}_o.exe
595     \@mv $$hashref{name}_o.exe \$(binarystore)/$$hashref{name}
596     binfiles+=$$hashref{file}
597     ENDTEXT
598     }
599     close binGNUmakefile;
600     }
601    
602     sub External_StartTag {
603     my $self=shift;
604     my $name=shift;
605     my $hashref=shift;
606    
607     my $tool;
608     if ( $self->{Arch} ) {
609     $self->{switch}->checktag($name,$hashref,'ref');
610    
611     # -- oo toolbox stuff
612     # - get the appropriate tool object
613     $$hashref{'ref'}=~tr[A-Z][a-z];
614     if ( ! exists $$hashref{'version'} ) {
615     $tool=$self->{toolbox}->gettool($$hashref{'ref'});
616     }
617     else {
618     $tool=$self->{toolbox}->gettool($$hashref{'ref'},$$hashref{'version'});
619     }
620     if ( ! defined $tool ) {
621     $self->{switch}->parseerror("Unknown Tool Specified ("
622     .$$hashref{'ref'}.")");
623     }
624    
625     # -- old fashioned GNUmakefile stuff
626     print GNUmakefile $$hashref{'ref'};
627     if ( defined $$hashref{'version'} ) {
628     print GNUmakefile "_V_".$$hashref{'version'};
629     }
630     print GNUmakefile "=true\n";
631    
632     # -- Sub system also specified?
633     if ( exists $$hashref{'use'} ) {
634     # -- look for a buildfile
635     my @paths=$tool->getfeature("INCLUDE");
636     my $file="";
637     my ($path,$testfile);
638     foreach $path ( @paths ) {
639     $testfile=$path."/".$$hashref{'use'}."/BuildFile" ;
640     if ( -f $testfile ) {
641     $file=$testfile;
642     $self->_pushremoteproject($path);
643     }
644     }
645     if ( $file eq "" ) {
646     $self->{switch}->parseerror("Unable to find SubSystem $testfile");
647     }
648     $self->ParseBuildFile_Export($file);
649     $self->_popremoteproject();
650     }
651     }
652     }
653    
654     sub Group_start {
655     my $self=shift;
656     my $name=shift;
657     my $hashref=shift;
658    
659     $self->{switch}->checktag($name, $hashref, 'name');
660     if ( $self->{Arch} ) {
661     print GNUmakefile "GROUP_".$$hashref{'name'};
662     if ( defined $$hashref{'version'} ) {
663     print GNUmakefile "_V_".$$hashref{'version'};
664     }
665     print GNUmakefile "=true\n";
666     }
667     }
668 williamc 1.1
669 williamc 1.2 sub Use_start {
670     my $self=shift;
671     my $name=shift;
672     my $hashref=shift;
673     my $filename;
674     use Utilities::SCRAMUtils;
675 williamc 1.1
676 williamc 1.2 $self->{switch}->checktag($name, $hashref, "name");
677     if ( $self->{Arch} ) {
678     if ( exists $$hashref{'group'} ) {
679     print GNUmakefile "GROUP_".$$hashref{'group'}."=true\n";
680     }
681     if ( ! defined $self->{remoteproject} ) {
682     $filename=SCRAMUtils::checkfile(
683     "/$ENV{INTsrc}/$$hashref{name}/BuildFile");
684     }
685     else {
686     $filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
687     print "trying $filename\n";
688     if ( ! -f $filename ) { $filename=""; };
689     }
690     if ( $filename ne "" ) {
691     $self->ParseBuildFile_Export( $filename );
692     }
693     else {
694     $self->{switch}->parseerror("Unable to detect Appropriate ".
695     "decription file for <$name name=".$$hashref{name}.">");
696     }
697     }
698 williamc 1.1 }
699    
700 williamc 1.2 # List association groups between <AssociateGroup> tags
701     # seperated by newlines or spaces
702     sub AssociateGroup {
703     my $self=shift;
704     my $name=shift;
705     my $string=shift;
706     my $word;
707    
708     if ( $self->{Arch} ) {
709     foreach $word ( (split /\s/, $string) ){
710     chomp $word;
711     next if /^#/;
712     if ( $word=~/none/ ) {
713     $self->{ignore}=1;
714     }
715     }
716     }
717     }
718    
719     sub Arch_Start {
720     my $self=shift;
721 williamc 1.1 my $name=shift;
722     my $hashref=shift;
723    
724 williamc 1.2 $self->{switch}->checktag($name, $hashref,'name');
725     ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
726     : ($self->{Arch}=0);
727     push @{$self->{ARCHBLOCK}}, $self->{Arch};
728 williamc 1.1 }
729    
730 williamc 1.2 sub Arch_End {
731 williamc 1.1 my $self=shift;
732     my $name=shift;
733    
734 williamc 1.2 pop @{$self->{ARCHBLOCK}};
735     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
736     }
737    
738     # Split up the Class Block String into a useable array
739     sub _CutBlock {
740     my $self=shift;
741     my $string= shift @_;
742     @BlockClassA = split /\//, $string;
743     }
744    
745     sub OutToMakefile {
746     my $self=shift;
747     my $name=shift;
748     my @vars=@_;
749    
750     if ( $self->{Arch} ) {
751     print GNUmakefile @vars;
752     }
753     }
754    
755     sub OutToScreen {
756     my $name=shift;
757     my @vars=@_;
758    
759     if ( $self->{Arch} ) {
760     print @vars;
761     }
762     }
763     sub setBlockClassPath {
764     my $self=shift;
765     my $name=shift;
766     my $hashref=shift;
767    
768     $self->{switch}->checktag($name, $hashref, 'path');
769     $self->{BlockClassPath}=$self->{BlockClassPath}.":".$$hashref{path};
770     $self->_CutBlock($$hashref{path});
771     }
772    
773     sub BlockClassPath {
774     my $self=shift;
775     return $self->{BlockClassPath};
776     }
777    
778     sub export_start_export {
779     my $self=shift;
780     my $name=shift;
781     my $hashref=shift;
782    
783     $self->{switch}->opengroup("__export");
784     }
785    
786     sub export_start {
787     my $self=shift;
788     my $name=shift;
789     my $hashref=shift;
790    
791     $self->{switch}->opengroup("__export");
792     if ( exists $$hashref{autoexport} ) {
793     print GNUmakefile "scram_autoexport=".$$hashref{autoexport}."\n";
794     if ( $$hashref{autoexport}=~/true/ ) {
795     $self->{switch}->allowgroup("__export","makebuild");
796     }
797     else {
798     $self->{switch}->disallowgroup("__export","makebuild");
799     }
800     }
801     # -- allow default setting from other makefiles
802     print GNUmakefile "ifeq (\$(scram_autoexport),true)\n";
803     }
804    
805     sub export_end_export {
806     my $self=shift;
807     $self->{switch}->closegroup("__export");
808     }
809 williamc 1.1
810 williamc 1.2 sub export_end {
811     my $self=shift;
812     $self->{switch}->closegroup("__export");
813     print GNUmakefile "endif\n";
814 williamc 1.1 }
815    
816 williamc 1.2 #
817     # Standard lib tag
818     #
819     sub lib_start {
820 williamc 1.1 my $self=shift;
821     my $name=shift;
822     my $hashref=shift;
823    
824 williamc 1.2 $self->{switch}->checktag($name, $hashref, 'name');
825     if ( $self->{Arch} ) {
826     print GNUmakefile "lib+=$$hashref{name}\n";
827     }
828     }
829    
830     #
831     # libtype specification
832     #
833     sub LibType_Start {
834     my $self=shift;
835     my $name=shift;
836     my $hashref=shift;
837 williamc 1.1
838 williamc 1.2 if ( $self->{Arch} ) {
839     if ( defined $self->{libtype_conext} ) {
840     $self->{switch}->parseerror("<$name> tag cannot be specified".
841     " without a </$name> tag to close previous context");
842 williamc 1.1 }
843     else {
844 williamc 1.2 $self->{libtype_conext}=1;
845     $self->{switch}->checktag($name, $hashref, 'type');
846    
847     print GNUmakefile "# Specify Library Type\n";
848     print GNUmakefile "DefaultLibsOff=yes\n";
849     if ( $$hashref{'type'}=~/^archive/i ) {
850     print GNUmakefile "LibArchive=true\n";
851     }
852     elsif ($$hashref{'type'}=~/debug_archive/i ) {
853     print GNUmakefile "LibDebugArchive=true\n";
854     }
855     elsif ($$hashref{'type'}=~/debug_shared/i ) {
856     print GNUmakefile "LibDebugShared=true\n";
857     }
858     elsif ($$hashref{'type'}=~/shared/i ) {
859     print GNUmakefile 'LibShared=true'."\n";
860 williamc 1.1 }
861 williamc 1.2 print GNUmakefile "\n";
862     }
863     }
864     }
865 williamc 1.1
866 williamc 1.2 sub LibType_text {
867 williamc 1.1 my $self=shift;
868     my $name=shift;
869 williamc 1.2 my $string=shift;
870 williamc 1.1
871 williamc 1.2 if ( $self->{Arch} ) {
872     $string=~s/\n/ /g;
873     print GNUmakefile "libmsg::\n\t\@echo Library info: ";
874     print GNUmakefile $string;
875     print GNUmakefile "\n";
876     }
877 williamc 1.1 }
878    
879 williamc 1.2 sub LibType_end {
880 williamc 1.1 my $self=shift;
881     my $name=shift;
882    
883 williamc 1.2 undef $self->{libtype_conext};
884 williamc 1.1 }
885    
886 williamc 1.2 sub Environment_start {
887 williamc 1.1 my $self=shift;
888     my $name=shift;
889     my $hashref=shift;
890 williamc 1.2
891     if ( $self->{Arch} ) {
892     $self->{envnum}++;
893    
894     # open a new Environment File
895 williamc 1.5 my $envfile="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_".
896 williamc 1.2 $self->{envnum}.".mk";
897     use FileHandle;
898     my $fh=FileHandle->new();
899     open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
900     push @{$self->{filehandlestack}}, $fh;
901     *GNUmakefile=$fh;
902    
903     # include the approprate environment file
904     if ( $self->{envlevel} == 0 ) {
905 williamc 1.5 print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
906 williamc 1.2 $self->{path}."/BuildFile.mk\n";
907     }
908     else {
909 williamc 1.5 print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
910 williamc 1.2 $self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
911     }
912     $self->{envlevel}++;
913     $self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
914 williamc 1.5 $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
915 williamc 1.2 }
916 williamc 1.1 }
917    
918 williamc 1.2 sub Environment_end {
919 williamc 1.1 my $self=shift;
920 williamc 1.2 my $fd;
921    
922     if ( $self->{Arch} ) {
923     $self->{envlevel}--;
924     if ( $self->{envlevel} < 0 ) {
925     print "Too many </Environent> Tags on $self->{switch}->line()\n";
926     exit 1;
927     }
928     close GNUmakefile;
929     # restore the last filehandle
930     $fd=pop @{$self->{filehandlestack}};
931     close $fd;
932     *GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
933     if ( $self->{envlevel} < 1 ) {
934 williamc 1.5 $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
935 williamc 1.2 "BuildFile.mk";
936     }
937     else {
938     $self->{currentenv}=
939 williamc 1.5 $self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_".
940 williamc 1.2 $self->{Envlevels}[$self->{envlevel}];
941     }
942     }
943 williamc 1.1 }