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.3.2.1
Committed: Mon Nov 13 15:49:49 2000 UTC (24 years, 6 months ago) by williamc
Content type: text/plain
Branch: V0_17branch
CVS Tags: V0_18_0
Changes since 1.1.2.7.2.2.2.1.2.3: +5 -0 lines
Log Message:
changes for tool makefiles

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 williamc 1.1.2.1 return $self;
25     }
26    
27     sub _generateexternals {
28     my $self=shift;
29     my $outfile=shift;
30    
31     # -- specifiy these files for dependency information
32     my $depfile=$ENV{projconfigdir}."/External_Dependencies";
33 williamc 1.1.2.3
34     # -- get list of dependent files
35     my $datadir=$ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH};
36     $fdir=FileHandle->new();
37 williamc 1.1.2.7 opendir $fdir, $datadir;
38 williamc 1.1.2.3 my @depfiles=grep !/^\.\.?$/, readdir $fdir;
39     undef $fdir;
40     for (my $i=0; $i<=$#depfiles; $i++ ) {
41     $depfiles[$i]=$datadir."/".$depfiles[$i];
42     }
43    
44 williamc 1.1.2.1 # -- do we need to rebuild?
45 williamc 1.1.2.3 if ( SCRAMUtils::dated($outfile,@depfiles) ) {
46 williamc 1.1.2.1 print "Configuring Local Area\n";
47     # -- open output file
48     my $fout=FileHandle->new();
49     $fout->open(">".$outfile) or die "Unable to open $outfile for output".
50     $!."\n";
51    
52     # -- print out tool/ version info
53     my ($tool,$toolobj,$f,$val,$version);
54 williamc 1.1.2.7.2.1 foreach $tool ( $self->{toolbox}->tools() ) {
55     $version=$self->{toolbox}->defaultversion($tool);
56 williamc 1.1.2.2 # default versions
57 williamc 1.1.2.1 print $fout "ifdef $tool\n".$tool."_V_".$version."=true\nendif\n";
58 williamc 1.1.2.7.2.1 # -- set up the different version -- externals
59     foreach $version ( $self->{toolbox}->versions($tool) ) {
60     $toolobj=$self->{toolbox}->gettool($tool,$version);
61     @deps=$toolobj->getfeature("_externals");
62     foreach $d ( @deps ) {
63 williamc 1.1.2.6 $d=~tr[A-Z][a-z];
64 williamc 1.1.2.2 print $fout "ifdef ".$tool."_V_".$version."\n $d=true\nendif\n";
65 williamc 1.1.2.7.2.1 }
66     # -- tool info
67     print $fout "ifdef ".$tool."_V_".$version."\n";
68     foreach $f ( $toolobj->features() ) {
69 williamc 1.1.2.1 foreach $val ( $toolobj->getfeature($f) ) {
70     print $fout "\t".$f." += ".$val."\n";
71     }
72 williamc 1.1.2.7.2.1 }
73 williamc 1.1.2.7.2.2.2.1.2.3.2.1 # -- include any makefiles associated with the tool
74     if ( -f $self->{toolbox}->toolmakefile($tool,$version) ) {
75     print $fout "-include ".
76     $self->{toolbox}->toolmakefile($tool,$version)."\n";
77     }
78 williamc 1.1.2.7.2.1 print $fout "endif\n";
79 williamc 1.1.2.1 }
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 williamc 1.1.2.7.2.2.2.1.2.3 print $fout 'LD_LIBRARY_PATH:=$(subst $(space),:,$(LD_LIBRARY_PATH))'."\n";
89 williamc 1.1.2.1
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 williamc 1.1.2.7.2.2.2.1.2.1 elsif ( $word=~/^-/ ) {
170     $targetnumber--;
171     }
172 williamc 1.1.2.1 else {
173     $ENV{"MAKETARGET_".$word}=$word;
174     }
175     }
176    
177     # If not specified default to the class name target
178     if ( $targetnumber == -1 ) {
179     push @Targets,$Class;
180     }
181    
182     $ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk";
183    
184     $SCRAM_GROUPSDIR=$ENV{LOCALTOP}."/".$ENV{projconfigdir}."/groups.mk";
185     if ( -f $SCRAM_GROUPSDIR ) {
186     $ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR;
187     }
188    
189     # Do a datestamp check so that make will build files that have changed
190     # rather than just those which are older than their dependencies
191     # The main build here
192     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config);
193     $rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets);
194     return $rv/256; # return the exit status of gmake
195     }
196    
197     sub getclass {
198     my $self=shift;
199     my $dirname = shift;
200     my $Class="DEFAULT";
201     my $ClassDir="";
202    
203     #return if $dirname eq "";
204     @DIRA=split /\//, $dirname;
205    
206     $thispath=".";
207     # bootstrap from project buildfile if it exists
208     my $bf=BuildSystem::BuildFile->new($self->{toolbox});
209     $bf->CheckBuildFile($ENV{projconfigdir});
210    
211     my @ClassPaths=split /:/, $bf->BlockClassPath();
212     foreach $BClassPath ( @ClassPaths ) {
213     next if ( $BClassPath eq "");
214     push @LoBCA, [ split /\//, $BClassPath ];
215     }
216     for ( $i=0; $i<=$#DIRA; $i++ ) {
217     $thispath=$thispath."/".$DIRA[$i];
218     if ( ($ClassName=$bf->CheckBuildFile($thispath)) ne "" ) {
219     $Class=$ClassName;
220     $ClassDir=$thispath;
221     }
222     # TODO --- Must test against position of last new BlockCaseA
223     # Need to reset array LoBCA to the New BlockPath
224     # - merge and replace options
225     #
226     else {
227     foreach $BlockClassA ( @LoBCA ) {
228     if ( $$BlockClassA[0]=~/^$DIRA[$i]\+/ ) {
229     $$BlockClassA[0]=~s/^$DIRA[$i]//;
230     }
231     if ( $$BlockClassA[0]=~/^\+/ ) {
232     ($Class=$$BlockClassA[0])=~s/^\+//;
233     $ClassDir=$thispath;
234     shift @$BlockClassA;
235     }
236     else {
237     @$BlockClassA=();
238     }
239     }
240     }
241     }
242     $ClassDir=~s/^\.\///;
243     return ( $Class, $ClassDir, $bf);
244     }