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/) {
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/) {
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 $mips_data = `$compiler_bin -E -dM - < /dev/null`;
239 if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
240 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
242 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
245 $binary = "" if ($?);
249 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
251 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
255 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
257 $binary = "" if ($?);
261 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
271 $link =~ s/\-Y\sP\,/\-Y/g;
273 $link =~ s/\-rpath\s+/\-rpath\@/g;
275 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
277 @flags = split(/[\s\,\n]/, $link);
278 # remove leading and trailing quotes from each flag.
279 @flags = map {s/^['"]|['"]$//g; $_} @flags;
281 foreach $flags (@flags) {
284 && ($flags !~ /^-LIST:/)
285 && ($flags !~ /^-LANG:/)
287 if ($vendor eq "PGI") {
288 $flags =~ s/lib$/libso/;
290 $linker_L .= $flags . " ";
293 if ($flags =~ /^\-Y/) {
294 next if ($hostos eq 'SunOS');
295 $linker_L .= "-Wl,". $flags . " ";
298 if ($flags =~ /^\--exclude-libs/) {
299 $linker_L .= "-Wl,". $flags . " ";
304 if ($flags =~ /^\-rpath\@/) {
306 if ($vendor eq "PGI") {
307 $flags =~ s/lib$/libso/;
309 $linker_L .= "-Wl,". $flags . " " ;
312 if ($flags =~ /^\-rpath-link\@/) {
314 if ($vendor eq "PGI") {
315 $flags =~ s/lib$/libso/;
317 $linker_L .= "-Wl,". $flags . " " ;
322 && ($flags !~ /gfortranbegin/)
323 && ($flags !~ /frtbegin/)
324 && ($flags !~ /pathfstart/)
325 && ($flags !~ /numa/)
326 && ($flags !~ /crt[0-9]/)
328 && ($flags !~ /user32/)
329 && ($flags !~ /kernel32/)
330 && ($flags !~ /advapi32/)
331 && ($flags !~ /shell32/)
332 && ($flags !~ /^\-l$/)
334 $linker_l .= $flags . " ";
337 $linker_a .= $flags . " " if $flags =~ /\.a$/;
342 if ($vendor eq "INTEL"){
343 $linker_a .= "-lgfortran"
346 if ($vendor eq "FLANG"){
347 $linker_a .= "-lflang"
350 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
351 open(CONFFILE, ">> $config" ) || die "Can't append $config";
353 print MAKEFILE "F_COMPILER=$vendor\n";
354 print MAKEFILE "FC=$compiler\n";
355 print MAKEFILE "BU=$bu\n" if $bu ne "";
356 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
358 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
359 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
360 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
362 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
364 if (($linker_l ne "") || ($linker_a ne "")) {
365 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";