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

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