ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildFile.pm
Revision: 1.1.2.23
Committed: Thu Jun 15 14:31:01 2000 UTC (24 years, 11 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.22: +11 -3 lines
Log Message:
Allow limited default overrides

File Contents

# Content
1 # BuildFile
2 #
3 # Interface
4 # ---------
5 # 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 # CheckBuildFile(dir) : return the BuildFile if it exists
11
12 package BuildSystem::BuildFile;
13 use ActiveDoc::SimpleDoc;
14 use BuildSystem::ToolBox;
15 require 5.004;
16
17 BEGIN {
18 $buildfile="BuildFile";
19 }
20
21 sub new {
22 my $class=shift;
23 my $self={};
24 bless $self, $class;
25 $self->{toolbox}=shift;
26 $self->{Arch}=1;
27 push @{$self->{ARCHBLOCK}}, $self->{Arch};
28 return $self;
29 }
30
31 sub ignore {
32 my $self=shift;
33 return (defined $self->{ignore})?$self->{ignore}:0;
34 }
35
36 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 $switch->addtag($parse,"Build", \&Build_start, $self);
44 $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 \&LibType_end,$self);
56 $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
79 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 \&OutToMakefile, $self,
99 "", $self);
100 $switch->addtag($parse,"Architecture",
101 \&Arch_Start,$self,
102 \&OutToMakefile, $self,
103 \&Arch_End,$self);
104 $switch->addtag($parse,"INCLUDE_PATH",
105 \&IncludePath_Start,$self,
106 \&OutToMakefile, $self,
107 "",$self);
108 return $switch;
109 }
110
111 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 sub ParseBuildFile {
136 my $self=shift;
137 my $base=shift;
138 my $path=shift;
139 my $filename=shift @_;
140 my $fullfilename;
141 if ( $filename!~/^\// ) {
142 $fullfilename="$base/$path/$filename";
143 }
144 else {
145 $fullfilename=$filename;
146 }
147 $self->{path}=$path;
148 #print "Processing $fullfilename\n";
149 $numbins=0;
150 $self->{envnum}=0;
151 $self->{envlevel}=0;
152 $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
153 "BuildFile.mk";
154 $ENV{SCRAM_CURRENTENV}=$self->{currentenv};
155
156 # open a temporary gnumakefile to store output.
157 use Utilities::AddDir;
158 AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}");
159 $self->GenerateMakefile($fullfilename,
160 $ENV{LOCALTOP}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk");
161 }
162
163 sub ParseBuildFile_Export {
164 my $self=shift;
165 my $filename=shift;
166 my $bf=BuildSystem::BuildFile->new($self->{toolbox});
167 if ( defined $self->{remoteproject} ) {
168 $bf->{remoteproject}=$self->{remoteproject};
169 }
170 $bf->_parseexport($filename);
171 undef $bf;
172 }
173
174 sub _location {
175 my $self=shift;
176 use File::Basename;
177
178 return dirname($self->{switch}->filetoparse());
179 }
180
181 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
204 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 }
219
220 sub _toolmapper {
221 my $self=shift;
222 if ( ! defined $self->{mapper} ) {
223 require BuildSystem::ToolMapper;
224 $self->{mapper}=BuildSystem::ToolMapper->new();
225 }
226 if ( @_ ) { #if a class is supplied then supply the map directly
227 my $class=shift;
228 return $self->{mapper}->getmap($class);
229 }
230 return $self->{mapper};
231 }
232
233
234 # ---- Tag routines
235
236 # -- 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
239 sub Class_StartTag {
240 my $self=shift;
241 my $name=shift;
242 my $hashref=shift;
243
244 if ( $self->{Arch} ) {
245 if ( defined $$hashref{'type'} ) {
246 $ClassName=$$hashref{'type'};
247 }
248 }
249 }
250
251 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 #
264 # generic build tag
265 #
266 sub Build_start {
267 my $self=shift;
268 my $name=shift;
269 my $hashref=shift;
270
271
272 $self->{switch}->checktag($name,$hashref,'class');
273 if ( $self->{Arch} ) {
274 my $fh=$self->{filehandlestack}[0];
275 # -- get the mapper object
276 my $mapper=$self->_toolmapper($$hashref{'class'});
277 if ( ! defined $mapper ) {
278 $self->{switch}->parseerror("Unknown class : ".$$hashref{'class'});
279 }
280 else {
281 # -- get default types
282 my @deftypes;
283 if ( ! exists $$hashref{'default'} ) {
284 @deftypes=$mapper->defaulttypes();
285 }
286 else {
287 @deftypes=split /,/, $$hashref{'default'};
288 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 }
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
307
308 my @targets=();
309
310 # -- generate generic targets
311 print $fh "ifndef _BuildLink_\n";
312 push @targets, ($self->_makegenerictargets($fh,$$hashref{'class'},
313 @deftypes));
314 print $fh $$hashref{'class'}."::\$(Sdefault_".$$hashref{'class'}
315 .")\n";
316 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 push @targets, $$hashref{'class'}."_".$$hashref{'name'};
322
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 # -- create a new directory rule for each type
334 push @targets, $pattern;
335 my $here="$ENV{LOCALTOP}/$ENV{INTwork}/\$(THISDIR)/".$dirname;
336 my $work=$ENV{INTwork}."/\$(THISDIR)/".$dirname;
337 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 " workdir=$work ".
346 " -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 print $fh "\t\@if [ ! -f \"$makefile\" ]; then \\\n";
352 print $fh "\t if [ ! -d \"$here\" ]; then \\\n";
353 print $fh "\t mkdir $here; \\\n";
354 print $fh "\t fi;\\\n";
355 #print $fh "\t echo include ".$self->{currentenv}." > ".
356 print $fh "\t echo include \$(SCRAM_CURRENTENV) > ".
357 "$makefile; \\\n";
358 print $fh "\t echo VPATH+=$ENV{LOCALTOP}/".${THISPATH}.
359 " >> $makefile; \\\n";
360 print $fh "\t echo buildsrcfiles:=".$$hashref{'src'}.
361 " >> $makefile; \\\n";
362 print $fh "\t echo buildname=$name >> $makefile;\\\n";
363 print $fh "\t echo ".$dirname.":".$pattern." >> $makefile;\\\n";
364 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 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 # -- 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 " workdir=$work ".
387 " -f \$(TOOL_HOME)/basics.mk ".
388 "echo_\$(subst ".$dirname."_echo_,,\$\@) ; \n\n";
389 push @targets, $dirname."_echo_VAR";
390
391 # -- 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 print $fh "\techo cleaning $dirname; \\\n";
398 print $fh "\tcd $here; \\\n";
399 print $fh "\t\$(MAKE) LatestBuildFile=$makefile workdir=".
400 $work." _BuildLink_=1 -f ".
401 "\$(TOOL_HOME)/basics.mk clean; \\\n";
402 print $fh "\tfi\n\n";
403
404
405 }
406 # -- cleanup
407 print $fh "Sdefault_".$$hashref{'class'}.
408 ":=\$(Sorigdefault_".$$hashref{'class'}.")\n";
409 # -- 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 }
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 #print $fh $class."::\$(Sdefault_".$class.")\n";
438 print $fh "\n\n";
439 return @targets;
440 }
441
442 sub Bin_start {
443 my $self=shift;
444 my $name=shift;
445 my $hashref=shift;
446
447 my $fileclass;
448 my @tools;
449 my $tool;
450 my $filename;
451 my $objectname;
452
453 $self->{switch}->checktag($name,$hashref,'file');
454 if ( $self->{Arch} ) {
455 if ( ! defined $$hashref{name} ) {
456 ($$hashref{name}=$$hashref{file})=~s/\..*//;
457 }
458 ($filename=$$hashref{file})=~s/^\///; # make sure full paths dont work
459 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 }
467 }
468
469 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 if ( exists $$hashref{'group'} ) {
546 print GNUmakefile "GROUP_".$$hashref{'group'}."=true\n";
547 }
548 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 my $name=shift;
604 my $hashref=shift;
605
606 $self->{switch}->checktag($name, $hashref,'name');
607 ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
608 : ($self->{Arch}=0);
609 push @{$self->{ARCHBLOCK}}, $self->{Arch};
610 }
611
612 sub Arch_End {
613 my $self=shift;
614 my $name=shift;
615
616 pop @{$self->{ARCHBLOCK}};
617 $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
618 }
619
620 # 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 }
626
627 sub OutToMakefile {
628 my $self=shift;
629 my $name=shift;
630 my @vars=@_;
631
632 if ( $self->{Arch} ) {
633 print GNUmakefile @vars;
634 }
635 }
636
637 sub OutToScreen {
638 my $name=shift;
639 my @vars=@_;
640
641 if ( $self->{Arch} ) {
642 print @vars;
643 }
644 }
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
655 sub BlockClassPath {
656 my $self=shift;
657 return $self->{BlockClassPath};
658 }
659
660 sub export_start_export {
661 my $self=shift;
662 my $name=shift;
663 my $hashref=shift;
664
665 $self->{switch}->opengroup("__export");
666 }
667
668 sub export_start {
669 my $self=shift;
670 my $name=shift;
671 my $hashref=shift;
672
673 $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 }
697
698 #
699 # Standard lib tag
700 #
701 sub lib_start {
702 my $self=shift;
703 my $name=shift;
704 my $hashref=shift;
705
706 $self->{switch}->checktag($name, $hashref, 'name');
707 if ( $self->{Arch} ) {
708 print GNUmakefile "lib+=$$hashref{name}\n";
709 }
710 }
711
712 #
713 # libtype specification
714 #
715 sub LibType_Start {
716 my $self=shift;
717 my $name=shift;
718 my $hashref=shift;
719
720 if ( $self->{Arch} ) {
721 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 $self->{switch}->checktag($name, $hashref, 'type');
728
729 print GNUmakefile "# Specify Library Type\n";
730 print GNUmakefile "DefaultLibsOff=yes\n";
731 if ( $$hashref{'type'}=~/^archive/i ) {
732 print GNUmakefile "LibArchive=true\n";
733 }
734 elsif ($$hashref{'type'}=~/debug_archive/i ) {
735 print GNUmakefile "LibDebugArchive=true\n";
736 }
737 elsif ($$hashref{'type'}=~/debug_shared/i ) {
738 print GNUmakefile "LibDebugShared=true\n";
739 }
740 elsif ($$hashref{'type'}=~/shared/i ) {
741 print GNUmakefile 'LibShared=true'."\n";
742 }
743 print GNUmakefile "\n";
744 }
745 }
746 }
747
748 sub LibType_text {
749 my $self=shift;
750 my $name=shift;
751 my $string=shift;
752
753 if ( $self->{Arch} ) {
754 $string=~s/\n/ /g;
755 print GNUmakefile "libmsg::\n\t\@echo Library info: ";
756 print GNUmakefile $string;
757 print GNUmakefile "\n";
758 }
759 }
760
761 sub LibType_end {
762 my $self=shift;
763 my $name=shift;
764
765 undef $self->{libtype_conext};
766 }
767
768 sub Environment_start {
769 my $self=shift;
770 my $name=shift;
771 my $hashref=shift;
772
773 if ( $self->{Arch} ) {
774 $self->{envnum}++;
775
776 # open a new Environment File
777 my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
778 $self->{envnum}.".mk";
779 use FileHandle;
780 my $fh=FileHandle->new();
781 open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
782 push @{$self->{filehandlestack}}, $fh;
783 *GNUmakefile=$fh;
784
785 # include the approprate environment file
786 if ( $self->{envlevel} == 0 ) {
787 print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
788 $self->{path}."/BuildFile.mk\n";
789 }
790 else {
791 print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
792 $self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
793 }
794 $self->{envlevel}++;
795 $self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
796 $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
797 }
798 $ENV{SCRAM_CURRENTENV}=$self->{currentenv};
799 }
800
801 sub Environment_end {
802 my $self=shift;
803 my $fd;
804
805 if ( $self->{Arch} ) {
806 $self->{envlevel}--;
807 if ( $self->{envlevel} < 0 ) {
808 print "Too many </Environent> Tags on $self->{switch}->line()\n";
809 exit 1;
810 }
811 close GNUmakefile;
812 # restore the last filehandle
813 $fd=pop @{$self->{filehandlestack}};
814 close $fd;
815 *GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
816 if ( $self->{envlevel} < 1 ) {
817 $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
818 "BuildFile.mk";
819 }
820 else {
821 $self->{currentenv}=
822 "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
823 $self->{Envlevels}[$self->{envlevel}];
824 }
825 $ENV{SCRAM_CURRENTENV}=$self->{currentenv};
826 }
827 }