ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.14
Committed: Thu Jul 27 11:06:03 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_13_3, V0_13_2
Changes since 1.1.2.13: +8 -0 lines
Log Message:
add MAKETARGETS variable

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