acinclude.m4 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. m4_include(../config/acx.m4)
  2. m4_include(../config/no-executables.m4)
  3. m4_include(../config/math.m4)
  4. dnl Check that we have a working GNU Fortran compiler
  5. AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
  6. AC_MSG_CHECKING([whether the GNU Fortran compiler is working])
  7. AC_LANG_PUSH([Fortran])
  8. AC_COMPILE_IFELSE([[
  9. program foo
  10. real, parameter :: bar = sin (12.34 / 2.5)
  11. end program foo]],
  12. [AC_MSG_RESULT([yes])],
  13. [AC_MSG_RESULT([no])
  14. AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
  15. ])
  16. AC_LANG_POP([Fortran])
  17. ])
  18. sinclude(../libtool.m4)
  19. dnl The lines below arrange for aclocal not to bring an installed
  20. dnl libtool.m4 into aclocal.m4, while still arranging for automake to
  21. dnl add a definition of LIBTOOL to Makefile.in.
  22. ifelse(,,,[AC_SUBST(LIBTOOL)
  23. AC_DEFUN([AM_PROG_LIBTOOL])
  24. AC_DEFUN([AC_LIBTOOL_DLOPEN])
  25. AC_DEFUN([AC_PROG_LD])
  26. ])
  27. dnl Check whether the target supports hidden visibility.
  28. AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
  29. AC_CACHE_CHECK([whether the target supports hidden visibility],
  30. libgfor_cv_have_attribute_visibility, [
  31. save_CFLAGS="$CFLAGS"
  32. CFLAGS="$CFLAGS -Werror"
  33. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])],
  34. libgfor_cv_have_attribute_visibility=yes,
  35. libgfor_cv_have_attribute_visibility=no)
  36. CFLAGS="$save_CFLAGS"])
  37. if test $libgfor_cv_have_attribute_visibility = yes; then
  38. AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
  39. [Define to 1 if the target supports __attribute__((visibility(...))).])
  40. fi])
  41. dnl Check whether the target supports dllexport
  42. AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT], [
  43. AC_CACHE_CHECK([whether the target supports dllexport],
  44. libgfor_cv_have_attribute_dllexport, [
  45. save_CFLAGS="$CFLAGS"
  46. CFLAGS="$CFLAGS -Werror"
  47. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((dllexport)) foo(void) { }]], [])],
  48. libgfor_cv_have_attribute_dllexport=yes,
  49. libgfor_cv_have_attribute_dllexport=no)
  50. CFLAGS="$save_CFLAGS"])
  51. if test $libgfor_cv_have_attribute_dllexport = yes; then
  52. AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
  53. [Define to 1 if the target supports __attribute__((dllexport)).])
  54. fi])
  55. dnl Check whether the target supports symbol aliases.
  56. AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
  57. AC_CACHE_CHECK([whether the target supports symbol aliases],
  58. libgfor_cv_have_attribute_alias, [
  59. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  60. void foo(void) { }
  61. extern void bar(void) __attribute__((alias("foo")));]],
  62. [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
  63. if test $libgfor_cv_have_attribute_alias = yes; then
  64. AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
  65. [Define to 1 if the target supports __attribute__((alias(...))).])
  66. fi])
  67. dnl Check whether the target supports __sync_fetch_and_add.
  68. AC_DEFUN([LIBGFOR_CHECK_SYNC_FETCH_AND_ADD], [
  69. AC_CACHE_CHECK([whether the target supports __sync_fetch_and_add],
  70. libgfor_cv_have_sync_fetch_and_add, [
  71. AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
  72. if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
  73. if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);]])],
  74. libgfor_cv_have_sync_fetch_and_add=yes, libgfor_cv_have_sync_fetch_and_add=no)])
  75. if test $libgfor_cv_have_sync_fetch_and_add = yes; then
  76. AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
  77. [Define to 1 if the target supports __sync_fetch_and_add])
  78. fi])
  79. dnl Check for pragma weak.
  80. AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
  81. AC_CACHE_CHECK([whether pragma weak works],
  82. libgfor_cv_have_pragma_weak, [
  83. gfor_save_CFLAGS="$CFLAGS"
  84. CFLAGS="$CFLAGS -Wunknown-pragmas"
  85. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  86. void foo (void);
  87. #pragma weak foo
  88. ]], [[if (foo) foo ();]])],
  89. libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
  90. if test $libgfor_cv_have_pragma_weak = yes; then
  91. AC_DEFINE(SUPPORTS_WEAK, 1,
  92. [Define to 1 if the target supports #pragma weak])
  93. fi
  94. case "$host" in
  95. *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
  96. AC_DEFINE(GTHREAD_USE_WEAK, 0,
  97. [Define to 0 if the target shouldn't use #pragma weak])
  98. ;;
  99. esac])
  100. dnl Check whether target can unlink a file still open.
  101. AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
  102. AC_CACHE_CHECK([whether the target can unlink an open file],
  103. libgfor_cv_have_unlink_open_file, [
  104. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  105. #include <errno.h>
  106. #include <fcntl.h>
  107. #include <unistd.h>
  108. #include <sys/stat.h>
  109. int main ()
  110. {
  111. int fd;
  112. fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
  113. if (fd <= 0)
  114. return 0;
  115. if (unlink ("testfile") == -1)
  116. return 1;
  117. write (fd, "This is a test\n", 15);
  118. close (fd);
  119. if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
  120. return 0;
  121. else
  122. return 1;
  123. }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
  124. case "${target}" in
  125. *mingw*) libgfor_cv_have_unlink_open_file=no ;;
  126. *) libgfor_cv_have_unlink_open_file=yes;;
  127. esac])])
  128. if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
  129. AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
  130. fi])
  131. dnl Check whether CRLF is the line terminator
  132. AC_DEFUN([LIBGFOR_CHECK_CRLF], [
  133. AC_CACHE_CHECK([whether the target has CRLF as line terminator],
  134. libgfor_cv_have_crlf, [
  135. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  136. /* This test program should exit with status 0 if system uses a CRLF as
  137. line terminator, and status 1 otherwise.
  138. Since it is used to check for mingw systems, and should return 0 in any
  139. other case, in case of a failure we will not use CRLF. */
  140. #include <sys/stat.h>
  141. #include <stdlib.h>
  142. #include <fcntl.h>
  143. #include <stdio.h>
  144. int main ()
  145. {
  146. #ifndef O_BINARY
  147. exit(1);
  148. #else
  149. int fd, bytes;
  150. char buff[5];
  151. fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
  152. if (fd < 0)
  153. exit(1);
  154. if (write (fd, "\n", 1) < 0)
  155. perror ("write");
  156. close (fd);
  157. if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
  158. exit(1);
  159. bytes = read (fd, buff, 5);
  160. if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
  161. exit(0);
  162. else
  163. exit(1);
  164. #endif
  165. }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
  166. case "${target}" in
  167. *mingw*) libgfor_cv_have_crlf=yes ;;
  168. *) libgfor_cv_have_crlf=no;;
  169. esac])])
  170. if test x"$libgfor_cv_have_crlf" = xyes; then
  171. AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
  172. fi])
  173. dnl Check whether the st_ino and st_dev stat fields taken together uniquely
  174. dnl identify the file within the system. This is should be true for POSIX
  175. dnl systems; it is known to be false on mingw32.
  176. AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
  177. AC_CACHE_CHECK([whether the target stat is reliable],
  178. libgfor_cv_have_working_stat, [
  179. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  180. #include <stdio.h>
  181. #include <sys/types.h>
  182. #include <sys/stat.h>
  183. #include <unistd.h>
  184. int main ()
  185. {
  186. FILE *f, *g;
  187. struct stat st1, st2;
  188. f = fopen ("foo", "w");
  189. g = fopen ("bar", "w");
  190. if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
  191. return 1;
  192. if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
  193. return 1;
  194. fclose(f);
  195. fclose(g);
  196. return 0;
  197. }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
  198. case "${target}" in
  199. *mingw*) libgfor_cv_have_working_stat=no ;;
  200. *) libgfor_cv_have_working_stat=yes;;
  201. esac])])
  202. if test x"$libgfor_cv_have_working_stat" = xyes; then
  203. AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
  204. fi])
  205. dnl Checks for fpsetmask function.
  206. AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
  207. AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
  208. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  209. #if HAVE_FLOATINGPOINT_H
  210. # include <floatingpoint.h>
  211. #endif /* HAVE_FLOATINGPOINT_H */
  212. #if HAVE_IEEEFP_H
  213. # include <ieeefp.h>
  214. #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
  215. eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
  216. ])
  217. if test x"$libgfor_cv_have_fpsetmask" = xyes; then
  218. have_fpsetmask=yes
  219. AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
  220. fi
  221. ])
  222. dnl Check whether we have a mingw that provides a __mingw_snprintf function
  223. AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
  224. AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
  225. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  226. #include <stdio.h>
  227. extern int __mingw_snprintf (char *, size_t, const char *, ...);
  228. ]],[[
  229. __mingw_snprintf (NULL, 0, "%d\n", 1);
  230. ]])],
  231. eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
  232. ])
  233. if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
  234. AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
  235. fi
  236. ])
  237. dnl Check whether we have a __float128 type
  238. AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
  239. LIBQUADSPEC=
  240. if test "x$enable_libquadmath_support" != xno; then
  241. AC_CACHE_CHECK([whether we have a usable __float128 type],
  242. libgfor_cv_have_float128, [
  243. GCC_TRY_COMPILE_OR_LINK([
  244. typedef _Complex float __attribute__((mode(TC))) __complex128;
  245. __float128 foo (__float128 x)
  246. {
  247. __complex128 z1, z2;
  248. z1 = x;
  249. z2 = x / 7.Q;
  250. z2 /= z1;
  251. return (__float128) z2;
  252. }
  253. __float128 bar (__float128 x)
  254. {
  255. return x * __builtin_huge_valq ();
  256. }
  257. ],[
  258. foo (1.2Q);
  259. bar (1.2Q);
  260. ],[
  261. libgfor_cv_have_float128=yes
  262. ],[
  263. libgfor_cv_have_float128=no
  264. ])])
  265. if test "x$libgfor_cv_have_float128" = xyes; then
  266. AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
  267. dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
  268. dnl
  269. dnl Turn warnings into error to avoid testsuite breakage. So enable
  270. dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
  271. dnl it off again. As a workaround, save and restore werror flag like
  272. dnl AC_PATH_XTRA.
  273. dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
  274. ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
  275. AC_CACHE_CHECK([whether --as-needed/-z ignore works],
  276. [libgfor_cv_have_as_needed],
  277. [
  278. # Test for native Solaris options first.
  279. # No whitespace after -z to pass it through -Wl.
  280. libgfor_cv_as_needed_option="-zignore"
  281. libgfor_cv_no_as_needed_option="-zrecord"
  282. save_LDFLAGS="$LDFLAGS"
  283. LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
  284. libgfor_cv_have_as_needed=no
  285. AC_LANG_WERROR
  286. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  287. [libgfor_cv_have_as_needed=yes],
  288. [libgfor_cv_have_as_needed=no])
  289. LDFLAGS="$save_LDFLAGS"
  290. if test "x$libgfor_cv_have_as_needed" = xno; then
  291. libgfor_cv_as_needed_option="--as-needed"
  292. libgfor_cv_no_as_needed_option="--no-as-needed"
  293. save_LDFLAGS="$LDFLAGS"
  294. LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
  295. libgfor_cv_have_as_needed=no
  296. AC_LANG_WERROR
  297. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  298. [libgfor_cv_have_as_needed=yes],
  299. [libgfor_cv_have_as_needed=no])
  300. LDFLAGS="$save_LDFLAGS"
  301. fi
  302. ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
  303. ])
  304. dnl For static libgfortran linkage, depend on libquadmath only if needed.
  305. if test "x$libgfor_cv_have_as_needed" = xyes; then
  306. LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
  307. else
  308. LIBQUADSPEC="-lquadmath"
  309. fi
  310. if test -f ../libquadmath/libquadmath.la; then
  311. LIBQUADLIB=../libquadmath/libquadmath.la
  312. LIBQUADLIB_DEP=../libquadmath/libquadmath.la
  313. LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
  314. else
  315. LIBQUADLIB="-lquadmath"
  316. LIBQUADLIB_DEP=
  317. LIBQUADINCLUDE=
  318. fi
  319. fi
  320. else
  321. # for --disable-quadmath
  322. LIBQUADLIB=
  323. LIBQUADLIB_DEP=
  324. LIBQUADINCLUDE=
  325. fi
  326. dnl For the spec file
  327. AC_SUBST(LIBQUADSPEC)
  328. AC_SUBST(LIBQUADLIB)
  329. AC_SUBST(LIBQUADLIB_DEP)
  330. AC_SUBST(LIBQUADINCLUDE)
  331. dnl We need a conditional for the Makefile
  332. AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
  333. ])
  334. dnl Check whether we have strerror_r
  335. AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
  336. dnl Check for three-argument POSIX version of strerror_r
  337. ac_save_CFLAGS="$CFLAGS"
  338. CFLAGS="-Wimplicit-function-declaration -Werror"
  339. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  340. #include <string.h>
  341. #include <locale.h>],
  342. [char s[128]; strerror_r(5, s, 128);],
  343. AC_DEFINE(HAVE_STRERROR_R, 1,
  344. [Define if strerror_r is available in <string.h>.]),)
  345. CFLAGS="$ac_save_CFLAGS"
  346. dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
  347. ac_save_CFLAGS="$CFLAGS"
  348. CFLAGS="-Wimplicit-function-declaration -Werror"
  349. AC_TRY_COMPILE([#define _GNU_SOURCE 1
  350. #include <string.h>
  351. #include <locale.h>],
  352. [char s[128]; strerror_r(5, s);],
  353. AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
  354. [Define if strerror_r takes two arguments and is available in <string.h>.]),)
  355. CFLAGS="$ac_save_CFLAGS"
  356. ])