3 $hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
7 # 1.1 Automatically detect, then check compiler
8 # 1.2 If no fortran compiler is detected, gfortran is default with NOFORTRAN definition
10 # 2.1 If path is correct, check compiler
11 # 2.2 If path is not correct, but still valid compiler name, force setting
12 # 2.2.2 Path is not correct, invalid compiler name, then gfortran is default with NOFORTRAN definition
15 $makefile = shift(@ARGV);
16 $config = shift(@ARGV);
20 $compiler = join(" ", @ARGV);
21 $compiler_bin = shift(@ARGV);
23 # f77 is too ambiguous
24 $compiler = "" if $compiler eq "f77";
26 @path = split(/:/, $ENV{"PATH"});
28 if ($compiler eq "") {
30 @lists = ("gfortran", "g95", "frt", "fort", "openf90", "openf95",
31 "sunf77", "sunf90", "sunf95",
32 "xlf95", "xlf90", "xlf",
33 "ppuf77", "ppuf95", "ppuf90", "ppuxlf",
35 "pgf95", "pgf90", "pgf77", "pgfortran", "nvfortran",
37 "ifort", "nagfor", "ifx");
40 foreach $lists (@lists) {
41 foreach $path (@path) {
42 if (-x $path . "/" . $lists) {
44 $compiler_bin = $lists;
52 if ($compiler eq "") {
55 $compiler = "gfortran";
61 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
66 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
68 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.c && rm -f ftest.c`;
70 if ($data =~ /zhoge_/) {
74 if ($data =~ /Fujitsu/) {
79 } elsif ($data =~ /GNU/ || $data =~ /GCC/ ) {
81 $data =~ s/\(+.*?\)+//g;
82 $data =~ /(\d+)\.(\d+).(\d+)/;
90 if ($compiler =~ /flang/) {
93 } elsif ($compiler =~ /ifx/) {
96 } elsif ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
107 if ($data =~ /g95/) {
112 if ($data =~ /Intel/) {
114 $openmp = "-fopenmp";
117 if ($data =~ /Sun Fortran/) {
119 $openmp = "-xopenmp=parallel";
122 if ($data =~ /PathScale/) {
127 if ($data =~ /Open64/) {
132 if ($data =~ /PGF/ || $data =~ /NVF/) {
137 if ($data =~ /IBM XL/) {
142 if ($data =~ /NAG/) {
147 # for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
148 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
150 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.c && rm -f ftest3.c`;
152 if ($data =~ / zho_ge__/) {
155 if ($vendor =~ /G95/) {
156 if ($ENV{NO_LAPACKE} != 1) {
164 if ($compiler =~ /g77/) {
170 if ($compiler =~ /g95/) {
176 if ($compiler =~ /gfortran/) {
179 $openmp = "-fopenmp";
182 if ($compiler =~ /ifort/ || $compiler =~ /ifx/) {
185 $openmp = "-fopenmp";
188 if ($compiler =~ /pathf/) {
194 if ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
200 if ($compiler =~ /ftn/) {
206 if ($compiler =~ /frt/) {
212 if ($compiler =~ /sunf77|sunf90|sunf95/) {
215 $openmp = "-xopenmp=parallel";
218 if ($compiler =~ /ppuf/) {
223 if ($compiler =~ /xlf/) {
228 if ($compiler =~ /open64/) {
233 if ($compiler =~ /flang/) {
236 $openmp = "-fopenmp";
239 if ($compiler =~ /nagfor/) {
247 $compiler = "gfortran";
256 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
260 $binary = $ENV{"BINARY"};
262 $openmp = "" if $ENV{USE_OPENMP} != 1;
265 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
267 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
271 $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
275 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
276 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
277 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
279 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
282 $binary = "" if ($?);
286 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
288 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
292 $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
296 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
300 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
302 $binary = "" if ($?);
305 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
309 if ( $vendor eq "NAG") {
310 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
318 $link =~ s/\-Y\sP\,/\-Y/g;
320 $link =~ s/\-R\s*/\-rpath\%/g;
322 $link =~ s/\-rpath\s+/\-rpath\%/g;
324 $link =~ s/\-rpath-link\s+/\-rpath-link\%/g;
326 @flags = split(/[\s\,\n]/, $link);
327 # remove leading and trailing quotes from each flag.
328 @flags = map {s/^['"]|['"]$//g; $_} @flags;
330 foreach $flags (@flags) {
333 && ($flags !~ /^-LIST:/)
334 && ($flags !~ /^-LANG:/)
336 $linker_L .= $flags . " ";
339 if ($flags =~ /^\-Y/) {
340 next if ($hostos eq 'SunOS');
341 $linker_L .= "-Wl,". $flags . " ";
344 if ($flags =~ /^\--exclude-libs/) {
345 $linker_L .= "-Wl,". $flags . " ";
350 if ($flags =~ /^\-rpath\%/) {
352 $linker_L .= "-Wl,". $flags . " " ;
355 if ($flags =~ /^\-rpath-link\%/) {
357 $linker_L .= "-Wl,". $flags . " " ;
359 if ($flags =~ /-lgomp/ && $ENV{"CC"} =~ /clang/) {
365 && ($flags !~ /ibrary/)
366 && ($flags !~ /gfortranbegin/)
367 && ($flags !~ /flangmain/)
368 && ($flags !~ /frtbegin/)
369 && ($flags !~ /pathfstart/)
370 && ($flags !~ /crt[0-9]/)
372 && ($flags !~ /user32/)
373 && ($flags !~ /kernel32/)
374 && ($flags !~ /advapi32/)
375 && ($flags !~ /shell32/)
376 && ($flags !~ /omp/ || ($vendor !~ /PGI/ && $vendor !~ /FUJITSU/ && $flags =~ /omp/))
377 && ($flags !~ /[0-9]+/ || ($vendor == FUJITSU && $flags =~ /^-lfj90/))
378 && ($flags !~ /^\-l$/)
380 $linker_l .= $flags . " ";
383 if ( $flags =~ /quickfit.o/ && $vendor == NAG) {
384 $linker_l .= $flags . " ";
386 if ( $flags =~ /safefit.o/ && $vendor == NAG) {
387 $linker_l .= $flags . " ";
389 if ( $flags =~ /thsafe.o/ && $vendor == NAG) {
390 $linker_l .= $flags . " ";
393 $linker_a .= $flags . " " if $flags =~ /\.a$/;
398 if ($vendor eq "FLANG"){
399 $linker_a .= "-lflang"
402 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
403 open(CONFFILE, ">> $config" ) || die "Can't append $config";
405 print MAKEFILE "F_COMPILER=$vendor\n";
406 print MAKEFILE "FC=$compiler\n";
407 print MAKEFILE "BU=$bu\n" if $bu ne "";
408 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
410 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
411 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
412 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
414 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
416 if (($linker_l ne "") || ($linker_a ne "")) {
417 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";