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