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

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 XL/) {
  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. $mips_data = `$compiler_bin -E -dM - < /dev/null`;
  177. if ($mips_data =~ /_MIPS_ISA_MIPS64/) {
  178. $link = `$compiler $openmp -mabi=n32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  179. } else {
  180. $link = `$compiler $openmp -mabi=32 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  181. }
  182. }
  183. $binary = "" if ($?);
  184. }
  185. if ($binary == 64) {
  186. $link = `$compiler $openmp -m64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  187. if ($?) {
  188. $link = `$compiler $openmp -q64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  189. }
  190. #For gfortran MIPS
  191. if ($?) {
  192. $link = `$compiler $openmp -mabi=64 -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  193. }
  194. $binary = "" if ($?);
  195. }
  196. if ($binary eq "") {
  197. $link = `$compiler $openmp -v ftest2.f 2>&1 && rm -f a.out a.exe`;
  198. }
  199. }
  200. $linker_L = "";
  201. $linker_l = "";
  202. $linker_a = "";
  203. if ($link ne "") {
  204. $link =~ s/\-Y\sP\,/\-Y/g;
  205. $link =~ s/\-rpath\s+/\-rpath\@/g;
  206. $link =~ s/\-rpath-link\s+/\-rpath-link\@/g;
  207. @flags = split(/[\s\,\n]/, $link);
  208. # remove leading and trailing quotes from each flag.
  209. @flags = map {s/^['"]|['"]$//g; $_} @flags;
  210. foreach $flags (@flags) {
  211. if (
  212. ($flags =~ /^\-L/)
  213. && ($flags !~ /^-LIST:/)
  214. && ($flags !~ /^-LANG:/)
  215. ) {
  216. if ($vendor eq "PGI") {
  217. $flags =~ s/lib$/libso/;
  218. }
  219. $linker_L .= $flags . " ";
  220. }
  221. if ($flags =~ /^\-Y/) {
  222. next if ($hostos eq 'SunOS');
  223. $linker_L .= "-Wl,". $flags . " ";
  224. }
  225. if ($flags =~ /^\--exclude-libs/) {
  226. $linker_L .= "-Wl,". $flags . " ";
  227. $flags="";
  228. }
  229. if ($flags =~ /^\-rpath\@/) {
  230. $flags =~ s/\@/\,/g;
  231. if ($vendor eq "PGI") {
  232. $flags =~ s/lib$/libso/;
  233. }
  234. $linker_L .= "-Wl,". $flags . " " ;
  235. }
  236. if ($flags =~ /^\-rpath-link\@/) {
  237. $flags =~ s/\@/\,/g;
  238. if ($vendor eq "PGI") {
  239. $flags =~ s/lib$/libso/;
  240. }
  241. $linker_L .= "-Wl,". $flags . " " ;
  242. }
  243. if (
  244. ($flags =~ /^\-l/)
  245. && ($flags !~ /gfortranbegin/)
  246. && ($flags !~ /frtbegin/)
  247. && ($flags !~ /pathfstart/)
  248. && ($flags !~ /numa/)
  249. && ($flags !~ /crt[0-9]/)
  250. && ($flags !~ /gcc/)
  251. && ($flags !~ /user32/)
  252. && ($flags !~ /kernel32/)
  253. && ($flags !~ /advapi32/)
  254. && ($flags !~ /shell32/)
  255. && ($flags !~ /^\-l$/)
  256. ) {
  257. $linker_l .= $flags . " ";
  258. }
  259. $linker_a .= $flags . " " if $flags =~ /\.a$/;
  260. }
  261. }
  262. if ($vendor eq "INTEL"){
  263. $linker_a .= "-lgfortran"
  264. }
  265. open(MAKEFILE, ">> $makefile") || die "Can't append $makefile";
  266. open(CONFFILE, ">> $config" ) || die "Can't append $config";
  267. print MAKEFILE "F_COMPILER=$vendor\n";
  268. print MAKEFILE "FC=$compiler\n";
  269. print MAKEFILE "BU=$bu\n" if $bu ne "";
  270. print MAKEFILE "NOFORTRAN=1\n" if $nofortran == 1;
  271. print CONFFILE "#define BUNDERSCORE\t$bu\n" if $bu ne "";
  272. print CONFFILE "#define NEEDBUNDERSCORE\t1\n" if $bu ne "";
  273. print CONFFILE "#define NEED2UNDERSCORES\t1\n" if $need2bu ne "";
  274. print MAKEFILE "NEED2UNDERSCORES=1\n" if $need2bu ne "";
  275. if (($linker_l ne "") || ($linker_a ne "")) {
  276. print MAKEFILE "FEXTRALIB=$linker_L $linker_l $linker_a\n";
  277. }
  278. close(MAKEFILE);
  279. close(CONFFILE);