beta-0.89.2
[luatex.git] / source / libs / mpfr / mpfr-3.1.3 / configure.ac
blob50535c7964d4329c083d3cd2ae5d228cb9cc247d
1 dnl Process this file with autoconf to produce a configure script.
3 AC_COPYRIGHT([
4 Copyright 1999-2015 Free Software Foundation, Inc.
5 Contributed by the AriC and Caramel projects, INRIA.
7 This file is part of the GNU MPFR Library.
9 The GNU MPFR Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 3 of the License, or (at
12 your option) any later version.
14 The GNU MPFR Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
21 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
22 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 dnl Add check-news when it checks for more than 15 lines
26 AC_INIT([MPFR],[3.1.3])
28 dnl Older Automake versions than 1.13 may still be supported, but no longer
29 dnl tested, and many things have changed in 1.13. Moreover the INSTALL file
30 dnl and MPFR manual assume that MPFR has been built using Automake 1.13+
31 dnl (due to parallel tests, introduced by default in Automake 1.13).
32 AM_INIT_AUTOMAKE([1.13 no-define dist-bzip2 dist-xz dist-zip])
33 AM_MAINTAINER_MODE(enable)
35 AC_CONFIG_MACRO_DIR([m4])
37 dnl FIXME: The AC_ARG_ENABLE(decimal-float...) part does things too
38 dnl early, even when this option is not used. In particular, it must
39 dnl be put after AC_PROG_CC; another problem is that the GMP CFLAGS
40 dnl and CC check may modify the compiler.
42 test_CFLAGS=${CFLAGS+set}
44 dnl Check if user request its CC and CFLAGS
45 if test -n "$CFLAGS" || test -n "$CC" ; then
46  user_redefine_cc=yes
49 dnl Basic Autoconf macros. At this point, they must not make Autoconf
50 dnl choose a compiler because of the CC and CFLAGS setup from gmp.h!
52 AC_CANONICAL_HOST
54 AC_PROG_EGREP
55 AC_PROG_SED
57 dnl To use a separate config header.
58 dnl There is still some problem with GMP's HAVE_CONFIG
59 dnl AC_CONFIG_HEADERS([mpfrconf.h:mpfrconf.in])
61 dnl Extra arguments to configure
62 unset gmp_lib_path GMP_CFLAGS GMP_CC
63 AC_ARG_WITH(gmp_include,
64    [  --with-gmp-include=DIR  GMP include directory ],
65    MPFR_PARSE_DIRECTORY(["$withval"],[withval])
66    CPPFLAGS="$CPPFLAGS -I$withval")
67 AC_ARG_WITH(gmp_lib,
68    [  --with-gmp-lib=DIR      GMP lib directory ], [
69    MPFR_PARSE_DIRECTORY(["$withval"],[withval])
70    LDFLAGS="$LDFLAGS -L$withval"
71    gmp_lib_path="$withval"
72   ])
73 AC_ARG_WITH(gmp,
74    [  --with-gmp=DIR          GMP install directory ], [
75    MPFR_PARSE_DIRECTORY(["$withval"],[withval])
76    if test -z "$with_gmp_lib" && test -z "$with_gmp_include" ; then
77       CPPFLAGS="$CPPFLAGS -I$withval/include"
78       LDFLAGS="$LDFLAGS -L$withval/lib"
79       gmp_lib_path="$withval/lib"
80    else
81       AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.])
82    fi
83   ])
85 AC_ARG_WITH(gmp_build,
86    [  --with-gmp-build=DIR    GMP build directory (please read INSTALL file)],
87    [
88    MPFR_PARSE_DIRECTORY(["$withval"],[withval])
89    if test -z "$gmp_lib_path" && test -z "$with_gmp_include" ; then
90       CPPFLAGS="$CPPFLAGS -I$withval -I$withval/tune"
91       LDFLAGS="$LDFLAGS -L$withval -L$withval/.libs -L$withval/tune"
92       gmp_lib_path="$withval$PATH_SEPARATOR$withval/.libs$PATH_SEPARATOR$withval/tune"
93       if test -r $withval/Makefile ; then
94          GMP_CFLAGS=`$SED -n 's/^CFLAGS = //p' $withval/Makefile`
95          GMP_CC=`$SED -n 's/^CC = //p' $withval/Makefile`
96          GMP_SOURCE=`$SED -n 's/^srcdir = *//p' $withval/Makefile`
97          case "$GMP_SOURCE" in
98            .)  GMP_SOURCE="" ;;
99            /*) ;;
100            ?*) GMP_SOURCE="$withval/$GMP_SOURCE" ;;
101          esac
102          if test -d "$GMP_SOURCE" ; then
103             CPPFLAGS="$CPPFLAGS -I$GMP_SOURCE -I$GMP_SOURCE/tune"
104          fi
105       fi
106       use_gmp_build=yes
107    else
108       AC_MSG_FAILURE([Do not use --with-gmp-build and other --with-gmp options simultaneously.])
109    fi
110    ])
112 AC_ARG_WITH(mulhigh_size,
113    [  --with-mulhigh-size=NUM internal threshold table for mulhigh],
114    AC_DEFINE_UNQUOTED([MPFR_MULHIGH_SIZE],$withval, [Mulhigh size]))
116 AC_ARG_ENABLE(gmp-internals,
117    [  --enable-gmp-internals  enable use of GMP undocumented functions [[default=no]]],
118    [ case $enableval in
119       yes) AC_DEFINE([WANT_GMP_INTERNALS],1,[Want GMP internals]) ;;
120       no)  ;;
121       *) AC_MSG_ERROR([bad value for --enable-gmp-internals: yes or no]) ;;
122      esac])
124 AC_ARG_ENABLE(assert,
125    [  --enable-assert         enable ASSERT checking [[default=no]]],
126    [ case $enableval in
127       yes) AC_DEFINE([MPFR_WANT_ASSERT],1,[Want assertion]) ;;
128       no)  ;;
129       full) AC_DEFINE([MPFR_WANT_ASSERT],2,[Want assertion]) ;;
130       *) AC_MSG_ERROR([bad value for --enable-assert: yes, no or full]) ;;
131      esac])
132 AC_ARG_ENABLE(logging,
133    [  --enable-logging        enable MPFR logging (the system must support it)
134                           [[default=no]]],
135    [ case $enableval in
136       yes) AC_DEFINE([MPFR_USE_LOGGING],1,[Log what MPFR does]) ;;
137       no)  ;;
138       *)   AC_MSG_ERROR([bad value for --enable-logging: yes or no]) ;;
139      esac])
140 AC_ARG_ENABLE(thread-safe,
141    [  --disable-thread-safe   explicitly disable TLS support
142   --enable-thread-safe    build MPFR as thread safe, i.e. with TLS support
143                           (the system must support it) [[default=autodetect]]],
144    [ case $enableval in
145       yes) ;;
146       no)  ;;
147       *)   AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
148      esac])
149 AC_ARG_ENABLE(warnings,
150    [  --enable-warnings       allow MPFR to output warnings to stderr [[default=no]]],
151    [ case $enableval in
152       yes) AC_DEFINE([MPFR_USE_WARNINGS],1,[Allow MPFR to output warnings to stderr]) ;;
153       no)  ;;
154       *)   AC_MSG_ERROR([bad value for --enable-warnings: yes or no]) ;;
155      esac])
157 AC_ARG_ENABLE(tests-timeout,
158    [  --enable-tests-timeout=NUM    enable timeout (NUM seconds) for test programs
159                           (NUM <= 9999) [[default=no]]; if enabled, env variable
160                           $MPFR_TESTS_TIMEOUT overrides NUM (0: no timeout).],
161    [ case $enableval in
162       no)   ;;
163       yes)  AC_DEFINE([MPFR_TESTS_TIMEOUT], 0, [timeout limit]) ;;
164       [[0-9]]|[[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]][[0-9]])
165        AC_DEFINE_UNQUOTED([MPFR_TESTS_TIMEOUT], $enableval, [timeout limit]) ;;
166       *)    AC_MSG_ERROR([bad value for --enable-tests-timeout]) ;;
167      esac])
171 dnl Setup CC and CFLAGS
174 dnl ********************************************************************
175 dnl Check for CC and CFLAGS in gmp.h
177 dnl Warning! The following tests must be done before Autoconf selects
178 dnl a compiler. This means that some macros such as AC_PROG_CC and
179 dnl AM_PROG_AR must be put after the following code.
181 if test -z "$user_redefine_cc" && test "$cross_compiling" != yes ; then
183 dnl We need to guess the C preprocessor instead of using AC_PROG_CPP,
184 dnl since AC_PROG_CPP implies AC_PROG_CC, which chooses a compiler
185 dnl (before we have the chance to get it from gmp.h) and does some
186 dnl checking related to this compiler (such as dependency tracking
187 dnl options); if the compiler changes due to __GMP_CC in gmp.h, one
188 dnl would have incorrect settings.
189 dnl FIXME: Move this in aclocal ?
190 if test -z "$GMP_CC$GMP_CFLAGS" ; then
191    AC_MSG_CHECKING(for CC and CFLAGS in gmp.h)
192    GMP_CC=__GMP_CC
193    GMP_CFLAGS=__GMP_CFLAGS
194    # /lib/cpp under Solaris doesn't support some environment variables
195    # used by GCC, such as C_INCLUDE_PATH. If the user has set up such
196    # environment variables, he probably wants to use them. So, let us
197    # prefer cpp and gcc to /lib/cpp.
198    for cpp in cpp gcc /lib/cpp cc c99
199    do
200      case $cpp in
201        *cpp*) ;;
202        *) cpp="$cpp -E" ;;
203      esac
204      echo foo > conftest.c
205      if $cpp $CPPFLAGS conftest.c > /dev/null 2> /dev/null ; then
206        # Get CC
207        echo "#include \"gmp.h\"" >  conftest.c
208        echo "MPFR_OPTION __GMP_CC"           >> conftest.c
209        GMP_CC=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
210        # Get CFLAGS
211        echo "#include \"gmp.h\"" >  conftest.c
212        echo "MPFR_OPTION __GMP_CFLAGS"           >> conftest.c
213        unset rmpedantic
214        [test "$enable_logging" = yes && rmpedantic='s/[ "]-pedantic[ "]/ /g;']
215        GMP_CFLAGS=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e "$rmpedantic"'s/MPFR_OPTION //g;s/ *" *//g'`
216        break
217      fi
218    done
219    rm -f conftest*
220    if test "x$GMP_CC" = "x__GMP_CC" || test "x$GMP_CFLAGS" = "x__GMP_CFLAGS" ; then
221       AC_MSG_RESULT(no)
222       GMP_CFLAGS=
223       GMP_CC=
224    else
225       AC_MSG_RESULT(yes [CC=$GMP_CC CFLAGS=$GMP_CFLAGS])
226    fi
229 dnl But these variables may be invalid, so we must check them first.
230 dnl Note: we do not use AC_RUN_IFELSE, as it implies AC_PROG_CC.
231 if test -n "$GMP_CC$GMP_CFLAGS" ; then
232    AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
233    echo "int main (void) { return 0; }" > conftest.c
234    if $GMP_CC $GMP_CFLAGS -o conftest conftest.c 2> /dev/null ; then
235      AC_MSG_RESULT(yes)
236      CFLAGS=$GMP_CFLAGS
237      CC=$GMP_CC
238    else
239      AC_MSG_RESULT(no)
240    fi
241    rm -f conftest*
246 dnl ********************************************************************
248 AC_PROG_CC
249 AC_PROG_CPP
250 AC_LANG(C)
252 dnl Support unusual archivers.
253 AM_PROG_AR
255 dnl For GCC, _Decimal64 was introduced in GCC 4.3 for some targets
256 dnl (note that it is not guaranteed to be available because it may
257 dnl be disabled in the GCC build). See:
258 dnl   https://gcc.gnu.org/gcc-4.3/changes.html
259 dnl _Decimal64 is not yet defined in GCC for C++:
260 dnl   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51364
261 dnl _Decimal64 support is broken with GCC 4.6.3 and 4.7.2 on powerpc64
262 dnl with the mode32 ABI, e.g. "-m32 -mpowerpc64 -mtune=970 -O3"; this
263 dnl is detected by the x != x test below.
264 AC_ARG_ENABLE(decimal-float,
265    [  --enable-decimal-float  build conversion functions from/to decimal floats
266                           [[default=no]]],
267    [ case $enableval in
268       yes) AC_DEFINE([MPFR_WANT_DECIMAL_FLOATS],1,
269               [Build decimal float functions])
270            AC_MSG_CHECKING(if compiler knows _Decimal64)
271            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[_Decimal64 x;]])],
272               [AC_MSG_RESULT(yes)
273                if test "$use_gmp_build" != yes ; then
274                   AC_MSG_ERROR([decimal float support requires --with-gmp-build])
275                fi
276                AC_MSG_CHECKING(if _GMP_IEEE_FLOATS is defined)
277                AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
278 #include "gmp.h"
279 #include "gmp-impl.h"
280 #ifndef _GMP_IEEE_FLOATS
281 #error "_GMP_IEEE_FLOATS is not defined"
282 #endif]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
283                   AC_MSG_ERROR([decimal float support requires _GMP_IEEE_FLOATS])])
284               ],
285               [AC_MSG_RESULT(no)
286 AC_MSG_ERROR([Compiler doesn't know _Decimal64 (ISO/IEC TR 24732).
287 Please use another compiler or build MPFR without --enable-decimal-float.])]
288            )
289            AC_MSG_CHECKING(decimal float format)
290            AC_RUN_IFELSE([AC_LANG_PROGRAM([[
291 #include <stdlib.h>
292 ]], [[
293 volatile _Decimal64 x = 1;
294 union { double d; _Decimal64 d64; } y;
295 if (x != x) return 3;
296 y.d64 = 1234567890123456.0dd;
297 return y.d == 0.14894469406741037E-123 ? 0 :
298        y.d == 0.59075095508629822E-68  ? 1 : 2;
299 ]])], [AC_MSG_RESULT(DPD)
300        AC_DEFINE([DPD_FORMAT],1,[])],
301       [case "$?" in
302          1) AC_MSG_RESULT(BID) ;;
303          2) AC_MSG_FAILURE(neither DPD nor BID) ;;
304          3) AC_MSG_FAILURE([_Decimal64 support is broken.
305 Please use another compiler or build MPFR without --enable-decimal-float.]) ;;
306          *) AC_MSG_FAILURE(internal error) ;;
307        esac],
308       [AC_MSG_RESULT(assuming DPD)
309        AC_DEFINE([DPD_FORMAT],1,[])])
310            ;;
311       no)  ;;
312       *)   AC_MSG_ERROR([bad value for --enable-decimal-float: yes or no]) ;;
313      esac])
315 dnl Check if compiler is ICC, and if such a case, disable GCC
316 dnl And add some specific flags.
317 dnl Don't add Warnings Flags (Otherwise you'll get more than 20000 warnings).
318 dnl Add -long_double flags? Don't use -pc64 !
319 dnl Notes (VL):
320 dnl   * With icc 10.1 20080212 on itanium, the __ICC macro is not defined,
321 dnl     even when the -icc option is used (contrary to what is documented
322 dnl     on the icc man page).
323 dnl   * When ICC is correctly detected (__ICC macro defined), unsetting
324 dnl     the GCC variable confuses libtool. See:
325 dnl       https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=485421
326 dnl   * If need be, the gcc predefined macros __GNUC_* can be disabled
327 dnl     thanks to the -no-gcc option.
328 AC_MSG_CHECKING(for ICC)
329 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
330 #if !defined(__ICC)
331 # error "ICC Not Found"
332 error
333 #endif
334 ]], [[]])],[
335  AC_MSG_RESULT(yes)
336  CFLAGS="-fp_port -mp -wd1572 -wd265 -wd186 -wd239 $CFLAGS"
337 ],[AC_MSG_RESULT(no)])
339 dnl If compiler is gcc, then use some specific flags.
340 dnl But don't touch user other flags.
341 if test "$test_CFLAGS" != set && test -n "$GCC"; then
342   CFLAGS="-Wpointer-arith $CFLAGS"
343   AC_MSG_CHECKING(whether the selected language is C++)
344   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
345 #if defined (__cplusplus)
346 # error "C++"
347 error
348 #endif
349   ]], [[]])],[
350     AC_MSG_RESULT(no)
351     CFLAGS="-Wmissing-prototypes $CFLAGS"
352   ],[
353     AC_MSG_RESULT(yes)
354     CFLAGS="-Wmissing-declarations -Wno-sign-compare $CFLAGS"
355   ])
356   CFLAGS="-Wall $CFLAGS"
359 AM_PROG_CC_C_O
361 case $host in
362   *-apple-darwin*)
363 dnl This allows to take the first GMP library in the library paths,
364 dnl whether it is dynamic or static. This behavior is more sensible,
365 dnl in particular because it is the only way to link with a version
366 dnl only available in static form when another version is available
367 dnl in dynamic, and also for consistency, because the compiler will
368 dnl take the first gmp.h found in the include paths (so, we need to
369 dnl take a library that corresponds to this header file). This is a
370 dnl common problem with darwin.
371     MPFR_LD_SEARCH_PATHS_FIRST ;;
372 esac
374 AC_C_CONST
375 AC_C_VOLATILE
376 MPFR_CONFIGS
378 # (Based on GMP 5.1)
379 # clock_gettime is in librt on *-*-osf5.1 and on glibc < 2.17, so add -lrt to
380 # TUNE_LIBS if needed (e.g. if clock_gettime is not already in the C library).
381 # On linux (tested on x86_32, 2.6.26), clock_getres reports ns accuracy,
382 # while in a quick test on osf, clock_getres said only 1 millisecond.
383 old_LIBS="$LIBS"
384 AC_SEARCH_LIBS(clock_gettime, rt, [
385   AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define to 1 if you have the `clock_gettime' function])])
386 TUNE_LIBS="$LIBS"
387 LIBS="$old_LIBS"
388 AC_SUBST(TUNE_LIBS)
391 dnl Setup GMP detection
394 dnl Check GMP Header
395 AC_MSG_CHECKING(for gmp.h)
396 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
397 #include "gmp.h"
398 ]])],[AC_MSG_RESULT(yes)],[
399  AC_MSG_RESULT(no)
400  AC_MSG_ERROR([gmp.h can't be found, or is unusable.])
403 dnl Configs for Windows DLLs.
404 dnl libtool requires "-no-undefined" for win32 dll
405 dnl It also disables the tests involving the linking with LIBGMP if DLL
407 dnl "-Wl,output-def" is used to get a .def file for use by MS lib to make
408 dnl a .lib import library, described in the manual.
410 dnl Incidentally, libtool does generate an import library libmpfr.dll.a,
411 dnl but it's "ar" format and cannot be used by the MS linker.  There
412 dnl doesn't seem to be any GNU tool for generating or converting to .lib.
413 AC_SUBST(MPFR_LDFLAGS)
414 AC_SUBST(LIBMPFR_LDFLAGS)
415 LT_INIT(win32-dll)
416 case $host in
417   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
418    AC_MSG_CHECKING(for DLL/static GMP)
419    if test "$enable_shared" = yes; then
420      MPFR_LDFLAGS="$MPFR_LDFLAGS -no-undefined"
421      LIBMPFR_LDFLAGS="$LIBMPFR_LDFLAGS -Wl,--output-def,.libs/libmpfr-4.dll.def"
422      dont_link_with_gmp="yes"
423      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
424 #include "gmp.h"
425 #if !__GMP_LIBGMP_DLL
426 # error "Dead man"
427 error
428 #endif
429      ]], [[]])],[AC_MSG_RESULT(DLL)],[
430   AC_MSG_RESULT(static)
431   AC_MSG_ERROR([gmp.h isn't a DLL: use --enable-static --disable-shared]) ])
432    else
433      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
434 #include "gmp.h"
435 #if __GMP_LIBGMP_DLL
436 # error "Dead man"
437 error
438 #endif
439      ]], [[]])],[AC_MSG_RESULT(static)],[
440   AC_MSG_RESULT(DLL)
441   AC_MSG_ERROR([gmp.h is a DLL: use --disable-static --enable-shared]) ])
442   fi
443   ;;
444 esac
448 dnl For mpfr-longlong.h - TODO: should be replaced (see acinclude.m4).
451 GMP_C_ATTRIBUTE_MODE
455 dnl Setup GMP detection (continued)
458 dnl Check minimal GMP version
459 dnl We only guarantee that with a *functional* and recent enough GMP version,
460 dnl MPFR will compile; we do not guarantee that GMP will compile.
461 dnl In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
462 dnl (at least on 64-bit Core 2 under Linux),
463 dnl see http://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html.
464 AC_MSG_CHECKING(for recent GMP)
465 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
466 #include "gmp.h"
467 #if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410)
468 # error "min GMP version is 4.1.0"
469 error
470 #endif
471 ]])],[AC_MSG_RESULT(yes)],[
472  AC_MSG_RESULT(no)
473  AC_MSG_ERROR([GMP 4.1.0 min required])
476 dnl Check if we can use internal header files of GMP (only --with-gmp-build)
477 if test "$use_gmp_build" = yes ; then
478    AC_MSG_CHECKING(for gmp internal files)
479    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
480    #include "gmp.h"
481    #include "gmp-impl.h"
482    #include "longlong.h"
483    ]])],[
484      AC_MSG_RESULT(yes)
485      AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
486    ],[
487      AC_MSG_ERROR([header files gmp-impl.h and longlong.h not found])
488    ])
491 dnl Check for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency.
492 dnl Problems may occur if gmp.h was generated with some ABI
493 dnl and is used with another ABI (or if nails are used).
494 dnl This test doesn't need to link with libgmp (at least it shouldn't).
495 AC_MSG_CHECKING(for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency)
496 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
497 #include <stdio.h>
498 #include <limits.h>
499 #include "gmp.h"
500 ]], [[
501   if (GMP_NUMB_BITS == sizeof(mp_limb_t) * CHAR_BIT)
502     return 0;
503   fprintf (stderr, "GMP_NUMB_BITS     = %ld\n", (long) GMP_NUMB_BITS);
504   fprintf (stderr, "sizeof(mp_limb_t) = %ld\n", (long) sizeof(mp_limb_t));
505   fprintf (stderr, "sizeof(mp_limb_t) * CHAR_BIT = %ld != GMP_NUMB_BITS\n",
506            (long) (sizeof(mp_limb_t) * CHAR_BIT));
507   return 1;
508 ]])], [AC_MSG_RESULT(yes)], [
509        AC_MSG_RESULT(no)
510        AC_MSG_ERROR([GMP_NUMB_BITS and sizeof(mp_limb_t) are not consistent.
511 You probably need to change some of the GMP or MPFR compile options.
512 See 'config.log' for details (search for GMP_NUMB_BITS).])],
513        [AC_MSG_RESULT([can't test])])
516 dnl We really need to link using libtool. But it is impossible with the current
517 dnl libtool.
518 dnl The practical problems appear only under MS Windows since the library name
519 dnl is libgmp-3 (due to libtool versionning). The best solution
520 dnl is to believe it works under MS-Windows.
521 if test "$dont_link_with_gmp" = yes ; then
522 LIBS="-lgmp $LIBS"
523 else
525 dnl Check if we can link with GMP
526 AC_CHECK_LIB(gmp, __gmpz_init, [LIBS="-lgmp $LIBS"],
527  [AC_MSG_ERROR(libgmp not found or uses a different ABI (including static vs shared).
528 Please read the INSTALL file -- see "In case of problem".)])
530 dnl Check for corresponding 'gmp.h' and libgmp.a
531 AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
532 dnl We do not set LD_LIBRARY_PATH, as it is not possible to set it just
533 dnl before the test program is run, and we do not want to affect other
534 dnl programs (such as the compiler), because the behavior could be
535 dnl incorrect and even have security implications.
536 dnl WARNING! LD_RUN_PATH is not taken into account by the GNU gold ld,
537 dnl e.g. from binutils-gold 2.22-5 under Debian; see
538 dnl   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660813
539 saved_LD_RUN_PATH="$LD_RUN_PATH"
540 LD_RUN_PATH="${LD_RUN_PATH:+$LD_RUN_PATH$PATH_SEPARATOR}$gmp_lib_path"
541 export LD_RUN_PATH
542 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
543 #include <stdio.h>
544 #include <string.h>
545 #include "gmp.h"
546 ]], [[
547   char buffer[100];
548   sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
549            __GNU_MP_VERSION_PATCHLEVEL);
550   printf ("(%s/%s) ", buffer, gmp_version);
551   if (strcmp (buffer, gmp_version) == 0)
552     return 0;
553   if (__GNU_MP_VERSION_PATCHLEVEL != 0)
554     return 1;
555   sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
556   return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
557 ]])],
558    [AC_MSG_RESULT(yes)
559     MPFR_CHECK_GMP
560     MPFR_CHECK_DBL2INT_BUG
561     MPFR_CHECK_PRINTF_SPEC],
562    [AC_MSG_RESULT(no)
563     AC_MSG_WARN([==========================================================])
564     AC_MSG_WARN(['gmp.h' and 'libgmp' seem to have different versions or])
565     AC_MSG_WARN([we cannot run a program linked with GMP (if you cannot])
566     AC_MSG_WARN([see the version numbers above). A cause may be different])
567     AC_MSG_WARN([GMP versions with different ABI's or the use of --with-gmp])
568     AC_MSG_WARN([or --with-gmp-include with a system include directory])
569     AC_MSG_WARN([(such as /usr/include or /usr/local/include).])
570     AC_MSG_WARN([However since we can't use 'libtool' inside the configure,])
571     AC_MSG_WARN([we can't be sure. See 'config.log' for details.])
572     AC_MSG_WARN([CC="$CC"])
573     AC_MSG_WARN([CFLAGS="$CFLAGS"])
574     AC_MSG_WARN([CPPFLAGS="$CPPFLAGS"])
575     AC_MSG_WARN([LDFLAGS="$LDFLAGS"])
576     AC_MSG_WARN([LIBS="$LIBS"])
577     AC_MSG_WARN([Temporary LD_RUN_PATH was "$LD_RUN_PATH".])
578     AC_MSG_WARN([==========================================================])
579     ],AC_MSG_RESULT([can not test])
581 LD_RUN_PATH="$saved_LD_RUN_PATH"
583 dnl Warning! __gmpn_rootrem is an internal GMP symbol; thus its behavior
584 dnl may change or this symbol may be removed in the future (without being
585 dnl handled by the library versioning system, which is even worse, as this
586 dnl can mean undetected incompatibilities in case of GMP library upgrade,
587 dnl without rebuilding MPFR). So, this symbol must not be used, unless
588 dnl WANT_GMP_INTERNALS is defined. Only the GMP public API should be used
589 dnl by default, in particular by binary distributions. Moreover the check
590 dnl below may yield an incorrect result as libtool isn't used in configure
591 dnl (see above).
592 dnl Same for __gmpn_sbpi1_divappr_q.
593 AC_CHECK_FUNCS([__gmpn_rootrem __gmpn_sbpi1_divappr_q])
595 dnl End of tests which need to link with GMP.
598 dnl Remove also many MACROS (AC_DEFINE) which are unused by MPFR
599 dnl and polluate (and slow down because libtool has to parse them) the build.
600 if test -f confdefs.h; then
601   $SED '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
602   $SED '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
603   $SED '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
604   $SED '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
605   $SED '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
606   $SED '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
607   $SED '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
608   $SED '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
609   $SED '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
610   $SED '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
611   $SED '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
612   $SED '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
613   $SED '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
614   $SED '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
615   $SED '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp
617   mv confdefs.tmp confdefs.h
620 if $EGREP -q -e '-dev$' $srcdir/VERSION; then
621   AC_SUBST([DATAFILES])dnl
622   DATAFILES=`echo \`$SED -n \
623     's/^ *data_check *("\(data\/[[^"]]*\)".*/tests\/\1/p' \
624     $srcdir/tests/*.c\``
627 dnl Output
628 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile tests/Makefile tune/Makefile src/mparam.h:src/mparam_h.in])
629 AC_OUTPUT
631 dnl NEWS README AUTHORS Changelog