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 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.1])
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 dnl Setup GMP detection
328 AC_MSG_CHECKING(for gmp.h)
329 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
331 ]])],[AC_MSG_RESULT(yes)],[
333 AC_MSG_ERROR([gmp.h can't be found, or is unusable.])
336 dnl Configs for Windows DLLs.
337 dnl libtool requires "-no-undefined" for win32 dll
338 dnl It also disables the tests involving the linking with LIBGMP if DLL
340 dnl "-Wl,output-def" is used to get a .def file for use by MS lib to make
341 dnl a .lib import library, described in the manual.
343 dnl Incidentally, libtool does generate an import library libmpfr.dll.a,
344 dnl but it's "ar" format and cannot be used by the MS linker. There
345 dnl doesn't seem to be any GNU tool for generating or converting to .lib.
346 AC_SUBST(MPFR_LDFLAGS)
347 AC_SUBST(LIBMPFR_LDFLAGS)
350 *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
351 AC_MSG_CHECKING(for DLL/static GMP)
352 if test "$enable_shared" = yes; then
353 MPFR_LDFLAGS="$MPFR_LDFLAGS -no-undefined"
354 LIBMPFR_LDFLAGS="$LIBMPFR_LDFLAGS -Wl,--output-def,.libs/libmpfr-4.dll.def"
355 dont_link_with_gmp="yes"
356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
358 #if !__GMP_LIBGMP_DLL
362 ]], [[]])],[AC_MSG_RESULT(DLL)],[
363 AC_MSG_RESULT(static)
364 AC_MSG_ERROR([gmp.h isn't a DLL: use --enable-static --disable-shared]) ])
366 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
372 ]], [[]])],[AC_MSG_RESULT(static)],[
374 AC_MSG_ERROR([gmp.h is a DLL: use --disable-static --enable-shared]) ])
378 dnl Finally set up LibTool
383 dnl For mpfr-longlong.h - TODO: should be replaced (see acinclude.m4).
390 dnl Setup GMP detection (continued)
393 dnl Check minimal GMP version
394 dnl We only guarantee that with a *functional* and recent enough GMP version,
395 dnl MPFR will compile; we do not guarantee that GMP will compile.
396 dnl In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
397 dnl (at least on 64-bit Core 2 under Linux),
398 dnl see http://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html.
399 AC_MSG_CHECKING(for recent GMP)
400 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
402 #if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410)
403 # error "min GMP version is 4.1.0"
406 ]])],[AC_MSG_RESULT(yes)],[
408 AC_MSG_ERROR([GMP 4.1.0 min required])
411 dnl Check if we can use internal header files of GMP (only --with-gmp-build)
412 if test "$use_gmp_build" = yes ; then
413 AC_MSG_CHECKING(for gmp internal files)
414 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
416 #include "gmp-impl.h"
417 #include "longlong.h"
420 AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
422 AC_MSG_ERROR([header files gmp-impl.h and longlong.h not found])
426 dnl Check for valid GMP_NUMB_BITS and BYTES_PER_MP_LIMB
427 dnl This test doesn't need to link with libgmp (at least it shouldn't).
428 if test "$use_gmp_build" = yes ; then
429 AC_MSG_CHECKING(for valid GMP_NUMB_BITS)
430 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
433 #include "gmp-impl.h"
435 return GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
436 && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
437 ]])], [AC_MSG_RESULT(yes)], [
439 AC_MSG_ERROR([GMP_NUMB_BITS is incorrect.
440 You probably need to change some of the GMP or MPFR compile options.])],
441 [AC_MSG_RESULT([can't test])])
445 dnl We really need to link using libtool. But it is impossible with the current
447 dnl The practical problems appear only under MS Windows since the library name
448 dnl is libgmp-3 (due to libtool versionning). The best solution
449 dnl is to believe it works under MS-Windows.
450 if test "$dont_link_with_gmp" = yes ; then
454 dnl Check if we can link with GMP
455 AC_CHECK_LIB(gmp, __gmpz_init, [LIBS="-lgmp $LIBS"],
456 [AC_MSG_ERROR(libgmp not found or uses a different ABI (including static vs shared).
457 Please read the INSTALL file -- see "In case of problem".)])
459 dnl Check for corresponding 'gmp.h' and libgmp.a
460 AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
461 dnl We do not set LD_LIBRARY_PATH, as it is not possible to set it just
462 dnl before the test program is run, and we do not want to affect other
463 dnl programs (such as the compiler), because the behavior could be
464 dnl incorrect and even have security implications.
465 saved_LD_RUN_PATH="$LD_RUN_PATH"
466 LD_RUN_PATH="${LD_RUN_PATH:+$LD_RUN_PATH$PATH_SEPARATOR}$gmp_lib_path"
468 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
474 sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
475 __GNU_MP_VERSION_PATCHLEVEL);
476 printf ("(%s/%s) ", buffer, gmp_version);
477 if (strcmp (buffer, gmp_version) == 0)
479 if (__GNU_MP_VERSION_PATCHLEVEL != 0)
481 sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
482 return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
485 MPFR_CHECK_PRINTF_SPEC],
487 AC_MSG_WARN([==========================================================])
488 AC_MSG_WARN(['gmp.h' and 'libgmp' seem to have different versions or])
489 AC_MSG_WARN([we cannot run a program linked with GMP (if you cannot])
490 AC_MSG_WARN([see the version numbers above). A cause may be different])
491 AC_MSG_WARN([GMP versions with different ABI's or the use of --with-gmp])
492 AC_MSG_WARN([or --with-gmp-include with a system include directory])
493 AC_MSG_WARN([(such as /usr/include or /usr/local/include).])
494 AC_MSG_WARN([However since we can't use 'libtool' inside the configure,])
495 AC_MSG_WARN([we can't be sure. See 'config.log' for details.])
496 AC_MSG_WARN([==========================================================])
497 ],AC_MSG_RESULT([can not test])
499 LD_RUN_PATH="$saved_LD_RUN_PATH"
501 dnl Warning! __gmpn_rootrem is an internal GMP symbol; thus its behavior
502 dnl may change or this symbol may be removed in the future (without being
503 dnl handled by the library versioning system, which is even worse, as this
504 dnl can mean undetected incompatibilities in case of GMP library upgrade,
505 dnl without rebuilding MPFR). So, this symbol must not be used, unless
506 dnl WANT_GMP_INTERNALS is defined. Only the GMP public API should be used
507 dnl by default, in particular by binary distributions. Moreover the check
508 dnl below may yield an incorrect result as libtool isn't used in configure
510 dnl Same for __gmpn_sbpi1_divappr_q.
511 AC_CHECK_FUNCS([__gmpn_rootrem __gmpn_sbpi1_divappr_q])
513 dnl End of tests which need to link with GMP.
516 dnl Remove also many MACROS (AC_DEFINE) which are unused by MPFR
517 dnl and polluate (and slow down because libtool has to parse them) the build.
518 if test -f confdefs.h; then
519 sed '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
520 sed '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
521 sed '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
522 sed '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
523 sed '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
524 sed '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
525 sed '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
526 sed '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
527 sed '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
528 sed '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
529 sed '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
530 sed '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
531 sed '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
532 sed '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
533 sed '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp
535 mv confdefs.tmp confdefs.h
538 if grep -q -e '-dev$' $srcdir/VERSION; then
539 AC_SUBST([DATAFILES])dnl
540 DATAFILES=`echo \`$SED -n \
541 's/^ *data_check *("\(data\/[[^"]]*\)".*/tests\/\1/p' \
546 AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile tests/Makefile tune/Makefile src/mparam.h:src/mparam_h.in])
549 dnl NEWS README AUTHORS Changelog