forked from OpenMathLib/OpenBLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
f_check
377 lines (301 loc) · 7.74 KB
/
f_check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#!/usr/bin/perl
$hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
#
# 1. Not specified
# 1.1 Automatically detect, then check compiler
# 1.2 If no fortran compiler is detected, gfortran is default with NOFORTRAN definition
# 2. Specified
# 2.1 If path is correct, check compiler
# 2.2 If path is not correct, but still valid compiler name, force setting
# 2.2.2 Path is not correct, invalid compiler name, then gfortran is default with NOFORTRAN definition
#
$makefile = shift(@ARGV);
$config = shift(@ARGV);
$nofortran = 0;
$compiler = join(" ", @ARGV);
$compiler_bin = shift(@ARGV);
# f77 is too ambiguous
$compiler = "" if $compiler eq "f77";
@path = split(/:/, $ENV{"PATH"});
if ($compiler eq "") {
@lists = ("gfortran", "g95", "frt", "fort", "openf90", "openf95",
"sunf77", "sunf90", "sunf95",
"xlf95", "xlf90", "xlf",
"ppuf77", "ppuf95", "ppuf90", "ppuxlf",
"pathf90", "pathf95",
"pgf95", "pgf90", "pgf77",
"flang",
"ifort");
OUTER:
foreach $lists (@lists) {
foreach $path (@path) {
if (-x $path . "/" . $lists) {
$compiler = $lists;
$compiler_bin = $lists;
last OUTER;
}
}
}
}
if ($compiler eq "") {
$nofortran = 1;
$compiler = "gfortran";
$vendor = GFORTRAN;
$bu = "_";
} else {
$data = `which $compiler_bin > /dev/null 2> /dev/null`;
$vendor = "";
if (!$?) {
$data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
if ($data =~ /zhoge_/) {
$bu = "_";
}
if ($data =~ /GNU/) {
$data =~ /(\d)\.(\d).(\d)/;
$major = $1;
$minor = $2;
if ($major >= 4) {
$vendor = GFORTRAN;
$openmp = "-fopenmp";
} else {
if ($compiler =~ /flang/) {
$vendor = FLANG;
$openmp = "-fopenmp";
} else {
$vendor = G77;
$openmp = "";
}
}
}
if ($data =~ /g95/) {
$vendor = G95;
$openmp = "";
}
if ($data =~ /Intel/) {
$vendor = INTEL;
$openmp = "-fopenmp";
}
if ($data =~ /Sun Fortran/) {
$vendor = SUN;
$openmp = "-xopenmp=parallel";
}
if ($data =~ /PathScale/) {
$vendor = PATHSCALE;
$openmp = "-openmp";
}
if ($data =~ /Open64/) {
$vendor = OPEN64;
$openmp = "-mp";
}
if ($data =~ /PGF/) {
$vendor = PGI;
$openmp = "-mp";
}
if ($data =~ /IBM XL/) {
$vendor = IBM;
$openmp = "-openmp";
}
# for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
$data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
if ($data =~ / zho_ge__/) {
$need2bu = 1;
}
}
if ($vendor eq "") {
if ($compiler =~ /g77/) {
$vendor = G77;
$bu = "_";
$openmp = "";
}
if ($compiler =~ /g95/) {
$vendor = G95;
$bu = "_";
$openmp = "";
}
if ($compiler =~ /gfortran/) {
$vendor = GFORTRAN;
$bu = "_";
$openmp = "-fopenmp";
}
if ($compiler =~ /ifort/) {
$vendor = INTEL;
$bu = "_";
$openmp = "-fopenmp";
}
if ($compiler =~ /pathf/) {
$vendor = PATHSCALE;
$bu = "_";
$openmp = "-mp";
}
if ($compiler =~ /pgf/) {
$vendor = PGI;
$bu = "_";
$openmp = "-mp";
}
if ($compiler =~ /ftn/) {
$vendor = PGI;
$bu = "_";
$openmp = "-openmp";
}
if ($compiler =~ /frt/) {
$vendor = FUJITSU;
$bu = "_";
$openmp = "-openmp";
}
if ($compiler =~ /sunf77|sunf90|sunf95/) {
$vendor = SUN;
$bu = "_";
$openmp = "-xopenmp=parallel";
}
if ($compiler =~ /ppuf/) {
$vendor = IBM;
$openmp = "-openmp";
}
if ($compiler =~ /xlf/) {
$vendor = IBM;
$openmp = "-openmp";
}
if ($compiler =~ /open64/) {
$vendor = OPEN64;
$openmp = "-mp";
}
if ($compiler =~ /flang/) {
$vendor = FLANG;
$bu = "_";
$openmp = "-fopenmp";
}
if ($vendor eq "") {
$nofortran = 1;
$compiler = "gfortran";
$vendor = GFORTRAN;
$bu = "_";
$openmp = "";
}
}
}
$data = `which $compiler_bin > /dev/null 2> /dev/null`;
if (!$?) {
$binary = $ENV{"BINARY"};
$openmp = "" if $ENV{USE_OPENMP} != 1;
if ($binary == 32) {
$link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
if ($?) {
$link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
# for AIX
if ($?) {
$link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
#For gfortran MIPS
if ($?) {
$mips_data = `$compiler_bin -E -dM - < /dev/null`;
if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
$link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
} else {
$link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
}
$binary = "" if ($?);
}
if ($binary == 64) {
$link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
if ($?) {
$link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
# for AIX
if ($?) {
$link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
#For gfortran MIPS
if ($?) {
$link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
$binary = "" if ($?);
}
if ($binary eq "") {
$link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
}
}
$linker_L = "";
$linker_l = "";
$linker_a = "";
if ($link ne "") {
$link =~ s/\-Y\sP\,/\-Y/g;
$link =~ s/\-rpath\s+/\-rpath\@/g;
$link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
@flags = split(/[\s\,\n]/, $link);
# remove leading and trailing quotes from each flag.
@flags = map {s/^['"]|['"]$//g; $_} @flags;
foreach $flags (@flags) {
if (
($flags =~ /^\-L/)
&& ($flags !~ /^-LIST:/)
&& ($flags !~ /^-LANG:/)
) {
if ($vendor eq "PGI") {
$flags =~ s/lib$/libso/;
}
$linker_L .= $flags . " ";
}
if ($flags =~ /^\-Y/) {
next if ($hostos eq 'SunOS');
$linker_L .= "-Wl,". $flags . " ";
}
if ($flags =~ /^\--exclude-libs/) {
$linker_L .= "-Wl,". $flags . " ";
$flags="";
}
if ($flags =~ /^\-rpath\@/) {
$flags =~ s/\@/\,/g;
if ($vendor eq "PGI") {
$flags =~ s/lib$/libso/;
}
$linker_L .= "-Wl,". $flags . " " ;
}
if ($flags =~ /^\-rpath-link\@/) {
$flags =~ s/\@/\,/g;
if ($vendor eq "PGI") {
$flags =~ s/lib$/libso/;
}
$linker_L .= "-Wl,". $flags . " " ;
}
if (
($flags =~ /^\-l/)
&& ($flags !~ /gfortranbegin/)
&& ($flags !~ /frtbegin/)
&& ($flags !~ /pathfstart/)
&& ($flags !~ /numa/)
&& ($flags !~ /crt[0-9]/)
&& ($flags !~ /gcc/)
&& ($flags !~ /user32/)
&& ($flags !~ /kernel32/)
&& ($flags !~ /advapi32/)
&& ($flags !~ /shell32/)
&& ($flags !~ /^\-l$/)
) {
$linker_l .= $flags . " ";
}
$linker_a .= $flags . " " if $flags =~ /\.a$/;
}
}
if ($vendor eq "INTEL"){
$linker_a .= "-lgfortran"
}
if ($vendor eq "FLANG"){
$linker_a .= "-lflang"
}
open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
open(CONFFILE, ">> $config" ) || die "Can't append $config";
print MAKEFILE "F_COMPILER=$vendor\n";
print MAKEFILE "FC=$compiler\n";
print MAKEFILE "BU=$bu\n" if $bu ne "";
print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
if (($linker_l ne "") || ($linker_a ne "")) {
print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";
}
close(MAKEFILE);
close(CONFFILE);