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

Comparing COMP/SCRAM/src/BuildSystem/BuildFile.pm (file contents):
Revision 1.2 by williamc, Mon Aug 28 08:23:08 2000 UTC vs.
Revision 1.12 by williamc, Tue Nov 14 15:18:41 2000 UTC

# Line 2 | Line 2
2   #
3   # Interface
4   # ---------
5 < # new(toolbox)
5 > # new(ConfigArea,Builder)
6   # ParseBuildFile($base,$path,$file)
7   # ParseBuildFileExport(filename)
8 + # BlockParse(Block) : perform a parse to modify the block
9   # BlockClassPath() : Return the class path
10   # ignore()      : return 1 if directory should be ignored 0 otherwise
11 + # classname()   : get/set the associated class
12 + # buildfile()   : get/set BuildFile location
13 + # makefile()    : get the generated makefile
14  
15   package BuildSystem::BuildFile;
16   use ActiveDoc::SimpleDoc;
# Line 21 | Line 25 | sub new {
25          my $class=shift;
26          my $self={};
27          bless $self, $class;
28 <        $self->{toolbox}=shift;
28 >        $self->{area}=shift;
29 >        $self->{Builder}=shift;
30 >        $self->{toolbox}=$self->{area}->toolbox();
31 >        $self->{localtop}=$self->{area}->location();
32 >        # -- set RELEASTOP
33 >        my $rarea=$self->{area}->linkarea();
34 >        if ( ! defined $rarea ) {
35 >          $self->{releasetop}=$self->{localtop};
36 >        }
37 >        else {
38 >          $self->{releasetop}=$rarea->location();
39 >        }
40 >        $self->{releasetop}=$self->{area}->location();
41          $self->{Arch}=1;
42          push @{$self->{ARCHBLOCK}}, $self->{Arch};
43          return $self;
44   }
45  
46 + sub buildfile {
47 +        my $self=shift;
48 +        if ( @_ ) {
49 +          $self->{buildfile}=shift;
50 +        }
51 +        return $self->{buildfile};
52 + }
53 +
54 + sub makefile {
55 +        my $self=shift;
56 +        if ( @_ ) {
57 +          $self->{makefile}=shift;
58 +        }
59 +        return $self->{makefile};
60 + }
61 +
62 + sub BlockParse {
63 +        my $self=shift;
64 +        $self->{block}=shift;
65 +
66 +        # -- set up the block parse
67 +        my $switch=$self->_initswitcher();
68 +        my $parse="block";
69 +        $switch->newparse($parse);
70 +        $switch->addignoretags($parse);
71 +        $switch->addtag($parse,"BuildParam", \&BuildBlock_start, $self);
72 +        $switch->filetoparse($self->buildfile());
73 +
74 +        # -- parse away
75 +        $self->{switch}=$switch;
76 +        $switch->parse("block");
77 + }
78 +
79 + sub Parsetofh {
80 +        my $self=shift;
81 +        my $fh=shift;
82 +        $self->{buildblock}=shift;
83 +
84 +        # -- set up for parse
85 +        @{$self->{filehandlestack}}=($fh);
86 +        $self->{switch}->filetoparse($self->buildfile());
87 +        *GNUmakefile=$fh;
88 +
89 +        # -- generate makefile
90 +        $self->{switch}->parse("makebuild"); # sort out supported tags
91 +
92 +        # -- Clean up
93 +        close GNUmakefile;
94 + }
95 +
96   sub ignore {
97          my $self=shift;
98          return (defined $self->{ignore})?$self->{ignore}:0;
# Line 39 | Line 105 | sub _initswitcher {
105          $switch->newparse($parse);
106          $switch->addignoretags($parse);
107          $self->_commontags($switch,$parse);
108 <        $switch->addtag($parse,"Build", \&Build_start, $self);
108 >        #$switch->addtag($parse,"Build", \&Build_start, $self);
109          $switch->addtag($parse,"none",
110                                          \&OutToMakefile,$self,
111                                          \&OutToMakefile, $self,
# Line 48 | Line 114 | sub _initswitcher {
114                                          \&Bin_start,$self,
115                                          \&OutToScreen, $self,
116                                          "", $self);
117 +         $switch->addtag($parse,"ProductStore",
118 +                                        \&Store_start,$self,
119 +                                        "", $self,
120 +                                        "", $self);
121          $switch->addtag($parse,"LibType",
122                                          \&LibType_Start,$self,
123                                          \&LibType_text, $self,
# Line 107 | Line 177 | sub _commontags {
177          return $switch;
178   }
179  
180 + sub GenerateMakefile {
181 +        my $self=shift;
182 +        my $infile=shift;
183 +        my $outfile=shift;
184 +
185 +        $self->{switch}=$self->_initswitcher();
186 +        $self->{switch}->filetoparse($infile);
187 +
188 +        # open a temporary gnumakefile to store output.
189 +        my $fh=FileHandle->new();
190 +        open ( $fh, ">$outfile") or die "Unable to open $outfile for output ".
191 +                                                                "$!\n";
192 +        @{$self->{filehandlestack}}=($fh);
193 +
194 +        #  -- make an alias
195 +        *GNUmakefile=$fh;
196 +        if ( -e $ENV{LatestBuildFile} ) {
197 +          print GNUmakefile "include $ENV{LatestBuildFile}\n";
198 +        }
199 +        $self->{switch}->parse("makebuild"); # sort out supported tags
200 +        close GNUmakefile;
201 +        return $outfile;
202 + }
203 +
204   sub ParseBuildFile {
205          my $self=shift;
206          my $base=shift;
# Line 124 | Line 218 | sub ParseBuildFile {
218          $numbins=0;
219          $self->{envnum}=0;
220          $self->{envlevel}=0;
221 <        $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
222 <                                                                "BuildFile.mk";
221 >        $self->{makefile}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
222 >                                                                "BuildFile.mk";
223 >        $self->{currentenv}=$self->{makefile};
224          $self->{switch}=$self->_initswitcher();
225          $self->{switch}->filetoparse($fullfilename);
226  
227   #       $self->{switch}->{Strict_no_cr}='no';
228          #open a temporary gnumakefile to store output.
229          use Utilities::AddDir;
230 <        AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}");
231 <        my $fh=FileHandle->new();
232 <        open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk"
233 <          ) or die 'Unable to open /$ENV{INTwork}/".$self->{path}."/BuildFile.mk $!\n';
234 <        @{$self->{filehandlestack}}=($fh);
235 <        # make an alias
236 <        *GNUmakefile=$fh;
237 <        if ( -e $ENV{LatestBuildFile} ) {
238 <          print GNUmakefile "include $ENV{LatestBuildFile}\n";
239 <        }
240 < #       print "writing to :\n".
146 < #               "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/BuildFile.mk\n";
147 <        $ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk";
148 <        $self->{switch}->parse("makebuild"); # sort out supported tags
149 <        if ( $numbins > 0 ) {
150 <         print GNUmakefile <<ENDTEXT;
151 < ifndef BINMODE
152 < help::
153 < \t\@echo Generic Binary targets
154 < \t\@echo ----------------------
155 < endif
156 < ENDTEXT
157 <         foreach $target ( keys %$targettypes ) {
158 <         print GNUmakefile <<ENDTEXT;
159 < ifndef BINMODE
160 < help::
161 < \t\@echo $target
162 < endif
163 < ENDTEXT
164 <         }
165 <        }
166 <        close GNUmakefile;
230 >        AddDir::adddir("$self->{localtop}/$ENV{INTwork}/$self->{path}");
231 >        $ENV{LatestBuildFile}=$self->GenerateMakefile($fullfilename,
232 >        $self->{localtop}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk");
233 > }
234 >
235 > sub classname {
236 >        my $self=shift;
237 >        if ( @_ ) {
238 >          $self->{classname}=shift;
239 >        }
240 >        return $self->{classname};
241   }
242  
243   sub ParseBuildFile_Export {
244          my $self=shift;
245          my $filename=shift;
246 <        my $bf=BuildSystem::BuildFile->new($self->{toolbox});
246 >        my $bf=BuildSystem::BuildFile->new($self->{area},$self->{Builder});
247          if ( defined $self->{remoteproject} ) {
248             $bf->{remoteproject}=$self->{remoteproject};
249          }
# Line 245 | Line 319 | sub Class_StartTag {
319          
320          if ( $self->{Arch} ) {
321           if ( defined $$hashref{'type'} ) {
322 <                $ClassName=$$hashref{'type'};
322 >                 $self->classname($$hashref{'type'});
323           }
324          }
325   }
# Line 263 | Line 337 | sub IncludePath_Start {
337   }
338  
339   #
340 < # generic build tag
340 > # --- <Build class=> tag
341 > #
342 >
343   #
344 + # Parameter collection
345 + #
346 + sub BuildBlock_start {
347 +        my $self=shift;
348 +        my $name=shift;
349 +        my $hashref=shift;
350 +
351 +
352 +        my $blockobjid=$self->__blockobjid($hashref);
353 +
354 +        if ( $self->{Arch} ) {
355 +
356 +           # -- get any objects that match
357 +           my $inheritobj=$self->{block}->getobj($blockobjid);
358 +
359 +           # -- create an object with inherited properties
360 +           my $obj;
361 +           if ( ! defined $inheritobj ) {
362 +               # -- check we have a lookup for the class type
363 +               my $mapper=$self->_toolmapper();
364 +               if ( ! $mapper->exists($$hashref{'class'}) ) {
365 +                 $self->{switch}->parseerror("Unknown class : ".
366 +                                                        $$hashref{'class'});
367 +               }
368 +               $obj=BuildSystem::BuildClass->new();
369 +           }
370 +           else {
371 +               # -- inherit the properties from class with the same id class
372 +               $obj=$inheritobj->child();
373 +           }
374 +
375 +           # -- add changes from our tag
376 +           $obj->paramupdate($hashref);
377 +
378 +           # -- store the new object in the block
379 +           $self->{block}->setobj($obj,$blockobjid);
380 +        }
381 + }
382 +
383 + sub BuilderClass_buildmakefile {
384 +        my $self=shift;
385 +        my $name=shift;
386 +        my $hashref=shift;
387 +
388 +        my $blockobjid=$self->__blockobjid($hashref);
389 +
390 +        if ( $self->{Arch} ) {
391 +           # -- get the matching block object
392 +           my $blockobj=$self->{buildblock}->getobj($blockobjid);
393 +
394 +           # -- top level buildfile
395 +           my $fh=$self->{filehandlestack}[0];
396 +
397 +           # -- var initialisation
398 +           my @deftypes=();
399 +           my $buildname="";
400 +           my @types=$self->_toolmapper()->types($$hashref{'class'});
401 +
402 +           # -- error checking
403 +           if ( ! defined $blockobj->param("default") ) {
404 +             $self->error("No default build parameter defined for ".
405 +                $$hashref{'class'}." ".$$hashref{'id'});
406 +           }
407 +           if ( ! defined $blockobj->param("name") ) {
408 +             $self->error("\"name\" parameter defined for ".
409 +                $$hashref{'class'}." ".$$hashref{'id'});
410 +           }
411 +
412 +
413 +           foreach $param ( $blockobj->paramlist() ) {
414 +             # -- check for params that need special handling
415 +             if ( $param eq "default" ) {
416 +                @deftypes=split /,/, $param;
417 +             }
418 +             elsif ( $param eq "name" ) {
419 +                $buildname=$blockobj->param($param);
420 +             }
421 +             else {
422 +                # -- simple transfer of block object parameters to makefile
423 +                print $fh $param.":=".$blockobj->param($param)."\n";
424 +             }
425 +           }
426 +
427 +           # -- construct the targets in the top makefile
428 +           $self->_generatedefaulttargets($fh,$$hashref{'class'},@deftypes);
429 +           $self->_generatetypetargets($fh,$$hashref{'class'},$buildname,@types);
430 +        }
431 + }
432 +
433 + sub _blockobjid {
434 +        my $self=shift;
435 +        my $hashref=shift;
436 +
437 +        $self->{switch}->checktag($name,$hashref,'class');
438 +        $self->{switch}->checktag($name,$hashref,'id');
439 +        my $blockobjid="bc_".$$hashref{'class'},"_".$$hashref{'id'};
440 +
441 +        return $blockobjid;
442 + }
443 +
444   sub Build_start {
445          my $self=shift;
446          my $name=shift;
447          my $hashref=shift;
448  
449          $self->{switch}->checktag($name,$hashref,'class');
450 +        $self->{switch}->checktag($name,$hashref,'id');
451          if ( $self->{Arch} ) {
452  
453            # -- determine the build products name
# Line 356 | Line 533 | sub Build_start {
533   #           print $typefile "\t\$(_quietbuild_)";
534   #           print $typefile $mapper->template($$hashref{'class'},$type)."\n";
535   #           print $typefile "\t\$(_quietstamp_)";
536 < #           print $typefile "$(SCRAMPERL) $(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
536 > #           print $typefile "\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$@.ds \$@ \$^\n";
537  
538              # -- cleaning targets
539              push @targets, "clean_$dirname";
# Line 514 | Line 691 | ENDTEXT
691          print binGNUmakefile "$$hashref{name}_Insure.exe:.psrc\n";
692          print binGNUmakefile "$$hashref{name}_d.exe:$objectname_d\n";
693          print binGNUmakefile "\t\$(CClinkCmdDebug)\n";
694 <        print binGNUmakefile "\t\@\$(SCRAMPERL) $(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
694 >        print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
695          print binGNUmakefile "$$hashref{name}_l_d.exe:$objectname_d\n";
696          print binGNUmakefile "\t\$(CClinkCmdDebugLocal)\n";
697 <        print binGNUmakefile "\t\@\$(SCRAMPERL) $(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
697 >        print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
698          print binGNUmakefile "$$hashref{name}_Insure.exe:$objectname_Insure\n";
699          print binGNUmakefile "\t\$(CClinkCmdInsure)\n";
700 <        print binGNUmakefile "\t\@\$(SCRAMPERL) $(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
700 >        print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
701          print binGNUmakefile "$$hashref{name}_o.exe:$objectname_o\n";
702          print binGNUmakefile "\t\$(CClinkCmd)\n";
703 <        print binGNUmakefile "\t\@\$(SCRAMPERL) $(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
703 >        print binGNUmakefile "\t\@\$(SCRAMPERL) \$(SCRAM_HOME)/src/scramdatestamp \$\@\.ds \$\@ \$\^\n";
704          print binGNUmakefile "$$hashref{name}.dep:$$hashref{file}\n";
705          print binGNUmakefile "-include $$hashref{name}.dep\n";
706   print binGNUmakefile <<ENDTEXT;
# Line 637 | Line 814 | sub Use_start {
814          if ( ! defined $self->{remoteproject} ) {
815            $filename=SCRAMUtils::checkfile(
816                  "/$ENV{INTsrc}/$$hashref{name}/BuildFile");
817 +          # -- force a dependency check if local
818 +          if ( $filename=~/^$self->{localtop}/ ) {
819 +            $self->{Builder}->BuildDir($ENV{INTsrc}."/".$$hashref{'name'});
820 +          }
821          }
822          else {
823            $filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
# Line 653 | Line 834 | sub Use_start {
834          }
835   }
836  
656 sub CheckBuildFile {
657         my $self=shift;
658         my $classdir=shift;
659         my $ClassName="";
660         my $thisfile="$classdir/$buildfile";
661
662         if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
663            $DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
664            $self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
665         }
666         elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
667            $DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
668            $self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
669         }
670         return $ClassName;
671 }
672
837   # List association groups between <AssociateGroup> tags
838   # seperated by newlines or spaces
839   sub AssociateGroup {
# Line 865 | Line 1029 | sub Environment_start {
1029            $self->{envnum}++;
1030  
1031            # open a new Environment File
1032 <          my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
1032 >          my $envfile=$self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_".
1033                  $self->{envnum}.".mk";
1034            use FileHandle;
1035            my $fh=FileHandle->new();
# Line 875 | Line 1039 | sub Environment_start {
1039  
1040            # include the approprate environment file
1041            if ( $self->{envlevel} == 0 ) {
1042 <             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
1042 >             print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
1043                  $self->{path}."/BuildFile.mk\n";
1044            }
1045            else {
1046 <             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
1046 >             print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
1047                  $self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
1048            }
1049            $self->{envlevel}++;
1050            $self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
1051 <          $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
1051 >          $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
1052          }
1053   }
1054  
# Line 904 | Line 1068 | sub Environment_end {
1068            close $fd;
1069            *GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
1070            if ( $self->{envlevel} < 1 ) {
1071 <            $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
1071 >            $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
1072                          "BuildFile.mk";
1073            }
1074            else {
1075              $self->{currentenv}=
1076 <             "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
1076 >             $self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_".
1077                  $self->{Envlevels}[$self->{envlevel}];
1078            }
1079          }
1080   }
1081 +
1082 + sub Store_start {
1083 +        my $self=shift;
1084 +        my $name=shift;
1085 +        my $hashref=shift;
1086 +
1087 +        if ( $self->{Arch} ) {
1088 +          $self->{switch}->checktag( $name, $hashref, 'name' );
1089 +
1090 +          # -- store creation
1091 +          my $dir=$$hashref{'name'};
1092 +          AddDir::adddir($self->{localtop}."/".$dir);
1093 +          if ( exists $$hashref{'type'} ) {
1094 +            # -- architecture specific store
1095 +            if ( $$hashref{'type'}=~/^arch/i ) {
1096 +                $dir=$dir."/".$ENV{SCRAM_ARCH};
1097 +                AddDir::adddir($self->{localtop}."/".$dir);
1098 +            }
1099 +            else {
1100 +                $self->parseerror("Unknown type in <$name> tag");
1101 +            }
1102 +          }
1103 +
1104 +          # -- set make variables for the store
1105 +          print GNUmakefile "SCRAMSTORENAME_".$$hashref{'name'}.":=".$dir."\n";
1106 +          print GNUmakefile "SCRAMSTORE_".$$hashref{'name'}.":=".
1107 +                                        $self->{localtop}."/".$dir."\n";
1108 +          print GNUmakefile "VPATH+=".$self->{localtop}
1109 +                        ."/".$dir.":".$self->{releasetop}."/".$dir."\n";
1110 +        }
1111 + }
1112 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines