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 = ("f77", "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/) {
121 if ($compiler =~ /g77/) {
127 if ($compiler =~ /g95/) {
133 if ($compiler =~ /gfortran/) {
136 $openmp = "-fopenmp";
139 if ($compiler =~ /ifort/) {
145 if ($compiler =~ /pathf/) {
151 if ($compiler =~ /pgf/) {
157 if ($compiler =~ /ftn/) {
163 if ($compiler =~ /frt/) {
169 if ($compiler =~ /sunf77|sunf90|sunf95/) {
172 $openmp = "-xopenmp=parallel";
175 if ($compiler =~ /ppuf/) {
180 if ($compiler =~ /xlf/) {
185 if ($compiler =~ /open64/) {
201 $data = `which $compiler > /dev/null 2> /dev/null`;
205 $binary = $ENV{"BINARY"};
207 $openmp = "" if $ENV{USE_OPENMP} != 1;
210 $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
212 $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
216 $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
218 $binary = "" if ($?);
222 $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
224 $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
228 $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
230 $binary = "" if ($?);
234 $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
244 $link =~ s/\-Y\sP\,/\-Y/g;
246 $link =~ s/\-rpath\s+/\-rpath\@/g;
248 @flags = split(/[\s\,\n]/, $link);
249 # remove leading and trailing quotes from each flag.
250 @flags = map {s/^['"]|['"]$//g; $_} @flags;
252 foreach $flags (@flags) {
255 && ($flags !~ /^-LIST:/)
256 && ($flags !~ /^-LANG:/)
258 if ($vendor eq "PGI") {
259 $flags =~ s/lib$/libso/;
261 $linker_L .= $flags . " ";
264 if ($flags =~ /^\-Y/) {
265 $linker_L .= "-Wl,". $flags . " ";
268 if ($flags =~ /^\-rpath/) {
270 if ($vendor eq "PGI") {
271 $flags =~ s/lib$/libso/;
273 $linker_L .= "-Wl,". $flags . " " ;
278 && ($flags !~ /gfortranbegin/)
279 && ($flags !~ /frtbegin/)
280 && ($flags !~ /pathfstart/)
281 && ($flags !~ /numa/)
282 && ($flags !~ /crt[0-9]/)
284 && ($flags !~ /user32/)
285 && ($flags !~ /kernel32/)
286 && ($flags !~ /advapi32/)
287 && ($flags !~ /shell32/)
288 && ($flags !~ /^\-l$/)
290 $linker_l .= $flags . " ";
293 $linker_a .= $flags . " " if $flags =~ /\.a$/;
298 if ($vendor eq "INTEL"){
299 $linker_a .= "-lgfortran"
302 open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
303 open(CONFFILE, ">> $config" ) || die "Can't append $config";
305 print MAKEFILE "F_COMPILER=$vendor\n";
306 print MAKEFILE "FC=$compiler\n";
307 print MAKEFILE "BU=$bu\n" if $bu ne "";
308 print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
310 print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
311 print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
313 if (($linker_l ne "") || ($linker_a ne "")) {
314 print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";