5 # 1.1 Automatically detect, then check compiler
6 # 1.2 If no fortran compiler is detected, g77 is default with NOFORTRAN definition
8 # 2.1 If path is correct, check compiler
9 # 2.2 If path is not correct, but still valid compiler name, force setting
10 # 2.2.2 Path is not correct, invalid compiler name, then g77 is default with NOFORTRAN definition
13 $makefile = shift(@ARGV);
14 $config = shift(@ARGV);
18 $compiler = join(" ", @ARGV);
20 # f77 is too ambiguous
21 $compiler = "" if $compiler eq "f77";
23 @path = split(/:/, $ENV{"PATH"});
25 if ($compiler eq "") {
27 @lists = ("g77", "g95", "gfortran", "frt", "fort", "openf90", "openf95",
28 "sunf77", "sunf90", "sunf95",
29 "xlf95", "xlf90", "xlf",
30 "ppuf77", "ppuf95", "ppuf90", "ppuxlf",
32 "pgf95", "pgf90", "pgf77",
36 foreach $lists (@lists) {
37 foreach $path (@path) {
38 if (-x $path . "/" . $lists) {
47 if ($compiler eq "") {
56 $data = `which $compiler > /dev/null 2> /dev/null`;
61 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
63 if ($data =~ /zhoge_/) {
69 $data =~ /(\d)\.(\d).(\d)/;
88 if ($data =~ /Intel/) {
93 if ($data =~ /Sun Fortran/) {
95 $openmp = "-xopenmp=parallel";
98 if ($data =~ /PathScale/) {
103 if ($data =~ /Open64/) {
108 if ($data =~ /PGF/) {
113 if ($data =~ /IBM/) {
118 # for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
119 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
120 if ($data =~ /zho_ge__/) {
127 if ($compiler =~ /g77/) {
133 if ($compiler =~ /g95/) {
139 if ($compiler =~ /gfortran/) {
142 $openmp = "-fopenmp";
145 if ($compiler =~ /ifort/) {
151 if ($compiler =~ /pathf/) {
157 if ($compiler =~ /pgf/) {
163 if ($compiler =~ /ftn/) {
169 if ($compiler =~ /frt/) {
175 if ($compiler =~ /sunf77|sunf90|sunf95/) {
178 $openmp = "-xopenmp=parallel";
181 if ($compiler =~ /ppuf/) {
186 if ($compiler =~ /xlf/) {
191 if ($compiler =~ /open64/) {
207 $data = `which $compiler > /dev/null 2> /dev/null`;
211 $binary = $ENV{"BINARY"};
213 $openmp = "" if $ENV{USE_OPENMP} != 1;
216 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
218 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
222 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
224 $binary = "" if ($?);
228 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
230 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
234 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
236 $binary = "" if ($?);
240 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
250 $link =~ s/\-Y\sP\,/\-Y/g;
252 $link =~ s/\-rpath\s+/\-rpath\@/g;
254 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
256 @flags = split(/[\s\,\n]/, $link);
257 # remove leading and trailing quotes from each flag.
258 @flags = map {s/^['"]|['"]$//g; $_} @flags;
260 foreach $flags (@flags) {
263 && ($flags !~ /^-LIST:/)
264 && ($flags !~ /^-LANG:/)
266 if ($vendor eq "PGI") {
267 $flags =~ s/lib$/libso/;
269 $linker_L .= $flags . " ";
272 if ($flags =~ /^\-Y/) {
273 $linker_L .= "-Wl,". $flags . " ";
276 if ($flags =~ /^\-rpath\@/) {
278 if ($vendor eq "PGI") {
279 $flags =~ s/lib$/libso/;
281 $linker_L .= "-Wl,". $flags . " " ;
284 if ($flags =~ /^\-rpath-link\@/) {
286 if ($vendor eq "PGI") {
287 $flags =~ s/lib$/libso/;
289 $linker_L .= "-Wl,". $flags . " " ;
294 && ($flags !~ /gfortranbegin/)
295 && ($flags !~ /frtbegin/)
296 && ($flags !~ /pathfstart/)
297 && ($flags !~ /numa/)
298 && ($flags !~ /crt[0-9]/)
300 && ($flags !~ /user32/)
301 && ($flags !~ /kernel32/)
302 && ($flags !~ /advapi32/)
303 && ($flags !~ /shell32/)
304 && ($flags !~ /^\-l$/)
306 $linker_l .= $flags . " ";
309 $linker_a .= $flags . " " if $flags =~ /\.a$/;
314 if ($vendor eq "INTEL"){
315 $linker_a .= "-lgfortran"
318 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
319 open(CONFFILE, ">> $config" ) || die "Can't append $config";
321 print MAKEFILE "F_COMPILER=$vendor\n";
322 print MAKEFILE "FC=$compiler\n";
323 print MAKEFILE "BU=$bu\n" if $bu ne "";
324 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
326 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
327 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
328 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
330 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
332 if (($linker_l ne "") || ($linker_a ne "")) {
333 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";