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