ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.6
Committed: Tue Sep 19 10:09:30 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -3 lines
Log Message:
Update from laptop

File Contents

# Content
1 #
2 #
3 # Interface
4 # ---------
5 # new(ConfigArea) : 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)
10
11 package BuildSystem::BuildSetup;
12 require 5.004;
13 use Utilities::Verbose;
14 use Utilities::SCRAMUtils;
15 use BuildSystem::BuildFile;
16 use Utilities::AddDir;
17 @ISA=qw(Utilities::Verbose);
18
19 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();
27 $self->{buildfilename}="BuildFile";
28 $self->_configurationsetup();
29 return $self;
30 }
31
32 sub _generateexternals {
33 my $self=shift;
34 my $outfile=shift;
35
36 # -- specifiy these files for dependency information
37 my $depfile=$self->{projconfigdir}."/External_Dependencies";
38
39 # -- get list of dependent files
40 my $datadir=$self->{localtop}."/.SCRAM/".$ENV{SCRAM_ARCH};
41 $fdir=FileHandle->new();
42 opendir $fdir, $datadir;
43 my @depfiles=grep !/^\.\.?$/, readdir $fdir;
44 undef $fdir;
45 for (my $i=0; $i<=$#depfiles; $i++ ) {
46 $depfiles[$i]=$datadir."/".$depfiles[$i];
47 }
48
49 # -- do we need to rebuild?
50 if ( SCRAMUtils::dated($outfile,@depfiles) ) {
51 print "Configuring Local Area\n";
52 # -- open output file
53 my $fout=FileHandle->new();
54 $fout->open(">".$outfile) or die "Unable to open $outfile for output".
55 $!."\n";
56
57 # -- print out tool/ version info
58 my ($tool,$toolobj,$f,$val,$version);
59 foreach $tool ( $self->{toolbox}->tools() ) {
60 $version=$self->{toolbox}->defaultversion($tool);
61 # default versions
62 print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
63 # -- set up the different version -- externals
64 foreach $version ( $self->{toolbox}->versions($tool) ) {
65 $toolobj=$self->{toolbox}->gettool($tool,$version);
66 @deps=$toolobj->getfeature("_externals");
67 foreach $d ( @deps ) {
68 $d=~tr[A-Z][a-z];
69 print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
70 }
71 # -- tool info
72 print $fout "ifdef ".$tool."_V_".$version."\n";
73 foreach $f ( $toolobj->features() ) {
74 foreach $val ( $toolobj->getfeature($f) ) {
75 print $fout "\t".$f." += ".$val."\n";
76 }
77 }
78 print $fout "endif\n";
79 }
80 }
81 # some addittional processing of specific vars
82 print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
83 print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
84 print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
85 print $fout 'lib+=$(extralib)'."\n";
86 print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
87 print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
88
89 undef $fout;
90 $self->verbose("End Configuration Setup");
91 }
92 }
93
94 sub classsetup {
95 my $self=shift;
96 my $THISDIR=shift;
97
98 my $classmakefile;
99
100 my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
101 $self->verbose("Class = $Class : ClassDir = $ClassDir for directory ".
102 $THISDIR);
103
104 # -- should we ignore?
105 if ( $bf->ignore() ) {
106 print "Nothing to be done - empty group\n";
107 exit;
108 }
109
110
111 # -- Create a makefile from the class BuildFile
112 my $classbuildfile=$self->{localtop}."/".
113 $self->{projconfigdir}."/".$Class."_BuildFile";
114 if ( -f $classbuildfile ) {
115 $classmakefile=$self->{localtop}."/".$ENV{INTwork}.
116 "/".$Class."_makefile.mk";
117 if ( SCRAMUtils::dated($classmakefile, $classbuildfile) ) {
118 # -- generate the new makefile if out of date
119 $self->verbose("Generating $classmakefile from".
120 " $classbuildfile");
121 my $classbf=BuildSystem::BuildFile->new($self->{area});
122 undef $ENV{LatestBuildFile}; # gets set by BuildFile
123 $classbf->GenerateMakefile($classbuildfile, $classmakefile);
124 undef $ENV{LatestBuildFile}; # we dont want this included in the
125 # hierarchy
126 }
127 }
128 else {
129 # -- No BuildFile - maybe its old style makefile
130 $classmakefile=$self->{localtop}."/".
131 $self->{projconfigdir}."/".$Class."_makefile.mk";
132 if ( ! -f $classmakefile ) {
133 $self->error("Unable to find matching ".$Class.
134 "_BuildFile or ".$Class."_makefile.mk");
135 }
136 }
137 # -- set LatestBuildFile
138 if ( $bf->buildfile() ne "" ) {
139 $ENV{LatestBuildFile}=$bf->makefile();
140 }
141 else {
142 $ENV{LatestBuildFile}=$self->{topbf}->makefile();
143 }
144
145 return ($Class,$ClassDir,$classmakefile);
146 }
147
148 sub _configurationsetup {
149 my $self=shift;
150
151 # -- set working directory
152 $self->{workdir}=$ENV{INTwork};
153 $self->{fullworkdir}=$self->{localtop}."/".$self->{workdir};
154
155 # -- make working directory
156 chdir $self->{localtop};
157 AddDir::adddir($self->{workdir});
158
159 # -- generate tool info
160 $self->_generateexternals($self->{fullworkdir}."/clientmakefile");
161
162 # -- process project BuildFile
163 $self->_topbuildfile();
164 }
165
166 sub BuildDir {
167 my $self=shift;
168 my $THISDIR=shift;
169 my @Targets=@_;
170 my $DefaultBuildFile="";
171
172 # -- Create working directory
173 my $workdir=$self->{workdir}."/".$THISDIR;
174 chdir $self->{localtop};
175 AddDir::adddir($workdir);
176 $ENV{workdir}=$workdir;
177 my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
178 chdir $fullworkdir || die "Unable to enter working directory $!";
179
180 # -- setup Class specifics
181 ($Class,$ClassDir,$classmakefile)=$self->classsetup($THISDIR);
182 $ENV{classmakefile}=$classmakefile;
183 $ENV{Class}=$Class;
184 $ENV{ClassDir}=$ClassDir;
185 $DefaultBuildFile=$ENV{classmakefile};
186 $ENV{DefaultBuildFile}=$DefaultBuildFile;
187
188
189 # -- Set up some other useful variables for the Build
190 # set variables listing directories/files available
191 my $fh=FileHandle->new();
192 opendir $fh, "$self->{localtop}/$THISDIR";
193 my @allfiles= grep !/^\.\.?$/, readdir $fh;
194 undef $fh;
195 foreach $file ( @allfiles ) {
196 if ( -d "$self->{localtop}/$THISDIR/$file" ) {
197 $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
198 }
199 else {
200 $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
201 }
202 }
203 my $targetnumber=$#Targets;
204 $ENV{"MAKETARGETS"}="";
205 foreach $word ( @Targets ) {
206 if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
207 $targetnumber--;
208 }
209 else {
210 # set some variables for use in makefiles
211 $ENV{"MAKETARGET_".$word}=$word;
212 if ( $ENV{"MAKETARGETS"} ne "" ) {
213 $ENV{"MAKETARGETS"}=$ENV{"MAKETARGETS"}." ".$word;
214 }
215 else {
216 $ENV{"MAKETARGETS"}=$word;
217 }
218 }
219 }
220
221 # -- If target not specified default to the class name target
222 if ( $targetnumber == -1 ) {
223 push @Targets,$Class;
224 }
225
226 $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
227
228 $SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
229 if ( -f $SCRAM_GROUPSDIR ) {
230 $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
231 }
232
233 # Do a datestamp check so that make will build files that have changed
234 # rather than just those which are older than their dependencies
235 # The main build here
236 $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
237 $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
238 return $rv/256; # return the exit status of gmake
239 }
240
241 sub getclass {
242 my $self=shift;
243 my $dirname = shift;
244 my $Class="DEFAULT";
245 my $ClassDir="";
246
247 #return if $dirname eq "";
248 @DIRA=split /\//, $dirname;
249
250 my $thispath=".";
251 # -- construct all class buildfiles in the path
252 for ( $i=0; $i<=$#DIRA; $i++ ) {
253 #$thispath=(($thispath eq "")?$DIRA[$i]:$thispath."/".$DIRA[$i]);
254 $thispath=$thispath."/".$DIRA[$i];
255 if ( ! exists $self->{pathbf}{$thispath} ) {
256 $self->verbose("Initialising BuildFile in $thispath");
257 $self->{pathbf}{$thispath}=$self->_startbuildfile($thispath);
258 }
259 # -- check class overriden by BuildFile
260 if ( defined $self->{pathbf}{$thispath}->classname() ) {
261 $Class=$self->{pathbf}{$thispath}->classname();
262 $ClassDir=$thispath;
263 }
264 else {
265 # -- sort it out from classpath directives
266 foreach $BlockClassA ( @{$self->{LoBCA}} ) {
267 foreach $elem ( @$BlockClassA ) {
268 if ( $elem=~/^$DIRA[$i]\+/ ) {
269 $elem=~s/^$DIRA[$i]//;
270 }
271 if ( $elem=~/^\+/ ) {
272 ($Class=$elem)=~s/^\+//;
273 $ClassDir=$thispath;
274 }
275 }
276 }
277 }
278 }
279 # -- default case
280 if ( $ClassDir eq "" ) {
281 if ( ! defined $self->{pathbf}{'.'}) {
282 $self->{pathbf}{'.'}=$self->_startbuildfile(".");
283 $self->verbose("DEFAULT class initialised : ".$self->{pathbf}{'.'});
284 }
285 $ClassDir=".";
286 }
287
288 # -- retunrs
289 ($ClassDir_c=$ClassDir)=~s/^\.\///;
290 return ( $Class, $ClassDir_c, $self->{pathbf}{$ClassDir});
291 }
292
293 #
294 # Check to see if the buildfile is local or in the release area and
295 # parse appropriately
296 #
297 sub _startbuildfile {
298 my $self=shift;
299 my $classdir=shift;
300
301 my $bf=BuildSystem::BuildFile->new($self->{area});
302 my $thisfile="$classdir/$self->{buildfilename}";
303
304 if ( -e $self->{localtop}."/".$thisfile ) {
305 $bf->buildfile($self->{localtop}."/".$thisfile);
306 $bf->ParseBuildFile($self->{localtop}, $classdir,
307 $self->{buildfilename});
308 }
309 elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) {
310 $bf->buildfile("$ENV{RELEASETOP}/$thisfile");
311 $bf->ParseBuildFile($ENV{RELEASETOP}, $classdir,
312 $slef->{buildfilename});
313 }
314 return $bf;
315 }
316
317 sub _topbuildfile {
318 my $self=shift;
319
320 # -- Analyse project buildfile if it exists
321 $self->{topbf}=BuildSystem::BuildFile->new($self->{area});
322
323 $self->{topbf}->buildfile($self->{localtop}."/".$self->{projconfigdir}
324 ."/".$self->{buildfilename});
325 # -- generate top level makefile
326 $self->verbose("Generating Top Level BuildFile");
327 $self->{topbf}->ParseBuildFile($self->{localtop},
328 $self->{projconfigdir},$self->{buildfilename});
329
330 my @ClassPaths=split /:/, $self->{topbf}->BlockClassPath();
331 foreach $BClassPath ( @ClassPaths ) {
332 next if ( $BClassPath eq "");
333 push @{$self->{LoBCA}}, [ split /\//, $BClassPath ];
334 }
335
336 }