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.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #For gfortran MIPS
  167. if ($?) {
  168. $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  169. }
  170. $binary = "" if ($?);
  171. }
  172. if ($binary == 64) {
  173. $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  174. if ($?) {
  175. $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  176. }
  177. #For gfortran MIPS
  178. if ($?) {
  179. $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  180. }
  181. $binary = "" if ($?);
  182. }
  183. if ($binary eq "") {
  184. $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  185. }
  186. }
  187. $linker_L = "";
  188. $linker_l = "";
  189. $linker_a = "";
  190. if ($link ne "") {
  191. $link =~ s/\-Y\sP\,/\-Y/g;
  192. $link =~ s/\-rpath\s+/\-rpath\@/g;
  193. @flags = split(/[\s\,\n]/, $link);
  194. # remove leading and trailing quotes from each flag.
  195. @flags = map {s/^['"]|['"]$//g; $_} @flags;
  196. foreach $flags (@flags) {
  197. if (
  198. ($flags =~ /^\-L/)
  199. && ($flags !~ /^-LIST:/)
  200. && ($flags !~ /^-LANG:/)
  201. ) {
  202. if ($vendor eq "PGI") {
  203. $flags =~ s/lib$/libso/;
  204. }
  205. $linker_L .= $flags . " ";
  206. }
  207. if ($flags =~ /^\-Y/) {
  208. $linker_L .= "-Wl,". $flags . " ";
  209. }
  210. if ($flags =~ /^\-rpath/) {
  211. $flags =~ s/\@/\,/g;
  212. if ($vendor eq "PGI") {
  213. $flags =~ s/lib$/libso/;
  214. }
  215. $linker_L .= "-Wl,". $flags . " " ;
  216. }
  217. if (
  218. ($flags =~ /^\-l/)
  219. && ($flags !~ /gfortranbegin/)
  220. && ($flags !~ /frtbegin/)
  221. && ($flags !~ /pathfstart/)
  222. && ($flags !~ /numa/)
  223. && ($flags !~ /crt[0-9]/)
  224. && ($flags !~ /gcc/)
  225. && ($flags !~ /user32/)
  226. && ($flags !~ /kernel32/)
  227. && ($flags !~ /advapi32/)
  228. && ($flags !~ /shell32/)
  229. && ($flags !~ /^\-l$/)
  230. ) {
  231. $linker_l .= $flags . " ";
  232. }
  233. $linker_a .= $flags . " " if $flags =~ /\.a$/;
  234. }
  235. }
  236. if ($vendor eq "INTEL"){
  237. $linker_a .= "-lgfortran"
  238. }
  239. open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
  240. open(CONFFILE, ">> $config" ) || die "Can't append $config";
  241. print MAKEFILE "F_COMPILER=$vendor\n";
  242. print MAKEFILE "FC=$compiler\n";
  243. print MAKEFILE "BU=$bu\n" if $bu ne "";
  244. print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
  245. print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
  246. print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
  247. if (($linker_l ne "") || ($linker_a ne "")) {
  248. print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";
  249. }
  250. close(MAKEFILE);
  251. close(CONFFILE);