ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildFile.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildFile.pm (file contents):
Revision 1.4 by williamc, Wed Mar 3 17:04:13 1999 UTC vs.
Revision 1.21.2.23 by williamc, Wed Oct 13 14:12:07 1999 UTC

# Line 8 | Line 8 | BEGIN {
8   use ToolBox;
9   $buildfile="BuildFile";
10   $toolbox=ToolBox->new();
11 + $Arch=1;
12 + push @ARCHBLOCK, $Arch;
13   }
14  
15   #Parse the BuildFile
16   sub ParseBuildFile {
17          my $base=shift;
18 <        my $path=shift;
18 >        $path=shift;
19          my $filename=shift @_;
20          my $fullfilename="$base/$path/$filename";
21          #print "Processing $fullfilename\n";
22          # This hash defines which Document Elements we can use
23 +        $numbins=0;
24 +        $envnum=0;
25 +        $envlevel=0;
26 +        $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
27          my $SupportedTags={
28                  'Use' => \&OutToMakefile,
29                  'Use_StartTag' => \&Use_start,
# Line 29 | Line 35 | sub ParseBuildFile {
35                  'ConfigurationClass' => \&OutToMakefile,
36                  'AssociateGroup' => \&AssociateGroup,
37                  'none' => \&OutToMakefile,
38 <                'Bin' => \&OutToMakefile,
38 >                'Bin' => 'none',
39                  'Bin_StartTag' => \&Bin_start,
40                  'ClassPath' => \&OutToMakefile,
41 <                'ClassPath_StartTag' => \&setBlockClassPath
41 >                'ClassPath_StartTag' => \&setBlockClassPath,
42 >                'Environment' => \&OutToMakefile,
43 >                'Environment_StartTag' => \&Environment_start,
44 >                'Environment_EndTag' => \&Environment_end,
45 >                'lib' => 'none',
46 >                'lib_StartTag' => \&lib_start,
47 >                'lib_EndTag' => 'none',
48 >                'ignore' => 'none',
49 >                'ignore_EndTag' => \&ignoretag_end,
50 >                'ignore_StartTag' => \&ignoretag,
51 >                'Architecture_StartTag' => \&Arch_Start,
52 >                'Architecture_EndTag' => \&Arch_End,
53 >                'Architecture' => \&OutToMakefile,
54 >                'LibType_StartTag' => \&LibType_Start,
55 >                'LibType_EndTag' => 'none',
56 >                #'LibType' => \&OutToScreen
57 >                'LibType' => \&LibType_text
58          };
59          use Utilities::Switcher;
60          $switch=Switcher->new($SupportedTags, $fullfilename);
# Line 40 | Line 62 | sub ParseBuildFile {
62          #open a temporary gnumakefile to store output.
63          use Utilities::AddDir;
64          AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}");
65 <        open ( GNUmakefile, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk") or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n';
65 >        my $fh=FileHandle->new();
66 >        open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk"
67 >          ) or die 'Unable to open /$ENV{INTwork}/${path}/BuildFile.mk $!\n';
68 >        @filehandlestack=($fh);
69 >        # make an alias
70 > #       open ( GNUmakefile, ">&=$fh") or die 'Unable to create alias for '.
71 > #                       "Filehandle $!\n";
72 >        *GNUmakefile=$fh;
73          if ( -e $ENV{LatestBuildFile} ) {
74            print GNUmakefile "include $ENV{LatestBuildFile}\n";
75          }
# Line 51 | Line 80 | sub ParseBuildFile {
80          close GNUmakefile;
81   }
82  
83 + sub ParseBuildFile_Export {
84 +        my $filename=shift;
85 +        use Tool;
86 +        # This hash defines which Document Elements we can use
87 +        my $SupportedTags={
88 +                'none' => 'none',
89 +                'export' => \&OutToMakefile,
90 +                'export_StartTag' => \&export_start,
91 +                'export_EndTag' => \&export_end,
92 +                'lib_StartTag' => \&lib_start_export,
93 +                'External_StartTag' => \&Ext_start_export,
94 +                'lib' => 'none'
95 +        };
96 +        use Utilities::Switcher;
97 +        $switchex=Switcher->new($SupportedTags, $filename);
98 +        $switchex->{Strict_no_cr}='no';
99 +        $switchex->parse(); # sort out supported tags
100 + }
101 +
102   sub initialterms() {
103          my $name=shift;
104          my @string=@_;
# Line 80 | Line 128 | sub Class_StartTag {
128          my @vars=@_;
129          
130          $hashref=$switch->SetupValueHash(\@vars);
131 +        if ( $Arch ) {
132          if ( defined $$hashref{'type'} ) {
133                  $ClassName=$$hashref{'type'};
134          }
135 +        }
136   }
137  
138   sub ClassPath_StartTag {
# Line 91 | Line 141 | sub ClassPath_StartTag {
141          my $hashref;
142  
143          $hashref=$switch->SetupValueHash(\@vars);
144 +        if ( $Arch ) {
145          if ( defined $$hashref{'defaultpath'} ) {
146          }
147 +        }
148   }
149  
150   sub Bin_start {
# Line 102 | Line 154 | sub Bin_start {
154          my $fileclass;
155          my @tools;
156          my $tool;
157 +        my $filename;
158 +        my $objectname;
159          
160          $hashref=$switch->SetupValueHash(\@vars);
161          $switch->checkparam($hashref, $name, 'file');
162 +        if ( $Arch ) {
163          if ( ! defined $$hashref{name} ) {
164                  ($$hashref{name}=$$hashref{file})=~s/\..*//;
165          }
166          # This stuff for later
167          #$fileclass=$toolbox->getclass($file);
168          #$toolbox->maketargets("exe",$fileclass, $$hashref{name}, $file );
169 <        print GNUmakefile "bin::$$hashref{name}\n";
170 <        print GNUmakefile "$$hashref{name}::$$hashref{file}\n";
169 >
170 >        ($filename=$$hashref{file})=~s/\..*//;
171 >
172 >        # Create a new directory for each binary target
173 >        my $dirname="bin_".$$hashref{name};
174 >        AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname");
175 >        open (binGNUmakefile,
176 >           ">$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk") or die           "Unable to make $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/".
177 >           "BuildFile.mk $!\n";
178 >
179 >        # Create the link targets
180 >        $numbins++;
181 >        my $fh=$filehandlestack[0];
182 >        print $fh <<ENDTEXT;
183 >
184 > # Link Targets to binary directories
185 > ifndef BINMODE
186 >
187 > define stepdown_$$hashref{'name'}
188 > if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname" ]; then \\
189 > echo - Invoking binary makefile \$\@ for $dirname; \\
190 > cd $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname; \\
191 > \$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk \$\@; \\
192 > fi
193 > echo - Finished binary makefile \$\@
194 > endef
195 >
196 > define stepdown2_$$hashref{'name'}
197 > if [ -d "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname" ]; then \\
198 > echo - Invoking binary makefile \$\@ for $dirname; \\
199 > cd $ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname; \\
200 > \$(MAKE) BINMODE=true LatestBuildFile=$ENV{LOCALTOP}/$ENV{INTwork}/${path}/$dirname/BuildFile.mk workdir=\$(workdir)/$dirname -f \$(TOOL_HOME)/basics.mk \$\*; \\
201 > fi
202 > echo - Finished binary makefile \$\@
203 > endef
204 >
205 > bin_$$hashref{'name'}_%:: dummy
206 >        \@\$(stepdown2_$$hashref{'name'})
207 >
208 > echo_%:: dummy
209 >        \@\$(stepdown_$$hashref{'name'})
210 >
211 > bin bin_debug bin_debug_local bin_insure bin_Insure clean $$hashref{'name'}:: dummy
212 >        \@\$(stepdown_$$hashref{'name'})
213 > endif
214 >
215 > ENDTEXT
216 >
217 >
218 > # the binary specifics makefile
219 >        print binGNUmakefile "include $currentenv\n";
220 >        print binGNUmakefile "VPATH+=$ENV{LOCALTOP}/${path}\n";
221 >
222 > # alias for bin_Insure
223 >        print binGNUmakefile <<ENDTEXT;
224 >
225 > bin_insure:bin_Insure
226 > ifdef MAKETARGET_bin_insure
227 > MAKETARGET_$$hashref{name}_Insure=1
228 > endif
229 >
230 > # debuggging target
231 > $$hashref{'name'}_echo_% :: echo_%
232 >
233 > ENDTEXT
234 >
235 > # Make generic rules for each type
236 >        $targettypes={
237 >                "bin" => 'o',
238 >                "bin_debug" => 'd',
239 >                "bin_debug_local" => 'l_d',
240 >                "bin_Insure" => 'Insure'
241 >        };
242 >        #
243 >        foreach $target ( keys %$targettypes ) {
244 >          print binGNUmakefile <<ENDTEXT;
245 >
246 > # Type $target specifics
247 > ifdef MAKETARGET_$target
248 > MAKETARGET_$$hashref{name}_$$targettypes{$target}=1
249 > endif
250 > $target ::$$hashref{name}_$$targettypes{$target}
251 >
252 > bintargets+=$$hashref{name}_$$targettypes{$target}
253 > clean::
254 > \t\@if [ -f \$(binarystore)/$$hashref{name}_$$targettypes{$target} ]; then \\
255 > \techo Removing \$(binarystore)/$$hashref{name}; \\
256 > \trm \$(binarystore)/$$hashref{name}_$$targettypes{$target}; \\
257 > \tfi
258 >
259 > ENDTEXT
260 >          ($objectname=$$hashref{file})=~s/\..*/_$$targettypes{$target}\.o/;
261 >          ${"objectname_$$targettypes{$target}"}=$objectname;
262 >          print binGNUmakefile "$objectname:$$hashref{name}.dep\n";
263 >        } # end loop
264 >
265 >        print binGNUmakefile "$$hashref{name}_Insure:.psrc\n";
266 >        print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
267 >        print binGNUmakefile "\t\$(CClinkCmdDebug)\n";
268 >        print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n";
269 >        print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n";
270 >        print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
271 >        print binGNUmakefile "\t\$(CClinkCmdInsure)\n";
272 >        print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n";
273 >        print binGNUmakefile "\t\$(CClinkCmd)\n";
274 >        print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
275 >        print binGNUmakefile "-include $$hashref{name}.dep\n";
276 > print binGNUmakefile <<ENDTEXT;
277 > clean::
278 > \t\@if [ -f \$(binarystore)/$$hashref{name} ]; then \\
279 > \techo Removing \$(binarystore)/$$hashref{name}; \\
280 > \trm \$(binarystore)/$$hashref{name}; \\
281 > \tfi
282 >
283 > $$hashref{name}_d.exe:\$(libslocal_d)
284 > $$hashref{name}_o.exe:\$(libslocal)
285 > ifdef MCCABE_DATA_DIR
286 > $$hashref{name}_mccabe.exe: \$(libslocal_d) \$(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp
287 > endif
288 > $$hashref{name}_Insure.exe:\$(libslocal_I)
289 > $$hashref{name}_d:$$hashref{name}_d.exe
290 >        \@cp $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
291 > $$hashref{name}_l_d:$$hashref{name}_l_d.exe
292 >        \@cp $$hashref{name}_l_d.exe \$(binarystore)/$$hashref{name}
293 > $$hashref{name}_Insure:$$hashref{name}_Insure.exe
294 >        \@cp $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure
295 > $$hashref{name}:$$hashref{name}_d.exe
296 >        \@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
297 > $$hashref{name}_o:$$hashref{name}_o.exe
298 >        \@mv $$hashref{name}_o.exe \$(binarystore)/$$hashref{name}
299 > binfiles+=$$hashref{file}
300 > ENDTEXT
301 >        }
302 >        close binGNUmakefile;
303 > }
304 >
305 > sub Ext_start_export {
306 >        my $name=shift;
307 >        my @vars=@_;
308 >        my $hashref;
309 >        
310 >        $hashref=$switch->SetupValueHash(\@vars);
311 >        if ( $Arch ) {
312 >         if ( $switchex->context('export') ) {
313 >          $$hashref{'ref'}=~tr[A-Z][a-z];
314 >          print GNUmakefile $$hashref{'ref'};
315 >          if ( defined $$hashref{'version'} ) {
316 >                print GNUmakefile "_V_".$$hashref{'version'};
317 >          }
318 >          print GNUmakefile "=true\n";
319 >         }
320 >        }
321   }
322  
323   sub External_StartTag {
# Line 121 | Line 326 | sub External_StartTag {
326          my $hashref;
327          
328          $hashref=$switch->SetupValueHash(\@vars);
329 +        if ( $Arch ) {
330 +        $$hashref{'ref'}=~tr[A-Z][a-z];
331          print GNUmakefile $$hashref{'ref'};
332          if ( defined $$hashref{'version'} ) {
333                  print GNUmakefile "_V_".$$hashref{'version'};
334          }
335          print GNUmakefile "=true\n";
336 +        }
337          
338   }      
339  
# Line 136 | Line 344 | sub Group_start {
344          
345          $hashref=$switch->SetupValueHash(\@vars);
346          $switch->checkparam($hashref, $name, 'name');
347 +        if ( $Arch ) {
348          print GNUmakefile "GROUP_".$$hashref{'name'};
349          if ( defined $$hashref{'version'} ) {
350                  print GNUmakefile "_V_".$$hashref{'version'};
351          }
352          print GNUmakefile "=true\n";
353 +        }
354   }      
355  
356   sub External {
# Line 167 | Line 377 | sub Use_start {
377          
378          $hashref=$switch->SetupValueHash(\@vars);
379          $switch->checkparam($hashref, $name, "name");
380 <        if ( $filename=checkfile("$ENV{INTsrc}/$$hashref{name}/BuildFile")
381 <                                                 ne "" ) {
382 <          print GNUmakefile "ReqDependencies += $filename\n";
380 >        if ( $Arch ) {
381 >        $filename=SCRAMUtils::checkfile(
382 >                "$ENV{INTsrc}/$$hashref{name}/BuildFile");
383 >        if ( $filename ne "" ) {
384 >          ParseBuildFile_Export( $filename );
385 >        }
386          }
174        print GNUmakefile "local__$$hashref{name}=true\n";
387   }
388  
389 < sub CheckBuildFile($directory) {
389 > sub CheckBuildFile {
390           my $classdir=shift;
391           $ClassName="";
392           $thisfile="$classdir/$buildfile";
# Line 204 | Line 416 | sub AssociateGroup {
416          }
417   }
418  
419 + sub ignoretag {
420 +        my $name=shift;
421 +        my @vars=@_;
422 +        
423 +        $Arch=0;
424 +        push @ARCHBLOCK, $Arch;
425 + }
426 +
427 + sub ignoretag_end {
428 +        my $name=shift;
429 +        my @vars=@_;
430 +        
431 +        pop @ARCHBLOCK;
432 +        $Arch=$ARCHBLOCK[$#ARCHBLOCK];
433 + }
434 +
435 + sub Arch_Start {
436 +        my $name=shift;
437 +        my @vars=@_;
438 +        my $hashref;
439 +
440 +        $hashref=$toolswitch->SetupValueHash( \@vars );
441 +        $toolswitch->checkparam($hashref, $name, 'name');
442 +        #( ($$hashref{name}=~/$ENV{SCRAM_ARCH}/) )?$Arch=1:$Arch=0;
443 +        ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($Arch=1) : ($Arch=0);
444 +        push @ARCHBLOCK, $Arch;
445 + }
446 + sub Arch_End {
447 +        my $name=shift;
448 +        my @vars=@_;
449 +
450 +        pop @ARCHBLOCK;
451 +        $Arch=$ARCHBLOCK[$#ARCHBLOCK];
452 + }
453 +
454   # Split up the Class Block String into a useable array
455 < sub _CutBlock($string) {
455 > sub _CutBlock {
456      my $string= shift @_;
457      @BlockClassA = split /\//, $string;
458   }
# Line 214 | Line 461 | sub OutToMakefile {
461          my $name=shift;
462          my @vars=@_;
463  
464 <        print GNUmakefile @vars;
464 >        if ( $Arch ) {
465 >          print GNUmakefile @vars;
466 >        }
467 > }
468 > sub OutToScreen {
469 >        my $name=shift;
470 >        my @vars=@_;
471 >
472 >        if ( $Arch ) {
473 >          print @vars;
474 >        }
475   }
476   sub setBlockClassPath {
477          my $name=shift;
# Line 226 | Line 483 | sub setBlockClassPath {
483          $BlockClassPath=$BlockClassPath.":".$$hashref{path};
484          _CutBlock($$hashref{path});
485   }
486 +
487 + sub export_start {
488 + #Set up a toolfile object
489 +        $exporttool=Tool->new();
490 + }
491 +
492 + sub export_end {
493 + #Write toolfile object to disk
494 +        $exporttool->envtomake(\*GNUmakefile);
495 + }
496 +
497 + #
498 + # Export Mode Lib Tag
499 + #
500 + sub lib_start_export {
501 +        my $name=shift;
502 +        my @vars=@_;
503 +        my $hashref;
504 +
505 +        $hashref=$switchex->SetupValueHash( \@vars );
506 +        $switchex->checkparam($hashref, $name, 'name');
507 +        if ( $Arch ) {
508 +         if ( $switchex->context('export') ) {
509 +                #If export mode then add this env to the export tool
510 +                $exporttool->addenv('lib',$$hashref{name});
511 +         }
512 +        }
513 + }
514 +
515 + #
516 + # Standard lib tag
517 + #
518 + sub lib_start {
519 +        my $name=shift;
520 +        my @vars=@_;
521 +        my $hashref;
522 +
523 +        $hashref=$switch->SetupValueHash( \@vars );
524 +        $switch->checkparam($hashref, $name, 'name');
525 +        if ( $Arch ) {
526 +           print GNUmakefile "lib+=$$hashref{name}\n";
527 +        }
528 + }
529 +
530 + #
531 + # libtype specification
532 + #
533 + sub LibType_Start {
534 +        my $name=shift;
535 +        my @vars=@_;
536 +        my $hashref;
537 +
538 +        if ( $Arch ) {
539 +        $hashref=$switch->SetupValueHash( \@vars );
540 +        $switch->checkparam($hashref, $name, 'type');
541 +        
542 +        print GNUmakefile "# Specify Library Type\n";
543 +        print GNUmakefile "DefaultLibsOff=yes\n";
544 +        if ( $$hashref{'type'}=~/^archive/i ) {
545 +          print GNUmakefile "LibArchive=true\n";
546 +        }
547 +        elsif ($$hashref{'type'}=~/debug_archive/i ) {
548 +          print GNUmakefile "LibDebugArchive=true\n";
549 +        }
550 +        elsif ($$hashref{'type'}=~/debug_shared/i ) {
551 +          print GNUmakefile "LibDebugShared=true\n";
552 +        }
553 +        elsif ($$hashref{'type'}=~/shared/i ) {
554 +          print GNUmakefile 'LibShared=true'."\n";
555 +        }
556 +        print GNUmakefile "\n";
557 +        }
558 + }
559 + sub LibType_text {
560 +        my $name=shift;
561 +        my @vars=@_;
562 +
563 +        if ( $Arch ) {
564 +          print GNUmakefile "libmsg::\n\t\@echo Library info: ";
565 +          print GNUmakefile @vars;
566 +          print GNUmakefile "\n";
567 +        }
568 + }
569 +
570 + sub Environment_start {
571 +        my $name=shift;
572 +        my @vars=@_;
573 +        my $hashref;
574 +
575 +        if ( $Arch ) {
576 +          $envnum++;
577 +
578 +          # open a new Environment File
579 +          my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk";
580 +          use FileHandle;
581 +          my $fh=FileHandle->new();
582 +          open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
583 +          push @filehandlestack, $fh;
584 +          *GNUmakefile=$fh;
585 +
586 +          # include the approprate environment file
587 +          if ( $envlevel == 0 ) {
588 +             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
589 +                                "BuildFile.mk\n";
590 +          }
591 +          else {
592 +             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
593 +                                "Env_$Envlevels[$envlevel]\.mk\n";
594 +          }
595 +          $envlevel++;
596 +          $Envlevels[$envlevel]=$envnum;
597 +          $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk";
598 +        }
599 + }
600 +
601 + sub Environment_end {
602 +        my $fd;
603 +
604 +        if ( $Arch ) {
605 +          $envlevel--;
606 +          if ( $envlevel < 0 ) {
607 +            print "Too many </Environent> Tags on $switch->line()\n";
608 +            exit;
609 +          }
610 +          close GNUmakefile;
611 +          # restore the last filehandle
612 +          $fd=pop @filehandlestack;
613 +          close $fd;
614 +          *GNUmakefile=$filehandlestack[$#filehandlestack];
615 +          if ( $envlevel < 1 ) {
616 +            $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
617 +          }
618 +          else {
619 +            $currentenv=
620 +             "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$Envlevels[$envlevel]";
621 +          }
622 +        }
623 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines