1AC_COPYRIGHT([ 2Copyright (c) 2008-2024 Stefan Krah. All rights reserved. 3 4Redistribution and use in source and binary forms, with or without 5modification, are permitted provided that the following conditions 6are met: 7 81. Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 102. Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 14THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24SUCH DAMAGE. 25]) 26 27AH_TOP([ 28/* 29 * The generated config.h is only included in runtest.cc, and there are 30 * no plans to use it elsewhere. All defines apart from HAVE_PTHREAD_H 31 * are purely informational. 32 */ 33]) 34 35AC_PREREQ([2.69]) 36 37AC_INIT([mpdecimal], 38 [4.0.0], 39 [mpdecimal-bugs@bytereef.org], 40 [mpdecimal], 41 [https://www.bytereef.org/mpdecimal/index.html]) 42 43AC_CONFIG_HEADERS([config.h]) 44 45AC_CONFIG_FILES([Makefile 46 libmpdec/Makefile 47 libmpdec/mpdecimal.h 48 libmpdec/.pc/libmpdec.pc 49 libmpdec++/Makefile 50 libmpdec++/.pc/libmpdec++.pc 51 tests/Makefile 52 tests++/Makefile]) 53 54# Link files for out-of-tree builds: 55AC_CONFIG_LINKS([CHANGELOG.txt:CHANGELOG.txt 56 COPYRIGHT.txt:COPYRIGHT.txt 57 INSTALL.txt:INSTALL.txt 58 Makefile.in:Makefile.in 59 README.txt:README.txt 60 config.guess:config.guess 61 config.h.in:config.h.in 62 config.sub:config.sub 63 configure:configure 64 configure.ac:configure.ac 65 install-sh:install-sh 66 67 doc/COPYRIGHT.txt:doc/COPYRIGHT.txt 68 doc/libmpdec.3:doc/libmpdec.3 69 doc/libmpdec++.3:doc/libmpdec++.3 70 doc/mpdecimal.3:doc/mpdecimal.3 71 72 libmpdec/Makefile.in:libmpdec/Makefile.in 73 libmpdec/Makefile.vc:libmpdec/Makefile.vc 74 libmpdec/README.txt:libmpdec/README.txt 75 libmpdec/basearith.c:libmpdec/basearith.c 76 libmpdec/basearith.h:libmpdec/basearith.h 77 libmpdec/bench.c:libmpdec/bench.c 78 libmpdec/bench_full.c:libmpdec/bench_full.c 79 libmpdec/bits.h:libmpdec/bits.h 80 libmpdec/constants.c:libmpdec/constants.c 81 libmpdec/constants.h:libmpdec/constants.h 82 libmpdec/context.c:libmpdec/context.c 83 libmpdec/convolute.c:libmpdec/convolute.c 84 libmpdec/convolute.h:libmpdec/convolute.h 85 libmpdec/crt.c:libmpdec/crt.c 86 libmpdec/crt.h:libmpdec/crt.h 87 libmpdec/difradix2.c:libmpdec/difradix2.c 88 libmpdec/difradix2.h:libmpdec/difradix2.h 89 libmpdec/fnt.c:libmpdec/fnt.c 90 libmpdec/fnt.h:libmpdec/fnt.h 91 libmpdec/fourstep.c:libmpdec/fourstep.c 92 libmpdec/fourstep.h:libmpdec/fourstep.h 93 libmpdec/io.c:libmpdec/io.c 94 libmpdec/io.h:libmpdec/io.h 95 libmpdec/mpalloc.c:libmpdec/mpalloc.c 96 libmpdec/mpalloc.h:libmpdec/mpalloc.h 97 libmpdec/mpdecimal.c:libmpdec/mpdecimal.c 98 libmpdec/mpdecimal32vc.h:libmpdec/mpdecimal32vc.h 99 libmpdec/mpdecimal64vc.h:libmpdec/mpdecimal64vc.h 100 libmpdec/mpdecimal.h.in:libmpdec/mpdecimal.h.in 101 libmpdec/mpsignal.c:libmpdec/mpsignal.c 102 libmpdec/numbertheory.c:libmpdec/numbertheory.c 103 libmpdec/numbertheory.h:libmpdec/numbertheory.h 104 libmpdec/sixstep.c:libmpdec/sixstep.c 105 libmpdec/sixstep.h:libmpdec/sixstep.h 106 libmpdec/transpose.c:libmpdec/transpose.c 107 libmpdec/transpose.h:libmpdec/transpose.h 108 libmpdec/typearith.h:libmpdec/typearith.h 109 libmpdec/umodarith.h:libmpdec/umodarith.h 110 libmpdec/vcdiv64.asm:libmpdec/vcdiv64.asm 111 112 libmpdec/examples/README.txt:libmpdec/examples/README.txt 113 libmpdec/examples/compare.c:libmpdec/examples/compare.c 114 libmpdec/examples/div.c:libmpdec/examples/div.c 115 libmpdec/examples/divmod.c:libmpdec/examples/divmod.c 116 libmpdec/examples/multiply.c:libmpdec/examples/multiply.c 117 libmpdec/examples/pow.c:libmpdec/examples/pow.c 118 libmpdec/examples/powmod.c:libmpdec/examples/powmod.c 119 libmpdec/examples/shift.c:libmpdec/examples/shift.c 120 libmpdec/examples/sqrt.c:libmpdec/examples/sqrt.c 121 122 libmpdec/.objs/README.txt:libmpdec/.objs/README.txt 123 libmpdec/.objs/symbols32.exp:libmpdec/.objs/symbols32.exp 124 libmpdec/.objs/symbols64.exp:libmpdec/.objs/symbols64.exp 125 libmpdec/.pc/libmpdec.pc.in:libmpdec/.pc/libmpdec.pc.in 126 libmpdec/.profile/train.sh:libmpdec/.profile/train.sh 127 128 libmpdec++/Makefile.in:libmpdec++/Makefile.in 129 libmpdec++/Makefile.vc:libmpdec++/Makefile.vc 130 libmpdec++/bench.cc:libmpdec++/bench.cc 131 libmpdec++/bench_full.cc:libmpdec++/bench_full.cc 132 libmpdec++/decimal.cc:libmpdec++/decimal.cc 133 libmpdec++/decimal.hh:libmpdec++/decimal.hh 134 135 libmpdec++/examples/factorial.cc:libmpdec++/examples/factorial.cc 136 libmpdec++/examples/pi.cc:libmpdec++/examples/pi.cc 137 138 libmpdec++/.objs/README.txt:libmpdec++/.objs/README.txt 139 libmpdec++/.pc/libmpdec++.pc.in:libmpdec++/.pc/libmpdec++.pc.in 140 libmpdec++/.profile/train.sh:libmpdec++/.profile/train.sh 141 142 tests/Makefile.in:tests/Makefile.in 143 tests/Makefile.vc:tests/Makefile.vc 144 tests/README.txt:tests/README.txt 145 tests/additional.decTest:tests/additional.decTest 146 tests/gettests.bat:tests/gettests.bat 147 tests/gettests.sh:tests/gettests.sh 148 tests/official.decTest:tests/official.decTest 149 tests/runshort.sh:tests/runshort.sh 150 tests/runshort_alloc.sh:tests/runshort_alloc.sh 151 tests/runtest.c:tests/runtest.c 152 tests/test.c:tests/test.c 153 tests/test.h:tests/test.h 154 tests/vctest.h:tests/vctest.h 155 156 tests/testdata_dist/baseconv.decTest:tests/testdata_dist/baseconv.decTest 157 tests/testdata_dist/binop_eq.decTest:tests/testdata_dist/binop_eq.decTest 158 tests/testdata_dist/cov.decTest:tests/testdata_dist/cov.decTest 159 tests/testdata_dist/divmod.decTest:tests/testdata_dist/divmod.decTest 160 tests/testdata_dist/divmod_eq.decTest:tests/testdata_dist/divmod_eq.decTest 161 tests/testdata_dist/extra.decTest:tests/testdata_dist/extra.decTest 162 tests/testdata_dist/fma_eq.decTest:tests/testdata_dist/fma_eq.decTest 163 tests/testdata_dist/format.decTest:tests/testdata_dist/format.decTest 164 tests/testdata_dist/getint.decTest:tests/testdata_dist/getint.decTest 165 tests/testdata_dist/invroot.decTest:tests/testdata_dist/invroot.decTest 166 tests/testdata_dist/largeint.decTest:tests/testdata_dist/largeint.decTest 167 tests/testdata_dist/maxprec.decTest:tests/testdata_dist/maxprec.decTest 168 tests/testdata_dist/powmod.decTest:tests/testdata_dist/powmod.decTest 169 tests/testdata_dist/powmod_eq.decTest:tests/testdata_dist/powmod_eq.decTest 170 tests/testdata_dist/shiftlr.decTest:tests/testdata_dist/shiftlr.decTest 171 tests/testdata_dist/testruntest.decTest:tests/testdata_dist/testruntest.decTest 172 173 tests++/Makefile.in:tests++/Makefile.in 174 tests++/Makefile.vc:tests++/Makefile.vc 175 tests++/README.txt:tests++/README.txt 176 tests++/additional.topTest:tests++/additional.topTest 177 tests++/apitest.cc:tests++/apitest.cc 178 tests++/gettests.bat:tests++/gettests.bat 179 tests++/gettests.sh:tests++/gettests.sh 180 tests++/official.topTest:tests++/official.topTest 181 tests++/runshort.sh:tests++/runshort.sh 182 tests++/runshort_alloc.sh:tests++/runshort_alloc.sh 183 tests++/runtest.cc:tests++/runtest.cc 184 tests++/test.cc:tests++/test.cc 185 tests++/test.hh:tests++/test.hh 186 tests++/vctest.hh:tests++/vctest.hh]) 187 188# ============================================================================== 189# MPD_HEADER_CONFIG 190# ============================================================================== 191 192CONFIG_64=" 193/* ABI: 64-bit */ 194#define MPD_CONFIG_64 1 195 196#ifdef MPD_CONFIG_32 197 #error \"cannot use MPD_CONFIG_32 with 64-bit header.\" 198#endif 199 200#ifdef CONFIG_32 201 #error \"cannot use CONFIG_32 with 64-bit header.\" 202#endif" 203 204CONFIG_32=" 205/* ABI: 32-bit */ 206#define MPD_CONFIG_32 1 207 208#ifdef MPD_CONFIG_64 209 #error \"cannot use MPD_CONFIG_64 with 32-bit header.\" 210#endif 211 212#ifdef CONFIG_64 213 #error \"cannot use CONFIG_64 with 32-bit header.\" 214#endif" 215 216CONFIG_32_LEGACY=" 217/* ABI: 32-bit */ 218#define MPD_CONFIG_32 1 219 220/* libmpdec was compiled without support for int64_t */ 221#define MPD_LEGACY_COMPILER 1 222 223#ifdef MPD_CONFIG_64 224 #error \"cannot use MPD_CONFIG_64 with 32-bit header.\" 225#endif 226 227#ifdef CONFIG_64 228 #error \"cannot use CONFIG_64 with 32-bit header.\" 229#endif" 230 231CONFIG_UNIVERSAL=" 232/* Mac OS X: support for building universal binaries */ 233#if defined(MPD_CONFIG_64) || defined(MPD_CONFIG_32) 234 #error \"cannot use MPD_CONFIG_64 or MPD_CONFIG_32 with universal header.\" 235#endif 236 237#if defined(CONFIG_64) || defined(CONFIG_32) 238 #error \"cannot use CONFIG_64 or CONFIG_32 with universal header.\" 239#endif 240 241#if defined(__ppc__) 242 #define MPD_CONFIG_32 1 243 #ifdef UNIVERSAL 244 #define CONFIG_32 245 #define ANSI 246 #endif 247#elif defined(__ppc64__) 248 #define MPD_CONFIG_64 1 249 #ifdef UNIVERSAL 250 #define CONFIG_64 251 #define ANSI 252 #endif 253#elif defined(__i386__) 254 #define MPD_CONFIG_32 1 255 #ifdef UNIVERSAL 256 #define CONFIG_32 257 #define ANSI 258 #endif 259#elif defined(__x86_64__) 260 #define MPD_CONFIG_64 1 261 #ifdef UNIVERSAL 262 #define CONFIG_64 263 #define ASM 264 #endif 265#elif defined(__arm64__) 266 #define MPD_CONFIG_64 1 267 #ifdef UNIVERSAL 268 #define CONFIG_64 269 #define ANSI 270 #endif 271#else 272 #error \"unknown architecture for universal build.\" 273#endif" 274 275CONFIG_UNIVERSAL_AIX_UINT128=" 276/* AIX: support for multilib */ 277#if defined(MPD_CONFIG_64) || defined(MPD_CONFIG_32) 278 #error \"cannot use MPD_CONFIG_64 or MPD_CONFIG_32 with multilib header.\" 279#endif 280 281#if defined(CONFIG_64) || defined(CONFIG_32) 282 #error \"cannot use CONFIG_64 or CONFIG_32 with multilib header.\" 283#endif 284 285#if defined(__64BIT__) 286 #define MPD_CONFIG_64 1 287 #ifdef UNIVERSAL 288 #define CONFIG_64 289 #define ANSI 290 #define HAVE_UINT128_T 291 #endif 292#else 293 #define MPD_CONFIG_32 1 294 #ifdef UNIVERSAL 295 #define CONFIG_32 296 #define ANSI 297 #endif 298#endif" 299 300CONFIG_UNIVERSAL_AIX_ANSI64=" 301/* AIX: support for multilib */ 302#if defined(MPD_CONFIG_64) || defined(MPD_CONFIG_32) 303 #error \"cannot use MPD_CONFIG_64 or MPD_CONFIG_32 with multilib header.\" 304#endif 305 306#if defined(CONFIG_64) || defined(CONFIG_32) 307 #error \"cannot use CONFIG_64 or CONFIG_32 with multilib header.\" 308#endif 309 310#if defined(__64BIT__) 311 #define MPD_CONFIG_64 1 312 #ifdef UNIVERSAL 313 #define CONFIG_64 314 #define ANSI 315 #endif 316#else 317 #define MPD_CONFIG_32 1 318 #ifdef UNIVERSAL 319 #define CONFIG_32 320 #define ANSI 321 #endif 322#endif" 323 324# ============================================================================== 325# Detect build and host systems 326# ============================================================================== 327 328AC_CANONICAL_HOST 329 330# ============================================================================== 331# Select library names 332# ============================================================================== 333 334# MinGW support: 335ENABLE_MINGW="no" 336 337# Set library names and linker flags: 338FPIC="-fPIC" 339LIBSTATIC=libmpdec.a 340LIBSHARED_USE_AR="no" 341LIBIMPORT= 342LINK_STATIC= 343LINK_DYNAMIC= 344case $host in 345 *-*-darwin*) 346 LIBNAME="libmpdec.dylib" 347 LIBSONAME="libmpdec.4.dylib" 348 LIBSHARED="libmpdec.4.0.0.dylib" 349 CONFIGURE_LDFLAGS="-dynamiclib $FPIC -install_name @rpath/$LIBSONAME -compatibility_version 4.0 -current_version 4.0.0" 350 ;; 351 *-*-aix*) 352 LIBNAME= 353 LIBSONAME= 354 LIBSHARED="shr.o" 355 LIBSHARED_USE_AR="yes" 356 CONFIGURE_LDFLAGS="-shared $FPIC -Wl,-bnoentry -Wl,-bE:.objs/symbols.exp" 357 LINK_STATIC="-Wl,-bstatic" 358 LINK_DYNAMIC="-Wl,-bshared" 359 ;; 360 *-*-mingw*) 361 FPIC= 362 LIBNAME= 363 LIBIMPORT="libmpdec.dll.a" 364 LIBSONAME= 365 LIBSHARED="libmpdec-4.dll" 366 CONFIGURE_LDFLAGS="-shared -Wl,--out-implib,$LIBIMPORT" 367 ENABLE_MINGW="yes" 368 ;; 369 *-*-msys) 370 FPIC= 371 LIBNAME= 372 LIBIMPORT="libmpdec.dll.a" 373 LIBSONAME= 374 LIBSHARED="msys-mpdec-4.dll" 375 CONFIGURE_LDFLAGS="-shared -Wl,--out-implib,$LIBIMPORT" 376 ENABLE_MINGW="yes" 377 ;; 378 *) 379 LIBNAME="libmpdec.so" 380 LIBSONAME="libmpdec.so.4" 381 LIBSHARED="libmpdec.so.4.0.0" 382 CONFIGURE_LDFLAGS="-shared $FPIC -Wl,-soname,$LIBSONAME" 383 ;; 384esac 385 386LIBSTATIC_CXX=libmpdec++.a 387LIBIMPORT_CXX= 388case $host in 389 *-*-darwin*) 390 LIBNAME_CXX="libmpdec++.dylib" 391 LIBSONAME_CXX="libmpdec++.4.dylib" 392 LIBSHARED_CXX="libmpdec++.4.0.0.dylib" 393 CONFIGURE_LDXXFLAGS="-dynamiclib $FPIC -install_name @rpath/$LIBSONAME_CXX -compatibility_version 4.0 -current_version 4.0.0" 394 ;; 395 *-*-aix*) 396 LIBNAME_CXX= 397 LIBSONAME_CXX= 398 LIBSHARED_CXX="shr.o" 399 CONFIGURE_LDXXFLAGS="-shared $FPIC -Wl,-bnoentry -Wl,-bE:.objs/symbols.exp" 400 ;; 401 *-*-mingw*) 402 LIBNAME_CXX= 403 LIBIMPORT_CXX="libmpdec++.dll.a" 404 LIBSONAME_CXX= 405 LIBSHARED_CXX="libmpdec++-4.dll" 406 CONFIGURE_LDXXFLAGS="-shared -Wl,--out-implib,$LIBIMPORT_CXX" 407 ;; 408 *-*-msys) 409 LIBNAME_CXX= 410 LIBIMPORT_CXX="libmpdec++.dll.a" 411 LIBSONAME_CXX= 412 LIBSHARED_CXX="msys-mpdec++-4.dll" 413 CONFIGURE_LDXXFLAGS="-shared -Wl,--out-implib,$LIBIMPORT_CXX" 414 ;; 415 *) 416 LIBNAME_CXX="libmpdec++.so" 417 LIBSONAME_CXX="libmpdec++.so.4" 418 LIBSHARED_CXX="libmpdec++.so.4.0.0" 419 CONFIGURE_LDXXFLAGS="-shared $FPIC -Wl,-soname,$LIBSONAME_CXX" 420 ;; 421esac 422 423AC_SUBST(FPIC) 424AC_SUBST(LIBSTATIC) 425AC_SUBST(LIBNAME) 426AC_SUBST(LIBSONAME) 427AC_SUBST(LIBSHARED) 428AC_SUBST(LIBIMPORT) 429AC_SUBST(LIBSHARED_USE_AR) 430AC_SUBST(LINK_STATIC) 431AC_SUBST(LINK_DYNAMIC) 432AC_SUBST(LIBSTATIC_CXX) 433AC_SUBST(LIBNAME_CXX) 434AC_SUBST(LIBSONAME_CXX) 435AC_SUBST(LIBSHARED_CXX) 436AC_SUBST(LIBIMPORT_CXX) 437AC_SUBST(ENABLE_MINGW) 438 439# ============================================================================== 440# User options 441# ============================================================================== 442 443# Check whether to build libmpdec++: 444AC_MSG_CHECKING(for --enable-cxx) 445AC_ARG_ENABLE(cxx, AS_HELP_STRING([--enable-cxx], 446 [enable building libmpdec++ (default is yes)])) 447 448ENABLE_CXX="$enable_cxx" 449if test -z "$ENABLE_CXX" 450then 451 if test x"$MACHINE" = x"ansi-legacy"; then 452 ENABLE_CXX="no" 453 else 454 ENABLE_CXX="yes" 455 fi 456fi 457AC_MSG_RESULT($ENABLE_CXX) 458 459# Check whether to build the static libraries: 460AC_MSG_CHECKING(for --enable-static) 461AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], 462 [enable building static libraries (default is yes)])) 463 464ENABLE_STATIC="$enable_static" 465if test -z "$ENABLE_STATIC" 466then 467 ENABLE_STATIC="yes" 468fi 469AC_MSG_RESULT($ENABLE_STATIC) 470 471# Check whether to build the shared libraries: 472AC_MSG_CHECKING(for --enable-shared) 473AC_ARG_ENABLE(shared, AS_HELP_STRING([--enable-shared], 474 [enable building shared libraries (default is yes)])) 475 476ENABLE_SHARED="$enable_shared" 477if test -z "$ENABLE_SHARED" 478then 479 ENABLE_SHARED="yes" 480fi 481AC_MSG_RESULT($ENABLE_SHARED) 482 483# Check whether at least one library is enabled: 484if test x"$ENABLE_STATIC" = x"no" -a x"$ENABLE_SHARED" = x"no" 485then 486 AC_MSG_ERROR([at least one of --enable-static or --enable-shared must be set]) 487fi 488 489# AIX: both static and shared libraries must be enabled: 490case $host in 491 *-*-aix*) 492 if test x"$ENABLE_STATIC" = x"no" -o x"$ENABLE_SHARED" = x"no" 493 then 494 AC_MSG_ERROR([the AIX build requires --enable-static and --enable-shared]) 495 fi 496 ;; 497esac 498 499# Check whether to install the documentation: 500AC_MSG_CHECKING(for --enable-doc) 501AC_ARG_ENABLE(doc, AS_HELP_STRING([--enable-doc], 502 [enable installing the documentation (default is yes)])) 503 504ENABLE_DOC="$enable_doc" 505if test -z "$ENABLE_DOC" 506then 507 ENABLE_DOC="yes" 508fi 509AC_MSG_RESULT($ENABLE_DOC) 510 511# Check whether to install the pkg-config files: 512AC_MSG_CHECKING(for --enable-pc) 513AC_ARG_ENABLE(pc, AS_HELP_STRING([--enable-pc], 514 [enable installing the pkg-config files (default is yes)])) 515 516ENABLE_PC="$enable_pc" 517if test -z "$ENABLE_PC" 518then 519 ENABLE_PC="yes" 520fi 521AC_MSG_RESULT($ENABLE_PC) 522 523AC_SUBST(ENABLE_CXX) 524AC_SUBST(ENABLE_STATIC) 525AC_SUBST(ENABLE_SHARED) 526AC_SUBST(ENABLE_DOC) 527AC_SUBST(ENABLE_PC) 528 529# ============================================================================== 530# Compilers and flags 531# ============================================================================== 532 533# Save initial compiler flags: 534INITIAL_CFLAGS="$CFLAGS" 535INITIAL_CXXFLAGS="$CXXFLAGS" 536INITIAL_LDFLAGS="$LDFLAGS" 537INITIAL_LDXXFLAGS="$LDXXFLAGS" 538 539case $CC in 540 cc) 541 case $build in 542 *-*-freebsd* | *-*-openbsd* | *-*-darwin*) 543 CC=clang 544 ;; 545 *-*-netbsd*) 546 CC=gcc 547 ;; 548 *-*-solaris* | *-*-sunos*) 549 CC=suncc 550 ;; 551 esac 552 ;; 553esac 554 555case $CXX in 556 c++) 557 case $build in 558 *-*-freebsd* | *-*-openbsd* | *-*-darwin*) 559 CXX=clang++ 560 ;; 561 *-*-netbsd*) 562 CXX=g++ 563 ;; 564 esac 565 ;; 566esac 567 568# Language and compiler: 569AC_LANG([C]) 570 571# Preference of tested compilers: 572case $host in 573 *-*-aix*) 574 PREFERRED_CC="ibm-clang_r ibm-clang gcc xlc_r xlc cc" 575 PREFERRED_CXX="ibm-clang++_r g++ c++" 576 ;; 577 *-*-freebsd* | *-*-openbsd*) 578 PREFERRED_CC="clang gcc cc" 579 PREFERRED_CXX="clang++ g++ c++" 580 ;; 581 *) 582 PREFERRED_CC="gcc icc clang icx suncc ccomp cc" 583 PREFERRED_CXX="g++ icpc clang++ icpx c++" 584 ;; 585esac 586 587# Find CC: 588saved_cflags="$CFLAGS" 589saved_ldflags="$LDFLAGS" 590AC_PROG_CC([$PREFERRED_CC]) 591CFLAGS="$saved_cflags" 592LDFLAGS="$saved_ldflags" 593 594# These compilers do not fully support C++11. Disable CXX to avoid mixing 595# different C and C++ compilers: 596case $CC in 597 *xlc* | suncc | ccomp) 598 ENABLE_CXX="no" 599 ;; 600esac 601 602# Find CXX: 603if test x"$ENABLE_CXX" = x"yes"; then 604 saved_cxxflags="$CXXFLAGS" 605 saved_ldxxflags="$LDXXFLAGS" 606 AC_PROG_CXX([$PREFERRED_CXX]) 607 CXXFLAGS="$saved_cxxflags" 608 LDXXFLAGS="$saved_ldxxflags" 609fi 610 611# Check availability of -O2: 612AC_MSG_CHECKING(for -O2) 613saved_cflags="$CFLAGS" 614saved_ldflags="$LDFLAGS" 615CFLAGS="-O2" 616LDFLAGS= 617AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[have_O2=yes],[have_O2=no]) 618AC_MSG_RESULT($have_O2) 619CFLAGS="$saved_cflags" 620LDFLAGS="$saved_ldflags" 621 622# Find ar and ranlib: 623AC_CHECK_TOOL(AR, ar, ar) 624AC_PROG_RANLIB 625 626# Force explicit configuration. This section must be here because the size 627# checks in the next section require the correct CFLAGS. 628AC_ARG_VAR(MACHINE, [ 629force configuration: x64, uint128, ansi64, ppro, ansi32, ansi-legacy, universal]) 630 631M64= 632M32= 633if test -n "$MACHINE"; then 634 case $host in 635 *-*-aix*) 636 case $CC in 637 *xlc*) 638 M64="-q64" 639 M32="-q32" 640 ;; 641 *gcc*) 642 M64="-maix64" 643 M32="-maix32" 644 ;; 645 *) 646 M64="-m64" 647 M32="-m32" 648 ;; 649 esac 650 ;; 651 *) 652 M64="-m64" 653 M32="-m32" 654 ;; 655 esac 656 657 case "$MACHINE" in 658 x64 | uint128 | ansi64) 659 CFLAGS="$CFLAGS $M64" 660 CXXFLAGS="$CXXFLAGS $M64" 661 LDFLAGS="$LDFLAGS $M64" 662 LDXXFLAGS="$LDXXFLAGS $M64" 663 ;; 664 ppro | ansi32 | ansi-legacy) 665 CFLAGS="$CFLAGS $M32" 666 CXXFLAGS="$CXXFLAGS $M32" 667 LDFLAGS="$LDFLAGS $M32" 668 LDXXFLAGS="$LDXXFLAGS $M64" 669 ;; 670 universal) 671 : 672 ;; 673 *) 674 AC_MSG_ERROR([invalid MACHINE variable: $MACHINE]) 675 ;; 676 esac 677 678 AC_MSG_CHECKING(whether the toolchain supports the chosen ABI) 679 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], 680 [machine_supported=yes], 681 [machine_supported=no], 682 [machine_supported=undefined]) 683 AC_MSG_RESULT($machine_supported) 684 if test "$machine_supported" = no; then 685 AC_MSG_ERROR([toolchain cannot handle MACHINE=$MACHINE]) 686 fi 687fi 688 689# Compiler dependent settings: 690MPD_PTHREAD= 691MPD_WARN= 692MPD_WARNXX= 693MPD_OPT="-O2" 694MPD_PGEN= 695MPD_PUSE= 696CONFIG_UNIVERSAL_AIX= 697FILTER_FOR_STATIC= 698case $CC in 699 *gcc*) 700 CONFIG_UNIVERSAL_AIX=$CONFIG_UNIVERSAL_AIX_UINT128 701 MPD_PTHREAD="-pthread" 702 MPD_WARN="-Wall -Wextra -Wno-unknown-pragmas -std=c99 -pedantic" 703 MPD_WARNXX="-Wall -Wextra -std=c++11 -pedantic" 704 MPD_OPT="-DNDEBUG -O2" 705 MPD_PGEN="-fprofile-generate -fprofile-values" 706 MPD_PUSE="-fprofile-use -freorder-blocks" 707 FILTER_FOR_STATIC="-flto% -ffat-lto-objects" 708 ;; 709 *icc*) 710 AR=xiar 711 LD="$CC" 712 CXX=icpc 713 LDXX=icpc 714 MPD_PTHREAD="-pthread" 715 MPD_WARN="-Wall -Wextra -Wno-unknown-pragmas -std=c99 -pedantic -diag-disable=11074,11076" 716 MPD_WARNXX="-Wall -Wextra -std=c++11 -pedantic -diag-disable=11074,11076" 717 MPD_OPT="-DNDEBUG -O2" 718 MPD_PGEN="-wd11505 -prof-gen" 719 MPD_PUSE="-wd11505 -prof-use" 720 ;; 721 *clang* | *icx* | *emcc*) 722 CONFIG_UNIVERSAL_AIX=$CONFIG_UNIVERSAL_AIX_UINT128 723 MPD_PTHREAD="-pthread" 724 MPD_WARN="-Wall -Wextra -Wno-unknown-pragmas -std=c99 -pedantic" 725 MPD_WARNXX="-Wall -Wextra -Wexit-time-destructors -std=c++11 -pedantic" 726 MPD_OPT="-DNDEBUG -O2" 727 ;; 728 *xlc*) 729 CONFIG_UNIVERSAL_AIX=$CONFIG_UNIVERSAL_AIX_ANSI64 730 LD="$CC" 731 CONFIGURE_LDFLAGS="-qmkshrobj -bnoentry -bE:.objs/symbols.exp" 732 LINK_STATIC="-bstatic" 733 LINK_DYNAMIC="-bshared" 734 MPD_PTHREAD="-qthreaded -D_THREAD_SAFE" 735 MPD_WARN="-qlanglvl=stdc99" 736 MPD_OPT="-DNDEBUG -O2 -qalias=ansi -qmaxmem=-1" 737 ;; 738 *suncc*) 739 MPD_WARN="-xc99" 740 MPD_OPT="-DNDEBUG -O2" 741 ;; 742 *ccomp*) 743 ENABLE_SHARED=no 744 LINK_STATIC="-Wl,-znoexecstack" 745 MPD_WARN="-Wall -Wno-unknown-pragmas -std=c99 -fstruct-passing" 746 MPD_OPT="-DNDEBUG -O2" 747 ;; 748 *) 749 ;; 750esac 751 752AC_ARG_VAR(LDXX, [C++ linker (default is $CXX)]) 753AC_ARG_VAR(LDXXFLAGS, [C++ linker flags]) 754 755if test -z "$LD"; then 756 LD="$CC" 757fi 758if test -z "$LDXX"; then 759 LDXX="$CXX" 760fi 761 762AC_SUBST(CC) 763AC_SUBST(LD) 764AC_SUBST(CXX) 765AC_SUBST(LDXX) 766AC_SUBST(FILTER_FOR_STATIC) 767AC_SUBST(MPD_PTHREAD) 768AC_SUBST(MPD_PGEN) 769AC_SUBST(MPD_PUSE) 770 771# ============================================================================== 772# Headers, types, assembly, install program 773# ============================================================================== 774 775# Check for header files: 776AC_CHECK_HEADERS(pthread.h) 777 778# Type availability checks: 779AC_TYPE_SIZE_T 780AC_TYPE_INT32_T 781AC_TYPE_INT64_T 782AC_TYPE_UINT32_T 783AC_TYPE_UINT64_T 784AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, 785 [Define if your compiler provides __uint128_t.]),,) 786 787# Sizes of various types: 788AC_CHECK_SIZEOF(size_t, 4) 789AC_CHECK_SIZEOF(__uint128_t, 16) 790 791# x64 with gcc asm: 792AC_MSG_CHECKING(for x64 gcc inline assembler) 793AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 794__asm__ __volatile__ ("movq %rcx, %rax"); 795]])],[have_gcc_asm_for_x64=yes],[have_gcc_asm_for_x64=no]) 796AC_MSG_RESULT($have_gcc_asm_for_x64) 797if test "$have_gcc_asm_for_x64" = yes; then 798AC_DEFINE(HAVE_GCC_ASM_FOR_X64, 1, 799[Define if we can use x64 gcc inline assembler.]) 800fi 801 802# x87 with gcc asm: 803AC_MSG_CHECKING(for x87 gcc inline assembler) 804AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 805 unsigned short cw; 806 __asm__ __volatile__ ("fnstcw %0" : "=m" (cw)); 807 __asm__ __volatile__ ("fldcw %0" : : "m" (cw)); 808]])],[have_gcc_asm_for_x87=yes],[have_gcc_asm_for_x87=no]) 809AC_MSG_RESULT($have_gcc_asm_for_x87) 810if test "$have_gcc_asm_for_x87" = yes; then 811AC_DEFINE(HAVE_GCC_ASM_FOR_X87, 1, 812[Define if we can use x87 gcc inline assembler.]) 813fi 814 815# Install program: 816AC_PROG_INSTALL 817AC_SUBST(INSTALL) 818 819# ============================================================================== 820# Detect toolchain bugs 821# ============================================================================== 822 823# _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect: 824# http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html 825AC_MSG_CHECKING(for glibc _FORTIFY_SOURCE/memmove bug) 826saved_cflags="$CFLAGS" 827saved_ldflags="$LDFLAGS" 828CFLAGS="-O2 -D_FORTIFY_SOURCE=2" 829if test "$have_O2" = no; then 830 CFLAGS= 831fi 832LDFLAGS= 833AC_RUN_IFELSE([AC_LANG_SOURCE([[ 834#include <stdio.h> 835#include <stdlib.h> 836#include <string.h> 837void foo(void *p, void *q) { memmove(p, q, 19); } 838int main() { 839 char a[32] = "123456789000000000"; 840 foo(&a[9], a); 841 if (strcmp(a, "123456789123456789000000000") != 0) 842 return 1; 843 foo(a, &a[9]); 844 if (strcmp(a, "123456789000000000") != 0) 845 return 1; 846 return 0; 847} 848]])], 849[have_glibc_memmove_bug=no], 850[have_glibc_memmove_bug=yes], 851[have_glibc_memmove_bug=undefined]) 852CFLAGS="$saved_cflags" 853LDFLAGS="$saved_ldflags" 854AC_MSG_RESULT($have_glibc_memmove_bug) 855if test "$have_glibc_memmove_bug" = yes; then 856 AC_DEFINE(HAVE_GLIBC_MEMMOVE_BUG, 1, 857 [Define if glibc has incorrect _FORTIFY_SOURCE wrappers 858 for memmove and bcopy.]) 859fi 860 861# ============================================================================== 862# Optimized configurations 863# ============================================================================== 864 865# Auto-detect machine dependent settings: 866AIX_AR= 867AIX_RANLIB= 868EXPORTSYMS= 869OBJECT_SUFFIX= 870DETECTED_MACHINE= 871if test $ac_cv_sizeof_size_t -eq 8; then 872 AIX_AR="ar -X64" 873 AIX_RANLIB="ranlib -X64" 874 EXPORTSYMS="symbols64.exp" 875 OBJECT_SUFFIX="4_64.o" 876 if test $have_gcc_asm_for_x64 = yes; then 877 DETECTED_MACHINE="x64" 878 elif test $ac_cv_type___uint128_t = yes; then 879 DETECTED_MACHINE="uint128" 880 else 881 DETECTED_MACHINE="ansi64" 882 fi 883else 884 AIX_AR="ar -X32" 885 AIX_RANLIB="ranlib -X32" 886 EXPORTSYMS="symbols32.exp" 887 OBJECT_SUFFIX="4.o" 888 DETECTED_MACHINE="ansi32" 889 if test $have_gcc_asm_for_x87 = yes; then 890 case $CC in 891 *gcc* | *clang*) # icc >= 11.0 works as well 892 case $host in 893 *-*-darwin*) 894 ;; 895 *) 896 DETECTED_MACHINE="ppro" 897 ;; 898 esac 899 ;; 900 esac 901 fi 902fi 903 904if test -z "$MACHINE"; then 905 MACHINE="$DETECTED_MACHINE" 906fi 907 908# Set configuration variables: 909MPD_ABI= 910MPD_PREC=9 911case "$MACHINE" in 912 x64) 913 MPD_HEADER_CONFIG=$CONFIG_64 914 MPD_ABI=$M64 915 MPD_CONFIG="-DCONFIG_64 -DASM" 916 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M64" 917 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M64" 918 MPD_PREC=19 919 ;; 920 uint128) 921 MPD_HEADER_CONFIG=$CONFIG_64 922 MPD_ABI=$M64 923 MPD_CONFIG="-DCONFIG_64 -DANSI -DHAVE_UINT128_T" 924 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M64" 925 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M64" 926 MPD_PREC=19 927 ;; 928 ansi64) 929 MPD_HEADER_CONFIG=$CONFIG_64 930 MPD_ABI=$M64 931 MPD_CONFIG="-DCONFIG_64 -DANSI" 932 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M64" 933 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M64" 934 MPD_PREC=19 935 ;; 936 ppro) 937 MPD_HEADER_CONFIG=$CONFIG_32 938 MPD_ABI=$M32 939 MPD_CONFIG="-DCONFIG_32 -DPPRO -DASM" 940 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M32" 941 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M32" 942 # Some versions of gcc miscompile inline asm: 943 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491 944 # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html 945 case $CC in 946 *gcc*) 947 AC_MSG_CHECKING(for gcc ipa-pure-const bug) 948 saved_cflags="$CFLAGS" 949 saved_ldflags="$LDFLAGS" 950 CFLAGS="-O2" 951 LDFLAGS= 952 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 953 __attribute__((noinline)) int 954 foo(int *p) { 955 int r; 956 asm ( "movl \$6, (%1)\n\t" 957 "xorl %0, %0\n\t" 958 : "=r" (r) : "r" (p) : "memory" 959 ); 960 return r; 961 } 962 int main() { 963 int p = 8; 964 if ((foo(&p) ? : p) != 6) 965 return 1; 966 return 0; 967 } 968 ]])], 969 [have_ipa_pure_const_bug=no], 970 [have_ipa_pure_const_bug=yes], 971 [have_ipa_pure_const_bug=undefined]) 972 CFLAGS="$saved_cflags" 973 LDFLAGS="$saved_ldflags" 974 AC_MSG_RESULT($have_ipa_pure_const_bug) 975 if test "$have_ipa_pure_const_bug" = yes; then 976 MPD_CONFIG="$MPD_CONFIG -fno-ipa-pure-const" 977 AC_DEFINE(HAVE_IPA_PURE_CONST_BUG, 1, 978 [Define if gcc has the ipa-pure-const bug.]) 979 fi 980 ;; 981 esac 982 ;; 983 ansi32) 984 MPD_HEADER_CONFIG=$CONFIG_32 985 MPD_ABI=$M32 986 MPD_CONFIG="-DCONFIG_32 -DANSI" 987 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M32" 988 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M32" 989 ;; 990 ansi-legacy) 991 MPD_HEADER_CONFIG=$CONFIG_32_LEGACY 992 MPD_ABI=$M32 993 MPD_CONFIG="-DCONFIG_32 -DANSI -DLEGACY_COMPILER" 994 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $M32" 995 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $M32" 996 ;; 997 universal) 998 MPD_HEADER_CONFIG=$CONFIG_UNIVERSAL 999 MPD_CONFIG="-DUNIVERSAL" 1000 ;; 1001 *) 1002 AC_MSG_ERROR([cannot detect MACHINE]) 1003 ;; 1004esac 1005 1006# Special cases: 1007MPD_CXXOPT= 1008MPD_GNU99= 1009case $host in 1010 *-*-aix*) 1011 AR=$AIX_AR 1012 RANLIB=$AIX_RANLIB 1013 MPD_OPT="-D_THREAD_SAFE $MPD_OPT" 1014 MPD_CXXOPT="-D_THREAD_SAFE" 1015 case "$MACHINE" in 1016 universal) 1017 MPD_HEADER_CONFIG=$CONFIG_UNIVERSAL_AIX 1018 AR="ar -X32_64" 1019 RANLIB="ranlib -X32_64" 1020 ;; 1021 esac 1022 ;; 1023 *-*-netbsd*) 1024 MPD_OPT="-D_REENTRANT $MPD_OPT" 1025 MPD_CXXOPT="-D_REENTRANT" 1026 ;; 1027 *-*-solaris* | *-*-sunos*) 1028 MPD_OPT="-D_REENTRANT $MPD_OPT" 1029 MPD_CXXOPT="-D_REENTRANT" 1030 case $CC in 1031 *gcc*) 1032 MPD_GNU99=-std=gnu99 1033 ;; 1034 esac 1035 ;; 1036esac 1037 1038AC_SUBST(AR) 1039AC_SUBST(RANLIB) 1040AC_SUBST(EXPORTSYMS) 1041AC_SUBST(OBJECT_SUFFIX) 1042AC_SUBST(MPD_HEADER_CONFIG) 1043AC_SUBST(MPD_GNU99) 1044AC_SUBST(MPD_PREC) 1045 1046# ============================================================================== 1047# Substitute remaining variables 1048# ============================================================================== 1049 1050if test -z "$INITIAL_CFLAGS"; then 1051 CONFIGURE_LIBMPDEC_CFLAGS="$MPD_WARN $MPD_CONFIG $MPD_OPT $MPD_ABI" 1052 CONFIGURE_CFLAGS="$MPD_WARN $MPD_OPT $MPD_ABI" 1053else 1054 CONFIGURE_LIBMPDEC_CFLAGS="$MPD_WARN $MPD_CONFIG $MPD_OPT $MPD_ABI $INITIAL_CFLAGS" 1055 CONFIGURE_CFLAGS="$MPD_WARN $MPD_OPT $MPD_ABI $INITIAL_CFLAGS" 1056fi 1057 1058if test "$have_glibc_memmove_bug" = yes; then 1059 CONFIGURE_LIBMPDEC_CFLAGS="$CONFIGURE_LIBMPDEC_CFLAGS -U_FORTIFY_SOURCE" 1060 CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -U_FORTIFY_SOURCE" 1061fi 1062 1063if test -z "$INITIAL_CXXFLAGS"; then 1064 CONFIGURE_CXXFLAGS="$MPD_WARNXX $MPD_CXXOPT -DNDEBUG -O3 $MPD_ABI" 1065else 1066 CONFIGURE_CXXFLAGS="$MPD_WARNXX $MPD_CXXOPT -DNDEBUG -O3 $MPD_ABI $INITIAL_CXXFLAGS" 1067fi 1068 1069if test -n "$INITIAL_LDFLAGS"; then 1070 CONFIGURE_LDFLAGS="$CONFIGURE_LDFLAGS $INITIAL_LDFLAGS" 1071fi 1072 1073if test -n "$INITIAL_LDXXFLAGS"; then 1074 CONFIGURE_LDXXFLAGS="$CONFIGURE_LDXXFLAGS $INITIAL_LDXXFLAGS" 1075fi 1076 1077AC_SUBST(CONFIGURE_LIBMPDEC_CFLAGS) 1078AC_SUBST(CONFIGURE_CFLAGS) 1079AC_SUBST(CONFIGURE_LDFLAGS) 1080AC_SUBST(CONFIGURE_CXXFLAGS) 1081AC_SUBST(CONFIGURE_LDXXFLAGS) 1082 1083# ============================================================================== 1084# Write output 1085# ============================================================================== 1086 1087AC_OUTPUT 1088 1089GLIBC_MEMMOVE_BUG_WARN=" 1090***************************** WARNING ********************************* 1091 1092Detected glibc _FORTIFY_SOURCE/memmove bug. See: 1093 1094 http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html 1095 1096Enabling -U_FORTIFY_SOURCE workaround. If -D_FORTIFY_SOURCE is also 1097present in the command line, make sure that the order of the two 1098options is: 1099 1100 ... -D_FORTIFY_SOURCE=2 ... -U_FORTIFY_SOURCE ... 1101 1102A better solution is to upgrade glibc or to report the bug to your 1103OS vendor. 1104 1105***************************** WARNING ********************************* 1106" 1107 1108if test "$have_glibc_memmove_bug" = yes; then 1109 echo "$GLIBC_MEMMOVE_BUG_WARN" 1110fi 1111