You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

f_check 8.0 kB

10 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #!/usr/bin/perl
  2. $hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
  3. #
  4. # 1. Not specified
  5. # 1.1 Automatically detect, then check compiler
  6. # 1.2 If no fortran compiler is detected, gfortran is default with NOFORTRAN definition
  7. # 2. Specified
  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 gfortran is default with NOFORTRAN definition
  11. #
  12. $makefile = shift(@ARGV);
  13. $config = shift(@ARGV);
  14. $nofortran = 0;
  15. $compiler = join(" ", @ARGV);
  16. $compiler_bin = shift(@ARGV);
  17. # f77 is too ambiguous
  18. $compiler = "" if $compiler eq "f77";
  19. @path = split(/:/, $ENV{"PATH"});
  20. if ($compiler eq "") {
  21. @lists = ("gfortran", "g95", "frt", "fort", "openf90", "openf95",
  22. "sunf77", "sunf90", "sunf95",
  23. "xlf95", "xlf90", "xlf",
  24. "ppuf77", "ppuf95", "ppuf90", "ppuxlf",
  25. "pathf90", "pathf95",
  26. "pgf95", "pgf90", "pgf77",
  27. "flang",
  28. "ifort");
  29. OUTER:
  30. foreach $lists (@lists) {
  31. foreach $path (@path) {
  32. if (-x $path . "/" . $lists) {
  33. $compiler = $lists;
  34. $compiler_bin = $lists;
  35. last OUTER;
  36. }
  37. }
  38. }
  39. }
  40. if ($compiler eq "") {
  41. $nofortran = 1;
  42. $compiler = "gfortran";
  43. $vendor = GFORTRAN;
  44. $bu = "_";
  45. } else {
  46. $data = `which $compiler_bin > /dev/null 2> /dev/null`;
  47. $vendor = "";
  48. if (!$?) {
  49. $data = `$compiler -O2 -S ftest.f > /dev/null 2>&1 && cat ftest.s && rm -f ftest.s`;
  50. if ($data =~ /zhoge_/) {
  51. $bu = "_";
  52. }
  53. if ($data =~ /GNU/) {
  54. $data =~ /(\d+)\.(\d+).(\d+)/;
  55. $major = $1;
  56. $minor = $2;
  57. if ($major >= 4) {
  58. $vendor = GFORTRAN;
  59. $openmp = "-fopenmp";
  60. } else {
  61. if ($compiler =~ /flang/) {
  62. $vendor = FLANG;
  63. $openmp = "-fopenmp";
  64. } elsif ($compiler =~ /pgf/) {
  65. $vendor = PGI;
  66. $openmp = "-mp";
  67. } else {
  68. $vendor = G77;
  69. $openmp = "";
  70. }
  71. }
  72. }
  73. if ($data =~ /g95/) {
  74. $vendor = G95;
  75. $openmp = "";
  76. }
  77. if ($data =~ /Intel/) {
  78. $vendor = INTEL;
  79. $openmp = "-fopenmp";
  80. }
  81. if ($data =~ /Sun Fortran/) {
  82. $vendor = SUN;
  83. $openmp = "-xopenmp=parallel";
  84. }
  85. if ($data =~ /PathScale/) {
  86. $vendor = PATHSCALE;
  87. $openmp = "-openmp";
  88. }
  89. if ($data =~ /Open64/) {
  90. $vendor = OPEN64;
  91. $openmp = "-mp";
  92. }
  93. if ($data =~ /PGF/) {
  94. $vendor = PGI;
  95. $openmp = "-mp";
  96. }
  97. if ($data =~ /IBM XL/) {
  98. $vendor = IBM;
  99. $openmp = "-openmp";
  100. }
  101. # for embedded underscore name, e.g. zho_ge, it may append 2 underscores.
  102. $data = `$compiler -O2 -S ftest3.f > /dev/null 2>&1 && cat ftest3.s && rm -f ftest3.s`;
  103. if ($data =~ / zho_ge__/) {
  104. $need2bu = 1;
  105. }
  106. if ($vendor =~ /G95/) {
  107. if ($ENV{NO_LAPACKE} != 1) {
  108. $need2bu = "";
  109. }
  110. }
  111. }
  112. if ($vendor eq "") {
  113. if ($compiler =~ /g77/) {
  114. $vendor = G77;
  115. $bu = "_";
  116. $openmp = "";
  117. }
  118. if ($compiler =~ /g95/) {
  119. $vendor = G95;
  120. $bu = "_";
  121. $openmp = "";
  122. }
  123. if ($compiler =~ /gfortran/) {
  124. $vendor = GFORTRAN;
  125. $bu = "_";
  126. $openmp = "-fopenmp";
  127. }
  128. if ($compiler =~ /ifort/) {
  129. $vendor = INTEL;
  130. $bu = "_";
  131. $openmp = "-fopenmp";
  132. }
  133. if ($compiler =~ /pathf/) {
  134. $vendor = PATHSCALE;
  135. $bu = "_";
  136. $openmp = "-mp";
  137. }
  138. if ($compiler =~ /pgf/) {
  139. $vendor = PGI;
  140. $bu = "_";
  141. $openmp = "-mp";
  142. }
  143. if ($compiler =~ /ftn/) {
  144. $vendor = PGI;
  145. $bu = "_";
  146. $openmp = "-openmp";
  147. }
  148. if ($compiler =~ /frt/) {
  149. $vendor = FUJITSU;
  150. $bu = "_";
  151. $openmp = "-openmp";
  152. }
  153. if ($compiler =~ /sunf77|sunf90|sunf95/) {
  154. $vendor = SUN;
  155. $bu = "_";
  156. $openmp = "-xopenmp=parallel";
  157. }
  158. if ($compiler =~ /ppuf/) {
  159. $vendor = IBM;
  160. $openmp = "-openmp";
  161. }
  162. if ($compiler =~ /xlf/) {
  163. $vendor = IBM;
  164. $openmp = "-openmp";
  165. }
  166. if ($compiler =~ /open64/) {
  167. $vendor = OPEN64;
  168. $openmp = "-mp";
  169. }
  170. if ($compiler =~ /flang/) {
  171. $vendor = FLANG;
  172. $bu = "_";
  173. $openmp = "-fopenmp";
  174. }
  175. if ($vendor eq "") {
  176. $nofortran = 1;
  177. $compiler = "gfortran";
  178. $vendor = GFORTRAN;
  179. $bu = "_";
  180. $openmp = "";
  181. }
  182. }
  183. }
  184. $data = `which $compiler_bin > /dev/null 2> /dev/null`;
  185. if (!$?) {
  186. $binary = $ENV{"BINARY"};
  187. $openmp = "" if $ENV{USE_OPENMP} != 1;
  188. if ($binary == 32) {
  189. $link = `$compiler $openmp -m32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  190. if ($?) {
  191. $link = `$compiler $openmp -q32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  192. }
  193. # for AIX
  194. if ($?) {
  195. $link = `$compiler $openmp -maix32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  196. }
  197. #For gfortran MIPS
  198. if ($?) {
  199. $mips_data = `$compiler_bin -E -dM - < /dev/null`;
  200. if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
  201. $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  202. } else {
  203. $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  204. }
  205. }
  206. $binary = "" if ($?);
  207. }
  208. if ($binary == 64) {
  209. $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  210. if ($?) {
  211. $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  212. }
  213. # for AIX
  214. if ($?) {
  215. $link = `$compiler $openmp -maix64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  216. }
  217. #For gfortran MIPS
  218. if ($?) {
  219. $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  220. }
  221. $binary = "" if ($?);
  222. }
  223. if ($binary eq "") {
  224. $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  225. }
  226. }
  227. $linker_L = "";
  228. $linker_l = "";
  229. $linker_a = "";
  230. if ($link ne "") {
  231. $link =~ s/\-Y\sP\,/\-Y/g;
  232. $link =~ s/\-R\s*/\-rpath\@/g;
  233. $link =~ s/\-rpath\s+/\-rpath\@/g;
  234. $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
  235. @flags = split(/[\s\,\n]/, $link);
  236. # remove leading and trailing quotes from each flag.
  237. @flags = map {s/^['"]|['"]$//g; $_} @flags;
  238. foreach $flags (@flags) {
  239. if (
  240. ($flags =~ /^\-L/)
  241. && ($flags !~ /^-LIST:/)
  242. && ($flags !~ /^-LANG:/)
  243. ) {
  244. $linker_L .= $flags . " ";
  245. }
  246. if ($flags =~ /^\-Y/) {
  247. next if ($hostos eq 'SunOS');
  248. $linker_L .= "-Wl,". $flags . " ";
  249. }
  250. if ($flags =~ /^\--exclude-libs/) {
  251. $linker_L .= "-Wl,". $flags . " ";
  252. $flags="";
  253. }
  254. if ($flags =~ /^\-rpath\@/) {
  255. $flags =~ s/\@/\,/g;
  256. $linker_L .= "-Wl,". $flags . " " ;
  257. }
  258. if ($flags =~ /^\-rpath-link\@/) {
  259. $flags =~ s/\@/\,/g;
  260. $linker_L .= "-Wl,". $flags . " " ;
  261. }
  262. if (
  263. ($flags =~ /^\-l/)
  264. && ($flags !~ /gfortranbegin/)
  265. && ($flags !~ /frtbegin/)
  266. && ($flags !~ /pathfstart/)
  267. && ($flags !~ /crt[0-9]/)
  268. && ($flags !~ /gcc/)
  269. && ($flags !~ /user32/)
  270. && ($flags !~ /kernel32/)
  271. && ($flags !~ /advapi32/)
  272. && ($flags !~ /shell32/)
  273. && ($flags !~ /omp/ || ($vendor !~ /PGI/ && $flags =~ /omp/))
  274. && ($flags !~ /[0-9]+/)
  275. && ($flags !~ /^\-l$/)
  276. ) {
  277. $linker_l .= $flags . " ";
  278. }
  279. $linker_a .= $flags . " " if $flags =~ /\.a$/;
  280. }
  281. }
  282. if ($vendor eq "INTEL"){
  283. $linker_a .= "-lgfortran"
  284. }
  285. if ($vendor eq "FLANG"){
  286. $linker_a .= "-lflang"
  287. }
  288. open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
  289. open(CONFFILE, ">> $config" ) || die "Can't append $config";
  290. print MAKEFILE "F_COMPILER=$vendor\n";
  291. print MAKEFILE "FC=$compiler\n";
  292. print MAKEFILE "BU=$bu\n" if $bu ne "";
  293. print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
  294. print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
  295. print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
  296. print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
  297. print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
  298. if (($linker_l ne "") || ($linker_a ne "")) {
  299. print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";
  300. }
  301. close(MAKEFILE);
  302. close(CONFFILE);