sync with texlive
[luatex.git] / source / libs / mpfr / mpfr-src / configure.ac
blob41a3e1750f1199fa01b61aa05839dc9e18e2ea50
1 dnl Process this file with autoconf to produce a configure script.
3 AC_COPYRIGHT([
4 Copyright 1999-2016 Free Software Foundation, Inc.
5 Contributed by the AriC and Caramba 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.5])
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
406 dnl "-Wl,output-def" is used to get a .def file for use by MS lib to make
407 dnl a .lib import library, described in the manual.
409 dnl Incidentally, libtool does generate an import library libmpfr.dll.a,
410 dnl but it's "ar" format and cannot be used by the MS linker.  There
411 dnl doesn't seem to be any GNU tool for generating or converting to .lib.
412 AC_SUBST(MPFR_LDFLAGS)
413 AC_SUBST(LIBMPFR_LDFLAGS)
414 LT_INIT(win32-dll)
415 case $host in
416   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
417    AC_MSG_CHECKING(for DLL/static GMP)
418    if test "$enable_shared" = yes; then
419      MPFR_LDFLAGS="$MPFR_LDFLAGS -no-undefined"
420      LIBMPFR_LDFLAGS="$LIBMPFR_LDFLAGS -Wl,--output-def,.libs/libmpfr-4.dll.def"
421      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
422 #include "gmp.h"
423 #if !__GMP_LIBGMP_DLL
424 # error "Dead man"
425 error
426 #endif
427      ]], [[]])],[AC_MSG_RESULT(DLL)],[
428   AC_MSG_RESULT(static)
429   AC_MSG_ERROR([gmp.h isn't a DLL: use --enable-static --disable-shared]) ])
430    else
431      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
432 #include "gmp.h"
433 #if __GMP_LIBGMP_DLL
434 # error "Dead man"
435 error
436 #endif
437      ]], [[]])],[AC_MSG_RESULT(static)],[
438   AC_MSG_RESULT(DLL)
439   AC_MSG_ERROR([gmp.h is a DLL: use --disable-static --enable-shared]) ])
440   fi
441   ;;
442 esac
446 dnl For mpfr-longlong.h - TODO: should be replaced (see acinclude.m4).
449 GMP_C_ATTRIBUTE_MODE
453 dnl Setup GMP detection (continued)
456 dnl Check minimal GMP version
457 dnl We only guarantee that with a *functional* and recent enough GMP version,
458 dnl MPFR will compile; we do not guarantee that GMP will compile.
459 dnl In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
460 dnl (at least on 64-bit Core 2 under Linux),
461 dnl see http://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html.
462 AC_MSG_CHECKING(for recent GMP)
463 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
464 #include "gmp.h"
465 #if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410)
466 # error "min GMP version is 4.1.0"
467 error
468 #endif
469 ]])],[AC_MSG_RESULT(yes)],[
470  AC_MSG_RESULT(no)
471  AC_MSG_ERROR([GMP 4.1.0 min required])
474 dnl Check if gmp.h is usable at link time; this may detect errors such as
475 dnl with GMP 4.1, which uses "extern __inline__" unconditionally with all
476 dnl GCC versions, which breaks by default with GCC 5.
477 dnl Note: No linking is done against the GMP library at this time, as we
478 dnl do not use any GMP symbol. The goal of this test is to avoid obscure
479 dnl errors with the following gmp.h tests.
480 AC_MSG_CHECKING(usable gmp.h at link time)
481 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
482 #include "gmp.h"
483 ]],[[]])],[AC_MSG_RESULT(yes)],[
484  AC_MSG_RESULT(no)
485  AC_MSG_ERROR([There is an incompatibility between gmp.h and the compiler.
486 See 'config.log' for details.
487 Such an incompatibility is known between GMP 4.1, which uses
488 "extern __inline__" with all GCC versions, and GCC 5.])
491 dnl Check if we can use internal header files of GMP (only --with-gmp-build)
492 if test "$use_gmp_build" = yes ; then
493    AC_MSG_CHECKING(for gmp internal files)
494    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
495    #include "gmp.h"
496    #include "gmp-impl.h"
497    #include "longlong.h"
498    ]])],[
499      AC_MSG_RESULT(yes)
500      AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
501    ],[
502      AC_MSG_ERROR([header files gmp-impl.h and longlong.h not found])
503    ])
506 dnl Check for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency.
507 dnl Problems may occur if gmp.h was generated with some ABI
508 dnl and is used with another ABI (or if nails are used).
509 dnl This test doesn't need to link with libgmp (at least it shouldn't).
510 AC_MSG_CHECKING(for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency)
511 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
512 #include <stdio.h>
513 #include <limits.h>
514 #include "gmp.h"
515 ]], [[
516   if (GMP_NUMB_BITS == sizeof(mp_limb_t) * CHAR_BIT)
517     return 0;
518   fprintf (stderr, "GMP_NUMB_BITS     = %ld\n", (long) GMP_NUMB_BITS);
519   fprintf (stderr, "sizeof(mp_limb_t) = %ld\n", (long) sizeof(mp_limb_t));
520   fprintf (stderr, "sizeof(mp_limb_t) * CHAR_BIT = %ld != GMP_NUMB_BITS\n",
521            (long) (sizeof(mp_limb_t) * CHAR_BIT));
522   return 1;
523 ]])], [AC_MSG_RESULT(yes)], [
524        AC_MSG_RESULT(no)
525        AC_MSG_ERROR([GMP_NUMB_BITS and sizeof(mp_limb_t) are not consistent.
526 You probably need to change some of the GMP or MPFR compile options.
527 See 'config.log' for details (search for GMP_NUMB_BITS).])],
528        [AC_MSG_RESULT([cannot test])])
531 dnl Check if we can link with GMP
532 AC_CHECK_LIB(gmp, __gmpz_init, [LIBS="-lgmp $LIBS"],
533  [AC_MSG_ERROR(libgmp not found or uses a different ABI (including static vs shared).
534 Please read the INSTALL file -- see "In case of problem".)])
536 dnl Check for corresponding 'gmp.h' and libgmp.a
537 AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
538 dnl We do not set LD_LIBRARY_PATH, as it is not possible to set it just
539 dnl before the test program is run, and we do not want to affect other
540 dnl programs (such as the compiler), because the behavior could be
541 dnl incorrect and even have security implications.
542 dnl WARNING! LD_RUN_PATH is not taken into account by the GNU gold ld,
543 dnl e.g. from binutils-gold 2.22-5 under Debian; see
544 dnl   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660813
545 saved_LD_RUN_PATH="$LD_RUN_PATH"
546 LD_RUN_PATH="${LD_RUN_PATH:+$LD_RUN_PATH$PATH_SEPARATOR}$gmp_lib_path"
547 export LD_RUN_PATH
548 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
549 #include <stdio.h>
550 #include <string.h>
551 #include "gmp.h"
552 ]], [[
553   char buffer[100];
554   sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
555            __GNU_MP_VERSION_PATCHLEVEL);
556   printf ("(%s/%s) ", buffer, gmp_version);
557   if (strcmp (buffer, gmp_version) == 0)
558     return 0;
559   if (__GNU_MP_VERSION_PATCHLEVEL != 0)
560     return 1;
561   sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
562   return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
563 ]])],
564    [AC_MSG_RESULT(yes)
565     MPFR_CHECK_GMP
566     MPFR_CHECK_DBL2INT_BUG
567     MPFR_CHECK_PRINTF_SPEC],
568    [AC_MSG_RESULT(no)
569     AC_MSG_WARN([==========================================================])
570     AC_MSG_WARN(['gmp.h' and 'libgmp' seem to have different versions or])
571     AC_MSG_WARN([we cannot run a program linked with GMP (if you cannot])
572     AC_MSG_WARN([see the version numbers above). A cause may be different])
573     AC_MSG_WARN([GMP versions with different ABI's or the use of --with-gmp])
574     AC_MSG_WARN([or --with-gmp-include with a system include directory])
575     AC_MSG_WARN([(such as /usr/include or /usr/local/include).])
576     AC_MSG_WARN([However since we can't use 'libtool' inside the configure,])
577     AC_MSG_WARN([we can't be sure. See 'config.log' for details.])
578     AC_MSG_WARN([CC="$CC"])
579     AC_MSG_WARN([CFLAGS="$CFLAGS"])
580     AC_MSG_WARN([CPPFLAGS="$CPPFLAGS"])
581     AC_MSG_WARN([LDFLAGS="$LDFLAGS"])
582     AC_MSG_WARN([LIBS="$LIBS"])
583     AC_MSG_WARN([Temporary LD_RUN_PATH was "$LD_RUN_PATH".])
584     AC_MSG_WARN([==========================================================])
585     ],AC_MSG_RESULT([cannot test])
587 LD_RUN_PATH="$saved_LD_RUN_PATH"
589 dnl Warning! __gmpn_rootrem is an internal GMP symbol; thus its behavior
590 dnl may change or this symbol may be removed in the future (without being
591 dnl handled by the library versioning system, which is even worse, as this
592 dnl can mean undetected incompatibilities in case of GMP library upgrade,
593 dnl without rebuilding MPFR). So, this symbol must not be used, unless
594 dnl WANT_GMP_INTERNALS is defined. Only the GMP public API should be used
595 dnl by default, in particular by binary distributions. Moreover the check
596 dnl below may yield an incorrect result as libtool isn't used in configure
597 dnl (see above).
598 dnl Same for __gmpn_sbpi1_divappr_q.
599 AC_CHECK_FUNCS([__gmpn_rootrem __gmpn_sbpi1_divappr_q])
601 dnl Remove also many MACROS (AC_DEFINE) which are unused by MPFR
602 dnl and polluate (and slow down because libtool has to parse them) the build.
603 if test -f confdefs.h; then
604   $SED '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
605   $SED '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
606   $SED '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
607   $SED '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
608   $SED '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
609   $SED '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
610   $SED '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
611   $SED '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
612   $SED '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
613   $SED '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
614   $SED '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
615   $SED '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
616   $SED '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
617   $SED '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
618   $SED '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp
620   mv confdefs.tmp confdefs.h
623 if $EGREP -q -e '-dev$' $srcdir/VERSION; then
624   AC_SUBST([DATAFILES])dnl
625   DATAFILES=`echo \`$SED -n \
626     's/^ *data_check *("\(data\/[[^"]]*\)".*/tests\/\1/p' \
627     $srcdir/tests/*.c\``
630 dnl Output
631 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile tests/Makefile tune/Makefile src/mparam.h:src/mparam_h.in])
632 AC_OUTPUT
634 dnl NEWS README AUTHORS Changelog