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

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