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

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