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`;
67 if ($data =~ /zhoge_/) {
71 if ($data =~ /Fujitsu/) {
76 } elsif ($data =~ /GNU/ || $data =~ /GCC/ ) {
78 $data =~ /(\d+)\.(\d+).(\d+)/;
86 if ($compiler =~ /flang/) {
89 } elsif ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
100 if ($data =~ /g95/) {
105 if ($data =~ /Intel/) {
107 $openmp = "-fopenmp";
110 if ($data =~ /Sun Fortran/) {
112 $openmp = "-xopenmp=parallel";
115 if ($data =~ /PathScale/) {
120 if ($data =~ /Open64/) {
125 if ($data =~ /PGF/ || $data =~ /NVF/) {
130 if ($data =~ /IBM XL/) {
135 # for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
136 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
137 if ($data =~ / zho_ge__/) {
140 if ($vendor =~ /G95/) {
141 if ($ENV{NO_LAPACKE} != 1) {
149 if ($compiler =~ /g77/) {
155 if ($compiler =~ /g95/) {
161 if ($compiler =~ /gfortran/) {
164 $openmp = "-fopenmp";
167 if ($compiler =~ /ifort/) {
170 $openmp = "-fopenmp";
173 if ($compiler =~ /pathf/) {
179 if ($compiler =~ /pgf/ || $compiler =~ /nvf/) {
185 if ($compiler =~ /ftn/) {
191 if ($compiler =~ /frt/) {
197 if ($compiler =~ /sunf77|sunf90|sunf95/) {
200 $openmp = "-xopenmp=parallel";
203 if ($compiler =~ /ppuf/) {
208 if ($compiler =~ /xlf/) {
213 if ($compiler =~ /open64/) {
218 if ($compiler =~ /flang/) {
221 $openmp = "-fopenmp";
226 $compiler = "gfortran";
235 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
239 $binary = $ENV{"BINARY"};
241 $openmp = "" if $ENV{USE_OPENMP} != 1;
244 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
246 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
250 $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
254 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
255 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
256 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
258 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
261 $binary = "" if ($?);
265 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
267 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
271 $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
275 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
277 $binary = "" if ($?);
281 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
291 $link =~ s/\-Y\sP\,/\-Y/g;
293 $link =~ s/\-R\s*/\-rpath\@/g;
295 $link =~ s/\-rpath\s+/\-rpath\@/g;
297 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
299 @flags = split(/[\s\,\n]/, $link);
300 # remove leading and trailing quotes from each flag.
301 @flags = map {s/^['"]|['"]$//g; $_} @flags;
303 foreach $flags (@flags) {
306 && ($flags !~ /^-LIST:/)
307 && ($flags !~ /^-LANG:/)
309 $linker_L .= $flags . " ";
312 if ($flags =~ /^\-Y/) {
313 next if ($hostos eq 'SunOS');
314 $linker_L .= "-Wl,". $flags . " ";
317 if ($flags =~ /^\--exclude-libs/) {
318 $linker_L .= "-Wl,". $flags . " ";
323 if ($flags =~ /^\-rpath\@/) {
325 $linker_L .= "-Wl,". $flags . " " ;
328 if ($flags =~ /^\-rpath-link\@/) {
330 $linker_L .= "-Wl,". $flags . " " ;
332 if ($flags =~ /-lgomp/ && $CC =~ /clang/) {
338 && ($flags !~ /gfortranbegin/)
339 && ($flags !~ /frtbegin/)
340 && ($flags !~ /pathfstart/)
341 && ($flags !~ /crt[0-9]/)
343 && ($flags !~ /user32/)
344 && ($flags !~ /kernel32/)
345 && ($flags !~ /advapi32/)
346 && ($flags !~ /shell32/)
347 && ($flags !~ /omp/ || ($vendor !~ /PGI/ && $vendor !~ /FUJITSU/ && $flags =~ /omp/))
348 && ($flags !~ /[0-9]+/ || ($vendor == FUJITSU && $flags =~ /^-lfj90/))
349 && ($flags !~ /^\-l$/)
351 $linker_l .= $flags . " ";
354 $linker_a .= $flags . " " if $flags =~ /\.a$/;
359 if ($vendor eq "INTEL"){
360 $linker_a .= "-lgfortran"
363 if ($vendor eq "FLANG"){
364 $linker_a .= "-lflang"
367 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
368 open(CONFFILE, ">> $config" ) || die "Can't append $config";
370 print MAKEFILE "F_COMPILER=$vendor\n";
371 print MAKEFILE "FC=$compiler\n";
372 print MAKEFILE "BU=$bu\n" if $bu ne "";
373 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
375 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
376 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
377 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
379 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
381 if (($linker_l ne "") || ($linker_a ne "")) {
382 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";