* tree-outof-ssa.h (ssaexpand): Add partitions_for_undefined_values.
[official-gcc.git] / libgfortran / acinclude.m4
blob90df4eea7b763f56d4910709b5525bc361786740
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])
10 AC_COMPILE_IFELSE([[
11       program foo
12       real, parameter :: bar = sin (12.34 / 2.5)
13       end program foo]],
14     [AC_MSG_RESULT([yes])],
15     [AC_MSG_RESULT([no])
16      AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
17     ])
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, [
36   save_CFLAGS="$CFLAGS"
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(...))).])
45   fi])
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([[
52 void foo(void) { }
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(...))).])
58   fi])
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])
71   fi])
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([[
80 void foo (void);
81 #pragma weak foo
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])
87   fi
88   case "$host" in
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])
92       ;;
93   esac])
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, [
99   save_CFLAGS="$CFLAGS"
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])
109   fi])
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([[
116 #include <errno.h>
117 #include <fcntl.h>
118 #include <unistd.h>
119 #include <sys/stat.h>
121 int main ()
123   int fd;
125   fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
126   if (fd <= 0)
127     return 0;
128   if (unlink ("testfile") == -1)
129     return 1;
130   write (fd, "This is a test\n", 15);
131   close (fd);
133   if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
134     return 0;
135   else
136     return 1;
137 }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
138 case "${target}" in
139   *mingw*) libgfor_cv_have_unlink_open_file=no ;;
140   *) libgfor_cv_have_unlink_open_file=yes;;
141 esac])])
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.])
144 fi])
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>
156 #include <stdlib.h>
157 #include <fcntl.h>
158 #include <stdio.h>
160 int main ()
162 #ifndef O_BINARY
163   exit(1);
164 #else
165   int fd, bytes;
166   char buff[5];
168   fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
169   if (fd < 0)
170     exit(1);
171   if (write (fd, "\n", 1) < 0)
172     perror ("write");
173   
174   close (fd);
175   
176   if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
177     exit(1);
178   bytes = read (fd, buff, 5);
179   if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
180     exit(0);
181   else
182     exit(1);
183 #endif
184 }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
185 case "${target}" in
186   *mingw*) libgfor_cv_have_crlf=yes ;;
187   *) libgfor_cv_have_crlf=no;;
188 esac])])
189 if test x"$libgfor_cv_have_crlf" = xyes; then
190   AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
191 fi])
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([[
200 #include <stdio.h>
201 #include <sys/types.h>
202 #include <sys/stat.h>
203 #include <unistd.h>
205 int main ()
207   FILE *f, *g;
208   struct stat st1, st2;
210   f = fopen ("foo", "w");
211   g = fopen ("bar", "w");
212   if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
213     return 1;
214   if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
215     return 1;
216   fclose(f);
217   fclose(g);
218   return 0;
219 }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
220 case "${target}" in
221   *mingw*) libgfor_cv_have_working_stat=no ;;
222   *) libgfor_cv_have_working_stat=yes;;
223 esac])])
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.])
226 fi])
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 */
235 #if HAVE_IEEEFP_H
236 # include <ieeefp.h>
237 #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
238     eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
239   ])
240   if test x"$libgfor_cv_have_fpsetmask" = xyes; then
241     have_fpsetmask=yes
242     AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
243   fi
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([[
250 #include <stdio.h>
251 extern int __mingw_snprintf (char *, size_t, const char *, ...);
252 ]],[[
253 __mingw_snprintf (NULL, 0, "%d\n", 1);
254 ]])],
255     eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
256   ])
257   if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
258     AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
259   fi
262 dnl Check whether we have a __float128 type
263 AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
264   LIBQUADSPEC=
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)
274     {
276      __complex128 z1, z2;
278      z1 = x;
279      z2 = x / 7.Q;
280      z2 /= z1;
282      return (__float128) z2;
283     }
285     __float128 bar (__float128 x)
286     {
287       return x * __builtin_huge_valq ();
288     }
289   ],[
290     foo (1.2Q);
291     bar (1.2Q);
292   ],[
293     libgfor_cv_have_float128=yes
294   ],[
295     libgfor_cv_have_float128=no
296 ])])
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
302     dnl 
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
306     dnl AC_PATH_XTRA.
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],
311       [
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
319       AC_LANG_WERROR
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
330         AC_LANG_WERROR
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"
335       fi
336       ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
337     ])
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}"
342     else
343       LIBQUADSPEC="-lquadmath"
344     fi
345     if test -f ../libquadmath/libquadmath.la; then
346       LIBQUADLIB=../libquadmath/libquadmath.la
347       LIBQUADLIB_DEP=../libquadmath/libquadmath.la
348       LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
349     else
350       LIBQUADLIB="-lquadmath"
351       LIBQUADLIB_DEP=
352       LIBQUADINCLUDE=
353     fi
354   fi
355   else
356     # for --disable-quadmath
357     LIBQUADLIB=
358     LIBQUADLIB_DEP=
359     LIBQUADINCLUDE=
360   fi
362   dnl For the spec file
363   AC_SUBST(LIBQUADSPEC)
364   AC_SUBST(LIBQUADLIB)
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
379                   #include <string.h>
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
390                   #include <string.h>
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"
398 dnl Check for AVX
400 AC_DEFUN([LIBGFOR_CHECK_AVX], [
401   ac_save_CFLAGS="$CFLAGS"
402   CFLAGS="-O2 -mavx"
403   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
404   void _mm256_zeroall (void)
405         {
406            __builtin_ia32_vzeroall ();
407         }]], [[]])],
408         AC_DEFINE(HAVE_AVX, 1,
409         [Define if AVX instructions can be compiled.]),
410         [])
411   CFLAGS="$ac_save_CFLAGS"
414 dnl Check for AVX2
416 AC_DEFUN([LIBGFOR_CHECK_AVX2], [
417   ac_save_CFLAGS="$CFLAGS"
418   CFLAGS="-O2 -mavx2"
419   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
420   typedef long long __v4di __attribute__ ((__vector_size__ (32)));
421         __v4di
422         mm256_is32_andnotsi256  (__v4di __X, __v4di __Y)
423         {
424            return __builtin_ia32_andnotsi256 (__X, __Y);
425         }]], [[]])],
426         AC_DEFINE(HAVE_AVX2, 1,
427         [Define if AVX2 instructions can be compiled.]),
428         [])
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)
440         {
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.  */
445 #ifdef __x86_64__
446           asm volatile ("" : : : "zmm16", "zmm17", "zmm18", "zmm19");
447 #endif
448           return b;
449         }]], [[]])],
450         AC_DEFINE(HAVE_AVX512F, 1,
451         [Define if AVX512f instructions can be compiled.]),
452         [])
453   CFLAGS="$ac_save_CFLAGS"
456 dnl Check for FMA3
458 AC_DEFUN([LIBGFOR_CHECK_FMA3], [
459   ac_save_CFLAGS="$CFLAGS"
460   CFLAGS="-O2 -mfma -mno-fma4"
461   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
462         typedef float __m128 __attribute__ ((__vector_size__ (16)));
463         typedef float __v4sf __attribute__ ((__vector_size__ (16)));
464         __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
465         {
466             return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
467                                                      (__v4sf)__B,
468                                                      (__v4sf)__C);
469         }]], [[]])],
470         AC_DEFINE(HAVE_FMA3, 1,
471         [Define if FMA3 instructions can be compiled.]),
472         [])
473   CFLAGS="$ac_save_CFLAGS"
476 dnl Check for FMA4
478 AC_DEFUN([LIBGFOR_CHECK_FMA4], [
479   ac_save_CFLAGS="$CFLAGS"
480   CFLAGS="-O2 -mfma4 -mno-fma"
481   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
482         typedef float __m128 __attribute__ ((__vector_size__ (16)));
483         typedef float __v4sf __attribute__ ((__vector_size__ (16)));
484         __m128 _mm_macc_ps(__m128 __A, __m128 __B, __m128 __C)
485         {
486             return (__m128) __builtin_ia32_vfmaddps ((__v4sf)__A,
487                                                      (__v4sf)__B,
488                                                      (__v4sf)__C);
489         }]], [[]])],
490         AC_DEFINE(HAVE_FMA4, 1,
491         [Define if FMA4 instructions can be compiled.]),
492         [])
493   CFLAGS="$ac_save_CFLAGS"
496 dnl Check for -mprefer-avx128
497 dnl This also defines an automake conditional.
498 AC_DEFUN([LIBGFOR_CHECK_AVX128], [
499   ac_save_CFLAGS="$CFLAGS"
500   CFLAGS="-O2 -mavx -mprefer-avx128"
501   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
502         void foo()
503         {
504         }]], [[]])],
505         AC_DEFINE(HAVE_AVX128, 1,
506         [Define if -mprefer-avx128 is supported.])
507         AM_CONDITIONAL([HAVE_AVX128],true),
508         [AM_CONDITIONAL([HAVE_AVX128],false)])
509   CFLAGS="$ac_save_CFLAGS"