xref: /netbsd-src/external/gpl3/gcc.old/dist/libgfortran/acinclude.m4 (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1*627f7eb2Smrgm4_include(../config/acx.m4)
2*627f7eb2Smrgm4_include(../config/no-executables.m4)
3*627f7eb2Smrgm4_include(../config/math.m4)
4*627f7eb2Smrgm4_include(../config/ax_check_define.m4)
5*627f7eb2Smrgm4_include(../config/enable.m4)
6*627f7eb2Smrgm4_include(../config/cet.m4)
7*627f7eb2Smrg
8*627f7eb2Smrgdnl Check that we have a working GNU Fortran compiler
9*627f7eb2SmrgAC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
10*627f7eb2SmrgAC_MSG_CHECKING([whether the GNU Fortran compiler is working])
11*627f7eb2SmrgAC_LANG_PUSH([Fortran])
12*627f7eb2SmrgAC_COMPILE_IFELSE([[
13*627f7eb2Smrg      program foo
14*627f7eb2Smrg      real, parameter :: bar = sin (12.34 / 2.5)
15*627f7eb2Smrg      end program foo]],
16*627f7eb2Smrg    [AC_MSG_RESULT([yes])],
17*627f7eb2Smrg    [AC_MSG_RESULT([no])
18*627f7eb2Smrg     AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
19*627f7eb2Smrg    ])
20*627f7eb2SmrgAC_LANG_POP([Fortran])
21*627f7eb2Smrg])
22*627f7eb2Smrg
23*627f7eb2Smrg
24*627f7eb2Smrgsinclude(../libtool.m4)
25*627f7eb2Smrgdnl The lines below arrange for aclocal not to bring an installed
26*627f7eb2Smrgdnl libtool.m4 into aclocal.m4, while still arranging for automake to
27*627f7eb2Smrgdnl add a definition of LIBTOOL to Makefile.in.
28*627f7eb2Smrgifelse(,,,[AC_SUBST(LIBTOOL)
29*627f7eb2SmrgAC_DEFUN([AM_PROG_LIBTOOL])
30*627f7eb2SmrgAC_DEFUN([AC_LIBTOOL_DLOPEN])
31*627f7eb2SmrgAC_DEFUN([AC_PROG_LD])
32*627f7eb2Smrg])
33*627f7eb2Smrg
34*627f7eb2Smrgdnl Check whether the target supports hidden visibility.
35*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
36*627f7eb2Smrg  AC_CACHE_CHECK([whether the target supports hidden visibility],
37*627f7eb2Smrg		 libgfor_cv_have_attribute_visibility, [
38*627f7eb2Smrg  save_CFLAGS="$CFLAGS"
39*627f7eb2Smrg  CFLAGS="$CFLAGS -Werror"
40*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])],
41*627f7eb2Smrg		    libgfor_cv_have_attribute_visibility=yes,
42*627f7eb2Smrg		    libgfor_cv_have_attribute_visibility=no)
43*627f7eb2Smrg  CFLAGS="$save_CFLAGS"])
44*627f7eb2Smrg  if test $libgfor_cv_have_attribute_visibility = yes; then
45*627f7eb2Smrg    AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
46*627f7eb2Smrg      [Define to 1 if the target supports __attribute__((visibility(...))).])
47*627f7eb2Smrg  fi])
48*627f7eb2Smrg
49*627f7eb2Smrgdnl Check whether the target supports symbol aliases.
50*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
51*627f7eb2Smrg  AC_CACHE_CHECK([whether the target supports symbol aliases],
52*627f7eb2Smrg		 libgfor_cv_have_attribute_alias, [
53*627f7eb2Smrg  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
54*627f7eb2Smrgvoid foo(void) { }
55*627f7eb2Smrgextern void bar(void) __attribute__((alias("foo")));]],
56*627f7eb2Smrg    [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
57*627f7eb2Smrg  if test $libgfor_cv_have_attribute_alias = yes; then
58*627f7eb2Smrg    AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
59*627f7eb2Smrg      [Define to 1 if the target supports __attribute__((alias(...))).])
60*627f7eb2Smrg  fi])
61*627f7eb2Smrg
62*627f7eb2Smrgdnl Check whether the target supports __atomic_fetch_add.
63*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_ATOMIC_FETCH_ADD], [
64*627f7eb2Smrg  AC_CACHE_CHECK([whether the target supports __atomic_fetch_add],
65*627f7eb2Smrg		 libgfor_cv_have_atomic_fetch_add, [
66*627f7eb2Smrg  AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
67*627f7eb2Smrgif (foovar <= 0) return __atomic_fetch_add (&foovar, 1, __ATOMIC_ACQ_REL);
68*627f7eb2Smrgif (foovar > 10) return __atomic_add_fetch (&foovar, -1, __ATOMIC_ACQ_REL);]])],
69*627f7eb2Smrg	      libgfor_cv_have_atomic_fetch_add=yes, libgfor_cv_have_atomic_fetch_add=no)])
70*627f7eb2Smrg  if test $libgfor_cv_have_atomic_fetch_add = yes; then
71*627f7eb2Smrg    AC_DEFINE(HAVE_ATOMIC_FETCH_ADD, 1,
72*627f7eb2Smrg	      [Define to 1 if the target supports __atomic_fetch_add])
73*627f7eb2Smrg  fi])
74*627f7eb2Smrg
75*627f7eb2Smrgdnl Check for pragma weak.
76*627f7eb2SmrgAC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
77*627f7eb2Smrg  AC_CACHE_CHECK([whether pragma weak works],
78*627f7eb2Smrg		 libgfor_cv_have_pragma_weak, [
79*627f7eb2Smrg  gfor_save_CFLAGS="$CFLAGS"
80*627f7eb2Smrg  CFLAGS="$CFLAGS -Wunknown-pragmas"
81*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
82*627f7eb2Smrgvoid foo (void);
83*627f7eb2Smrg#pragma weak foo
84*627f7eb2Smrg]], [[if (foo) foo ();]])],
85*627f7eb2Smrg		    libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
86*627f7eb2Smrg  if test $libgfor_cv_have_pragma_weak = yes; then
87*627f7eb2Smrg    AC_DEFINE(SUPPORTS_WEAK, 1,
88*627f7eb2Smrg	      [Define to 1 if the target supports #pragma weak])
89*627f7eb2Smrg  fi
90*627f7eb2Smrg  case "$host" in
91*627f7eb2Smrg    *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | *-*-musl* )
92*627f7eb2Smrg      AC_DEFINE(GTHREAD_USE_WEAK, 0,
93*627f7eb2Smrg		[Define to 0 if the target shouldn't use #pragma weak])
94*627f7eb2Smrg      ;;
95*627f7eb2Smrg  esac])
96*627f7eb2Smrg
97*627f7eb2Smrgdnl Check whether target effectively supports weakref
98*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_WEAKREF], [
99*627f7eb2Smrg  AC_CACHE_CHECK([whether the target supports weakref],
100*627f7eb2Smrg		 libgfor_cv_have_weakref, [
101*627f7eb2Smrg  save_CFLAGS="$CFLAGS"
102*627f7eb2Smrg  CFLAGS="$CFLAGS -Wunknown-pragmas -Werror"
103*627f7eb2Smrg  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
104*627f7eb2Smrgstatic int mytoto (int) __attribute__((__weakref__("toto")));
105*627f7eb2Smrg]], [[return (mytoto != 0);]])],
106*627f7eb2Smrg		 libgfor_cv_have_weakref=yes, libgfor_cv_have_weakref=no)
107*627f7eb2Smrg  CFLAGS="$save_CFLAGS"])
108*627f7eb2Smrg  if test $libgfor_cv_have_weakref = yes; then
109*627f7eb2Smrg    AC_DEFINE(SUPPORTS_WEAKREF, 1,
110*627f7eb2Smrg	      [Define to 1 if the target supports weakref])
111*627f7eb2Smrg  fi])
112*627f7eb2Smrg
113*627f7eb2Smrgdnl Check whether target can unlink a file still open.
114*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
115*627f7eb2Smrg  AC_CACHE_CHECK([whether the target can unlink an open file],
116*627f7eb2Smrg                  libgfor_cv_have_unlink_open_file, [
117*627f7eb2Smrg  AC_RUN_IFELSE([AC_LANG_SOURCE([[
118*627f7eb2Smrg#include <errno.h>
119*627f7eb2Smrg#include <fcntl.h>
120*627f7eb2Smrg#include <unistd.h>
121*627f7eb2Smrg#include <sys/stat.h>
122*627f7eb2Smrg
123*627f7eb2Smrgint main ()
124*627f7eb2Smrg{
125*627f7eb2Smrg  int fd;
126*627f7eb2Smrg
127*627f7eb2Smrg  fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
128*627f7eb2Smrg  if (fd <= 0)
129*627f7eb2Smrg    return 0;
130*627f7eb2Smrg  if (unlink ("testfile") == -1)
131*627f7eb2Smrg    return 1;
132*627f7eb2Smrg  write (fd, "This is a test\n", 15);
133*627f7eb2Smrg  close (fd);
134*627f7eb2Smrg
135*627f7eb2Smrg  if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
136*627f7eb2Smrg    return 0;
137*627f7eb2Smrg  else
138*627f7eb2Smrg    return 1;
139*627f7eb2Smrg}]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
140*627f7eb2Smrgcase "${target}" in
141*627f7eb2Smrg  *mingw*) libgfor_cv_have_unlink_open_file=no ;;
142*627f7eb2Smrg  *) libgfor_cv_have_unlink_open_file=yes;;
143*627f7eb2Smrgesac])])
144*627f7eb2Smrgif test x"$libgfor_cv_have_unlink_open_file" = xyes; then
145*627f7eb2Smrg  AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
146*627f7eb2Smrgfi])
147*627f7eb2Smrg
148*627f7eb2Smrgdnl Check whether CRLF is the line terminator
149*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_CRLF], [
150*627f7eb2Smrg  AC_CACHE_CHECK([whether the target has CRLF as line terminator],
151*627f7eb2Smrg                  libgfor_cv_have_crlf, [
152*627f7eb2Smrg  AC_RUN_IFELSE([AC_LANG_SOURCE([[
153*627f7eb2Smrg/* This test program should exit with status 0 if system uses a CRLF as
154*627f7eb2Smrg   line terminator, and status 1 otherwise.
155*627f7eb2Smrg   Since it is used to check for mingw systems, and should return 0 in any
156*627f7eb2Smrg   other case, in case of a failure we will not use CRLF.  */
157*627f7eb2Smrg#include <sys/stat.h>
158*627f7eb2Smrg#include <stdlib.h>
159*627f7eb2Smrg#include <fcntl.h>
160*627f7eb2Smrg#include <stdio.h>
161*627f7eb2Smrg
162*627f7eb2Smrgint main ()
163*627f7eb2Smrg{
164*627f7eb2Smrg#ifndef O_BINARY
165*627f7eb2Smrg  exit(1);
166*627f7eb2Smrg#else
167*627f7eb2Smrg  int fd, bytes;
168*627f7eb2Smrg  char buff[5];
169*627f7eb2Smrg
170*627f7eb2Smrg  fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
171*627f7eb2Smrg  if (fd < 0)
172*627f7eb2Smrg    exit(1);
173*627f7eb2Smrg  if (write (fd, "\n", 1) < 0)
174*627f7eb2Smrg    perror ("write");
175*627f7eb2Smrg
176*627f7eb2Smrg  close (fd);
177*627f7eb2Smrg
178*627f7eb2Smrg  if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
179*627f7eb2Smrg    exit(1);
180*627f7eb2Smrg  bytes = read (fd, buff, 5);
181*627f7eb2Smrg  if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
182*627f7eb2Smrg    exit(0);
183*627f7eb2Smrg  else
184*627f7eb2Smrg    exit(1);
185*627f7eb2Smrg#endif
186*627f7eb2Smrg}]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
187*627f7eb2Smrgcase "${target}" in
188*627f7eb2Smrg  *mingw*) libgfor_cv_have_crlf=yes ;;
189*627f7eb2Smrg  *) libgfor_cv_have_crlf=no;;
190*627f7eb2Smrgesac])])
191*627f7eb2Smrgif test x"$libgfor_cv_have_crlf" = xyes; then
192*627f7eb2Smrg  AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
193*627f7eb2Smrgfi])
194*627f7eb2Smrg
195*627f7eb2Smrgdnl Check whether the st_ino and st_dev stat fields taken together uniquely
196*627f7eb2Smrgdnl identify the file within the system. This is should be true for POSIX
197*627f7eb2Smrgdnl systems; it is known to be false on mingw32.
198*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
199*627f7eb2Smrg  AC_CACHE_CHECK([whether the target stat is reliable],
200*627f7eb2Smrg                  libgfor_cv_have_working_stat, [
201*627f7eb2Smrg  AC_RUN_IFELSE([AC_LANG_SOURCE([[
202*627f7eb2Smrg#include <stdio.h>
203*627f7eb2Smrg#include <sys/types.h>
204*627f7eb2Smrg#include <sys/stat.h>
205*627f7eb2Smrg#include <unistd.h>
206*627f7eb2Smrg
207*627f7eb2Smrgint main ()
208*627f7eb2Smrg{
209*627f7eb2Smrg  FILE *f, *g;
210*627f7eb2Smrg  struct stat st1, st2;
211*627f7eb2Smrg
212*627f7eb2Smrg  f = fopen ("foo", "w");
213*627f7eb2Smrg  g = fopen ("bar", "w");
214*627f7eb2Smrg  if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
215*627f7eb2Smrg    return 1;
216*627f7eb2Smrg  if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
217*627f7eb2Smrg    return 1;
218*627f7eb2Smrg  fclose(f);
219*627f7eb2Smrg  fclose(g);
220*627f7eb2Smrg  return 0;
221*627f7eb2Smrg}]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
222*627f7eb2Smrgcase "${target}" in
223*627f7eb2Smrg  *mingw*) libgfor_cv_have_working_stat=no ;;
224*627f7eb2Smrg  *) libgfor_cv_have_working_stat=yes;;
225*627f7eb2Smrgesac])])
226*627f7eb2Smrgif test x"$libgfor_cv_have_working_stat" = xyes; then
227*627f7eb2Smrg  AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
228*627f7eb2Smrgfi])
229*627f7eb2Smrg
230*627f7eb2Smrgdnl Checks for fpsetmask function.
231*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
232*627f7eb2Smrg  AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
233*627f7eb2Smrg    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
234*627f7eb2Smrg#if HAVE_FLOATINGPOINT_H
235*627f7eb2Smrg# include <floatingpoint.h>
236*627f7eb2Smrg#endif /* HAVE_FLOATINGPOINT_H */
237*627f7eb2Smrg#if HAVE_IEEEFP_H
238*627f7eb2Smrg# include <ieeefp.h>
239*627f7eb2Smrg#endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
240*627f7eb2Smrg    eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
241*627f7eb2Smrg  ])
242*627f7eb2Smrg  if test x"$libgfor_cv_have_fpsetmask" = xyes; then
243*627f7eb2Smrg    have_fpsetmask=yes
244*627f7eb2Smrg    AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
245*627f7eb2Smrg  fi
246*627f7eb2Smrg])
247*627f7eb2Smrg
248*627f7eb2Smrgdnl Check whether we have a mingw that provides a __mingw_snprintf function
249*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
250*627f7eb2Smrg  AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
251*627f7eb2Smrg    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
252*627f7eb2Smrg#include <stdio.h>
253*627f7eb2Smrgextern int __mingw_snprintf (char *, size_t, const char *, ...);
254*627f7eb2Smrg]],[[
255*627f7eb2Smrg__mingw_snprintf (NULL, 0, "%d\n", 1);
256*627f7eb2Smrg]])],
257*627f7eb2Smrg    eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
258*627f7eb2Smrg  ])
259*627f7eb2Smrg  if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
260*627f7eb2Smrg    AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
261*627f7eb2Smrg  fi
262*627f7eb2Smrg])
263*627f7eb2Smrg
264*627f7eb2Smrgdnl Check whether we have a __float128 type
265*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
266*627f7eb2Smrg  LIBQUADSPEC=
267*627f7eb2Smrg
268*627f7eb2Smrg  if test "x$enable_libquadmath_support" != xno; then
269*627f7eb2Smrg
270*627f7eb2Smrg  AC_CACHE_CHECK([whether we have a usable __float128 type],
271*627f7eb2Smrg                 libgfor_cv_have_float128, [
272*627f7eb2Smrg   GCC_TRY_COMPILE_OR_LINK([
273*627f7eb2Smrg    typedef _Complex float __attribute__((mode(TC))) __complex128;
274*627f7eb2Smrg
275*627f7eb2Smrg    __float128 foo (__float128 x)
276*627f7eb2Smrg    {
277*627f7eb2Smrg
278*627f7eb2Smrg     __complex128 z1, z2;
279*627f7eb2Smrg
280*627f7eb2Smrg     z1 = x;
281*627f7eb2Smrg     z2 = x / 7.Q;
282*627f7eb2Smrg     z2 /= z1;
283*627f7eb2Smrg
284*627f7eb2Smrg     return (__float128) z2;
285*627f7eb2Smrg    }
286*627f7eb2Smrg
287*627f7eb2Smrg    __float128 bar (__float128 x)
288*627f7eb2Smrg    {
289*627f7eb2Smrg      return x * __builtin_huge_valq ();
290*627f7eb2Smrg    }
291*627f7eb2Smrg  ],[
292*627f7eb2Smrg    foo (1.2Q);
293*627f7eb2Smrg    bar (1.2Q);
294*627f7eb2Smrg  ],[
295*627f7eb2Smrg    libgfor_cv_have_float128=yes
296*627f7eb2Smrg  ],[
297*627f7eb2Smrg    libgfor_cv_have_float128=no
298*627f7eb2Smrg])])
299*627f7eb2Smrg
300*627f7eb2Smrg  if test "x$libgfor_cv_have_float128" = xyes; then
301*627f7eb2Smrg    AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
302*627f7eb2Smrg
303*627f7eb2Smrg    dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
304*627f7eb2Smrg    dnl
305*627f7eb2Smrg    dnl Turn warnings into error to avoid testsuite breakage.  So enable
306*627f7eb2Smrg    dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
307*627f7eb2Smrg    dnl it off again.  As a workaround, save and restore werror flag like
308*627f7eb2Smrg    dnl AC_PATH_XTRA.
309*627f7eb2Smrg    dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
310*627f7eb2Smrg    ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
311*627f7eb2Smrg    AC_CACHE_CHECK([whether --as-needed/-z ignore works],
312*627f7eb2Smrg      [libgfor_cv_have_as_needed],
313*627f7eb2Smrg      [
314*627f7eb2Smrg      # Test for native Solaris options first.
315*627f7eb2Smrg      # No whitespace after -z to pass it through -Wl.
316*627f7eb2Smrg      libgfor_cv_as_needed_option="-zignore"
317*627f7eb2Smrg      libgfor_cv_no_as_needed_option="-zrecord"
318*627f7eb2Smrg      save_LDFLAGS="$LDFLAGS"
319*627f7eb2Smrg      LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
320*627f7eb2Smrg      libgfor_cv_have_as_needed=no
321*627f7eb2Smrg      AC_LANG_WERROR
322*627f7eb2Smrg      AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
323*627f7eb2Smrg		     [libgfor_cv_have_as_needed=yes],
324*627f7eb2Smrg		     [libgfor_cv_have_as_needed=no])
325*627f7eb2Smrg      LDFLAGS="$save_LDFLAGS"
326*627f7eb2Smrg      if test "x$libgfor_cv_have_as_needed" = xno; then
327*627f7eb2Smrg	libgfor_cv_as_needed_option="--as-needed"
328*627f7eb2Smrg	libgfor_cv_no_as_needed_option="--no-as-needed"
329*627f7eb2Smrg	save_LDFLAGS="$LDFLAGS"
330*627f7eb2Smrg	LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
331*627f7eb2Smrg	libgfor_cv_have_as_needed=no
332*627f7eb2Smrg	AC_LANG_WERROR
333*627f7eb2Smrg	AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
334*627f7eb2Smrg		       [libgfor_cv_have_as_needed=yes],
335*627f7eb2Smrg		       [libgfor_cv_have_as_needed=no])
336*627f7eb2Smrg	LDFLAGS="$save_LDFLAGS"
337*627f7eb2Smrg      fi
338*627f7eb2Smrg      ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
339*627f7eb2Smrg    ])
340*627f7eb2Smrg
341*627f7eb2Smrg    dnl For static libgfortran linkage, depend on libquadmath only if needed.
342*627f7eb2Smrg    if test "x$libgfor_cv_have_as_needed" = xyes; then
343*627f7eb2Smrg      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
344*627f7eb2Smrg    else
345*627f7eb2Smrg      LIBQUADSPEC="-lquadmath"
346*627f7eb2Smrg    fi
347*627f7eb2Smrg    if test -f ../libquadmath/libquadmath.la; then
348*627f7eb2Smrg      LIBQUADLIB=../libquadmath/libquadmath.la
349*627f7eb2Smrg      LIBQUADLIB_DEP=../libquadmath/libquadmath.la
350*627f7eb2Smrg      LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
351*627f7eb2Smrg    else
352*627f7eb2Smrg      LIBQUADLIB="-lquadmath"
353*627f7eb2Smrg      LIBQUADLIB_DEP=
354*627f7eb2Smrg      LIBQUADINCLUDE=
355*627f7eb2Smrg    fi
356*627f7eb2Smrg  fi
357*627f7eb2Smrg  else
358*627f7eb2Smrg    # for --disable-quadmath
359*627f7eb2Smrg    LIBQUADLIB=
360*627f7eb2Smrg    LIBQUADLIB_DEP=
361*627f7eb2Smrg    LIBQUADINCLUDE=
362*627f7eb2Smrg  fi
363*627f7eb2Smrg
364*627f7eb2Smrg  dnl For the spec file
365*627f7eb2Smrg  AC_SUBST(LIBQUADSPEC)
366*627f7eb2Smrg  AC_SUBST(LIBQUADLIB)
367*627f7eb2Smrg  AC_SUBST(LIBQUADLIB_DEP)
368*627f7eb2Smrg  AC_SUBST(LIBQUADINCLUDE)
369*627f7eb2Smrg
370*627f7eb2Smrg  dnl We need a conditional for the Makefile
371*627f7eb2Smrg  AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
372*627f7eb2Smrg])
373*627f7eb2Smrg
374*627f7eb2Smrg
375*627f7eb2Smrgdnl Check whether we have strerror_r
376*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
377*627f7eb2Smrg  dnl Check for three-argument POSIX version of strerror_r
378*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
379*627f7eb2Smrg  CFLAGS="-Wimplicit-function-declaration -Werror"
380*627f7eb2Smrg  AC_TRY_COMPILE([#define _GNU_SOURCE 1
381*627f7eb2Smrg	     	  #include <string.h>
382*627f7eb2Smrg		  #include <locale.h>],
383*627f7eb2Smrg		  [char s[128]; strerror_r(5, s, 128);],
384*627f7eb2Smrg		  AC_DEFINE(HAVE_STRERROR_R, 1,
385*627f7eb2Smrg		  [Define if strerror_r is available in <string.h>.]),)
386*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
387*627f7eb2Smrg
388*627f7eb2Smrg  dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
389*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
390*627f7eb2Smrg  CFLAGS="-Wimplicit-function-declaration -Werror"
391*627f7eb2Smrg  AC_TRY_COMPILE([#define _GNU_SOURCE 1
392*627f7eb2Smrg	     	  #include <string.h>
393*627f7eb2Smrg		  #include <locale.h>],
394*627f7eb2Smrg		  [char s[128]; strerror_r(5, s);],
395*627f7eb2Smrg		  AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
396*627f7eb2Smrg		  [Define if strerror_r takes two arguments and is available in <string.h>.]),)
397*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
398*627f7eb2Smrg])
399*627f7eb2Smrg
400*627f7eb2Smrgdnl Check for AVX
401*627f7eb2Smrg
402*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_AVX], [
403*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
404*627f7eb2Smrg  CFLAGS="-O2 -mavx"
405*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
406*627f7eb2Smrg  void _mm256_zeroall (void)
407*627f7eb2Smrg        {
408*627f7eb2Smrg           __builtin_ia32_vzeroall ();
409*627f7eb2Smrg        }]], [[]])],
410*627f7eb2Smrg	AC_DEFINE(HAVE_AVX, 1,
411*627f7eb2Smrg	[Define if AVX instructions can be compiled.]),
412*627f7eb2Smrg	[])
413*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
414*627f7eb2Smrg])
415*627f7eb2Smrg
416*627f7eb2Smrgdnl Check for AVX2
417*627f7eb2Smrg
418*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_AVX2], [
419*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
420*627f7eb2Smrg  CFLAGS="-O2 -mavx2"
421*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
422*627f7eb2Smrg  typedef long long __v4di __attribute__ ((__vector_size__ (32)));
423*627f7eb2Smrg	__v4di
424*627f7eb2Smrg	mm256_is32_andnotsi256  (__v4di __X, __v4di __Y)
425*627f7eb2Smrg        {
426*627f7eb2Smrg	   return __builtin_ia32_andnotsi256 (__X, __Y);
427*627f7eb2Smrg        }]], [[]])],
428*627f7eb2Smrg	AC_DEFINE(HAVE_AVX2, 1,
429*627f7eb2Smrg	[Define if AVX2 instructions can be compiled.]),
430*627f7eb2Smrg	[])
431*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
432*627f7eb2Smrg])
433*627f7eb2Smrg
434*627f7eb2Smrgdnl Check for AVX512f
435*627f7eb2Smrg
436*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_AVX512F], [
437*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
438*627f7eb2Smrg  CFLAGS="-O2 -mavx512f"
439*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
440*627f7eb2Smrg	typedef double __m512d __attribute__ ((__vector_size__ (64)));
441*627f7eb2Smrg	__m512d _mm512_add (__m512d a)
442*627f7eb2Smrg	{
443*627f7eb2Smrg	  __m512d b = __builtin_ia32_addpd512_mask (a, a, a, 1, 4);
444*627f7eb2Smrg	  /* For -m64/-mx32 also verify that code will work even if
445*627f7eb2Smrg	     the target uses call saved zmm16+ and needs to emit
446*627f7eb2Smrg	     unwind info for them (e.g. on mingw).  See PR79127.  */
447*627f7eb2Smrg#ifdef __x86_64__
448*627f7eb2Smrg	  asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19");
449*627f7eb2Smrg#endif
450*627f7eb2Smrg	  return b;
451*627f7eb2Smrg        }]], [[]])],
452*627f7eb2Smrg	AC_DEFINE(HAVE_AVX512F, 1,
453*627f7eb2Smrg	[Define if AVX512f instructions can be compiled.]),
454*627f7eb2Smrg	[])
455*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
456*627f7eb2Smrg])
457*627f7eb2Smrg
458*627f7eb2Smrgdnl Check for FMA3
459*627f7eb2Smrgdnl
460*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_FMA3], [
461*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
462*627f7eb2Smrg  CFLAGS="-O2 -mfma -mno-fma4"
463*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
464*627f7eb2Smrg        typedef float __m128 __attribute__ ((__vector_size__ (16)));
465*627f7eb2Smrg	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
466*627f7eb2Smrg	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
467*627f7eb2Smrg	{
468*627f7eb2Smrg	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
469*627f7eb2Smrg						     (__v4sf)__B,
470*627f7eb2Smrg						     (__v4sf)__C);
471*627f7eb2Smrg        }]], [[]])],
472*627f7eb2Smrg	AC_DEFINE(HAVE_FMA3, 1,
473*627f7eb2Smrg	[Define if FMA3 instructions can be compiled.]),
474*627f7eb2Smrg	[])
475*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
476*627f7eb2Smrg])
477*627f7eb2Smrg
478*627f7eb2Smrgdnl Check for FMA4
479*627f7eb2Smrgdnl
480*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_FMA4], [
481*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
482*627f7eb2Smrg  CFLAGS="-O2 -mfma4 -mno-fma"
483*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
484*627f7eb2Smrg        typedef float __m128 __attribute__ ((__vector_size__ (16)));
485*627f7eb2Smrg	typedef float __v4sf __attribute__ ((__vector_size__ (16)));
486*627f7eb2Smrg	__m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
487*627f7eb2Smrg	{
488*627f7eb2Smrg	    return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
489*627f7eb2Smrg						     (__v4sf)__B,
490*627f7eb2Smrg						     (__v4sf)__C);
491*627f7eb2Smrg        }]], [[]])],
492*627f7eb2Smrg	AC_DEFINE(HAVE_FMA4, 1,
493*627f7eb2Smrg	[Define if FMA4 instructions can be compiled.]),
494*627f7eb2Smrg	[])
495*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
496*627f7eb2Smrg])
497*627f7eb2Smrg
498*627f7eb2Smrgdnl Check for -mprefer-avx128
499*627f7eb2Smrgdnl This also defines an automake conditional.
500*627f7eb2SmrgAC_DEFUN([LIBGFOR_CHECK_AVX128], [
501*627f7eb2Smrg  ac_save_CFLAGS="$CFLAGS"
502*627f7eb2Smrg  CFLAGS="-O2 -mavx -mprefer-avx128"
503*627f7eb2Smrg  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
504*627f7eb2Smrg        void foo()
505*627f7eb2Smrg	{
506*627f7eb2Smrg        }]], [[]])],
507*627f7eb2Smrg	AC_DEFINE(HAVE_AVX128, 1,
508*627f7eb2Smrg	[Define if -mprefer-avx128 is supported.])
509*627f7eb2Smrg	AM_CONDITIONAL([HAVE_AVX128],true),
510*627f7eb2Smrg	[AM_CONDITIONAL([HAVE_AVX128],false)])
511*627f7eb2Smrg  CFLAGS="$ac_save_CFLAGS"
512*627f7eb2Smrg])
513