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