1 # Autoconf macros for the GNU MPFR Library.
2 # Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 # Contributed by the AriC and Caramel projects, INRIA.
5 # Copyright (C) 2014, 2015 Peter Breitenlohner <tex-live@tug.org>
6 # Extracted from mpfr-3.1.2/acinclude.m4 and adapted for TeX Live.
8 # This file is free software; the copyright holders
9 # give unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 dnl ------------------------------------------------------------
13 dnl You must put in MPFR_CONFIGS everything which configure MPFR
15 dnl -everything dealing with CC and CFLAGS in particular the ABI
16 dnl but the IEEE-754 specific flags must be set here.
19 dnl -Handling of special arguments of MPFR's configure.
20 AC_DEFUN([MPFR_CONFIGS], [dnl
21 AC_REQUIRE([AC_HEADER_TIME])
22 AC_REQUIRE([AC_CANONICAL_HOST])
24 dnl Check for wide characters (wchar_t and wint_t)
25 AC_CHECK_HEADERS([wchar.h])
28 AC_DEFINE([HAVE_STDARG], 1, [Define if stdarg])
30 AC_CHECK_HEADERS([sys/time.h])
32 dnl Check how to get `alloca'
38 AC_MSG_CHECKING([how to copy va_list])
39 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
45 AC_MSG_RESULT([va_copy])
46 AC_DEFINE([HAVE_VA_COPY], 1, [Define to 1 if you have the `va_copy' function.])
47 ], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
52 ]])], [AC_DEFINE([HAVE___VA_COPY], 1, [Define to 1 if you have the `__va_copy' function.])
53 AC_MSG_RESULT([__va_copy])],
54 [AC_MSG_RESULT([memcpy])])])
56 dnl Check for IEEE-754 switches on Alpha
59 AC_CACHE_CHECK([for IEEE-754 switches], [mpfr_cv_ieee_switches], [
61 if test -n "$GCC"; then
62 mpfr_cv_ieee_switches="-mfp-rounding-mode=d -mieee-with-inexact"
64 mpfr_cv_ieee_switches="-fprm d -ieee_with_inexact"
66 CFLAGS="$CFLAGS $mpfr_cv_ieee_switches"
67 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
68 [], [mpfr_cv_ieee_switches=none])
71 test "x$mpfr_cv_ieee_switches" = xnone || CFLAGS="$CFLAGS $mpfr_cv_ieee_switches"
74 dnl check for long long
75 AC_CHECK_TYPE([long long int],
76 [AC_DEFINE([HAVE_LONG_LONG], 1, [Define if compiler supports long long])])
79 AC_CHECK_TYPES([intmax_t])
80 if test "x$ac_cv_type_intmax_t" = xyes; then
81 AC_CACHE_CHECK([for working INTMAX_MAX], [mpfr_cv_have_intmax_max], [
82 saved_CPPFLAGS=$CPPFLAGS
83 CPPFLAGS="$CPPFLAGS -I$srcdir/mpfr-]mpfr_version[/src"
84 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "mpfr-intmax.h"]],
85 [[intmax_t x = INTMAX_MAX;]])],
86 [mpfr_cv_have_intmax_max=yes], [mpfr_cv_have_intmax_max=no])
87 CPPFLAGS=$saved_CPPFLAGS
89 if test "x$mpfr_cv_have_intmax_max" = xyes; then
90 AC_DEFINE([MPFR_HAVE_INTMAX_MAX], 1, [Define if you have a working INTMAX_MAX.])
94 KPSE_SEARCH_LIBS([MPFR_LIBM], [pow], [m])
96 dnl Check for fesetround
97 AC_CACHE_CHECK([for fesetround], [mpfr_cv_have_fesetround], [
99 LIBS="$LIBS $MPFR_LIBM"
100 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <fenv.h>]], [[fesetround(FE_TONEAREST);]])],
101 [mpfr_cv_have_fesetround=yes], [mpfr_cv_have_fesetround=no])
104 if test "x$mpfr_cv_have_fesetround" = xyes; then
105 AC_DEFINE([MPFR_HAVE_FESETROUND], 1,
106 [Define if you have the `fesetround' function via the <fenv.h> header file.])
109 dnl Check for gcc float-conversion bug; if need be, -ffloat-store is used to
110 dnl force the conversion to the destination type when a value is stored to
111 dnl a variable (see ISO C99 standard 5.1.2.3#13, 6.3.1.5#2, 6.3.1.8#2). This
112 dnl is important concerning the exponent range. Note that this doesn't solve
113 dnl the double-rounding problem.
114 if test -n "$GCC"; then
115 AC_CACHE_CHECK([for gcc float-conversion bug], [mpfr_cv_gcc_floatconv_bug], [
117 LIBS="$LIBS $MPFR_LIBM"
120 #ifdef MPFR_HAVE_FESETROUND
123 static double get_max (void);
128 for (i = 1; i <= 11; i++)
132 #ifdef MPFR_HAVE_FESETROUND
133 /* Useful test for the G4 PowerPC */
134 fesetround(FE_TOWARDZERO);
142 static double get_max (void) { static volatile double d = DBL_MAX; return d; }
143 ], [mpfr_cv_gcc_floatconv_bug="no"],
144 [mpfr_cv_gcc_floatconv_bug="yes, use -ffloat-store"],
145 [mpfr_cv_gcc_floatconv_bug="cannot test, use -ffloat-store"])
148 test "x$mpfr_cv_gcc_floatconv_bug" = xno || CFLAGS="$CFLAGS -ffloat-store"
151 dnl Check if denormalized numbers are supported
152 AC_CACHE_CHECK([for denormalized numbers], [mpfr_cv_have_denorms], [
157 double x = 2.22507385850720138309e-308;
158 fprintf (stderr, "%e\n", x / 2.0);
159 return 2.0 * (x / 2.0) != x;
161 ], [mpfr_cv_have_denorms=yes], [mpfr_cv_have_denorms=no], [mpfr_cv_have_denorms=no])
163 if test "x$mpfr_cv_have_denorms" = xyes; then
164 AC_DEFINE([HAVE_DENORMS], 1, [Define if denormalized floats work.])
167 dnl Check the FP division by 0 fails (e.g. on a non-IEEE-754 platform).
168 dnl In such a case, MPFR_ERRDIVZERO is defined to disable the tests
169 dnl involving a FP division by 0.
170 dnl For the developers: to check whether all these tests are disabled,
171 dnl configure MPFR with "-DMPFR_TEST_DIVBYZERO=1 -DMPFR_ERRDIVZERO=1".
172 AC_CACHE_CHECK([if the FP division by 0 fails], [mpfr_cv_errdivzero], [
175 volatile double d = 0.0, x;
180 ], [mpfr_cv_errdivzero="no"],
181 [mpfr_cv_errdivzero="yes"],
182 [mpfr_cv_errdivzero="cannot test, assume no"])
184 if test "x$mpfr_cv_errdivzero" = xyes; then
185 AC_DEFINE([MPFR_ERRDIVZERO], 1, [Define if the FP division by 0 fails.])
186 AC_MSG_WARN([The floating-point division by 0 fails instead of])
187 AC_MSG_WARN([returning a special value: NaN or infinity. Tests])
188 AC_MSG_WARN([involving a FP division by 0 will be disabled.])
191 dnl Check whether NAN != NAN (as required by the IEEE-754 standard,
192 dnl but not by the ISO C standard). For instance, this is false with
193 dnl MIPSpro 7.3.1.3m under IRIX64. By default, assume this is true.
194 AC_CACHE_CHECK([if NAN == NAN], [mpfr_cv_nanisnan], [
199 # define NAN (0.0/0.0)
206 ], [mpfr_cv_nanisnan="yes"],
207 [mpfr_cv_nanisnan="no"],
208 [mpfr_cv_nanisnan="cannot test, assume no"])
210 if test "x$mpfr_cv_nanisnan" = xyes; then
211 AC_DEFINE([MPFR_NANISNAN], 1, [Define if NAN == NAN.])
212 AC_MSG_WARN([The test NAN != NAN is false. The probable reason is that])
213 AC_MSG_WARN([your compiler optimizes floating-point expressions in an])
214 AC_MSG_WARN([unsafe way because some option, such as -ffast-math or])
215 AC_MSG_WARN([-fast (depending on the compiler), has been used. You])
216 AC_MSG_WARN([should NOT use such an option, otherwise MPFR functions])
217 AC_MSG_WARN([such as mpfr_get_d and mpfr_set_d may return incorrect])
218 AC_MSG_WARN([results on special FP numbers (e.g. NaN or signed zeros).])
219 AC_MSG_WARN([If you did not use such an option, please send us a bug])
220 AC_MSG_WARN([report so that we can try to find a workaround for your])
221 AC_MSG_WARN([platform and/or document the behavior.])
224 dnl Check if the chars '0' to '9' are consecutive values
225 AC_MSG_CHECKING([if charset has consecutive values])
226 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
227 char *number = "0123456789";
228 char *lower = "abcdefghijklmnopqrstuvwxyz";
229 char *upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
233 for (p = (unsigned char*) number, i = 0; i < 9; i++)
234 if ( (*p)+1 != *(p+1) ) return 1;
235 for (p = (unsigned char*) lower, i = 0; i < 25; i++)
236 if ( (*p)+1 != *(p+1) ) return 1;
237 for (p = (unsigned char*) upper, i = 0; i < 25; i++)
238 if ( (*p)+1 != *(p+1) ) return 1;
239 ]])], [AC_MSG_RESULT([yes])],[
241 AC_DEFINE([MPFR_NO_CONSECUTIVE_CHARSET], 1, [Charset is not consecutive])
242 ], [AC_MSG_RESULT([cannot test])])
244 dnl Now try to check the long double format
245 MPFR_C_LONG_DOUBLE_FORMAT
248 dnl end of MPFR_CONFIGS
251 dnl MPFR_LD_SEARCH_PATHS_FIRST
252 dnl --------------------------
254 AC_DEFUN([MPFR_LD_SEARCH_PATHS_FIRST],
256 [*-Wl,-search_paths_first*], [],
257 [AC_MSG_CHECKING([if the compiler understands -Wl,-search_paths_first])
258 saved_LDFLAGS=$LDFLAGS
259 LDFLAGS="-Wl,-search_paths_first $LDFLAGS"
260 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
261 [AC_MSG_RESULT([yes])],
263 LDFLAGS=$saved_LDFLAGS])])