ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.3
Committed: Wed Sep 6 10:14:29 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.2: +57 -36 lines
Log Message:
Import from V0_13_3

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 #
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 return $self;
28 }
29
30 sub _generateexternals {
31 my $self=shift;
32 my $outfile=shift;
33
34 # -- specifiy these files for dependency information
35 my $depfile=$self->{projconfigdir}."/External_Dependencies";
36
37 # -- get list of dependent files
38 my $datadir=$self->{localtop}."/.SCRAM/".$ENV{SCRAM_ARCH};
39 $fdir=FileHandle->new();
40 opendir $fdir, $datadir;
41 my @depfiles=grep !/^\.\.?$/, readdir $fdir;
42 undef $fdir;
43 for (my $i=0; $i<=$#depfiles; $i++ ) {
44 $depfiles[$i]=$datadir."/".$depfiles[$i];
45 }
46
47 # -- do we need to rebuild?
48 if ( SCRAMUtils::dated($outfile,@depfiles) ) {
49 print "Configuring Local Area\n";
50 # -- open output file
51 my $fout=FileHandle->new();
52 $fout->open(">".$outfile) or die "Unable to open $outfile for output".
53 $!."\n";
54
55 # -- print out tool/ version info
56 my ($tool,$toolobj,$f,$val,$version);
57 foreach $tool ( $self->{toolbox}->tools() ) {
58 $version=$self->{toolbox}->defaultversion($tool);
59 # default versions
60 print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
61 # -- set up the different version -- externals
62 foreach $version ( $self->{toolbox}->versions($tool) ) {
63 $toolobj=$self->{toolbox}->gettool($tool,$version);
64 @deps=$toolobj->getfeature("_externals");
65 foreach $d ( @deps ) {
66 $d=~tr[A-Z][a-z];
67 print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
68 }
69 # -- tool info
70 print $fout "ifdef ".$tool."_V_".$version."\n";
71 foreach $f ( $toolobj->features() ) {
72 foreach $val ( $toolobj->getfeature($f) ) {
73 print $fout "\t".$f." += ".$val."\n";
74 }
75 }
76 print $fout "endif\n";
77 }
78 }
79 # some addittional processing of specific vars
80 print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
81 print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
82 print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
83 print $fout 'lib+=$(extralib)'."\n";
84 print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
85 print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
86
87 undef $fout;
88 $self->verbose("End Configuration Setup");
89 }
90 }
91
92 sub BuildSetup {
93 my $self=shift;
94 my $THISDIR=shift;
95 my @Targets=@_;
96 my $DefaultBuildFile="";
97
98 # -- Create working directory
99 chdir $self->{localtop};
100 AddDir::adddir($ENV{INTwork}."/".$THISDIR);
101
102 my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
103 $self->verbose("Class = $Class");
104 $self->verbose("ClassDir = $ClassDir");
105
106 if ( $bf->ignore() ) {
107 print "Nothing to be done - empty group\n";
108 exit;
109 }
110 shift;
111 $self->_generateexternals($self->{localtop}."/".$ENV{INTwork}."/clientmakefile");
112
113 # set up the workdir variable
114 #$ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
115 $ENV{workdir}=$ENV{INTwork}."/".$THISDIR;
116 my $fullworkdir=$self->{localtop}."/".$ENV{workdir};
117
118 # set up projdeps variable
119 my $projectfile=$self->{projconfigdir}."/External_Dependencies";
120 if ( -e $self->{localtop}."/".$projectfile ) {
121 $ENV{projdeps}=$self->{localtop}."/".$projectfile;
122 }
123 elsif ( -e $ENV{RELEASETOP}."/".$projectfile ) {
124 $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 }
153 }
154 # Map Relevant makefile classmakefile directory
155 $ENV{classmakefile}=$classmakefile;
156 $DefaultBuildFile=$ENV{classmakefile};
157 }
158
159 $ENV{ClassDir}=$ClassDir;
160 $ENV{Class}=$Class;
161 $ENV{DefaultBuildFile}=$DefaultBuildFile;
162
163 chdir $fullworkdir || die "Unable to enter working directory $!";
164
165 # Set up some other useful variables fo the Build
166 # list of directories available
167 opendir IDR, "$self->{localtop}/$THISDIR";
168 @allfiles= grep !/^\.\.?$/, readdir IDR;
169 foreach $file ( @allfiles ) {
170 if ( -d "$self->{localtop}/$THISDIR/$file" ) { # only add if its a directory
171 $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
172 }
173 else {
174 $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
175 }
176 }
177 $targetnumber=$#Targets;
178 $ENV{"MAKETARGETS"}="";
179 foreach $word ( @Targets ) {
180 if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
181 $targetnumber--;
182 }
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 }
199
200 $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
201
202 $SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk";
203 if ( -f $SCRAM_GROUPSDIR ) {
204 $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
205 }
206
207 # Do a datestamp check so that make will build files that have changed
208 # rather than just those which are older than their dependencies
209 # The main build here
210 $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 }
214
215 sub getclass {
216 my $self=shift;
217 my $dirname = shift;
218 my $Class="DEFAULT";
219 my $ClassDir="";
220
221 #return if $dirname eq "";
222 @DIRA=split /\//, $dirname;
223
224 $thispath=".";
225 # bootstrap from project buildfile if it exists
226 my $bf=BuildSystem::BuildFile->new($self->{area});
227 $bf->CheckBuildFile($self->{projconfigdir});
228
229 my @ClassPaths=split /:/, $bf->BlockClassPath();
230 foreach $BClassPath ( @ClassPaths ) {
231 next if ( $BClassPath eq "");
232 push @LoBCA, [ split /\//, $BClassPath ];
233 }
234 for ( $i=0; $i<=$#DIRA; $i++ ) {
235 $thispath=$thispath."/".$DIRA[$i];
236 if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
237 $Class=$ClassName;
238 $ClassDir=$thispath;
239 }
240 # TODO --- Must test against position of last new BlockCaseA
241 # Need to reset array LoBCA to the New BlockPath
242 # - merge and replace options
243 #
244 else {
245 foreach $BlockClassA ( @LoBCA ) {
246 if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
247 $$BlockClassA[0]=~s/^$DIRA[$i]//;
248 }
249 if ( $$BlockClassA[0]=~/^\+/ ) {
250 ($Class=$$BlockClassA[0])=~s/^\+//;
251 $ClassDir=$thispath;
252 shift @$BlockClassA;
253 }
254 else {
255 @$BlockClassA=();
256 }
257 }
258 }
259 }
260 $ClassDir=~s/^\.\///;
261 return ( $Class, $ClassDir, $bf);
262 }