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 embedded 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 $linker_L .= $flags . " ";
298 if ($flags =~ /^\-Y/) {
299 next if ($hostos eq 'SunOS');
300 $linker_L .= "-Wl,". $flags . " ";
303 if ($flags =~ /^\--exclude-libs/) {
304 $linker_L .= "-Wl,". $flags . " ";
309 if ($flags =~ /^\-rpath\@/) {
311 $linker_L .= "-Wl,". $flags . " " ;
314 if ($flags =~ /^\-rpath-link\@/) {
316 $linker_L .= "-Wl,". $flags . " " ;
321 && ($flags !~ /gfortranbegin/)
322 && ($flags !~ /frtbegin/)
323 && ($flags !~ /pathfstart/)
324 && ($flags !~ /crt[0-9]/)
326 && ($flags !~ /user32/)
327 && ($flags !~ /kernel32/)
328 && ($flags !~ /advapi32/)
329 && ($flags !~ /shell32/)
330 && ($flags !~ /^\-l$/)
332 $linker_l .= $flags . " ";
335 $linker_a .= $flags . " " if $flags =~ /\.a$/;
340 if ($vendor eq "INTEL"){
341 $linker_a .= "-lgfortran"
344 if ($vendor eq "FLANG"){
345 $linker_a .= "-lflang"
348 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
349 open(CONFFILE, ">> $config" ) || die "Can't append $config";
351 print MAKEFILE "F_COMPILER=$vendor\n";
352 print MAKEFILE "FC=$compiler\n";
353 print MAKEFILE "BU=$bu\n" if $bu ne "";
354 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
356 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
357 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
358 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
360 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
362 if (($linker_l ne "") || ($linker_a ne "")) {
363 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";