ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.7.2.1
Committed: Mon Aug 14 15:03:07 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
Changes since 1.1.2.7: +15 -12 lines
Log Message:
Update for new toolbox interface

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