ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.10
Committed: Thu Jun 8 10:33:18 2000 UTC (24 years, 11 months ago) by williamc
Content type: text/plain
Branch: V0_9branch
Changes since 1.1.2.9: +3 -0 lines
Log Message:
Get Build hierarcy correct

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     #
3     # Interface
4     # ---------
5 williamc 1.1.2.5 # new(toolbox) : A new BuildSetup
6 williamc 1.1.2.1 # 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 williamc 1.1.2.5 $self->{toolbox}=shift;
24     #$self->init();
25 williamc 1.1.2.1 return $self;
26     }
27    
28     sub init {
29     my $self=shift;
30 williamc 1.1.2.5 $self->{toolbox}=BuildSystem::ToolBox->new($ENV{LOCALTOP});
31 williamc 1.1.2.1 }
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 williamc 1.1.2.3
40     # -- get list of dependent files
41     my $datadir=$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH};
42     $fdir=FileHandle->new();
43 williamc 1.1.2.7 opendir $fdir, $datadir;
44 williamc 1.1.2.3 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 williamc 1.1.2.1 # -- do we need to rebuild?
51 williamc 1.1.2.3 if ( SCRAMUtils::dated($outfile,@depfiles) ) {
52 williamc 1.1.2.1 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 williamc 1.1.2.2 # default versions
64 williamc 1.1.2.1 print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
65     $toolobj=$self->{toolbox}->gettool($tool,$version);
66 williamc 1.1.2.2 # -- externals
67     @deps=$toolobj->getfeature("_externals");
68     foreach $d ( @deps ) {
69 williamc 1.1.2.6 $d=~tr[A-Z][a-z];
70 williamc 1.1.2.2 print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
71     }
72     # -- tool info
73 williamc 1.1.2.1 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     undef $fout;
89 williamc 1.1.2.9
90 williamc 1.1.2.8 $self->verbose("End Configuration Setup");
91 williamc 1.1.2.1 }
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 williamc 1.1.2.8 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 williamc 1.1.2.10 undef $ENV{LatestBuildFile};
142 williamc 1.1.2.8 $classbf->GenerateMakefile($classbuildfile, $classmakefile);
143 williamc 1.1.2.10 undef $ENV{LatestBuildFile}; # we dont want this included in the
144     # hierarchy
145 williamc 1.1.2.8 }
146 williamc 1.1.2.1 }
147     else {
148 williamc 1.1.2.8 $classmakefile=$ENV{LOCALTOP}."/".
149     $ENV{projconfigdir}."/".$Class."_makefile.mk";
150     if ( ! -f $classmakefile ) {
151     $self->error("Unable to find matching ".$Class."_BuildFile or ".
152     $Class."_makefile.mk");
153     }
154 williamc 1.1.2.1 }
155 williamc 1.1.2.8 # Map Relevant makefile classmakefile directory
156     $ENV{classmakefile}=$classmakefile;
157     $DefaultBuildFile=$ENV{classmakefile};
158     }
159 williamc 1.1.2.1
160     $ENV{ClassDir}=$ClassDir;
161     $ENV{Class}=$Class;
162     $ENV{DefaultBuildFile}=$DefaultBuildFile;
163    
164     chdir $fullworkdir || die "Unable to enter working directory $!";
165    
166     # Set up some other useful variables fo the Build
167     # list of directories available
168     opendir IDR, "$ENV{LOCALTOP}/$THISDIR";
169     @allfiles= grep !/^\.\.?$/, readdir IDR;
170     foreach $file ( @allfiles ) {
171     if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" ) { # only add if its a directory
172     $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
173     }
174     else {
175     $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
176     }
177     }
178     $targetnumber=$#Targets;
179     foreach $word ( @Targets ) {
180     if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
181     $targetnumber--;
182     }
183     else {
184     $ENV{"MAKETARGET_".$word}=$word;
185     }
186     }
187    
188     # If not specified default to the class name target
189     if ( $targetnumber == -1 ) {
190     push @Targets,$Class;
191     }
192    
193     $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
194    
195     $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
196     if ( -f $SCRAM_GROUPSDIR ) {
197     $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
198     }
199    
200     # Do a datestamp check so that make will build files that have changed
201     # rather than just those which are older than their dependencies
202     # The main build here
203     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
204     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
205     return $rv/256; # return the exit status of gmake
206     }
207    
208     sub getclass {
209     my $self=shift;
210     my $dirname = shift;
211     my $Class="DEFAULT";
212     my $ClassDir="";
213    
214     #return if $dirname eq "";
215     @DIRA=split /\//, $dirname;
216    
217     $thispath=".";
218     # bootstrap from project buildfile if it exists
219     my $bf=BuildSystem::BuildFile->new($self->{toolbox});
220     $bf->CheckBuildFile($ENV{projconfigdir});
221    
222     my @ClassPaths=split /:/, $bf->BlockClassPath();
223     foreach $BClassPath ( @ClassPaths ) {
224     next if ( $BClassPath eq "");
225     push @LoBCA, [ split /\//, $BClassPath ];
226     }
227     for ( $i=0; $i<=$#DIRA; $i++ ) {
228     $thispath=$thispath."/".$DIRA[$i];
229     if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
230     $Class=$ClassName;
231     $ClassDir=$thispath;
232     }
233     # TODO --- Must test against position of last new BlockCaseA
234     # Need to reset array LoBCA to the New BlockPath
235     # - merge and replace options
236     #
237     else {
238     foreach $BlockClassA ( @LoBCA ) {
239     if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
240     $$BlockClassA[0]=~s/^$DIRA[$i]//;
241     }
242     if ( $$BlockClassA[0]=~/^\+/ ) {
243     ($Class=$$BlockClassA[0])=~s/^\+//;
244     $ClassDir=$thispath;
245     shift @$BlockClassA;
246     }
247     else {
248     @$BlockClassA=();
249     }
250     }
251     }
252     }
253     $ClassDir=~s/^\.\///;
254     return ( $Class, $ClassDir, $bf);
255     }