1 |
+ |
#____________________________________________________________________ |
2 |
+ |
# File: ToolData.pm |
3 |
+ |
#____________________________________________________________________ |
4 |
+ |
# |
5 |
+ |
# Author: Shaun Ashby <Shaun.Ashby@cern.ch> |
6 |
+ |
# Update: 2003-11-21 15:26:07+0100 |
7 |
+ |
# Revision: $Id$ |
8 |
+ |
# |
9 |
+ |
# Copyright: 2003 (C) Shaun Ashby |
10 |
+ |
# |
11 |
+ |
#-------------------------------------------------------------------- |
12 |
+ |
package BuildSystem::ToolData; |
13 |
+ |
require 5.004; |
14 |
+ |
|
15 |
+ |
use Exporter; |
16 |
+ |
|
17 |
+ |
@ISA=qw(Exporter); |
18 |
+ |
# |
19 |
+ |
sub new |
20 |
+ |
############################################################### |
21 |
+ |
# new # |
22 |
+ |
############################################################### |
23 |
+ |
# modified : Fri Nov 21 15:26:14 2003 / SFA # |
24 |
+ |
# params : # |
25 |
+ |
# : # |
26 |
+ |
# function : # |
27 |
+ |
# : # |
28 |
+ |
############################################################### |
29 |
+ |
{ |
30 |
+ |
my $proto=shift; |
31 |
+ |
my $class=ref($proto) || $proto; |
32 |
+ |
my $self={SCRAM_PROJECT => 0}; |
33 |
+ |
bless $self,$class; |
34 |
+ |
return $self; |
35 |
+ |
} |
36 |
+ |
|
37 |
+ |
sub toolname() |
38 |
+ |
{ |
39 |
+ |
my $self=shift; |
40 |
+ |
@_ ? $self->{TOOLNAME} = shift |
41 |
+ |
: $self->{TOOLNAME}; |
42 |
+ |
} |
43 |
+ |
|
44 |
+ |
sub toolversion() |
45 |
+ |
{ |
46 |
+ |
my $self=shift; |
47 |
+ |
@_ ? $self->{TOOLVERSION} = shift |
48 |
+ |
: $self->{TOOLVERSION}; |
49 |
+ |
} |
50 |
+ |
|
51 |
+ |
sub lib() |
52 |
+ |
{ |
53 |
+ |
my $self=shift; |
54 |
+ |
# Add libs to array: |
55 |
+ |
@_ ? push(@{$self->{LIB}},@{$_[0]}) |
56 |
+ |
: @{$self->{LIB}}; |
57 |
+ |
} |
58 |
+ |
|
59 |
+ |
sub include() |
60 |
+ |
{ |
61 |
+ |
my $self=shift; |
62 |
+ |
# Add libs to array: |
63 |
+ |
@_ ? push(@{$self->{INCLUDE}},@{$_[0]}) |
64 |
+ |
: @{$self->{INCLUDE}}; |
65 |
+ |
} |
66 |
+ |
|
67 |
+ |
sub libdir() |
68 |
+ |
{ |
69 |
+ |
my $self=shift; |
70 |
+ |
# Add libdir to array: |
71 |
+ |
@_ ? push(@{$self->{LIBDIR}},@{$_[0]}) |
72 |
+ |
: @{$self->{LIBDIR}}; |
73 |
+ |
} |
74 |
+ |
|
75 |
+ |
sub use() |
76 |
+ |
{ |
77 |
+ |
my $self=shift; |
78 |
+ |
# Add deps to array: |
79 |
+ |
@_ ? push(@{$self->{USE}},@{$_[0]}) |
80 |
+ |
: @{$self->{USE}}; |
81 |
+ |
} |
82 |
+ |
|
83 |
+ |
sub makefile() |
84 |
+ |
{ |
85 |
+ |
my $self=shift; |
86 |
+ |
@_ ? push(@{$self->{MAKEFILE}},@{$_[0]}) |
87 |
+ |
: @{$self->{MAKEFILE}}; |
88 |
+ |
} |
89 |
+ |
|
90 |
+ |
sub flags() |
91 |
+ |
{ |
92 |
+ |
my $self=shift; |
93 |
+ |
my ($flag,$flagvalue) = @_; |
94 |
+ |
|
95 |
+ |
if ($flag && $flagvalue) |
96 |
+ |
{ |
97 |
+ |
if (exists ($self->{FLAGS}->{$flag})) |
98 |
+ |
{ |
99 |
+ |
# Add each flag ONLY if it doesn't already exist: |
100 |
+ |
foreach my $F (@$flagvalue) |
101 |
+ |
{ |
102 |
+ |
push(@{$self->{FLAGS}->{$flag}},$F), |
103 |
+ |
if (! grep($F eq $_,@{$self->{FLAGS}->{$flag}})); |
104 |
+ |
} |
105 |
+ |
} |
106 |
+ |
else |
107 |
+ |
{ |
108 |
+ |
$self->{FLAGS}->{$flag} = [ @$flagvalue ]; |
109 |
+ |
} |
110 |
+ |
} |
111 |
+ |
elsif ($flag && $self->{FLAGS}->{$flag}->[0] ne '') |
112 |
+ |
{ |
113 |
+ |
return @{$self->{FLAGS}->{$flag}}; |
114 |
+ |
} |
115 |
+ |
else |
116 |
+ |
{ |
117 |
+ |
return ""; |
118 |
+ |
} |
119 |
+ |
} |
120 |
+ |
|
121 |
+ |
sub allflags() |
122 |
+ |
{ |
123 |
+ |
my $self=shift; |
124 |
+ |
(scalar(keys %{$self->{FLAGS}}) > 0) ? return $self->{FLAGS} : return undef; |
125 |
+ |
} |
126 |
+ |
|
127 |
+ |
sub scram_project() |
128 |
+ |
{ |
129 |
+ |
my $self=shift; |
130 |
+ |
@_ ? $self->{SCRAM_PROJECT} = shift |
131 |
+ |
: $self->{SCRAM_PROJECT}; |
132 |
+ |
} |
133 |
+ |
|
134 |
+ |
sub variable_data() |
135 |
+ |
{ |
136 |
+ |
my $self=shift; |
137 |
+ |
my ($varname,$varvalue) = @_; |
138 |
+ |
|
139 |
+ |
if ($varname && $varvalue) |
140 |
+ |
{ |
141 |
+ |
$self->{$varname} = $varvalue; # Maybe need to handle more than one value? |
142 |
+ |
# Keep track of all variables: |
143 |
+ |
if (! grep($varname eq $_, @{$self->{VARIABLES}}))# Remove duplicates!! |
144 |
+ |
{ |
145 |
+ |
push(@{$self->{VARIABLES}},$varname); |
146 |
+ |
} |
147 |
+ |
} |
148 |
+ |
else |
149 |
+ |
{ |
150 |
+ |
return $self->{$varname}; |
151 |
+ |
} |
152 |
+ |
} |
153 |
+ |
|
154 |
+ |
sub list_variables |
155 |
+ |
{ |
156 |
+ |
my $self=shift; |
157 |
+ |
return @{$self->{VARIABLES}}; |
158 |
+ |
} |
159 |
+ |
|
160 |
+ |
sub runtime() |
161 |
+ |
{ |
162 |
+ |
my $self=shift; |
163 |
+ |
my ($rt,$rtvalue) = @_; |
164 |
+ |
|
165 |
+ |
# If both a runtime name and value are supplied, store this variable: |
166 |
+ |
if ($rt && $rtvalue) |
167 |
+ |
{ |
168 |
+ |
# Check to see if the environment already exists: |
169 |
+ |
if (exists ($self->{RUNTIME}->{$rt})) |
170 |
+ |
{ |
171 |
+ |
push(@{$self->{RUNTIME}->{$rt}},@$rtvalue); |
172 |
+ |
} |
173 |
+ |
else |
174 |
+ |
{ |
175 |
+ |
# Doesn't already exist so just set the value, in an array: |
176 |
+ |
$self->{RUNTIME}->{$rt} = [ @$rtvalue ]; |
177 |
+ |
} |
178 |
+ |
} |
179 |
+ |
elsif ($rt) |
180 |
+ |
{ |
181 |
+ |
# Return the value for this runtime var name: |
182 |
+ |
return $self->{RUNTIME}->{$rt}; |
183 |
+ |
} |
184 |
+ |
else |
185 |
+ |
{ |
186 |
+ |
# Return all RT settings: |
187 |
+ |
return $self->{RUNTIME}; |
188 |
+ |
} |
189 |
+ |
} |
190 |
+ |
|
191 |
+ |
sub getfeatures() |
192 |
+ |
{ |
193 |
+ |
my $self=shift; |
194 |
+ |
my ($feature)=@_; |
195 |
+ |
my @feature_vars=$self->list_variables(); |
196 |
+ |
my @features; |
197 |
+ |
push (@features, @feature_vars, qw(LIB LIBDIR INCLUDE MAKEFILE USE)); |
198 |
+ |
|
199 |
+ |
# Make sure feature name is uppercase: |
200 |
+ |
$feature =~ tr/a-z/A-Z/; |
201 |
+ |
if ($feature) # A feature name was given |
202 |
+ |
{ |
203 |
+ |
# Check to see if this feature is valid and is defined for this tool: |
204 |
+ |
if (grep($feature eq $_, @features) && exists($self->{$feature})) |
205 |
+ |
{ |
206 |
+ |
(ref($self->{$feature}) eq 'ARRAY') ? print join(" ",@{$self->{$feature}}) |
207 |
+ |
: print join(" ",$self->{$feature}); |
208 |
+ |
print "\n"; |
209 |
+ |
} |
210 |
+ |
else |
211 |
+ |
{ |
212 |
+ |
# This feature isn't a valid feature or is valid but doens't |
213 |
+ |
# have a value for this tool: |
214 |
+ |
print "SCRAM: No type of variable called \"",$feature,"\" ","defined for this tool.\n"; |
215 |
+ |
} |
216 |
+ |
} |
217 |
+ |
else |
218 |
+ |
{ |
219 |
+ |
# No feature name so dump list of valid features for current tool: |
220 |
+ |
map |
221 |
+ |
{ |
222 |
+ |
print $_,"\n", if (exists ($self->{$_})); |
223 |
+ |
} @features; |
224 |
+ |
} |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
sub summarize_features() |
228 |
+ |
{ |
229 |
+ |
my $self=shift; |
230 |
+ |
my @variables = $self->list_variables(); |
231 |
+ |
|
232 |
+ |
# Show whether this tool is a SCRAM project or not: |
233 |
+ |
print "SCRAM_PROJECT="; |
234 |
+ |
($self->scram_project() == 1) ? print "yes" : print "no"; |
235 |
+ |
print "\n"; |
236 |
+ |
|
237 |
+ |
# Print out any variables: |
238 |
+ |
foreach my $var (@variables) |
239 |
+ |
{ |
240 |
+ |
print $var,"=",$self->{$var},"\n"; |
241 |
+ |
} |
242 |
+ |
|
243 |
+ |
# Makefile and flags first: |
244 |
+ |
if (exists($self->{'MAKEFILE'}) && $#{$self->{'MAKEFILE'}} != -1) |
245 |
+ |
{ |
246 |
+ |
print join(" ",@{$self->{'MAKEFILE'}}),"\n\n"; |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
if (exists($self->{'FLAGS'}) && (my ($nkeys) = scalar(keys %{$self->{'FLAGS'}}) > 0 )) |
250 |
+ |
{ |
251 |
+ |
my $flags=$self->allflags(); |
252 |
+ |
|
253 |
+ |
while (my ($f,$fv) = each %{$flags}) |
254 |
+ |
{ |
255 |
+ |
print $f,"+=",join(" ",@{$fv}),"\n"; |
256 |
+ |
} |
257 |
+ |
} |
258 |
+ |
|
259 |
+ |
foreach my $feature (qw( LIB LIBDIR INCLUDE USE )) |
260 |
+ |
{ |
261 |
+ |
if (exists($self->{$feature}) && $#{$self->{$feature}} != -1) |
262 |
+ |
{ |
263 |
+ |
print $feature,"=",join(" ",@{$self->{$feature}}),"\n"; |
264 |
+ |
} |
265 |
+ |
} |
266 |
+ |
|
267 |
+ |
# Finally, look for runtime vars: |
268 |
+ |
if (exists($self->{'RUNTIME'}) && (my ($nkeys) = scalar(keys %{$self->{'RUNTIME'}}) > 0 )) |
269 |
+ |
{ |
270 |
+ |
while (my ($rt,$val) = each %{$self->{$feature}}) |
271 |
+ |
{ |
272 |
+ |
if ($rt =~ /:/) |
273 |
+ |
{ |
274 |
+ |
my ($type,$name) = split(":",$rt); |
275 |
+ |
print $name,"=",join(":",@$val),"\n"; |
276 |
+ |
} |
277 |
+ |
else |
278 |
+ |
{ |
279 |
+ |
print $rt,"=",join(":",@$val),"\n"; |
280 |
+ |
} |
281 |
+ |
} |
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
print "\n"; |
285 |
+ |
} |
286 |
+ |
|
287 |
+ |
|
288 |
+ |
sub addreleasetoself() |
289 |
+ |
{ |
290 |
+ |
my $self=shift; |
291 |
+ |
# Go through the settings obtained so far (only from SELF) and, for |
292 |
+ |
# every LIBDIR/INCLUDE/RUNTIME path, add another value with |
293 |
+ |
# LOCALTOP==RELEASETOP: |
294 |
+ |
my $relldir = []; |
295 |
+ |
my $relinc = []; |
296 |
+ |
my @locallibdirs = $self->libdir(); |
297 |
+ |
my @localincdirs = $self->include(); |
298 |
+ |
|
299 |
+ |
foreach my $libdir (@locallibdirs) |
300 |
+ |
{ |
301 |
+ |
# Convert LOCAL to RELEASE top: |
302 |
+ |
$libdir =~ s/$ENV{LOCALTOP}/$ENV{RELEASETOP}/g; |
303 |
+ |
push(@$relldir, $libdir); |
304 |
+ |
} |
305 |
+ |
|
306 |
+ |
# Add the new libdirs to our object: |
307 |
+ |
$self->libdir($relldir); |
308 |
+ |
|
309 |
+ |
foreach my $incdir (@localincdirs) |
310 |
+ |
{ |
311 |
+ |
# Convert LOCAL to RELEASE top: |
312 |
+ |
$incdir =~ s/$ENV{LOCALTOP}/$ENV{RELEASETOP}/g; |
313 |
+ |
push(@$relinc, $incdir); |
314 |
+ |
} |
315 |
+ |
|
316 |
+ |
# Add the new libdirs to our object: |
317 |
+ |
$self->include($relinc); |
318 |
+ |
|
319 |
+ |
# Handle runtime settings: |
320 |
+ |
my $runtime=$self->runtime(); |
321 |
+ |
|
322 |
+ |
while (my ($rt,$val) = each %{$runtime}) |
323 |
+ |
{ |
324 |
+ |
# Only handle anything that's a PATH: |
325 |
+ |
if ($rt =~ /:/) |
326 |
+ |
{ |
327 |
+ |
my ($type,$name) = split(":",$rt); |
328 |
+ |
|
329 |
+ |
if ($type eq 'PATH') |
330 |
+ |
{ |
331 |
+ |
my @PATHS=@$val; |
332 |
+ |
my $RELPATHS=[]; |
333 |
+ |
|
334 |
+ |
# Process the values for this path: |
335 |
+ |
foreach my $rtpath (@PATHS) |
336 |
+ |
{ |
337 |
+ |
$rtpath =~ s/$ENV{LOCALTOP}/$ENV{RELEASETOP}/g; |
338 |
+ |
push(@$RELPATHS,$rtpath); |
339 |
+ |
} |
340 |
+ |
|
341 |
+ |
# Add the new settings: |
342 |
+ |
$self->runtime($rt,$RELPATHS); |
343 |
+ |
} |
344 |
+ |
} |
345 |
+ |
} |
346 |
+ |
|
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
1; |