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",
39 foreach $lists (@lists) {
40 foreach $path (@path) {
41 if (-x $path . "/" . $lists) {
43 $compiler_bin = $lists;
51 if ($compiler eq "") {
54 $compiler = "gfortran";
60 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
65 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
67 if ($data =~ /zhoge_/) {
73 $data =~ /(\d)\.(\d).(\d)/;
92 if ($data =~ /Intel/) {
97 if ($data =~ /Sun Fortran/) {
99 $openmp = "-xopenmp=parallel";
102 if ($data =~ /PathScale/) {
107 if ($data =~ /Open64/) {
112 if ($data =~ /PGF/) {
117 if ($data =~ /IBM XL/) {
122 # for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
123 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
124 if ($data =~ /zho_ge__/) {
131 if ($compiler =~ /g77/) {
137 if ($compiler =~ /g95/) {
143 if ($compiler =~ /gfortran/) {
146 $openmp = "-fopenmp";
149 if ($compiler =~ /ifort/) {
155 if ($compiler =~ /pathf/) {
161 if ($compiler =~ /pgf/) {
167 if ($compiler =~ /ftn/) {
173 if ($compiler =~ /frt/) {
179 if ($compiler =~ /sunf77|sunf90|sunf95/) {
182 $openmp = "-xopenmp=parallel";
185 if ($compiler =~ /ppuf/) {
190 if ($compiler =~ /xlf/) {
195 if ($compiler =~ /open64/) {
202 $compiler = "gfortran";
211 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
215 $binary = $ENV{"BINARY"};
217 $openmp = "" if $ENV{USE_OPENMP} != 1;
220 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
222 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
226 $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
228 $binary = "" if ($?);
232 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
234 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
238 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
240 $binary = "" if ($?);
244 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
254 $link =~ s/\-Y\sP\,/\-Y/g;
256 $link =~ s/\-rpath\s+/\-rpath\@/g;
258 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
260 @flags = split(/[\s\,\n]/, $link);
261 # remove leading and trailing quotes from each flag.
262 @flags = map {s/^['"]|['"]$//g; $_} @flags;
264 foreach $flags (@flags) {
267 && ($flags !~ /^-LIST:/)
268 && ($flags !~ /^-LANG:/)
270 if ($vendor eq "PGI") {
271 $flags =~ s/lib$/libso/;
273 $linker_L .= $flags . " ";
276 if ($flags =~ /^\-Y/) {
277 next if ($hostos eq 'SunOS');
278 $linker_L .= "-Wl,". $flags . " ";
281 if ($flags =~ /^\-rpath\@/) {
283 if ($vendor eq "PGI") {
284 $flags =~ s/lib$/libso/;
286 $linker_L .= "-Wl,". $flags . " " ;
289 if ($flags =~ /^\-rpath-link\@/) {
291 if ($vendor eq "PGI") {
292 $flags =~ s/lib$/libso/;
294 $linker_L .= "-Wl,". $flags . " " ;
299 && ($flags !~ /gfortranbegin/)
300 && ($flags !~ /frtbegin/)
301 && ($flags !~ /pathfstart/)
302 && ($flags !~ /numa/)
303 && ($flags !~ /crt[0-9]/)
305 && ($flags !~ /user32/)
306 && ($flags !~ /kernel32/)
307 && ($flags !~ /advapi32/)
308 && ($flags !~ /shell32/)
309 && ($flags !~ /^\-l$/)
311 $linker_l .= $flags . " ";
314 $linker_a .= $flags . " " if $flags =~ /\.a$/;
319 if ($vendor eq "INTEL"){
320 $linker_a .= "-lgfortran"
323 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
324 open(CONFFILE, ">> $config" ) || die "Can't append $config";
326 print MAKEFILE "F_COMPILER=$vendor\n";
327 print MAKEFILE "FC=$compiler\n";
328 print MAKEFILE "BU=$bu\n" if $bu ne "";
329 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
331 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
332 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
333 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
335 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
337 if (($linker_l ne "") || ($linker_a ne "")) {
338 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";