1 |
williamc |
1.2 |
#
|
2 |
|
|
#
|
3 |
|
|
# Interface
|
4 |
|
|
# ---------
|
5 |
williamc |
1.13 |
# new(toolbox) : A new BuildSetup
|
6 |
|
|
# BuildSetup(directory,targets) : prepare the ground for a build and build
|
7 |
williamc |
1.12 |
# getclass(directory) : return (Class, ClassDir, BuildFileobject)
|
8 |
|
|
# associated with directory
|
9 |
williamc |
1.13 |
#
|
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.13 |
$self->{toolbox}=shift;
|
24 |
williamc |
1.2 |
return $self;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
sashby |
1.14 |
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 |
williamc |
1.2 |
|
44 |
sashby |
1.14 |
# -- 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 |
williamc |
1.2 |
|
70 |
sashby |
1.14 |
# -- 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 |
williamc |
1.2 |
|
80 |
sashby |
1.14 |
# -- 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 |
williamc |
1.2 |
}
|
109 |
sashby |
1.14 |
}
|
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 |
williamc |
1.2 |
|
123 |
sashby |
1.15 |
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 |
williamc |
1.13 |
|
151 |
sashby |
1.15 |
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 |
williamc |
1.13 |
$ENV{projdeps}=$ENV{LOCALTOP}."/".$projectfile;
|
168 |
sashby |
1.15 |
}
|
169 |
|
|
elsif ( -e $ENV{RELEASETOP}."/".$projectfile )
|
170 |
|
|
{
|
171 |
williamc |
1.13 |
$ENV{projectfile}=$ENV{RELEASETOP}."/".$projectfile;
|
172 |
sashby |
1.15 |
}
|
173 |
|
|
if ( $DefaultBuildFile eq "" )
|
174 |
|
|
{
|
175 |
williamc |
1.13 |
# Map Relevant makefile classmakefile directory
|
176 |
|
|
my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk";
|
177 |
sashby |
1.15 |
if ( -e $ENV{LOCALTOP}."/".$classmakefile )
|
178 |
|
|
{
|
179 |
|
|
$ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile;
|
180 |
|
|
}
|
181 |
|
|
elsif ( -e $ENV{RELEASETOP}."/".$classmakefile )
|
182 |
|
|
{
|
183 |
williamc |
1.13 |
$ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile;
|
184 |
sashby |
1.15 |
}
|
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 |
williamc |
1.13 |
$DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override
|
193 |
sashby |
1.15 |
}
|
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 |
|
|
foreach $word ( @Targets )
|
219 |
|
|
{
|
220 |
|
|
if ( $word=~/.*=.*/ )
|
221 |
|
|
{ # if we have an assignment it cant be a target
|
222 |
williamc |
1.13 |
$targetnumber--;
|
223 |
sashby |
1.15 |
}
|
224 |
|
|
elsif ( $word=~/^-/ )
|
225 |
|
|
{
|
226 |
williamc |
1.13 |
$targetnumber--;
|
227 |
sashby |
1.15 |
}
|
228 |
|
|
else
|
229 |
|
|
{
|
230 |
|
|
$ENV{"MAKETARGET_".$word}=$word;
|
231 |
|
|
}
|
232 |
williamc |
1.13 |
}
|
233 |
sashby |
1.15 |
|
234 |
|
|
# If not specified default to the class name target
|
235 |
|
|
if ( $targetnumber == -1 )
|
236 |
|
|
{
|
237 |
|
|
push @Targets,$Class;
|
238 |
williamc |
1.13 |
}
|
239 |
williamc |
1.2 |
|
240 |
sashby |
1.15 |
$ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
|
241 |
williamc |
1.2 |
|
242 |
sashby |
1.15 |
$SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
|
243 |
|
|
if ( -f $SCRAM_GROUPSDIR )
|
244 |
|
|
{
|
245 |
williamc |
1.2 |
$ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
|
246 |
sashby |
1.15 |
}
|
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 |
sashby |
1.20 |
|
252 |
sashby |
1.15 |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
|
253 |
|
|
|
254 |
sashby |
1.18 |
my $gmakejobsflag = "-j";
|
255 |
sashby |
1.16 |
# Temporarily hard-code ncpu as 1:
|
256 |
sashby |
1.19 |
my $ncpu = 1;
|
257 |
|
|
|
258 |
sashby |
1.15 |
$rv=system("gmake","--no-print-directory","$gmakejobsflag","$ncpu","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
|
259 |
sashby |
1.16 |
|
260 |
sashby |
1.15 |
return $rv/256; # return the exit status of gmake
|
261 |
|
|
}
|
262 |
williamc |
1.8 |
|
263 |
williamc |
1.13 |
sub getclass {
|
264 |
williamc |
1.2 |
my $self=shift;
|
265 |
|
|
my $dirname = shift;
|
266 |
|
|
my $Class="DEFAULT";
|
267 |
|
|
my $ClassDir="";
|
268 |
williamc |
1.13 |
|
269 |
|
|
@DIRA=split /\//, $dirname;
|
270 |
williamc |
1.12 |
|
271 |
williamc |
1.13 |
$thispath=".";
|
272 |
|
|
# bootstrap from project buildfile if it exists
|
273 |
|
|
my $bf=BuildSystem::BuildFile->new($self->{toolbox});
|
274 |
|
|
$bf->CheckBuildFile($ENV{projconfigdir});
|
275 |
williamc |
1.2 |
|
276 |
williamc |
1.13 |
my @ClassPaths=split /:/, $bf->BlockClassPath();
|
277 |
|
|
foreach $BClassPath ( @ClassPaths ) {
|
278 |
|
|
next if ( $BClassPath eq "");
|
279 |
|
|
push @LoBCA, [ split /\//, $BClassPath ];
|
280 |
|
|
}
|
281 |
williamc |
1.2 |
for ( $i=0; $i<=$#DIRA; $i++ ) {
|
282 |
williamc |
1.12 |
$thispath=$thispath."/".$DIRA[$i];
|
283 |
williamc |
1.13 |
if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
|
284 |
|
|
$Class=$ClassName;
|
285 |
williamc |
1.2 |
$ClassDir=$thispath;
|
286 |
|
|
}
|
287 |
williamc |
1.13 |
# TODO --- Must test against position of last new BlockCaseA
|
288 |
|
|
# Need to reset array LoBCA to the New BlockPath
|
289 |
|
|
# - merge and replace options
|
290 |
|
|
#
|
291 |
|
|
else {
|
292 |
|
|
foreach $BlockClassA ( @LoBCA ) {
|
293 |
|
|
if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
|
294 |
|
|
$$BlockClassA[0]=~s/^$DIRA[$i]//;
|
295 |
|
|
}
|
296 |
|
|
if ( $$BlockClassA[0]=~/^\+/ ) {
|
297 |
|
|
($Class=$$BlockClassA[0])=~s/^\+//;
|
298 |
williamc |
1.2 |
$ClassDir=$thispath;
|
299 |
williamc |
1.13 |
shift @$BlockClassA;
|
300 |
|
|
}
|
301 |
|
|
else {
|
302 |
|
|
@$BlockClassA=();
|
303 |
|
|
}
|
304 |
|
|
}
|
305 |
williamc |
1.12 |
}
|
306 |
williamc |
1.5 |
}
|
307 |
williamc |
1.13 |
$ClassDir=~s/^\.\///;
|
308 |
|
|
return ( $Class, $ClassDir, $bf);
|
309 |
williamc |
1.2 |
}
|