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

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