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.21 by sashby, Tue Dec 11 10:05:05 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
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 +      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 <         # Do a datestamp check so that make will build files that have changed
124 <         # rather than just those which are older than their dependencies
125 <         $self->_checkdatestampindir($ClassDir);
126 <
127 <         # -- The main build here
128 <         $rv=system("gmake","--no-print-directory","-r","-k","-f",
129 <                "$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}", @Targets);
130 <    }
131 <    return $rv/256; # return the exit status of gmake
132 <
133 < }
134 <
135 < # TODO - work in progress - replacement for BuildDir that can handle <Build> OK
136 < sub BuildIt {
137 <        my $self=shift;
138 <        my $dir=shift;
139 <        my @Targets=@_;
140 <
141 <
142 <        # -- get the top building block
143 <        my $topblock=$self->_gettopblock();
144 <        $ENV{LatestBuildFile}=$self->_gettopbf()->makefile();
145 <
146 <        # -- is there a class block associated with the directory?
147 <        my ($Class,$ClassDir)=getclass($dir);
148 <        $self->verbose("Using Class $Class");
149 <        my $classblock=$self->_getclassblock($Class,$topblock);
150 <
151 <        # -- If target not specified default to the class name target
152 <        if ( $targetnumber == -1 ) {
153 <          push @Targets,$Class;
154 <        }
155 <
156 <        # -- Create working directory
157 <        my $workdir=$self->{workdir}."/".$ClassDir;
158 <        chdir $self->{localtop};
159 <        AddDir::adddir($workdir);
160 <        $ENV{workdir}=$workdir;
161 <        my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
162 <        chdir $fullworkdir || die "Unable to enter working directory $!";
163 <        $self->verbose("Working area setup");
164 <
165 <        # -- Search for Blocks up to tree root
166 <        my @dirblocks=();
167 <        my @dirs=split /\//, $dir;
168 <        my $fulldir="";
169 <        my $currentblock=$classblock;
170 <        foreach $dire ( @dirs ) {
171 <              ($fulldir eq "")?$fulldir=$dire
172 <                              :$fulldir=$fulldir."/".$dire;
173 <              $self->verbose("Searching $fulldir for Block");
174 <              my $block=$self->_getdirblock($fulldir,$currentblock);
175 <              if ( defined $block ) {
176 <                 $currentblock=$block;
177 <              }
178 <              $ENV{LatestBuildFile}=$self->gettopbf()->makefile();
179 <        }
180 <
181 <        # -- Create a makefile to include both BuildFile and
182 <        #    class makefile
183 <
184 <        my $fh=FileHandle->new();
185 <        my $mfile=$fullworkdir."/BuildFile.mk";
186 <        $self->verbose("Building makefile $mfile");
187 <        $fh->open(">".$mfile);
188 <        $fh->autoflush(1);
189 <        if ( -e $ENV{LatestBuildFile} ) {
190 <          print $fh "include $ENV{LatestBuildFile}\n";
191 <        }
192 <
193 <        # -- Parse the local BuildFile
194 <        my $dbf=$self->_getdirbf($dir);
195 <        if ( defined $dbf ) {
196 <          $dbf->Parsetofh($fh,$currentblock);
197 <        }
198 <
199 <        # -- Parse the class BuildFile
200 <        my $cbf=$self->_getclassbf($Class);
201 <        if ( defined $cbf ) {
202 <          $cbf->Parsetofh($fh,$currentblock);
203 <        }
204 <        $fh->close();
205 <        $ENV{DefaultMakefile}=$mfile;
206 <
207 <        # -- Hack around make by checking datestamps in local working and
208 <        #    in _class_ working directories
209 <        $self->_checkdatestampindir($ClassDir);
210 <        opendir $fh, $ClassDir;
211 <        my @dfiles= grep { -d $_ } readdir $fh;
212 <        undef $fh;
213 <        foreach $dir ( @dfiles ) {
214 <          if ( $dir=~/^_class_/ ) {
215 <           $self->_checkdatestampindir($ClassDir."/".$dir);
216 <          }
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;
389 <
390 <        if ( ! defined $self->{topblocks} ) {
391 <            $self->verbose("Initialising Top Block");
392 <            $self->{topblock}=BuildSystem::Block->new();
393 <            # -- get class buildfile
394 <            my $bf=$self->_gettopbf();
395 <            if ( @_ ) {
396 <              $self->{topblock}->parent(shift);
397 <            }
398 <            $bf->BlockParse($self->{topblock});
399 <            $self->verbose("Initialisation Complete for Top Block");
400 <        }
401 <        return $self->{topblock};
402 < }
403 <
404 < sub _getdirblock {
405 <        my $self=shift;
406 <        my $dir=shift;
407 <        my $block=shift;
408 <
409 <        if ( defined $dir || $dir ne "" ) {
410 <        if ( ! defined $self->{blocks}{$dir} ) {
411 <          # -- get a buildfile and do a block parse
412 <          $self->{blocks}{$dir}=BuildSystem::Block->new();
413 <          my $bf=$self->_getbuildfile($dir);
414 <          $self->{blocks}{$dir}->parent($block);
415 <          $bf->blockparse($self->{blocks}{$dir});
416 <        }
417 <        return $self->{blocks}{$dir};
418 <        }
419 <        return undef;
420 < }
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 >   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 < #
219 < # -- BuildFile generation routines
220 < #
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 < sub _getclassbf {
235 <        my $self=shift;
236 <        my $class=shift;
237 <
238 <        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 < }
234 >   # If not specified default to the class name target
235 >   if ( $targetnumber == -1 )
236 >      {
237 >      push @Targets,$Class;
238 >      }
239  
240 < sub _gettopbf {
455 <        my $self=shift;
240 >   $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
241  
242 <        if ( ! defined $self->{topbf} ) {
243 <          $self->{topbf}=BuildSystem::BuildFile->new($self->{area},$self);
244 <          $self->{topbf}->buildfile($self->{localtop}."/".
245 <                        $self->{projconfigdir}."/".$self->{buildfilename});
246 <        }
247 <        return $self->{topbf};
248 < }
249 < #
250 < # Returns undef if BF does not exist at this dir level
251 < #
252 < sub _getdirbf {
253 <        my $self=shift;
254 <        my $dir=shift;
255 <
256 <        if ( ! exists $self->{dirbf}{$dir} ) {
257 <          $self->verbose("initialising dir BuildFile $dir");
258 <          # -- determine if local or releasetop
259 <          my $fname=$self->{path}."/".$self->{buildfilename};
260 <          if ( -f $self->{localtop}."/".$fname ) {
261 <            $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);
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 >   # The main build here
251 >
252 >   $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
253 >
254 >   # Be verbose:
255 >   $self->verbose(">> Going to use ".$ENV{DefaultMakefile}." as the default makefile");
256 >  
257 >   my $gmakejobsflag = "-j";
258 >   # Temporarily hard-code ncpu as 1:
259 >   my $ncpu = 1;
260 >  
261 >   $rv=system("gmake","--no-print-directory","$gmakejobsflag","$ncpu","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
262  
263 <          $self->verbose("initialisation complete for dir BuildFile $dir");
264 <        }
493 <        return $self->{dirbf}{$dir};
494 < }
263 >   return $rv/256; # return the exit status of gmake
264 >   }
265  
266 < sub getclass2 {
266 > sub getclass {
267      my $self=shift;
268      my $dirname = shift;
269      my $Class="DEFAULT";
270      my $ClassDir="";
271 +        
272 +    @DIRA=split /\//, $dirname;
273  
274 <    #return if $dirname eq "";
275 <    my @DIRA=split /\//, $dirname;
274 >    $thispath=".";
275 >    # bootstrap from project buildfile if it exists
276 >    my $bf=BuildSystem::BuildFile->new($self->{toolbox});
277 >    $bf->CheckBuildFile($ENV{projconfigdir});
278  
279 <    my $thispath=".";
280 <    # -- construct all class buildfiles in the path
279 >    my @ClassPaths=split /:/, $bf->BlockClassPath();
280 >    foreach $BClassPath ( @ClassPaths ) {
281 >      next if ( $BClassPath eq "");
282 >      push @LoBCA, [ split /\//, $BClassPath ];
283 >    }
284      for ( $i=0; $i<=$#DIRA; $i++ ) {
508        #$thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
285          $thispath=$thispath."/".$DIRA[$i];
286 <        if ( ! exists $self->{pathbf}{$thispath} ) {
287 <          $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/^\+//;
286 >        if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
287 >                $Class=$ClassName;
288                  $ClassDir=$thispath;
531            }
532          #}
533         }
289          }
290 <    }
291 <    # -- default case
292 <    if ( $ClassDir eq "" ) {
293 <      if ( ! defined $self->{pathbf}{'.'}) {
294 <          $self->{pathbf}{'.'}=$self->_startbuildfile(".");
295 <          $self->verbose("DEFAULT class initialised : ".$self->{pathbf}{'.'});
296 <      }
297 <      $ClassDir=".";
298 <    }
299 <
300 <    # -- 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/^\+//;
290 >        # TODO --- Must test against position of last new BlockCaseA
291 >        # Need to reset array LoBCA to the New BlockPath
292 >        # - merge and replace options
293 >        #
294 >        else {
295 >          foreach $BlockClassA ( @LoBCA ) {
296 >            if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
297 >                $$BlockClassA[0]=~s/^$DIRA[$i]//;
298 >            }
299 >            if ( $$BlockClassA[0]=~/^\+/ ) {
300 >                ($Class=$$BlockClassA[0])=~s/^\+//;
301                  $ClassDir=$thispath;
302 <            }
303 <          }
302 >                shift @$BlockClassA;
303 >            }
304 >            else {
305 >                @$BlockClassA=();
306 >            }
307 >          }
308          }
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 ];
309      }
310 <    $self->verbose("End top buildfile generation");
311 < }
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;
310 >    $ClassDir=~s/^\.\///;
311 >    return ( $Class, $ClassDir, $bf);
312   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines