ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.1.2.20
Committed: Wed Jun 14 19:28:00 2000 UTC (24 years, 11 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.19: +4 -3 lines
Log Message:
fix cleaning targets

File Contents

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