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.3 by williamc, Wed Sep 6 10:14:29 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
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
# Line 20 | Line 20 | sub new {
20          my $class=shift;
21          my $self={};
22          bless $self,$class;
23 <        $self->{area}=shift;
24 <        $self->{toolbox}=$self->{area}->toolbox();
25 <        $self->{projconfigdir}=$self->{area}->configurationdir();
26 <        $self->{localtop}=$self->{area}->location();
23 >        $self->{toolbox}=shift;
24          return $self;
25   }
26  
27 < sub _generateexternals {
28 <        my $self=shift;
29 <        my $outfile=shift;
30 <
31 <        # -- specifiy 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 Configuration Setup");
120 <        }
90 < }
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 < sub BuildSetup {
123 <    my $self=shift;
124 <    my $THISDIR=shift;
125 <    my @Targets=@_;
126 <    my $DefaultBuildFile="";
127 <
128 <    # -- Create working directory
129 <    chdir $self->{localtop};
130 <    AddDir::adddir($ENV{INTwork}."/".$THISDIR);
131 <
132 <    my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
133 <    $self->verbose("Class = $Class");
134 <    $self->verbose("ClassDir = $ClassDir");
122 >      undef $fout;
123 >      }
124 >   }
125 >
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 <        print "Nothing to be done - empty group\n";
156 <        exit;
157 <    }  
158 <    shift;
159 <    $self->_generateexternals($self->{localtop}."/".$ENV{INTwork}."/clientmakefile");
160 <
161 <    # set up the workdir variable
162 <    #$ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
163 <    $ENV{workdir}=$ENV{INTwork}."/".$THISDIR;
164 <    my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
165 <
166 <    # set up projdeps variable
167 <    my $projectfile=$self->{projconfigdir}."/External_Dependencies";
168 <    if ( -e $self->{localtop}."/".$projectfile ) {
169 <      $ENV{projdeps}=$self->{localtop}."/".$projectfile;
170 <    }
171 <    elsif ( -e $ENV{RELEASETOP}."/".$projectfile ) {
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;
125    }
126    if ( (! defined $DefaultBuildFile) || ($DefaultBuildFile eq "") ) {
127      # -- Create a makefile from the class BuildFile
128      my $classbuildfile=$self->{localtop}."/".
129                $self->{projconfigdir}."/".$Class."_BuildFile";
130      $self->verbose("Processing Class BuildFile $classbuildfile");
131      my $classmakefile;
132      if ( -f $classbuildfile ) {
133        $classmakefile=$self->{localtop}."/".$ENV{INTwork}.
134                                        "/".$Class."_makefile.mk";
135        if ( SCRAMUtils::dated($classmakefile, $classbuildfile) ) {
136          # -- generate the new makefile if out of date
137          $self->verbose("Generating $classmakefile from $classbuildfile");
138          my $classbf=BuildSystem::BuildFile->new($self->{area});
139          undef $ENV{LatestBuildFile};
140          $classbf->GenerateMakefile($classbuildfile, $classmakefile);
141          undef $ENV{LatestBuildFile}; # we dont want this included in the
142                                       # hierarchy
143        }
144      }
145      else {
146        # Map Relevant makefile classmakefile directory
147        $classmakefile=$self->{localtop}."/".
148                $self->{projconfigdir}."/".$Class."_makefile.mk";
149         if ( ! -f $classmakefile ) {
150           $self->error("Unable to find matching ".$Class."_BuildFile or ".
151                $Class."_makefile.mk");
152         }
175        }
176 +   if ( $DefaultBuildFile eq "" )
177 +      {
178        # Map Relevant makefile classmakefile directory
179 <      $ENV{classmakefile}=$classmakefile;
180 <      $DefaultBuildFile=$ENV{classmakefile};
181 <    }
182 <
183 <    $ENV{ClassDir}=$ClassDir;
184 <    $ENV{Class}=$Class;
185 <    $ENV{DefaultBuildFile}=$DefaultBuildFile;
186 <
187 <    chdir $fullworkdir || die "Unable to enter working directory $!";
188 <
189 <    # Set up some other useful variables fo the Build
190 <    # list of directories available
191 <    opendir IDR, "$self->{localtop}/$THISDIR";
192 <    @allfiles= grep !/^\.\.?$/, readdir IDR;
193 <    foreach $file ( @allfiles ) {
194 <      if ( -d "$self->{localtop}/$THISDIR/$file" ) { # only add if its a directory
195 <        $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
196 <      }
197 <      else {
198 <        $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
199 <      }
200 <    }
201 <    $targetnumber=$#Targets;
202 <    $ENV{"MAKETARGETS"}="";
203 <    foreach $word ( @Targets ) {
204 <      if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
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 >   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 +   # If not specified default to the class name target
238 +   if ( $targetnumber == -1 )
239 +      {
240 +      push @Targets,$Class;
241        }
183      else {
184        # set some variables for use in makefiles
185        $ENV{"MAKETARGET_".$word}=$word;
186        if ( $ENV{"MAKETARGETS"} ne "" ) {
187          $ENV{"MAKETARGETS"}=$ENV{"MAKETARGETS"}." ".$word;
188        }
189        else {
190          $ENV{"MAKETARGETS"}=$word;
191        }
192      }
193    }
194
195    # If not specified default to the class name target
196    if ( $targetnumber == -1 ) {
197        push @Targets,$Class;
198    }
242  
243 <    $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
243 >   $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
244  
245 <    $SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
246 <    if ( -f $SCRAM_GROUPSDIR ) {
245 >   $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
246 >   if ( -f $SCRAM_GROUPSDIR )
247 >      {
248        $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
249 <    }
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 <    # Do a datestamp check so that make will build files that have changed
265 <    # rather than just those which are older than their dependencies
266 <    # The main build here
267 <    $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
211 <    $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
212 <    return $rv/256; # return the exit status of gmake
213 < }
264 >   $rv=system("gmake","--no-print-directory","$gmakejobsflag","$ncpu","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
265 >
266 >   return $rv/256; # return the exit status of gmake
267 >   }
268  
269   sub getclass {
270      my $self=shift;
# Line 218 | Line 272 | sub getclass {
272      my $Class="DEFAULT";
273      my $ClassDir="";
274          
221    #return if $dirname eq "";
275      @DIRA=split /\//, $dirname;
276  
277      $thispath=".";
278      # bootstrap from project buildfile if it exists
279 <    my $bf=BuildSystem::BuildFile->new($self->{area});
280 <    $bf->CheckBuildFile($self->{projconfigdir});
279 >    my $bf=BuildSystem::BuildFile->new($self->{toolbox});
280 >    $bf->CheckBuildFile($ENV{projconfigdir});
281  
282      my @ClassPaths=split /:/, $bf->BlockClassPath();
283      foreach $BClassPath ( @ClassPaths ) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines