]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/acinclude.m4
* acinclude.m4: Remove LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT.
[thirdparty/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 for pragma weak.
73 AC_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([[
79 void 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
94 dnl Check whether target can unlink a file still open.
95 AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
96 AC_CACHE_CHECK([whether the target can unlink an open file],
97 libgfor_cv_have_unlink_open_file, [
98 AC_RUN_IFELSE([AC_LANG_SOURCE([[
99 #include <errno.h>
100 #include <fcntl.h>
101 #include <unistd.h>
102 #include <sys/stat.h>
103
104 int main ()
105 {
106 int fd;
107
108 fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
109 if (fd <= 0)
110 return 0;
111 if (unlink ("testfile") == -1)
112 return 1;
113 write (fd, "This is a test\n", 15);
114 close (fd);
115
116 if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
117 return 0;
118 else
119 return 1;
120 }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
121 case "${target}" in
122 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
123 *) libgfor_cv_have_unlink_open_file=yes;;
124 esac])])
125 if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
126 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
127 fi])
128
129 dnl Check whether CRLF is the line terminator
130 AC_DEFUN([LIBGFOR_CHECK_CRLF], [
131 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
132 libgfor_cv_have_crlf, [
133 AC_RUN_IFELSE([AC_LANG_SOURCE([[
134 /* This test program should exit with status 0 if system uses a CRLF as
135 line terminator, and status 1 otherwise.
136 Since it is used to check for mingw systems, and should return 0 in any
137 other case, in case of a failure we will not use CRLF. */
138 #include <sys/stat.h>
139 #include <stdlib.h>
140 #include <fcntl.h>
141 #include <stdio.h>
142
143 int main ()
144 {
145 #ifndef O_BINARY
146 exit(1);
147 #else
148 int fd, bytes;
149 char buff[5];
150
151 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
152 if (fd < 0)
153 exit(1);
154 if (write (fd, "\n", 1) < 0)
155 perror ("write");
156
157 close (fd);
158
159 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
160 exit(1);
161 bytes = read (fd, buff, 5);
162 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
163 exit(0);
164 else
165 exit(1);
166 #endif
167 }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
168 case "${target}" in
169 *mingw*) libgfor_cv_have_crlf=yes ;;
170 *) libgfor_cv_have_crlf=no;;
171 esac])])
172 if test x"$libgfor_cv_have_crlf" = xyes; then
173 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
174 fi])
175
176 dnl Check whether the st_ino and st_dev stat fields taken together uniquely
177 dnl identify the file within the system. This is should be true for POSIX
178 dnl systems; it is known to be false on mingw32.
179 AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
180 AC_CACHE_CHECK([whether the target stat is reliable],
181 libgfor_cv_have_working_stat, [
182 AC_RUN_IFELSE([AC_LANG_SOURCE([[
183 #include <stdio.h>
184 #include <sys/types.h>
185 #include <sys/stat.h>
186 #include <unistd.h>
187
188 int main ()
189 {
190 FILE *f, *g;
191 struct stat st1, st2;
192
193 f = fopen ("foo", "w");
194 g = fopen ("bar", "w");
195 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
196 return 1;
197 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
198 return 1;
199 fclose(f);
200 fclose(g);
201 return 0;
202 }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
203 case "${target}" in
204 *mingw*) libgfor_cv_have_working_stat=no ;;
205 *) libgfor_cv_have_working_stat=yes;;
206 esac])])
207 if test x"$libgfor_cv_have_working_stat" = xyes; then
208 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
209 fi])
210
211 dnl Checks for fpsetmask function.
212 AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
213 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
214 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
215 #if HAVE_FLOATINGPOINT_H
216 # include <floatingpoint.h>
217 #endif /* HAVE_FLOATINGPOINT_H */
218 #if HAVE_IEEEFP_H
219 # include <ieeefp.h>
220 #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
221 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
222 ])
223 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
224 have_fpsetmask=yes
225 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
226 fi
227 ])
228
229 dnl Check whether we have a mingw that provides a __mingw_snprintf function
230 AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
231 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
232 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
233 #include <stdio.h>
234 extern int __mingw_snprintf (char *, size_t, const char *, ...);
235 ]],[[
236 __mingw_snprintf (NULL, 0, "%d\n", 1);
237 ]])],
238 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
239 ])
240 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
241 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
242 fi
243 ])
244
245 dnl Check whether we have a __float128 type
246 AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
247 LIBQUADSPEC=
248
249 if test "x$enable_libquadmath_support" != xno; then
250
251 AC_CACHE_CHECK([whether we have a usable __float128 type],
252 libgfor_cv_have_float128, [
253 GCC_TRY_COMPILE_OR_LINK([
254 typedef _Complex float __attribute__((mode(TC))) __complex128;
255
256 __float128 foo (__float128 x)
257 {
258
259 __complex128 z1, z2;
260
261 z1 = x;
262 z2 = x / 7.Q;
263 z2 /= z1;
264
265 return (__float128) z2;
266 }
267
268 __float128 bar (__float128 x)
269 {
270 return x * __builtin_huge_valq ();
271 }
272 ],[
273 foo (1.2Q);
274 bar (1.2Q);
275 ],[
276 libgfor_cv_have_float128=yes
277 ],[
278 libgfor_cv_have_float128=no
279 ])])
280
281 if test "x$libgfor_cv_have_float128" = xyes; then
282 AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
283
284 dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
285 dnl
286 dnl Turn warnings into error to avoid testsuite breakage. So enable
287 dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
288 dnl it off again. As a workaround, save and restore werror flag like
289 dnl AC_PATH_XTRA.
290 dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
291 ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
292 AC_CACHE_CHECK([whether --as-needed/-z ignore works],
293 [libgfor_cv_have_as_needed],
294 [
295 # Test for native Solaris options first.
296 # No whitespace after -z to pass it through -Wl.
297 libgfor_cv_as_needed_option="-zignore"
298 libgfor_cv_no_as_needed_option="-zrecord"
299 save_LDFLAGS="$LDFLAGS"
300 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
301 libgfor_cv_have_as_needed=no
302 AC_LANG_WERROR
303 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
304 [libgfor_cv_have_as_needed=yes],
305 [libgfor_cv_have_as_needed=no])
306 LDFLAGS="$save_LDFLAGS"
307 if test "x$libgfor_cv_have_as_needed" = xno; then
308 libgfor_cv_as_needed_option="--as-needed"
309 libgfor_cv_no_as_needed_option="--no-as-needed"
310 save_LDFLAGS="$LDFLAGS"
311 LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
312 libgfor_cv_have_as_needed=no
313 AC_LANG_WERROR
314 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
315 [libgfor_cv_have_as_needed=yes],
316 [libgfor_cv_have_as_needed=no])
317 LDFLAGS="$save_LDFLAGS"
318 fi
319 ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
320 ])
321
322 dnl For static libgfortran linkage, depend on libquadmath only if needed.
323 if test "x$libgfor_cv_have_as_needed" = xyes; then
324 LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
325 else
326 LIBQUADSPEC="-lquadmath"
327 fi
328 if test -f ../libquadmath/libquadmath.la; then
329 LIBQUADLIB=../libquadmath/libquadmath.la
330 LIBQUADLIB_DEP=../libquadmath/libquadmath.la
331 LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
332 else
333 LIBQUADLIB="-lquadmath"
334 LIBQUADLIB_DEP=
335 LIBQUADINCLUDE=
336 fi
337 fi
338 else
339 # for --disable-quadmath
340 LIBQUADLIB=
341 LIBQUADLIB_DEP=
342 LIBQUADINCLUDE=
343 fi
344
345 dnl For the spec file
346 AC_SUBST(LIBQUADSPEC)
347 AC_SUBST(LIBQUADLIB)
348 AC_SUBST(LIBQUADLIB_DEP)
349 AC_SUBST(LIBQUADINCLUDE)
350
351 dnl We need a conditional for the Makefile
352 AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])
353 ])
354
355
356 dnl Check whether we have strerror_r
357 AC_DEFUN([LIBGFOR_CHECK_STRERROR_R], [
358 dnl Check for three-argument POSIX version of strerror_r
359 ac_save_CFLAGS="$CFLAGS"
360 CFLAGS="-Wimplicit-function-declaration -Werror"
361 AC_TRY_COMPILE([#define _GNU_SOURCE 1
362 #include <string.h>
363 #include <locale.h>],
364 [char s[128]; strerror_r(5, s, 128);],
365 AC_DEFINE(HAVE_STRERROR_R, 1,
366 [Define if strerror_r is available in <string.h>.]),)
367 CFLAGS="$ac_save_CFLAGS"
368
369 dnl Check for two-argument version of strerror_r (e.g. for VxWorks)
370 ac_save_CFLAGS="$CFLAGS"
371 CFLAGS="-Wimplicit-function-declaration -Werror"
372 AC_TRY_COMPILE([#define _GNU_SOURCE 1
373 #include <string.h>
374 #include <locale.h>],
375 [char s[128]; strerror_r(5, s);],
376 AC_DEFINE(HAVE_STRERROR_R_2ARGS, 1,
377 [Define if strerror_r takes two arguments and is available in <string.h>.]),)
378 CFLAGS="$ac_save_CFLAGS"
379 ])