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
Committed: Mon Aug 14 15:35:18 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: V0_14_0
Branch point for: V0_15branch
Changes since 1.1.2.7.2.1: +0 -2 lines
Log Message:
Clean out old comments

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