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