]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/acinclude.m4
libgfortran.h (likely,unlikely): New makros.
[thirdparty/gcc.git] / libgfortran / acinclude.m4
CommitLineData
891c05b1
JJ
1m4_include(../config/acx.m4)
2m4_include(../config/no-executables.m4)
3
15e92535
FXC
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
6de9cd9a
DN
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
7d7b8bfe
RH
30dnl Check whether the target supports hidden visibility.
31AC_DEFUN([LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY], [
32 AC_CACHE_CHECK([whether the target supports hidden visibility],
6d26724a 33 libgfor_cv_have_attribute_visibility, [
7d7b8bfe
RH
34 save_CFLAGS="$CFLAGS"
35 CFLAGS="$CFLAGS -Werror"
36 AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
6d26724a
RW
37 [], libgfor_cv_have_attribute_visibility=yes,
38 libgfor_cv_have_attribute_visibility=no)
7d7b8bfe 39 CFLAGS="$save_CFLAGS"])
6d26724a 40 if test $libgfor_cv_have_attribute_visibility = yes; then
7d7b8bfe
RH
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],
6d26724a 48 libgfor_cv_have_attribute_dllexport, [
7d7b8bfe
RH
49 save_CFLAGS="$CFLAGS"
50 CFLAGS="$CFLAGS -Werror"
51 AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
6d26724a
RW
52 [], libgfor_cv_have_attribute_dllexport=yes,
53 libgfor_cv_have_attribute_dllexport=no)
7d7b8bfe 54 CFLAGS="$save_CFLAGS"])
6d26724a 55 if test $libgfor_cv_have_attribute_dllexport = yes; then
7d7b8bfe
RH
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],
6d26724a 63 libgfor_cv_have_attribute_alias, [
7d7b8bfe 64 AC_TRY_LINK([
7d7b8bfe 65void foo(void) { }
16a314a9 66extern void bar(void) __attribute__((alias("foo")));],
6d26724a
RW
67 [bar();], libgfor_cv_have_attribute_alias=yes, libgfor_cv_have_attribute_alias=no)])
68 if test $libgfor_cv_have_attribute_alias = yes; then
7d7b8bfe
RH
69 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
70 [Define to 1 if the target supports __attribute__((alias(...))).])
71 fi])
10c682a0 72
5e805e44
JJ
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],
6d26724a 76 libgfor_cv_have_sync_fetch_and_add, [
5e805e44
JJ
77 AC_TRY_LINK([int foovar = 0;], [
78if (foovar <= 0) return __sync_fetch_and_add (&foovar, 1);
79if (foovar > 10) return __sync_add_and_fetch (&foovar, -1);],
6d26724a
RW
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
5e805e44
JJ
82 AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD, 1,
83 [Define to 1 if the target supports __sync_fetch_and_add])
84 fi])
85
86dnl Check if threads are supported.
87AC_DEFUN([LIBGFOR_CHECK_GTHR_DEFAULT], [
88 AC_CACHE_CHECK([configured target thread model],
10465436
RW
89 libgfor_cv_target_thread_file, [
90libgfor_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`])
5e805e44 91
10465436 92 if test $libgfor_cv_target_thread_file != single; then
5e805e44
JJ
93 AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
94 [Define if the compiler has a thread header that is non single.])
95 fi])
96
97dnl Check for pragma weak.
e669bd2b 98AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
5e805e44 99 AC_CACHE_CHECK([whether pragma weak works],
6d26724a 100 libgfor_cv_have_pragma_weak, [
5e805e44
JJ
101 gfor_save_CFLAGS="$CFLAGS"
102 CFLAGS="$CFLAGS -Wunknown-pragmas"
103 AC_TRY_COMPILE([void foo (void);
104#pragma weak foo], [if (foo) foo ();],
6d26724a
RW
105 libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
106 if test $libgfor_cv_have_pragma_weak = yes; then
e669bd2b 107 AC_DEFINE(SUPPORTS_WEAK, 1,
5e805e44 108 [Define to 1 if the target supports #pragma weak])
e669bd2b
JJ
109 fi
110 case "$host" in
6e20eae9 111 *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
e669bd2b
JJ
112 AC_DEFINE(GTHREAD_USE_WEAK, 0,
113 [Define to 0 if the target shouldn't use #pragma weak])
114 ;;
115 esac])
5e805e44 116
10c682a0
FXC
117dnl Check whether target can unlink a file still open.
118AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
119 AC_CACHE_CHECK([whether the target can unlink an open file],
6d26724a 120 libgfor_cv_have_unlink_open_file, [
10c682a0
FXC
121 AC_TRY_RUN([
122#include <errno.h>
123#include <fcntl.h>
124#include <unistd.h>
125#include <sys/stat.h>
126
127int main ()
128{
129 int fd;
130
131 fd = open ("testfile", O_RDWR | O_CREAT, S_IWRITE | S_IREAD);
132 if (fd <= 0)
133 return 0;
134 if (unlink ("testfile") == -1)
135 return 1;
136 write (fd, "This is a test\n", 15);
137 close (fd);
138
139 if (open ("testfile", O_RDONLY, S_IWRITE | S_IREAD) == -1 && errno == ENOENT)
140 return 0;
141 else
142 return 1;
6d26724a 143}], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
10c682a0 144case "${target}" in
6d26724a
RW
145 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
146 *) libgfor_cv_have_unlink_open_file=yes;;
10c682a0 147esac])])
6d26724a 148if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
10c682a0
FXC
149 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
150fi])
3c127520
FXC
151
152dnl Check whether CRLF is the line terminator
153AC_DEFUN([LIBGFOR_CHECK_CRLF], [
154 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
6d26724a 155 libgfor_cv_have_crlf, [
3c127520
FXC
156 AC_TRY_RUN([
157/* This test program should exit with status 0 if system uses a CRLF as
158 line terminator, and status 1 otherwise.
159 Since it is used to check for mingw systems, and should return 0 in any
160 other case, in case of a failure we will not use CRLF. */
161#include <sys/stat.h>
162#include <stdlib.h>
163#include <fcntl.h>
164#include <stdio.h>
165
166int main ()
167{
168#ifndef O_BINARY
169 exit(1);
170#else
171 int fd, bytes;
172 char buff[5];
173
174 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
175 if (fd < 0)
176 exit(1);
177 if (write (fd, "\n", 1) < 0)
178 perror ("write");
179
180 close (fd);
181
182 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
183 exit(1);
184 bytes = read (fd, buff, 5);
185 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
186 exit(0);
187 else
188 exit(1);
189#endif
6d26724a 190}], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
3c127520 191case "${target}" in
6d26724a
RW
192 *mingw*) libgfor_cv_have_crlf=yes ;;
193 *) libgfor_cv_have_crlf=no;;
3c127520 194esac])])
6d26724a 195if test x"$libgfor_cv_have_crlf" = xyes; then
3c127520
FXC
196 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
197fi])
118ea208
SE
198
199dnl Check whether isfinite is broken.
200dnl The most common problem is that it does not work on long doubles.
201AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISFINITE], [
202 AC_CACHE_CHECK([whether isfinite is broken],
6d26724a 203 libgfor_cv_have_broken_isfinite, [
118ea208
SE
204 libgfor_check_for_broken_isfinite_save_LIBS=$LIBS
205 LIBS="$LIBS -lm"
206 AC_TRY_RUN([
118ea208 207#include <math.h>
118ea208
SE
208#include <float.h>
209int main ()
210{
211#ifdef isfinite
212#ifdef LDBL_MAX
213 if (!isfinite(LDBL_MAX)) return 1;
214#endif
215#ifdef DBL_MAX
216 if (!isfinite(DBL_MAX)) return 1;
217#endif
218#endif
219return 0;
6d26724a 220}], libgfor_cv_have_broken_isfinite=no, libgfor_cv_have_broken_isfinite=yes, [
118ea208 221case "${target}" in
6d26724a
RW
222 hppa*-*-hpux*) libgfor_cv_have_broken_isfinite=yes ;;
223 *) libgfor_cv_have_broken_isfinite=no ;;
118ea208
SE
224esac])]
225 LIBS=$libgfor_check_for_broken_isfinite_save_LIBS)
6d26724a 226if test x"$libgfor_cv_have_broken_isfinite" = xyes; then
118ea208
SE
227 AC_DEFINE(HAVE_BROKEN_ISFINITE, 1, [Define if isfinite is broken.])
228fi])
229
230dnl Check whether isnan is broken.
231dnl The most common problem is that it does not work on long doubles.
232AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_ISNAN], [
233 AC_CACHE_CHECK([whether isnan is broken],
6d26724a 234 libgfor_cv_have_broken_isnan, [
118ea208
SE
235 libgfor_check_for_broken_isnan_save_LIBS=$LIBS
236 LIBS="$LIBS -lm"
237 AC_TRY_RUN([
118ea208 238#include <math.h>
118ea208
SE
239#include <float.h>
240int main ()
241{
242#ifdef isnan
243#ifdef LDBL_MAX
244 {
245 long double x;
246 x = __builtin_nanl ("");
247 if (!isnan(x)) return 1;
248 if (isnan(LDBL_MAX)) return 1;
249#ifdef NAN
250 x = (long double) NAN;
251 if (!isnan(x)) return 1;
252#endif
253 }
254#endif
255#ifdef DBL_MAX
256 {
257 double y;
258 y = __builtin_nan ("");
259 if (!isnan(y)) return 1;
260 if (isnan(DBL_MAX)) return 1;
261#ifdef NAN
262 y = (double) NAN;
263 if (!isnan(y)) return 1;
264#endif
265 }
266#endif
267#endif
268return 0;
6d26724a 269}], libgfor_cv_have_broken_isnan=no, libgfor_cv_have_broken_isnan=yes, [
118ea208 270case "${target}" in
6d26724a
RW
271 hppa*-*-hpux*) libgfor_cv_have_broken_isnan=yes ;;
272 *) libgfor_cv_have_broken_isnan=no ;;
118ea208
SE
273esac])]
274 LIBS=$libgfor_check_for_broken_isnan_save_LIBS)
6d26724a 275if test x"$libgfor_cv_have_broken_isnan" = xyes; then
118ea208
SE
276 AC_DEFINE(HAVE_BROKEN_ISNAN, 1, [Define if isnan is broken.])
277fi])
278
279dnl Check whether fpclassify is broken.
280dnl The most common problem is that it does not work on long doubles.
281AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY], [
282 AC_CACHE_CHECK([whether fpclassify is broken],
6d26724a 283 libgfor_cv_have_broken_fpclassify, [
118ea208
SE
284 libgfor_check_for_broken_fpclassify_save_LIBS=$LIBS
285 LIBS="$LIBS -lm"
286 AC_TRY_RUN([
118ea208 287#include <math.h>
118ea208
SE
288#include <float.h>
289int main ()
290{
291#ifdef fpclassify
292#ifdef LDBL_MAX
293 if (fpclassify(LDBL_MAX) == FP_NAN
294 || fpclassify(LDBL_MAX) == FP_INFINITE) return 1;
295#endif
296#ifdef DBL_MAX
297 if (fpclassify(DBL_MAX) == FP_NAN
298 || fpclassify(DBL_MAX) == FP_INFINITE) return 1;
299#endif
300#endif
301return 0;
6d26724a 302}], libgfor_cv_have_broken_fpclassify=no, libgfor_cv_have_broken_fpclassify=yes, [
118ea208 303case "${target}" in
6d26724a
RW
304 hppa*-*-hpux*) libgfor_cv_have_broken_fpclassify=yes ;;
305 *) libgfor_cv_have_broken_fpclassify=no ;;
118ea208
SE
306esac])]
307 LIBS=$libgfor_check_for_broken_fpclassify_save_LIBS)
6d26724a 308if test x"$libgfor_cv_have_broken_fpclassify" = xyes; then
118ea208
SE
309 AC_DEFINE(HAVE_BROKEN_FPCLASSIFY, 1, [Define if fpclassify is broken.])
310fi])
ad238e4f
FXC
311
312dnl Check whether the st_ino and st_dev stat fields taken together uniquely
313dnl identify the file within the system. This is should be true for POSIX
314dnl systems; it is known to be false on mingw32.
315AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
316 AC_CACHE_CHECK([whether the target stat is reliable],
6d26724a 317 libgfor_cv_have_working_stat, [
ad238e4f
FXC
318 AC_TRY_RUN([
319#include <stdio.h>
320#include <sys/types.h>
321#include <sys/stat.h>
322#include <unistd.h>
323
324int main ()
325{
326 FILE *f, *g;
327 struct stat st1, st2;
328
329 f = fopen ("foo", "w");
330 g = fopen ("bar", "w");
331 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
332 return 1;
333 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
334 return 1;
335 fclose(f);
336 fclose(g);
337 return 0;
6d26724a 338}], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
ad238e4f 339case "${target}" in
6d26724a
RW
340 *mingw*) libgfor_cv_have_working_stat=no ;;
341 *) libgfor_cv_have_working_stat=yes;;
ad238e4f 342esac])])
6d26724a 343if test x"$libgfor_cv_have_working_stat" = xyes; then
ad238e4f
FXC
344 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
345fi])
3b14f664
FXC
346
347dnl Checks for fpsetmask function.
348AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
6d26724a 349 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
3b14f664
FXC
350 AC_TRY_LINK([
351#if HAVE_FLOATINGPOINT_H
352# include <floatingpoint.h>
353#endif /* HAVE_FLOATINGPOINT_H */
354#if HAVE_IEEEFP_H
355# include <ieeefp.h>
356#endif /* HAVE_IEEEFP_H */],[fpsetmask(0);],
6d26724a 357 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
3b14f664 358 ])
6d26724a 359 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
3b14f664
FXC
360 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
361 fi
362])
db8092dc
FXC
363
364dnl Check whether we have a mingw that provides a __mingw_snprintf function
365AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
6d26724a 366 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
db8092dc
FXC
367 AC_TRY_LINK([
368#include <stdio.h>
369extern int __mingw_snprintf (char *, size_t, const char *, ...);
370],[
371__mingw_snprintf (NULL, 0, "%d\n", 1);
372],
6d26724a 373 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
db8092dc 374 ])
6d26724a 375 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
db8092dc
FXC
376 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
377 fi
378])