ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.7.2.2.2.1.2.1
Committed: Thu Oct 26 09:57:51 2000 UTC (24 years, 6 months ago) by williamc
Content type: text/plain
Branch: V0_16branch
CVS Tags: V0_16_3, V0_16_2, V0_16_1
Changes since 1.1.2.7.2.2.2.1: +3 -0 lines
Log Message:
take into account -xxx options when considering the number of targets

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 $ENV{SCRAM_ARCH});
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 $tool ( $self->{toolbox}->tools() ) {
62 $version=$self->{toolbox}->defaultversion($tool);
63 # default versions
64 print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
65 # -- set up the different version -- externals
66 foreach $version ( $self->{toolbox}->versions($tool) ) {
67 $toolobj=$self->{toolbox}->gettool($tool,$version);
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 }
83 # some addittional processing of specific vars
84 print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
85 print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
86 print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
87 print $fout 'lib+=$(extralib)'."\n";
88 print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
89 print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
90
91 undef $fout;
92 }
93 }
94
95 sub BuildSetup {
96 my $self=shift;
97 my $THISDIR=shift;
98 my @Targets=@_;
99 my $DefaultBuildFile="";
100 my $Class="";
101
102 # -- Create working directory
103 chdir $ENV{LOCALTOP};
104 AddDir::adddir($ENV{INTwork}."/".$THISDIR);
105
106 my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
107 $self->verbose("Class = $Class");
108 $self->verbose("ClassDir = $ClassDir");
109
110 if ( $bf->ignore() ) {
111 print "Nothing to be done - empty group\n";
112 exit;
113 }
114 shift;
115 $self->_generateexternals($ENV{LOCALTOP}."/".$ENV{INTwork}."/clientmakefile");
116
117 # set up the workdir variable
118 $ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
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 ( $DefaultBuildFile eq "" ) {
130 # Map Relevant makefile classmakefile directory
131 my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk";
132 if ( -e $ENV{LOCALTOP}."/".$classmakefile ) {
133 $ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile;
134 }
135 elsif ( -e $ENV{RELEASETOP}."/".$classmakefile ) {
136 $ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile;
137 }
138 else {
139 print "\nUnable to locate $classmakefile\n";
140 print " Not in $ENV{LOCALTOP}\n";
141 print " Not in $ENV{RELEASETOP}\n";
142 exit 1;
143 }
144 $DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override
145 }
146
147 $ENV{ClassDir}=$ClassDir;
148 $ENV{Class}=$Class;
149 $ENV{DefaultBuildFile}=$DefaultBuildFile;
150
151 chdir $fullworkdir || die "Unable to enter working directory $!";
152
153 # Set up some other useful variables fo the Build
154 # list of directories available
155 opendir IDR, "$ENV{LOCALTOP}/$THISDIR";
156 @allfiles= grep !/^\.\.?$/, readdir IDR;
157 foreach $file ( @allfiles ) {
158 if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" ) { # only add if its a directory
159 $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
160 }
161 else {
162 $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
163 }
164 }
165 $targetnumber=$#Targets;
166 foreach $word ( @Targets ) {
167 if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
168 $targetnumber--;
169 }
170 elsif ( $word=~/^-/ ) {
171 $targetnumber--;
172 }
173 else {
174 $ENV{"MAKETARGET_".$word}=$word;
175 }
176 }
177
178 # If not specified default to the class name target
179 if ( $targetnumber == -1 ) {
180 push @Targets,$Class;
181 }
182
183 $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
184
185 $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
186 if ( -f $SCRAM_GROUPSDIR ) {
187 $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
188 }
189
190 # Do a datestamp check so that make will build files that have changed
191 # rather than just those which are older than their dependencies
192 # The main build here
193 $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
194 $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
195 return $rv/256; # return the exit status of gmake
196 }
197
198 sub getclass {
199 my $self=shift;
200 my $dirname = shift;
201 my $Class="DEFAULT";
202 my $ClassDir="";
203
204 #return if $dirname eq "";
205 @DIRA=split /\//, $dirname;
206
207 $thispath=".";
208 # bootstrap from project buildfile if it exists
209 my $bf=BuildSystem::BuildFile->new($self->{toolbox});
210 $bf->CheckBuildFile($ENV{projconfigdir});
211
212 my @ClassPaths=split /:/, $bf->BlockClassPath();
213 foreach $BClassPath ( @ClassPaths ) {
214 next if ( $BClassPath eq "");
215 push @LoBCA, [ split /\//, $BClassPath ];
216 }
217 for ( $i=0; $i<=$#DIRA; $i++ ) {
218 $thispath=$thispath."/".$DIRA[$i];
219 if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
220 $Class=$ClassName;
221 $ClassDir=$thispath;
222 }
223 # TODO --- Must test against position of last new BlockCaseA
224 # Need to reset array LoBCA to the New BlockPath
225 # - merge and replace options
226 #
227 else {
228 foreach $BlockClassA ( @LoBCA ) {
229 if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
230 $$BlockClassA[0]=~s/^$DIRA[$i]//;
231 }
232 if ( $$BlockClassA[0]=~/^\+/ ) {
233 ($Class=$$BlockClassA[0])=~s/^\+//;
234 $ClassDir=$thispath;
235 shift @$BlockClassA;
236 }
237 else {
238 @$BlockClassA=();
239 }
240 }
241 }
242 }
243 $ClassDir=~s/^\.\///;
244 return ( $Class, $ClassDir, $bf);
245 }