ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/BuildSetup.pm
Revision: 1.1.2.5
Committed: Thu May 4 07:53:04 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_3
Changes since 1.1.2.4: +4 -3 lines
Log Message:
ToolBox Searching added + url bugfixes

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