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 7.0 kB

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