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 9.3 kB

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