1 |
+ |
# |
2 |
+ |
# |
3 |
+ |
# Interface |
4 |
+ |
# --------- |
5 |
+ |
# new() : 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 |
+ |
# |
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->init(); |
24 |
+ |
return $self; |
25 |
+ |
} |
26 |
+ |
|
27 |
+ |
sub init { |
28 |
+ |
my $self=shift; |
29 |
+ |
$self->{toolbox}=BuildSystem::ToolBox->new(); |
30 |
+ |
} |
31 |
+ |
|
32 |
+ |
sub _generateexternals { |
33 |
+ |
my $self=shift; |
34 |
+ |
my $outfile=shift; |
35 |
+ |
|
36 |
+ |
# -- specifiy these files for dependency information |
37 |
+ |
my $depfile=$ENV{projconfigdir}."/External_Dependencies"; |
38 |
+ |
my $clientfile="$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/clientsettings"; |
39 |
+ |
my $clientreq="$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/". |
40 |
+ |
"clientsettings_reqs"; |
41 |
+ |
# -- do we need to rebuild? |
42 |
+ |
if ( SCRAMUtils::dated($outfile,$depfile, $clientfile,$clientreq) ) { |
43 |
+ |
print "Configuring Local Area\n"; |
44 |
+ |
# -- open output file |
45 |
+ |
my $fout=FileHandle->new(); |
46 |
+ |
$fout->open(">".$outfile) or die "Unable to open $outfile for output". |
47 |
+ |
$!."\n"; |
48 |
+ |
|
49 |
+ |
# -- cludge in the dependencies - need to go via toolbox really |
50 |
+ |
my $fh=FileHandle->new(); |
51 |
+ |
open ($fh, "<$clientreq" ); |
52 |
+ |
while( <$fh> ) { |
53 |
+ |
print $fout $_; |
54 |
+ |
} |
55 |
+ |
undef $fh; |
56 |
+ |
|
57 |
+ |
# -- print out tool/ version info |
58 |
+ |
my ($tool,$toolobj,$f,$val,$version); |
59 |
+ |
foreach $toolpair ( $self->{toolbox}->tools() ) { |
60 |
+ |
$tool=$$toolpair[0]; |
61 |
+ |
$version=$$toolpair[1]; |
62 |
+ |
print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n"; |
63 |
+ |
$toolobj=$self->{toolbox}->gettool($tool,$version); |
64 |
+ |
print $fout "ifdef ".$tool."_V_".$version."\n"; |
65 |
+ |
foreach $f ( $toolobj->features() ) { |
66 |
+ |
foreach $val ( $toolobj->getfeature($f) ) { |
67 |
+ |
print $fout "\t".$f." += ".$val."\n"; |
68 |
+ |
} |
69 |
+ |
} |
70 |
+ |
print $fout "endif\n"; |
71 |
+ |
} |
72 |
+ |
# some addittional processing of specific vars |
73 |
+ |
print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n"; |
74 |
+ |
print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n"; |
75 |
+ |
print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n"; |
76 |
+ |
print $fout 'lib+=$(extralib)'."\n"; |
77 |
+ |
print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n"; |
78 |
+ |
print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n"; |
79 |
+ |
|
80 |
+ |
undef $fout; |
81 |
+ |
} |
82 |
+ |
} |
83 |
+ |
|
84 |
+ |
sub BuildSetup { |
85 |
+ |
my $self=shift; |
86 |
+ |
my $THISDIR=shift; |
87 |
+ |
my @Targets=@_; |
88 |
+ |
my $DefaultBuildFile=""; |
89 |
+ |
my $Class=""; |
90 |
+ |
|
91 |
+ |
# -- Create working directory |
92 |
+ |
chdir $ENV{LOCALTOP}; |
93 |
+ |
AddDir::adddir($ENV{INTwork}."/".$THISDIR); |
94 |
+ |
|
95 |
+ |
my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR); |
96 |
+ |
$self->verbose("Class = $Class"); |
97 |
+ |
$self->verbose("ClassDir = $ClassDir"); |
98 |
+ |
|
99 |
+ |
if ( $bf->ignore() ) { |
100 |
+ |
print "Nothing to be done - empty group\n"; |
101 |
+ |
exit; |
102 |
+ |
} |
103 |
+ |
shift; |
104 |
+ |
$self->_generateexternals($ENV{LOCALTOP}."/".$ENV{INTwork}."/clientmakefile"); |
105 |
+ |
|
106 |
+ |
# set up the workdir variable |
107 |
+ |
$ENV{workdir}=$ENV{INTwork}."/".$ClassDir; |
108 |
+ |
my $fullworkdir=$ENV{LOCALTOP}."/".$ENV{workdir}; |
109 |
+ |
|
110 |
+ |
# set up projdeps variable |
111 |
+ |
my $projectfile=$ENV{projconfigdir}."/External_Dependencies"; |
112 |
+ |
if ( -e $ENV{LOCALTOP}."/".$projectfile ) { |
113 |
+ |
$ENV{projdeps}=$ENV{LOCALTOP}."/".$projectfile; |
114 |
+ |
} |
115 |
+ |
elsif ( -e $ENV{RELEASETOP}."/".$projectfile ) { |
116 |
+ |
$ENV{projectfile}=$ENV{RELEASETOP}."/".$projectfile; |
117 |
+ |
} |
118 |
+ |
else { |
119 |
+ |
print "Warning : Unable to find $projectfile\n"; |
120 |
+ |
} |
121 |
+ |
if ( $DefaultBuildFile eq "" ) { |
122 |
+ |
# Map Relevant makefile classmakefile directory |
123 |
+ |
my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk"; |
124 |
+ |
if ( -e $ENV{LOCALTOP}."/".$classmakefile ) { |
125 |
+ |
$ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile; |
126 |
+ |
} |
127 |
+ |
elsif ( -e $ENV{RELEASETOP}."/".$classmakefile ) { |
128 |
+ |
$ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile; |
129 |
+ |
} |
130 |
+ |
else { |
131 |
+ |
print "\nUnable to locate $classmakefile\n"; |
132 |
+ |
print " Not in $ENV{LOCALTOP}\n"; |
133 |
+ |
print " Not in $ENV{RELEASETOP}\n"; |
134 |
+ |
exit 1; |
135 |
+ |
} |
136 |
+ |
$DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override |
137 |
+ |
} |
138 |
+ |
|
139 |
+ |
$ENV{ClassDir}=$ClassDir; |
140 |
+ |
$ENV{Class}=$Class; |
141 |
+ |
$ENV{DefaultBuildFile}=$DefaultBuildFile; |
142 |
+ |
|
143 |
+ |
chdir $fullworkdir || die "Unable to enter working directory $!"; |
144 |
+ |
|
145 |
+ |
# Set up some other useful variables fo the Build |
146 |
+ |
# list of directories available |
147 |
+ |
opendir IDR, "$ENV{LOCALTOP}/$THISDIR"; |
148 |
+ |
@allfiles= grep !/^\.\.?$/, readdir IDR; |
149 |
+ |
foreach $file ( @allfiles ) { |
150 |
+ |
if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" ) { # only add if its a directory |
151 |
+ |
$ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file; |
152 |
+ |
} |
153 |
+ |
else { |
154 |
+ |
$ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file; |
155 |
+ |
} |
156 |
+ |
} |
157 |
+ |
$targetnumber=$#Targets; |
158 |
+ |
foreach $word ( @Targets ) { |
159 |
+ |
if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target |
160 |
+ |
$targetnumber--; |
161 |
+ |
} |
162 |
+ |
else { |
163 |
+ |
$ENV{"MAKETARGET_".$word}=$word; |
164 |
+ |
} |
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
# If not specified default to the class name target |
168 |
+ |
if ( $targetnumber == -1 ) { |
169 |
+ |
push @Targets,$Class; |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
$ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk"; |
173 |
+ |
|
174 |
+ |
$SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk"; |
175 |
+ |
if ( -f $SCRAM_GROUPSDIR ) { |
176 |
+ |
$ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR; |
177 |
+ |
} |
178 |
+ |
|
179 |
+ |
# Do a datestamp check so that make will build files that have changed |
180 |
+ |
# rather than just those which are older than their dependencies |
181 |
+ |
# The main build here |
182 |
+ |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config); |
183 |
+ |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets); |
184 |
+ |
return $rv/256; # return the exit status of gmake |
185 |
+ |
} |
186 |
+ |
|
187 |
+ |
sub getclass { |
188 |
+ |
my $self=shift; |
189 |
+ |
my $dirname = shift; |
190 |
+ |
my $Class="DEFAULT"; |
191 |
+ |
my $ClassDir=""; |
192 |
+ |
|
193 |
+ |
#return if $dirname eq ""; |
194 |
+ |
@DIRA=split /\//, $dirname; |
195 |
+ |
|
196 |
+ |
$thispath="."; |
197 |
+ |
# bootstrap from project buildfile if it exists |
198 |
+ |
my $bf=BuildSystem::BuildFile->new($self->{toolbox}); |
199 |
+ |
$bf->CheckBuildFile($ENV{projconfigdir}); |
200 |
+ |
|
201 |
+ |
my @ClassPaths=split /:/, $bf->BlockClassPath(); |
202 |
+ |
foreach $BClassPath ( @ClassPaths ) { |
203 |
+ |
next if ( $BClassPath eq ""); |
204 |
+ |
push @LoBCA, [ split /\//, $BClassPath ]; |
205 |
+ |
} |
206 |
+ |
for ( $i=0; $i<=$#DIRA; $i++ ) { |
207 |
+ |
$thispath=$thispath."/".$DIRA[$i]; |
208 |
+ |
if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) { |
209 |
+ |
$Class=$ClassName; |
210 |
+ |
$ClassDir=$thispath; |
211 |
+ |
} |
212 |
+ |
# TODO --- Must test against position of last new BlockCaseA |
213 |
+ |
# Need to reset array LoBCA to the New BlockPath |
214 |
+ |
# - merge and replace options |
215 |
+ |
# |
216 |
+ |
else { |
217 |
+ |
foreach $BlockClassA ( @LoBCA ) { |
218 |
+ |
if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) { |
219 |
+ |
$$BlockClassA[0]=~s/^$DIRA[$i]//; |
220 |
+ |
} |
221 |
+ |
if ( $$BlockClassA[0]=~/^\+/ ) { |
222 |
+ |
($Class=$$BlockClassA[0])=~s/^\+//; |
223 |
+ |
$ClassDir=$thispath; |
224 |
+ |
shift @$BlockClassA; |
225 |
+ |
} |
226 |
+ |
else { |
227 |
+ |
@$BlockClassA=(); |
228 |
+ |
} |
229 |
+ |
} |
230 |
+ |
} |
231 |
+ |
} |
232 |
+ |
$ClassDir=~s/^\.\///; |
233 |
+ |
return ( $Class, $ClassDir, $bf); |
234 |
+ |
} |