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.12 by williamc, Tue Nov 14 15:18:41 2000 UTC vs.
Revision 1.13 by williamc, Wed Nov 15 14:49:22 2000 UTC

# Line 2 | Line 2
2   #
3   # Interface
4   # ---------
5 < # new(ConfigArea,Builder)
5 > # new(toolbox)
6   # ParseBuildFile($base,$path,$file)
7   # ParseBuildFileExport(filename)
8 # BlockParse(Block) : perform a parse to modify the block
8   # BlockClassPath() : Return the class path
9   # 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
10  
11   package BuildSystem::BuildFile;
12   use ActiveDoc::SimpleDoc;
# Line 25 | Line 21 | sub new {
21          my $class=shift;
22          my $self={};
23          bless $self, $class;
24 <        $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();
24 >        $self->{toolbox}=shift;
25          $self->{Arch}=1;
26          push @{$self->{ARCHBLOCK}}, $self->{Arch};
27          return $self;
28   }
29  
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
30   sub ignore {
31          my $self=shift;
32          return (defined $self->{ignore})?$self->{ignore}:0;
# Line 105 | Line 39 | sub _initswitcher {
39          $switch->newparse($parse);
40          $switch->addignoretags($parse);
41          $self->_commontags($switch,$parse);
42 <        #$switch->addtag($parse,"Build", \&Build_start, $self);
42 >        $switch->addtag($parse,"Build", \&Build_start, $self);
43          $switch->addtag($parse,"none",
44                                          \&OutToMakefile,$self,
45                                          \&OutToMakefile, $self,
# Line 177 | Line 111 | sub _commontags {
111          return $switch;
112   }
113  
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
114   sub ParseBuildFile {
115          my $self=shift;
116          my $base=shift;
# Line 218 | Line 128 | sub ParseBuildFile {
128          $numbins=0;
129          $self->{envnum}=0;
130          $self->{envlevel}=0;
131 <        $self->{makefile}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
132 <                                                                "BuildFile.mk";
223 <        $self->{currentenv}=$self->{makefile};
131 >        $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
132 >                                                                "BuildFile.mk";
133          $self->{switch}=$self->_initswitcher();
134          $self->{switch}->filetoparse($fullfilename);
135  
136   #       $self->{switch}->{Strict_no_cr}='no';
137          #open a temporary gnumakefile to store output.
138          use Utilities::AddDir;
139 <        AddDir::adddir("$self->{localtop}/$ENV{INTwork}/$self->{path}");
140 <        $ENV{LatestBuildFile}=$self->GenerateMakefile($fullfilename,
141 <        $self->{localtop}."/".$ENV{INTwork}."/".$self->{path}."/BuildFile.mk");
142 < }
143 <
144 < sub classname {
145 <        my $self=shift;
146 <        if ( @_ ) {
147 <          $self->{classname}=shift;
148 <        }
149 <        return $self->{classname};
139 >        AddDir::adddir("$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}");
140 >        my $fh=FileHandle->new();
141 >        open ( $fh, ">$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk"
142 >          ) or die "Unable to open /$ENV{INTwork}/".$self->{path}."/BuildFile.mk $!\n";
143 >        @{$self->{filehandlestack}}=($fh);
144 >        # make an alias
145 >        *GNUmakefile=$fh;
146 >        if ( -e $ENV{LatestBuildFile} ) {
147 >          print GNUmakefile "include $ENV{LatestBuildFile}\n";
148 >        }
149 > #       print "writing to :\n".
150 > #               "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/BuildFile.mk\n";
151 >        $ENV{LatestBuildFile}="$ENV{LOCALTOP}/$ENV{INTwork}/".$self->{path}."/BuildFile.mk";
152 >        $self->{switch}->parse("makebuild"); # sort out supported tags
153 >        if ( $numbins > 0 ) {
154 >         print GNUmakefile <<ENDTEXT;
155 > ifndef BINMODE
156 > help::
157 > \t\@echo Generic Binary targets
158 > \t\@echo ----------------------
159 > endif
160 > ENDTEXT
161 >         foreach $target ( keys %$targettypes ) {
162 >         print GNUmakefile <<ENDTEXT;
163 > ifndef BINMODE
164 > help::
165 > \t\@echo $target
166 > endif
167 > ENDTEXT
168 >         }
169 >        }
170 >        close GNUmakefile;
171   }
172  
173   sub ParseBuildFile_Export {
174          my $self=shift;
175          my $filename=shift;
176 <        my $bf=BuildSystem::BuildFile->new($self->{area},$self->{Builder});
176 >        my $bf=BuildSystem::BuildFile->new($self->{toolbox});
177          if ( defined $self->{remoteproject} ) {
178             $bf->{remoteproject}=$self->{remoteproject};
179          }
# Line 319 | Line 249 | sub Class_StartTag {
249          
250          if ( $self->{Arch} ) {
251           if ( defined $$hashref{'type'} ) {
252 <                 $self->classname($$hashref{'type'});
252 >                $ClassName=$$hashref{'type'};
253           }
254          }
255   }
# Line 337 | Line 267 | sub IncludePath_Start {
267   }
268  
269   #
270 < # --- <Build class=> tag
341 < #
342 <
270 > # generic build tag
271   #
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
272   sub Build_start {
273          my $self=shift;
274          my $name=shift;
275          my $hashref=shift;
276  
277          $self->{switch}->checktag($name,$hashref,'class');
450        $self->{switch}->checktag($name,$hashref,'id');
278          if ( $self->{Arch} ) {
279  
280            # -- determine the build products name
# Line 814 | Line 641 | sub Use_start {
641          if ( ! defined $self->{remoteproject} ) {
642            $filename=SCRAMUtils::checkfile(
643                  "/$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          }
644          }
645          else {
646            $filename=$self->{remoteproject}."/$$hashref{name}/BuildFile";
# Line 834 | Line 657 | sub Use_start {
657          }
658   }
659  
660 + sub CheckBuildFile {
661 +         my $self=shift;
662 +         my $classdir=shift;
663 +         my $ClassName="";
664 +         my $thisfile="$classdir/$buildfile";
665 +
666 +         if ( -e $ENV{LOCALTOP}."/".$thisfile ) {
667 +            $DefaultBuildfile="$ENV{LOCALTOP}/$thisfile";
668 +            $self->ParseBuildFile($ENV{LOCALTOP}, $classdir, $buildfile);
669 +         }
670 +         elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
671 +            $DefaultBuildfile="$ENV{RELEASETOP}/$thisfile";
672 +            $self->ParseBuildFile($ENV{RELEASETOP}, $classdir, $buildfile);
673 +         }
674 +         return $ClassName;
675 + }
676 +
677   # List association groups between <AssociateGroup> tags
678   # seperated by newlines or spaces
679   sub AssociateGroup {
# Line 1029 | Line 869 | sub Environment_start {
869            $self->{envnum}++;
870  
871            # open a new Environment File
872 <          my $envfile=$self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_".
872 >          my $envfile="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
873                  $self->{envnum}.".mk";
874            use FileHandle;
875            my $fh=FileHandle->new();
# Line 1039 | Line 879 | sub Environment_start {
879  
880            # include the approprate environment file
881            if ( $self->{envlevel} == 0 ) {
882 <             print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
882 >             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
883                  $self->{path}."/BuildFile.mk\n";
884            }
885            else {
886 <             print GNUmakefile "include $self->{localtop}/$ENV{INTwork}/".
886 >             print GNUmakefile "include $ENV{LOCALTOP}/$ENV{INTwork}/".
887                  $self->{path}."/Env_".$self->{Envlevels}[$self->{envlevel}].".mk\n";
888            }
889            $self->{envlevel}++;
890            $self->{Envlevels}[$self->{envlevel}]=$self->{envnum};
891 <          $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
891 >          $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_$self->{envnum}.mk";
892          }
893   }
894  
# Line 1068 | Line 908 | sub Environment_end {
908            close $fd;
909            *GNUmakefile=$self->{filehandlestack}[$#{$self->{filehandlestack}}];
910            if ( $self->{envlevel} < 1 ) {
911 <            $self->{currentenv}="$self->{localtop}/$ENV{INTwork}/$self->{path}/".
911 >            $self->{currentenv}="$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/".
912                          "BuildFile.mk";
913            }
914            else {
915              $self->{currentenv}=
916 <             $self->{localtop}."/$ENV{INTwork}/$self->{path}/Env_".
916 >             "$ENV{LOCALTOP}/$ENV{INTwork}/$self->{path}/Env_".
917                  $self->{Envlevels}[$self->{envlevel}];
918            }
919          }
# Line 1089 | Line 929 | sub Store_start {
929  
930            # -- store creation
931            my $dir=$$hashref{'name'};
932 <          AddDir::adddir($self->{localtop}."/".$dir);
932 >          AddDir::adddir($ENV{LOCALTOP}."/".$dir);
933            if ( exists $$hashref{'type'} ) {
934              # -- architecture specific store
935              if ( $$hashref{'type'}=~/^arch/i ) {
936                  $dir=$dir."/".$ENV{SCRAM_ARCH};
937 <                AddDir::adddir($self->{localtop}."/".$dir);
937 >                AddDir::adddir($ENV{LOCALTOP}."/".$dir);
938              }
939              else {
940                  $self->parseerror("Unknown type in <$name> tag");
# Line 1104 | Line 944 | sub Store_start {
944            # -- set make variables for the store
945            print GNUmakefile "SCRAMSTORENAME_".$$hashref{'name'}.":=".$dir."\n";
946            print GNUmakefile "SCRAMSTORE_".$$hashref{'name'}.":=".
947 <                                        $self->{localtop}."/".$dir."\n";
948 <          print GNUmakefile "VPATH+=".$self->{localtop}
949 <                        ."/".$dir.":".$self->{releasetop}."/".$dir."\n";
947 >                                        $ENV{LOCALTOP}."/".$dir."\n";
948 >          print GNUmakefile "VPATH+=".$ENV{LOCALTOP}
949 >                        ."/".$dir.":".$ENV{RELEASETOP}."/".$dir."\n";
950          }
951   }
952  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines