1 m4_include(../config/acx.m4)
2 m4_include(../config/no-executables.m4)
3 m4_include(../config/math.m4)
4 m4_include(../config/ax_check_define.m4)
5 m4_include(../config/enable.m4)
6 m4_include(../config/cet.m4)
8 dnl Check that we have a working GNU Fortran compiler
9 AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
10 AC_MSG_CHECKING([whether the GNU Fortran compiler is working])
11 AC_LANG_PUSH([Fortran])
14 real, parameter :: bar = sin (12.34 / 2.5)
16 [AC_MSG_RESULT([yes])],
18 AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
20 AC_LANG_POP([Fortran])
24 sinclude(../libtool.m4)
25 dnl The lines below arrange for aclocal not to bring an installed
26 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
27 dnl add a definition of LIBTOOL to Makefile.in.
28 ifelse(,,,[AC_SUBST(LIBTOOL)
29 AC_DEFUN([AM_PROG_LIBTOOL])
30 AC_DEFUN([AC_LIBTOOL_DLOPEN])
31 AC_DEFUN([AC_PROG_LD])
34 dnl Check whether the target supports hidden visibility.
35 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
36 AC_CACHE_CHECK([whether the target supports hidden visibility],
37 libgfor_cv_have_attribute_visibility, [
39 CFLAGS="$CFLAGS -Werror"
40 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])],
41 libgfor_cv_have_attribute_visibility=yes,
42 libgfor_cv_have_attribute_visibility=no)
43 CFLAGS="$save_CFLAGS"])
44 if test $libgfor_cv_have_attribute_visibility = yes; then
45 AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
46 [Define to 1 if the target supports __attribute__((visibility(...))).])
49 dnl Check whether the target supports symbol aliases.
50 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
51 AC_CACHE_CHECK([whether the target supports symbol aliases],
52 libgfor_cv_have_attribute_alias, [
53 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
55 extern void bar(void) __attribute__((alias("foo")));]],
56 [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
57 if test $libgfor_cv_have_attribute_alias = yes; then
58 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
59 [Define to 1 if the target supports __attribute__((alias(...))).])
62 dnl Check whether the target supports __atomic_fetch_add.
63 AC_DEFUN([LIBGFOR_CHECK_ATOMIC_FETCH_ADD], [
64 AC_CACHE_CHECK([whether the target supports __atomic_fetch_add],
65 libgfor_cv_have_atomic_fetch_add, [
66 AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
67 if (foovar <= 0) return __atomic_fetch_add (&foovar, 1, __ATOMIC_ACQ_REL);
68 if (foovar > 10) return __atomic_add_fetch (&foovar, -1, __ATOMIC_ACQ_REL);]])],
69 libgfor_cv_have_atomic_fetch_add=yes, libgfor_cv_have_atomic_fetch_add=no)])
70 if test $libgfor_cv_have_atomic_fetch_add = yes; then
71 AC_DEFINE(HAVE_ATOMIC_FETCH_ADD, 1,
72 [Define to 1 if the target supports __atomic_fetch_add])
75 dnl Check for pragma weak.
76 AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
77 AC_CACHE_CHECK([whether pragma weak works],
78 libgfor_cv_have_pragma_weak, [
79 gfor_save_CFLAGS="$CFLAGS"
80 CFLAGS="$CFLAGS -Wunknown-pragmas"
81 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
84 ]], [[if (foo) foo ();]])],
85 libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
86 if test $libgfor_cv_have_pragma_weak = yes; then
87 AC_DEFINE(SUPPORTS_WEAK, 1,
88 [Define to 1 if the target supports #pragma weak])
91 *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
92 AC_DEFINE(GTHREAD_USE_WEAK, 0,
93 [Define to 0 if the target shouldn't use #pragma weak])
97 dnl Check whether target effectively supports weakref
98 AC_DEFUN([LIBGFOR_CHECK_WEAKREF], [
99 AC_CACHE_CHECK([whether the target supports weakref],
100 libgfor_cv_have_weakref, [
101 save_CFLAGS="$CFLAGS"
102 CFLAGS="$CFLAGS -Wunknown-pragmas -Werror"
103 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
104 static int mytoto (int) __attribute__((__weakref__("toto")));
105 ]], [[return (mytoto != 0);]])],
106 libgfor_cv_have_weakref=yes, libgfor_cv_have_weakref=no)
107 CFLAGS="$save_CFLAGS"])
108 if test $libgfor_cv_have_weakref = yes; then
109 AC_DEFINE(SUPPORTS_WEAKREF, 1,
110 [Define to 1 if the target supports weakref])
113 dnl Check whether target can unlink a file still open.
114 AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
115 AC_CACHE_CHECK([whether the target can unlink an open file],
116 libgfor_cv_have_unlink_open_file, [
117 AC_RUN_IFELSE([AC_LANG_SOURCE([[
121 #include <sys/stat.h>
127 fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
130 if (unlink ("testfile") == -1)
132 write (fd, "This is a test\n", 15);
135 if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
139 }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
141 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
142 *) libgfor_cv_have_unlink_open_file=yes;;
144 if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
145 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
148 dnl Check whether CRLF is the line terminator
149 AC_DEFUN([LIBGFOR_CHECK_CRLF], [
150 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
151 libgfor_cv_have_crlf, [
152 AC_RUN_IFELSE([AC_LANG_SOURCE([[
153 /* This test program should exit with status 0 if system uses a CRLF as
154 line terminator, and status 1 otherwise.
155 Since it is used to check for mingw systems, and should return 0 in any
156 other case, in case of a failure we will not use CRLF. */
157 #include <sys/stat.h>
170 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
173 if (write (fd, "\n", 1) < 0)
178 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
180 bytes = read (fd, buff, 5);
181 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
186 }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
188 *mingw*) libgfor_cv_have_crlf=yes ;;
189 *) libgfor_cv_have_crlf=no;;
191 if test x"$libgfor_cv_have_crlf" = xyes; then
192 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
195 dnl Check whether the st_ino and st_dev stat fields taken together uniquely
196 dnl identify the file within the system. This is should be true for POSIX
197 dnl systems; it is known to be false on mingw32.
198 AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
199 AC_CACHE_CHECK([whether the target stat is reliable],
200 libgfor_cv_have_working_stat, [
201 AC_RUN_IFELSE([AC_LANG_SOURCE([[
203 #include <sys/types.h>
204 #include <sys/stat.h>
210 struct stat st1, st2;
212 f = fopen ("foo", "w");
213 g = fopen ("bar", "w");
214 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
216 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
221 }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
223 *mingw*) libgfor_cv_have_working_stat=no ;;
224 *) libgfor_cv_have_working_stat=yes;;
226 if test x"$libgfor_cv_have_working_stat" = xyes; then
227 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
230 dnl Checks for fpsetmask function.
231 AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
232 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
233 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
234 #if HAVE_FLOATINGPOINT_H
235 # include <floatingpoint.h>
236 #endif /* HAVE_FLOATINGPOINT_H */
239 #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
240 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
242 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
244 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
248 dnl Check whether we have a mingw that provides a __mingw_snprintf function
249 AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
250 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
251 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
253 extern int __mingw_snprintf (char *, size_t, const char *, ...);
255 __mingw_snprintf (NULL, 0, "%d\n", 1);
257 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
259 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
260 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
264 dnl Check whether we have a __float128 and _Float128 type
265 AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
272 if test "x$enable_libquadmath_support" != xno; then
274 AC_CACHE_CHECK([whether we have a usable _Float128 type],
275 libgfor_cv_have_float128, [
276 GCC_TRY_COMPILE_OR_LINK([
277 _Float128 foo (_Float128 x)
279 _Complex _Float128 z1, z2;
285 return (_Float128) z2;
288 _Float128 bar (_Float128 x)
290 return x * __builtin_huge_valf128 ();
293 __float128 baz (__float128 x)
295 return x * __builtin_huge_valf128 ();
305 libgfor_cv_have_float128=yes
307 libgfor_cv_have_float128=no
310 if test "x$have_iec_60559_libc_support$enable_libquadmath_support$libgfor_cv_have_float128" = xyesdefaultyes; then
315 if test "x$libgfor_cv_have_float128" = xyes; then
316 if test "x$USE_IEC_60559" = xyes; then
317 AC_DEFINE(USE_IEC_60559, 1, [Define if IEC 60559 *f128 APIs should be used for _Float128.])
319 AC_DEFINE(HAVE_FLOAT128, 1, [Define if target has usable _Float128 and __float128 types.])
321 dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
323 dnl Turn warnings into error to avoid testsuite breakage. So enable
324 dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
325 dnl it off again. As a workaround, save and restore werror flag like
327 dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
328 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
329 AC_CACHE_CHECK([whether --as-needed/-z ignore works],
330 [libgfor_cv_have_as_needed],
332 # Test for native Solaris options first.
333 # No whitespace after -z to pass it through -Wl.
334 libgfor_cv_as_needed_option="-zignore"
335 libgfor_cv_no_as_needed_option="-zrecord"
336 save_LDFLAGS="$LDFLAGS"
337 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
338 libgfor_cv_have_as_needed=no
340 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
341 [libgfor_cv_have_as_needed=yes],
342 [libgfor_cv_have_as_needed=no])
343 LDFLAGS="$save_LDFLAGS"
344 if test "x$libgfor_cv_have_as_needed" = xno; then
345 libgfor_cv_as_needed_option="--as-needed"
346 libgfor_cv_no_as_needed_option="--no-as-needed"
347 save_LDFLAGS="$LDFLAGS"
348 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
349 libgfor_cv_have_as_needed=no
351 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
352 [libgfor_cv_have_as_needed=yes],
353 [libgfor_cv_have_as_needed=no])
354 LDFLAGS="$save_LDFLAGS"
356 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
359 dnl For static libgfortran linkage, depend on libquadmath only if needed.
360 dnl If using *f128 APIs from libc/libm, depend on libquadmath only if needed
361 dnl even for dynamic libgfortran linkage, and don't link libgfortran against
363 if test "x$libgfor_cv_have_as_needed" = xyes; then
364 if test "x$USE_IEC_60559" = xyes; then
365 LIBQUADSPEC="$libgfor_cv_as_needed_option -lquadmath $libgfor_cv_no_as_needed_option"
367 LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
370 LIBQUADSPEC="-lquadmath"
372 if test "x$USE_IEC_60559" != xyes; then
373 if test -f ../libquadmath/libquadmath.la; then
374 LIBQUADLIB=../libquadmath/libquadmath.la
375 LIBQUADLIB_DEP=../libquadmath/libquadmath.la
376 LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
378 LIBQUADLIB="-lquadmath"
386 dnl For the spec file
387 AC_SUBST(LIBQUADSPEC)
389 AC_SUBST(LIBQUADLIB_DEP)
390 AC_SUBST(LIBQUADINCLUDE)
391 AC_SUBST(USE_IEC_60559)
395 dnl Check whether we have strerror_r
396 AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
397 dnl Check for three-argument POSIX version of strerror_r
398 ac_save_CFLAGS="$CFLAGS"
399 CFLAGS="-Wimplicit-function-declaration -Werror"
400 AC_TRY_COMPILE([#define _GNU_SOURCE 1
402 #include <locale.h>],
403 [char s[128]; strerror_r(5, s, 128);],
404 AC_DEFINE(HAVE_STRERROR_R, 1,
405 [Define if strerror_r is available in <string.h>.]),)
406 CFLAGS="$ac_save_CFLAGS"
408 dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
409 ac_save_CFLAGS="$CFLAGS"
410 CFLAGS="-Wimplicit-function-declaration -Werror"
411 AC_TRY_COMPILE([#define _GNU_SOURCE 1
413 #include <locale.h>],
414 [char s[128]; strerror_r(5, s);],
415 AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
416 [Define if strerror_r takes two arguments and is available in <string.h>.]),)
417 CFLAGS="$ac_save_CFLAGS"
422 AC_DEFUN([LIBGFOR_CHECK_AVX], [
423 ac_save_CFLAGS="$CFLAGS"
425 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
426 void _mm256_zeroall (void)
428 __builtin_ia32_vzeroall ();
430 AC_DEFINE(HAVE_AVX, 1,
431 [Define if AVX instructions can be compiled.]),
433 CFLAGS="$ac_save_CFLAGS"
438 AC_DEFUN([LIBGFOR_CHECK_AVX2], [
439 ac_save_CFLAGS="$CFLAGS"
441 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
442 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
444 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
446 return __builtin_ia32_andnotsi256 (__X, __Y);
448 AC_DEFINE(HAVE_AVX2, 1,
449 [Define if AVX2 instructions can be compiled.]),
451 CFLAGS="$ac_save_CFLAGS"
454 dnl Check for AVX512f
456 AC_DEFUN([LIBGFOR_CHECK_AVX512F], [
457 ac_save_CFLAGS="$CFLAGS"
458 CFLAGS="-O2 -mavx512f"
459 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
460 typedef double __m512d __attribute__ ((__vector_size__ (64)));
461 __m512d _mm512_add (__m512d a)
463 __m512d b = __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
464 /* For -m64/-mx32 also verify that code will work even if
465 the target uses call saved zmm16+ and needs to emit
466 unwind info for them (e.g. on mingw). See PR79127. */
468 asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19");
472 AC_DEFINE(HAVE_AVX512F, 1,
473 [Define if AVX512f instructions can be compiled.]),
475 CFLAGS="$ac_save_CFLAGS"
480 AC_DEFUN([LIBGFOR_CHECK_FMA3], [
481 ac_save_CFLAGS="$CFLAGS"
482 CFLAGS="-O2 -mfma -mno-fma4"
483 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
484 typedef float __m128 __attribute__ ((__vector_size__ (16)));
485 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
486 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
488 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
492 AC_DEFINE(HAVE_FMA3, 1,
493 [Define if FMA3 instructions can be compiled.]),
495 CFLAGS="$ac_save_CFLAGS"
500 AC_DEFUN([LIBGFOR_CHECK_FMA4], [
501 ac_save_CFLAGS="$CFLAGS"
502 CFLAGS="-O2 -mfma4 -mno-fma"
503 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
504 typedef float __m128 __attribute__ ((__vector_size__ (16)));
505 typedef float __v4sf __attribute__ ((__vector_size__ (16)));
506 __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
508 return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
512 AC_DEFINE(HAVE_FMA4, 1,
513 [Define if FMA4 instructions can be compiled.]),
515 CFLAGS="$ac_save_CFLAGS"
518 dnl Check for -mprefer-avx128
519 dnl This also defines an automake conditional.
520 AC_DEFUN([LIBGFOR_CHECK_AVX128], [
521 ac_save_CFLAGS="$CFLAGS"
522 CFLAGS="-O2 -mavx -mprefer-avx128"
523 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
527 AC_DEFINE(HAVE_AVX128, 1,
528 [Define if -mprefer-avx128 is supported.])
529 AM_CONDITIONAL([HAVE_AVX128],true),
530 [AM_CONDITIONAL([HAVE_AVX128],false)])
531 CFLAGS="$ac_save_CFLAGS"
534 AC_DEFUN([LIBGFOR_CHECK_MATH_IEEE128],
536 AC_REQUIRE([GCC_CHECK_LIBM])
537 AC_REQUIRE([GCC_CHECK_MATH_HEADERS])
538 AC_CACHE_CHECK([for $1], [gcc_cv_math_func_$1],
539 [AC_LINK_IFELSE([AC_LANG_SOURCE([
540 _Float128 $1 (_Float128);
541 _Float128 (*ptr)(_Float128) = $1;
549 [gcc_cv_math_func_$1=yes],
550 [gcc_cv_math_func_$1=no])])
551 if test $gcc_cv_math_func_$1 = yes; then
552 AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1),[1],
553 [Define to 1 if you have the `$1' function.])