ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.4
Committed: Thu Apr 20 13:49:54 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_2, V0_12_1, V0_12_0
Changes since 1.1.2.3: +0 -3 lines
Log Message:
Use requirements doc to determine version defaults

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     #
3     # Interface
4     # ---------
5     # new() : 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->init();
24     return $self;
25     }
26    
27     sub init {
28     my $self=shift;
29     $self->{toolbox}=BuildSystem::ToolBox->new();
30     }
31    
32     sub _generateexternals {
33     my $self=shift;
34     my $outfile=shift;
35    
36     # -- specifiy these files for dependency information
37     my $depfile=$ENV{projconfigdir}."/External_Dependencies";
38 williamc 1.1.2.3
39     # -- get list of dependent files
40     my $datadir=$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH};
41     $fdir=FileHandle->new();
42     opendir $fdir, $datadir or die
43     "unable to access $datadir $!\n";
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 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     print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
70     }
71     # -- tool info
72 williamc 1.1.2.1 print $fout "ifdef ".$tool."_V_".$version."\n";
73     foreach $f ( $toolobj->features() ) {
74     foreach $val ( $toolobj->getfeature($f) ) {
75     print $fout "\t".$f." += ".$val."\n";
76     }
77     }
78     print $fout "endif\n";
79     }
80     # some addittional processing of specific vars
81     print $fout 'INCLUDEPATH+=$(addprefix -I,$(INCLUDE))'."\n";
82     print $fout 'LDFLAGS+=$(addprefix -L,$(LIBDIR))'."\n";
83     print $fout 'CPPFLAGS+=$(addprefix -D,$(CPPDEFINES))'."\n";
84     print $fout 'lib+=$(extralib)'."\n";
85     print $fout 'LDLIBS+=$(addprefix -l,$(lib))'."\n";
86     print $fout 'LDLIBS+=$(addprefix -l,$(REQUIRES))'."\n";
87    
88     undef $fout;
89     }
90     }
91    
92     sub BuildSetup {
93     my $self=shift;
94     my $THISDIR=shift;
95     my @Targets=@_;
96     my $DefaultBuildFile="";
97     my $Class="";
98    
99     # -- Create working directory
100     chdir $ENV{LOCALTOP};
101     AddDir::adddir($ENV{INTwork}."/".$THISDIR);
102    
103     my ($Class, $ClassDir, $bf)=$self->getclass($THISDIR);
104     $self->verbose("Class = $Class");
105     $self->verbose("ClassDir = $ClassDir");
106    
107     if ( $bf->ignore() ) {
108     print "Nothing to be done - empty group\n";
109     exit;
110     }
111     shift;
112     $self->_generateexternals($ENV{LOCALTOP}."/".$ENV{INTwork}."/clientmakefile");
113    
114     # set up the workdir variable
115     $ENV{workdir}=$ENV{INTwork}."/".$ClassDir;
116     my $fullworkdir=$ENV{LOCALTOP}."/".$ENV{workdir};
117    
118     # set up projdeps variable
119     my $projectfile=$ENV{projconfigdir}."/External_Dependencies";
120     if ( -e $ENV{LOCALTOP}."/".$projectfile ) {
121     $ENV{projdeps}=$ENV{LOCALTOP}."/".$projectfile;
122     }
123     elsif ( -e $ENV{RELEASETOP}."/".$projectfile ) {
124     $ENV{projectfile}=$ENV{RELEASETOP}."/".$projectfile;
125     }
126     if ( $DefaultBuildFile eq "" ) {
127     # Map Relevant makefile classmakefile directory
128     my $classmakefile=$ENV{projconfigdir}."/".$Class."_makefile.mk";
129     if ( -e $ENV{LOCALTOP}."/".$classmakefile ) {
130     $ENV{classmakefile}=$ENV{LOCALTOP}."/".$classmakefile;
131     }
132     elsif ( -e $ENV{RELEASETOP}."/".$classmakefile ) {
133     $ENV{classmakefile}=$ENV{RELEASETOP}."/".$classmakefile;
134     }
135     else {
136     print "\nUnable to locate $classmakefile\n";
137     print " Not in $ENV{LOCALTOP}\n";
138     print " Not in $ENV{RELEASETOP}\n";
139     exit 1;
140     }
141     $DefaultBuildFile=$ENV{classmakefile}; # TODO - only for override
142     }
143    
144     $ENV{ClassDir}=$ClassDir;
145     $ENV{Class}=$Class;
146     $ENV{DefaultBuildFile}=$DefaultBuildFile;
147    
148     chdir $fullworkdir || die "Unable to enter working directory $!";
149    
150     # Set up some other useful variables fo the Build
151     # list of directories available
152     opendir IDR, "$ENV{LOCALTOP}/$THISDIR";
153     @allfiles= grep !/^\.\.?$/, readdir IDR;
154     foreach $file ( @allfiles ) {
155     if ( -d "$ENV{LOCALTOP}/$THISDIR/$file" ) { # only add if its a directory
156     $ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file;
157     }
158     else {
159     $ENV{SCRAM_AVAILFILES}=$ENV{SCRAM_AVAILFILES}." ".$file;
160     }
161     }
162     $targetnumber=$#Targets;
163     foreach $word ( @Targets ) {
164     if ( $word=~/.*=.*/ ) { # if we have an assignment it cant be a target
165     $targetnumber--;
166     }
167     else {
168     $ENV{"MAKETARGET_".$word}=$word;
169     }
170     }
171    
172     # If not specified default to the class name target
173     if ( $targetnumber == -1 ) {
174     push @Targets,$Class;
175     }
176    
177     $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
178    
179     $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
180     if ( -f $SCRAM_GROUPSDIR ) {
181     $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
182     }
183    
184     # Do a datestamp check so that make will build files that have changed
185     # rather than just those which are older than their dependencies
186     # The main build here
187     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
188     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
189     return $rv/256; # return the exit status of gmake
190     }
191    
192     sub getclass {
193     my $self=shift;
194     my $dirname = shift;
195     my $Class="DEFAULT";
196     my $ClassDir="";
197    
198     #return if $dirname eq "";
199     @DIRA=split /\//, $dirname;
200    
201     $thispath=".";
202     # bootstrap from project buildfile if it exists
203     my $bf=BuildSystem::BuildFile->new($self->{toolbox});
204     $bf->CheckBuildFile($ENV{projconfigdir});
205    
206     my @ClassPaths=split /:/, $bf->BlockClassPath();
207     foreach $BClassPath ( @ClassPaths ) {
208     next if ( $BClassPath eq "");
209     push @LoBCA, [ split /\//, $BClassPath ];
210     }
211     for ( $i=0; $i<=$#DIRA; $i++ ) {
212     $thispath=$thispath."/".$DIRA[$i];
213     if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
214     $Class=$ClassName;
215     $ClassDir=$thispath;
216     }
217     # TODO --- Must test against position of last new BlockCaseA
218     # Need to reset array LoBCA to the New BlockPath
219     # - merge and replace options
220     #
221     else {
222     foreach $BlockClassA ( @LoBCA ) {
223     if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
224     $$BlockClassA[0]=~s/^$DIRA[$i]//;
225     }
226     if ( $$BlockClassA[0]=~/^\+/ ) {
227     ($Class=$$BlockClassA[0])=~s/^\+//;
228     $ClassDir=$thispath;
229     shift @$BlockClassA;
230     }
231     else {
232     @$BlockClassA=();
233     }
234     }
235     }
236     }
237     $ClassDir=~s/^\.\///;
238     return ( $Class, $ClassDir, $bf);
239     }