ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.1.2.26
Committed: Thu Jun 22 10:02:40 2000 UTC (24 years, 10 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.25: +4 -3 lines
Log Message:
Initiaialise with a configarea rather than just the toolbox

File Contents

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