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

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