xref: /netbsd-src/external/lgpl3/mpfr/dist/acinclude.m4 (revision 796c32c94f6e154afc9de0f63da35c91bb739b45)
1dnl  MPFR specific autoconf macros
2
3dnl  Copyright 2000, 2002-2016 Free Software Foundation, Inc.
4dnl  Contributed by the AriC and Caramba projects, INRIA.
5dnl
6dnl  This file is part of the GNU MPFR Library.
7dnl
8dnl  The GNU MPFR Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of the GNU Lesser General Public License as published
10dnl  by the Free Software Foundation; either version 3 of the License, or (at
11dnl  your option) any later version.
12dnl
13dnl  The GNU MPFR Library is distributed in the hope that it will be useful, but
14dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16dnl  License for more details.
17dnl
18dnl  You should have received a copy of the GNU Lesser General Public License
19dnl  along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20dnl  http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21dnl  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22
23dnl  autoconf 2.60 is necessary because of the use of AC_PROG_SED.
24dnl  The following line allows the autoconf wrapper (when installed)
25dnl  to work as expected.
26dnl  If you change the required version, please update README.dev too!
27AC_PREREQ(2.60)
28
29dnl ------------------------------------------------------------
30dnl You must put in MPFR_CONFIGS everything which configure MPFR
31dnl except:
32dnl   - Everything dealing with CC and CFLAGS in particular the ABI
33dnl     but the IEEE-754 specific flags must be set here.
34dnl   - Tests that depend on gmp.h (see MPFR_CHECK_DBL2INT_BUG as an example:
35dnl     a function needs to be defined and called in configure.ac).
36dnl   - GMP's linkage.
37dnl   - Libtool stuff.
38dnl   - Handling of special arguments of MPFR's configure.
39AC_DEFUN([MPFR_CONFIGS],
40[
41AC_REQUIRE([AC_OBJEXT])
42AC_REQUIRE([MPFR_CHECK_LIBM])
43AC_REQUIRE([AC_HEADER_TIME])
44AC_REQUIRE([AC_CANONICAL_HOST])
45
46AC_CHECK_HEADER([limits.h],, AC_MSG_ERROR([limits.h not found]))
47AC_CHECK_HEADER([float.h],,  AC_MSG_ERROR([float.h not found]))
48AC_CHECK_HEADER([string.h],, AC_MSG_ERROR([string.h not found]))
49
50dnl Check for locales
51AC_CHECK_HEADERS([locale.h])
52
53dnl Check for wide characters (wchar_t and wint_t)
54AC_CHECK_HEADERS([wchar.h])
55
56dnl Check for stdargs
57AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([HAVE_STDARG],1,[Define if stdarg])],
58  [AC_CHECK_HEADER([varargs.h],,
59    AC_MSG_ERROR([stdarg.h or varargs.h not found]))])
60
61dnl sys/fpu.h - MIPS specific
62AC_CHECK_HEADERS([sys/time.h sys/fpu.h])
63
64dnl Android has a <locale.h>, but not the following members.
65AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep],,,
66  [#include <locale.h>])
67
68dnl Check how to get `alloca'
69AC_FUNC_ALLOCA
70
71dnl SIZE_MAX macro
72gl_SIZE_MAX
73
74dnl va_copy macro
75AC_MSG_CHECKING([how to copy va_list])
76AC_LINK_IFELSE([AC_LANG_PROGRAM([[
77#include <stdarg.h>
78]], [[
79   va_list ap1, ap2;
80   va_copy(ap1, ap2);
81]])], [
82   AC_MSG_RESULT([va_copy])
83   AC_DEFINE(HAVE_VA_COPY)
84], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
85#include <stdarg.h>
86]], [[
87   va_list ap1, ap2;
88   __va_copy(ap1, ap2);
89]])], [AC_DEFINE([HAVE___VA_COPY]) AC_MSG_RESULT([__va_copy])],
90   [AC_MSG_RESULT([memcpy])])])
91
92dnl FIXME: The functions memmove, memset and strtol are really needed by
93dnl MPFR, but if they are implemented as macros, this is also OK (in our
94dnl case).  So, we do not return an error, but their tests are currently
95dnl useless.
96dnl gettimeofday is not defined for MinGW
97AC_CHECK_FUNCS([memmove memset setlocale strtol gettimeofday])
98
99dnl Check for IEEE-754 switches on Alpha
100case $host in
101alpha*-*-*)
102  saved_CFLAGS="$CFLAGS"
103  AC_CACHE_CHECK([for IEEE-754 switches], mpfr_cv_ieee_switches, [
104  if test -n "$GCC"; then
105    mpfr_cv_ieee_switches="-mfp-rounding-mode=d -mieee-with-inexact"
106  else
107    mpfr_cv_ieee_switches="-fprm d -ieee_with_inexact"
108  fi
109  CFLAGS="$CFLAGS $mpfr_cv_ieee_switches"
110  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], , mpfr_cv_ieee_switches="none")
111  ])
112  if test "$mpfr_cv_ieee_switches" = "none"; then
113    CFLAGS="$saved_CFLAGS"
114  else
115    CFLAGS="$saved_CFLAGS $mpfr_cv_ieee_switches"
116  fi
117esac
118
119dnl check for long long
120AC_CHECK_TYPE([long long int],
121   AC_DEFINE(HAVE_LONG_LONG, 1, [Define if compiler supports long long]),,)
122
123dnl intmax_t is C99
124AC_CHECK_TYPES([intmax_t])
125if test "$ac_cv_type_intmax_t" = yes; then
126  AC_CACHE_CHECK([for working INTMAX_MAX], mpfr_cv_have_intmax_max, [
127    saved_CPPFLAGS="$CPPFLAGS"
128    CPPFLAGS="$CPPFLAGS -I$srcdir/src"
129    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
130        [[#include "mpfr-intmax.h"]],
131        [[intmax_t x = INTMAX_MAX; (void) x;]]
132      )],
133      mpfr_cv_have_intmax_max=yes, mpfr_cv_have_intmax_max=no)
134    CPPFLAGS="$saved_CPPFLAGS"
135  ])
136  if test "$mpfr_cv_have_intmax_max" = "yes"; then
137    AC_DEFINE(MPFR_HAVE_INTMAX_MAX,1,[Define if you have a working INTMAX_MAX.])
138  fi
139fi
140
141AC_CHECK_TYPE( [union fpc_csr],
142   AC_DEFINE(HAVE_FPC_CSR,1,[Define if union fpc_csr is available]), ,
143[
144#if HAVE_SYS_FPU_H
145#  include <sys/fpu.h>
146#endif
147])
148
149dnl Check for fesetround
150AC_CACHE_CHECK([for fesetround], mpfr_cv_have_fesetround, [
151saved_LIBS="$LIBS"
152LIBS="$LIBS $MPFR_LIBM"
153AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <fenv.h>]], [[fesetround(FE_TONEAREST);]])],
154  mpfr_cv_have_fesetround=yes, mpfr_cv_have_fesetround=no)
155LIBS="$saved_LIBS"
156])
157if test "$mpfr_cv_have_fesetround" = "yes"; then
158  AC_DEFINE(MPFR_HAVE_FESETROUND,1,[Define if you have the `fesetround' function via the <fenv.h> header file.])
159fi
160
161dnl Check for gcc float-conversion bug; if need be, -ffloat-store is used to
162dnl force the conversion to the destination type when a value is stored to
163dnl a variable (see ISO C99 standard 5.1.2.3#13, 6.3.1.5#2, 6.3.1.8#2). This
164dnl is important concerning the exponent range. Note that this doesn't solve
165dnl the double-rounding problem.
166if test -n "$GCC"; then
167  AC_CACHE_CHECK([for gcc float-conversion bug], mpfr_cv_gcc_floatconv_bug, [
168  saved_LIBS="$LIBS"
169  LIBS="$LIBS $MPFR_LIBM"
170  AC_RUN_IFELSE([AC_LANG_SOURCE([[
171#include <float.h>
172#ifdef MPFR_HAVE_FESETROUND
173#include <fenv.h>
174#endif
175static double get_max (void);
176int main (void) {
177  double x = 0.5;
178  double y;
179  int i;
180  for (i = 1; i <= 11; i++)
181    x *= x;
182  if (x != 0)
183    return 1;
184#ifdef MPFR_HAVE_FESETROUND
185  /* Useful test for the G4 PowerPC */
186  fesetround(FE_TOWARDZERO);
187  x = y = get_max ();
188  x *= 2.0;
189  if (x != y)
190    return 1;
191#endif
192  return 0;
193}
194static double get_max (void) { static volatile double d = DBL_MAX; return d; }
195  ]])],
196     [mpfr_cv_gcc_floatconv_bug="no"],
197     [mpfr_cv_gcc_floatconv_bug="yes, use -ffloat-store"],
198     [mpfr_cv_gcc_floatconv_bug="cannot test, use -ffloat-store"])
199  LIBS="$saved_LIBS"
200  ])
201  if test "$mpfr_cv_gcc_floatconv_bug" != "no"; then
202    CFLAGS="$CFLAGS -ffloat-store"
203  fi
204fi
205
206dnl Check if subnormal (denormalized) numbers are supported
207AC_CACHE_CHECK([for subnormal numbers], mpfr_cv_have_denorms, [
208AC_RUN_IFELSE([AC_LANG_SOURCE([[
209#include <stdio.h>
210int main (void) {
211  double x = 2.22507385850720138309e-308;
212  fprintf (stderr, "%e\n", x / 2.0);
213  return 2.0 * (x / 2.0) != x;
214}
215]])],
216   [mpfr_cv_have_denorms="yes"],
217   [mpfr_cv_have_denorms="no"],
218   [mpfr_cv_have_denorms="cannot test, assume no"])
219])
220if test "$mpfr_cv_have_denorms" = "yes"; then
221  AC_DEFINE(HAVE_DENORMS,1,[Define if subnormal (denormalized) floats work.])
222fi
223
224dnl Check if signed zeros are supported. Note: the test will fail
225dnl if the division by 0 generates a trap.
226AC_CACHE_CHECK([for signed zeros], mpfr_cv_have_signedz, [
227AC_RUN_IFELSE([AC_LANG_SOURCE([[
228int main (void) {
229  return 1.0 / 0.0 == 1.0 / -0.0;
230}
231]])],
232   [mpfr_cv_have_signedz="yes"],
233   [mpfr_cv_have_signedz="no"],
234   [mpfr_cv_have_signedz="cannot test, assume no"])
235])
236if test "$mpfr_cv_have_signedz" = "yes"; then
237  AC_DEFINE(HAVE_SIGNEDZ,1,[Define if signed zeros are supported.])
238fi
239
240dnl Check the FP division by 0 fails (e.g. on a non-IEEE-754 platform).
241dnl In such a case, MPFR_ERRDIVZERO is defined to disable the tests
242dnl involving a FP division by 0.
243dnl For the developers: to check whether all these tests are disabled,
244dnl configure MPFR with "-DMPFR_TEST_DIVBYZERO=1 -DMPFR_ERRDIVZERO=1".
245AC_CACHE_CHECK([if the FP division by 0 fails], mpfr_cv_errdivzero, [
246AC_RUN_IFELSE([AC_LANG_SOURCE([[
247int main (void) {
248  volatile double d = 0.0, x;
249  x = 0.0 / d;
250  x = 1.0 / d;
251  (void) x;
252  return 0;
253}
254]])],
255   [mpfr_cv_errdivzero="no"],
256   [mpfr_cv_errdivzero="yes"],
257   [mpfr_cv_errdivzero="cannot test, assume no"])
258])
259if test "$mpfr_cv_errdivzero" = "yes"; then
260  AC_DEFINE(MPFR_ERRDIVZERO,1,[Define if the FP division by 0 fails.])
261  AC_MSG_WARN([The floating-point division by 0 fails instead of])
262  AC_MSG_WARN([returning a special value: NaN or infinity. Tests])
263  AC_MSG_WARN([involving a FP division by 0 will be disabled.])
264fi
265
266dnl Check whether NAN != NAN (as required by the IEEE-754 standard,
267dnl but not by the ISO C standard). For instance, this is false with
268dnl MIPSpro 7.3.1.3m under IRIX64. By default, assume this is true.
269AC_CACHE_CHECK([if NAN == NAN], mpfr_cv_nanisnan, [
270AC_RUN_IFELSE([AC_LANG_SOURCE([[
271#include <stdio.h>
272#include <math.h>
273#ifndef NAN
274# define NAN (0.0/0.0)
275#endif
276int main (void) {
277  double d;
278  d = NAN;
279  return d != d;
280}
281]])],
282   [mpfr_cv_nanisnan="yes"],
283   [mpfr_cv_nanisnan="no"],
284   [mpfr_cv_nanisnan="cannot test, assume no"])
285])
286if test "$mpfr_cv_nanisnan" = "yes"; then
287  AC_DEFINE(MPFR_NANISNAN,1,[Define if NAN == NAN.])
288  AC_MSG_WARN([The test NAN != NAN is false. The probable reason is that])
289  AC_MSG_WARN([your compiler optimizes floating-point expressions in an])
290  AC_MSG_WARN([unsafe way because some option, such as -ffast-math or])
291  AC_MSG_WARN([-fast (depending on the compiler), has been used.  You])
292  AC_MSG_WARN([should NOT use such an option, otherwise MPFR functions])
293  AC_MSG_WARN([such as mpfr_get_d and mpfr_set_d may return incorrect])
294  AC_MSG_WARN([results on special FP numbers (e.g. NaN or signed zeros).])
295  AC_MSG_WARN([If you did not use such an option, please send us a bug])
296  AC_MSG_WARN([report so that we can try to find a workaround for your])
297  AC_MSG_WARN([platform and/or document the behavior.])
298fi
299
300dnl Check if the chars '0' to '9' are consecutive values
301AC_MSG_CHECKING([if charset has consecutive values])
302AC_RUN_IFELSE([AC_LANG_PROGRAM([[
303char *number = "0123456789";
304char *lower  = "abcdefghijklmnopqrstuvwxyz";
305char *upper  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
306]],[[
307 int i;
308 unsigned char *p;
309 for (p = (unsigned char*) number, i = 0; i < 9; i++)
310   if ( (*p)+1 != *(p+1) ) return 1;
311 for (p = (unsigned char*) lower, i = 0; i < 25; i++)
312   if ( (*p)+1 != *(p+1) ) return 1;
313 for (p = (unsigned char*) upper, i = 0; i < 25; i++)
314   if ( (*p)+1 != *(p+1) ) return 1;
315]])], [AC_MSG_RESULT(yes)],[
316 AC_MSG_RESULT(no)
317 AC_DEFINE(MPFR_NO_CONSECUTIVE_CHARSET,1,[Charset is not consecutive])
318], [AC_MSG_RESULT(cannot test)])
319
320dnl Must be checked with the LIBM
321dnl but we don't want to add the LIBM to MPFR dependency.
322dnl Can't use AC_CHECK_FUNCS since the function may be in LIBM but
323dnl not exported in math.h
324saved_LIBS="$LIBS"
325LIBS="$LIBS $MPFR_LIBM"
326dnl AC_CHECK_FUNCS([round trunc floor ceil nearbyint])
327AC_MSG_CHECKING(for math/round)
328AC_LINK_IFELSE([AC_LANG_PROGRAM([[
329#include <math.h>
330static int f (double (*func)(double)) { return 0; }
331]], [[
332 return f(round);
333]])], [
334   AC_MSG_RESULT(yes)
335   AC_DEFINE(HAVE_ROUND, 1,[Have ISO C99 round function])
336],[AC_MSG_RESULT(no)])
337
338AC_MSG_CHECKING(for math/trunc)
339AC_LINK_IFELSE([AC_LANG_PROGRAM([[
340#include <math.h>
341static int f (double (*func)(double)) { return 0; }
342]], [[
343 return f(trunc);
344]])], [
345   AC_MSG_RESULT(yes)
346   AC_DEFINE(HAVE_TRUNC, 1,[Have ISO C99 trunc function])
347],[AC_MSG_RESULT(no)])
348
349AC_MSG_CHECKING(for math/floor)
350AC_LINK_IFELSE([AC_LANG_PROGRAM([[
351#include <math.h>
352static int f (double (*func)(double)) { return 0; }
353]], [[
354 return f(floor);
355]])], [
356   AC_MSG_RESULT(yes)
357   AC_DEFINE(HAVE_FLOOR, 1,[Have ISO C99 floor function])
358],[AC_MSG_RESULT(no)])
359
360AC_MSG_CHECKING(for math/ceil)
361AC_LINK_IFELSE([AC_LANG_PROGRAM([[
362#include <math.h>
363static int f (double (*func)(double)) { return 0; }
364]], [[
365 return f(ceil);
366]])], [
367   AC_MSG_RESULT(yes)
368   AC_DEFINE(HAVE_CEIL, 1,[Have ISO C99 ceil function])
369],[AC_MSG_RESULT(no)])
370
371AC_MSG_CHECKING(for math/nearbyint)
372AC_LINK_IFELSE([AC_LANG_PROGRAM([[
373#include <math.h>
374static int f (double (*func)(double)) { return 0; }
375]], [[
376 return f(nearbyint);
377]])], [
378   AC_MSG_RESULT(yes)
379   AC_DEFINE(HAVE_NEARBYINT, 1,[Have ISO C99 nearbyint function])
380],[AC_MSG_RESULT(no)])
381
382LIBS="$saved_LIBS"
383
384dnl Now try to check the long double format
385MPFR_C_LONG_DOUBLE_FORMAT
386
387if test "$enable_logging" = yes; then
388  if test "$enable_thread_safe" = yes; then
389    AC_MSG_ERROR([Enable either `Logging' or `thread-safe', not both])
390  else
391    enable_thread_safe=no
392  fi
393fi
394
395dnl Check if thread-local variables are supported.
396dnl At least two problems can occur in practice:
397dnl 1. The compilation fails, e.g. because the compiler doesn't know
398dnl    about the __thread keyword.
399dnl 2. The compilation succeeds, but the system doesn't support TLS or
400dnl    there is some ld configuration problem. One of the effects can
401dnl    be that thread-local variables always evaluate to 0. So, it is
402dnl    important to run the test below.
403if test "$enable_thread_safe" != no; then
404AC_MSG_CHECKING(for TLS support using C11)
405saved_CPPFLAGS="$CPPFLAGS"
406CPPFLAGS="$CPPFLAGS -I$srcdir/src"
407AC_RUN_IFELSE([AC_LANG_SOURCE([[
408#define MPFR_USE_THREAD_SAFE 1
409#define MPFR_USE_C11_THREAD_SAFE 1
410#include "mpfr-thread.h"
411MPFR_THREAD_ATTR int x = 17;
412int main (void) {
413  return x != 17;
414}
415  ]])],
416     [AC_MSG_RESULT(yes)
417      AC_DEFINE([MPFR_USE_THREAD_SAFE],1,[Build MPFR as thread safe])
418      AC_DEFINE([MPFR_USE_C11_THREAD_SAFE],1,[Build MPFR as thread safe using C11])
419      tls_c11_support=yes
420     ],
421     [AC_MSG_RESULT(no)
422     ],
423     [AC_MSG_RESULT([cannot test, assume no])
424     ])
425CPPFLAGS="$saved_CPPFLAGS"
426
427if test "$tls_c11_support" != "yes"
428then
429
430 AC_MSG_CHECKING(for TLS support)
431 saved_CPPFLAGS="$CPPFLAGS"
432 CPPFLAGS="$CPPFLAGS -I$srcdir/src"
433 AC_RUN_IFELSE([AC_LANG_SOURCE([[
434 #define MPFR_USE_THREAD_SAFE 1
435 #include "mpfr-thread.h"
436 MPFR_THREAD_ATTR int x = 17;
437 int main (void) {
438   return x != 17;
439 }
440   ]])],
441      [AC_MSG_RESULT(yes)
442       AC_DEFINE([MPFR_USE_THREAD_SAFE],1,[Build MPFR as thread safe])
443      ],
444      [AC_MSG_RESULT(no)
445       if test "$enable_thread_safe" = yes; then
446         AC_MSG_ERROR([please configure with --disable-thread-safe])
447       fi
448      ],
449      [if test "$enable_thread_safe" = yes; then
450         AC_MSG_RESULT([cannot test, assume yes])
451         AC_DEFINE([MPFR_USE_THREAD_SAFE],1,[Build MPFR as thread safe])
452       else
453         AC_MSG_RESULT([cannot test, assume no])
454       fi
455      ])
456 CPPFLAGS="$saved_CPPFLAGS"
457 fi
458fi
459])
460dnl end of MPFR_CONFIGS
461
462
463dnl MPFR_CHECK_GMP
464dnl --------------
465dnl Check GMP library vs header. Useful if the user provides --with-gmp
466dnl with a directory containing a GMP version that doesn't have the
467dnl correct ABI: the previous tests won't trigger the error if the same
468dnl GMP version with the right ABI is installed on the system, as this
469dnl library is automatically selected by the linker, while the header
470dnl (which depends on the ABI) of the --with-gmp include directory is
471dnl used.
472dnl Note: if the error is changed to a warning due to that fact that
473dnl libtool is not used, then the same thing should be done for the
474dnl other tests based on GMP.
475AC_DEFUN([MPFR_CHECK_GMP], [
476AC_REQUIRE([MPFR_CONFIGS])dnl
477AC_CACHE_CHECK([for GMP library vs header correctness], mpfr_cv_check_gmp, [
478AC_RUN_IFELSE([AC_LANG_PROGRAM([[
479#include <stdio.h>
480#include <limits.h>
481#include <gmp.h>
482]], [[
483  fprintf (stderr, "GMP_NAIL_BITS     = %d\n", (int) GMP_NAIL_BITS);
484  fprintf (stderr, "GMP_NUMB_BITS     = %d\n", (int) GMP_NUMB_BITS);
485  fprintf (stderr, "mp_bits_per_limb  = %d\n", (int) mp_bits_per_limb);
486  fprintf (stderr, "sizeof(mp_limb_t) = %d\n", (int) sizeof(mp_limb_t));
487  if (GMP_NAIL_BITS != 0)
488    {
489      fprintf (stderr, "GMP_NAIL_BITS != 0\n");
490      return 1;
491    }
492  if (GMP_NUMB_BITS != mp_bits_per_limb)
493    {
494      fprintf (stderr, "GMP_NUMB_BITS != mp_bits_per_limb\n");
495      return 2;
496    }
497  if (GMP_NUMB_BITS != sizeof(mp_limb_t) * CHAR_BIT)
498    {
499      fprintf (stderr, "GMP_NUMB_BITS != sizeof(mp_limb_t) * CHAR_BIT\n");
500      return 3;
501    }
502  return 0;
503]])], [mpfr_cv_check_gmp="yes"],
504      [mpfr_cv_check_gmp="no (exit status is $?)"],
505      [mpfr_cv_check_gmp="cannot test, assume yes"])
506])
507case $mpfr_cv_check_gmp in
508no*)
509  AC_MSG_ERROR([bad GMP library or header - ABI problem?
510See 'config.log' for details.])
511esac
512])
513
514
515dnl MPFR_CHECK_DBL2INT_BUG
516dnl ----------------------
517dnl Check for double-to-integer conversion bug
518dnl https://gforge.inria.fr/tracker/index.php?func=detail&aid=14435
519dnl For the exit status, the lowest values (including some values after 128)
520dnl are reserved for various system errors. So, let's use the largest values
521dnl below 255 for errors in the test itself.
522dnl The following problem has been seen under Solaris in config.log,
523dnl i.e. the failure to link with libgmp wasn't detected in the first
524dnl test:
525dnl   configure: checking if gmp.h version and libgmp version are the same
526dnl   configure: gcc -o conftest -Wall -Wmissing-prototypes [...]
527dnl   configure: $? = 0
528dnl   configure: ./conftest
529dnl   ld.so.1: conftest: fatal: libgmp.so.10: open failed: No such file [...]
530dnl   configure: $? = 0
531dnl   configure: result: yes
532dnl   configure: checking for double-to-integer conversion bug
533dnl   configure: gcc -o conftest -Wall -Wmissing-prototypes [...]
534dnl   configure: $? = 0
535dnl   configure: ./conftest
536dnl   ld.so.1: conftest: fatal: libgmp.so.10: open failed: No such file [...]
537dnl   ./configure[1680]: eval: line 1: 1971: Killed
538dnl   configure: $? = 9
539dnl   configure: program exited with status 9
540AC_DEFUN([MPFR_CHECK_DBL2INT_BUG], [
541AC_REQUIRE([MPFR_CONFIGS])dnl
542AC_CACHE_CHECK([for double-to-integer conversion bug], mpfr_cv_dbl_int_bug, [
543AC_RUN_IFELSE([AC_LANG_PROGRAM([[
544#include <gmp.h>
545]], [[
546  double d;
547  mp_limb_t u;
548  int i;
549
550  d = 1.0;
551  for (i = 0; i < GMP_NUMB_BITS - 1; i++)
552    d = d + d;
553  u = (mp_limb_t) d;
554  for (; i > 0; i--)
555    {
556      if (u & 1)
557        break;
558      u = u >> 1;
559    }
560  return (i == 0 && u == 1UL) ? 0 : 254 - i;
561]])], [mpfr_cv_dbl_int_bug="no"],
562      [mpfr_cv_dbl_int_bug="yes or failed to exec (exit status is $?)"],
563      [mpfr_cv_dbl_int_bug="cannot test, assume not present"])
564])
565case $mpfr_cv_dbl_int_bug in
566yes*)
567  AC_MSG_ERROR([double-to-integer conversion is incorrect.
568You need to use another compiler (or lower the optimization level).])
569esac
570])
571
572dnl MPFR_PARSE_DIRECTORY
573dnl Input:  $1 = a string to a relative or absolute directory
574dnl Output: $2 = the variable to set with the absolute directory
575AC_DEFUN([MPFR_PARSE_DIRECTORY],
576[
577 dnl Check if argument is a directory
578 if test -d $1 ; then
579    dnl Get the absolute path of the directory
580    dnl in case of relative directory.
581    dnl If realpath is not a valid command,
582    dnl an error is produced and we keep the given path.
583    local_tmp=`realpath $1 2>/dev/null`
584    if test "$local_tmp" != "" ; then
585       if test -d "$local_tmp" ; then
586           $2="$local_tmp"
587       else
588           $2=$1
589       fi
590    else
591       $2=$1
592    fi
593    dnl Check for space in the directory
594    if test `echo $1|cut -d' ' -f1` != $1 ; then
595        AC_MSG_ERROR($1 directory shall not contain any space.)
596    fi
597 else
598    AC_MSG_ERROR($1 shall be a valid directory)
599 fi
600])
601
602
603dnl  MPFR_C_LONG_DOUBLE_FORMAT
604dnl  -------------------------
605dnl  Determine the format of a long double.
606dnl
607dnl  The object file is grepped, so as to work when cross compiling.  A
608dnl  start and end sequence is included to avoid false matches, and
609dnl  allowance is made for the desired data crossing an "od -b" line
610dnl  boundary.  The test number is a small integer so it should appear
611dnl  exactly, no rounding or truncation etc.
612dnl
613dnl  "od -b" is supported even by Unix V7, and the awk script used doesn't
614dnl  have functions or anything, so even an "old" awk should suffice.
615dnl
616dnl  The 10-byte IEEE extended format is generally padded to either 12 or 16
617dnl  bytes for alignment purposes.  The SVR4 i386 ABI is 12 bytes, or i386
618dnl  gcc -m128bit-long-double selects 16 bytes.  IA-64 is 16 bytes in LP64
619dnl  mode, or 12 bytes in ILP32 mode.  The first 10 bytes is the relevant
620dnl  part in all cases (big and little endian).
621dnl
622dnl  Enhancements:
623dnl
624dnl  Could match more formats, but no need to worry until there's code
625dnl  wanting to use them.
626dnl
627dnl  Don't want to duplicate the double matching from GMP_C_DOUBLE_FORMAT,
628dnl  perhaps we should merge with that macro, to match data formats
629dnl  irrespective of the C type in question.  Or perhaps just let the code
630dnl  use DOUBLE macros when sizeof(double)==sizeof(long double).
631
632AC_DEFUN([MPFR_C_LONG_DOUBLE_FORMAT],
633[AC_REQUIRE([AC_PROG_CC])
634AC_REQUIRE([AC_PROG_AWK])
635AC_REQUIRE([AC_OBJEXT])
636AC_CHECK_TYPES([long double])
637AC_CACHE_CHECK([format of `long double' floating point],
638                mpfr_cv_c_long_double_format,
639[mpfr_cv_c_long_double_format=unknown
640if test "$ac_cv_type_long_double" != yes; then
641  mpfr_cv_c_long_double_format="not available"
642else
643  cat >conftest.c <<\EOF
644[
645/* "before" is 16 bytes to ensure there's no padding between it and "x".
646   We're not expecting any "long double" bigger than 16 bytes or with
647   alignment requirements stricter than 16 bytes.  */
648struct {
649  char         before[16];
650  long double  x;
651  char         after[8];
652} foo = {
653  { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
654    '\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
655  -123456789.0,
656  { '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' }
657};
658]
659EOF
660  mpfr_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AS_MESSAGE_LOG_FD 2>&1"
661  if AC_TRY_EVAL(mpfr_compile); then
662    cat >conftest.awk <<\EOF
663[
664BEGIN {
665  found = 0
666}
667
668# got[] holds a sliding window of bytes read the input.  got[0] is the most
669# recent byte read, and got[31] the oldest byte read, so when looking to
670# match some data the indices are "reversed".
671#
672{
673  for (f = 2; f <= NF; f++)
674    {
675      # new byte, shift others up
676      for (i = 31; i >= 0; i--)
677        got[i+1] = got[i];
678      got[0] = $f;
679
680      # end sequence
681      if (got[7] != "376") continue
682      if (got[6] != "334") continue
683      if (got[5] != "272") continue
684      if (got[4] != "230") continue
685      if (got[3] != "166") continue
686      if (got[2] != "124") continue
687      if (got[1] != "062") continue
688      if (got[0] != "020") continue
689
690      # start sequence, with 8-byte body
691      if (got[23] == "001" && \
692          got[22] == "043" && \
693          got[21] == "105" && \
694          got[20] == "147" && \
695          got[19] == "211" && \
696          got[18] == "253" && \
697          got[17] == "315" && \
698          got[16] == "357")
699        {
700          saw = " (" got[15] \
701                 " " got[14] \
702                 " " got[13] \
703                 " " got[12] \
704                 " " got[11] \
705                 " " got[10] \
706                 " " got[9]  \
707                 " " got[8] ")"
708
709          if (got[15] == "301" && \
710              got[14] == "235" && \
711              got[13] == "157" && \
712              got[12] == "064" && \
713              got[11] == "124" && \
714              got[10] == "000" && \
715              got[9] ==  "000" && \
716              got[8] ==  "000")
717            {
718              print "IEEE double, big endian"
719              found = 1
720              exit
721            }
722
723          if (got[15] == "000" && \
724              got[14] == "000" && \
725              got[13] == "000" && \
726              got[12] == "124" && \
727              got[11] == "064" && \
728              got[10] == "157" && \
729              got[9] ==  "235" && \
730              got[8] ==  "301")
731            {
732              print "IEEE double, little endian"
733              found = 1
734              exit
735            }
736        }
737
738      # start sequence, with 12-byte body
739      if (got[27] == "001" && \
740          got[26] == "043" && \
741          got[25] == "105" && \
742          got[24] == "147" && \
743          got[23] == "211" && \
744          got[22] == "253" && \
745          got[21] == "315" && \
746          got[20] == "357")
747        {
748          saw = " (" got[19] \
749                 " " got[18] \
750                 " " got[17] \
751                 " " got[16] \
752                 " " got[15] \
753                 " " got[14] \
754                 " " got[13] \
755                 " " got[12] \
756                 " " got[11] \
757                 " " got[10] \
758                 " " got[9]  \
759                 " " got[8] ")"
760
761          if (got[19] == "000" && \
762              got[18] == "000" && \
763              got[17] == "000" && \
764              got[16] == "000" && \
765              got[15] == "240" && \
766              got[14] == "242" && \
767              got[13] == "171" && \
768              got[12] == "353" && \
769              got[11] == "031" && \
770              got[10] == "300")
771            {
772              print "IEEE extended, little endian"
773              found = 1
774              exit
775            }
776
777          if (got[19] == "300" && \
778              got[18] == "031" && \
779              got[17] == "000" && \
780              got[16] == "000" && \
781              got[15] == "353" && \
782              got[14] == "171" && \
783              got[13] == "242" && \
784              got[12] == "240" && \
785              got[11] == "000" && \
786              got[10] == "000" && \
787              got[09] == "000" && \
788              got[08] == "000")
789            {
790              # format found on m68k
791              print "IEEE extended, big endian"
792              found = 1
793              exit
794            }
795        }
796
797      # start sequence, with 16-byte body
798      if (got[31] == "001" && \
799          got[30] == "043" && \
800          got[29] == "105" && \
801          got[28] == "147" && \
802          got[27] == "211" && \
803          got[26] == "253" && \
804          got[25] == "315" && \
805          got[24] == "357")
806        {
807          saw = " (" got[23] \
808                 " " got[22] \
809                 " " got[21] \
810                 " " got[20] \
811                 " " got[19] \
812                 " " got[18] \
813                 " " got[17] \
814                 " " got[16] \
815                 " " got[15] \
816                 " " got[14] \
817                 " " got[13] \
818                 " " got[12] \
819                 " " got[11] \
820                 " " got[10] \
821                 " " got[9]  \
822                 " " got[8] ")"
823
824          if (got[23] == "000" && \
825              got[22] == "000" && \
826              got[21] == "000" && \
827              got[20] == "000" && \
828              got[19] == "240" && \
829              got[18] == "242" && \
830              got[17] == "171" && \
831              got[16] == "353" && \
832              got[15] == "031" && \
833              got[14] == "300")
834            {
835              print "IEEE extended, little endian"
836              found = 1
837              exit
838            }
839
840          if (got[23] == "300" && \
841              got[22] == "031" && \
842              got[21] == "326" && \
843              got[20] == "363" && \
844              got[19] == "105" && \
845              got[18] == "100" && \
846              got[17] == "000" && \
847              got[16] == "000" && \
848              got[15] == "000" && \
849              got[14] == "000" && \
850              got[13] == "000" && \
851              got[12] == "000" && \
852              got[11] == "000" && \
853              got[10] == "000" && \
854              got[9]  == "000" && \
855              got[8]  == "000")
856            {
857              # format used on HP 9000/785 under HP-UX
858              print "IEEE quad, big endian"
859              found = 1
860              exit
861            }
862
863          if (got[23] == "000" && \
864              got[22] == "000" && \
865              got[21] == "000" && \
866              got[20] == "000" && \
867              got[19] == "000" && \
868              got[18] == "000" && \
869              got[17] == "000" && \
870              got[16] == "000" && \
871              got[15] == "000" && \
872              got[14] == "000" && \
873              got[13] == "100" && \
874              got[12] == "105" && \
875              got[11] == "363" && \
876              got[10] == "326" && \
877              got[9]  == "031" && \
878	      got[8]  == "300")
879            {
880              print "IEEE quad, little endian"
881              found = 1
882              exit
883            }
884
885          if (got[23] == "301" && \
886              got[22] == "235" && \
887              got[21] == "157" && \
888              got[20] == "064" && \
889              got[19] == "124" && \
890              got[18] == "000" && \
891              got[17] == "000" && \
892              got[16] == "000" && \
893              got[15] == "000" && \
894              got[14] == "000" && \
895              got[13] == "000" && \
896              got[12] == "000" && \
897              got[11] == "000" && \
898              got[10] == "000" && \
899              got[9]  == "000" && \
900              got[8]  == "000")
901            {
902              # format used on 32-bit PowerPC (Mac OS X and Debian GNU/Linux)
903              print "possibly double-double, big endian"
904              found = 1
905              exit
906            }
907        }
908    }
909}
910
911END {
912  if (! found)
913    print "unknown", saw
914}
915]
916EOF
917    mpfr_cv_c_long_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
918    case $mpfr_cv_c_long_double_format in
919    unknown*)
920      echo "cannot match anything, conftest.$OBJEXT contains" >&AS_MESSAGE_LOG_FD
921      od -b conftest.$OBJEXT >&AS_MESSAGE_LOG_FD
922      ;;
923    esac
924  else
925    AC_MSG_WARN([oops, cannot compile test program])
926  fi
927fi
928rm -f conftest*
929])
930
931AH_VERBATIM([HAVE_LDOUBLE],
932[/* Define one of the following to 1 for the format of a `long double'.
933   If your format is not among these choices, or you don't know what it is,
934   then leave all undefined.
935   IEEE_EXT is the 10-byte IEEE extended precision format.
936   IEEE_QUAD is the 16-byte IEEE quadruple precision format.
937   LITTLE or BIG is the endianness.  */
938#undef HAVE_LDOUBLE_IEEE_EXT_LITTLE
939#undef HAVE_LDOUBLE_IEEE_QUAD_BIG])
940
941case $mpfr_cv_c_long_double_format in
942  "IEEE extended, little endian")
943    AC_DEFINE(HAVE_LDOUBLE_IEEE_EXT_LITTLE, 1)
944    ;;
945  "IEEE quad, big endian")
946    AC_DEFINE(HAVE_LDOUBLE_IEEE_QUAD_BIG, 1)
947    ;;
948  "IEEE quad, little endian")
949    AC_DEFINE(HAVE_LDOUBLE_IEEE_QUAD_LITTLE, 1)
950    ;;
951  "possibly double-double, big endian")
952    AC_MSG_WARN([This format is known on GCC/PowerPC platforms,])
953    AC_MSG_WARN([but due to GCC PR26374, we can't test further.])
954    AC_MSG_WARN([You can safely ignore this warning, though.])
955    # Since we are not sure, we do not want to define a macro.
956    ;;
957  unknown* | "not available")
958    ;;
959  *)
960    AC_MSG_WARN([oops, unrecognised float format: $mpfr_cv_c_long_double_format])
961    ;;
962esac
963])
964
965
966dnl  MPFR_CHECK_LIBM
967dnl  ---------------
968dnl  Determine a math library -lm to use.
969
970AC_DEFUN([MPFR_CHECK_LIBM],
971[AC_REQUIRE([AC_CANONICAL_HOST])
972AC_SUBST(MPFR_LIBM,'')
973case $host in
974  *-*-beos* | *-*-cygwin* | *-*-pw32*)
975    # According to libtool AC CHECK LIBM, these systems don't have libm
976    ;;
977  *-*-solaris*)
978    # On Solaris the math functions new in C99 are in -lm9x.
979    # FIXME: Do we need -lm9x as well as -lm, or just instead of?
980    AC_CHECK_LIB(m9x, main, MPFR_LIBM="-lm9x")
981    AC_CHECK_LIB(m,   main, MPFR_LIBM="$MPFR_LIBM -lm")
982    ;;
983  *-ncr-sysv4.3*)
984    # FIXME: What does -lmw mean?  Libtool AC CHECK LIBM does it this way.
985    AC_CHECK_LIB(mw, _mwvalidcheckl, MPFR_LIBM="-lmw")
986    AC_CHECK_LIB(m, main, MPFR_LIBM="$MPFR_LIBM -lm")
987    ;;
988  *)
989    AC_CHECK_LIB(m, main, MPFR_LIBM="-lm")
990    ;;
991esac
992])
993
994
995dnl  MPFR_LD_SEARCH_PATHS_FIRST
996dnl  --------------------------
997
998AC_DEFUN([MPFR_LD_SEARCH_PATHS_FIRST],
999[case "$LD $LDFLAGS" in
1000  *-Wl,-search_paths_first*) ;;
1001  *) AC_MSG_CHECKING([if the compiler understands -Wl,-search_paths_first])
1002     saved_LDFLAGS="$LDFLAGS"
1003     LDFLAGS="-Wl,-search_paths_first $LDFLAGS"
1004     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1005       [AC_MSG_RESULT(yes)],
1006       [AC_MSG_RESULT(no)]
1007        LDFLAGS="$saved_LDFLAGS")
1008     ;;
1009 esac
1010])
1011
1012
1013dnl  GMP_C_ATTRIBUTE_MODE
1014dnl  --------------------
1015dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
1016dnl  Needed for mpfr-longlong.h; this is currently necessary for s390.
1017dnl
1018dnl  TODO: Replace this with a cleaner type size detection, as this
1019dnl  solution only works with gcc and assumes CHAR_BIT == 8. Probably use
1020dnl  <stdint.h>, and <http://gcc.gnu.org/viewcvs/trunk/config/stdint.m4>
1021dnl  as a fallback.
1022
1023AC_DEFUN([GMP_C_ATTRIBUTE_MODE],
1024[AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
1025               gmp_cv_c_attribute_mode,
1026[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[typedef int SItype __attribute__ ((mode (SI)));]], [[]])],
1027 gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
1028])
1029if test $gmp_cv_c_attribute_mode = yes; then
1030 AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
1031 [Define to 1 if the compiler accepts gcc style __attribute__ ((mode (XX)))])
1032fi
1033])
1034
1035
1036dnl  MPFR_FUNC_GMP_PRINTF_SPEC
1037dnl  ------------------------------------
1038dnl  MPFR_FUNC_GMP_PRINTF_SPEC(spec, type, [includes], [if-true], [if-false])
1039dnl  Check if gmp_sprintf supports the conversion specification 'spec'
1040dnl  with type 'type'.
1041dnl  Expand 'if-true' if printf supports 'spec', 'if-false' otherwise.
1042
1043AC_DEFUN([MPFR_FUNC_GMP_PRINTF_SPEC],[
1044AC_MSG_CHECKING(if gmp_printf supports "%$1")
1045AC_RUN_IFELSE([AC_LANG_PROGRAM([[
1046#include <stdio.h>
1047#include <string.h>
1048$3
1049#include <gmp.h>
1050]], [[
1051  char s[256];
1052  $2 a = 17;
1053
1054  if (gmp_sprintf (s, "(%0.0$1)(%d)", a, 42) == -1) return 1;
1055  return (strcmp (s, "(17)(42)") != 0);
1056]])],
1057  [AC_MSG_RESULT(yes)
1058  $4],
1059  [AC_MSG_RESULT(no)
1060  $5],
1061  [AC_MSG_RESULT(cross-compiling, assuming yes)
1062  $4])
1063])
1064
1065
1066dnl MPFR_CHECK_PRINTF_SPEC
1067dnl ----------------------
1068dnl Check if gmp_printf supports some optional length modifiers.
1069dnl Defined symbols are negative to shorten the gcc command line.
1070
1071AC_DEFUN([MPFR_CHECK_PRINTF_SPEC], [
1072AC_REQUIRE([MPFR_CONFIGS])dnl
1073if test "$ac_cv_type_intmax_t" = yes; then
1074 MPFR_FUNC_GMP_PRINTF_SPEC([jd], [intmax_t], [
1075#ifdef HAVE_INTTYPES_H
1076# include <inttypes.h>
1077#endif
1078#ifdef HAVE_STDINT_H
1079# include <stdint.h>
1080#endif
1081         ],,
1082         [AC_DEFINE([NPRINTF_J], 1, [gmp_printf cannot read intmax_t])])
1083fi
1084
1085MPFR_FUNC_GMP_PRINTF_SPEC([hhd], [char], [
1086#include <gmp.h>
1087         ],,
1088         [AC_DEFINE([NPRINTF_HH], 1, [gmp_printf cannot use `hh' length modifier])])
1089
1090MPFR_FUNC_GMP_PRINTF_SPEC([lld], [long long int], [
1091#include <gmp.h>
1092         ],,
1093         [AC_DEFINE([NPRINTF_LL], 1, [gmp_printf cannot read long long int])])
1094
1095MPFR_FUNC_GMP_PRINTF_SPEC([Lf], [long double], [
1096#include <gmp.h>
1097         ],,
1098         [AC_DEFINE([NPRINTF_L], 1, [gmp_printf cannot read long double])])
1099
1100MPFR_FUNC_GMP_PRINTF_SPEC([td], [ptrdiff_t], [
1101#if defined (__cplusplus)
1102#include <cstddef>
1103#else
1104#include <stddef.h>
1105#endif
1106#include <gmp.h>
1107    ],,
1108    [AC_DEFINE([NPRINTF_T], 1, [gmp_printf cannot read ptrdiff_t])])
1109])
1110