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.12 by williamc, Tue Nov 14 15:18:41 2000 UTC vs.
Revision 1.23 by sashby, Mon May 13 12:43:53 2002 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
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 < # setup(dir)
9 > #
10  
11   package BuildSystem::BuildSetup;
12   require 5.004;
13   use Utilities::Verbose;
14   use Utilities::SCRAMUtils;
15   use BuildSystem::BuildFile;
16 use BuildSystem::BuildRecorder;
17 use BuildSystem::DateStampRecord;
18 use BuildSystem::Block;
16   use Utilities::AddDir;
17   @ISA=qw(Utilities::Verbose);
18  
# Line 23 | Line 20 | sub new {
20          my $class=shift;
21          my $self={};
22          bless $self,$class;
23 <        $self->{area}=shift;
27 <        $self->{toolbox}=$self->{area}->toolbox();
28 <        $self->{projconfigdir}=$self->{area}->configurationdir();
29 <        $self->{localtop}=$self->{area}->location();
30 <        $self->{releasearea}=$self->{area}->linkarea();
31 <        if ( ! defined $self->{releasearea} ) {
32 <           $self->{releasearea}=$self->{area};
33 <        }
34 <        $self->{releasetop}=$self->{releasearea}->location();
35 <        $self->{buildfilename}="BuildFile";
36 <        $self->verbosity(1);
37 <        $self->_configurationsetup();
38 <        # -- clean up from any previous builds
39 <        $self->{BuildDBfile}=$self->{localtop}."/".
40 <                                $self->{workdir}."/BuildRecorderFile";
41 <        if ( -f $self->{BuildDBfile} ) {
42 <           unlink $self->{BuildDBfile};
43 <        }
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              }
95          }
96          # -- some addittional processing of specific vars
97          print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
98          print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
99          print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
100          print $fout 'lib+=$(extralib)'."\n";
101          print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
102          print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
103          print $fout 'LD_LIBRARY_PATH:=$(subst $(space),:,$(LD_LIBRARY_PATH))'."\n";
104
105          undef $fout;
106          $self->verbose("End Externals Configuration Setup");
107        }
108 }
109
110 sub classsetup {
111        my $self=shift;
112        my $THISDIR=shift;
113
114        my $classmakefile;
115
116        my ($Class, $ClassDir, $bf)=$self->getclass2($THISDIR);
117        $self->verbose("Class = $Class : ClassDir = $ClassDir for directory ".
118                        $THISDIR);
119
120        # -- should we ignore?
121        if ( $bf->ignore() ) {
122           print "Nothing to be done - empty group\n";
123           exit;
124        }
125
126
127        # -- Create a makefile from the class BuildFile
128        my $classbuildfile=$self->{localtop}."/".
129                $self->{projconfigdir}."/".$Class."_BuildFile";
130        if ( -f $classbuildfile ) {
131              $classmakefile=$self->{localtop}."/".$ENV{INTwork}.
132                                        "/".$Class."_makefile.mk";
133              if ( SCRAMUtils::dated($classmakefile, $classbuildfile) ) {
134                # -- generate the new makefile if out of date
135                $self->verbose("Generating $classmakefile from".
136                                                " $classbuildfile");
137                my $classbf=BuildSystem::BuildFile->new($self->{area},$self);
138                undef $ENV{LatestBuildFile}; # gets set by BuildFile
139                $classbf->GenerateMakefile($classbuildfile, $classmakefile);
140                undef $ENV{LatestBuildFile}; # gets set by BuildFile
141              }
142        }
143        else {
144           # -- No BuildFile - maybe its old style makefile
145              $classmakefile=$self->{localtop}."/".
146              $self->{projconfigdir}."/".$Class."_makefile.mk";
147              if ( ! -f $classmakefile ) {
148                   $self->error("Unable to find matching ".$Class.
149                                "_BuildFile or ".$Class."_makefile.mk");
150              }
151        }
152        # -- set LatestBuildFile
153        if ( $bf->buildfile() ne "" ) {
154          $ENV{LatestBuildFile}=$bf->makefile();
155        }
156        else {
157          $ENV{LatestBuildFile}=$self->{topbf}->makefile();
158        }
159
160        return ($Class,$ClassDir,$classmakefile);
161 }
162
163 sub _configurationsetup {
164        my $self=shift;
165
166        # -- set working directory
167        $self->{workdir}=$ENV{INTwork};
168        $self->{fullworkdir}=$self->{localtop}."/".$self->{workdir};
169
170        # -- make working directory
171        chdir $self->{localtop};
172        AddDir::adddir($self->{workdir});
173
174        # -- generate tool info
175        $self->_generateexternals($self->{fullworkdir}."/clientmakefile");
176
177        # -- process project BuildFile
178        $self->_topbuildfile();
179 }
180
181 sub BuildDir {
182        my $self=shift;
183        my $THISDIR=shift;
184        my @Targets=@_;
185        my $DefaultBuildFile="";
186
187        # -- Setup Class specifics
188        ($Class,$ClassDir,$classmakefile)=$self->classsetup($THISDIR);
189        $ENV{classmakefile}=$classmakefile;
190        $ENV{Class}=$Class;
191        $ENV{ClassDir}=$ClassDir;
192        $DefaultBuildFile=$ENV{classmakefile};
193        $ENV{DefaultBuildFile}=$DefaultBuildFile;
194
195        # -- Create working directory
196        my $workdir=$self->{workdir}."/".$ClassDir;
197        chdir $self->{localtop};
198        AddDir::adddir($workdir);
199        $ENV{workdir}=$workdir;
200        my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
201        chdir $fullworkdir || die "Unable to enter working directory $!";
202
203        # -- Set up some other useful variables for the Build
204        # set variables listing directories/files available
205        my $fh=FileHandle->new();
206        opendir $fh, "$self->{localtop}/$ClassDir";
207        my @allfiles= grep !/^\.\.?$/, readdir $fh;
208        undef $fh;
209        foreach $file ( @allfiles ) {
210         if ( -d "$self->{localtop}/$ClassDir/$file" ) {
211           $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
212         }
213         else {
214           $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
215         }
216        }
217        my $targetnumber=$#Targets;
218        $ENV{"MAKETARGETS"}="";
219        foreach $word ( @Targets ) {
220         if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
221           $targetnumber--;
222         }
223         else {
224          # set some variables for use in makefiles
225          $ENV{"MAKETARGET_".$word}=$word;
226          if ( $ENV{"MAKETARGETS"} ne "" ) {
227            $ENV{"MAKETARGETS"}=$ENV{"MAKETARGETS"}." ".$word;
228          }
229          else {
230            $ENV{"MAKETARGETS"}=$word;
231          }
232         }
233        }
234
235       # -- If target not specified default to the class name target
236       if ( $targetnumber == -1 ) {
237        push @Targets,$Class;
238       }
239
240    $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
241
242
243    $SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
244    if ( -f $SCRAM_GROUPSDIR ) {
245      $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
246    }
247
248
249    #
250    # Keep a track of what we have built this run
251    #
252    if ( ! defined $self->{BuildDB} ) {
253         my $file=$self->{BuildDBfile};
254         $self->{BuildDB}=BuildSystem::BuildRecorder->new($file);
255    }  
256    my $rv=0;
257    if ( ! $self->{BuildDB}->checked($ClassDir) ) {
258         if ( $Targets[0] eq $Class ) {
259         $self->{BuildDB}->checked($ClassDir,1); # Mark it as taken care of
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 +      # Hack to parse the lib list and remove duplicates:
116 +      print $fout 'ORDEREDLIB=$(shell $(SCRAMPERL) $(TOOL_HOME)/ProcessLibs $(lib))',"\n";
117 +      print $fout 'LDLIBS+=$(addprefix -l,$(ORDEREDLIB))'."\n";
118 +      #print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
119 +      print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
120 +      print $fout 'LD_LIBRARY_PATH:=$(subst $(space),:,$(LD_LIBRARY_PATH))'."\n";
121  
122 <         # Do a datestamp check so that make will build files that have changed
123 <         # rather than just those which are older than their dependencies
124 <         $self->_checkdatestampindir($ClassDir);
265 <
266 <         # -- The main build here
267 <         $rv=system("gmake","--no-print-directory","-r","-k","-f",
268 <                "$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}", @Targets);
269 <    }
270 <    return $rv/256; # return the exit status of gmake
271 <
272 < }
273 <
274 < # TODO - work in progress - replacement for BuildDir that can handle <Build> OK
275 < sub BuildIt {
276 <        my $self=shift;
277 <        my $dir=shift;
278 <        my @Targets=@_;
279 <
280 <
281 <        # -- get the top building block
282 <        my $topblock=$self->_gettopblock();
283 <        $ENV{LatestBuildFile}=$self->_gettopbf()->makefile();
284 <
285 <        # -- is there a class block associated with the directory?
286 <        my ($Class,$ClassDir)=getclass($dir);
287 <        $self->verbose("Using Class $Class");
288 <        my $classblock=$self->_getclassblock($Class,$topblock);
289 <
290 <        # -- If target not specified default to the class name target
291 <        if ( $targetnumber == -1 ) {
292 <          push @Targets,$Class;
293 <        }
294 <
295 <        # -- Create working directory
296 <        my $workdir=$self->{workdir}."/".$ClassDir;
297 <        chdir $self->{localtop};
298 <        AddDir::adddir($workdir);
299 <        $ENV{workdir}=$workdir;
300 <        my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
301 <        chdir $fullworkdir || die "Unable to enter working directory $!";
302 <        $self->verbose("Working area setup");
303 <
304 <        # -- Search for Blocks up to tree root
305 <        my @dirblocks=();
306 <        my @dirs=split /\//, $dir;
307 <        my $fulldir="";
308 <        my $currentblock=$classblock;
309 <        foreach $dire ( @dirs ) {
310 <              ($fulldir eq "")?$fulldir=$dire
311 <                              :$fulldir=$fulldir."/".$dire;
312 <              $self->verbose("Searching $fulldir for Block");
313 <              my $block=$self->_getdirblock($fulldir,$currentblock);
314 <              if ( defined $block ) {
315 <                 $currentblock=$block;
316 <              }
317 <              $ENV{LatestBuildFile}=$self->gettopbf()->makefile();
318 <        }
319 <
320 <        # -- Create a makefile to include both BuildFile and
321 <        #    class makefile
322 <
323 <        my $fh=FileHandle->new();
324 <        my $mfile=$fullworkdir."/BuildFile.mk";
325 <        $self->verbose("Building makefile $mfile");
326 <        $fh->open(">".$mfile);
327 <        $fh->autoflush(1);
328 <        if ( -e $ENV{LatestBuildFile} ) {
329 <          print $fh "include $ENV{LatestBuildFile}\n";
330 <        }
331 <
332 <        # -- Parse the local BuildFile
333 <        my $dbf=$self->_getdirbf($dir);
334 <        if ( defined $dbf ) {
335 <          $dbf->Parsetofh($fh,$currentblock);
336 <        }
337 <
338 <        # -- Parse the class BuildFile
339 <        my $cbf=$self->_getclassbf($Class);
340 <        if ( defined $cbf ) {
341 <          $cbf->Parsetofh($fh,$currentblock);
342 <        }
343 <        $fh->close();
344 <        $ENV{DefaultMakefile}=$mfile;
345 <
346 <        # -- Hack around make by checking datestamps in local working and
347 <        #    in _class_ working directories
348 <        $self->_checkdatestampindir($ClassDir);
349 <        opendir $fh, $ClassDir;
350 <        my @dfiles= grep { -d $_ } readdir $fh;
351 <        undef $fh;
352 <        foreach $dir ( @dfiles ) {
353 <          if ( $dir=~/^_class_/ ) {
354 <           $self->_checkdatestampindir($ClassDir."/".$dir);
355 <          }
356 <        }
357 <
358 <        # -- Call gmake to do the actual build
359 <        $rv=system("gmake","--no-print-directory","-r","-k","-f",
360 <                "$mfile","-I$ENV{TOOL_HOME}", @Targets);
361 <        return $rv/256; # return the exit status of gmake
362 < }
363 <
364 < #
365 < # -- Block generation Routines
366 < #
367 <
368 < sub _getclassblock {
369 <        my $self=shift;
370 <        my $key=shift;
371 <
372 <        if ( ! defined $self->{classblocks}{$key} ) {
373 <            $self->verbose("Initialising Class Block $key");
374 <            $self->{classblocks}{$key}=BuildSystem::Block->new();
375 <            # -- get class buildfile
376 <            my $bf=$self->_getclassbf($key);
377 <            if ( @_ ) {
378 <              $self->{classblocks}{$key}->parent(shift);
379 <            }
380 <            $bf->BlockParse($self->{classblocks}{$key});
381 <            $self->verbose("Initialisation Complete for Class Block $key");
382 <        }
383 <        return $self->{classblocks}{$key};
384 <
385 < }
386 <
387 < sub _gettopblock {
388 <        my $self=shift;
122 >      undef $fout;
123 >      }
124 >   }
125  
126 <        if ( ! defined $self->{topblocks} ) {
127 <            $self->verbose("Initialising Top Block");
128 <            $self->{topblock}=BuildSystem::Block->new();
129 <            # -- get class buildfile
130 <            my $bf=$self->_gettopbf();
131 <            if ( @_ ) {
132 <              $self->{topblock}->parent(shift);
133 <            }
134 <            $bf->BlockParse($self->{topblock});
135 <            $self->verbose("Initialisation Complete for Top Block");
136 <        }
137 <        return $self->{topblock};
138 < }
126 > sub BuildSetup
127 >   {
128 >   ###############################################################
129 >   # BuildSetup                                                  #
130 >   ###############################################################
131 >   # modified : Fri Aug 10 16:57:03 2001 / SFA                   #
132 >   # params   :                                                  #
133 >   #          :                                                  #
134 >   #          :                                                  #
135 >   #          :                                                  #
136 >   # function : Build targets.                                   #
137 >   #          :                                                  #
138 >   #          :                                                  #
139 >   ###############################################################
140 >   my $self=shift;
141 >   my $THISDIR=shift;
142 >   my @Targets=@_;
143 >   my $DefaultBuildFile="";
144 >   my $Class="";
145 >
146 >   # -- Create working directory
147 >   chdir $ENV{LOCALTOP};
148 >   AddDir::adddir($ENV{INTwork}."/".$THISDIR);
149 >
150 >   my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
151 >   $self->verbose("Class = $Class");
152 >   $self->verbose("ClassDir = $ClassDir");
153 >        
154 >   if ( $bf->ignore() )
155 >      {
156 >      print "Nothing to be done - empty group\n";
157 >      exit;
158 >      }
159 >   shift;
160 >   $self->_generateexternals($ENV{LOCALTOP}."/".$ENV{INTwork}."/clientmakefile");
161 >
162 >   # set up the workdir variable
163 >   $ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
164 >   my $fullworkdir=$ENV{LOCALTOP}."/".$ENV{workdir};
165 >  
166 >   # set up projdeps variable
167 >   my $projectfile=$ENV{projconfigdir}."/External_Dependencies";
168 >   if ( -e $ENV{LOCALTOP}."/".$projectfile )
169 >      {
170 >      $ENV{projdeps}=$ENV{LOCALTOP}."/".$projectfile;
171 >      }
172 >   elsif ( -e $ENV{RELEASETOP}."/".$projectfile )
173 >      {
174 >      $ENV{projectfile}=$ENV{RELEASETOP}."/".$projectfile;
175 >      }
176 >   if ( $DefaultBuildFile eq "" )
177 >      {
178 >      # Map Relevant makefile classmakefile directory
179 >      my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk";
180 >      if ( -e $ENV{LOCALTOP}."/".$classmakefile )
181 >         {
182 >         $ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile;
183 >         }
184 >      elsif ( -e $ENV{RELEASETOP}."/".$classmakefile )
185 >         {
186 >         $ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile;
187 >         }
188 >      else
189 >         {
190 >         print "\nUnable to locate $classmakefile\n";
191 >         print " Not in $ENV{LOCALTOP}\n";
192 >         print " Not in $ENV{RELEASETOP}\n";
193 >         exit 1;
194 >         }
195 >      $DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override
196 >      }
197 >  
198 >   $ENV{ClassDir}=$ClassDir;
199 >   $ENV{Class}=$Class;
200 >   $ENV{DefaultBuildFile}=$DefaultBuildFile;
201 >  
202 >   chdir $fullworkdir || die "Unable to enter working directory $!";
203 >
204 >   # Set up some other useful variables fo the Build
205 >   # list of directories available
206 >   opendir IDR, "$ENV{LOCALTOP}/$THISDIR";
207 >   @allfiles= grep !/^\.\.?$/, readdir IDR;
208 >   foreach $file ( @allfiles )
209 >      {
210 >      if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" )
211 >         { # only add if its a directory
212 >         $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
213 >         }
214 >      else
215 >         {
216 >         $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
217 >         }
218 >      }
219 >   $targetnumber=$#Targets;
220  
221 < sub _getdirblock {
222 <        my $self=shift;
223 <        my $dir=shift;
224 <        my $block=shift;
225 <
226 <        if ( defined $dir || $dir ne "" ) {
227 <        if ( ! defined $self->{blocks}{$dir} ) {
228 <          # -- get a buildfile and do a block parse
229 <          $self->{blocks}{$dir}=BuildSystem::Block->new();
230 <          my $bf=$self->_getbuildfile($dir);
231 <          $self->{blocks}{$dir}->parent($block);
232 <          $bf->blockparse($self->{blocks}{$dir});
233 <        }
234 <        return $self->{blocks}{$dir};
235 <        }
419 <        return undef;
420 < }
221 >   foreach $word ( @Targets )
222 >      {
223 >      if ( $word=~/.*=.*/ )
224 >         { # if we have an assignment it cant be a target
225 >         $targetnumber--;
226 >         }
227 >      elsif ( $word=~/^-/ )
228 >         {
229 >         $targetnumber--;
230 >         }
231 >      else
232 >         {
233 >         $ENV{"MAKETARGET_".$word}=$word;
234 >         }
235 >      }
236  
237 < #
238 < # -- BuildFile generation routines
239 < #
237 >   # If not specified default to the class name target
238 >   if ( $targetnumber == -1 )
239 >      {
240 >      push @Targets,$Class;
241 >      }
242  
243 < sub _getclassbf {
427 <        my $self=shift;
428 <        my $class=shift;
429 <
430 <        if ( ! defined $self->{classbf}{$class} ) {
431 <          $self->verbose("Initialising Class BuildFile $class");
432 <          # -- determine BuildFile or makefile
433 <          my $fname=$self->{localtop}."/".$self->{projconfigdir}.
434 <                                                        "/".$class."_";
435 <          if ( -f $fname.$self->{buildfilename} ) {
436 <             $fname=$fname.$self->{buildfilename};
437 <          }
438 <          elsif ( -f $fname."makefile.mk" ) {
439 <             $fname=$fname."makefile.mk";
440 <          }
441 <          else {
442 <             $self->error("$fname".$self->{buildfilename}." does not exist in ".
443 <                        $self->{projconfigdir});
444 <          }
445 <
446 <          # -- create a BuildFile object
447 <          $self->{classbf}{$class}=BuildSystem::BuildFile->new($self->{area},$self);
448 <          $self->{classbf}{$class}->buildfile($fname);
449 <          $self->verbose("Finished Initialising Class BuildFile $class");
450 <        }
451 <        return $self->{classbf}{$class};
452 < }
243 >   $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
244  
245 < sub _gettopbf {
246 <        my $self=shift;
245 >   $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
246 >   if ( -f $SCRAM_GROUPSDIR )
247 >      {
248 >      $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
249 >      }
250 >  
251 >   # Do a datestamp check so that make will build files that have changed
252 >   # rather than just those which are older than their dependencies
253 >   # The main build here
254 >
255 >   $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
256 >
257 >   # Be verbose:
258 >   $self->verbose(">> Going to use ".$ENV{DefaultMakefile}." as the default makefile");
259 >  
260 >   my $gmakejobsflag = "-j";
261 >   # Temporarily hard-code ncpu as 1:
262 >   my $ncpu = 1;
263  
264 <        if ( ! defined $self->{topbf} ) {
458 <          $self->{topbf}=BuildSystem::BuildFile->new($self->{area},$self);
459 <          $self->{topbf}->buildfile($self->{localtop}."/".
460 <                        $self->{projconfigdir}."/".$self->{buildfilename});
461 <        }
462 <        return $self->{topbf};
463 < }
464 < #
465 < # Returns undef if BF does not exist at this dir level
466 < #
467 < sub _getdirbf {
468 <        my $self=shift;
469 <        my $dir=shift;
470 <
471 <        if ( ! exists $self->{dirbf}{$dir} ) {
472 <          $self->verbose("initialising dir BuildFile $dir");
473 <          # -- determine if local or releasetop
474 <          my $fname=$self->{path}."/".$self->{buildfilename};
475 <          if ( -f $self->{localtop}."/".$fname ) {
476 <            $fname=$self->{localtop}."/".$fname;
477 <          }
478 <          elsif ( -f $self->{releasetop}."/".$fname ) {
479 <            $fname=$self->{releasetop}."/".$fname;
480 <          }
481 <          else {
482 <            $self->{dirbf}{$dir}=undef;
483 <            $self->verbose("initialisation complete for dir BuildFile $dir");
484 <            return $self->{dirbf}{$dir};
485 <          }
486 <
487 <          # -- construct the bf object
488 <          $self->{dirbf}{$dir}=BuildSystem::BuildFile->new($self->{area},$self);
489 <          $self->{dirbf}{$dir}->buildfile($fname);
264 >   $rv=system("gmake","--no-print-directory","$gmakejobsflag","$ncpu","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
265  
266 <          $self->verbose("initialisation complete for dir BuildFile $dir");
267 <        }
493 <        return $self->{dirbf}{$dir};
494 < }
266 >   return $rv/256; # return the exit status of gmake
267 >   }
268  
269 < sub getclass2 {
269 > sub getclass {
270      my $self=shift;
271      my $dirname = shift;
272      my $Class="DEFAULT";
273      my $ClassDir="";
274 +        
275 +    @DIRA=split /\//, $dirname;
276  
277 <    #return if $dirname eq "";
278 <    my @DIRA=split /\//, $dirname;
277 >    $thispath=".";
278 >    # bootstrap from project buildfile if it exists
279 >    my $bf=BuildSystem::BuildFile->new($self->{toolbox});
280 >    $bf->CheckBuildFile($ENV{projconfigdir});
281  
282 <    my $thispath=".";
283 <    # -- construct all class buildfiles in the path
282 >    my @ClassPaths=split /:/, $bf->BlockClassPath();
283 >    foreach $BClassPath ( @ClassPaths ) {
284 >      next if ( $BClassPath eq "");
285 >      push @LoBCA, [ split /\//, $BClassPath ];
286 >    }
287      for ( $i=0; $i<=$#DIRA; $i++ ) {
508        #$thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
288          $thispath=$thispath."/".$DIRA[$i];
289 <        if ( ! exists $self->{pathbf}{$thispath} ) {
290 <          $self->verbose("Initialising BuildFile in $thispath");
512 <          $self->{pathbf}{$thispath}=$self->_startbuildfile($thispath);
513 <        }
514 <        # -- check class overriden by BuildFile
515 <        if ( defined $self->{pathbf}{$thispath}->classname() ) {
516 <                $Class=$self->{pathbf}{$thispath}->classname();
517 <                $ClassDir=$thispath;
518 <        }
519 <        else {
520 <          # -- sort it out from classpath directives
521 <          foreach $BlockClassA ( @{$self->{LoBCA}} ) {
522 <           next if ( $#{$BlockClassA} < $i );
523 <           $elem=${$BlockClassA}[$i];
524 <            if ( $elem=~/^$DIRA[$i]\+/ ) {
525 <                $elem=~s/^$DIRA[$i]//;
526 <            }
527 <            #print $elem." ".$DIRA[$i]."\n";
528 <            if ( $elem=~/^\+/ ) {
529 <                ($Class=$elem)=~s/^\+//;
289 >        if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
290 >                $Class=$ClassName;
291                  $ClassDir=$thispath;
531            }
532          #}
533         }
292          }
293 <    }
294 <    # -- default case
295 <    if ( $ClassDir eq "" ) {
296 <      if ( ! defined $self->{pathbf}{'.'}) {
297 <          $self->{pathbf}{'.'}=$self->_startbuildfile(".");
298 <          $self->verbose("DEFAULT class initialised : ".$self->{pathbf}{'.'});
299 <      }
300 <      $ClassDir=".";
301 <    }
302 <
303 <    # -- returns
546 <    ($ClassDir_c=$ClassDir)=~s/^\.\///;
547 <    return ( $Class, $ClassDir_c, $self->{pathbf}{$ClassDir});
548 < }
549 <
550 < sub getclass {
551 <    my $self=shift;
552 <    my $dirname = shift;
553 <
554 <     my $Class="DEFAULT";
555 <        my $ClassDir=".";
556 <
557 <        # return if $dirname eq "";
558 <        my @DIRA=split /\//, $dirname;
559 <
560 <        my $thispath="";
561 <        for ( $i=0; $i<=$#DIRA; $i++ ) {
562 <          $thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
563 <
564 <          # -- sort it out from classpath directives
565 <          foreach $BlockClassA ( @{$self->{LoBCA}} ) {
566 <           next if ( $#{$BlockClassA} < $i );
567 <           $elem=${$BlockClassA}[$i];
568 <            if ( $elem=~/^$DIRA[$i]\+/ ) {
569 <                $elem=~s/^$DIRA[$i]//;
570 <            }
571 <            #print $elem." ".$DIRA[$i]."\n";
572 <            if ( $elem=~/^\+/ ) {
573 <                ($Class=$elem)=~s/^\+//;
293 >        # TODO --- Must test against position of last new BlockCaseA
294 >        # Need to reset array LoBCA to the New BlockPath
295 >        # - merge and replace options
296 >        #
297 >        else {
298 >          foreach $BlockClassA ( @LoBCA ) {
299 >            if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
300 >                $$BlockClassA[0]=~s/^$DIRA[$i]//;
301 >            }
302 >            if ( $$BlockClassA[0]=~/^\+/ ) {
303 >                ($Class=$$BlockClassA[0])=~s/^\+//;
304                  $ClassDir=$thispath;
305 <            }
306 <          }
305 >                shift @$BlockClassA;
306 >            }
307 >            else {
308 >                @$BlockClassA=();
309 >            }
310 >          }
311          }
578        return ( $Class, $ClassDir );
579 }
580
581 #
582 # Check to see if the buildfile is local or in the release area and
583 # parse appropriately
584 #
585 sub _startbuildfile {
586         my $self=shift;
587         my $classdir=shift;
588
589         my $bf=BuildSystem::BuildFile->new($self->{area},$self);
590         my $thisfile="$classdir/$self->{buildfilename}";
591
592         if ( -e $self->{localtop}."/".$thisfile ) {
593            $bf->buildfile($self->{localtop}."/".$thisfile);
594            $bf->ParseBuildFile($self->{localtop}, $classdir,
595                                $self->{buildfilename});
596         }
597         elsif ( -e $self->{releasetop}."/".$thisfile ) {
598            $bf->buildfile($self->{releasetop}."/".$thisfile);
599            $bf->ParseBuildFile($self->{releasetop}, $classdir,
600                                                $self->{buildfilename});
601         }
602         return $bf;
603 }
604
605 sub _topbuildfile {
606    my $self=shift;
607
608    $self->verbose("Generating Top Level BuildFile");
609    # -- Analyse project buildfile if it exists
610
611    my $topbf=$self->_gettopbf();
612
613    # -- generate top level makefile
614    undef $ENV{LatestBuildFile};
615    $topbf->ParseBuildFile($self->{localtop},
616                        $self->{projconfigdir},$self->{buildfilename});
617
618    # -- Extract BuildStructure Information
619    my @ClassPaths=split /:/, $self->{topbf}->BlockClassPath();
620    foreach $BClassPath ( @ClassPaths ) {
621      next if ( $BClassPath eq "");
622      push @{$self->{LoBCA}}, [ split /\//, $BClassPath ];
312      }
313 <    $self->verbose("End top buildfile generation");
314 < }
626 <
627 < sub _checkdatestampindir {
628 <        my $self=shift;
629 <        my $dir=shift;
630 <
631 <        # -- get all local .ds files
632 <        my $fh=FileHandle->new();
633 <        my $ldir=$self->{localtop}."/".$self->{workdir}."/".$dir;
634 <        opendir $fh, $ldir;
635 <        my @dsfiles= grep /^.*\.ds$/, readdir $fh;
636 <        $fh->close();
637 <
638 <        # -- copy across ds files from releasetop if not existing locally
639 <        if ( $#dsfiles < 0 ) {
640 <          # -- get all releasetop .ds files
641 <          my $rdir=$self->{releasetop}."/".$self->{workdir}."/".$dir;
642 <          opendir $fh, $rdir;
643 <          my @releasedsfiles= grep /^.*\.ds$/, readdir $fh;
644 <          foreach $file ( @releasedsfiles ) {
645 <                use File::Copy;
646 <                $self->verbose("Copying $file from $rdir to $ldir");
647 <                copy($rdir."/".$file,$ldir."/".$file);
648 <          }
649 <          $fh->close();
650 <          @dsfiles=@releasedsfiles;
651 <        }
652 <
653 <        # -- process ds files
654 <        my $file;
655 <        foreach $datafile ( @dsfiles ) {
656 <          $self->verbose("Processing $ldir/$datafile\n");
657 <          my $ds=BuildSystem::DateStampRecord->new($ldir."/".$datafile);
658 <          $ds->verbosity($self->verbosity());
659 <          my $date;
660 <          my $needsupdate;
661 <          my $productfile=$ds->product();
662 <          my (%files,%moddate);
663 <
664 <          # now get dates in our dependency list
665 <          my @datedfiles=$ds->dated();
666 <          if ( $#datedfiles >= 0 ) {
667 <
668 <             $needsupdate=1;
669 <             $date=$datedfiles[0][1]-1;
670 <          }
671 <          else {
672 <           # -- extra checks for local replacement of files
673 <           foreach $file ( $ds->contents() ) {
674 <            # -- only check files
675 <            if ( -f $file ) {
676 <             $files{$file}=$ds->filedate($file);
677 <             # -- check to see if we have a new local copy
678 <             if ( ($file=~/\Q$self->{releasetop}\E/) &&
679 <                                ($self->{releasetop} ne $self->{localtop}) ) {
680 <              ($tempfile=$file)=~s/\Q$self->{releasetop}\E/$self->{localtop}/;
681 <              if ( -f $tempfile ) {
682 <                $files{$tempfile}=$files{$file};
683 <                $file=$tempfile;
684 <              }
685 <             }
686 <             $moddate{$file}=(stat($file))[9];
687 <             if ( $moddate{$file} != $files{$file} ) {
688 <              $self->verbose($file." changed");
689 <              $date=$moddate{$file}-1;
690 <              $needsupdate=1;
691 <             }
692 <            }
693 <           }
694 <          }
695 <          # time stamp the product file to be older than the dependencies
696 <          if ( $needsupdate == 1 ) { # touch file into the past
697 <          my $newproductfile;
698 <          if ( $productfile!~/\Q$self->{localtop}\E/ ) {
699 <           if ( $productfile=~/\Q$self->{releasetop}\E/ ) {
700 <             ($newproductfile=$productfile)=~
701 <                        s/\Q$self->{releasetop}\E/$self->{localtop}/;
702 <             $self->verbose("Copying $productfile to $newproductfile");
703 <             copy($productfile,$newproductfile);
704 <           }
705 <           else { # assume no path to worry about
706 <             $newproductfile=$self->{localtop}."/".$ENV{workdir}.
707 <                                                      "/".$productfile;
708 <              # -- make a local copy of the product file if not already here
709 <              my $oldproductfile=$self->{releasetop}."/".$ENV{workdir}.
710 <                                                        "/".$productfile;
711 <             if ( ! -f $newproductfile ) {
712 <              if ( -f $oldproductfile ) {
713 <                $self->verbose("Copying $oldproductfile to $newproductfile");
714 <                copy($oldproductfile,$newproductfile);
715 <              }
716 <             }
717 <           }
718 <          }
719 <          else {
720 <             $newproductfile=$productfile;
721 <          }
722 <          if ( -f $newproductfile ) {
723 <            $self->verbose("Blasting $newproductfile to the past ($date)");
724 <            # If the (local) productfile exists - make it older
725 <            utime($date,$date,$newproductfile);
726 <          }
727 <          else {
728 <            $self->verbose("SomeThing Wrong(?) with $newproductfile\n".
729 <                "RELEASETOP=".$self->{releasetop}."\n".
730 <                "LOCALTOP=".$self->{localtop}."\n".
731 <                "workdir=".$ENV{workdir});
732 <          }
733 <        }
734 <        else {
735 <          $self->verbose("No need to touch $productfile");
736 <        }
737 <        }
738 <        undef $fh;
313 >    $ClassDir=~s/^\.\///;
314 >    return ( $Class, $ClassDir, $bf);
315   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines