configure.ac revision 1.1.1.3
1dnl Process this file with autoconf to produce a configure script.
2
3dnl WARNING! C code starting with # (preprocessor directives) must not
4dnl be indented!
5
6AC_COPYRIGHT([
7Copyright 1999-2018 Free Software Foundation, Inc.
8Contributed by the AriC and Caramba projects, INRIA.
9
10This file is part of the GNU MPFR Library.
11
12The GNU MPFR Library is free software; you can redistribute it and/or modify
13it under the terms of the GNU Lesser General Public License as published
14by the Free Software Foundation; either version 3 of the License, or (at
15your option) any later version.
16
17The GNU MPFR Library is distributed in the hope that it will be useful, but
18WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20License for more details.
21
22You should have received a copy of the GNU Lesser General Public License
23along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
24http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
2551 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26])
27
28dnl Add check-news when it checks for more than 15 lines
29AC_INIT([MPFR],[4.0.1])
30
31dnl Older Automake versions than 1.13 may still be supported, but no longer
32dnl tested, and many things have changed in 1.13. Moreover the INSTALL file
33dnl and MPFR manual assume that MPFR has been built using Automake 1.13+
34dnl (due to parallel tests, introduced by default in Automake 1.13).
35AM_INIT_AUTOMAKE([1.13 no-define dist-bzip2 dist-xz dist-zip])
36AM_MAINTAINER_MODE(enable)
37
38AC_CONFIG_MACRO_DIR([m4])
39
40dnl FIXME: Several AC_RUN_IFELSE programs can return several values
41dnl (one for each format to be detected), but the Autoconf manual says:
42dnl "This exit status might be that of a failed compilation, or it might
43dnl be that of a failed program execution." Unfortunately, we cannot
44dnl know whether a non-zero exit status comes from a failed compilation,
45dnl so that the detection may be incorrect. To avoid this problem, write
46dnl a test program for each possible format? Alternatively, the test
47dnl program could output the result of the format detection to a file
48dnl and return with the 0 exit status if it could do that successfully.
49
50test_CFLAGS=${CFLAGS+set}
51
52dnl Check if user request its CC and CFLAGS
53if test -n "$CFLAGS" || test -n "$CC" ; then
54 user_redefine_cc=yes
55fi
56
57dnl Basic Autoconf macros. At this point, they must not make Autoconf
58dnl choose a compiler because of the CC and CFLAGS setup from gmp.h!
59
60AC_CANONICAL_HOST
61
62AC_PROG_EGREP
63AC_PROG_SED
64
65dnl To use a separate config header.
66dnl There is still some problem with GMP's HAVE_CONFIG
67dnl AC_CONFIG_HEADERS([mpfrconf.h:mpfrconf.in])
68
69dnl Extra arguments to configure
70
71unset gmp_lib_path GMP_CFLAGS GMP_CC
72
73AC_ARG_WITH(gmp_include,
74   [  --with-gmp-include=DIR  GMP include directory ],
75   MPFR_PARSE_DIRECTORY(["$withval"],[withval])
76   CPPFLAGS="$CPPFLAGS -I$withval")
77
78AC_ARG_WITH(gmp_lib,
79   [  --with-gmp-lib=DIR      GMP lib directory ], [
80   MPFR_PARSE_DIRECTORY(["$withval"],[withval])
81   LDFLAGS="$LDFLAGS -L$withval"
82   gmp_lib_path="$withval"
83  ])
84
85AC_ARG_WITH(gmp,
86   [  --with-gmp=DIR          GMP install directory ], [
87   MPFR_PARSE_DIRECTORY(["$withval"],[withval])
88   if test -z "$with_gmp_lib" && test -z "$with_gmp_include" ; then
89      CPPFLAGS="$CPPFLAGS -I$withval/include"
90      LDFLAGS="$LDFLAGS -L$withval/lib"
91      gmp_lib_path="$withval/lib"
92   else
93      AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.])
94   fi
95  ])
96
97AC_ARG_WITH(gmp_build,
98   [  --with-gmp-build=DIR    GMP build directory (please read INSTALL file)],
99   [
100   MPFR_PARSE_DIRECTORY(["$withval"],[withval])
101   if test -z "$gmp_lib_path" && test -z "$with_gmp_include" ; then
102      CPPFLAGS="$CPPFLAGS -I$withval -I$withval/tune"
103      LDFLAGS="$LDFLAGS -L$withval -L$withval/.libs -L$withval/tune"
104      gmp_lib_path="$withval$PATH_SEPARATOR$withval/.libs$PATH_SEPARATOR$withval/tune"
105      if test -r $withval/Makefile ; then
106         GMP_CFLAGS=`$SED -n 's/^CFLAGS = //p' $withval/Makefile`
107         GMP_CC=`$SED -n 's/^CC = //p' $withval/Makefile`
108         GMP_SOURCE=`$SED -n 's/^srcdir = *//p' $withval/Makefile`
109         case "$GMP_SOURCE" in
110           .)  GMP_SOURCE="" ;;
111           /*) ;;
112           ?*) GMP_SOURCE="$withval/$GMP_SOURCE" ;;
113         esac
114         if test -d "$GMP_SOURCE" ; then
115            CPPFLAGS="$CPPFLAGS -I$GMP_SOURCE -I$GMP_SOURCE/tune"
116         fi
117      fi
118      use_gmp_build=yes
119   else
120      AC_MSG_FAILURE([Do not use --with-gmp-build and other --with-gmp options simultaneously.])
121   fi
122   ])
123
124AC_ARG_WITH(mulhigh_size,
125   [  --with-mulhigh-size=NUM internal threshold table for mulhigh],
126   AC_DEFINE_UNQUOTED([MPFR_MULHIGH_SIZE],$withval, [Mulhigh size]))
127
128AC_ARG_ENABLE(gmp-internals,
129   [  --enable-gmp-internals  enable use of GMP undocumented functions [[default=no]]],
130   [ case $enableval in
131      yes) AC_DEFINE([WANT_GMP_INTERNALS],1,[Want GMP internals]) ;;
132      no)  ;;
133      *) AC_MSG_ERROR([bad value for --enable-gmp-internals: yes or no]) ;;
134     esac])
135
136AC_ARG_ENABLE(assert,
137   [  --enable-assert         enable ASSERT checking [[default=no]]],
138   [ case $enableval in
139      yes) AC_DEFINE([MPFR_WANT_ASSERT],1,[Want all simple assertions]) ;;
140      none) AC_DEFINE([MPFR_WANT_ASSERT],-1,[Do no want any assertion]) ;;
141      no)  ;;
142      full) AC_DEFINE([MPFR_WANT_ASSERT],2,[Want full assertions]) ;;
143      *) AC_MSG_ERROR([bad value for --enable-assert: yes, no, none or full]) ;;
144     esac])
145
146AC_ARG_ENABLE(logging,
147   [  --enable-logging        enable MPFR logging (the system must support it)
148                          [[default=no]]],
149   [ case $enableval in
150      yes) AC_DEFINE([MPFR_USE_LOGGING],1,[Enable MPFR logging support]) ;;
151      no)  ;;
152      *)   AC_MSG_ERROR([bad value for --enable-logging: yes or no]) ;;
153     esac])
154
155AC_ARG_ENABLE(thread-safe,
156   [  --disable-thread-safe   explicitly disable TLS support
157  --enable-thread-safe    build MPFR as thread safe, i.e. with TLS support
158                          (the system must support it) [[default=autodetect]]],
159   [ case $enableval in
160      yes) ;;
161      no)  ;;
162      *)   AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
163     esac])
164
165AC_ARG_ENABLE(shared-cache,
166   [  --enable-shared-cache   enable use of caches shared by all threads,
167                          for all MPFR constants.  It usually makes MPFR
168                          dependent on PTHREAD [[default=no]]],
169   [ case $enableval in
170      yes) mpfr_want_shared_cache=yes
171         AC_DEFINE([WANT_SHARED_CACHE],1,[Want shared cache]) ;;
172      no)  ;;
173      *) AC_MSG_ERROR([bad value for --enable-shared-cache: yes or no]) ;;
174     esac])
175
176AC_ARG_ENABLE(warnings,
177   [  --enable-warnings       allow MPFR to output warnings to stderr [[default=no]]],
178   [ case $enableval in
179      yes) AC_DEFINE([MPFR_USE_WARNINGS],1,[Allow MPFR to output warnings to stderr]) ;;
180      no)  ;;
181      *)   AC_MSG_ERROR([bad value for --enable-warnings: yes or no]) ;;
182     esac])
183
184AC_ARG_ENABLE(tests-timeout,
185   [  --enable-tests-timeout=NUM
186                          [[for developers]] enable timeout for test programs
187                          (NUM seconds, <= 9999) [[default=no]]; if this is
188                          enabled, the environment variable $MPFR_TESTS_TIMEOUT
189                          overrides NUM (0: no timeout)],
190   [ case $enableval in
191      no)   ;;
192      yes)  AC_DEFINE([MPFR_TESTS_TIMEOUT], 0, [timeout limit]) ;;
193      [[0-9]]|[[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]][[0-9]])
194       AC_DEFINE_UNQUOTED([MPFR_TESTS_TIMEOUT], $enableval, [timeout limit]) ;;
195      *)    AC_MSG_ERROR([bad value for --enable-tests-timeout]) ;;
196     esac])
197
198AC_ARG_ENABLE(tune-for-coverage,
199   [  --enable-tune-for-coverage
200                          [[for developers]] tune MPFR for coverage tests],
201   [ case $enableval in
202      no)   ;;
203      yes)  AC_DEFINE([MPFR_TUNE_COVERAGE], 1, [tune for coverage]) ;;
204      *)    AC_MSG_ERROR([bad value for --enable-tune-for-coverage]) ;;
205     esac])
206
207
208dnl
209dnl Setup CC and CFLAGS
210dnl
211
212dnl ********************************************************************
213dnl Check for CC and CFLAGS in gmp.h
214
215dnl Warning! The following tests must be done before Autoconf selects
216dnl a compiler. This means that some macros such as AC_PROG_CC and
217dnl AM_PROG_AR must be put after the following code.
218
219if test -z "$user_redefine_cc" && test "$cross_compiling" != yes ; then
220
221dnl We need to guess the C preprocessor instead of using AC_PROG_CPP,
222dnl since AC_PROG_CPP implies AC_PROG_CC, which chooses a compiler
223dnl (before we have the chance to get it from gmp.h) and does some
224dnl checking related to this compiler (such as dependency tracking
225dnl options); if the compiler changes due to __GMP_CC in gmp.h, one
226dnl would have incorrect settings.
227dnl FIXME: Move this in acinclude.m4 ?
228if test -z "$GMP_CC$GMP_CFLAGS" ; then
229   AC_MSG_CHECKING(for CC and CFLAGS in gmp.h)
230   GMP_CC=__GMP_CC
231   GMP_CFLAGS=__GMP_CFLAGS
232   # /lib/cpp under Solaris doesn't support some environment variables
233   # used by GCC, such as C_INCLUDE_PATH. If the user has set up such
234   # environment variables, he probably wants to use them. So, let us
235   # prefer cpp and gcc to /lib/cpp. However, note that this won't
236   # work if GCC has been installed with versioned names only (e.g.
237   # with cpp-5 and gcc-5).
238   for cpp in "cpp -P" "cpp" "gcc -P -E" "gcc -E" "/lib/cpp -P" "/lib/cpp" "cc -P -E" "cc -E" "c99 -P -E" "c99 -E" "clang -E" "cl -E" "icl -E"
239   do
240     # Get CC
241     echo "#include \"gmp.h\"" > conftest.c
242     echo "MPFR_OPTION __GMP_CC" >> conftest.c
243     $cpp $CPPFLAGS conftest.c 2> /dev/null > conftest.txt
244     test $? -ne 0 && continue
245     GMP_CC=`$EGREP MPFR_OPTION conftest.txt | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
246     # Get CFLAGS
247     echo "#include \"gmp.h\"" >  conftest.c
248     echo "MPFR_OPTION __GMP_CFLAGS" >> conftest.c
249     unset rmpedantic
250     [test "$enable_logging" = yes && rmpedantic='s/[ "]-pedantic[ "]/ /g;']
251     $cpp $CPPFLAGS conftest.c 2> /dev/null > conftest.txt
252     test $? -ne 0 && continue
253     GMP_CFLAGS=`$EGREP MPFR_OPTION conftest.txt | $SED -e "$rmpedantic"'s/MPFR_OPTION //g;s/ *" *//g'`
254     break
255   done
256   rm -f conftest*
257   if test "x$GMP_CC" = "x__GMP_CC" || test "x$GMP_CFLAGS" = "x__GMP_CFLAGS" ; then
258      AC_MSG_RESULT(failed)
259      GMP_CFLAGS=
260      GMP_CC=
261   else
262      AC_MSG_RESULT([CC=$GMP_CC CFLAGS=$GMP_CFLAGS])
263   fi
264fi
265
266dnl But these variables may be invalid, so we must check them first.
267dnl Note: we do not use AC_RUN_IFELSE, as it implies AC_PROG_CC.
268if test -n "$GMP_CC$GMP_CFLAGS" ; then
269   AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
270   echo "int main (void) { return 0; }" > conftest.c
271   if $GMP_CC $GMP_CFLAGS -o conftest conftest.c 2> /dev/null ; then
272     AC_MSG_RESULT(yes)
273     CFLAGS=$GMP_CFLAGS
274     CC=$GMP_CC
275   else
276     AC_MSG_RESULT(no)
277   fi
278   rm -f conftest*
279fi
280
281fi
282
283dnl ********************************************************************
284
285AC_PROG_CC
286AC_PROG_CPP
287AC_LANG(C)
288
289dnl AM_PROG_AR is needed so that ar-lib (wrapper for Microsoft lib.exe)
290dnl gets installed by "automake -i" (if absent, "automake --warnings=all"
291dnl gives a warning).
292AM_PROG_AR
293
294dnl This must done before MPFR_CONFIGS.
295LT_INIT(win32-dll)
296
297dnl Try to determine the double format
298AC_MSG_CHECKING(format of `double' floating point)
299AC_RUN_IFELSE([AC_LANG_PROGRAM([[
300]], [[
301union ieee_double_extract
302{
303  double d;
304  unsigned char x[8];
305} t;
306t.d = 2.877939254133025759330166692961938679218292236328125; /* exact */
307if (sizeof (double) != 8)
308   return 0;
309if (sizeof (unsigned char) != 1)
310   return 0;
311if (t.x[0] == 1 && t.x[1] == 2 && t.x[2] == 3 && t.x[3] == 4 &&
312    t.x[4] == 5 && t.x[5] == 6 && t.x[6] == 7 && t.x[7] == 64)
313   return 1; /* little endian */
314else if (t.x[7] == 1 && t.x[6] == 2 && t.x[5] == 3 && t.x[4] == 4 &&
315    t.x[3] == 5 && t.x[2] == 6 && t.x[1] == 7 && t.x[0] == 64)
316   return 2; /* big endian */
317else
318   return 0; /* unknown */
319]])],
320   [mpfr_ieee_double=$?],
321   [mpfr_ieee_double=$?],
322   [mpfr_ieee_double=0])
323case "$mpfr_ieee_double" in
324  1) AC_MSG_RESULT([IEEE little endian])
325     AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_ENDIAN) ;;
326  2) AC_MSG_RESULT([IEEE big endian])
327     AC_DEFINE(HAVE_DOUBLE_IEEE_BIG_ENDIAN) ;;
328  *) AC_MSG_WARN([format of `double' floating-point not recognized]) ;;
329esac
330
331dnl For GCC, _Decimal64 was introduced in GCC 4.3 for some targets
332dnl (note that it is not guaranteed to be available because it may
333dnl be disabled in the GCC build). See:
334dnl   https://gcc.gnu.org/gcc-4.3/changes.html
335dnl _Decimal64 is not yet defined in GCC for C++:
336dnl   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51364
337dnl _Decimal64 support is broken with GCC 4.6.3 and 4.7.2 on powerpc64
338dnl with the mode32 ABI, e.g. "-m32 -mpowerpc64 -mtune=970 -O3"; this
339dnl is detected by the x != x test below.
340AC_ARG_ENABLE(decimal-float,
341   [  --disable-decimal-float explicitly disable decimal floats support
342  --enable-decimal-float  build conversion functions from/to decimal floats
343                          [[default=autodetect]]],
344   [ case $enableval in
345      yes) ;;
346      no)  ;;
347      *)   AC_MSG_ERROR([bad value for --enable-decimal-float: yes or no]) ;;
348     esac])
349
350dnl GCC >= 4.3 provides __float128, but since this is not standard,
351dnl the default is "autodetect" and not "yes"
352AC_ARG_ENABLE(float128,
353   [  --disable-float128      explicitly disable __float128 support
354  --enable-float128       build conversion functions from/to __float128
355                          [[default=autodetect]]],
356   [ case $enableval in
357      yes) ;;
358      no)  ;;
359      *)   AC_MSG_ERROR([bad value for --enable-float128: yes or no]) ;;
360     esac])
361
362test_libgmp=__gmpz_init
363
364AC_ARG_ENABLE(mini-gmp,
365   [  --enable-mini-gmp       build MPFR with mini-gmp (experimental) [[default=no]]],
366   [ case $enableval in
367      yes) AC_DEFINE([MPFR_USE_MINI_GMP],1,[Use mini-gmp])
368           # With mini-gmp, mp_limb_t is always unsigned long.
369           AC_COMPUTE_INT(nettle_cv_gmp_numb_bits, [(sizeof(unsigned long) * CHAR_BIT)],
370              [#include <limits.h>],
371              [AC_MSG_FAILURE([cannot find value of GMP_NUMB_BITS])])
372           AC_MSG_RESULT([$nettle_cv_gmp_numb_bits bits])
373           AC_DEFINE_UNQUOTED([GMP_NUMB_BITS], $nettle_cv_gmp_numb_bits, [number of bits in a limb])
374           AC_DEFINE([GMP_NAIL_BITS], 0, [number of nails in a limb])
375           test_libgmp=mpz_init;;
376      no)  ;;
377      *) AC_MSG_ERROR([bad value for --enable-mini-gmp: yes or no]) ;;
378     esac])
379
380AC_ARG_ENABLE(debug-prediction,
381   [  --enable-debug-prediction
382                          [[for developers]] enable debug of branch prediction
383                          (for x86 and x86-64 with GCC, static libs)],
384   [ case $enableval in
385      yes)  if test "$enable_shared" != no; then
386              AC_MSG_ERROR([--enable-debug-prediction can only work in static mode (--disable-shared)])
387            fi
388            AC_DEFINE([MPFR_DEBUG_PREDICTION],1,
389	       [Enable debug of branch prediction]) ;;
390      no)   ;;
391      *)    AC_MSG_ERROR([bad value for --enable-debug-prediction: yes or no]) ;;
392     esac])
393
394AC_ARG_ENABLE(lto,
395   [  --enable-lto            build MPFR with link-time-optimization
396                          (experimental) [[default: no]]],
397   [ case $enableval in
398      yes)  if test "$enable_shared" != "no"; then
399              AC_MSG_ERROR([--enable-lto can only work in static mode (--disable-shared)])
400            fi
401            enable_lto=yes
402            ;;
403      no)   ;;
404      *)    AC_MSG_ERROR([bad value for --enable-lto: yes or no]) ;;
405     esac])
406
407dnl Check if compiler is ICC, and if such a case, disable GCC
408dnl And add some specific flags.
409dnl Don't add Warnings Flags (Otherwise you'll get more than 20000 warnings).
410dnl Add -long_double flags? Don't use -pc64 !
411dnl Notes (VL):
412dnl   * With icc 10.1 20080212 on itanium, the __ICC macro is not defined,
413dnl     even when the -icc option is used (contrary to what is documented
414dnl     on the icc man page).
415dnl   * When ICC is correctly detected (__ICC macro defined), unsetting
416dnl     the GCC variable confuses libtool. See:
417dnl       https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=485421
418dnl   * If need be, the gcc predefined macros __GNUC_* can be disabled
419dnl     thanks to the -no-gcc option.
420dnl   * Now use -mieee-fp instead of -mp (ICC 13 says: option '-mp' is
421dnl     deprecated and will be removed in a future release.). According
422dnl     to "icc -help", both options are equivalent; it also suggests
423dnl     to use -fp-model <arg> instead of -mp, but what is <arg>? Anyway
424dnl     -mieee-fp solves the tset_d failure due to a negative zero. This
425dnl     option has been introduced in ICC 9.0 for Linux (2005-06):
426dnl     http://www.ncsa.illinois.edu/UserInfo/Resources/Software/Intel/Compilers/9.0/C_ReleaseNotes.htm
427AC_MSG_CHECKING(for ICC)
428AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
429#if !defined(__ICC)
430# error "Not ICC"
431error
432#endif
433]], [[]])],[
434 AC_MSG_RESULT(yes)
435 CFLAGS="-fp_port -mieee-fp -wd1572 -wd265 -wd186 -wd239 $CFLAGS"
436],[AC_MSG_RESULT(no)])
437
438dnl If compiler is gcc, then use some specific flags.
439dnl But don't touch user other flags.
440if test "$test_CFLAGS" != set && test -n "$GCC"; then
441  CFLAGS="-Wpointer-arith $CFLAGS"
442  AC_MSG_CHECKING(whether the selected language is C++)
443  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
444#if defined (__cplusplus)
445# error "C++"
446error
447#endif
448  ]], [[]])],[
449    AC_MSG_RESULT(no)
450    CFLAGS="-Wmissing-prototypes $CFLAGS"
451  ],[
452    AC_MSG_RESULT(yes)
453    CFLAGS="-Wmissing-declarations -Wno-sign-compare $CFLAGS"
454  ])
455  CFLAGS="-Wall $CFLAGS"
456fi
457
458AM_PROG_CC_C_O
459
460case $host in
461  *-apple-darwin*)
462dnl This allows to take the first GMP library in the library paths,
463dnl whether it is dynamic or static. This behavior is more sensible,
464dnl in particular because it is the only way to link with a version
465dnl only available in static form when another version is available
466dnl in dynamic, and also for consistency, because the compiler will
467dnl take the first gmp.h found in the include paths (so, we need to
468dnl take a library that corresponds to this header file). This is a
469dnl common problem with darwin.
470    MPFR_LD_SEARCH_PATHS_FIRST ;;
471esac
472
473AC_C_CONST
474AC_C_VOLATILE
475dnl Determine the endianness of integer. But since MPFR doesn't use
476dnl AC_CONFIG_HEADERS, configure cannot provide such information for
477dnl universal binaries containing variants with different endianness
478dnl (i.e. generic code must be used).
479AC_C_BIGENDIAN([AC_DEFINE(HAVE_BIG_ENDIAN)],[AC_DEFINE(HAVE_LITTLE_ENDIAN)],
480[true],[true])
481
482MPFR_CONFIGS
483
484# (Based on GMP 5.1)
485# clock_gettime is in librt on *-*-osf5.1 and on glibc < 2.17, so add -lrt to
486# TUNE_LIBS if needed (e.g. if clock_gettime is not already in the C library).
487# On linux (tested on x86_32, 2.6.26), clock_getres reports ns accuracy,
488# while in a quick test on osf, clock_getres said only 1 millisecond.
489old_LIBS="$LIBS"
490AC_SEARCH_LIBS(clock_gettime, rt, [
491  AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define to 1 if you have the `clock_gettime' function])])
492TUNE_LIBS="$LIBS"
493LIBS="$old_LIBS"
494AC_SUBST(TUNE_LIBS)
495
496dnl
497dnl Setup GMP detection
498dnl
499
500dnl Check GMP Header
501AC_MSG_CHECKING(for gmp.h)
502AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
503#include "gmp.h"
504]])],[AC_MSG_RESULT(yes)],[
505 AC_MSG_RESULT(no)
506 AC_MSG_ERROR([gmp.h can't be found, or is unusable.])
507])
508
509dnl Configs for Windows DLLs.
510dnl libtool requires "-no-undefined" for win32 dll
511dnl
512dnl "-Wl,output-def" is used to get a .def file for use by MS lib to make
513dnl a .lib import library, described in the manual.
514dnl
515dnl Incidentally, libtool does generate an import library libmpfr.dll.a,
516dnl but it's "ar" format and cannot be used by the MS linker.  There
517dnl doesn't seem to be any GNU tool for generating or converting to .lib.
518dnl
519dnl The DLL version (the number in libmpfr-*.dll.def below) must be the
520dnl version of the oldest supported interface (i.e. CURRENT - AGE in
521dnl src/Makefile.am).
522AC_SUBST(MPFR_LDFLAGS)
523AC_SUBST(LIBMPFR_LDFLAGS)
524case $host in
525  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
526   AC_MSG_CHECKING(for DLL/static GMP)
527   if test "$enable_shared" = yes; then
528     MPFR_LDFLAGS="$MPFR_LDFLAGS -no-undefined"
529     LIBMPFR_LDFLAGS="$LIBMPFR_LDFLAGS -Wl,--output-def,.libs/libmpfr-6.dll.def"
530     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
531#include "gmp.h"
532#if !__GMP_LIBGMP_DLL
533# error "Dead man"
534error
535#endif
536     ]], [[]])],[AC_MSG_RESULT(DLL)],[
537  AC_MSG_RESULT(static)
538  AC_MSG_ERROR([libgmp isn't provided as a DLL: use --enable-static --disable-shared]) ])
539   else
540     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
541#include "gmp.h"
542#if __GMP_LIBGMP_DLL
543# error "Dead man"
544error
545#endif
546     ]], [[]])],[AC_MSG_RESULT(static)],[
547  AC_MSG_RESULT(DLL)
548  AC_MSG_ERROR([libgmp is provided as a DLL: use --disable-static --enable-shared]) ])
549  fi
550  ;;
551esac
552
553dnl Under Linux, make sure that the old dtags are used if LD_LIBRARY_PATH
554dnl is defined. The issue is that with the new dtags, LD_LIBRARY_PATH has
555dnl the precedence over the run path, so that if a compatible MPFR library
556dnl is installed in some directory from $LD_LIBRARY_PATH, then the tested
557dnl MPFR library will be this library instead of the MPFR library from the
558dnl build tree. Other OS with the same issue might be added later.
559dnl
560dnl References:
561dnl   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=859732
562dnl   http://lists.gnu.org/archive/html/libtool/2017-05/msg00000.html
563dnl
564dnl We need to check whether --disable-new-dtags is supported as alternate
565dnl linkers may be used (e.g., with tcc: CC=tcc LD=tcc).
566dnl
567case $host in
568  *-*-linux*)
569    if test -n "$LD_LIBRARY_PATH"; then
570      saved_LDFLAGS="$LDFLAGS"
571      LDFLAGS="$LDFLAGS -Wl,--disable-new-dtags"
572      AC_MSG_CHECKING(whether --disable-new-dtags is supported by the linker)
573      AC_LINK_IFELSE([AC_LANG_SOURCE([[
574int main (void) { return 0; }
575      ]])],
576      [AC_MSG_RESULT(yes (use it since LD_LIBRARY_PATH is set))],
577      [AC_MSG_RESULT(no)
578       LDFLAGS="$saved_LDFLAGS"
579      ])
580    fi
581    ;;
582esac
583
584dnl
585dnl For mpfr-longlong.h - TODO: should be replaced (see acinclude.m4).
586dnl
587
588GMP_C_ATTRIBUTE_MODE
589
590
591dnl
592dnl Setup GMP detection (continued)
593dnl
594
595dnl Check minimal GMP version
596dnl We only guarantee that with a *functional* and recent enough GMP version,
597dnl MPFR will compile; we do not guarantee that GMP will compile.
598dnl In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
599dnl (at least on 64-bit Core 2 under Linux),
600dnl see <https://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html>.
601if test -z "$enable_mini_gmp" ; then
602  AC_MSG_CHECKING(for recent GMP)
603  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
604#include "gmp.h"
605#if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 500)
606# error "GMP 5.0.0 or newer is required"
607error
608#endif
609  ]])],[AC_MSG_RESULT(yes)],[
610   AC_MSG_RESULT(no)
611   AC_MSG_ERROR([GMP 5.0.0 or newer is required])
612])
613fi
614
615dnl Check if gmp.h is usable at link time; this may detect errors such as
616dnl with GMP 4.1, which uses "extern __inline__" unconditionally with all
617dnl GCC versions, which breaks by default with GCC 5 (this problem with
618dnl GMP 4.1 is no longer possible as we now require GMP 5.0.0 or newer,
619dnl but the same kind of problem may occur in the future).
620dnl Note: No linking is done against the GMP library at this time, as we
621dnl do not use any GMP symbol. The goal of this test is to avoid obscure
622dnl errors with the following gmp.h tests.
623AC_MSG_CHECKING(usable gmp.h at link time)
624AC_LINK_IFELSE([AC_LANG_PROGRAM([[
625#include "gmp.h"
626]],[[]])],[AC_MSG_RESULT(yes)],[
627 AC_MSG_RESULT(no)
628 AC_MSG_ERROR([there is an incompatibility between gmp.h and the compiler.
629See 'config.log' for details.])
630])
631
632dnl Check if we can use internal header files of GMP (only --with-gmp-build)
633if test "$use_gmp_build" = yes ; then
634   AC_MSG_CHECKING(for gmp internal files)
635   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
636   #include "gmp.h"
637   #include "gmp-impl.h"
638   #include "longlong.h"
639   ]])],[
640     AC_MSG_RESULT(yes)
641     AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
642   ],[
643     AC_MSG_ERROR([header files gmp-impl.h and longlong.h not found])
644   ])
645fi
646
647dnl Check for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency.
648dnl Problems may occur if gmp.h was generated with some ABI
649dnl and is used with another ABI (or if nails are used).
650dnl This test doesn't need to link with libgmp (at least it shouldn't).
651AC_MSG_CHECKING(for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency)
652AC_RUN_IFELSE([AC_LANG_PROGRAM([[
653#include <stdio.h>
654#include <limits.h>
655#include "gmp.h"
656]], [[
657  if (GMP_NUMB_BITS == sizeof(mp_limb_t) * CHAR_BIT)
658    return 0;
659  fprintf (stderr, "GMP_NUMB_BITS     = %ld\n", (long) GMP_NUMB_BITS);
660  fprintf (stderr, "sizeof(mp_limb_t) = %ld\n", (long) sizeof(mp_limb_t));
661  fprintf (stderr, "sizeof(mp_limb_t) * CHAR_BIT = %ld != GMP_NUMB_BITS\n",
662           (long) (sizeof(mp_limb_t) * CHAR_BIT));
663  return 1;
664]])], [AC_MSG_RESULT(yes)], [
665       AC_MSG_RESULT(no)
666       AC_MSG_ERROR([GMP_NUMB_BITS and sizeof(mp_limb_t) are not consistent.
667You probably need to change some of the GMP or MPFR compile options.
668See 'config.log' for details (search for GMP_NUMB_BITS).])],
669       [AC_MSG_RESULT([cannot test])])
670
671dnl Check if we can link with GMP
672AC_CHECK_LIB(gmp, $test_libgmp, [LIBS="-lgmp $LIBS"],
673 [AC_MSG_ERROR([libgmp not found or uses a different ABI (including static vs shared).
674Please read the INSTALL file -- see "In case of problem".])])
675
676dnl Check for corresponding 'gmp.h' and libgmp
677AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
678dnl We do not set LD_LIBRARY_PATH, as it is not possible to set it just
679dnl before the test program is run, and we do not want to affect other
680dnl programs (such as the compiler), because the behavior could be
681dnl incorrect and even have security implications.
682dnl WARNING! LD_RUN_PATH is not taken into account by the GNU gold ld,
683dnl e.g. from binutils-gold 2.22-5 under Debian; see
684dnl   https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660813
685if test -z "$enable_mini_gmp" ; then
686  saved_LD_RUN_PATH="$LD_RUN_PATH"
687  LD_RUN_PATH="${LD_RUN_PATH:+$LD_RUN_PATH$PATH_SEPARATOR}$gmp_lib_path"
688  export LD_RUN_PATH
689  AC_RUN_IFELSE([AC_LANG_PROGRAM([[
690#include <stdio.h>
691#include <string.h>
692#include "gmp.h"
693  ]], [[
694  char buffer[100];
695  sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
696           __GNU_MP_VERSION_PATCHLEVEL);
697  printf ("(%s/%s) ", buffer, gmp_version);
698  fflush (stdout);
699  /* Also put information in config.log (stderr) */
700  fprintf (stderr, "gmp.h: %s / libgmp: %s\n", buffer, gmp_version);
701  if (strcmp (buffer, gmp_version) == 0)
702    return 0;
703  if (__GNU_MP_VERSION_PATCHLEVEL != 0)
704    return 1;
705  sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
706  return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
707  ]])],
708   [AC_MSG_RESULT(yes)
709    MPFR_CHECK_GMP
710    MPFR_CHECK_DBL2INT_BUG
711    MPFR_CHECK_PRINTF_SPEC],
712   [AC_MSG_RESULT(no)
713    AC_MSG_WARN([==========================================================])
714    AC_MSG_WARN(['gmp.h' and 'libgmp' seem to have different versions or])
715    AC_MSG_WARN([we cannot run a program linked with GMP (if you cannot])
716    AC_MSG_WARN([see the version numbers above). A cause may be different])
717    AC_MSG_WARN([GMP versions with different ABI's or the use of --with-gmp])
718    AC_MSG_WARN([or --with-gmp-include with a system include directory])
719    AC_MSG_WARN([(such as /usr/include or /usr/local/include).])
720    AC_MSG_WARN([However since we can't use 'libtool' inside the configure,])
721    AC_MSG_WARN([we can't be sure. See 'config.log' for details.])
722    AC_MSG_WARN([CC="$CC"])
723    AC_MSG_WARN([CFLAGS="$CFLAGS"])
724    AC_MSG_WARN([CPPFLAGS="$CPPFLAGS"])
725    AC_MSG_WARN([LDFLAGS="$LDFLAGS"])
726    AC_MSG_WARN([LIBS="$LIBS"])
727    AC_MSG_WARN([Temporary LD_RUN_PATH was "$LD_RUN_PATH".])
728    AC_MSG_WARN([==========================================================])
729    ],AC_MSG_RESULT([cannot test])
730  )
731  LD_RUN_PATH="$saved_LD_RUN_PATH"
732fi
733
734dnl __gmpn_sbpi1_divappr_q is an internal GMP symbol; thus its behavior
735dnl may change or this symbol may be removed in the future (without being
736dnl handled by the library versioning system, which is even worse, as this
737dnl can mean undetected incompatibilities in case of GMP library upgrade,
738dnl without rebuilding MPFR). So, this symbol must not be used, unless
739dnl WANT_GMP_INTERNALS is defined. Only the GMP public API should be used
740dnl by default, in particular by binary distributions. Moreover the check
741dnl below may yield an incorrect result as libtool isn't used in configure
742dnl (see above).
743AC_CHECK_FUNCS([__gmpn_sbpi1_divappr_q])
744dnl same for other GMP internal functions
745AC_CHECK_FUNCS([__gmpn_invert_limb])
746AC_CHECK_FUNCS([__gmpn_rsblsh_n])
747
748MPFR_CHECK_MP_LIMB_T_VS_LONG
749
750dnl The getrusage function is needed for MPFR bench (cf tools/bench)
751AC_CHECK_FUNCS([getrusage])
752
753dnl Remove also many MACROS (AC_DEFINE) which are unused by MPFR
754dnl and polluate (and slow down because libtool has to parse them) the build.
755if test -f confdefs.h; then
756  $SED '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
757  $SED '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
758  $SED '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
759  $SED '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
760  $SED '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
761  $SED '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
762  $SED '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
763  $SED '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
764  $SED '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
765  $SED '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
766  $SED '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
767  $SED '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
768  $SED '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
769  $SED '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
770  $SED '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp
771
772  mv confdefs.tmp confdefs.h
773fi
774
775if $EGREP -q -e '-dev$' $srcdir/VERSION; then
776  AC_SUBST([DATAFILES])dnl
777  DATAFILES=`echo \`$SED -n \
778    's/^ *data_check *("\(data\/[[^"]]*\)".*/tests\/\1/p' \
779    $srcdir/tests/*.c\``
780fi
781
782dnl Output
783AC_CONFIG_FILES([Makefile mpfr.pc doc/Makefile src/Makefile tests/Makefile tune/Makefile src/mparam.h:src/mparam_h.in tools/bench/Makefile])
784AC_OUTPUT
785
786dnl NEWS README AUTHORS Changelog
787