1 dnl Process this file with autoconf to produce a configure script.
4 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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.2])
28 AM_INIT_AUTOMAKE([1.11 no-define dist-bzip2 dist-xz dist-zip])
29 AM_MAINTAINER_MODE(enable)
31 AC_CONFIG_MACRO_DIR([m4])
33 dnl FIXME: The AC_ARG_ENABLE(decimal-float...) part does things too
34 dnl early, even when this option is not used. In particular, it must
35 dnl be put after AC_PROG_CC; another problem is that the GMP CFLAGS
36 dnl and CC check may modify the compiler.
38 test_CFLAGS=${CFLAGS+set}
45 dnl To use a separate config header.
46 dnl There is still some problem with GMP's HAVE_CONFIG
47 dnl AC_CONFIG_HEADERS([mpfrconf.h:mpfrconf.in])
49 dnl Extra arguments to configure
50 unset gmp_lib_path GMP_CFLAGS GMP_CC
51 AC_ARG_WITH(gmp_include,
52 [ --with-gmp-include=DIR GMP include directory ],
53 CPPFLAGS="$CPPFLAGS -I$withval")
55 [ --with-gmp-lib=DIR GMP lib directory ], [
56 LDFLAGS="$LDFLAGS -L$withval"
57 gmp_lib_path="$withval"
60 [ --with-gmp=DIR GMP install directory ], [
61 if test -z "$with_gmp_lib" && test -z "$with_gmp_include" ; then
62 CPPFLAGS="$CPPFLAGS -I$withval/include"
63 LDFLAGS="$LDFLAGS -L$withval/lib"
64 gmp_lib_path="$withval/lib"
66 AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.])
70 AC_ARG_WITH(gmp_build,
71 [ --with-gmp-build=DIR GMP build directory (please read INSTALL file)],
73 if test -z "$gmp_lib_path" && test -z "$with_gmp_include" ; then
74 CPPFLAGS="$CPPFLAGS -I$withval -I$withval/tune"
75 LDFLAGS="$LDFLAGS -L$withval -L$withval/.libs -L$withval/tune"
76 gmp_lib_path="$withval$PATH_SEPARATOR$withval/.libs$PATH_SEPARATOR$withval/tune"
77 if test -r $withval/Makefile ; then
78 GMP_CFLAGS=`$SED -n 's/^CFLAGS = //p' $withval/Makefile`
79 GMP_CC=`$SED -n 's/^CC = //p' $withval/Makefile`
80 GMP_SOURCE=`$SED -n 's/^srcdir = *//p' $withval/Makefile`
84 ?*) GMP_SOURCE="$withval/$GMP_SOURCE" ;;
86 if test -d "$GMP_SOURCE" ; then
87 CPPFLAGS="$CPPFLAGS -I$GMP_SOURCE -I$GMP_SOURCE/tune"
92 AC_MSG_FAILURE([Do not use --with-gmp-build and other --with-gmp options simultaneously.])
96 AC_ARG_WITH(mulhigh_size,
97 [ --with-mulhigh-size=NUM internal threshold table for mulhigh],
98 AC_DEFINE_UNQUOTED([MPFR_MULHIGH_SIZE],$withval, [Mulhigh size]))
100 AC_ARG_ENABLE(gmp-internals,
101 [ --enable-gmp-internals enable use of GMP undocumented functions [[default=no]]],
103 yes) AC_DEFINE([WANT_GMP_INTERNALS],1,[Want GMP internals]) ;;
105 *) AC_MSG_ERROR([bad value for --enable-gmp-internals: yes or no]) ;;
108 AC_ARG_ENABLE(assert,
109 [ --enable-assert enable ASSERT checking [[default=no]]],
111 yes) AC_DEFINE([WANT_ASSERT],1,[Want assertion]) ;;
113 full) AC_DEFINE([WANT_ASSERT],2,[Want assertion]) ;;
114 *) AC_MSG_ERROR([bad value for --enable-assert: yes, no or full]) ;;
116 AC_ARG_ENABLE(logging,
117 [ --enable-logging enable MPFR logging (the system must support it)
120 yes) AC_DEFINE([MPFR_USE_LOGGING],1,[Log what MPFR does]) ;;
122 *) AC_MSG_ERROR([bad value for --enable-logging: yes or no]) ;;
124 AC_ARG_ENABLE(thread-safe,
125 [ --disable-thread-safe explicitly disable TLS support
126 --enable-thread-safe build MPFR as thread safe, i.e. with TLS support
127 (the system must support it) [[default=autodetect]]],
131 *) AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
133 AC_ARG_ENABLE(warnings,
134 [ --enable-warnings allow MPFR to output warnings to stderr [[default=no]]],
136 yes) AC_DEFINE([MPFR_USE_WARNINGS],1,[Allow MPFR to output warnings to stderr]) ;;
138 *) AC_MSG_ERROR([bad value for --enable-warnings: yes or no]) ;;
141 AC_ARG_ENABLE(tests-timeout,
142 [ --enable-tests-timeout=NUM enable timeout (NUM seconds) for test programs
143 (NUM <= 9999) [[default=no]]; if enabled, env variable
144 $MPFR_TESTS_TIMEOUT overrides NUM (0: no timeout).],
147 yes) AC_DEFINE([MPFR_TESTS_TIMEOUT], 0, [timeout limit]) ;;
148 [[0-9]]|[[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]]|[[0-9]][[0-9]][[0-9]][[0-9]])
149 AC_DEFINE_UNQUOTED([MPFR_TESTS_TIMEOUT], $enableval, [timeout limit]) ;;
150 *) AC_MSG_ERROR([bad value for --enable-tests-timeout]) ;;
155 dnl Setup CC and CFLAGS
158 dnl Check if user request its CC and CFLAGS
159 if test -n "$CFLAGS" || test -n "$CC" ; then
163 dnl ********************************************************************
164 dnl Check for CC and CFLAGS in gmp.h
166 if test -z "$user_redefine_cc" && test "$cross_compiling" != yes ; then
168 dnl We need to guess the C preprocessor instead of using AC_PROG_CPP,
169 dnl since AC_PROG_CPP implies AC_PROG_CC, which chooses a compiler
170 dnl (before we have the chance to get it from gmp.h) and does some
171 dnl checking related to this compiler (such as dependency tracking
172 dnl options); if the compiler changes due to __GMP_CC in gmp.h, one
173 dnl would have incorrect settings.
174 dnl FIXME: Move this in aclocal ?
175 if test -z "$GMP_CC$GMP_CFLAGS" ; then
176 AC_MSG_CHECKING(for CC and CFLAGS in gmp.h)
178 GMP_CFLAGS=__GMP_CFLAGS
179 for cpp in /lib/cpp gcc cc c99
181 test $cpp = /lib/cpp || cpp="$cpp -E"
182 echo foo > conftest.c
183 if $cpp $CPPFLAGS conftest.c > /dev/null 2> /dev/null ; then
185 echo "#include \"gmp.h\"" > conftest.c
186 echo "MPFR_OPTION __GMP_CC" >> conftest.c
187 GMP_CC=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e 's/MPFR_OPTION //g;s/ *" *//g'`
189 echo "#include \"gmp.h\"" > conftest.c
190 echo "MPFR_OPTION __GMP_CFLAGS" >> conftest.c
192 [test "$enable_logging" = yes && rmpedantic='s/[ "]-pedantic[ "]/ /g;']
193 GMP_CFLAGS=`$cpp $CPPFLAGS conftest.c 2> /dev/null | $EGREP MPFR_OPTION | $SED -e "$rmpedantic"'s/MPFR_OPTION //g;s/ *" *//g'`
198 if test "x$GMP_CC" = "x__GMP_CC" || test "x$GMP_CFLAGS" = "x__GMP_CFLAGS" ; then
203 AC_MSG_RESULT(yes [CC=$GMP_CC CFLAGS=$GMP_CFLAGS])
207 dnl But these variables may be invalid, so we must check them first.
208 dnl Note: we do not use AC_RUN_IFELSE, as it implies AC_PROG_CC.
209 if test -n "$GMP_CC$GMP_CFLAGS" ; then
210 AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
211 echo "int main (void) { return 0; }" > conftest.c
212 if $GMP_CC $GMP_CFLAGS -o conftest conftest.c 2> /dev/null ; then
224 dnl ********************************************************************
230 AC_ARG_ENABLE(decimal-float,
231 [ --enable-decimal-float build conversion functions from/to decimal floats
234 yes) AC_DEFINE([MPFR_WANT_DECIMAL_FLOATS],1,
235 [Build decimal float functions])
236 AC_MSG_CHECKING(if compiler knows _Decimal64)
237 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[_Decimal64 x;]])],
239 if test "$use_gmp_build" != yes ; then
240 AC_MSG_ERROR([decimal float support requires --with-gmp-build])
242 AC_MSG_CHECKING(if _GMP_IEEE_FLOATS is defined)
243 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
245 #include "gmp-impl.h"
246 #ifndef _GMP_IEEE_FLOATS
247 #error "_GMP_IEEE_FLOATS is not defined"
248 #endif]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
249 AC_MSG_ERROR([decimal float support requires _GMP_IEEE_FLOATS])])
251 [AC_MSG_ERROR([Compiler doesn't know _Decimal64; try GCC >= 4.2, configured with --enable-decimal-float]
253 AC_MSG_CHECKING(decimal float format)
254 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
257 union { double d; _Decimal64 d64; } y;
258 y.d64 = 1234567890123456.0dd;
259 return y.d == 0.14894469406741037E-123 ? 0 :
260 y.d == 0.59075095508629822E-68 ? 1 : 2;
261 ]])], [AC_MSG_RESULT(DPD)
262 AC_DEFINE([DPD_FORMAT],1,[])],
263 [if test "$?" != 1 ; then
264 AC_MSG_FAILURE(neither DPD nor BID)
267 [AC_MSG_RESULT(assuming DPD)
268 AC_DEFINE([DPD_FORMAT],1,[])])
271 *) AC_MSG_ERROR([bad value for --enable-decimal-float: yes or no]) ;;
274 dnl Check if compiler is ICC, and if such a case, disable GCC
275 dnl And add some specific flags.
276 dnl Don't add Warnings Flags (Otherwise you'll get more than 20000 warnings).
277 dnl Add -long_double flags? Don't use -pc64 !
279 dnl * With icc 10.1 20080212 on itanium, the __ICC macro is not defined,
280 dnl even when the -icc option is used (contrary to what is documented
281 dnl on the icc man page).
282 dnl * When ICC is correctly detected (__ICC macro defined), unsetting
283 dnl the GCC variable confuses libtool. See:
284 dnl http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=485421
285 dnl * If need be, the gcc predefined macros __GNUC_* can be disabled
286 dnl thanks to the -no-gcc option.
287 AC_MSG_CHECKING(for ICC)
288 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
290 # error "ICC Not Found"
295 CFLAGS="-fp_port -mp -wd1572 -wd265 -wd186 -wd239 $CFLAGS"
296 ],[AC_MSG_RESULT(no)])
298 dnl If compiler is gcc, then use some specific flags.
299 dnl But don't touch user other flags.
300 if test "$test_CFLAGS" != set && test -n "$GCC"; then
301 CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith $CFLAGS"
308 dnl This allows to take the first GMP library in the library paths,
309 dnl whether it is dynamic or static. This behavior is more sensible,
310 dnl in particular because it is the only way to link with a version
311 dnl only available in static form when another version is available
312 dnl in dynamic, and also for consistency, because the compiler will
313 dnl take the first gmp.h found in the include paths (so, we need to
314 dnl take a library that corresponds to this header file). This is a
315 dnl common problem with darwin.
316 MPFR_LD_SEARCH_PATHS_FIRST ;;
324 # clock_gettime is in librt on *-*-osf5.1 and on glibc < 2.17, so add -lrt to
325 # TUNE_LIBS if needed (e.g. if clock_gettime is not already in the C library).
326 # On linux (tested on x86_32, 2.6.26), clock_getres reports ns accuracy,
327 # while in a quick test on osf, clock_getres said only 1 millisecond.
329 AC_SEARCH_LIBS(clock_gettime, rt, [
330 AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define to 1 if you have the `clock_gettime' function])])
336 dnl Setup GMP detection
340 AC_MSG_CHECKING(for gmp.h)
341 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
343 ]])],[AC_MSG_RESULT(yes)],[
345 AC_MSG_ERROR([gmp.h can't be found, or is unusable.])
348 dnl Configs for Windows DLLs.
349 dnl libtool requires "-no-undefined" for win32 dll
350 dnl It also disables the tests involving the linking with LIBGMP if DLL
352 dnl "-Wl,output-def" is used to get a .def file for use by MS lib to make
353 dnl a .lib import library, described in the manual.
355 dnl Incidentally, libtool does generate an import library libmpfr.dll.a,
356 dnl but it's "ar" format and cannot be used by the MS linker. There
357 dnl doesn't seem to be any GNU tool for generating or converting to .lib.
358 AC_SUBST(MPFR_LDFLAGS)
359 AC_SUBST(LIBMPFR_LDFLAGS)
362 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
363 AC_MSG_CHECKING(for DLL/static GMP)
364 if test "$enable_shared" = yes; then
365 MPFR_LDFLAGS="$MPFR_LDFLAGS -no-undefined"
366 LIBMPFR_LDFLAGS="$LIBMPFR_LDFLAGS -Wl,--output-def,.libs/libmpfr-4.dll.def"
367 dont_link_with_gmp="yes"
368 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
370 #if !__GMP_LIBGMP_DLL
374 ]], [[]])],[AC_MSG_RESULT(DLL)],[
375 AC_MSG_RESULT(static)
376 AC_MSG_ERROR([gmp.h isn't a DLL: use --enable-static --disable-shared]) ])
378 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
384 ]], [[]])],[AC_MSG_RESULT(static)],[
386 AC_MSG_ERROR([gmp.h is a DLL: use --disable-static --enable-shared]) ])
390 dnl Finally set up LibTool
395 dnl For mpfr-longlong.h - TODO: should be replaced (see acinclude.m4).
402 dnl Setup GMP detection (continued)
405 dnl Check minimal GMP version
406 dnl We only guarantee that with a *functional* and recent enough GMP version,
407 dnl MPFR will compile; we do not guarantee that GMP will compile.
408 dnl In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
409 dnl (at least on 64-bit Core 2 under Linux),
410 dnl see http://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html.
411 AC_MSG_CHECKING(for recent GMP)
412 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
414 #if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410)
415 # error "min GMP version is 4.1.0"
418 ]])],[AC_MSG_RESULT(yes)],[
420 AC_MSG_ERROR([GMP 4.1.0 min required])
423 dnl Check if we can use internal header files of GMP (only --with-gmp-build)
424 if test "$use_gmp_build" = yes ; then
425 AC_MSG_CHECKING(for gmp internal files)
426 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
428 #include "gmp-impl.h"
429 #include "longlong.h"
432 AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
434 AC_MSG_ERROR([header files gmp-impl.h and longlong.h not found])
438 dnl Check for valid GMP_NUMB_BITS and BYTES_PER_MP_LIMB
439 dnl This test doesn't need to link with libgmp (at least it shouldn't).
440 if test "$use_gmp_build" = yes ; then
441 AC_MSG_CHECKING(for valid GMP_NUMB_BITS)
442 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
445 #include "gmp-impl.h"
447 return GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
448 && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
449 ]])], [AC_MSG_RESULT(yes)], [
451 AC_MSG_ERROR([GMP_NUMB_BITS is incorrect.
452 You probably need to change some of the GMP or MPFR compile options.])],
453 [AC_MSG_RESULT([can't test])])
457 dnl We really need to link using libtool. But it is impossible with the current
459 dnl The practical problems appear only under MS Windows since the library name
460 dnl is libgmp-3 (due to libtool versionning). The best solution
461 dnl is to believe it works under MS-Windows.
462 if test "$dont_link_with_gmp" = yes ; then
466 dnl Check if we can link with GMP
467 AC_CHECK_LIB(gmp, __gmpz_init, [LIBS="-lgmp $LIBS"],
468 [AC_MSG_ERROR(libgmp not found or uses a different ABI (including static vs shared).
469 Please read the INSTALL file -- see "In case of problem".)])
471 dnl Check for corresponding 'gmp.h' and libgmp.a
472 AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
473 dnl We do not set LD_LIBRARY_PATH, as it is not possible to set it just
474 dnl before the test program is run, and we do not want to affect other
475 dnl programs (such as the compiler), because the behavior could be
476 dnl incorrect and even have security implications.
477 saved_LD_RUN_PATH="$LD_RUN_PATH"
478 LD_RUN_PATH="${LD_RUN_PATH:+$LD_RUN_PATH$PATH_SEPARATOR}$gmp_lib_path"
480 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
486 sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
487 __GNU_MP_VERSION_PATCHLEVEL);
488 printf ("(%s/%s) ", buffer, gmp_version);
489 if (strcmp (buffer, gmp_version) == 0)
491 if (__GNU_MP_VERSION_PATCHLEVEL != 0)
493 sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
494 return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
497 MPFR_CHECK_PRINTF_SPEC],
499 AC_MSG_WARN([==========================================================])
500 AC_MSG_WARN(['gmp.h' and 'libgmp' seem to have different versions or])
501 AC_MSG_WARN([we cannot run a program linked with GMP (if you cannot])
502 AC_MSG_WARN([see the version numbers above). A cause may be different])
503 AC_MSG_WARN([GMP versions with different ABI's or the use of --with-gmp])
504 AC_MSG_WARN([or --with-gmp-include with a system include directory])
505 AC_MSG_WARN([(such as /usr/include or /usr/local/include).])
506 AC_MSG_WARN([However since we can't use 'libtool' inside the configure,])
507 AC_MSG_WARN([we can't be sure. See 'config.log' for details.])
508 AC_MSG_WARN([==========================================================])
509 ],AC_MSG_RESULT([can not test])
511 LD_RUN_PATH="$saved_LD_RUN_PATH"
513 dnl Warning! __gmpn_rootrem is an internal GMP symbol; thus its behavior
514 dnl may change or this symbol may be removed in the future (without being
515 dnl handled by the library versioning system, which is even worse, as this
516 dnl can mean undetected incompatibilities in case of GMP library upgrade,
517 dnl without rebuilding MPFR). So, this symbol must not be used, unless
518 dnl WANT_GMP_INTERNALS is defined. Only the GMP public API should be used
519 dnl by default, in particular by binary distributions. Moreover the check
520 dnl below may yield an incorrect result as libtool isn't used in configure
522 dnl Same for __gmpn_sbpi1_divappr_q.
523 AC_CHECK_FUNCS([__gmpn_rootrem __gmpn_sbpi1_divappr_q])
525 dnl End of tests which need to link with GMP.
528 dnl Remove also many MACROS (AC_DEFINE) which are unused by MPFR
529 dnl and polluate (and slow down because libtool has to parse them) the build.
530 if test -f confdefs.h; then
531 $SED '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
532 $SED '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
533 $SED '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
534 $SED '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
535 $SED '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
536 $SED '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
537 $SED '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
538 $SED '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
539 $SED '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
540 $SED '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
541 $SED '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
542 $SED '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
543 $SED '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
544 $SED '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
545 $SED '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp
547 mv confdefs.tmp confdefs.h
550 if $EGREP -q -e '-dev$' $srcdir/VERSION; then
551 AC_SUBST([DATAFILES])dnl
552 DATAFILES=`echo \`$SED -n \
553 's/^ *data_check *("\(data\/[[^"]]*\)".*/tests\/\1/p' \
558 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile tests/Makefile tune/Makefile src/mparam.h:src/mparam_h.in])
561 dnl NEWS README AUTHORS Changelog