]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/acinclude.m4
Move gthr to toplevel libgcc
[thirdparty/gcc.git] / libgfortran / acinclude.m4
CommitLineData
4c82c0dd 1m4_include(../config/acx.m4)
2m4_include(../config/no-executables.m4)
3
2e4ef4e4 4dnl Check that we have a working GNU Fortran compiler
5AC_DEFUN([LIBGFOR_WORKING_GFORTRAN], [
6AC_MSG_CHECKING([whether the GNU Fortran compiler is working])
7AC_LANG_PUSH([Fortran])
8AC_COMPILE_IFELSE([[
9 program foo
10 real, parameter :: bar = sin (12.34 / 2.5)
11 end program foo]],
12 [AC_MSG_RESULT([yes])],
13 [AC_MSG_RESULT([no])
14 AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
15 ])
16AC_LANG_POP([Fortran])
17])
18
19
4ee9c684 20sinclude(../libtool.m4)
21dnl The lines below arrange for aclocal not to bring an installed
22dnl libtool.m4 into aclocal.m4, while still arranging for automake to
23dnl add a definition of LIBTOOL to Makefile.in.
24ifelse(,,,[AC_SUBST(LIBTOOL)
25AC_DEFUN([AM_PROG_LIBTOOL])
26AC_DEFUN([AC_LIBTOOL_DLOPEN])
27AC_DEFUN([AC_PROG_LD])
28])
29
7b6cb5bd 30dnl Check whether the target supports hidden visibility.
31AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
32 AC_CACHE_CHECK([whether the target supports hidden visibility],
6992582a 33 libgfor_cv_have_attribute_visibility, [
7b6cb5bd 34 save_CFLAGS="$CFLAGS"
35 CFLAGS="$CFLAGS -Werror"
b9a8e1d9 36 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((visibility("hidden"))) foo(void) { }]], [])],
37 libgfor_cv_have_attribute_visibility=yes,
38 libgfor_cv_have_attribute_visibility=no)
7b6cb5bd 39 CFLAGS="$save_CFLAGS"])
6992582a 40 if test $libgfor_cv_have_attribute_visibility = yes; then
7b6cb5bd 41 AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
42 [Define to 1 if the target supports __attribute__((visibility(...))).])
43 fi])
44
45dnl Check whether the target supports dllexport
46AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT], [
47 AC_CACHE_CHECK([whether the target supports dllexport],
6992582a 48 libgfor_cv_have_attribute_dllexport, [
7b6cb5bd 49 save_CFLAGS="$CFLAGS"
50 CFLAGS="$CFLAGS -Werror"
b9a8e1d9 51 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void __attribute__((dllexport)) foo(void) { }]], [])],
52 libgfor_cv_have_attribute_dllexport=yes,
53 libgfor_cv_have_attribute_dllexport=no)
7b6cb5bd 54 CFLAGS="$save_CFLAGS"])
6992582a 55 if test $libgfor_cv_have_attribute_dllexport = yes; then
7b6cb5bd 56 AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
57 [Define to 1 if the target supports __attribute__((dllexport)).])
58 fi])
59
60dnl Check whether the target supports symbol aliases.
61AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_ALIAS], [
62 AC_CACHE_CHECK([whether the target supports symbol aliases],
6992582a 63 libgfor_cv_have_attribute_alias, [
b9a8e1d9 64 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
7b6cb5bd 65void foo(void) { }
b9a8e1d9 66extern void bar(void) __attribute__((alias("foo")));]],
67 [[bar();]])], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
6992582a 68 if test $libgfor_cv_have_attribute_alias = yes; then
7b6cb5bd 69 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
70 [Define to 1 if the target supports __attribute__((alias(...))).])
71 fi])
1dc95e51 72
60c514ba 73dnl Check whether the target supports __sync_fetch_and_add.
74AC_DEFUN([LIBGFOR_CHECK_SYNC_FETCH_AND_ADD], [
75 AC_CACHE_CHECK([whether the target supports __sync_fetch_and_add],
6992582a 76 libgfor_cv_have_sync_fetch_and_add, [
b9a8e1d9 77 AC_LINK_IFELSE([AC_LANG_PROGRAM([[int foovar = 0;]], [[
60c514ba 78if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
b9a8e1d9 79if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);]])],
6992582a 80 libgfor_cv_have_sync_fetch_and_add=yes, libgfor_cv_have_sync_fetch_and_add=no)])
81 if test $libgfor_cv_have_sync_fetch_and_add = yes; then
60c514ba 82 AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
83 [Define to 1 if the target supports __sync_fetch_and_add])
84 fi])
85
60c514ba 86dnl Check for pragma weak.
0a207fde 87AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
60c514ba 88 AC_CACHE_CHECK([whether pragma weak works],
6992582a 89 libgfor_cv_have_pragma_weak, [
60c514ba 90 gfor_save_CFLAGS="$CFLAGS"
91 CFLAGS="$CFLAGS -Wunknown-pragmas"
b9a8e1d9 92 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
93void foo (void);
94#pragma weak foo
95]], [[if (foo) foo ();]])],
96 libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
6992582a 97 if test $libgfor_cv_have_pragma_weak = yes; then
0a207fde 98 AC_DEFINE(SUPPORTS_WEAK, 1,
60c514ba 99 [Define to 1 if the target supports #pragma weak])
0a207fde 100 fi
101 case "$host" in
d90d0997 102 *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | alpha*-dec-osf* )
0a207fde 103 AC_DEFINE(GTHREAD_USE_WEAK, 0,
104 [Define to 0 if the target shouldn't use #pragma weak])
105 ;;
106 esac])
60c514ba 107
1dc95e51 108dnl Check whether target can unlink a file still open.
109AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
110 AC_CACHE_CHECK([whether the target can unlink an open file],
6992582a 111 libgfor_cv_have_unlink_open_file, [
b9a8e1d9 112 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1dc95e51 113#include <errno.h>
114#include <fcntl.h>
115#include <unistd.h>
116#include <sys/stat.h>
117
118int main ()
119{
120 int fd;
121
122 fd = open ("testfile", O_RDWR | O_CREAT, S_IWRITE | S_IREAD);
123 if (fd <= 0)
124 return 0;
125 if (unlink ("testfile") == -1)
126 return 1;
127 write (fd, "This is a test\n", 15);
128 close (fd);
129
130 if (open ("testfile", O_RDONLY, S_IWRITE | S_IREAD) == -1 && errno == ENOENT)
131 return 0;
132 else
133 return 1;
b9a8e1d9 134}]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
1dc95e51 135case "${target}" in
6992582a 136 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
137 *) libgfor_cv_have_unlink_open_file=yes;;
1dc95e51 138esac])])
6992582a 139if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
1dc95e51 140 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
141fi])
cf55c3cf 142
143dnl Check whether CRLF is the line terminator
144AC_DEFUN([LIBGFOR_CHECK_CRLF], [
145 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
6992582a 146 libgfor_cv_have_crlf, [
b9a8e1d9 147 AC_RUN_IFELSE([AC_LANG_SOURCE([[
cf55c3cf 148/* This test program should exit with status 0 if system uses a CRLF as
149 line terminator, and status 1 otherwise.
150 Since it is used to check for mingw systems, and should return 0 in any
151 other case, in case of a failure we will not use CRLF. */
152#include <sys/stat.h>
153#include <stdlib.h>
154#include <fcntl.h>
155#include <stdio.h>
156
157int main ()
158{
159#ifndef O_BINARY
160 exit(1);
161#else
162 int fd, bytes;
163 char buff[5];
164
165 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
166 if (fd < 0)
167 exit(1);
168 if (write (fd, "\n", 1) < 0)
169 perror ("write");
170
171 close (fd);
172
173 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
174 exit(1);
175 bytes = read (fd, buff, 5);
176 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
177 exit(0);
178 else
179 exit(1);
180#endif
b9a8e1d9 181}]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
cf55c3cf 182case "${target}" in
6992582a 183 *mingw*) libgfor_cv_have_crlf=yes ;;
184 *) libgfor_cv_have_crlf=no;;
cf55c3cf 185esac])])
6992582a 186if test x"$libgfor_cv_have_crlf" = xyes; then
cf55c3cf 187 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
188fi])
839904a0 189
daad4fd5 190dnl Check whether the st_ino and st_dev stat fields taken together uniquely
191dnl identify the file within the system. This is should be true for POSIX
192dnl systems; it is known to be false on mingw32.
193AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
194 AC_CACHE_CHECK([whether the target stat is reliable],
6992582a 195 libgfor_cv_have_working_stat, [
b9a8e1d9 196 AC_RUN_IFELSE([AC_LANG_SOURCE([[
daad4fd5 197#include <stdio.h>
198#include <sys/types.h>
199#include <sys/stat.h>
200#include <unistd.h>
201
202int main ()
203{
204 FILE *f, *g;
205 struct stat st1, st2;
206
207 f = fopen ("foo", "w");
208 g = fopen ("bar", "w");
209 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
210 return 1;
211 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
212 return 1;
213 fclose(f);
214 fclose(g);
215 return 0;
b9a8e1d9 216}]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
daad4fd5 217case "${target}" in
6992582a 218 *mingw*) libgfor_cv_have_working_stat=no ;;
219 *) libgfor_cv_have_working_stat=yes;;
daad4fd5 220esac])])
6992582a 221if test x"$libgfor_cv_have_working_stat" = xyes; then
daad4fd5 222 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
223fi])
aaa798ba 224
225dnl Checks for fpsetmask function.
226AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
6992582a 227 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
b9a8e1d9 228 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
aaa798ba 229#if HAVE_FLOATINGPOINT_H
230# include <floatingpoint.h>
231#endif /* HAVE_FLOATINGPOINT_H */
232#if HAVE_IEEEFP_H
233# include <ieeefp.h>
b9a8e1d9 234#endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
6992582a 235 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
aaa798ba 236 ])
6992582a 237 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
b00fa2cf 238 have_fpsetmask=yes
aaa798ba 239 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
240 fi
241])
3b99ec70 242
243dnl Check whether we have a mingw that provides a __mingw_snprintf function
244AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
6992582a 245 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
b9a8e1d9 246 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
3b99ec70 247#include <stdio.h>
248extern int __mingw_snprintf (char *, size_t, const char *, ...);
b9a8e1d9 249]],[[
3b99ec70 250__mingw_snprintf (NULL, 0, "%d\n", 1);
b9a8e1d9 251]])],
6992582a 252 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
3b99ec70 253 ])
6992582a 254 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
3b99ec70 255 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
256 fi
257])
0dc2aff5 258
259dnl Check whether we have a broken powf implementation
260AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_POWF], [
261 AC_CACHE_CHECK([whether powf is broken], libgfor_cv_have_broken_powf, [
262case "${target}" in
263 hppa*64*-*-hpux*) libgfor_cv_have_broken_powf=yes ;;
264 *) libgfor_cv_have_broken_powf=no;;
265esac])
266 if test x"$libgfor_cv_have_broken_powf" = xyes; then
267 AC_DEFINE(HAVE_BROKEN_POWF, 1, [Define if powf is broken.])
268 fi
269])
87969c8c 270
271dnl Check whether we have a __float128 type
272AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
273 LIBQUADSPEC=
d9d975ae 274
275 if test "x$enable_libquadmath_support" != xno; then
276
87969c8c 277 AC_CACHE_CHECK([whether we have a usable __float128 type],
278 libgfor_cv_have_float128, [
9af9660c 279 GCC_TRY_COMPILE_OR_LINK([
280 typedef _Complex float __attribute__((mode(TC))) __complex128;
87969c8c 281
9af9660c 282 __float128 foo (__float128 x)
283 {
87969c8c 284
9af9660c 285 __complex128 z1, z2;
87969c8c 286
9af9660c 287 z1 = x;
288 z2 = x / 7.Q;
289 z2 /= z1;
290
291 return (__float128) z2;
292 }
293
294 __float128 bar (__float128 x)
295 {
296 return x * __builtin_huge_valq ();
297 }
298 ],[
299 foo (1.2Q);
300 bar (1.2Q);
301 ],[
302 libgfor_cv_have_float128=yes
303 ],[
304 libgfor_cv_have_float128=no
305])])
87969c8c 306
307 if test "x$libgfor_cv_have_float128" = xyes; then
308 AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
309
310 dnl Check whether -Wl,--as-needed is supported
311 dnl
312 dnl Turn warnings into error to avoid testsuite breakage. So enable
313 dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
314 dnl it off again. As a workaround, save and restore werror flag like
315 dnl AC_PATH_XTRA.
316 dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
317 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
318 AC_CACHE_CHECK([whether --as-needed works],
319 [libgfor_cv_have_as_needed],
320 [
321 save_LDFLAGS="$LDFLAGS"
322 LDFLAGS="$LDFLAGS -Wl,--as-needed -lm -Wl,--no-as-needed"
323 libgfor_cv_have_as_needed=no
324 AC_LANG_WERROR
325 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
326 [libgfor_cv_have_as_needed=yes],
327 [libgfor_cv_have_as_needed=no])
328 LDFLAGS="$save_LDFLAGS"
329 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
330 ])
331
332 dnl For static libgfortran linkage, depend on libquadmath only if needed.
333 if test "x$libgfor_cv_have_as_needed" = xyes; then
334 LIBQUADSPEC="%{static-libgfortran:--as-needed} -lquadmath %{static-libgfortran:--no-as-needed}"
335 else
336 LIBQUADSPEC="-lquadmath"
337 fi
338 if test -f ../libquadmath/libquadmath.la; then
339 LIBQUADLIB=../libquadmath/libquadmath.la
340 LIBQUADLIB_DEP=../libquadmath/libquadmath.la
341 LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
342 else
343 LIBQUADLIB="-lquadmath"
344 LIBQUADLIB_DEP=
345 LIBQUADINCLUDE=
346 fi
347 fi
d9d975ae 348 else
349 # for --disable-quadmath
350 LIBQUADLIB=
351 LIBQUADLIB_DEP=
352 LIBQUADINCLUDE=
353 fi
87969c8c 354
355 dnl For the spec file
356 AC_SUBST(LIBQUADSPEC)
357 AC_SUBST(LIBQUADLIB)
358 AC_SUBST(LIBQUADLIB_DEP)
359 AC_SUBST(LIBQUADINCLUDE)
360
361 dnl We need a conditional for the Makefile
362 AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
363])