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",
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 =~ /pgf/ || $compiler =~ /nvf/) {
104 if ($data =~ /g95/) {
109 if ($data =~ /Intel/) {
111 $openmp = "-fopenmp";
114 if ($data =~ /Sun Fortran/) {
116 $openmp = "-xopenmp=parallel";
119 if ($data =~ /PathScale/) {
124 if ($data =~ /Open64/) {
129 if ($data =~ /PGF/ || $data =~ /NVF/) {
134 if ($data =~ /IBM XL/) {
139 if ($data =~ /NAG/) {
144 # for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
145 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
147 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.c && rm -f ftest3.c`;
149 if ($data =~ / zho_ge__/) {
152 if ($vendor =~ /G95/) {
153 if ($ENV{NO_LAPACKE} != 1) {
161 if ($compiler =~ /g77/) {
167 if ($compiler =~ /g95/) {
173 if ($compiler =~ /gfortran/) {
176 $openmp = "-fopenmp";
179 if ($compiler =~ /ifort/) {
182 $openmp = "-fopenmp";
185 if ($compiler =~ /pathf/) {
191 if ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
197 if ($compiler =~ /ftn/) {
203 if ($compiler =~ /frt/) {
209 if ($compiler =~ /sunf77|sunf90|sunf95/) {
212 $openmp = "-xopenmp=parallel";
215 if ($compiler =~ /ppuf/) {
220 if ($compiler =~ /xlf/) {
225 if ($compiler =~ /open64/) {
230 if ($compiler =~ /flang/) {
233 $openmp = "-fopenmp";
236 if ($compiler =~ /nagfor/) {
244 $compiler = "gfortran";
253 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
257 $binary = $ENV{"BINARY"};
259 $openmp = "" if $ENV{USE_OPENMP} != 1;
262 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
264 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
268 $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
272 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
273 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
274 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
276 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
279 $binary = "" if ($?);
283 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
285 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
289 $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
293 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
297 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
299 $binary = "" if ($?);
302 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
306 if ( $vendor eq "NAG") {
307 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
315 $link =~ s/\-Y\sP\,/\-Y/g;
317 $link =~ s/\-R\s*/\-rpath\%/g;
319 $link =~ s/\-rpath\s+/\-rpath\%/g;
321 $link =~ s/\-rpath-link\s+/\-rpath-link\%/g;
323 @flags = split(/[\s\,\n]/, $link);
324 # remove leading and trailing quotes from each flag.
325 @flags = map {s/^['"]|['"]$//g; $_} @flags;
327 foreach $flags (@flags) {
330 && ($flags !~ /^-LIST:/)
331 && ($flags !~ /^-LANG:/)
333 $linker_L .= $flags . " ";
336 if ($flags =~ /^\-Y/) {
337 next if ($hostos eq 'SunOS');
338 $linker_L .= "-Wl,". $flags . " ";
341 if ($flags =~ /^\--exclude-libs/) {
342 $linker_L .= "-Wl,". $flags . " ";
347 if ($flags =~ /^\-rpath\%/) {
349 $linker_L .= "-Wl,". $flags . " " ;
352 if ($flags =~ /^\-rpath-link\%/) {
354 $linker_L .= "-Wl,". $flags . " " ;
356 if ($flags =~ /-lgomp/ && $ENV{"CC"} =~ /clang/) {
362 && ($flags !~ /ibrary/)
363 && ($flags !~ /gfortranbegin/)
364 && ($flags !~ /flangmain/)
365 && ($flags !~ /frtbegin/)
366 && ($flags !~ /pathfstart/)
367 && ($flags !~ /crt[0-9]/)
369 && ($flags !~ /user32/)
370 && ($flags !~ /kernel32/)
371 && ($flags !~ /advapi32/)
372 && ($flags !~ /shell32/)
373 && ($flags !~ /omp/ || ($vendor !~ /PGI/ && $vendor !~ /FUJITSU/ && $flags =~ /omp/))
374 && ($flags !~ /[0-9]+/ || ($vendor == FUJITSU && $flags =~ /^-lfj90/))
375 && ($flags !~ /^\-l$/)
377 $linker_l .= $flags . " ";
380 if ( $flags =~ /quickfit.o/ && $vendor == NAG) {
381 $linker_l .= $flags . " ";
383 if ( $flags =~ /safefit.o/ && $vendor == NAG) {
384 $linker_l .= $flags . " ";
386 if ( $flags =~ /thsafe.o/ && $vendor == NAG) {
387 $linker_l .= $flags . " ";
390 $linker_a .= $flags . " " if $flags =~ /\.a$/;
395 if ($vendor eq "FLANG"){
396 $linker_a .= "-lflang"
399 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
400 open(CONFFILE, ">> $config" ) || die "Can't append $config";
402 print MAKEFILE "F_COMPILER=$vendor\n";
403 print MAKEFILE "FC=$compiler\n";
404 print MAKEFILE "BU=$bu\n" if $bu ne "";
405 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
407 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
408 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
409 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
411 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
413 if (($linker_l ne "") || ($linker_a ne "")) {
414 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";