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", "ftn", "crayftn");
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 =~ /Cray/) {
84 } elsif ($data =~ /GNU/ || $data =~ /GCC/ ) {
86 $data =~ s/\(+.*?\)+//g;
87 $data =~ /(\d+)\.(\d+).(\d+)/;
95 if ($compiler =~ /flang/) {
98 } elsif ($compiler =~ /ifx/) {
100 $openmp = "-fopenmp";
101 } elsif ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
112 if ($data =~ /g95/) {
117 if ($data =~ /Intel/) {
119 $openmp = "-fopenmp";
122 if ($data =~ /Sun Fortran/) {
124 $openmp = "-xopenmp=parallel";
127 if ($data =~ /PathScale/) {
132 if ($data =~ /Open64/) {
137 if ($data =~ /PGF/ || $data =~ /NVF/) {
142 if ($data =~ /IBM XL/) {
147 if ($data =~ /NAG/) {
152 # for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
153 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
155 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.c && rm -f ftest3.c`;
157 if ($data =~ / zho_ge__/) {
160 if ($vendor =~ /G95/) {
161 if ($ENV{NO_LAPACKE} != 1) {
169 if ($compiler =~ /g77/) {
175 if ($compiler =~ /g95/) {
181 if ($compiler =~ /gfortran/) {
184 $openmp = "-fopenmp";
187 if ($compiler =~ /ifort/ || $compiler =~ /ifx/) {
190 $openmp = "-fopenmp";
193 if ($compiler =~ /pathf/) {
199 if ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
205 if ($compiler =~ /ftn/) {
211 if ($compiler =~ /frt/) {
217 if ($compiler =~ /sunf77|sunf90|sunf95/) {
220 $openmp = "-xopenmp=parallel";
223 if ($compiler =~ /ppuf/) {
228 if ($compiler =~ /xlf/) {
233 if ($compiler =~ /open64/) {
238 if ($compiler =~ /flang/) {
241 $openmp = "-fopenmp";
244 if ($compiler =~ /nagfor/) {
252 $compiler = "gfortran";
261 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
265 $binary = $ENV{"BINARY"};
267 $openmp = "" if $ENV{USE_OPENMP} != 1;
270 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
272 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
276 $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
280 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
281 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
282 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
284 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
287 $binary = "" if ($?);
291 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
293 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
297 $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
301 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
305 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
307 $binary = "" if ($?);
310 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
314 if ( $vendor eq "NAG") {
315 $link = `$compiler $openmp -dryrun ftest2.f 2>&1 && rm -f a.out a.exe`;
317 if ( $vendor eq "CRAY") {
318 $link = `$compiler $openmp -hnopattern ftest2.f 2>&1 && rm -f a.out a.exe`;
326 $link =~ s/\-Y\sP\,/\-Y/g;
328 $link =~ s/\-R\s*/\-rpath\%/g;
330 $link =~ s/\-rpath\s+/\-rpath\%/g;
332 $link =~ s/\-rpath-link\s+/\-rpath-link\%/g;
334 @flags = split(/[\s\,\n]/, $link);
335 # remove leading and trailing quotes from each flag.
336 @flags = map {s/^['"]|['"]$//g; $_} @flags;
338 foreach $flags (@flags) {
341 && ($flags !~ /^-LIST:/)
342 && ($flags !~ /^-LANG:/)
344 $linker_L .= $flags . " ";
347 if ($flags =~ /^\-Y/) {
348 next if ($hostos eq 'SunOS');
349 $linker_L .= "-Wl,". $flags . " ";
352 if ($flags =~ /^\--exclude-libs/) {
353 $linker_L .= "-Wl,". $flags . " ";
358 if ($flags =~ /^\-rpath\%/) {
360 $linker_L .= "-Wl,". $flags . " " ;
363 if ($flags =~ /^\-rpath-link\%/) {
365 $linker_L .= "-Wl,". $flags . " " ;
367 if ($flags =~ /-lgomp/ && $ENV{"CC"} =~ /clang/) {
373 && ($flags !~ /ibrary/)
374 && ($flags !~ /gfortranbegin/)
375 && ($flags !~ /flangmain/)
376 && ($flags !~ /frtbegin/)
377 && ($flags !~ /pathfstart/)
378 && ($flags !~ /crt[0-9]/)
380 && ($flags !~ /user32/)
381 && ($flags !~ /kernel32/)
382 && ($flags !~ /advapi32/)
383 && ($flags !~ /shell32/)
384 && ($flags !~ /omp/ || ($vendor !~ /PGI/ && $vendor !~ /FUJITSU/ && $flags =~ /omp/))
385 && ($flags !~ /[0-9]+/ || ($vendor == FUJITSU && $flags =~ /^-lfj90/))
386 && ($flags !~ /^\-l$/)
388 $linker_l .= $flags . " ";
391 if ( $flags =~ /quickfit.o/ && $vendor == NAG) {
392 $linker_l .= $flags . " ";
394 if ( $flags =~ /safefit.o/ && $vendor == NAG) {
395 $linker_l .= $flags . " ";
397 if ( $flags =~ /thsafe.o/ && $vendor == NAG) {
398 $linker_l .= $flags . " ";
401 $linker_a .= $flags . " " if $flags =~ /\.a$/;
406 if ($vendor eq "FLANG"){
407 $linker_a .= "-lflang"
410 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
411 open(CONFFILE, ">> $config" ) || die "Can't append $config";
413 print MAKEFILE "F_COMPILER=$vendor\n";
414 print MAKEFILE "FC=$compiler\n";
415 print MAKEFILE "BU=$bu\n" if $bu ne "";
416 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
418 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
419 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
420 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
422 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
424 if (($linker_l ne "") || ($linker_a ne "")) {
425 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";