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) {
48 if ($compiler eq "") {
57 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
62 $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
64 if ($data =~ /zhoge_/) {
70 $data =~ /(\d)\.(\d).(\d)/;
89 if ($data =~ /Intel/) {
94 if ($data =~ /Sun Fortran/) {
96 $openmp = "-xopenmp=parallel";
99 if ($data =~ /PathScale/) {
104 if ($data =~ /Open64/) {
109 if ($data =~ /PGF/) {
114 if ($data =~ /IBM/) {
119 # for embeded underscore name, e.g. zho_ge, it may append 2 underscores.
120 $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
121 if ($data =~ /zho_ge__/) {
128 if ($compiler =~ /g77/) {
134 if ($compiler =~ /g95/) {
140 if ($compiler =~ /gfortran/) {
143 $openmp = "-fopenmp";
146 if ($compiler =~ /ifort/) {
152 if ($compiler =~ /pathf/) {
158 if ($compiler =~ /pgf/) {
164 if ($compiler =~ /ftn/) {
170 if ($compiler =~ /frt/) {
176 if ($compiler =~ /sunf77|sunf90|sunf95/) {
179 $openmp = "-xopenmp=parallel";
182 if ($compiler =~ /ppuf/) {
187 if ($compiler =~ /xlf/) {
192 if ($compiler =~ /open64/) {
208 $data = `which $compiler_bin > /dev/null 2> /dev/null`;
212 $binary = $ENV{"BINARY"};
214 $openmp = "" if $ENV{USE_OPENMP} != 1;
217 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
219 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
223 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
225 $binary = "" if ($?);
229 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
231 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
235 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
237 $binary = "" if ($?);
241 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
251 $link =~ s/\-Y\sP\,/\-Y/g;
253 $link =~ s/\-rpath\s+/\-rpath\@/g;
255 $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
257 @flags = split(/[\s\,\n]/, $link);
258 # remove leading and trailing quotes from each flag.
259 @flags = map {s/^['"]|['"]$//g; $_} @flags;
261 foreach $flags (@flags) {
264 && ($flags !~ /^-LIST:/)
265 && ($flags !~ /^-LANG:/)
267 if ($vendor eq "PGI") {
268 $flags =~ s/lib$/libso/;
270 $linker_L .= $flags . " ";
273 if ($flags =~ /^\-Y/) {
274 $linker_L .= "-Wl,". $flags . " ";
277 if ($flags =~ /^\-rpath\@/) {
279 if ($vendor eq "PGI") {
280 $flags =~ s/lib$/libso/;
282 $linker_L .= "-Wl,". $flags . " " ;
285 if ($flags =~ /^\-rpath-link\@/) {
287 if ($vendor eq "PGI") {
288 $flags =~ s/lib$/libso/;
290 $linker_L .= "-Wl,". $flags . " " ;
295 && ($flags !~ /gfortranbegin/)
296 && ($flags !~ /frtbegin/)
297 && ($flags !~ /pathfstart/)
298 && ($flags !~ /numa/)
299 && ($flags !~ /crt[0-9]/)
301 && ($flags !~ /user32/)
302 && ($flags !~ /kernel32/)
303 && ($flags !~ /advapi32/)
304 && ($flags !~ /shell32/)
305 && ($flags !~ /^\-l$/)
307 $linker_l .= $flags . " ";
310 $linker_a .= $flags . " " if $flags =~ /\.a$/;
315 if ($vendor eq "INTEL"){
316 $linker_a .= "-lgfortran"
319 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
320 open(CONFFILE, ">> $config" ) || die "Can't append $config";
322 print MAKEFILE "F_COMPILER=$vendor\n";
323 print MAKEFILE "FC=$compiler\n";
324 print MAKEFILE "BU=$bu\n" if $bu ne "";
325 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
327 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
328 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
329 print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
331 print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
333 if (($linker_l ne "") || ($linker_a ne "")) {
334 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";