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