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);
19 $compiler_bin = shift(@ARGV);
21 # f77 is too ambiguous
22 $compiler = "" if $compiler eq "f77";
24 @path = split(/:/, $ENV{"PATH"});
26 if ($compiler eq "") {
28 @lists = ("g77", "g95", "gfortran", "frt", "fort", "openf90", "openf95",
29 "sunf77", "sunf90", "sunf95",
30 "xlf95", "xlf90", "xlf",
31 "ppuf77", "ppuf95", "ppuf90", "ppuxlf",
33 "pgf95", "pgf90", "pgf77",
37 foreach $lists (@lists) {
38 foreach $path (@path) {
39 if (-x $path . "/" . $lists) {
41 $compiler_bin = $lists;
49 if ($compiler eq "") {
58 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
63 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
65 if ($data =~ /zhoge_/) {
71 $data =~ /(\d)\.(\d).(\d)/;
90 if ($data =~ /Intel/) {
95 if ($data =~ /Sun Fortran/) {
97 $openmp = "-xopenmp=parallel";
100 if ($data =~ /PathScale/) {
105 if ($data =~ /Open64/) {
110 if ($data =~ /PGF/) {
115 if ($data =~ /IBM/) {
120 # for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
121 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
122 if ($data =~ /zho_ge__/) {
129 if ($compiler =~ /g77/) {
135 if ($compiler =~ /g95/) {
141 if ($compiler =~ /gfortran/) {
144 $openmp = "-fopenmp";
147 if ($compiler =~ /ifort/) {
153 if ($compiler =~ /pathf/) {
159 if ($compiler =~ /pgf/) {
165 if ($compiler =~ /ftn/) {
171 if ($compiler =~ /frt/) {
177 if ($compiler =~ /sunf77|sunf90|sunf95/) {
180 $openmp = "-xopenmp=parallel";
183 if ($compiler =~ /ppuf/) {
188 if ($compiler =~ /xlf/) {
193 if ($compiler =~ /open64/) {
209 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
213 $binary = $ENV{"BINARY"};
215 $openmp = "" if $ENV{USE_OPENMP} != 1;
218 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
220 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
224 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
226 $binary = "" if ($?);
230 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
232 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
236 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
238 $binary = "" if ($?);
242 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
252 $link =~ s/\-Y\sP\,/\-Y/g;
254 $link =~ s/\-rpath\s+/\-rpath\@/g;
256 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
258 @flags = split(/[\s\,\n]/, $link);
259 # remove leading and trailing quotes from each flag.
260 @flags = map {s/^['"]|['"]$//g; $_} @flags;
262 foreach $flags (@flags) {
265 && ($flags !~ /^-LIST:/)
266 && ($flags !~ /^-LANG:/)
268 if ($vendor eq "PGI") {
269 $flags =~ s/lib$/libso/;
271 $linker_L .= $flags . " ";
274 if ($flags =~ /^\-Y/) {
275 $linker_L .= "-Wl,". $flags . " ";
278 if ($flags =~ /^\-rpath\@/) {
280 if ($vendor eq "PGI") {
281 $flags =~ s/lib$/libso/;
283 $linker_L .= "-Wl,". $flags . " " ;
286 if ($flags =~ /^\-rpath-link\@/) {
288 if ($vendor eq "PGI") {
289 $flags =~ s/lib$/libso/;
291 $linker_L .= "-Wl,". $flags . " " ;
296 && ($flags !~ /gfortranbegin/)
297 && ($flags !~ /frtbegin/)
298 && ($flags !~ /pathfstart/)
299 && ($flags !~ /numa/)
300 && ($flags !~ /crt[0-9]/)
302 && ($flags !~ /user32/)
303 && ($flags !~ /kernel32/)
304 && ($flags !~ /advapi32/)
305 && ($flags !~ /shell32/)
306 && ($flags !~ /^\-l$/)
308 $linker_l .= $flags . " ";
311 $linker_a .= $flags . " " if $flags =~ /\.a$/;
316 if ($vendor eq "INTEL"){
317 $linker_a .= "-lgfortran"
320 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
321 open(CONFFILE, ">> $config" ) || die "Can't append $config";
323 print MAKEFILE "F_COMPILER=$vendor\n";
324 print MAKEFILE "FC=$compiler\n";
325 print MAKEFILE "BU=$bu\n" if $bu ne "";
326 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
328 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
329 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
330 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
332 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
334 if (($linker_l ne "") || ($linker_a ne "")) {
335 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";