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.2
Committed: Tue Oct 31 13:05:04 2000 UTC (24 years, 6 months ago) by williamc
Content type: text/plain
Branch: V0_16branch
Changes since 1.1.2.7.2.2.2.1.2.1: +0 -7 lines
Log Message:
Remove obsolete init method

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