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.22 by williamc, Wed Oct 13 12:44:00 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 BINMADE
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) BINMADE=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 > $$hashref{'name'}_echo_%:: dummy
197 >        \@\$(stepdown_$$hashref{'name'})
198 >
199 > echo_%:: dummy
200 >        \@\$(stepdown_$$hashref{'name'})
201 >
202 > bin bin_debug bin_debug_local bin_insure bin_Insure clean $$hashref{'name'}:: dummy
203 >        \@\$(stepdown_$$hashref{'name'})
204 > endif
205 >
206 > ENDTEXT
207 >
208 >
209 > # the binary specifics makefile
210 >        print binGNUmakefile "include $currentenv\n";
211 >        print binGNUmakefile "VPATH+=$ENV{LOCALTOP}/${path}\n";
212 >
213 > # alias for bin_Insure
214 >        print binGNUmakefile <<ENDTEXT;
215 >
216 > bin_insure:bin_Insure
217 > ifdef MAKETARGET_bin_insure
218 > MAKETARGET_$$hashref{name}_Insure=1
219 > endif
220 >
221 > # debuggging target
222 > $$hashref{'name'}_echo_% :: echo_%
223 >
224 > ENDTEXT
225 >
226 > # Make generic rules for each type
227 >        $targettypes={
228 >                "bin" => 'o',
229 >                "bin_debug" => 'd',
230 >                "bin_debug_local" => 'l_d',
231 >                "bin_Insure" => 'Insure'
232 >        };
233 >        #
234 >        foreach $target ( keys %$targettypes ) {
235 >          print binGNUmakefile <<ENDTEXT;
236 >
237 > # Type $target specifics
238 > ifdef MAKETARGET_$target
239 > MAKETARGET_$$hashref{name}_$$targettypes{$target}=1
240 > endif
241 > $target ::$$hashref{name}_$$targettypes{$target}
242 >
243 > bintargets+=$$hashref{name}_$$targettypes{$target}
244 > clean::
245 > \t\@if [ -f \$(binarystore)/$$hashref{name}_$$targettypes{$target} ]; then \\
246 > \techo Removing \$(binarystore)/$$hashref{name}; \\
247 > \trm \$(binarystore)/$$hashref{name}_$$targettypes{$target}; \\
248 > \tfi
249 >
250 > ENDTEXT
251 >          ($objectname=$$hashref{file})=~s/\..*/_$$targettypes{$target}\.o/;
252 >          ${"objectname_$$targettypes{$target}"}=$objectname;
253 >          print binGNUmakefile "$objectname:$$hashref{name}.dep\n";
254 >        } # end loop
255 >
256 >        print binGNUmakefile "$$hashref{name}_Insure:.psrc\n";
257 >        print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
258 >        print binGNUmakefile "\t\$(CClinkCmdDebug)\n";
259 >        print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n";
260 >        print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n";
261 >        print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
262 >        print binGNUmakefile "\t\$(CClinkCmdInsure)\n";
263 >        print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n";
264 >        print binGNUmakefile "\t\$(CClinkCmd)\n";
265 >        print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
266 >        print binGNUmakefile "-include $$hashref{name}.dep\n";
267 > print binGNUmakefile <<ENDTEXT;
268 > clean::
269 > \t\@if [ -f \$(binarystore)/$$hashref{name} ]; then \\
270 > \techo Removing \$(binarystore)/$$hashref{name}; \\
271 > \trm \$(binarystore)/$$hashref{name}; \\
272 > \tfi
273 >
274 > $$hashref{name}_d.exe:\$(libslocal_d)
275 > $$hashref{name}_o.exe:\$(libslocal)
276 > ifdef MCCABE_DATA_DIR
277 > $$hashref{name}_mccabe.exe: \$(libslocal_d) \$(MCCABE_DATA_DIR)/mccabeinstr/instplus.cpp
278 > endif
279 > $$hashref{name}_Insure.exe:\$(libslocal_I)
280 > $$hashref{name}_d:$$hashref{name}_d.exe
281 >        \@cp $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
282 > $$hashref{name}_l_d:$$hashref{name}_l_d.exe
283 >        \@cp $$hashref{name}_l_d.exe \$(binarystore)/$$hashref{name}
284 > $$hashref{name}_Insure:$$hashref{name}_Insure.exe
285 >        \@cp $$hashref{name}_Insure.exe \$(binarystore)/$$hashref{name}_Insure
286 > $$hashref{name}:$$hashref{name}_d.exe
287 >        \@mv $$hashref{name}_d.exe \$(binarystore)/$$hashref{name}
288 > $$hashref{name}_o:$$hashref{name}_o.exe
289 >        \@mv $$hashref{name}_o.exe \$(binarystore)/$$hashref{name}
290 > binfiles+=$$hashref{file}
291 > ENDTEXT
292 >        }
293 >        close binGNUmakefile;
294 > }
295 >
296 > sub Ext_start_export {
297 >        my $name=shift;
298 >        my @vars=@_;
299 >        my $hashref;
300 >        
301 >        $hashref=$switch->SetupValueHash(\@vars);
302 >        if ( $Arch ) {
303 >         if ( $switchex->context('export') ) {
304 >          $$hashref{'ref'}=~tr[A-Z][a-z];
305 >          print GNUmakefile $$hashref{'ref'};
306 >          if ( defined $$hashref{'version'} ) {
307 >                print GNUmakefile "_V_".$$hashref{'version'};
308 >          }
309 >          print GNUmakefile "=true\n";
310 >         }
311 >        }
312   }
313  
314   sub External_StartTag {
# Line 121 | Line 317 | sub External_StartTag {
317          my $hashref;
318          
319          $hashref=$switch->SetupValueHash(\@vars);
320 +        if ( $Arch ) {
321 +        $$hashref{'ref'}=~tr[A-Z][a-z];
322          print GNUmakefile $$hashref{'ref'};
323          if ( defined $$hashref{'version'} ) {
324                  print GNUmakefile "_V_".$$hashref{'version'};
325          }
326          print GNUmakefile "=true\n";
327 +        }
328          
329   }      
330  
# Line 136 | Line 335 | sub Group_start {
335          
336          $hashref=$switch->SetupValueHash(\@vars);
337          $switch->checkparam($hashref, $name, 'name');
338 +        if ( $Arch ) {
339          print GNUmakefile "GROUP_".$$hashref{'name'};
340          if ( defined $$hashref{'version'} ) {
341                  print GNUmakefile "_V_".$$hashref{'version'};
342          }
343          print GNUmakefile "=true\n";
344 +        }
345   }      
346  
347   sub External {
# Line 167 | Line 368 | sub Use_start {
368          
369          $hashref=$switch->SetupValueHash(\@vars);
370          $switch->checkparam($hashref, $name, "name");
371 <        if ( $filename=checkfile("$ENV{INTsrc}/$$hashref{name}/BuildFile")
372 <                                                 ne "" ) {
373 <          print GNUmakefile "ReqDependencies += $filename\n";
371 >        if ( $Arch ) {
372 >        $filename=SCRAMUtils::checkfile(
373 >                "$ENV{INTsrc}/$$hashref{name}/BuildFile");
374 >        if ( $filename ne "" ) {
375 >          ParseBuildFile_Export( $filename );
376 >        }
377          }
174        print GNUmakefile "local__$$hashref{name}=true\n";
378   }
379  
380 < sub CheckBuildFile($directory) {
380 > sub CheckBuildFile {
381           my $classdir=shift;
382           $ClassName="";
383           $thisfile="$classdir/$buildfile";
# Line 204 | Line 407 | sub AssociateGroup {
407          }
408   }
409  
410 + sub ignoretag {
411 +        my $name=shift;
412 +        my @vars=@_;
413 +        
414 +        $Arch=0;
415 +        push @ARCHBLOCK, $Arch;
416 + }
417 +
418 + sub ignoretag_end {
419 +        my $name=shift;
420 +        my @vars=@_;
421 +        
422 +        pop @ARCHBLOCK;
423 +        $Arch=$ARCHBLOCK[$#ARCHBLOCK];
424 + }
425 +
426 + sub Arch_Start {
427 +        my $name=shift;
428 +        my @vars=@_;
429 +        my $hashref;
430 +
431 +        $hashref=$toolswitch->SetupValueHash( \@vars );
432 +        $toolswitch->checkparam($hashref, $name, 'name');
433 +        #( ($$hashref{name}=~/$ENV{SCRAM_ARCH}/) )?$Arch=1:$Arch=0;
434 +        ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($Arch=1) : ($Arch=0);
435 +        push @ARCHBLOCK, $Arch;
436 + }
437 + sub Arch_End {
438 +        my $name=shift;
439 +        my @vars=@_;
440 +
441 +        pop @ARCHBLOCK;
442 +        $Arch=$ARCHBLOCK[$#ARCHBLOCK];
443 + }
444 +
445   # Split up the Class Block String into a useable array
446 < sub _CutBlock($string) {
446 > sub _CutBlock {
447      my $string= shift @_;
448      @BlockClassA = split /\//, $string;
449   }
# Line 214 | Line 452 | sub OutToMakefile {
452          my $name=shift;
453          my @vars=@_;
454  
455 <        print GNUmakefile @vars;
455 >        if ( $Arch ) {
456 >          print GNUmakefile @vars;
457 >        }
458 > }
459 > sub OutToScreen {
460 >        my $name=shift;
461 >        my @vars=@_;
462 >
463 >        if ( $Arch ) {
464 >          print @vars;
465 >        }
466   }
467   sub setBlockClassPath {
468          my $name=shift;
# Line 226 | Line 474 | sub setBlockClassPath {
474          $BlockClassPath=$BlockClassPath.":".$$hashref{path};
475          _CutBlock($$hashref{path});
476   }
477 +
478 + sub export_start {
479 + #Set up a toolfile object
480 +        $exporttool=Tool->new();
481 + }
482 +
483 + sub export_end {
484 + #Write toolfile object to disk
485 +        $exporttool->envtomake(\*GNUmakefile);
486 + }
487 +
488 + #
489 + # Export Mode Lib Tag
490 + #
491 + sub lib_start_export {
492 +        my $name=shift;
493 +        my @vars=@_;
494 +        my $hashref;
495 +
496 +        $hashref=$switchex->SetupValueHash( \@vars );
497 +        $switchex->checkparam($hashref, $name, 'name');
498 +        if ( $Arch ) {
499 +         if ( $switchex->context('export') ) {
500 +                #If export mode then add this env to the export tool
501 +                $exporttool->addenv('lib',$$hashref{name});
502 +         }
503 +        }
504 + }
505 +
506 + #
507 + # Standard lib tag
508 + #
509 + sub lib_start {
510 +        my $name=shift;
511 +        my @vars=@_;
512 +        my $hashref;
513 +
514 +        $hashref=$switch->SetupValueHash( \@vars );
515 +        $switch->checkparam($hashref, $name, 'name');
516 +        if ( $Arch ) {
517 +           print GNUmakefile "lib+=$$hashref{name}\n";
518 +        }
519 + }
520 +
521 + #
522 + # libtype specification
523 + #
524 + sub LibType_Start {
525 +        my $name=shift;
526 +        my @vars=@_;
527 +        my $hashref;
528 +
529 +        if ( $Arch ) {
530 +        $hashref=$switch->SetupValueHash( \@vars );
531 +        $switch->checkparam($hashref, $name, 'type');
532 +        
533 +        print GNUmakefile "# Specify Library Type\n";
534 +        print GNUmakefile "DefaultLibsOff=yes\n";
535 +        if ( $$hashref{'type'}=~/^archive/i ) {
536 +          print GNUmakefile "LibArchive=true\n";
537 +        }
538 +        elsif ($$hashref{'type'}=~/debug_archive/i ) {
539 +          print GNUmakefile "LibDebugArchive=true\n";
540 +        }
541 +        elsif ($$hashref{'type'}=~/debug_shared/i ) {
542 +          print GNUmakefile "LibDebugShared=true\n";
543 +        }
544 +        elsif ($$hashref{'type'}=~/shared/i ) {
545 +          print GNUmakefile 'LibShared=true'."\n";
546 +        }
547 +        print GNUmakefile "\n";
548 +        }
549 + }
550 + sub LibType_text {
551 +        my $name=shift;
552 +        my @vars=@_;
553 +
554 +        if ( $Arch ) {
555 +          print GNUmakefile "libmsg::\n\t\@echo Library info: ";
556 +          print GNUmakefile @vars;
557 +          print GNUmakefile "\n";
558 +        }
559 + }
560 +
561 + sub Environment_start {
562 +        my $name=shift;
563 +        my @vars=@_;
564 +        my $hashref;
565 +
566 +        if ( $Arch ) {
567 +          $envnum++;
568 +
569 +          # open a new Environment File
570 +          my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk";
571 +          use FileHandle;
572 +          my $fh=FileHandle->new();
573 +          open ($fh,">$envfile") or die "Unable to open file $envfile \n$!\n";
574 +          push @filehandlestack, $fh;
575 +          *GNUmakefile=$fh;
576 +
577 +          # include the approprate environment file
578 +          if ( $envlevel == 0 ) {
579 +             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
580 +                                "BuildFile.mk\n";
581 +          }
582 +          else {
583 +             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/${path}/".
584 +                                "Env_$Envlevels[$envlevel]\.mk\n";
585 +          }
586 +          $envlevel++;
587 +          $Envlevels[$envlevel]=$envnum;
588 +          $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$envnum.mk";
589 +        }
590 + }
591 +
592 + sub Environment_end {
593 +        my $fd;
594 +
595 +        if ( $Arch ) {
596 +          $envlevel--;
597 +          if ( $envlevel < 0 ) {
598 +            print "Too many </Environent> Tags on $switch->line()\n";
599 +            exit;
600 +          }
601 +          close GNUmakefile;
602 +          # restore the last filehandle
603 +          $fd=pop @filehandlestack;
604 +          close $fd;
605 +          *GNUmakefile=$filehandlestack[$#filehandlestack];
606 +          if ( $envlevel < 1 ) {
607 +            $currentenv="$ENV{LOCALTOP}/$ENV{INTwork}/${path}/BuildFile.mk";
608 +          }
609 +          else {
610 +            $currentenv=
611 +             "$ENV{LOCALTOP}/$ENV{INTwork}/${path}/Env_$Envlevels[$envlevel]";
612 +          }
613 +        }
614 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines