1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# These are mutually exclusive |
4 |
# -e - an EXE with a main (CEXE, FEXE, or SERVEREXE) |
5 |
# -m - a C module (MODEXE, MODEXE_SOCK, MODEXE_USEF, MODEXE_USEF_SOCK) |
6 |
# -M - a Fortran module (FMODEXE_SOCK) |
7 |
|
8 |
# -c - links with C compiler (CEXE, SERVEREXE, MODEXE, MODEXE_SOCK) |
9 |
# -f - links with Fortran compiler (FEXE, FMODEXE_SOCK, MODEXE_USEF, MODEXE_USEF_SOCK) |
10 |
|
11 |
# -s - socket connect (which also means client version of the DRMS library) |
12 |
# (CEXE, FEXE, MODEXE_SOCK, FMODEXE_SOCK, MODEXE_USEF_SOCK) |
13 |
# -d - direct connect (which also means server version of the DRMS library) (SERVEREXE, MODEXE, MODEXE_USEF) |
14 |
|
15 |
# CEXE ==> -ecs |
16 |
# FEXE ==> -efs |
17 |
# SERVEREXE ==> -ecd |
18 |
# MODEXE ==> -mcd |
19 |
# MODEXE_SOCK ==> -mcs |
20 |
# FMODEXE_SOCK ==> -Mfs |
21 |
# MODEXE_USEF ==> -mfd |
22 |
# MODEXE_USEF_SOCK ==> -msf |
23 |
|
24 |
use Switch; |
25 |
|
26 |
# Default locations for third-party libraries are specified with a configuration file. The file can |
27 |
# be edited to customize the locations |
28 |
use constant kJCCCONF ==> "jcc.conf"; |
29 |
|
30 |
use constant kCEXE ==> 1; |
31 |
use constant kFEXE ==> 2; |
32 |
use constant kSERVEXE ==> 3; |
33 |
use constant kCMOD ==> 4; |
34 |
use constant kCMOD_SOCK ==> 5; |
35 |
use constant kFMOD_SOCK ==> 6; |
36 |
use constant kCMOD_USEF ==> 7; |
37 |
use constant kCMOD_USEF_SOCK ==> 8; |
38 |
|
39 |
use constant kCompType_icc ==> 0; |
40 |
use constant kCompType_gcc ==> 1; |
41 |
use constant kCompType_none ==> 2; |
42 |
use constant kFCompType_ifort ==> 0; |
43 |
use constant kFCompType_gfort ==> 1; |
44 |
use constant kFCompType_none ==> 2; |
45 |
|
46 |
use constant kDRMSBinRoot ==> "/home/jsoc/cvs/JSOC/"; |
47 |
use constant kDRMSBinRoot_x86_64 ==> "/home/jsoc/cvs/JSOC/_linux_x86_64"; |
48 |
use constant kDRMSBinRoot_ia32 ==> "/home/jsoc/cvs/JSOC/_linux_ia32"; |
49 |
|
50 |
use constant kLinux_X86_64 ==> 0; |
51 |
use constant kLinux_IA32 ==> 1; |
52 |
|
53 |
use constant kICCMAJOR => 9; |
54 |
use constant kICCMINOR => 0; |
55 |
use constant kIFORTMAJOR => 9; |
56 |
use constant kIFORTMINOR => 0; |
57 |
use constant kGCCMAJOR => 3; |
58 |
use constant kGCCMINOR => 0; |
59 |
use constant kGFORTMAJOR => 4; |
60 |
use constant kGFORTMINOR => 2; |
61 |
|
62 |
use constant kCFAll_icc ==> ""; |
63 |
use constant kLFAll_icc ==> ""; |
64 |
|
65 |
my($arg); |
66 |
my($pos); |
67 |
my($flagstr); |
68 |
my($aflag); |
69 |
my(@flags); |
70 |
my(@sortedflags); |
71 |
my($progtype); |
72 |
my($src); |
73 |
my($cf); |
74 |
my($lf); |
75 |
|
76 |
my($overrideDbg); |
77 |
my($overrideWrn); |
78 |
my($overrideWrnICC); |
79 |
my($overrideCComp); |
80 |
my($overrideFComp); |
81 |
|
82 |
my($line); |
83 |
my($cvsmod); |
84 |
|
85 |
my($conf); |
86 |
my(@comps); |
87 |
my($platenv); |
88 |
my($plat); |
89 |
my($useccomp); |
90 |
my($debug); |
91 |
my($warn); |
92 |
my($warnmore); |
93 |
my($comp); |
94 |
my($pgipath); |
95 |
my($pglpath); |
96 |
my($cfitsioipath); |
97 |
my($cfitsiolpath); |
98 |
|
99 |
SetArgs(\$progtype, \$useccomp, \$src, \$cf, \$lf, \$warnmore, \$debug, \$warn); |
100 |
|
101 |
# check arguments as necessary |
102 |
|
103 |
if (defined($src)) |
104 |
{ |
105 |
if ($src !~ /\.c$/ && $src !~ /\.f$/) |
106 |
{ |
107 |
if (-e "$src\.c") |
108 |
{ |
109 |
$src = "$src\.c"; |
110 |
} |
111 |
elsif (-e "$src\.f") |
112 |
{ |
113 |
$src = "$src\.f"; |
114 |
} |
115 |
else |
116 |
{ |
117 |
die "Cannot find source file $src\.c or $src\.f.\nGood bye.\n"; |
118 |
} |
119 |
} |
120 |
else |
121 |
{ |
122 |
# Verify file exists |
123 |
if (!(-e $src)) |
124 |
{ |
125 |
die "Cannot find source file $src.\nGood bye.\n"; |
126 |
} |
127 |
} |
128 |
} |
129 |
else |
130 |
{ |
131 |
die "Missing source file name.\nGood bye.\n"; |
132 |
} |
133 |
|
134 |
# sort flags |
135 |
#@sortedflags = sort({$a cmp $b}, @flags); |
136 |
|
137 |
# find out what platform |
138 |
$platenv = $ENV{'JSOC_MACHINE'}; |
139 |
|
140 |
if (!defined($platenv)) |
141 |
{ |
142 |
die "Must define environment variable JSOC_MACHINE.\nGood bye.\n"; |
143 |
} |
144 |
elsif ($platenv eq "linux_x86_64") |
145 |
{ |
146 |
$plat = kLinux_X86_64; |
147 |
} |
148 |
elsif ($platenv eq "linux_ia32") |
149 |
{ |
150 |
$plat = kLinux_IA32; |
151 |
} |
152 |
else |
153 |
{ |
154 |
die "Invalid value ($platenv) for environment variable JSOC_MACHINE"; |
155 |
} |
156 |
|
157 |
# look for environment variables that override compiler, debugging symbols, etc. |
158 |
$overrideDbg = $ENV{'JSOC_DEBUG'}; |
159 |
$overrideWrn = $ENV{'JSOC_WARN'}; |
160 |
$overrideWrnICC = $ENV{'JSOC_WARNICC'}; |
161 |
$overrideComp = $ENV{'JSOC_COMPILER'}; |
162 |
$overrideFComp = $ENV{'JSOC_FCOMPILER'}; |
163 |
|
164 |
# autoconfigure compilers |
165 |
@comps = ChooseComps(); |
166 |
|
167 |
if (defined($overrideComp)) |
168 |
{ |
169 |
if ($overrideComp =~ /icc/ && comps[0] == 1) |
170 |
{ |
171 |
$comp = "icc"; |
172 |
} |
173 |
elsif ($overrideComp =~ /gcc/ && comps[1] == 1) |
174 |
{ |
175 |
$comp = "gcc"; |
176 |
} |
177 |
elsif ($useccomp) |
178 |
{ |
179 |
die "Compiler $overrideComp not available.\nGood bye.\n"; |
180 |
} |
181 |
} |
182 |
|
183 |
if (defined($overrideFComp)) |
184 |
{ |
185 |
if ($overrideFComp =~ /ifort/ && comps[2] == 1) |
186 |
{ |
187 |
$comp = "ifort"; |
188 |
} |
189 |
elsif ($overrideFComp =~ /gfort/ && comps[3] == 1) |
190 |
{ |
191 |
$comp = "gfort"; |
192 |
} |
193 |
elsif (!$useccomp) |
194 |
{ |
195 |
die "Compiler $overrideFComp not available.\nGood bye.\n"; |
196 |
} |
197 |
} |
198 |
|
199 |
# set up debugging and warnings |
200 |
if (!defined($debug)) |
201 |
{ |
202 |
if (defined($overrideDbg)) |
203 |
{ |
204 |
$debug = $overrideDbg; |
205 |
} |
206 |
else |
207 |
{ |
208 |
$debug = 0; |
209 |
} |
210 |
} |
211 |
|
212 |
if (!defined($warn)) |
213 |
{ |
214 |
if (defined($overrideDbg)) |
215 |
{ |
216 |
$warn = $overrideDbg; |
217 |
} |
218 |
else |
219 |
{ |
220 |
$warn = 0; |
221 |
} |
222 |
} |
223 |
|
224 |
if (defined($warn) && !defined($warnmore)) |
225 |
{ |
226 |
if (defined($overrideWrnICC)) |
227 |
{ |
228 |
$warnmore = $overrideWrnICC; |
229 |
} |
230 |
else |
231 |
{ |
232 |
$warnmore = ""; |
233 |
} |
234 |
} |
235 |
|
236 |
# set up third-party library paths |
237 |
$conf = kJCCCONF; |
238 |
open(JCCCONF, "<$conf"); |
239 |
|
240 |
while (defined($line = <JCCCONF>)) |
241 |
{ |
242 |
chomp($line); |
243 |
|
244 |
if ($line !~ /^#/ && length($line) > 0) |
245 |
{ |
246 |
if ($line =~ /(.+)\s+(.+)/) |
247 |
{ |
248 |
$key = $1; |
249 |
$value = $2; |
250 |
|
251 |
if ($key =~ /PGIPATH/i) |
252 |
{ |
253 |
$pgipath = $value; |
254 |
} |
255 |
elsif ($key =~ /CFITSIOIPATH/i) |
256 |
{ |
257 |
$cfitioipath = $value; |
258 |
} |
259 |
elsif ($plat == kLinux_IA32 && $key =~ /CFITSIOLPATH32/i) |
260 |
{ |
261 |
$cfitsiolpath = $value; |
262 |
} |
263 |
elsif ($plat == kLinux_X86_64 && $key =~ /CFITSIOLPATH64/i) |
264 |
{ |
265 |
$cfitsiolpath = $value; |
266 |
} |
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
close(JCCCONF); |
272 |
|
273 |
|
274 |
|
275 |
|
276 |
if (!$debug) |
277 |
{ |
278 |
|
279 |
} |
280 |
else |
281 |
{ |
282 |
|
283 |
} |
284 |
|
285 |
switch ($progtype) |
286 |
{ |
287 |
case kCMOD |
288 |
{ |
289 |
|
290 |
} |
291 |
|
292 |
} |
293 |
|
294 |
sub SetArgs |
295 |
{ |
296 |
my($progtype) = $_[0]; |
297 |
my($useccomp) = $_[1]; |
298 |
my($src) = $_[2]; |
299 |
my($cf) = $_[3]; |
300 |
my($lf) = $_[4]; |
301 |
my($warnmore) = $_[5]; |
302 |
my($debug) = $_[6]; |
303 |
my($warn) = $_[7]; |
304 |
|
305 |
$$useccomp = 1; |
306 |
|
307 |
while ($arg = shift(@ARGV)) |
308 |
{ |
309 |
if ($arg =~ /t=(.+)/) |
310 |
{ |
311 |
# module type |
312 |
my($ptype); |
313 |
|
314 |
$ptype = $1; |
315 |
if ($ptype =~ /CEXE/i) |
316 |
{ |
317 |
$$progtype = kCEXE; |
318 |
} |
319 |
elsif ($ptype =~ /FEXE/i) |
320 |
{ |
321 |
$$progtype = kFEXE; |
322 |
$$useccomp = 0; |
323 |
} |
324 |
elsif ($ptype =~ /SERVEXE/i) |
325 |
{ |
326 |
$$progtype = kSERVEXE; |
327 |
} |
328 |
elsif ($ptype =~ /CMOD/i) |
329 |
{ |
330 |
$$progtype = kCMOD; |
331 |
} |
332 |
elsif ($ptype =~ /CMODSOCK/i) |
333 |
{ |
334 |
$$progtype = kCMOD_SOCK; |
335 |
} |
336 |
elsif ($ptype =~ /FMODSOCK/i) |
337 |
{ |
338 |
$$progtype = kFMOD_SOCK; |
339 |
} |
340 |
elsif ($ptype =~ /CMODUSEF/i) |
341 |
{ |
342 |
$$progtype = kCMOD_USEF; |
343 |
} |
344 |
elsif ($ptype =~ /CMODUSEFSOCK/i) |
345 |
{ |
346 |
$$progtype = kCMOD_USEF_SOCK; |
347 |
} |
348 |
else |
349 |
{ |
350 |
print STDERR "Unsupported binary type.\n"; |
351 |
die; |
352 |
} |
353 |
} |
354 |
elsif ($arg =~ /src=(.+)/) |
355 |
{ |
356 |
$$src = $1; |
357 |
} |
358 |
elsif ($arg !~ /=/) |
359 |
{ |
360 |
$$src = $arg; |
361 |
} |
362 |
elsif ($arg =~ /cf=(.+)/) |
363 |
{ |
364 |
# compile flags |
365 |
$$cf = $1; |
366 |
} |
367 |
elsif ($arg =~ /lf=(.+)/) |
368 |
{ |
369 |
# link flags |
370 |
$$lf = $1; |
371 |
} |
372 |
elsif ($arg =~ /wm=(.+)/) |
373 |
{ |
374 |
$$warnmore = $1; |
375 |
} |
376 |
elsif ($arg eq "-d") |
377 |
{ |
378 |
$$debug = 1; |
379 |
} |
380 |
elsif ($arg eq "-w") |
381 |
{ |
382 |
$$warn = 1; |
383 |
} |
384 |
} |
385 |
} |
386 |
|
387 |
sub IsVersion |
388 |
{ |
389 |
my($maj1) = $_[0]; |
390 |
my($min1) = $_[1]; |
391 |
my($maj2) = $_[2]; |
392 |
my($min2) = $_[3]; |
393 |
|
394 |
my($res) = 0; |
395 |
|
396 |
if ($maj1 > $maj2 || ($maj1 == $maj2 && $min1 >= $min2)) |
397 |
{ |
398 |
$res = 1; |
399 |
} |
400 |
|
401 |
return $res; |
402 |
} |
403 |
|
404 |
sub ChooseComps |
405 |
{ |
406 |
my(@ret); |
407 |
my($ans); |
408 |
my($major); |
409 |
my($minor); |
410 |
|
411 |
my($hasicc); |
412 |
my($hasifort); |
413 |
my($hasgcc); |
414 |
my($hasgfort); |
415 |
|
416 |
# Try icc |
417 |
$ans = `icc -V 2>&1`; |
418 |
|
419 |
if (defined($ans) && $ans =~ /Version\s+(\d+)\.(\d+)/) |
420 |
{ |
421 |
$major = $1; |
422 |
$minor = $2; |
423 |
|
424 |
if (IsVersion($major, $minor, kICCMAJOR, kICCMINOR)) |
425 |
{ |
426 |
$hasicc = 1; |
427 |
} |
428 |
} |
429 |
|
430 |
# Try gcc |
431 |
if (!$hasicc) |
432 |
{ |
433 |
$ans = `gcc -v 2>&1`; |
434 |
if (defined($ans) && $ans =~ /gcc\s+version\s+(\d+)\.(\d+)/) |
435 |
{ |
436 |
$major = $1; |
437 |
$minor = $2; |
438 |
|
439 |
if (IsVersion($major, $minor, kGCCMAJOR, kGCCMINOR)) |
440 |
{ |
441 |
$hasgcc = 1; |
442 |
} |
443 |
} |
444 |
} |
445 |
|
446 |
# Try ifort |
447 |
$ans = `ifort -V 2>&1`; |
448 |
if (defined($ans) && $ans =~ /Version\s+(\d+)\.(\d+)/) |
449 |
{ |
450 |
$major = $1; |
451 |
$minor = $2; |
452 |
|
453 |
if (IsVersion($major, $minor, kIFORTMAJOR, kIFORTMINOR)) |
454 |
{ |
455 |
$hasifort = 1; |
456 |
} |
457 |
} |
458 |
|
459 |
# Try gfortran |
460 |
if (!$hasifort) |
461 |
{ |
462 |
$ans = `gfortran -v 2>&1`; |
463 |
if (defined($ans) && $ans =~ /gcc\s+version\s+(\d+)\.(\d+)/) |
464 |
{ |
465 |
$major = $1; |
466 |
$minor = $2; |
467 |
|
468 |
if (IsVersion($major, $minor, kGFORTMAJOR, kGFORTMINOR)) |
469 |
{ |
470 |
$hasgfort = 1; |
471 |
} |
472 |
} |
473 |
} |
474 |
|
475 |
$ret[0] = $hasicc; |
476 |
$ret[1] = $hasgcc; |
477 |
$ret[2] = $hasifort; |
478 |
$ret[3] = $hasgfort; |
479 |
|
480 |
return @ret; |
481 |
} |