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)
6 dnl Check that we have a working GNU Fortran compiler
7 AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
8 AC_MSG_CHECKING([whether the GNU Fortran compiler is working])
9 AC_LANG_PUSH([Fortran])
12 real, parameter :: bar = sin (12.34 / 2.5)
14 [AC_MSG_RESULT([yes])],
16 AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
18 AC_LANG_POP([Fortran])
22 sinclude(../libtool.m4)
23 dnl The lines below arrange for aclocal not to bring an installed
24 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
25 dnl add a definition of LIBTOOL to Makefile.in.
26 ifelse(,,,[AC_SUBST(LIBTOOL)
27 AC_DEFUN([AM_PROG_LIBTOOL])
28 AC_DEFUN([AC_LIBTOOL_DLOPEN])
29 AC_DEFUN([AC_PROG_LD])
32 dnl Check whether the target supports hidden visibility.
33 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
34 AC_CACHE_CHECK([whether the target supports hidden visibility],
35 libgfor_cv_have_attribute_visibility, [
37 CFLAGS="$CFLAGS -Werror"
38 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])],
39 libgfor_cv_have_attribute_visibility=yes,
40 libgfor_cv_have_attribute_visibility=no)
41 CFLAGS="$save_CFLAGS"])
42 if test $libgfor_cv_have_attribute_visibility = yes; then
43 AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
44 [Define to 1 if the target supports __attribute__((visibility(...))).])
47 dnl Check whether the target supports symbol aliases.
48 AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
49 AC_CACHE_CHECK([whether the target supports symbol aliases],
50 libgfor_cv_have_attribute_alias, [
51 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
53 extern void bar(void) __attribute__((alias("foo")));]],
54 [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
55 if test $libgfor_cv_have_attribute_alias = yes; then
56 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
57 [Define to 1 if the target supports __attribute__((alias(...))).])
60 dnl Check whether the target supports __sync_fetch_and_add.
61 AC_DEFUN([LIBGFOR_CHECK_SYNC_FETCH_AND_ADD], [
62 AC_CACHE_CHECK([whether the target supports __sync_fetch_and_add],
63 libgfor_cv_have_sync_fetch_and_add, [
64 AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
65 if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
66 if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);]])],
67 libgfor_cv_have_sync_fetch_and_add=yes, libgfor_cv_have_sync_fetch_and_add=no)])
68 if test $libgfor_cv_have_sync_fetch_and_add = yes; then
69 AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
70 [Define to 1 if the target supports __sync_fetch_and_add])
73 dnl Check for pragma weak.
74 AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
75 AC_CACHE_CHECK([whether pragma weak works],
76 libgfor_cv_have_pragma_weak, [
77 gfor_save_CFLAGS="$CFLAGS"
78 CFLAGS="$CFLAGS -Wunknown-pragmas"
79 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
82 ]], [[if (foo) foo ();]])],
83 libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
84 if test $libgfor_cv_have_pragma_weak = yes; then
85 AC_DEFINE(SUPPORTS_WEAK, 1,
86 [Define to 1 if the target supports #pragma weak])
89 *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
90 AC_DEFINE(GTHREAD_USE_WEAK, 0,
91 [Define to 0 if the target shouldn't use #pragma weak])
95 dnl Check whether target effectively supports weakref
96 AC_DEFUN([LIBGFOR_CHECK_WEAKREF], [
97 AC_CACHE_CHECK([whether the target supports weakref],
98 libgfor_cv_have_weakref, [
100 CFLAGS="$CFLAGS -Wunknown-pragmas -Werror"
101 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
102 static int mytoto (int) __attribute__((__weakref__("toto")));
103 ]], [[return (mytoto != 0);]])],
104 libgfor_cv_have_weakref=yes, libgfor_cv_have_weakref=no)
105 CFLAGS="$save_CFLAGS"])
106 if test $libgfor_cv_have_weakref = yes; then
107 AC_DEFINE(SUPPORTS_WEAKREF, 1,
108 [Define to 1 if the target supports weakref])
111 dnl Check whether target can unlink a file still open.
112 AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
113 AC_CACHE_CHECK([whether the target can unlink an open file],
114 libgfor_cv_have_unlink_open_file, [
115 AC_RUN_IFELSE([AC_LANG_SOURCE([[
119 #include <sys/stat.h>
125 fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
128 if (unlink ("testfile") == -1)
130 write (fd, "This is a test\n", 15);
133 if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
137 }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
139 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
140 *) libgfor_cv_have_unlink_open_file=yes;;
142 if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
143 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
146 dnl Check whether CRLF is the line terminator
147 AC_DEFUN([LIBGFOR_CHECK_CRLF], [
148 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
149 libgfor_cv_have_crlf, [
150 AC_RUN_IFELSE([AC_LANG_SOURCE([[
151 /* This test program should exit with status 0 if system uses a CRLF as
152 line terminator, and status 1 otherwise.
153 Since it is used to check for mingw systems, and should return 0 in any
154 other case, in case of a failure we will not use CRLF. */
155 #include <sys/stat.h>
168 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
171 if (write (fd, "\n", 1) < 0)
176 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
178 bytes = read (fd, buff, 5);
179 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
184 }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
186 *mingw*) libgfor_cv_have_crlf=yes ;;
187 *) libgfor_cv_have_crlf=no;;
189 if test x"$libgfor_cv_have_crlf" = xyes; then
190 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
193 dnl Check whether the st_ino and st_dev stat fields taken together uniquely
194 dnl identify the file within the system. This is should be true for POSIX
195 dnl systems; it is known to be false on mingw32.
196 AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
197 AC_CACHE_CHECK([whether the target stat is reliable],
198 libgfor_cv_have_working_stat, [
199 AC_RUN_IFELSE([AC_LANG_SOURCE([[
201 #include <sys/types.h>
202 #include <sys/stat.h>
208 struct stat st1, st2;
210 f = fopen ("foo", "w");
211 g = fopen ("bar", "w");
212 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
214 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
219 }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
221 *mingw*) libgfor_cv_have_working_stat=no ;;
222 *) libgfor_cv_have_working_stat=yes;;
224 if test x"$libgfor_cv_have_working_stat" = xyes; then
225 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
228 dnl Checks for fpsetmask function.
229 AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
230 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
231 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
232 #if HAVE_FLOATINGPOINT_H
233 # include <floatingpoint.h>
234 #endif /* HAVE_FLOATINGPOINT_H */
237 #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
238 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
240 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
242 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
246 dnl Check whether we have a mingw that provides a __mingw_snprintf function
247 AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
248 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
249 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
251 extern int __mingw_snprintf (char *, size_t, const char *, ...);
253 __mingw_snprintf (NULL, 0, "%d\n", 1);
255 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
257 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
258 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
262 dnl Check whether we have a __float128 type
263 AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
266 if test "x$enable_libquadmath_support" != xno; then
268 AC_CACHE_CHECK([whether we have a usable __float128 type],
269 libgfor_cv_have_float128, [
270 GCC_TRY_COMPILE_OR_LINK([
271 typedef _Complex float __attribute__((mode(TC))) __complex128;
273 __float128 foo (__float128 x)
282 return (__float128) z2;
285 __float128 bar (__float128 x)
287 return x * __builtin_huge_valq ();
293 libgfor_cv_have_float128=yes
295 libgfor_cv_have_float128=no
298 if test "x$libgfor_cv_have_float128" = xyes; then
299 AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
301 dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
303 dnl Turn warnings into error to avoid testsuite breakage. So enable
304 dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
305 dnl it off again. As a workaround, save and restore werror flag like
307 dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
308 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
309 AC_CACHE_CHECK([whether --as-needed/-z ignore works],
310 [libgfor_cv_have_as_needed],
312 # Test for native Solaris options first.
313 # No whitespace after -z to pass it through -Wl.
314 libgfor_cv_as_needed_option="-zignore"
315 libgfor_cv_no_as_needed_option="-zrecord"
316 save_LDFLAGS="$LDFLAGS"
317 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
318 libgfor_cv_have_as_needed=no
320 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
321 [libgfor_cv_have_as_needed=yes],
322 [libgfor_cv_have_as_needed=no])
323 LDFLAGS="$save_LDFLAGS"
324 if test "x$libgfor_cv_have_as_needed" = xno; then
325 libgfor_cv_as_needed_option="--as-needed"
326 libgfor_cv_no_as_needed_option="--no-as-needed"
327 save_LDFLAGS="$LDFLAGS"
328 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
329 libgfor_cv_have_as_needed=no
331 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
332 [libgfor_cv_have_as_needed=yes],
333 [libgfor_cv_have_as_needed=no])
334 LDFLAGS="$save_LDFLAGS"
336 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
339 dnl For static libgfortran linkage, depend on libquadmath only if needed.
340 if test "x$libgfor_cv_have_as_needed" = xyes; then
341 LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
343 LIBQUADSPEC="-lquadmath"
345 if test -f ../libquadmath/libquadmath.la; then
346 LIBQUADLIB=../libquadmath/libquadmath.la
347 LIBQUADLIB_DEP=../libquadmath/libquadmath.la
348 LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
350 LIBQUADLIB="-lquadmath"
356 # for --disable-quadmath
362 dnl For the spec file
363 AC_SUBST(LIBQUADSPEC)
365 AC_SUBST(LIBQUADLIB_DEP)
366 AC_SUBST(LIBQUADINCLUDE)
368 dnl We need a conditional for the Makefile
369 AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
373 dnl Check whether we have strerror_r
374 AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
375 dnl Check for three-argument POSIX version of strerror_r
376 ac_save_CFLAGS="$CFLAGS"
377 CFLAGS="-Wimplicit-function-declaration -Werror"
378 AC_TRY_COMPILE([#define _GNU_SOURCE 1
380 #include <locale.h>],
381 [char s[128]; strerror_r(5, s, 128);],
382 AC_DEFINE(HAVE_STRERROR_R, 1,
383 [Define if strerror_r is available in <string.h>.]),)
384 CFLAGS="$ac_save_CFLAGS"
386 dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
387 ac_save_CFLAGS="$CFLAGS"
388 CFLAGS="-Wimplicit-function-declaration -Werror"
389 AC_TRY_COMPILE([#define _GNU_SOURCE 1
391 #include <locale.h>],
392 [char s[128]; strerror_r(5, s);],
393 AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
394 [Define if strerror_r takes two arguments and is available in <string.h>.]),)
395 CFLAGS="$ac_save_CFLAGS"
400 AC_DEFUN([LIBGFOR_CHECK_AVX], [
401 ac_save_CFLAGS="$CFLAGS"
403 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
404 void _mm256_zeroall (void)
406 __builtin_ia32_vzeroall ();
408 AC_DEFINE(HAVE_AVX, 1,
409 [Define if AVX instructions can be compiled.]),
411 CFLAGS="$ac_save_CFLAGS"
416 AC_DEFUN([LIBGFOR_CHECK_AVX2], [
417 ac_save_CFLAGS="$CFLAGS"
419 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
420 typedef long long __v4di __attribute__ ((__vector_size__ (32)));
422 mm256_is32_andnotsi256 (__v4di __X, __v4di __Y)
424 return __builtin_ia32_andnotsi256 (__X, __Y);
426 AC_DEFINE(HAVE_AVX2, 1,
427 [Define if AVX2 instructions can be compiled.]),
429 CFLAGS="$ac_save_CFLAGS"
432 dnl Check for AVX512f
434 AC_DEFUN([LIBGFOR_CHECK_AVX512F], [
435 ac_save_CFLAGS="$CFLAGS"
436 CFLAGS="-O2 -mavx512f"
437 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
438 typedef double __m512d __attribute__ ((__vector_size__ (64)));
439 __m512d _mm512_add (__m512d a)
441 __m512d b = __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
442 /* For -m64/-mx32 also verify that code will work even if
443 the target uses call saved zmm16+ and needs to emit
444 unwind info for them (e.g. on mingw). See PR79127. */
446 asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19");
450 AC_DEFINE(HAVE_AVX512F, 1,
451 [Define if AVX512f instructions can be compiled.]),
453 CFLAGS="$ac_save_CFLAGS"