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",
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 if ($data =~ /zhoge_/) {
74 $data =~ /(\d)\.(\d).(\d)/;
82 if ($compiler =~ /flang/) {
98 if ($data =~ /Intel/) {
100 $openmp = "-fopenmp";
103 if ($data =~ /Sun Fortran/) {
105 $openmp = "-xopenmp=parallel";
108 if ($data =~ /PathScale/) {
113 if ($data =~ /Open64/) {
118 if ($data =~ /PGF/) {
123 if ($data =~ /IBM XL/) {
128 # for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
129 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
130 if ($data =~ / zho_ge__/) {
137 if ($compiler =~ /g77/) {
143 if ($compiler =~ /g95/) {
149 if ($compiler =~ /gfortran/) {
152 $openmp = "-fopenmp";
155 if ($compiler =~ /ifort/) {
158 $openmp = "-fopenmp";
161 if ($compiler =~ /pathf/) {
167 if ($compiler =~ /pgf/) {
173 if ($compiler =~ /ftn/) {
179 if ($compiler =~ /frt/) {
185 if ($compiler =~ /sunf77|sunf90|sunf95/) {
188 $openmp = "-xopenmp=parallel";
191 if ($compiler =~ /ppuf/) {
196 if ($compiler =~ /xlf/) {
201 if ($compiler =~ /open64/) {
206 if ($compiler =~ /flang/) {
209 $openmp = "-fopenmp";
214 $compiler = "gfortran";
223 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
227 $binary = $ENV{"BINARY"};
229 $openmp = "" if $ENV{USE_OPENMP} != 1;
232 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
234 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
238 $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
242 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
243 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
244 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
246 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
249 $binary = "" if ($?);
253 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
255 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
259 $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
263 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
265 $binary = "" if ($?);
269 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
279 $link =~ s/\-Y\sP\,/\-Y/g;
281 $link =~ s/\-rpath\s+/\-rpath\@/g;
283 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
285 @flags = split(/[\s\,\n]/, $link);
286 # remove leading and trailing quotes from each flag.
287 @flags = map {s/^['"]|['"]$//g; $_} @flags;
289 foreach $flags (@flags) {
292 && ($flags !~ /^-LIST:/)
293 && ($flags !~ /^-LANG:/)
295 if ($vendor eq "PGI") {
296 $flags =~ s/lib$/libso/;
298 $linker_L .= $flags . " ";
301 if ($flags =~ /^\-Y/) {
302 next if ($hostos eq 'SunOS');
303 $linker_L .= "-Wl,". $flags . " ";
306 if ($flags =~ /^\--exclude-libs/) {
307 $linker_L .= "-Wl,". $flags . " ";
312 if ($flags =~ /^\-rpath\@/) {
314 if ($vendor eq "PGI") {
315 $flags =~ s/lib$/libso/;
317 $linker_L .= "-Wl,". $flags . " " ;
320 if ($flags =~ /^\-rpath-link\@/) {
322 if ($vendor eq "PGI") {
323 $flags =~ s/lib$/libso/;
325 $linker_L .= "-Wl,". $flags . " " ;
330 && ($flags !~ /gfortranbegin/)
331 && ($flags !~ /frtbegin/)
332 && ($flags !~ /pathfstart/)
333 && ($flags !~ /numa/)
334 && ($flags !~ /crt[0-9]/)
336 && ($flags !~ /user32/)
337 && ($flags !~ /kernel32/)
338 && ($flags !~ /advapi32/)
339 && ($flags !~ /shell32/)
340 && ($flags !~ /^\-l$/)
342 $linker_l .= $flags . " ";
345 $linker_a .= $flags . " " if $flags =~ /\.a$/;
350 if ($vendor eq "INTEL"){
351 $linker_a .= "-lgfortran"
354 if ($vendor eq "FLANG"){
355 $linker_a .= "-lflang"
358 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
359 open(CONFFILE, ">> $config" ) || die "Can't append $config";
361 print MAKEFILE "F_COMPILER=$vendor\n";
362 print MAKEFILE "FC=$compiler\n";
363 print MAKEFILE "BU=$bu\n" if $bu ne "";
364 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
366 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
367 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
368 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
370 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
372 if (($linker_l ne "") || ($linker_a ne "")) {
373 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";