1 m4_include(../config/acx.m4)
2 m4_include(../config/no-executables.m4)
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])
10 real, parameter :: bar = sin (12.34 / 2.5)
12 [AC_MSG_RESULT([yes])],
14 AC_MSG_ERROR([GNU Fortran is not working; please report a bug in http://gcc.gnu.org/bugzilla, attaching $PWD/config.log])
16 AC_LANG_POP([Fortran])
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])
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, [
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(...))).])
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, [
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)).])
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([[
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(...))).])
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])
86 dnl Check for pragma weak.
87 AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
88 AC_CACHE_CHECK([whether pragma weak works],
89 libgfor_cv_have_pragma_weak, [
90 gfor_save_CFLAGS="$CFLAGS"
91 CFLAGS="$CFLAGS -Wunknown-pragmas"
92 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
95 ]], [[if (foo) foo ();]])],
96 libgfor_cv_have_pragma_weak=yes, libgfor_cv_have_pragma_weak=no)])
97 if test $libgfor_cv_have_pragma_weak = yes; then
98 AC_DEFINE(SUPPORTS_WEAK, 1,
99 [Define to 1 if the target supports #pragma weak])
102 *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | alpha*-dec-osf* )
103 AC_DEFINE(GTHREAD_USE_WEAK, 0,
104 [Define to 0 if the target shouldn't use #pragma weak])
108 dnl Check whether target can unlink a file still open.
109 AC_DEFUN([LIBGFOR_CHECK_UNLINK_OPEN_FILE], [
110 AC_CACHE_CHECK([whether the target can unlink an open file],
111 libgfor_cv_have_unlink_open_file, [
112 AC_RUN_IFELSE([AC_LANG_SOURCE([[
116 #include <sys/stat.h>
122 fd = open ("testfile", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
125 if (unlink ("testfile") == -1)
127 write (fd, "This is a test\n", 15);
130 if (open ("testfile", O_RDONLY) == -1 && errno == ENOENT)
134 }]])], libgfor_cv_have_unlink_open_file=yes, libgfor_cv_have_unlink_open_file=no, [
136 *mingw*) libgfor_cv_have_unlink_open_file=no ;;
137 *) libgfor_cv_have_unlink_open_file=yes;;
139 if test x"$libgfor_cv_have_unlink_open_file" = xyes; then
140 AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
143 dnl Check whether CRLF is the line terminator
144 AC_DEFUN([LIBGFOR_CHECK_CRLF], [
145 AC_CACHE_CHECK([whether the target has CRLF as line terminator],
146 libgfor_cv_have_crlf, [
147 AC_RUN_IFELSE([AC_LANG_SOURCE([[
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>
165 fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
168 if (write (fd, "\n", 1) < 0)
173 if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
175 bytes = read (fd, buff, 5);
176 if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
181 }]])], libgfor_cv_have_crlf=yes, libgfor_cv_have_crlf=no, [
183 *mingw*) libgfor_cv_have_crlf=yes ;;
184 *) libgfor_cv_have_crlf=no;;
186 if test x"$libgfor_cv_have_crlf" = xyes; then
187 AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
190 dnl Check whether the st_ino and st_dev stat fields taken together uniquely
191 dnl identify the file within the system. This is should be true for POSIX
192 dnl systems; it is known to be false on mingw32.
193 AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
194 AC_CACHE_CHECK([whether the target stat is reliable],
195 libgfor_cv_have_working_stat, [
196 AC_RUN_IFELSE([AC_LANG_SOURCE([[
198 #include <sys/types.h>
199 #include <sys/stat.h>
205 struct stat st1, st2;
207 f = fopen ("foo", "w");
208 g = fopen ("bar", "w");
209 if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
211 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
216 }]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
218 *mingw*) libgfor_cv_have_working_stat=no ;;
219 *) libgfor_cv_have_working_stat=yes;;
221 if test x"$libgfor_cv_have_working_stat" = xyes; then
222 AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
225 dnl Checks for fpsetmask function.
226 AC_DEFUN([LIBGFOR_CHECK_FPSETMASK], [
227 AC_CACHE_CHECK([whether fpsetmask is present], libgfor_cv_have_fpsetmask, [
228 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
229 #if HAVE_FLOATINGPOINT_H
230 # include <floatingpoint.h>
231 #endif /* HAVE_FLOATINGPOINT_H */
234 #endif /* HAVE_IEEEFP_H */]],[[fpsetmask(0);]])],
235 eval "libgfor_cv_have_fpsetmask=yes", eval "libgfor_cv_have_fpsetmask=no")
237 if test x"$libgfor_cv_have_fpsetmask" = xyes; then
239 AC_DEFINE(HAVE_FPSETMASK, 1, [Define if you have fpsetmask.])
243 dnl Check whether we have a mingw that provides a __mingw_snprintf function
244 AC_DEFUN([LIBGFOR_CHECK_MINGW_SNPRINTF], [
245 AC_CACHE_CHECK([whether __mingw_snprintf is present], libgfor_cv_have_mingw_snprintf, [
246 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
248 extern int __mingw_snprintf (char *, size_t, const char *, ...);
250 __mingw_snprintf (NULL, 0, "%d\n", 1);
252 eval "libgfor_cv_have_mingw_snprintf=yes", eval "libgfor_cv_have_mingw_snprintf=no")
254 if test x"$libgfor_cv_have_mingw_snprintf" = xyes; then
255 AC_DEFINE(HAVE_MINGW_SNPRINTF, 1, [Define if you have __mingw_snprintf.])
259 dnl Check whether we have a broken powf implementation
260 AC_DEFUN([LIBGFOR_CHECK_FOR_BROKEN_POWF], [
261 AC_CACHE_CHECK([whether powf is broken], libgfor_cv_have_broken_powf, [
263 hppa*64*-*-hpux*) libgfor_cv_have_broken_powf=yes ;;
264 *) libgfor_cv_have_broken_powf=no;;
266 if test x"$libgfor_cv_have_broken_powf" = xyes; then
267 AC_DEFINE(HAVE_BROKEN_POWF, 1, [Define if powf is broken.])
271 dnl Check whether we have a __float128 type
272 AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
275 if test "x$enable_libquadmath_support" != xno; then
277 AC_CACHE_CHECK([whether we have a usable __float128 type],
278 libgfor_cv_have_float128, [
279 GCC_TRY_COMPILE_OR_LINK([
280 typedef _Complex float __attribute__((mode(TC))) __complex128;
282 __float128 foo (__float128 x)
291 return (__float128) z2;
294 __float128 bar (__float128 x)
296 return x * __builtin_huge_valq ();
302 libgfor_cv_have_float128=yes
304 libgfor_cv_have_float128=no
307 if test "x$libgfor_cv_have_float128" = xyes; then
308 AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
310 dnl Check whether -Wl,--as-needed is supported
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
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],
321 save_LDFLAGS="$LDFLAGS"
322 LDFLAGS="$LDFLAGS -Wl,--as-needed -lm -Wl,--no-as-needed"
323 libgfor_cv_have_as_needed=no
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
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}"
336 LIBQUADSPEC="-lquadmath"
338 if test -f ../libquadmath/libquadmath.la; then
339 LIBQUADLIB=../libquadmath/libquadmath.la
340 LIBQUADLIB_DEP=../libquadmath/libquadmath.la
341 LIBQUADINCLUDE='-I$(srcdir)/../libquadmath'
343 LIBQUADLIB="-lquadmath"
349 # for --disable-quadmath
355 dnl For the spec file
356 AC_SUBST(LIBQUADSPEC)
358 AC_SUBST(LIBQUADLIB_DEP)
359 AC_SUBST(LIBQUADINCLUDE)
361 dnl We need a conditional for the Makefile
362 AM_CONDITIONAL(LIBGFOR_BUILD_QUAD, [test "x$libgfor_cv_have_float128" = xyes])