ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.8
Committed: Mon Jun 5 14:51:04 2000 UTC (24 years, 11 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.7: +26 -14 lines
Log Message:
Allow for Class BuildFiles as well as Class_makefile.mk files

File Contents

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