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