ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.1.2.24
Committed: Mon Jun 19 12:05:04 2000 UTC (24 years, 10 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_13_0
Changes since 1.1.2.23: +7 -12 lines
Log Message:
Add LibTags

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 williamc 1.1.2.21 # open a temporary gnumakefile to store output.
157 williamc 1.1.2.1 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 williamc 1.1.2.21
272 williamc 1.1.2.11 $self->{switch}->checktag($name,$hashref,'class');
273     if ( $self->{Arch} ) {
274 williamc 1.1.2.21 my $fh=$self->{filehandlestack}[0];
275     # -- get the mapper object
276 williamc 1.1.2.16 my $mapper=$self->_toolmapper($$hashref{'class'});
277     if ( ! defined $mapper ) {
278 williamc 1.1.2.11 $self->{switch}->parseerror("Unknown class : ".$$hashref{'class'});
279     }
280     else {
281 williamc 1.1.2.21 # -- get default types
282     my @deftypes;
283     if ( ! exists $$hashref{'default'} ) {
284     @deftypes=$mapper->defaulttypes();
285     }
286     else {
287     @deftypes=split /,/, $$hashref{'default'};
288 williamc 1.1.2.23 print $fh "# -- default override\n";
289     print $fh "Sorigdefault_".$$hashref{'class'}.":=".
290     "\$(Sdefault_".$$hashref{'class'}.")\n";
291     print $fh "Sdefault_".$$hashref{'class'}.":=\n\n";
292 williamc 1.1.2.21 }
293    
294     # -- no src parameter so it must be a default setting tag
295     if ( ! exists $$hashref{src} ) {
296     # -- general default setting
297     $self->{switch}->checktag($name,$hashref,'default');
298     $mapper->defaulttypes(@deftypes);
299     $self->_makegenerictargets($fh, $$hashref{'class'},@deftypes);
300     }
301     else {
302     $self->{switch}->checktag($name,$hashref,'src');
303     $self->{switch}->checktag($name,$hashref,'name');
304     my $name=$$hashref{'name'};
305     my @types=$mapper->types();
306 williamc 1.1.2.16
307 williamc 1.1.2.11
308     my @targets=();
309    
310     # -- generate generic targets
311     print $fh "ifndef _BuildLink_\n";
312 williamc 1.1.2.21 push @targets, ($self->_makegenerictargets($fh,$$hashref{'class'},
313     @deftypes));
314 williamc 1.1.2.23 print $fh $$hashref{'class'}."::\$(Sdefault_".$$hashref{'class'}
315     .")\n";
316 williamc 1.1.2.21 print $fh "Sdefault_".$$hashref{'class'}."_".$$hashref{'name'}.
317     "=\$(addsuffix _".$$hashref{'name'}.",\$(Sdefault_".
318     $$hashref{'class'}."))\n";
319     print $fh $$hashref{'class'}."_".$$hashref{'name'}."::\$(".
320     "Sdefault_".$$hashref{'class'}."_".$$hashref{'name'}.")\n";
321 williamc 1.1.2.19 push @targets, $$hashref{'class'}."_".$$hashref{'name'};
322 williamc 1.1.2.11
323     # -- generate targets for each type
324     foreach $type ( @types ) {
325    
326     # -- generic name for each type
327     my $pattern=$$hashref{'class'}."_".$type;
328     my $dirname=$$hashref{'class'}."_".$type."_".$name;
329     print $fh "# ------ $pattern rules ---------------\n";
330     print $fh $$hashref{'class'}."_".$type."::".$$hashref{'class'}.
331     "_".$type."_$name\n\n";
332    
333 williamc 1.1.2.12 # -- create a new directory rule for each type
334 williamc 1.1.2.11 push @targets, $pattern;
335 williamc 1.1.2.13 my $here="$ENV{LOCALTOP}/$ENV{INTwork}/\$(THISDIR)/".$dirname;
336 williamc 1.1.2.20 my $work=$ENV{INTwork}."/\$(THISDIR)/".$dirname;
337 williamc 1.1.2.11 my $makefile=$here."/BuildFile.mk";
338    
339     # -- create link targets to the directory
340     push @targets, $dirname;
341     print $fh "# -- Link Targets to $type directories\n";
342     print $fh "$dirname: make_$dirname\n";
343     print $fh "\t\@cd $here; \\\n";
344     print $fh "\t\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
345 williamc 1.1.2.20 " workdir=$work ".
346 williamc 1.1.2.11 " -f \$(TOOL_HOME)/basics.mk datestamp \$\@; \n\n";
347    
348     # -- write target to make makefile for each directory
349     print $fh "# -- Build target directories\n";
350     print $fh "make_$dirname:\n";
351 williamc 1.1.2.14 print $fh "\t\@if [ ! -f \"$makefile\" ]; then \\\n";
352 williamc 1.1.2.11 print $fh "\t if [ ! -d \"$here\" ]; then \\\n";
353     print $fh "\t mkdir $here; \\\n";
354     print $fh "\t fi;\\\n";
355 williamc 1.1.2.15 #print $fh "\t echo include ".$self->{currentenv}." > ".
356     print $fh "\t echo include \$(SCRAM_CURRENTENV) > ".
357 williamc 1.1.2.11 "$makefile; \\\n";
358 williamc 1.1.2.15 print $fh "\t echo VPATH+=$ENV{LOCALTOP}/".${THISPATH}.
359 williamc 1.1.2.11 " >> $makefile; \\\n";
360 williamc 1.1.2.18 print $fh "\t echo buildsrcfiles:=".$$hashref{'src'}.
361     " >> $makefile; \\\n";
362 williamc 1.1.2.11 print $fh "\t echo buildname=$name >> $makefile;\\\n";
363     print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n";
364 williamc 1.1.2.15 print $fh "\t echo ifdef DefaultBuildFile >> $makefile; \\\n";
365     print $fh "\t echo include \$(DefaultBuildFile) >> $makefile; \\\n";
366     print $fh "\t echo DefaultBuildFileIn=true >> $makefile; \\\n";
367     print $fh "\t echo endif >> $makefile; \\\n";
368 williamc 1.1.2.11 if ( defined (my @file=$mapper->rulesfile($$hashref{'class'})) ) {
369     foreach $f ( @file ) {
370     print $fh "\t echo -include $f >> $makefile; \\\n";
371     }
372     }
373     print $fh "\tfi\n";
374     print $fh "\n";
375     # print $typefile "$name :\n";
376     # print $typefile "\t\$(_quietbuild_)";
377     # print $typefile $mapper->template($$hashref{'class'},$type)."\n";
378     # print $typefile "\t\$(_quietstamp_)";
379     # print $typefile "$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
380    
381 williamc 1.1.2.15 # -- debug targets
382     print $fh "# -- debug targets\n";
383     print $fh $dirname."_echo_% : make_$dirname\n";
384     print $fh "\t\@cd $here; \n";
385     print $fh "\t\@\$(MAKE) LatestBuildFile=$makefile _BuildLink_=1".
386 williamc 1.1.2.20 " workdir=$work ".
387 williamc 1.1.2.15 " -f \$(TOOL_HOME)/basics.mk ".
388     "echo_\$(subst ".$dirname."_echo_,,\$\@) ; \n\n";
389     push @targets, $dirname."_echo_VAR";
390    
391 williamc 1.1.2.11 # -- cleaning targets
392     push @targets, "clean_$dirname";
393     print $fh "# -- cleaning targets\n";
394     print $fh "clean::clean_$dirname\n";
395     print $fh "clean_".$dirname."::\n";
396     print $fh "\t\@if [ -d $here ]; then \\\n";
397 williamc 1.1.2.17 print $fh "\techo cleaning $dirname; \\\n";
398 williamc 1.1.2.11 print $fh "\tcd $here; \\\n";
399     print $fh "\t\$(MAKE) LatestBuildFile=$makefile workdir=".
400 williamc 1.1.2.20 $work." _BuildLink_=1 -f ".
401 williamc 1.1.2.11 "\$(TOOL_HOME)/basics.mk clean; \\\n";
402     print $fh "\tfi\n\n";
403    
404    
405     }
406 williamc 1.1.2.23 # -- cleanup
407     print $fh "Sdefault_".$$hashref{'class'}.
408     ":=\$(Sorigdefault_".$$hashref{'class'}.")\n";
409 williamc 1.1.2.11 # -- help targets
410     print $fh "helpheader::\n";
411     print $fh "\t\@echo Targets available:\n";
412     print $fh "\t\@echo ------------------\n\n";
413     print $fh "help::helpheader\n";
414     foreach $target ( @targets ) {
415     print $fh "help::\n";
416     print $fh "\t\@echo $target\n"
417     }
418     print $fh "endif\n";
419     } # end else
420     }
421 williamc 1.1.2.21 }
422     }
423    
424     sub _makegenerictargets {
425     my $self=shift;
426     my $fh=shift;
427     my $class=shift;
428     my @deftypes=@_;
429    
430     my @targets=();
431     # -- generate generic targets
432     print $fh "# -- Generic targets\n";
433     push @targets, $class;
434     foreach $dtype ( @deftypes ) {
435     print $fh "Sdefault_".$class."+=".$class."_".$dtype."\n";
436     }
437 williamc 1.1.2.23 #print $fh $class."::\$(Sdefault_".$class.")\n";
438     print $fh "\n\n";
439 williamc 1.1.2.21 return @targets;
440 williamc 1.1.2.11 }
441    
442 williamc 1.1.2.1 sub Bin_start {
443 williamc 1.1 my $self=shift;
444     my $name=shift;
445     my $hashref=shift;
446    
447 williamc 1.1.2.1 my $fileclass;
448     my @tools;
449     my $tool;
450     my $filename;
451     my $objectname;
452 williamc 1.1
453 williamc 1.1.2.1 $self->{switch}->checktag($name,$hashref,'file');
454     if ( $self->{Arch} ) {
455 williamc 1.1.2.18 if ( ! defined $$hashref{name} ) {
456 williamc 1.1.2.1 ($$hashref{name}=$$hashref{file})=~s/\..*//;
457 williamc 1.1.2.18 }
458 williamc 1.1.2.19 ($filename=$$hashref{file})=~s/^\///; # make sure full paths dont work
459 williamc 1.1.2.22 my $arghash={ "class" => "bin",
460     "src" => $filename,
461     "name" => $$hashref{'name'}};
462     if ( exists $$hashref{'default'} ) {
463     $arghash->{'default'}=$$hashref{'default'};
464     }
465     $self->Build_start($name, $arghash);
466 williamc 1.1.2.1 }
467 williamc 1.1 }
468    
469 williamc 1.1.2.1 sub External_StartTag {
470     my $self=shift;
471     my $name=shift;
472     my $hashref=shift;
473    
474     my $tool;
475     if ( $self->{Arch} ) {
476     $self->{switch}->checktag($name,$hashref,'ref');
477    
478     # -- oo toolbox stuff
479     # - get the appropriate tool object
480     $$hashref{'ref'}=~tr[A-Z][a-z];
481     if ( ! exists $$hashref{'version'} ) {
482     $tool=$self->{toolbox}->gettool($$hashref{'ref'});
483     }
484     else {
485     $tool=$self->{toolbox}->gettool($$hashref{'ref'},$$hashref{'version'});
486     }
487     if ( ! defined $tool ) {
488     $self->{switch}->parseerror("Unknown Tool Specified ("
489     .$$hashref{'ref'}.")");
490     }
491    
492     # -- old fashioned GNUmakefile stuff
493     print GNUmakefile $$hashref{'ref'};
494     if ( defined $$hashref{'version'} ) {
495     print GNUmakefile "_V_".$$hashref{'version'};
496     }
497     print GNUmakefile "=true\n";
498    
499     # -- Sub system also specified?
500     if ( exists $$hashref{'use'} ) {
501     # -- look for a buildfile
502     my @paths=$tool->getfeature("INCLUDE");
503     my $file="";
504     my ($path,$testfile);
505     foreach $path ( @paths ) {
506     $testfile=$path."/".$$hashref{'use'}."/BuildFile" ;
507     if ( -f $testfile ) {
508     $file=$testfile;
509     $self->_pushremoteproject($path);
510     }
511     }
512     if ( $file eq "" ) {
513     $self->{switch}->parseerror("Unable to find SubSystem $testfile");
514     }
515     $self->ParseBuildFile_Export($file);
516     $self->_popremoteproject();
517     }
518     }
519     }
520    
521     sub Group_start {
522     my $self=shift;
523     my $name=shift;
524     my $hashref=shift;
525    
526     $self->{switch}->checktag($name, $hashref, 'name');
527     if ( $self->{Arch} ) {
528     print GNUmakefile "GROUP_".$$hashref{'name'};
529     if ( defined $$hashref{'version'} ) {
530     print GNUmakefile "_V_".$$hashref{'version'};
531     }
532     print GNUmakefile "=true\n";
533     }
534     }
535    
536     sub Use_start {
537     my $self=shift;
538     my $name=shift;
539     my $hashref=shift;
540     my $filename;
541     use Utilities::SCRAMUtils;
542    
543     $self->{switch}->checktag($name, $hashref, "name");
544     if ( $self->{Arch} ) {
545 williamc 1.1.2.9 if ( exists $$hashref{'group'} ) {
546     print GNUmakefile "GROUP_".$$hashref{'group'}."=true\n";
547     }
548 williamc 1.1.2.1 if ( ! defined $self->{remoteproject} ) {
549     $filename=SCRAMUtils::checkfile(
550     "/$ENV{INTsrc}/$$hashref{name}/BuildFile");
551     }
552     else {
553     $filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
554     print "trying $filename\n";
555     if ( ! -f $filename ) { $filename=""; };
556     }
557     if ( $filename ne "" ) {
558     $self->ParseBuildFile_Export( $filename );
559     }
560     else {
561     $self->{switch}->parseerror("Unable to detect Appropriate ".
562     "decription file for <$name name=".$$hashref{name}.">");
563     }
564     }
565     }
566    
567     sub CheckBuildFile {
568     my $self=shift;
569     my $classdir=shift;
570     my $ClassName="";
571     my $thisfile="$classdir/$buildfile";
572    
573     if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
574     $DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
575     $self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
576     }
577     elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
578     $DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
579     $self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
580     }
581     return $ClassName;
582     }
583    
584     # List association groups between <AssociateGroup> tags
585     # seperated by newlines or spaces
586     sub AssociateGroup {
587     my $self=shift;
588     my $name=shift;
589     my $string=shift;
590     my $word;
591    
592     foreach $word ( (split /\s/, $string) ){
593     chomp $word;
594     next if /^#/;
595     if ( $word=~/none/ ) {
596     $self->{ignore}=1;
597     }
598     }
599     }
600    
601     sub Arch_Start {
602     my $self=shift;
603 williamc 1.1 my $name=shift;
604     my $hashref=shift;
605    
606 williamc 1.1.2.10 $self->{switch}->checktag($name, $hashref,'name');
607 williamc 1.1.2.1 ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
608     : ($self->{Arch}=0);
609     push @{$self->{ARCHBLOCK}}, $self->{Arch};
610 williamc 1.1 }
611    
612 williamc 1.1.2.1 sub Arch_End {
613 williamc 1.1 my $self=shift;
614     my $name=shift;
615    
616 williamc 1.1.2.1 pop @{$self->{ARCHBLOCK}};
617     $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
618     }
619 williamc 1.1
620 williamc 1.1.2.1 # Split up the Class Block String into a useable array
621     sub _CutBlock {
622     my $self=shift;
623     my $string= shift @_;
624     @BlockClassA = split /\//, $string;
625 williamc 1.1 }
626    
627 williamc 1.1.2.1 sub OutToMakefile {
628     my $self=shift;
629 williamc 1.1 my $name=shift;
630 williamc 1.1.2.1 my @vars=@_;
631 williamc 1.1
632 williamc 1.1.2.1 if ( $self->{Arch} ) {
633     print GNUmakefile @vars;
634 williamc 1.1 }
635 williamc 1.1.2.1 }
636    
637     sub OutToScreen {
638     my $name=shift;
639     my @vars=@_;
640    
641     if ( $self->{Arch} ) {
642     print @vars;
643 williamc 1.1 }
644 williamc 1.1.2.1 }
645     sub setBlockClassPath {
646     my $self=shift;
647     my $name=shift;
648     my $hashref=shift;
649    
650     $self->{switch}->checktag($name, $hashref, 'path');
651     $self->{BlockClassPath}=$self->{BlockClassPath}.":".$$hashref{path};
652     $self->_CutBlock($$hashref{path});
653     }
654 williamc 1.1
655 williamc 1.1.2.1 sub BlockClassPath {
656 williamc 1.1 my $self=shift;
657 williamc 1.1.2.1 return $self->{BlockClassPath};
658     }
659 williamc 1.1
660 williamc 1.1.2.1 sub export_start_export {
661     my $self=shift;
662     my $name=shift;
663     my $hashref=shift;
664    
665     $self->{switch}->opengroup("__export");
666 williamc 1.1 }
667    
668 williamc 1.1.2.1 sub export_start {
669 williamc 1.1 my $self=shift;
670 williamc 1.1.2.1 my $name=shift;
671     my $hashref=shift;
672 williamc 1.1
673 williamc 1.1.2.1 $self->{switch}->opengroup("__export");
674     if ( exists $$hashref{autoexport} ) {
675     print GNUmakefile "scram_autoexport=".$$hashref{autoexport}."\n";
676     if ( $$hashref{autoexport}=~/true/ ) {
677     $self->{switch}->allowgroup("__export","makebuild");
678     }
679     else {
680     $self->{switch}->disallowgroup("__export","makebuild");
681     }
682     }
683     # -- allow default setting from other makefiles
684     print GNUmakefile "ifeq (\$(scram_autoexport),true)\n";
685     }
686    
687     sub export_end_export {
688     my $self=shift;
689     $self->{switch}->closegroup("__export");
690     }
691    
692     sub export_end {
693     my $self=shift;
694     $self->{switch}->closegroup("__export");
695     print GNUmakefile "endif\n";
696 williamc 1.1 }
697    
698 williamc 1.1.2.1 #
699     # Standard lib tag
700     #
701 williamc 1.1 sub lib_start {
702     my $self=shift;
703     my $name=shift;
704     my $hashref=shift;
705 williamc 1.1.2.1
706     $self->{switch}->checktag($name, $hashref, 'name');
707     if ( $self->{Arch} ) {
708     print GNUmakefile "lib+=$$hashref{name}\n";
709     }
710 williamc 1.1 }
711    
712 williamc 1.1.2.1 #
713     # libtype specification
714     #
715     sub LibType_Start {
716 williamc 1.1 my $self=shift;
717     my $name=shift;
718     my $hashref=shift;
719 williamc 1.1.2.1
720     if ( $self->{Arch} ) {
721 williamc 1.1.2.3 if ( defined $self->{libtype_conext} ) {
722     $self->{switch}->parseerror("<$name> tag cannot be specified".
723     " without a </$name> tag to close previous context");
724     }
725     else {
726     $self->{libtype_conext}=1;
727 williamc 1.1.2.1 $self->{switch}->checktag($name, $hashref, 'type');
728    
729 williamc 1.1.2.24 my $string=$$hashref{'type'};
730     # -- do some translation for backwards compatability
731     if ($$hashref{'type'}=~/debug_archive/i ) {
732     $string="archive_debug";
733 williamc 1.1.2.1 }
734     elsif ($$hashref{'type'}=~/debug_shared/i ) {
735 williamc 1.1.2.24 $string="shared_debug";
736 williamc 1.1.2.1 }
737 williamc 1.1.2.24 # -- call the Build defaults method
738     $self->Build_start($name, {"class" => "lib", "default" => $string });
739 williamc 1.1.2.1 }
740 williamc 1.1.2.3 }
741 williamc 1.1.2.1 }
742 williamc 1.1.2.3
743 williamc 1.1.2.1 sub LibType_text {
744     my $self=shift;
745     my $name=shift;
746     my $string=shift;
747    
748     if ( $self->{Arch} ) {
749 williamc 1.1.2.2 $string=~s/\n/ /g;
750 williamc 1.1.2.1 print GNUmakefile "libmsg::\n\t\@echo Library info: ";
751     print GNUmakefile $string;
752     print GNUmakefile "\n";
753     }
754 williamc 1.1.2.3 }
755    
756     sub LibType_end {
757     my $self=shift;
758     my $name=shift;
759    
760     undef $self->{libtype_conext};
761 williamc 1.1.2.1 }
762    
763     sub Environment_start {
764     my $self=shift;
765     my $name=shift;
766     my $hashref=shift;
767    
768     if ( $self->{Arch} ) {
769     $self->{envnum}++;
770    
771     # open a new Environment File
772     my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
773     $self->{envnum}.".mk";
774     use FileHandle;
775     my $fh=FileHandle->new();
776     open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
777     push @{$self->{filehandlestack}}, $fh;
778     *GNUmakefile=$fh;
779    
780     # include the approprate environment file
781     if ( $self->{envlevel} == 0 ) {
782     print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
783     $self->{path}."/BuildFile.mk\n";
784     }
785     else {
786     print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
787     $self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
788     }
789     $self->{envlevel}++;
790     $self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
791 williamc 1.1.2.11 $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
792 williamc 1.1.2.1 }
793 williamc 1.1.2.15 $ENV{SCRAM_CURRENTENV}=$self->{currentenv};
794 williamc 1.1.2.1 }
795    
796     sub Environment_end {
797     my $self=shift;
798     my $fd;
799    
800     if ( $self->{Arch} ) {
801     $self->{envlevel}--;
802     if ( $self->{envlevel} < 0 ) {
803     print "Too many </Environent> Tags on $self->{switch}->line()\n";
804     exit 1;
805     }
806     close GNUmakefile;
807     # restore the last filehandle
808     $fd=pop @{$self->{filehandlestack}};
809     close $fd;
810     *GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
811     if ( $self->{envlevel} < 1 ) {
812 williamc 1.1.2.11 $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
813     "BuildFile.mk";
814 williamc 1.1.2.1 }
815     else {
816 williamc 1.1.2.11 $self->{currentenv}=
817 williamc 1.1.2.1 "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
818     $self->{Envlevels}[$self->{envlevel}];
819     }
820 williamc 1.1.2.15 $ENV{SCRAM_CURRENTENV}=$self->{currentenv};
821 williamc 1.1.2.1 }
822 williamc 1.1 }