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

Comparing COMP/SCRAM/src/BuildSystem/BuildSetup.pm (file contents):
Revision 1.11 by williamc, Thu Nov 2 15:19:45 2000 UTC vs.
Revision 1.15 by sashby, Wed Aug 22 12:40:13 2001 UTC

# Line 2 | Line 2
2   #
3   # Interface
4   # ---------
5 < # new(ConfigArea) : A new BuildSetup
6 < # BuildDir(directory,targets) : prepare the ground for a build and build
7 < # getclass(directory) : return (Class, ClassDir) associated with directory
8 < # setup(dir)
5 > # new(toolbox) : A new BuildSetup
6 > # BuildSetup(directory,targets) : prepare the ground for a build and build
7 > # getclass(directory) : return (Class, ClassDir, BuildFileobject)
8 > #                       associated with directory
9 > #
10  
11   package BuildSystem::BuildSetup;
12   require 5.004;
13   use Utilities::Verbose;
14   use Utilities::SCRAMUtils;
15   use BuildSystem::BuildFile;
15 use BuildSystem::DateStampRecord;
16 use BuildSystem::Block;
16   use Utilities::AddDir;
17   @ISA=qw(Utilities::Verbose);
18  
# Line 21 | Line 20 | sub new {
20          my $class=shift;
21          my $self={};
22          bless $self,$class;
23 <        $self->{area}=shift;
25 <        $self->{toolbox}=$self->{area}->toolbox();
26 <        $self->{projconfigdir}=$self->{area}->configurationdir();
27 <        $self->{localtop}=$self->{area}->location();
28 <        $self->{releasearea}=$self->{area}->linkarea();
29 <        if ( ! defined $self->{releasearea} ) {
30 <           $self->{releasearea}=$self->{area};
31 <        }
32 <        $self->{releasetop}=$self->{releasearea}->location();
33 <        $self->{buildfilename}="BuildFile";
34 <        $self->verbosity(1);
35 <        $self->_configurationsetup();
23 >        $self->{toolbox}=shift;
24          return $self;
25   }
26  
27 < sub _generateexternals {
28 <        my $self=shift;
29 <        my $outfile=shift;
30 <
31 <        # -- specify these files for dependency information
32 <        my $depfile=$self->{projconfigdir}."/External_Dependencies";
33 <
34 <        # -- get list of dependent files
35 <        my $datadir=$self->{localtop}."/.SCRAM/".$ENV{SCRAM_ARCH};
36 <        $fdir=FileHandle->new();
37 <        opendir $fdir, $datadir;
38 <        my @depfiles=grep !/^\.\.?$/, readdir $fdir;
39 <        undef $fdir;
40 <        for (my $i=0; $i<=$#depfiles; $i++ ) {
41 <           $depfiles[$i]=$datadir."/".$depfiles[$i];
42 <        }
43 <
44 <        # -- do we need to rebuild?
45 <        if ( SCRAMUtils::dated($outfile,@depfiles) ) {
46 <          print "Configuring Local Area\n";
47 <          # -- open output file
48 <          my $fout=FileHandle->new();
49 <          $fout->open(">".$outfile) or die "Unable to open $outfile for output".
50 <                                        $!."\n";
51 <
52 <          # -- print out tool/version info
53 <          my ($tool,$toolobj,$f,$val,$version);
54 <          foreach $tool ( $self->{toolbox}->tools() ) {
55 <            $version=$self->{toolbox}->defaultversion($tool);
56 <            # default versions
57 <            print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
58 <            # -- set up the different version  -- externals
59 <            foreach $version ( $self->{toolbox}->versions($tool) ) {
60 <             $toolobj=$self->{toolbox}->gettool($tool,$version);
61 <             @deps=$toolobj->getfeature("_externals");
62 <             foreach $d ( @deps ) {
63 <              $d=~tr[A-Z][a-z];
64 <              print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
65 <             }
66 <             # -- tool info
67 <             print $fout "ifdef ".$tool."_V_".$version."\n";
68 <             foreach $f ( $toolobj->features() ) {
69 <              foreach $val ( $toolobj->getfeature($f) ) {
70 <                print $fout "\t".$f." += ".$val."\n";
71 <              }
72 <             }
73 <             print $fout "endif\n";
27 > sub _generateexternals
28 >   ###############################################################
29 >   # _generateexternals                                          #
30 >   ###############################################################
31 >   # modified : Thu Jul 12 12:06:50 2001 / SFA                   #
32 >   # params   :                                                  #
33 >   #          :                                                  #
34 >   #          :                                                  #
35 >   #          :                                                  #
36 >   # function :                                                  #
37 >   #          :                                                  #
38 >   #          :                                                  #
39 >   ###############################################################
40 >   {
41 >   my $self=shift;
42 >   my $outfile=shift;
43 >
44 >   # -- specifiy these files for dependency information
45 >   # NB: This file is never used!
46 >  
47 >   my $depfile=$ENV{projconfigdir}."/External_Dependencies";
48 >  
49 >   # -- get list of dependent files
50 >   my $datadir=$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH};
51 >   $fdir=FileHandle->new();
52 >   opendir $fdir, $datadir;
53 >   my @depfiles=grep !/^\.\.?$/, readdir $fdir;
54 >   undef $fdir;
55 >  
56 >   for (my $i=0; $i<=$#depfiles; $i++ )
57 >      {
58 >      $depfiles[$i]=$datadir."/".$depfiles[$i];
59 >      }
60 >  
61 >   # -- do we need to rebuild?
62 >   if ( SCRAMUtils::dated($outfile,@depfiles) )
63 >      {
64 >      print "Configuring Local Area\n";
65 >      # -- open output file
66 >      my $fout=FileHandle->new();
67 >      $fout->open(">".$outfile) or die "Unable to open $outfile for output".
68 >         $!."\n";
69 >
70 >      # -- print out tool/ version info
71 >      my ($tool,$toolobj,$f,$val,$version);
72 >          
73 >      foreach $tool ( $self->{toolbox}->tools() )
74 >         {
75 >         $version=$self->{toolbox}->defaultversion($tool);
76 >        
77 >         # default versions
78 >         print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
79 >
80 >         # -- set up the different version  -- externals
81 >         foreach $version ( $self->{toolbox}->versions($tool) )
82 >            {
83 >            $toolobj=$self->{toolbox}->gettool($tool,$version);
84 >            @deps=$toolobj->getfeature("_externals");
85 >            #
86 >            foreach $d ( @deps )
87 >               {
88 >               $d=~tr[A-Z][a-z];
89 >               print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
90 >               }
91 >            # -- tool info
92 >            print $fout "ifdef ".$tool."_V_".$version."\n";
93 >            
94 >            foreach $f ( $toolobj->features() )
95 >               {
96 >               foreach $val ( $toolobj->getfeature($f) )
97 >                  {
98 >                  print $fout "\t".$f." += ".$val."\n";
99 >                  }
100 >               }
101 >            # -- include any makefiles associated with the tool
102 >            if ( -f $self->{toolbox}->toolmakefile($tool,$version) )
103 >               {
104 >               print $fout "-include ".
105 >                  $self->{toolbox}->toolmakefile($tool,$version)."\n";
106 >               }
107 >            print $fout "endif\n";
108              }
109 <          }
110 <          # -- some addittional processing of specific vars
111 <          print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
112 <          print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
113 <          print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
114 <          print $fout 'lib+=$(extralib)'."\n";
115 <          print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
116 <          print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
117 <
118 <          undef $fout;
119 <          $self->verbose("End Externals Configuration Setup");
120 <        }
121 < }
100 <
101 < sub classsetup {
102 <        my $self=shift;
103 <        my $THISDIR=shift;
104 <
105 <        my $classmakefile;
106 <
107 <        my ($Class, $ClassDir, $bf)=$self->getclass2($THISDIR);
108 <        $self->verbose("Class = $Class : ClassDir = $ClassDir for directory ".
109 <                        $THISDIR);
110 <
111 <        # -- should we ignore?
112 <        if ( $bf->ignore() ) {
113 <           print "Nothing to be done - empty group\n";
114 <           exit;
115 <        }      
116 <
117 <
118 <        # -- Create a makefile from the class BuildFile
119 <        my $classbuildfile=$self->{localtop}."/".
120 <                $self->{projconfigdir}."/".$Class."_BuildFile";
121 <        if ( -f $classbuildfile ) {
122 <              $classmakefile=$self->{localtop}."/".$ENV{INTwork}.
123 <                                        "/".$Class."_makefile.mk";
124 <              if ( SCRAMUtils::dated($classmakefile, $classbuildfile) ) {
125 <                # -- generate the new makefile if out of date
126 <                $self->verbose("Generating $classmakefile from".
127 <                                                " $classbuildfile");
128 <                my $classbf=BuildSystem::BuildFile->new($self->{area});
129 <                undef $ENV{LatestBuildFile}; # gets set by BuildFile
130 <                $classbf->GenerateMakefile($classbuildfile, $classmakefile);
131 <                undef $ENV{LatestBuildFile}; # gets set by BuildFile
132 <              }
133 <        }
134 <        else {
135 <           # -- No BuildFile - maybe its old style makefile
136 <              $classmakefile=$self->{localtop}."/".
137 <              $self->{projconfigdir}."/".$Class."_makefile.mk";
138 <              if ( ! -f $classmakefile ) {
139 <                   $self->error("Unable to find matching ".$Class.
140 <                                "_BuildFile or ".$Class."_makefile.mk");
141 <              }
142 <        }
143 <        # -- set LatestBuildFile
144 <        if ( $bf->buildfile() ne "" ) {
145 <          $ENV{LatestBuildFile}=$bf->makefile();
146 <        }
147 <        else {
148 <          $ENV{LatestBuildFile}=$self->{topbf}->makefile();
149 <        }
150 <
151 <        return ($Class,$ClassDir,$classmakefile);
152 < }
153 <
154 < sub _blockdir {
155 <        my $self=shift;
156 <        my $dir=shift;
157 <
158 <        if ( ! defined $self->{blocks}{$dir} ) {
159 <           $self->{blocks}{$dir}=BuildSystem::Block->new();
160 <        }
161 <        return $self->{blocks}{$dir};
162 < }
163 <
164 < sub _configurationsetup {
165 <        my $self=shift;
166 <
167 <        # -- set working directory
168 <        $self->{workdir}=$ENV{INTwork};
169 <        $self->{fullworkdir}=$self->{localtop}."/".$self->{workdir};
170 <
171 <        # -- make working directory
172 <        chdir $self->{localtop};
173 <        AddDir::adddir($self->{workdir});
174 <
175 <        # -- generate tool info
176 <        $self->_generateexternals($self->{fullworkdir}."/clientmakefile");
177 <
178 <        # -- process project BuildFile
179 <        $self->_topbuildfile();
180 < }
109 >         }
110 >      # some addittional processing of specific vars
111 >      print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
112 >      print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
113 >      print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
114 >      print $fout 'lib+=$(extralib)'."\n";
115 >      print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
116 >      print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
117 >      print $fout 'LD_LIBRARY_PATH:=$(subst $(space),:,$(LD_LIBRARY_PATH))'."\n";
118 >      
119 >      undef $fout;
120 >      }
121 >   }
122  
123 < sub BuildDir {
124 <        my $self=shift;
125 <        my $THISDIR=shift;
126 <        my @Targets=@_;
127 <        my $DefaultBuildFile="";
128 <
129 <        # -- Setup Class specifics
130 <        ($Class,$ClassDir,$classmakefile)=$self->classsetup($THISDIR);
131 <        $ENV{classmakefile}=$classmakefile;
132 <        $ENV{Class}=$Class;
133 <        $ENV{ClassDir}=$ClassDir;
134 <        $DefaultBuildFile=$ENV{classmakefile};
135 <        $ENV{DefaultBuildFile}=$DefaultBuildFile;
136 <
137 <        # -- Create working directory
138 <        my $workdir=$self->{workdir}."/".$ClassDir;
139 <        chdir $self->{localtop};
140 <        AddDir::adddir($workdir);
141 <        $ENV{workdir}=$workdir;
142 <        my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
143 <        chdir $fullworkdir || die "Unable to enter working directory $!";
123 > sub BuildSetup
124 >   {
125 >   ###############################################################
126 >   # BuildSetup                                                  #
127 >   ###############################################################
128 >   # modified : Fri Aug 10 16:57:03 2001 / SFA                   #
129 >   # params   :                                                  #
130 >   #          :                                                  #
131 >   #          :                                                  #
132 >   #          :                                                  #
133 >   # function : Build targets.                                   #
134 >   #          :                                                  #
135 >   #          :                                                  #
136 >   ###############################################################
137 >   my $self=shift;
138 >   my $THISDIR=shift;
139 >   my @Targets=@_;
140 >   my $DefaultBuildFile="";
141 >   my $Class="";
142 >
143 >   # -- Create working directory
144 >   chdir $ENV{LOCALTOP};
145 >   AddDir::adddir($ENV{INTwork}."/".$THISDIR);
146 >
147 >   my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
148 >   $self->verbose("Class = $Class");
149 >   $self->verbose("ClassDir = $ClassDir");
150          
151 <        # -- Set up some other useful variables for the Build
152 <        # set variables listing directories/files available
153 <        my $fh=FileHandle->new();
154 <        opendir $fh, "$self->{localtop}/$ClassDir";
155 <        my @allfiles= grep !/^\.\.?$/, readdir $fh;
156 <        undef $fh;
157 <        foreach $file ( @allfiles ) {
158 <         if ( -d "$self->{localtop}/$ClassDir/$file" ) {
159 <           $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
160 <         }
161 <         else {
162 <           $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
163 <         }
164 <        }
165 <        my $targetnumber=$#Targets;
166 <        $ENV{"MAKETARGETS"}="";
167 <        foreach $word ( @Targets ) {
168 <         if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
169 <           $targetnumber--;
170 <         }
171 <         else {
172 <          # set some variables for use in makefiles
173 <          $ENV{"MAKETARGET_".$word}=$word;
174 <          if ( $ENV{"MAKETARGETS"} ne "" ) {
175 <            $ENV{"MAKETARGETS"}=$ENV{"MAKETARGETS"}." ".$word;
176 <          }
177 <          else {
178 <            $ENV{"MAKETARGETS"}=$word;
179 <          }
180 <         }
181 <        }
151 >   if ( $bf->ignore() )
152 >      {
153 >      print "Nothing to be done - empty group\n";
154 >      exit;
155 >      }
156 >   shift;
157 >   $self->_generateexternals($ENV{LOCALTOP}."/".$ENV{INTwork}."/clientmakefile");
158 >
159 >   # set up the workdir variable
160 >   $ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
161 >   my $fullworkdir=$ENV{LOCALTOP}."/".$ENV{workdir};
162 >  
163 >   # set up projdeps variable
164 >   my $projectfile=$ENV{projconfigdir}."/External_Dependencies";
165 >   if ( -e $ENV{LOCALTOP}."/".$projectfile )
166 >      {
167 >      $ENV{projdeps}=$ENV{LOCALTOP}."/".$projectfile;
168 >      }
169 >   elsif ( -e $ENV{RELEASETOP}."/".$projectfile )
170 >      {
171 >      $ENV{projectfile}=$ENV{RELEASETOP}."/".$projectfile;
172 >      }
173 >   if ( $DefaultBuildFile eq "" )
174 >      {
175 >      # Map Relevant makefile classmakefile directory
176 >      my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk";
177 >      if ( -e $ENV{LOCALTOP}."/".$classmakefile )
178 >         {
179 >         $ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile;
180 >         }
181 >      elsif ( -e $ENV{RELEASETOP}."/".$classmakefile )
182 >         {
183 >         $ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile;
184 >         }
185 >      else
186 >         {
187 >         print "\nUnable to locate $classmakefile\n";
188 >         print " Not in $ENV{LOCALTOP}\n";
189 >         print " Not in $ENV{RELEASETOP}\n";
190 >         exit 1;
191 >         }
192 >      $DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override
193 >      }
194 >  
195 >   $ENV{ClassDir}=$ClassDir;
196 >   $ENV{Class}=$Class;
197 >   $ENV{DefaultBuildFile}=$DefaultBuildFile;
198 >  
199 >   chdir $fullworkdir || die "Unable to enter working directory $!";
200 >
201 >   # Set up some other useful variables fo the Build
202 >   # list of directories available
203 >   opendir IDR, "$ENV{LOCALTOP}/$THISDIR";
204 >   @allfiles= grep !/^\.\.?$/, readdir IDR;
205 >   foreach $file ( @allfiles )
206 >      {
207 >      if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" )
208 >         { # only add if its a directory
209 >         $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
210 >         }
211 >      else
212 >         {
213 >         $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
214 >         }
215 >      }
216 >   $targetnumber=$#Targets;
217  
218 <       # -- If target not specified default to the class name target
219 <       if ( $targetnumber == -1 ) {
220 <        push @Targets,$Class;
221 <       }
218 >   foreach $word ( @Targets )
219 >      {
220 >      if ( $word=~/.*=.*/ )
221 >         { # if we have an assignment it cant be a target
222 >         $targetnumber--;
223 >         }
224 >      elsif ( $word=~/^-/ )
225 >         {
226 >         $targetnumber--;
227 >         }
228 >      else
229 >         {
230 >         $ENV{"MAKETARGET_".$word}=$word;
231 >         }
232 >      }
233  
234 <    $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
234 >   # If not specified default to the class name target
235 >   if ( $targetnumber == -1 )
236 >      {
237 >      push @Targets,$Class;
238 >      }
239  
240 +   $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
241  
242 <    $SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
243 <    if ( -f $SCRAM_GROUPSDIR ) {
242 >   $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
243 >   if ( -f $SCRAM_GROUPSDIR )
244 >      {
245        $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
246 <    }
247 <
248 <    # Do a datestamp check so that make will build files that have changed
249 <    # rather than just those which are older than their dependencies
250 <    $self->_checkdatestampindir($ClassDir);
251 <
252 <
253 <    # The main build here
254 <    $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}", @Targets);
255 <    return $rv/256; # return the exit status of gmake
256 <        
257 < }
258 <
259 < sub BuildIt {
260 <        my $self=shift;
261 <        my $dir=shift;
262 <        my @Targets=@_;
263 <
264 <
265 <        # -- get the top building block
266 <        my $topblock=$self->_gettopblock();
267 <        $ENV{LatestBuildFile}=$self->_gettopbf()->makefile();
268 <
269 <        # -- is there a class block associated with the directory?
270 <        my ($Class,$ClassDir)=getclass($dir);
271 <        $self->verbose("Using Class $Class");
272 <        my $classblock=$self->_getclassblock($Class,$topblock);
273 <
274 <        # -- If target not specified default to the class name target
275 <        if ( $targetnumber == -1 ) {
276 <          push @Targets,$Class;
277 <        }
279 <
280 <        # -- Create working directory
281 <        my $workdir=$self->{workdir}."/".$ClassDir;
282 <        chdir $self->{localtop};
283 <        AddDir::adddir($workdir);
284 <        $ENV{workdir}=$workdir;
285 <        my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
286 <        chdir $fullworkdir || die "Unable to enter working directory $!";
287 <        $self->verbose("Working area setup");
288 <
289 <        # -- Search for Blocks up to tree root
290 <        my @dirblocks=();
291 <        my @dirs=split /\//, $dir;
292 <        my $fulldir="";
293 <        my $currentblock=$classblock;
294 <        foreach $dire ( @dirs ) {
295 <              ($fulldir eq "")?$fulldir=$dire
296 <                              :$fulldir=$fulldir."/".$dire;  
297 <              $self->verbose("Searching $fulldir for Block");
298 <              my $block=$self->_getdirblock($fulldir,$currentblock);
299 <              if ( defined $block ) {
300 <                 $currentblock=$block;
301 <              }
302 <              $ENV{LatestBuildFile}=$self->gettopbf()->makefile();
303 <        }
304 <
305 <        # -- Create a makefile to include both BuildFile and
306 <        #    class makefile
307 <
308 <        my $fh=FileHandle->new();
309 <        my $mfile=$fullworkdir."/BuildFile.mk";
310 <        $self->verbose("Building makefile $mfile");
311 <        $fh->open(">".$mfile);
312 <        $fh->autoflush(1);
313 <        if ( -e $ENV{LatestBuildFile} ) {
314 <          print $fh "include $ENV{LatestBuildFile}\n";
315 <        }
316 <
317 <        # -- Parse the local BuildFile
318 <        my $dbf=$self->_getdirbf($dir);
319 <        if ( defined $dbf ) {
320 <          $dbf->Parsetofh($fh,$currentblock);
321 <        }
322 <
323 <        # -- Parse the class BuildFile
324 <        my $cbf=$self->_getclassbf($Class);
325 <        if ( defined $cbf ) {
326 <          $cbf->Parsetofh($fh,$currentblock);
327 <        }
328 <        $fh->close();                  
329 <        $ENV{DefaultMakefile}=$mfile;
330 <
331 <        # -- Hack around make by checking datestamps in local working and
332 <        #    in _class_ working directories
333 <        $self->_checkdatestampindir($ClassDir);
334 <        opendir $fh, $ClassDir;
335 <        my @dfiles= grep { -d $_ } readdir $fh;
336 <        undef $fh;
337 <        foreach $dir ( @dfiles ) {
338 <          if ( $dir=~/^_class_/ ) {
339 <           $self->_checkdatestampindir($ClassDir."/".$dir);
340 <          }
341 <        }
342 <
343 <        # -- Call gmake to do the actual build
344 <        $rv=system("gmake","--no-print-directory","-r","-k","-f",
345 <                "$mfile","-I$ENV{TOOL_HOME}", @Targets);
346 <        return $rv/256; # return the exit status of gmake  
347 < }
348 <
349 < #
350 < # -- Block generation Routines
351 < #
352 <
353 < sub _getclassblock {
354 <        my $self=shift;
355 <        my $key=shift;
356 <
357 <        if ( ! defined $self->{classblocks}{$key} ) {
358 <            $self->verbose("Initialising Class Block $key");
359 <            $self->{classblocks}{$key}=BuildSystem::Block->new();
360 <            # -- get class buildfile
361 <            my $bf=$self->_getclassbf($key);
362 <            if ( @_ ) {
363 <              $self->{classblocks}{$key}->parent(shift);
364 <            }
365 <            $bf->BlockParse($self->{classblocks}{$key});
366 <            $self->verbose("Initialisation Complete for Class Block $key");
367 <        }
368 <        return $self->{classblocks}{$key};
369 <
370 < }
371 <
372 < sub _gettopblock {
373 <        my $self=shift;
374 <
375 <        if ( ! defined $self->{topblocks} ) {
376 <            $self->verbose("Initialising Top Block");
377 <            $self->{topblock}=BuildSystem::Block->new();
378 <            # -- get class buildfile
379 <            my $bf=$self->_gettopbf();
380 <            if ( @_ ) {
381 <              $self->{topblock}->parent(shift);
382 <            }
383 <            $bf->BlockParse($self->{topblock});
384 <            $self->verbose("Initialisation Complete for Top Block");
385 <        }
386 <        return $self->{topblock};
387 < }
388 <
389 < sub _getdirblock {
390 <        my $self=shift;
391 <        my $dir=shift;
392 <        my $block=shift;
393 <
394 <        if ( defined $dir || $dir ne "" ) {
395 <        if ( ! defined $self->{blocks}{$dir} ) {
396 <          # -- get a buildfile and do a block parse
397 <          $self->{blocks}{$dir}=BuildSystem::Block->new();
398 <          my $bf=$self->_getbuildfile($dir);
399 <          $self->{blocks}{$dir}->parent($block);
400 <          $bf->blockparse($self->{blocks}{$dir});
401 <        }
402 <        return $self->{blocks}{$dir};
403 <        }
404 <        return undef;
405 < }
406 <
407 < #
408 < # -- BuildFile generation routines
409 < #
410 <
411 < sub _getclassbf {
412 <        my $self=shift;
413 <        my $class=shift;
414 <
415 <        if ( ! defined $self->{classbf}{$class} ) {
416 <          $self->verbose("Initialising Class BuildFile $class");
417 <          # -- determine BuildFile or makefile
418 <          my $fname=$self->{localtop}."/".$self->{projconfigdir}.
419 <                                                        "/".$class."_";
420 <          if ( -f $fname.$self->{buildfilename} ) {
421 <             $fname=$fname.$self->{buildfilename};
422 <          }
423 <          elsif ( -f $fname."makefile.mk" ) {
424 <             $fname=$fname."makefile.mk";
425 <          }
426 <          else {
427 <             $self->error("$fname".$self->{buildfilename}." does not exist in ".
428 <                        $self->{projconfigdir});
429 <          }
430 <
431 <          # -- create a BuildFile object
432 <          $self->{classbf}{$class}=BuildSystem::BuildFile->new($self->{area});
433 <          $self->{classbf}{$class}->buildfile($fname);
434 <          $self->verbose("Finished Initialising Class BuildFile $class");
435 <        }
436 <        return $self->{classbf}{$class};
437 < }
438 <
439 < sub _gettopbf {
440 <        my $self=shift;
441 <
442 <        if ( ! defined $self->{topbf} ) {
443 <          $self->{topbf}=BuildSystem::BuildFile->new($self->{area});
444 <          $self->{topbf}->buildfile($self->{localtop}."/".
445 <                        $self->{projconfigdir}."/".$self->{buildfilename});
446 <        }
447 <        return $self->{topbf};
448 < }
449 <
450 < #
451 < # Returns undef if BF does not exist at this dir level
452 < #
453 < sub _getdirbf {
454 <        my $self=shift;
455 <        my $dir=shift;
456 <
457 <        if ( ! exists $self->{dirbf}{$dir} ) {
458 <          $self->verbose("initialising dir BuildFile $dir");
459 <          # -- determine if local or releasetop
460 <          my $fname=$self->{path}."/".$self->{buildfilename};
461 <          if ( -f $self->{localtop}."/".$fname ) {
462 <            $fname=$self->{localtop}."/".$fname;
463 <          }
464 <          elsif ( -f $self->{releasetop}."/".$fname ) {
465 <            $fname=$self->{releasetop}."/".$fname;
466 <          }
467 <          else {
468 <            $self->{dirbf}{$dir}=undef;
469 <            $self->verbose("initialisation complete for dir BuildFile $dir");
470 <            return $self->{dirbf}{$dir};
471 <          }
472 <
473 <          # -- construct the bf object
474 <          $self->{dirbf}{$dir}=BuildSystem::BuildFile->new($self->{area});
475 <          $self->{dirbf}{$dir}->buildfile($fname);
476 <
477 <          $self->verbose("initialisation complete for dir BuildFile $dir");
478 <        }
479 <        return $self->{dirbf}{$dir};
480 < }
246 >      }
247 >  
248 >   # Do a datestamp check so that make will build files that have changed
249 >   # rather than just those which are older than their dependencies
250 >   # The main build here
251 >   $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
252 >
253 >   print "\n","scram BUILDSYSTEM: V1.0  ****","\n";
254 >
255 >   my $gmakejobsflag = "-j";
256 >   chomp(my $currentOS = `uname`);
257 >  
258 >   # Only use -j option if there are more then 1 cpu's.....
259 >   if ( $currentOS eq "Linux" )
260 >      {
261 >      chomp($ncpu=`cat /proc/cpuinfo | grep -c processor`);
262 >      }
263 >   elsif ( $currentOS eq "SunOS" )
264 >      # How can you tell how many CPUs you've got in a Sun box?:
265 >      {
266 >      $ncpu = 1;
267 >      }
268 >   else
269 >      # Who knows what the OS is. Leave as default:
270 >      {
271 >      $npcu = 1;
272 >      }
273 >  
274 >   # Modify: try to force make to spawn more than one job (option: -j ).
275 >   $rv=system("gmake","--no-print-directory","$gmakejobsflag","$ncpu","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
276 >   return $rv/256; # return the exit status of gmake
277 >   }
278  
279 < sub getclass2 {
279 > sub getclass {
280      my $self=shift;
281      my $dirname = shift;
282      my $Class="DEFAULT";
283      my $ClassDir="";
284          
285      #return if $dirname eq "";
286 <    my @DIRA=split /\//, $dirname;
286 >    @DIRA=split /\//, $dirname;
287  
288 <    my $thispath=".";
289 <    # -- construct all class buildfiles in the path
288 >    $thispath=".";
289 >    # bootstrap from project buildfile if it exists
290 >    my $bf=BuildSystem::BuildFile->new($self->{toolbox});
291 >    $bf->CheckBuildFile($ENV{projconfigdir});
292 >
293 >    my @ClassPaths=split /:/, $bf->BlockClassPath();
294 >    foreach $BClassPath ( @ClassPaths ) {
295 >      next if ( $BClassPath eq "");
296 >      push @LoBCA, [ split /\//, $BClassPath ];
297 >    }
298      for ( $i=0; $i<=$#DIRA; $i++ ) {
299 <        #$thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
300 <        $thispath=$thispath."/".$DIRA[$i];
301 <        if ( ! exists $self->{pathbf}{$thispath} ) {
497 <          $self->verbose("Initialising BuildFile in $thispath");
498 <          $self->{pathbf}{$thispath}=$self->_startbuildfile($thispath);
499 <        }
500 <        # -- check class overriden by BuildFile
501 <        if ( defined $self->{pathbf}{$thispath}->classname() ) {
502 <                $Class=$self->{pathbf}{$thispath}->classname();
299 >        $thispath=$thispath."/".$DIRA[$i];
300 >        if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
301 >                $Class=$ClassName;
302                  $ClassDir=$thispath;
303          }
304 +        # TODO --- Must test against position of last new BlockCaseA
305 +        # Need to reset array LoBCA to the New BlockPath
306 +        # - merge and replace options
307 +        #
308          else {
309 <          # -- sort it out from classpath directives
310 <          foreach $BlockClassA ( @{$self->{LoBCA}} ) {
311 <           next if ( $#{$BlockClassA} < $i );
509 <           $elem=${$BlockClassA}[$i];
510 <            if ( $elem=~/^$DIRA[$i]\+/ ) {
511 <                $elem=~s/^$DIRA[$i]//;
309 >          foreach $BlockClassA ( @LoBCA ) {
310 >            if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
311 >                $$BlockClassA[0]=~s/^$DIRA[$i]//;
312              }
313 <            #print $elem." ".$DIRA[$i]."\n";
314 <            if ( $elem=~/^\+/ ) {
515 <                ($Class=$elem)=~s/^\+//;
313 >            if ( $$BlockClassA[0]=~/^\+/ ) {
314 >                ($Class=$$BlockClassA[0])=~s/^\+//;
315                  $ClassDir=$thispath;
316 +                shift @$BlockClassA;
317 +            }
318 +            else {
319 +                @$BlockClassA=();
320              }
518          #}
519         }
520        }
521    }
522    # -- default case
523    if ( $ClassDir eq "" ) {
524      if ( ! defined $self->{pathbf}{'.'}) {
525          $self->{pathbf}{'.'}=$self->_startbuildfile(".");
526          $self->verbose("DEFAULT class initialised : ".$self->{pathbf}{'.'});
527      }
528      $ClassDir=".";
529    }
530
531    # -- returns
532    ($ClassDir_c=$ClassDir)=~s/^\.\///;
533    return ( $Class, $ClassDir_c, $self->{pathbf}{$ClassDir});
534 }
535
536 sub getclass {
537        my $self=shift;
538        my $dirname = shift;
539
540        my $Class="DEFAULT";
541        my $ClassDir=".";
542        
543        # return if $dirname eq "";
544        my @DIRA=split /\//, $dirname;
545
546        my $thispath="";
547        for ( $i=0; $i<=$#DIRA; $i++ ) {
548          $thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
549
550          # -- sort it out from classpath directives
551          foreach $BlockClassA ( @{$self->{LoBCA}} ) {
552           next if ( $#{$BlockClassA} < $i );
553           $elem=${$BlockClassA}[$i];
554            if ( $elem=~/^$DIRA[$i]\+/ ) {
555                $elem=~s/^$DIRA[$i]//;
556            }
557            #print $elem." ".$DIRA[$i]."\n";
558            if ( $elem=~/^\+/ ) {
559                ($Class=$elem)=~s/^\+//;
560                $ClassDir=$thispath;
561            }
562          }
563        }
564        return ( $Class, $ClassDir );
565 }
566
567 #
568 # Check to see if the buildfile is local or in the release area and
569 # parse appropriately
570 #
571 sub _startbuildfile {
572         my $self=shift;
573         my $classdir=shift;
574
575         my $bf=BuildSystem::BuildFile->new($self->{area});
576         my $thisfile="$classdir/$self->{buildfilename}";
577
578         if ( -e $self->{localtop}."/".$thisfile ) {
579            $bf->buildfile($self->{localtop}."/".$thisfile);
580            $bf->ParseBuildFile($self->{localtop}, $classdir,
581                                $self->{buildfilename});
582         }
583         elsif ( -e $self->{releasetop}."/".$thisfile ) {
584            $bf->buildfile($self->{releasetop}."/".$thisfile);
585            $bf->ParseBuildFile($self->{releasetop}, $classdir,
586                                                $self->{buildfilename});
587         }
588         return $bf;
589 }
590
591 sub _topbuildfile {
592    my $self=shift;
593
594    $self->verbose("Generating Top Level BuildFile");
595    # -- Analyse project buildfile if it exists
596
597    my $topbf=$self->_gettopbf();
598
599    # -- generate top level makefile
600    undef $ENV{LatestBuildFile};
601    $topbf->ParseBuildFile($self->{localtop},
602                        $self->{projconfigdir},$self->{buildfilename});
603
604    # -- Extract BuildStructure Information
605    my @ClassPaths=split /:/, $self->{topbf}->BlockClassPath();
606    foreach $BClassPath ( @ClassPaths ) {
607      next if ( $BClassPath eq "");
608      push @{$self->{LoBCA}}, [ split /\//, $BClassPath ];
609    }
610    $self->verbose("End top buildfile generation");
611 }
612
613 sub _checkdatestampindir {
614        my $self=shift;
615        my $dir=shift;
616        
617        # -- get all local .ds files
618        my $fh=FileHandle->new();
619        my $ldir=$self->{localtop}."/".$self->{workdir}."/".$dir;
620        opendir $fh, $ldir;
621        my @dsfiles= grep /^.*\.ds$/, readdir $fh;
622        $fh->close();                  
623
624        # -- copy across ds files from releasetop if not existing locally
625        if ( $#dsfiles < 0 ) {
626          # -- get all releasetop .ds files
627          my $rdir=$self->{releasetop}."/".$self->{workdir}."/".$dir;
628          opendir $fh, $rdir;
629          my @releasedsfiles= grep /^.*\.ds$/, readdir $fh;
630          foreach $file ( @releasedsfiles ) {
631                use File::Copy;
632                $self->verbose("Copying $file from $rdir to $ldir");
633                copy($rdir."/".$file,$ldir."/".$file);
634          }
635          $fh->close();
636          @dsfiles=@releasedsfiles;
637        }
638
639        # -- process ds files
640        my $file;
641        foreach $datafile ( @dsfiles ) {
642          $self->verbose("Processing $ldir/$datafile\n");
643          my $ds=BuildSystem::DateStampRecord->new($ldir."/".$datafile);
644          $ds->verbosity($self->verbosity());
645          my $needsupdate;
646          my $productfile=$ds->product();
647          my (%files,%moddate);
648
649          # now get dates in our dependency list
650          my @datedfiles=$ds->dated();
651          if ( $#datedfiles >= 0 ) {
652            
653             $needsupdate=1;
654             $date=$datedfiles[0][1]-1;
655          }
656          else {
657           # -- extra checks for local replacement of files
658           foreach $file ( $ds->contents() ) {
659            # -- only check files
660            if ( -f $file ) {
661             $files{$file}=$ds->filedate($file);
662             # -- check to see if we have a new local copy
663             if ( ($file=~/\Q$self->{releasetop}\E/) &&
664                                ($self->{releasetop} ne $self->{localtop}) ) {
665              ($tempfile=$file)=~s/\Q$self->{releasetop}\E/$self->{localtop}/;
666              if ( -f $tempfile ) {
667                $files{$tempfile}=$files{$file};
668                $file=$tempfile;
669              }
670             }
671             $moddate{$file}=(stat($file))[9];
672             if ( $moddate{$file} != $files{$file} ) {
673              $self->verbose($file." changed");
674              $date=$moddate{$file}-1;
675              $needsupdate=1;
676             }
677            }
678           }
679          }
680          # time stamp the product file to be older than the dependencies
681          if ( $needsupdate == 1 ) { # touch file into the past
682          my $newproductfile;
683          if ( $productfile!~/\Q$self->{localtop}\E/ ) {
684           if ( $productfile=~/\Q$self->{releasetop}\E/ ) {
685             ($newproductfile=$productfile)=~
686                        s/\Q$self->{releasetop}\E/$self->{localtop}/;
687             $self->verbose("Copying $productfile to $newproductfile");
688             copy($productfile,$newproductfile);
689           }
690           else { # assume no path to worry about
691             $newproductfile=$self->{localtop}."/".$ENV{workdir}.
692                                                      "/".$productfile;
693              # -- make a local copy of the product file if not already here
694              my $oldproductfile=$self->{releasetop}."/".$ENV{workdir}.
695                                                        "/".$productfile;
696             if ( ! -f $newproductfile ) {
697              if ( -f $oldproductfile ) {  
698                $self->verbose("Copying $oldproductfile to $newproductfile");
699                copy($oldproductfile,$newproductfile);
700              }
701             }
702           }
703          }
704          else {
705             $newproductfile=$productfile;
321            }
707          if ( -f $newproductfile ) {
708            $self->verbose("Blasting $newproductfile to the past ($date)");
709            # If the (local) productfile exists - make it older
710            utime($date,$date,$newproductfile);
711          }
712          else {
713            $self->verbose("SomeThing Wrong(?) with $newproductfile\n".
714                "RELEASETOP=".$self->{releasetop}."\n".
715                "LOCALTOP=".$self->{localtop}."\n".
716                "workdir=".$ENV{workdir});
717          }
322          }
323 <        else {
324 <          $self->verbose("No need to touch $productfile");
325 <        }      
722 <        }
723 <        undef $fh;                  
323 >    }
324 >    $ClassDir=~s/^\.\///;
325 >    return ( $Class, $ClassDir, $bf);
326   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines