1 |
williamc |
1.2 |
#
|
2 |
|
|
#
|
3 |
|
|
# Interface
|
4 |
|
|
# ---------
|
5 |
williamc |
1.3 |
# new(ConfigArea) : A new BuildSetup
|
6 |
williamc |
1.2 |
# BuildSetup(directory,targets) : prepare the ground for a build and build
|
7 |
|
|
# getclass(directory) : return (Class, ClassDir, BuildFileobject)
|
8 |
|
|
# associated with directory
|
9 |
williamc |
1.4 |
# setup(dir)
|
10 |
williamc |
1.2 |
|
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 |
williamc |
1.3 |
$self->{area}=shift;
|
24 |
|
|
$self->{toolbox}=$self->{area}->toolbox();
|
25 |
|
|
$self->{projconfigdir}=$self->{area}->configurationdir();
|
26 |
|
|
$self->{localtop}=$self->{area}->location();
|
27 |
williamc |
1.5 |
$self->{buildfilename}="BuildFile";
|
28 |
|
|
$self->_configurationsetup();
|
29 |
williamc |
1.2 |
return $self;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
sub _generateexternals {
|
33 |
|
|
my $self=shift;
|
34 |
|
|
my $outfile=shift;
|
35 |
|
|
|
36 |
|
|
# -- specifiy these files for dependency information
|
37 |
williamc |
1.3 |
my $depfile=$self->{projconfigdir}."/External_Dependencies";
|
38 |
williamc |
1.2 |
|
39 |
|
|
# -- get list of dependent files
|
40 |
williamc |
1.3 |
my $datadir=$self->{localtop}."/.SCRAM/".$ENV{SCRAM_ARCH};
|
41 |
williamc |
1.2 |
$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 |
williamc |
1.3 |
$self->verbose("End Configuration Setup");
|
91 |
williamc |
1.2 |
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
williamc |
1.4 |
sub classsetup {
|
95 |
|
|
my $self=shift;
|
96 |
|
|
my $THISDIR=shift;
|
97 |
|
|
|
98 |
|
|
my $classmakefile;
|
99 |
|
|
|
100 |
|
|
my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
|
101 |
williamc |
1.5 |
$self->verbose("Class = $Class : ClassDir = $ClassDir for directory ".
|
102 |
|
|
$THISDIR);
|
103 |
williamc |
1.4 |
|
104 |
|
|
# -- should we ignore?
|
105 |
|
|
if ( $bf->ignore() ) {
|
106 |
|
|
print "Nothing to be done - empty group\n";
|
107 |
|
|
exit;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
williamc |
1.5 |
|
111 |
williamc |
1.4 |
# -- 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 |
williamc |
1.5 |
# -- set LatestBuildFile
|
138 |
|
|
if ( $bf->buildfile() ne "" ) {
|
139 |
|
|
$ENV{LatestBuildFile}=$bf->buildfile();
|
140 |
|
|
}
|
141 |
|
|
else {
|
142 |
|
|
$ENV{LatestBuildFile}=$self->{topbf}->buildfile();
|
143 |
|
|
}
|
144 |
|
|
|
145 |
williamc |
1.4 |
return ($Class,$ClassDir,$classmakefile);
|
146 |
|
|
}
|
147 |
|
|
|
148 |
williamc |
1.5 |
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 |
williamc |
1.4 |
my $self=shift;
|
168 |
|
|
my $THISDIR=shift;
|
169 |
|
|
my @Targets=@_;
|
170 |
|
|
my $DefaultBuildFile="";
|
171 |
|
|
|
172 |
|
|
# -- Create working directory
|
173 |
williamc |
1.5 |
my $workdir=$self->{workdir}."/".$THISDIR;
|
174 |
williamc |
1.4 |
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 |
williamc |
1.2 |
|
188 |
williamc |
1.4 |
|
189 |
williamc |
1.5 |
# -- 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 |
williamc |
1.4 |
}
|
203 |
williamc |
1.5 |
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 |
williamc |
1.3 |
}
|
220 |
williamc |
1.2 |
|
221 |
williamc |
1.5 |
# -- If target not specified default to the class name target
|
222 |
|
|
if ( $targetnumber == -1 ) {
|
223 |
williamc |
1.2 |
push @Targets,$Class;
|
224 |
williamc |
1.5 |
}
|
225 |
williamc |
1.2 |
|
226 |
|
|
$ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
|
227 |
|
|
|
228 |
williamc |
1.3 |
$SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
|
229 |
williamc |
1.2 |
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 |
williamc |
1.5 |
my $thispath=".";
|
251 |
|
|
# -- construct all class buildfiles in the path
|
252 |
williamc |
1.2 |
for ( $i=0; $i<=$#DIRA; $i++ ) {
|
253 |
williamc |
1.5 |
#$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 |
williamc |
1.2 |
$ClassDir=$thispath;
|
263 |
|
|
}
|
264 |
|
|
else {
|
265 |
williamc |
1.5 |
# -- 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 |
williamc |
1.2 |
}
|
271 |
williamc |
1.5 |
if ( $elem=~/^\+/ ) {
|
272 |
|
|
($Class=$elem)=~s/^\+//;
|
273 |
williamc |
1.2 |
$ClassDir=$thispath;
|
274 |
|
|
}
|
275 |
|
|
}
|
276 |
williamc |
1.5 |
}
|
277 |
williamc |
1.2 |
}
|
278 |
|
|
}
|
279 |
williamc |
1.5 |
# -- 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 |
|
|
# -- generate top level makefile
|
324 |
|
|
$self->{topbf}->buildfile($self->{localtop}."/".$self->{projconfigdir}
|
325 |
|
|
."/".$self->{buildfilename});
|
326 |
|
|
$self->{topbf}->ParseBuildFile($self->{localtop},
|
327 |
|
|
$self->{projconfigdir},$self->{buildfilename});
|
328 |
|
|
|
329 |
|
|
my @ClassPaths=split /:/, $self->{topbf}->BlockClassPath();
|
330 |
|
|
foreach $BClassPath ( @ClassPaths ) {
|
331 |
|
|
next if ( $BClassPath eq "");
|
332 |
|
|
push @{$self->{LoBCA}}, [ split /\//, $BClassPath ];
|
333 |
|
|
}
|
334 |
|
|
|
335 |
williamc |
1.2 |
}
|