configure.ac raw

   1  # Copyright (c) 1999-2001 by Red Hat, Inc. All rights reserved.
   2  # Copyright (c) 2005-2009 Hewlett-Packard Development Company, L.P.
   3  # Copyright (c) 2009-2022 Ivan Maidanski
   4  #
   5  # THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
   6  # OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
   7  #
   8  # Permission is hereby granted to use or copy this program
   9  # for any purpose, provided the above notices are retained on all copies.
  10  # Permission to modify the code and to distribute modified code is granted,
  11  # provided the above notices are retained, and a notice that the code was
  12  # modified is included with the above copyright notice.
  13  
  14  dnl Process this file with `autoconf` to produce `configure` file.
  15  
  16  dnl Initialization.
  17  AC_INIT(gc,8.3.0,https://github.com/bdwgc/bdwgc/issues)
  18  dnl Version must conform to: [0-9]+[.][0-9]+[.][0-9]+
  19  
  20  AC_CONFIG_SRCDIR(gcj_mlc.c)
  21  AC_CONFIG_MACRO_DIR([m4])
  22  AC_CANONICAL_TARGET
  23  AC_PREREQ(2.61)
  24  GC_SET_VERSION
  25  AM_INIT_AUTOMAKE([foreign nostdinc subdir-objects])
  26  AC_CONFIG_HEADERS([include/config.h])
  27  AM_MAINTAINER_MODE
  28  
  29  AC_SUBST(PACKAGE)
  30  AC_SUBST(GC_VERSION)
  31  
  32  AM_PROG_CC_C_O
  33  AC_PROG_CXX
  34  AM_PROG_AS
  35  AC_PROG_INSTALL
  36  LT_INIT([disable-static])
  37  # Only the shared libraries are produced by default, use `--enable-static`
  38  # option to override it.
  39  dnl Note: If Autoconf reports that LIBTOOL (or AC_ENABLE_SHARED) is
  40  dnl undefined, Libtool installation should be checked.
  41  
  42  # Special `CFLAGS` to use when building.
  43  gc_cflags=""
  44  
  45  # Set to `yes` on platforms where `mmap` should be used instead of `sbrk`.
  46  # This will define `USE_MMAP`.
  47  gc_use_mmap=""
  48  
  49  # We should set `-fexceptions` if we are using gcc and might be used
  50  # inside something like `gcj`.  This is the zeroth approximation:
  51  if test :"$GCC": = :yes: ; then
  52      gc_cflags="${gc_cflags} -fexceptions"
  53  else
  54      case "$host" in
  55        hppa*-*-hpux*)
  56          if test :$GCC: != :"yes": ; then
  57              gc_cflags="${gc_cflags} +ESdbgasm"
  58          fi
  59          # :TODO: actually we should check using `autoconf` if the compiler
  60          # supports this option.
  61          ;;
  62      esac
  63  fi
  64  
  65  # target_optspace: `--enable-target-optspace` (`yes`, `no`, or empty)
  66  case "${target_optspace}:${host}" in
  67    yes:*)
  68      gc_cflags="${gc_cflags} -Os"
  69      ;;
  70    :m32r-* | :d10v-* | :d30v-*)
  71      gc_cflags="${gc_cflags} -Os"
  72      ;;
  73    no:* | :*)
  74      # Nothing.
  75      ;;
  76  esac
  77  
  78  # Set any host dependent compiler flags.
  79  case "${host}" in
  80    mips-tx39-* | mipstx39-unknown-*)
  81      gc_cflags="${gc_cflags} -G 0"
  82      ;;
  83  esac
  84  
  85  AC_MSG_CHECKING([for emscripten])
  86  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  87  #   ifndef __EMSCRIPTEN__
  88  #     error This is not Emscripten
  89  #   endif
  90    ]])], [emscripten=yes], [emscripten=no])
  91  AM_CONDITIONAL(EMSCRIPTEN, test x$emscripten = xyes)
  92  AC_MSG_RESULT([$emscripten])
  93  
  94  AC_ARG_ENABLE(emscripten-asyncify,
  95      [AS_HELP_STRING([--enable-emscripten-asyncify],
  96                      [use Emscripten asyncify feature])])
  97  # Use this option if your program is targeting `-sASYNCIFY`.  The latter is
  98  # required to scan the stack, `ASYNCIFY_STACK_SIZE` is probably needed for
  99  # `gctest` only.
 100  AS_IF([test "${emscripten}" = yes -a "${enable_emscripten_asyncify}" = yes],
 101        [gc_cflags="${gc_cflags} -DEMSCRIPTEN_ASYNCIFY"
 102         gc_cflags="${gc_cflags} -sASYNCIFY -sASYNCIFY_STACK_SIZE=128000"])
 103  
 104  GC_CFLAGS=${gc_cflags}
 105  AC_SUBST(GC_CFLAGS)
 106  
 107  dnl Extra user-defined flags to pass both to C and C++ compilers.
 108  AC_SUBST([CFLAGS_EXTRA])
 109  
 110  AC_ARG_ENABLE(threads,
 111    [AS_HELP_STRING([--enable-threads=TYPE], [choose threading package])],
 112    THREADS=$enableval,
 113     [AC_MSG_CHECKING([for thread model used by GCC])
 114      THREADS=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
 115      if test -z "$THREADS" -o "x$emscripten" = "xyes"; then
 116        THREADS=no
 117      fi
 118      if test "$THREADS" = "posix"; then
 119        case "$host" in
 120          *-*-mingw*)
 121            # Adjust thread model if cross-compiling for MinGW.
 122            THREADS=win32
 123            ;;
 124        esac
 125      fi
 126      AC_MSG_RESULT([$THREADS])])
 127  
 128  AC_ARG_ENABLE(parallel-mark,
 129      [AS_HELP_STRING([--disable-parallel-mark],
 130          [do not parallelize marking and free list construction])],
 131      [case "$THREADS" in
 132        no | none | single)
 133          if test "${enable_parallel_mark}" != no; then
 134            AC_MSG_ERROR([Parallel mark requires --enable-threads=x spec])
 135          fi
 136          ;;
 137       esac])
 138  
 139  AC_ARG_ENABLE(thread-local-alloc,
 140      [AS_HELP_STRING([--disable-thread-local-alloc],
 141          [turn off thread-local allocation optimization])],
 142      [case "$THREADS" in
 143        no | none | single)
 144          if test "${enable_thread_local_alloc}" = yes; then
 145            AC_MSG_ERROR(
 146                  [Thread-local allocation requires --enable-threads=x spec])
 147          fi
 148          ;;
 149       esac])
 150  
 151  AC_ARG_ENABLE(threads-discovery,
 152      [AS_HELP_STRING([--disable-threads-discovery],
 153                      [disable threads discovery in GC])])
 154  if test "${enable_threads_discovery}" = no; then
 155      AC_DEFINE([GC_NO_THREADS_DISCOVERY], 1,
 156                [Disable threads discovery in the collector.])
 157  fi
 158  
 159  AC_ARG_ENABLE(rwlock,
 160      [AS_HELP_STRING([--enable-rwlock],
 161                      [enable reader mode of the allocator lock])])
 162  if test "${enable_rwlock}" = yes; then
 163      AC_DEFINE([USE_RWLOCK], 1,
 164                [Use `rwlock` for the allocator lock instead of mutex.])
 165  fi
 166  
 167  AC_ARG_ENABLE(cplusplus,
 168      [AS_HELP_STRING([--enable-cplusplus], [install C++ support])])
 169  
 170  dnl Features which may be selected in the following thread-detection switch.
 171  AH_TEMPLATE([PARALLEL_MARK], [Define to enable parallel marking.])
 172  AH_TEMPLATE([THREAD_LOCAL_ALLOC],
 173              [Define to enable thread-local allocation optimization.])
 174  AH_TEMPLATE([USE_COMPILER_TLS],
 175              [Define to use of compiler-support for thread-local variables.])
 176  
 177  dnl Thread selection macros.
 178  AH_TEMPLATE([GC_THREADS], [Define to support platform-specific threads.])
 179  AH_TEMPLATE([GC_WIN32_PTHREADS],
 180                  [Define to support pthreads-win32 or winpthreads.])
 181  
 182  dnl System header feature requests.
 183  AH_TEMPLATE([_POSIX_C_SOURCE], [The POSIX feature macro.])
 184  AH_TEMPLATE([_PTHREADS], [Indicates the use of `pthreads` (NetBSD).])
 185  
 186  dnl Win32-specific API usage controls.
 187  AH_TEMPLATE([UNICODE],
 188          [Use Unicode (W) variant of Win32 API instead of ASCII (A) one.])
 189  
 190  dnl GC API symbols export control.
 191  AH_TEMPLATE([GC_DLL],
 192          [Define to build dynamic libraries with only API symbols exposed.])
 193  
 194  dnl Check for a flavor of supported inline keyword.
 195  old_CFLAGS="$CFLAGS"
 196  CFLAGS="$CFLAGS $CFLAGS_EXTRA"
 197  AC_C_INLINE
 198  CFLAGS="$old_CFLAGS"
 199  
 200  THREADDLLIBS=
 201  need_atomic_ops_asm=false
 202  need_lib_rt=false
 203  compile_asm=false
 204  use_parallel_mark=no
 205  use_thread_local_alloc=no
 206  # Libraries needed to support dynamic loading and/or threads.
 207  case "$THREADS" in
 208    no | none | single)
 209      THREADS=none
 210      ;;
 211    posix | pthreads)
 212      THREADS=posix
 213      default_threadlibs=false
 214      # Common defines for most POSIX platforms.
 215      case "$host" in
 216        *-*-aix* | *-*-android* | *-*-cygwin* | *-*-darwin* | *-*-dragonfly* | \
 217        *-*-freebsd* | *-*-haiku* | *-*-hpux11* | *-*-irix* | \
 218        *-*-kfreebsd*-gnu | *-*-gnu* | *-*-*linux* | *-*-msys* | *-*-nacl* | \
 219        *-*-netbsd* | *-*-openbsd* | *-*-osf* | *-*-serenity* | *-*-solaris*)
 220          AC_DEFINE(GC_THREADS)
 221          AC_DEFINE([_REENTRANT], [1],
 222                    [Required define if using POSIX threads.])
 223          use_parallel_mark=$enable_parallel_mark
 224          use_thread_local_alloc=$enable_thread_local_alloc
 225          default_threadlibs=true
 226          AC_MSG_WARN("Explicit GC_INIT() calls may be required.")
 227          ;;
 228      esac
 229      AC_CHECK_LIB(pthread, pthread_self, THREADDLLIBS="-lpthread",,)
 230      case "$host" in
 231        *-*-hpux11*)
 232          AC_MSG_WARN("Only HP/UX 11 POSIX threads are supported.")
 233          AC_DEFINE(_POSIX_C_SOURCE,199506L)
 234          THREADDLLIBS="-lpthread"
 235          # HPUX needs `REENTRANT` for the `_r` calls.
 236          need_lib_rt=true
 237          ;;
 238        *-*-openbsd*)
 239          AM_CFLAGS="$AM_CFLAGS -pthread"
 240          THREADDLLIBS=-pthread
 241          ;;
 242        *-*-freebsd*)
 243          AM_CFLAGS="$AM_CFLAGS -pthread"
 244          ;;
 245        *-*-kfreebsd*-gnu)
 246          AM_CFLAGS="$AM_CFLAGS -pthread"
 247          THREADDLLIBS=-pthread
 248          ;;
 249        *-*-gnu*)
 250          # E.g. Linux but excluding `kfreebsd`.
 251          # Use the default `THREADDLLIBS`.
 252          ;;
 253        *-*-netbsd*)
 254          AC_DEFINE(_PTHREADS)
 255          THREADDLLIBS="-lpthread"
 256          need_lib_rt=true
 257          ;;
 258        *-*-solaris*)
 259          THREADDLLIBS="-lpthread"
 260          need_lib_rt=true
 261          ;;
 262        *-*-cygwin* | *-*-msys*)
 263          # Cygwin does not have a real `libpthread`, so Libtool cannot link
 264          # against it.
 265          THREADDLLIBS=""
 266          win32_threads=true
 267          ;;
 268        *-*-mingw*)
 269          AC_DEFINE(GC_WIN32_PTHREADS)
 270          # Using pthreads-win32 (or other non-Cygwin `pthreads`) library.
 271          THREADDLLIBS="-lpthread"
 272          use_parallel_mark=$enable_parallel_mark
 273          use_thread_local_alloc=$enable_thread_local_alloc
 274          win32_threads=true
 275          ;;
 276        *-*-darwin*)
 277          darwin_threads=true
 278          ;;
 279        *-*-osf*)
 280          AM_CFLAGS="$AM_CFLAGS -pthread"
 281          THREADDLLIBS="-lpthread"
 282          need_lib_rt=true
 283          ;;
 284        *)
 285          AS_IF([test x$default_threadlibs != xtrue],
 286                [AC_MSG_ERROR(
 287                      [Pthreads not supported by the GC on this platform])])
 288          # The default `THREADDLLIBS`.
 289          ;;
 290      esac
 291      case "$host" in
 292        sparc*)
 293          if test "$GCC" != yes; then
 294            need_atomic_ops_asm=true
 295          fi
 296          ;;
 297      esac
 298      ;;
 299    mcf | win32)
 300      AC_DEFINE(GC_THREADS)
 301      use_parallel_mark=$enable_parallel_mark
 302      if test "${enable_parallel_mark}" != no \
 303              -o "${enable_shared}" != yes -o "${enable_static}" != no; then
 304        # Imply `THREAD_LOCAL_ALLOC` unless `GC_DLL`.
 305        use_thread_local_alloc=$enable_thread_local_alloc
 306      fi
 307      if test "${enable_win32_dllmain}" = yes; then
 308        AC_DEFINE(GC_INSIDE_DLL, 1,
 309                  [Enable Win32 `DllMain`-based approach of threads
 310                   registering.])
 311      fi
 312      win32_threads=true
 313      AC_DEFINE([EMPTY_GETENV_RESULTS], [1],
 314                [Wine `getenv` may not return `NULL` for missing entry.])
 315      ;;
 316    dgux386)
 317      AC_DEFINE(GC_THREADS)
 318      # Use `pthread` GCC switch.
 319      THREADDLLIBS=-pthread
 320      use_parallel_mark=$enable_parallel_mark
 321      use_thread_local_alloc=$enable_thread_local_alloc
 322      AC_MSG_WARN("Explicit GC_INIT() calls may be required.")
 323      AM_CFLAGS="-pthread $AM_CFLAGS"
 324      ;;
 325    aix)
 326      THREADS=posix
 327      THREADDLLIBS=-lpthread
 328      AC_DEFINE(GC_THREADS)
 329      AC_DEFINE(_REENTRANT)
 330      use_parallel_mark=$enable_parallel_mark
 331      use_thread_local_alloc=$enable_thread_local_alloc
 332      ;;
 333    rtems)
 334      THREADS=posix
 335      AC_DEFINE(GC_THREADS)
 336      use_parallel_mark=$enable_parallel_mark
 337      use_thread_local_alloc=$enable_thread_local_alloc
 338      ;;
 339    decosf1 | irix | mach | os2 | solaris | dce | vxworks)
 340      AC_MSG_ERROR(thread package $THREADS not yet supported)
 341      ;;
 342    *)
 343      AC_MSG_ERROR($THREADS is an unknown thread package)
 344      ;;
 345  esac
 346  
 347  # Check whether `-lrt` linker option is needed to use `clock_gettime`.
 348  if test "x$need_lib_rt" != xtrue; then
 349    AC_MSG_CHECKING(for clock_gettime without additional libraries)
 350    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>],
 351                      [struct timespec t; clock_gettime(CLOCK_REALTIME, &t)])],
 352      [AC_MSG_RESULT(yes)],
 353      [AC_MSG_RESULT(no)
 354       AC_CHECK_LIB(rt, clock_gettime, [need_lib_rt=true])])
 355  fi
 356  
 357  if test "x$need_lib_rt" = xtrue; then
 358    THREADDLLIBS="$THREADDLLIBS -lrt"
 359  fi
 360  AC_SUBST(THREADDLLIBS)
 361  
 362  AM_CONDITIONAL(THREADS, test x$THREADS != xnone)
 363  AM_CONDITIONAL(PTHREADS, test x$THREADS = xposix)
 364  AM_CONDITIONAL(DARWIN_THREADS, test x$darwin_threads = xtrue)
 365  AM_CONDITIONAL(WIN32_THREADS, test x$win32_threads = xtrue)
 366  
 367  compiler_suncc=no
 368  pthread_start_standalone=no
 369  case "$host" in
 370    *-*-*linux*)
 371      # Turn on the workaround described in `pthread_start.c` file.
 372      AS_IF([test "$THREADS" = posix], [pthread_start_standalone=yes])
 373      ;;
 374    powerpc-*-darwin*)
 375      powerpc_darwin=true
 376      ;;
 377    *-*-solaris*)
 378      if test "$GCC" != yes; then
 379        # Solaris SunCC
 380        compiler_suncc=yes
 381        CFLAGS="-O $CFLAGS"
 382      fi
 383      ;;
 384    *-*-wince*)
 385      if test "$enable_gc_debug" != "no"; then
 386        AC_DEFINE([GC_READ_ENV_FILE], 1,
 387                  [Read environment variables from the GC 'env' file.])
 388      fi
 389      ;;
 390  esac
 391  AM_CONDITIONAL(PTHREAD_START_STANDALONE,
 392                 test x$pthread_start_standalone = xyes)
 393  
 394  if test "$GCC" = yes; then
 395    # Output all warnings.
 396    AC_MSG_CHECKING([whether compiler supports -Wextra])
 397    old_CFLAGS="$CFLAGS"
 398    CFLAGS="-Wextra $CFLAGS"
 399    AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
 400                      [ac_cv_cc_wextra=yes], [ac_cv_cc_wextra=no])
 401    CFLAGS="$old_CFLAGS"
 402    AC_MSG_RESULT($ac_cv_cc_wextra)
 403    AS_IF([test "$ac_cv_cc_wextra" = yes], [WEXTRA="-Wextra"], [WEXTRA="-W"])
 404    AC_MSG_CHECKING([whether compiler supports -Wpedantic])
 405    CFLAGS="-Wpedantic -Wno-long-long $CFLAGS"
 406    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[extern int quiet;]])],
 407                      [ac_cv_cc_pedantic=yes], [ac_cv_cc_pedantic=no])
 408    CFLAGS="$old_CFLAGS"
 409    AC_MSG_RESULT($ac_cv_cc_pedantic)
 410    WPEDANTIC=
 411    AS_IF([test "$ac_cv_cc_pedantic" = yes],
 412          [WPEDANTIC="-Wpedantic -Wno-long-long"])
 413    CFLAGS="-Wall $WEXTRA $WPEDANTIC $CFLAGS"
 414    CXXFLAGS="-Wall $WEXTRA $WPEDANTIC $CXXFLAGS"
 415  fi
 416  
 417  AC_MSG_CHECKING(for xlc)
 418  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
 419  #   ifndef __xlC__
 420  #     error
 421  #   endif
 422    ]])], [compiler_xlc=yes], [compiler_xlc=no])
 423  AC_MSG_RESULT($compiler_xlc)
 424  if test $compiler_xlc = yes -a "$powerpc_darwin" = true; then
 425    # The darwin stack-frame-walking code is completely broken on xlc.
 426    AC_DEFINE([DARWIN_DONT_PARSE_STACK], 1,
 427              [Define to discover thread stack bounds on Darwin without trying
 428               to walk the frames on the stack.])
 429  fi
 430  
 431  # XLC neither requires nor tolerates the unnecessary assembler goop.
 432  # Similar for the Sun C compiler.
 433  AM_CONDITIONAL([ASM_WITH_CPP_UNSUPPORTED],
 434      [test $compiler_xlc = yes -o $compiler_suncc = yes])
 435  
 436  # Check for `getcontext` (e.g., uClibc can be configured without it)
 437  AC_CHECK_FUNC([getcontext], [],
 438      [AC_DEFINE([NO_GETCONTEXT], [1], [Missing `getcontext` function.])])
 439  
 440  # Check whether `dl_iterate_phdr` exists (as a strong symbol).
 441  case "$host" in
 442    *-*-cygwin* | *-*-darwin* | *-*-msys*)
 443      ;;
 444    *)
 445      AC_CHECK_FUNCS([dl_iterate_phdr])
 446      ;;
 447  esac
 448  
 449  case "$host" in
 450  # While IRIX 6 has `libdl` for the O32 and N32 ABIs, it is missing for N64
 451  # and unnecessary everywhere.
 452    mips-sgi-irix6*)
 453      ;;
 454  # We never want libdl on darwin. It is a fake libdl that just ends up making
 455  # `dyld` calls anyway.  The same applies to Cygwin.
 456    *-*-cygwin* | *-*-darwin* | *-*-msys*)
 457      ;;
 458    *)
 459      AC_CHECK_LIB(dl, dlopen, THREADDLLIBS="$THREADDLLIBS -ldl")
 460      ;;
 461  esac
 462  
 463  avoid_cpp_lib=no
 464  case "$host" in
 465    *-*-hpux*)
 466      avoid_cpp_lib=yes
 467      ;;
 468  esac
 469  AM_CONDITIONAL(AVOID_CPP_LIB,test $avoid_cpp_lib = yes)
 470  
 471  # Check for various headers.
 472  AC_CHECK_HEADER([execinfo.h], [],
 473      [AC_DEFINE([GC_MISSING_EXECINFO_H], [1], [Missing execinfo.h header.])])
 474  
 475  # extra `LD` flags which are required for targets.
 476  case "${host}" in
 477    *-*-darwin*)
 478      extra_ldflags_libgc=-Wl,-single_module
 479      ;;
 480  esac
 481  AC_SUBST(extra_ldflags_libgc)
 482  
 483  AC_SUBST(EXTRA_TEST_LIBS)
 484  
 485  target_all=libgc.la
 486  AC_SUBST(target_all)
 487  
 488  dnl If the target is an eCos system, use the appropriate eCos
 489  dnl I/O routines.
 490  dnl FIXME: this should not be a local option but a global target
 491  dnl system; at present there is no eCos target.
 492  TARGET_ECOS="no"
 493  AC_ARG_WITH([ecos],
 494      [AS_HELP_STRING([--with-ecos], [enable runtime eCos target support])],
 495      [TARGET_ECOS="$with_ecos"])
 496  
 497  addobjs=
 498  addlibs=
 499  CXXLIBS=
 500  
 501  case "$TARGET_ECOS" in
 502    no)
 503      ;;
 504    *)
 505      AC_DEFINE([ECOS], 1, [Define to enable eCos target support.])
 506      AM_CPPFLAGS="-I${TARGET_ECOS}/include $AM_CPPFLAGS"
 507      addobjs="$addobjs ecos.lo"
 508      ;;
 509  esac
 510  
 511  AM_CONDITIONAL(CPLUSPLUS, test "${enable_cplusplus}" = yes)
 512  
 513  AC_ARG_ENABLE(throw-bad-alloc-library,
 514      [AS_HELP_STRING([--disable-throw-bad-alloc-library],
 515                      [do not build C++ gctba library])])
 516  AM_CONDITIONAL(GC_TBA_LIBRARY,
 517                 test "${enable_cplusplus}" = yes \
 518                      -a "${enable_throw_bad_alloc_library}" != no)
 519  
 520  if test "$GCC" = yes; then
 521    if test "${enable_cplusplus}" = yes; then
 522      case "$host" in
 523        *-*-cygwin* | *-*-mingw* | *-*-msys*)
 524          AC_MSG_CHECKING([whether libsupc++ required])
 525          SUPC="`$CXX -print-file-name=libsupc++.a 2>/dev/null`"
 526          if test -n "$SUPC" -a "$SUPC" != "libsupc++.a"; then
 527            AC_MSG_RESULT(yes)
 528            CXXLIBS="-lsupc++"
 529          else
 530            AC_MSG_RESULT(no)
 531          fi
 532          ;;
 533      esac
 534    fi
 535  fi
 536  
 537  AC_SUBST(CXX)
 538  AC_SUBST(AM_CFLAGS)
 539  AC_SUBST(AM_CPPFLAGS)
 540  AC_SUBST(CXXLIBS)
 541  
 542  # Configuration of shared libraries.
 543  AC_MSG_CHECKING(whether to build shared libraries)
 544  AC_ENABLE_SHARED
 545  
 546  case "$host" in
 547    alpha-*-openbsd*)
 548      enable_shared=no
 549      ;;
 550  esac
 551  
 552  AC_MSG_RESULT($enable_shared)
 553  
 554  # Compile with `GC_DLL` defined unless building static libraries.
 555  if test "${enable_shared}" != no -a "${enable_static}" != yes; then
 556      AC_DEFINE(GC_DLL)
 557      if test "$GCC" = yes; then
 558        # Pass `-fvisibility=hidden` option if supported.
 559        AC_MSG_CHECKING([whether compiler supports -fvisibility])
 560        old_CFLAGS="$CFLAGS"
 561        CFLAGS="-Werror -fvisibility=hidden $CFLAGS"
 562        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
 563                  [ac_cv_fvisibility_hidden=yes], [ac_cv_fvisibility_hidden=no])
 564        CFLAGS="$old_CFLAGS"
 565        AS_IF([test "$ac_cv_fvisibility_hidden" = yes],
 566              [CFLAGS="-DGC_VISIBILITY_HIDDEN_SET -fvisibility=hidden $CFLAGS"],
 567              [CFLAGS="-DGC_NO_VISIBILITY $CFLAGS"])
 568        AC_MSG_RESULT($ac_cv_fvisibility_hidden)
 569      fi
 570  else
 571  
 572    case "$host" in
 573      *-*-cygwin* | *-*-mingw* | *-*-msys*)
 574        # Do not require the clients to link with `user32` system library.
 575        AC_DEFINE([DONT_USE_USER32_DLL], 1,
 576                  [Do not use user32.dll import library (Win32).])
 577        # Use inline variant of GC operators `new` and `delete` in `cpptest`
 578        # otherwise the system ones might be used instead because of arbitrary
 579        # ordering of object files when linking.
 580        CXXFLAGS="$CXXFLAGS -DGC_NOT_DLL"
 581        ;;
 582    esac
 583  fi
 584  
 585  # Configuration of machine-dependent code.
 586  AC_MSG_CHECKING(which machine-dependent code should be used)
 587  machdep=
 588  case "$host" in
 589    alpha-*-openbsd*)
 590      if test x"${ac_cv_lib_dl_dlopen}" != xyes ; then
 591        AC_MSG_WARN(
 592           "OpenBSD/Alpha without dlopen(). Shared library support is disabled.")
 593      fi
 594      ;;
 595    sparc-*-netbsd*)
 596      machdep="sparc_netbsd_mach_dep.lo"
 597      compile_asm=true
 598      ;;
 599    sparc*-*-linux* | sparc*-*-openbsd* | sparc64-*-freebsd* | sparc64-*-netbsd*)
 600      machdep="sparc_mach_dep.lo"
 601      compile_asm=true
 602      ;;
 603    sparc-sun-solaris2.3)
 604      machdep="sparc_mach_dep.lo"
 605      compile_asm=true
 606      AC_DEFINE(SUNOS53_SHARED_LIB, 1,
 607                [Define to work around a Solaris 5.3 bug (see dyn_load.c).])
 608      ;;
 609    sparc*-sun-solaris*)
 610      machdep="sparc_mach_dep.lo"
 611      compile_asm=true
 612      ;;
 613    ia64-*-*)
 614      machdep="ia64_save_regs_in_stack.lo"
 615      ;;
 616  esac
 617  if test "x$machdep" = x; then
 618    AC_MSG_RESULT(none)
 619  else
 620    AC_MSG_RESULT($machdep)
 621    addobjs="$addobjs $machdep"
 622  fi
 623  AC_SUBST(addobjs)
 624  AC_SUBST(addlibs)
 625  
 626  # Suppress "extension used" clang warning (when compiling `.S` files).
 627  if test x$compile_asm = xtrue -a "$GCC" = yes; then
 628    AC_MSG_CHECKING([whether compiler supports -Wno-language-extension-token])
 629    old_CFLAGS="$CFLAGS"
 630    CFLAGS="$CFLAGS -Werror -Wno-language-extension-token"
 631    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
 632                      [ac_cv_lang_ext_token=yes], [ac_cv_lang_ext_token=no])
 633    CFLAGS="$old_CFLAGS"
 634    AS_IF([test "$ac_cv_lang_ext_token" = yes],
 635          [CFLAGS="$CFLAGS -Wno-language-extension-token"])
 636    AC_MSG_RESULT($ac_cv_lang_ext_token)
 637  fi
 638  
 639  dnl We use these options to decide which functions to include.
 640  AC_ARG_WITH([target-subdir],
 641      [AS_HELP_STRING([--with-target-subdir=SUBDIR],
 642                      [configuring target with a cross compiler])])
 643  AC_ARG_WITH([cross-host],
 644      [AS_HELP_STRING([--with-cross-host=HOST],
 645                      [configuring host with a cross compiler])])
 646  
 647  dnl `automake` wants to see `AC_EXEEXT`.  But we do not need it.  And having
 648  dnl it is actually a problem, because the compiler we passed cannot
 649  dnl necessarily do a full link.  So we fool automake here.
 650  if false; then
 651    dnl `autoconf-2.50` runs `AC_EXEEXT` by default, and the macro expands
 652    dnl to nothing, so nothing would remain between `then` and `fi` if it
 653    dnl were not for the ":" below.
 654    :
 655    AC_EXEEXT
 656  fi
 657  
 658  dnl The collector might not properly work on IBM AIX when
 659  dnl built with gcc and -O.  So we remove -O in the appropriate case.
 660  AC_MSG_CHECKING(whether AIX gcc optimization fix is necessary)
 661  case "$host" in
 662    *aix*)
 663      if test "$GCC" = yes; then
 664        AC_MSG_RESULT(yes)
 665        new_CFLAGS=
 666        for i in $CFLAGS; do
 667          case "$i" in
 668            -O*)
 669              ;;
 670            *)
 671              new_CFLAGS="$new_CFLAGS $i"
 672              ;;
 673          esac
 674        done
 675        CFLAGS="$new_CFLAGS"
 676      else
 677        AC_MSG_RESULT(no)
 678      fi
 679      ;;
 680    *)
 681      AC_MSG_RESULT(no)
 682      ;;
 683  esac
 684  
 685  dnl Include defines that have become de facto standard.
 686  dnl ALL_INTERIOR_POINTERS and NO_EXECUTE_PERMISSION can be overridden
 687  dnl in the startup code.
 688  AC_DEFINE([NO_EXECUTE_PERMISSION], [1],
 689            [Define to make the collector not allocate executable memory
 690             by default.])
 691  AC_DEFINE([ALL_INTERIOR_POINTERS], [1],
 692            [Define to recognize all pointers to the interior of objects.])
 693  
 694  
 695  dnl Interface Selection
 696  dnl -------------------
 697  dnl
 698  dnl By default, make the library as general as possible.
 699  AC_ARG_ENABLE(gcj-support,
 700      [AS_HELP_STRING([--disable-gcj-support], [disable support for gcj])])
 701  if test x"$enable_gcj_support" != xno; then
 702      AC_DEFINE(GC_GCJ_SUPPORT, 1, [Define to include support for `gcj`.])
 703      case "$host" in
 704        *-*-kfreebsd*-gnu)
 705          # FIXME: For a reason, `gctest` hangs up on kFreeBSD if both of
 706          # `THREAD_LOCAL_ALLOC` and `GC_ENABLE_SUSPEND_THREAD` are defined.
 707          if test "${enable_thread_local_alloc}" = no; then
 708            AC_DEFINE(GC_ENABLE_SUSPEND_THREAD)
 709          fi
 710          ;;
 711        *)
 712          AC_DEFINE([GC_ENABLE_SUSPEND_THREAD], 1,
 713                [Define to turn on `GC_suspend_thread` support (Linux only).])
 714          ;;
 715      esac
 716  fi
 717  AM_CONDITIONAL(ENABLE_GCJ_SUPPORT, [test x"enable_gcj_support" != xno])
 718  
 719  dnl Interaction with other programs that might use signals.
 720  AC_ARG_ENABLE(sigrt-signals,
 721      [AS_HELP_STRING([--enable-sigrt-signals],
 722          [force GC to use SIGRTMIN-based signals for thread suspend/resume])])
 723  if test x"${enable_sigrt_signals}" = xyes; then
 724      AC_DEFINE([GC_USESIGRT_SIGNALS], 1,
 725                [Force the GC to use signals based on `SIGRTMIN+k`.])
 726  fi
 727  
 728  
 729  dnl Debugging
 730  dnl ---------
 731  
 732  AH_TEMPLATE([GC_HAVE_BUILTIN_BACKTRACE],
 733              [Define if backtrace information is supported.])
 734  AH_TEMPLATE([MAKE_BACK_GRAPH],
 735              [Define to build the collector with the support of the
 736               functionality to print max length of chain through unreachable
 737               objects ending in a reachable one.])
 738  AH_TEMPLATE([SAVE_CALL_COUNT],
 739              [The number of caller frames saved when allocating with the
 740               debugging API.])
 741  
 742  AC_ARG_ENABLE(valgrind-tracking,
 743      [AS_HELP_STRING([--enable-valgrind-tracking],
 744                      [heap profiler allocation tracking])],
 745      [if test "${enable_valgrind_tracking}" = yes; then
 746        AC_DEFINE([VALGRIND_TRACKING], 1,
 747                  [Define to support tracking `GC_malloc` and friends for heap
 748                   profiling tools.])
 749       fi])
 750  
 751  UNWINDLIBS=
 752  AC_ARG_ENABLE(gc-debug,
 753                [AS_HELP_STRING([--enable-gc-debug],
 754                      [include full support for pointer backtracing etc.])],
 755   [if test "$enable_gc_debug" = "yes"; then
 756      AC_MSG_WARN("Should define GC_DEBUG and use debug alloc in clients.")
 757      AC_DEFINE([KEEP_BACK_PTRS], 1,
 758                [Define to save back-pointers in debugging headers.])
 759      keep_back_ptrs=true
 760      AC_DEFINE([DBG_HDRS_ALL], 1,
 761                [Define to force debug headers on all objects.])
 762      AH_TEMPLATE([SHORT_DBG_HDRS],
 763                  [Shorten the headers to minimize object size at the expense
 764                   of checking for writes past the end.])
 765      case $host in
 766        ia64-*-linux*)
 767          AC_CHECK_LIB(unwind, backtrace,
 768             [AC_DEFINE(GC_HAVE_BUILTIN_BACKTRACE)
 769              UNWINDLIBS=-lunwind
 770              AC_MSG_WARN("Client code may need to link against libunwind.")])
 771          ;;
 772      esac
 773      case $host in
 774        i[3456]86-*-dgux* | *-*-*linux*)
 775          AC_DEFINE(MAKE_BACK_GRAPH)
 776          ;;
 777      esac
 778      case $host in
 779        e2k-*-linux*)
 780          # Some bug exists in `backtrace()`.
 781          ;;
 782        *-*-*linux*)
 783          AC_MSG_WARN("Client must not use -fomit-frame-pointer.")
 784          AC_DEFINE(SAVE_CALL_COUNT, 8)
 785          ;;
 786      esac
 787    fi])
 788  AM_CONDITIONAL([MAKE_BACK_GRAPH], [test x"$enable_gc_debug" = xyes])
 789  AM_CONDITIONAL([KEEP_BACK_PTRS], [test x"$keep_back_ptrs" = xtrue])
 790  
 791  # Check whether a compiler warning of unsafe `__builtin_return_address(1)`
 792  # could be suppressed by `-Wno-frame-address` option.
 793  # `__builtin_return_address(1)` is used by `libgc` for debugging purposes only.
 794  AC_MSG_CHECKING([whether -Wno-frame-address works])
 795  use_wno_error_frame_address=no
 796  old_CFLAGS="$CFLAGS"
 797  CFLAGS="$CFLAGS -Werror -Wno-frame-address $CFLAGS_EXTRA"
 798  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
 799      [if (!__builtin_return_address(1)) return 1;])],
 800    [use_wno_error_frame_address=yes])
 801  CFLAGS="$old_CFLAGS"
 802  AC_MSG_RESULT($use_wno_error_frame_address)
 803  if test x"$use_wno_error_frame_address" = xyes; then
 804    CFLAGS="$CFLAGS -Wno-frame-address"
 805  fi
 806  
 807  # Check for `dladdr` (used for debugging).
 808  AC_MSG_CHECKING(for dladdr)
 809  have_dladdr=no
 810  old_CFLAGS="$CFLAGS"
 811  CFLAGS="$CFLAGS $CFLAGS_EXTRA"
 812  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 813  #   define _GNU_SOURCE 1
 814  #   include <dlfcn.h>
 815    ], [
 816      Dl_info info;
 817      (void)dladdr("", &info);
 818    ])], [have_dladdr=yes])
 819  CFLAGS="$old_CFLAGS"
 820  AC_MSG_RESULT($have_dladdr)
 821  if test x"$have_dladdr" = xyes; then
 822    AC_DEFINE([HAVE_DLADDR], 1, [Define to use `dladdr` function.])
 823  fi
 824  
 825  # Check for `pthread_sigmask` and `sigset_t`.
 826  AS_IF([test "$THREADS" = posix],
 827    [AS_IF([test x$darwin_threads != xtrue -a x$win32_threads != xtrue],
 828      [AC_MSG_CHECKING(for pthread_sigmask)
 829       old_CFLAGS="$CFLAGS"
 830       CFLAGS="$CFLAGS $CFLAGS_EXTRA"
 831       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 832  #           define _GNU_SOURCE 1
 833  #           include <pthread.h>
 834  #           include <signal.h>
 835           ], [sigset_t t; (void)pthread_sigmask(SIG_BLOCK, 0, &t)])],
 836         [AC_MSG_RESULT(yes)
 837          AC_DEFINE([GC_HAVE_PTHREAD_SIGMASK], [1],
 838                    [Define to use `pthread_sigmask` function if needed.])],
 839         [AC_MSG_RESULT(no)])
 840       CFLAGS="$old_CFLAGS"])])
 841  
 842  # `sigsetjmp` could be a macro (thus `AC_CHECK_FUNCS` cannot be used).
 843  AC_MSG_CHECKING(for sigsetjmp)
 844  old_CFLAGS="$CFLAGS"
 845  CFLAGS="$CFLAGS $CFLAGS_EXTRA"
 846  AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <setjmp.h>],
 847                                  [sigjmp_buf t; sigsetjmp(t, 0)])],
 848    [AC_MSG_RESULT(yes)],
 849    [AC_MSG_RESULT(no)
 850     AC_DEFINE([GC_NO_SIGSETJMP], [1], [Missing `sigsetjmp` function.])])
 851  CFLAGS="$old_CFLAGS"
 852  
 853  # Build with `GC_wcsdup` support if possible.
 854  AC_MSG_CHECKING(for wcslen)
 855  old_CFLAGS="$CFLAGS"
 856  CFLAGS="$CFLAGS $CFLAGS_EXTRA"
 857  AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <wchar.h>],
 858                                  [wchar_t ws[] = {0}; (void)wcslen(&ws)])],
 859    [AC_MSG_RESULT(yes)
 860     AC_DEFINE([GC_REQUIRE_WCSDUP], [1],
 861               [Define and export `GC_wcsdup` function.])],
 862    [AC_MSG_RESULT(no)])
 863  CFLAGS="$old_CFLAGS"
 864  
 865  # `pthread_setname_np`, if available, may have 1, 2 or 3 arguments.
 866  AS_IF([test "$THREADS" = posix],
 867    [AC_MSG_CHECKING(for pthread_setname_np)
 868     old_CFLAGS="$CFLAGS"
 869     CFLAGS="$CFLAGS $CFLAGS_EXTRA -Werror"
 870     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 871  #         define _GNU_SOURCE 1
 872  #         include <pthread.h>
 873          ], [pthread_setname_np("thread-name")])],
 874       [AC_MSG_RESULT([yes (w/o tid)])
 875        AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID], [1],
 876                  [Define to use `pthread_setname_np(const char *)` function.])],
 877       [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 878  #         define _GNU_SOURCE 1
 879  #         include <pthread.h>
 880          ], [pthread_setname_np(pthread_self(), "thread-name-%u", 0)])],
 881         [AC_MSG_RESULT([yes (with tid and arg)])
 882          AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG], [1],
 883           [Define to use `pthread_setname_np(pthread_t, const char *, void *)`
 884            function.])],
 885         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 886  #             define _GNU_SOURCE 1
 887  #             include <pthread.h>
 888              ], [pthread_setname_np(pthread_self(), "thread-name")])],
 889           [AC_MSG_RESULT([yes (with tid)])
 890            AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITH_TID], [1],
 891                      [Define to use
 892                       `pthread_setname_np(pthread_t, const char *)`
 893                       function.])],
 894           [AC_MSG_RESULT(no)
 895            AC_MSG_CHECKING(for pthread_set_name_np)
 896            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
 897  #               include <pthread.h>
 898  #               include <pthread_np.h>
 899                ], [pthread_set_name_np(pthread_self(), "thread-name")])],
 900             [AC_MSG_RESULT(yes)
 901              AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP], [1],
 902                  [Define to use `pthread_set_name_np(pthread_t, const char *)`
 903                   function.])],
 904             [AC_MSG_RESULT(no)])])])])
 905     CFLAGS="$old_CFLAGS"])
 906  
 907  # Check for AViiON Machines running DGUX.
 908  ac_is_dgux=no
 909  AC_CHECK_HEADER(sys/dg_sys_info.h,
 910  [ac_is_dgux=yes;])
 911  
 912  dnl :GOTCHA: we do not check anything but sys/dg_sys_info.h
 913  if test $ac_is_dgux = yes; then
 914      dgux_spec_opts="-DDGUX -D_DGUX_SOURCE -Di386 -mno-legend -O2"
 915      CFLAGS="$dgux_spec_opts $CFLAGS"
 916      CXXFLAGS="$dgux_spec_opts $CXXFLAGS"
 917      if test "$enable_gc_debug" = "yes"; then
 918        CFLAGS="-g -mstandard $CFLAGS"
 919        CXXFLAGS="-g -mstandard $CXXFLAGS"
 920      fi
 921      AC_SUBST(CFLAGS)
 922      AC_SUBST(CXXFLAGS)
 923  fi
 924  
 925  AC_ARG_ENABLE(java-finalization,
 926      [AS_HELP_STRING([--disable-java-finalization],
 927                      [disable support for java finalization])])
 928  if test x"$enable_java_finalization" != xno; then
 929      AC_DEFINE([JAVA_FINALIZATION], 1,
 930                [Define to make it somewhat safer by default to finalize objects
 931                 out of order by specifying a nonstandard finalization mark
 932                 procedure.])
 933  fi
 934  
 935  AC_ARG_ENABLE(atomic-uncollectable,
 936      [AS_HELP_STRING([--disable-atomic-uncollectible],
 937                      [disable support for atomic uncollectible allocation])])
 938  if test x"$enable_atomic_uncollectible" != x"no"; then
 939      AC_DEFINE([GC_ATOMIC_UNCOLLECTABLE], 1,
 940          [Define to enable atomic uncollectible allocation.])
 941  fi
 942  
 943  AC_ARG_ENABLE(redirect-malloc,
 944      [AS_HELP_STRING([--enable-redirect-malloc],
 945                      [redirect malloc and friends to GC routines])])
 946  
 947  if test "${enable_redirect_malloc}" = yes; then
 948      if test "${enable_gc_debug}" = yes; then
 949          AC_DEFINE([REDIRECT_MALLOC], GC_debug_malloc_replacement,
 950                    [If defined, redirect `malloc` to this function.])
 951          AC_DEFINE([REDIRECT_REALLOC], GC_debug_realloc_replacement,
 952                    [If defined, redirect `realloc` to this function.])
 953          AC_DEFINE([REDIRECT_FREE], GC_debug_free,
 954                    [If defined, redirect `free` to this function.])
 955      else
 956          AC_DEFINE(REDIRECT_MALLOC, GC_malloc)
 957      fi
 958      AC_DEFINE([GC_USE_DLOPEN_WRAP], 1,
 959                [Define to cause the collector to redefine `malloc` and
 960                 intercepted `pthreads` routines with their real names while
 961                 using `dlsym` to refer to the original routines.])
 962  fi
 963  
 964  AC_ARG_ENABLE(disclaim,
 965      [AS_HELP_STRING([--disable-disclaim],
 966          [disable alternative (more efficient) finalization interface])])
 967  if test x"$enable_disclaim" != xno; then
 968      AC_DEFINE(ENABLE_DISCLAIM, 1,
 969          [Define to enable alternative finalization interface.])
 970  fi
 971  AM_CONDITIONAL(ENABLE_DISCLAIM,
 972      [test x"$enable_disclaim" != xno])
 973  
 974  AC_ARG_ENABLE(dynamic-pointer-mask,
 975      [AS_HELP_STRING([--enable-dynamic-pointer-mask],
 976          [support pointer mask/shift set at runtime])])
 977  if test "${enable_dynamic_pointer_mask}" = yes; then
 978      AC_DEFINE(DYNAMIC_POINTER_MASK, 1,
 979                [Define to support pointer mask/shift set at runtime.])
 980  fi
 981  
 982  AC_ARG_ENABLE(large-config,
 983      [AS_HELP_STRING([--enable-large-config],
 984          [optimize for large (> 100 MB) heap or root set])])
 985  if test "${enable_large_config}" = yes; then
 986      AC_DEFINE(LARGE_CONFIG, 1,
 987                [Define to optimize for large heaps or root sets.])
 988  fi
 989  
 990  dnl This is something of a hack.  When cross-compiling we turn off
 991  dnl some functionality.  We also enable the "small" configuration.
 992  dnl These is only correct when targeting an embedded system.  FIXME.
 993  if test -n "${with_cross_host}"; then
 994     AC_DEFINE([NO_CLOCK], 1,
 995               [Define to not use system clock (cross compiling).])
 996     AC_DEFINE([SMALL_CONFIG], 1,
 997               [Define to tune the collector for small heap sizes.])
 998  fi
 999  
1000  if test "$enable_gc_debug" = "no"; then
1001     AC_DEFINE([NO_DEBUGGING], 1,
1002               [Disable debugging, like `GC_dump` and its callees.])
1003  fi
1004  
1005  AC_SUBST(UNWINDLIBS)
1006  
1007  AC_ARG_ENABLE(gc-assertions,
1008      [AS_HELP_STRING([--enable-gc-assertions],
1009          [collector-internal assertion checking])])
1010  if test "${enable_gc_assertions}" = yes; then
1011      AC_DEFINE([GC_ASSERTIONS], 1,
1012                [Define to enable internal debug assertions.])
1013  fi
1014  
1015  AC_ARG_ENABLE(mmap,
1016      [AS_HELP_STRING([--enable-mmap],
1017                      [use mmap instead of sbrk to expand the heap])],
1018      gc_use_mmap=$enableval)
1019  
1020  AC_ARG_ENABLE(munmap,
1021      [AS_HELP_STRING([--enable-munmap=N],
1022                      [return page to the OS if page is marked as
1023                       empty during N collections (default: 7)])],
1024      MUNMAP_THRESHOLD=$enableval)
1025  if test x$enable_munmap != xno; then
1026      AC_DEFINE([USE_MMAP], 1,
1027                [Define to use `mmap` instead of `sbrk` to expand the heap.])
1028      AH_TEMPLATE([USE_WINALLOC],
1029                    [Define to use Win32 `VirtualAlloc` (instead of `sbrk` or
1030                     `mmap`) to expand the heap.])
1031      AC_DEFINE([USE_MUNMAP], 1,
1032                [Define to return memory to OS with `munmap` calls.])
1033      if test x$MUNMAP_THRESHOLD = x -o x$MUNMAP_THRESHOLD = xyes; then
1034        MUNMAP_THRESHOLD=7
1035      fi
1036      AC_DEFINE_UNQUOTED([MUNMAP_THRESHOLD], [${MUNMAP_THRESHOLD}],
1037          [Number of sequential garbage collections during those a candidate
1038           block for unmapping should be marked as free.])
1039  else
1040      if test "${gc_use_mmap}" = "yes"; then
1041        AC_DEFINE([USE_MMAP], 1,
1042                  [Define to use `mmap` instead of `sbrk` to expand the heap.])
1043      fi
1044  fi
1045  
1046  AC_ARG_ENABLE(dynamic-loading,
1047      [AS_HELP_STRING([--disable-dynamic-loading],
1048                      [build the collector with disabled tracing
1049                       of dynamic library data roots])])
1050  if test "${enable_dynamic_loading}" = "no"; then
1051    AC_DEFINE([IGNORE_DYNAMIC_LOADING], 1,
1052              [Do not define `DYNAMIC_LOADING` even if supported (i.e., build
1053               the collector with disabled tracing of dynamic library data
1054               roots).])
1055  fi
1056  
1057  AC_ARG_ENABLE(register-main-static-data,
1058      [AS_HELP_STRING([--disable-register-main-static-data],
1059                      [skip the initial guess of data root sets])])
1060  if test "${enable_register_main_static_data}" = "no"; then
1061      AC_DEFINE([GC_DONT_REGISTER_MAIN_STATIC_DATA], 1,
1062                [Skip the initial guess of data root sets.])
1063  fi
1064  
1065  AC_ARG_ENABLE(checksums,
1066      [AS_HELP_STRING([--enable-checksums],
1067                      [report on erroneously cleared dirty bits at
1068                       substantial performance cost; use only for
1069                       debugging of the incremental collector])])
1070  if test x$enable_checksums = xyes; then
1071      if test x$enable_munmap != xno -o x$THREADS != xnone; then
1072          AC_MSG_ERROR([CHECKSUMS not compatible with USE_MUNMAP or threads])
1073      fi
1074      AC_DEFINE([CHECKSUMS], 1,
1075                [Erroneously cleared dirty bits checking.  Use only for
1076                 debugging of the incremental collector.])
1077  fi
1078  AM_CONDITIONAL([CHECKSUMS], test x$enable_checksums = xyes)
1079  
1080  AM_CONDITIONAL(USE_LIBDIR, test -z "$with_cross_host")
1081  
1082  AC_ARG_ENABLE(werror,
1083      [AS_HELP_STRING([--enable-werror], [pass -Werror to the C compiler])],
1084      werror_flag=$enableval, werror_flag=no)
1085  if test x$werror_flag = xyes; then
1086      WERROR_CFLAGS="-Werror"
1087  fi
1088  AC_SUBST([WERROR_CFLAGS])
1089  
1090  AC_ARG_ENABLE(single-obj-compilation,
1091      [AS_HELP_STRING([--enable-single-obj-compilation],
1092                      [compile all libgc source files into single .o
1093                       (default: yes if static libraries are disabled)])],
1094      [], [AS_IF([test x"$enable_static" = xno],
1095                 [enable_single_obj_compilation=yes])])
1096  AM_CONDITIONAL([SINGLE_GC_OBJ],
1097                 [test x"$enable_single_obj_compilation" = xyes])
1098  
1099  AC_ARG_ENABLE(gcov,
1100      [AS_HELP_STRING([--enable-gcov], [turn on code coverage analysis])])
1101  if test "$enable_gcov" = "yes"; then
1102    CFLAGS="-D NTHREADS=20 $CFLAGS --coverage"
1103    if test "${enable_shared}" = no; then
1104      # FIXME: As of g++-4.8.4/x64, in case of shared library build, `cpptest`
1105      # linkage fails with "hidden symbol atexit is referenced by DSO" message.
1106      CXXFLAGS="$CXXFLAGS --coverage"
1107    fi
1108    # Turn off optimization to get accurate line numbers.
1109    CFLAGS=`echo "$CFLAGS" | sed -e 's/-O\(1\|2\|3\|4\|s\|fast\)\?//g'`
1110    CXXFLAGS=`echo "$CXXFLAGS" | sed -e 's/-O\(1\|2\|3\|4\|s\|fast\)\?//g'`
1111  fi
1112  
1113  AC_ARG_ENABLE(docs,
1114          [AS_HELP_STRING([--disable-docs],
1115                          [do not build and install documentation])])
1116  AM_CONDITIONAL(ENABLE_DOCS, test x$enable_docs != xno)
1117  
1118  AM_CONDITIONAL(ENABLE_SHARED, test x$enable_shared = xyes)
1119  
1120  # Atomic_ops
1121  # ----------
1122  
1123  # Do we want to use an external `libatomic_ops`?  By default use it
1124  # if it is found.
1125  AC_ARG_WITH([libatomic-ops],
1126      [AS_HELP_STRING([--with-libatomic-ops[=yes|no|check|none]],
1127                      [use an external libatomic_ops? (default: check;
1128                       none: use compiler intrinsics or no thread support)])],
1129      [], [AS_IF([test x"$THREADS" != xnone],
1130                 [with_libatomic_ops=check], [with_libatomic_ops=none])])
1131  
1132  # Check whether compiler atomic intrinsics can be used.
1133  if test x"$with_libatomic_ops" = xcheck; then
1134    AC_MSG_CHECKING(for compiler intrinsics support)
1135    old_CFLAGS="$CFLAGS"
1136    CFLAGS="$CFLAGS $CFLAGS_EXTRA -DGC_BUILTIN_ATOMIC"
1137    CFLAGS="$CFLAGS -I${srcdir}/include -I${srcdir}"
1138    AC_RUN_IFELSE([AC_LANG_SOURCE([[#include "tests/atomicops.c"]])],
1139      [AC_MSG_RESULT(yes)
1140       with_libatomic_ops=none],
1141      [AC_MSG_RESULT(no)], [AC_MSG_RESULT(skipped because cross-compiling)])
1142    CFLAGS="$old_CFLAGS"
1143  fi
1144  
1145  # Check for an external `libatomic_ops` if the above answer is `yes` or
1146  # `check`.  If not found, fail on `yes`, and convert `check` to `no`.
1147  # First, check that `libatomic_ops` usage is not disabled explicitly.
1148  missing_libatomic_ops=false
1149  AS_IF([test x"$with_libatomic_ops" != xno -a x"$with_libatomic_ops" != xnone],
1150    [missing_libatomic_ops=true])
1151  
1152  dnl To avoid "syntax error near unexpected token ATOMIC_OPS" configure error
1153  dnl observed by some clients, the following 3 code lines are commented out:
1154  dnl
1155  dnl AS_IF([test x$missing_libatomic_ops = xtrue],
1156  dnl  [PKG_CHECK_MODULES([ATOMIC_OPS], [atomic_ops],
1157  dnl    [missing_libatomic_ops=false], [[]])])
1158  
1159  dnl Retry with AC_CHECK_HEADER if PKG_CHECK_MODULES failed.
1160  AS_IF([test x$missing_libatomic_ops = xtrue],
1161        [AC_CHECK_HEADER([atomic_ops.h], [missing_libatomic_ops=false])])
1162  AS_IF([test x$missing_libatomic_ops = xtrue],
1163        [AS_IF([test x"$with_libatomic_ops" != xcheck],
1164               [AC_MSG_ERROR([An external libatomic_ops was not found])])
1165          with_libatomic_ops=no])
1166  
1167  # If we have neither an external or an internal variant, offer a useful hint
1168  # and exit.
1169  AS_IF([test x"$with_libatomic_ops" = xno \
1170              -a ! -e "$srcdir/libatomic_ops/src/atomic_ops.h"],
1171    [AC_MSG_ERROR([libatomic_ops is required.  You can either install it on
1172                   your system, or fetch and unpack a recent version into the
1173                   source directory and link or rename it to libatomic_ops.])])
1174  
1175  # Finally, emit the definitions for bundled or external AO library.
1176  AC_MSG_CHECKING([which libatomic_ops to use])
1177  AS_IF([test x"$with_libatomic_ops" != xno],
1178    [AS_IF([test x"$with_libatomic_ops" != xnone -a x"$THREADS" != xnone],
1179           [AC_MSG_RESULT([external])
1180            ATOMIC_OPS_LIBS="-latomic_ops"
1181            AC_SUBST([ATOMIC_OPS_LIBS])],
1182           [AC_MSG_RESULT([none])
1183            AS_IF([test x"$THREADS" != xnone],
1184                  [AC_DEFINE([GC_BUILTIN_ATOMIC], [1],
1185                             [Use GCC atomic intrinsics instead of
1186                              `libatomic_ops` primitives.])])])
1187      AO_TRYLINK_CFLAGS=""],
1188    [AC_MSG_RESULT([internal])
1189     AO_TRYLINK_CFLAGS="-I${srcdir}/libatomic_ops/src"
1190     ATOMIC_OPS_CFLAGS='-I$(top_builddir)/libatomic_ops/src -I$(top_srcdir)/libatomic_ops/src'
1191     ATOMIC_OPS_LIBS=""
1192     AC_SUBST([ATOMIC_OPS_CFLAGS])
1193     AC_CONFIG_SUBDIRS([libatomic_ops])
1194    ])
1195  AM_CONDITIONAL([USE_INTERNAL_LIBATOMIC_OPS],
1196      [test x$with_libatomic_ops = xno -a x"$THREADS" != xnone])
1197  AM_CONDITIONAL([NEED_ATOMIC_OPS_ASM],
1198      [test x$with_libatomic_ops = xno -a x$need_atomic_ops_asm = xtrue])
1199  
1200  # Check whether particular AO primitives are emulated with locks.
1201  # The check below is based on the fact that linking with the `libatomic_ops`
1202  # binary file is not needed in case of absence of the emulation (except for
1203  # Solaris/SPARC).
1204  AS_IF([test x$with_libatomic_ops != xnone -a x$need_atomic_ops_asm != xtrue],
1205      [old_CFLAGS="$CFLAGS"
1206       CFLAGS="$CFLAGS $AO_TRYLINK_CFLAGS $CFLAGS_EXTRA"
1207       AC_MSG_CHECKING([for lock-free AO_or primitive])
1208       AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "atomic_ops.h"],
1209                                       [AO_t x=0; AO_or(&x,1)])],
1210         [AC_MSG_RESULT(yes)
1211          AC_DEFINE([HAVE_LOCKFREE_AO_OR], [1],
1212            [`libatomic_ops` `AO_or` primitive implementation is lock-free.])],
1213         [AC_MSG_RESULT(no)])
1214       AC_MSG_CHECKING([for lock-free AO load/store, test-and-set primitives])
1215       AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "atomic_ops.h"],
1216   [AO_t x=0;unsigned char c=0;AO_TS_t z=AO_TS_INITIALIZER;
1217    (void)AO_test_and_set_acquire(&z);AO_CLEAR(&z);AO_compiler_barrier();
1218    AO_store(&x,AO_load(&x)+1);AO_char_store(&c,AO_char_load(&c)+1);
1219    AO_store_release(&x,AO_load_acquire(&x)+1)])],
1220          [AC_MSG_RESULT(yes)],
1221          [AC_MSG_RESULT(no)
1222           use_thread_local_alloc=no
1223           AC_DEFINE([BASE_ATOMIC_OPS_EMULATED], [1],
1224                     [AO load, store and/or test-and-set primitives are
1225                      implemented in `libatomic_ops` using locks.])])
1226        AS_IF([test x$use_parallel_mark != xno],
1227          [AC_MSG_CHECKING(
1228              [for lock-free compare-and-swap and fetch-and-add primitives])
1229           AC_LINK_IFELSE([AC_LANG_PROGRAM([
1230  #             define AO_REQUIRE_CAS
1231  #             include "atomic_ops.h"
1232              ],
1233   [AO_t x=0;(void)AO_fetch_and_add(&x,1);(void)AO_compare_and_swap(&x,1,2)])],
1234                      [AC_MSG_RESULT(yes)],
1235                      [AC_MSG_RESULT(no)
1236                       use_parallel_mark=no ])])
1237        CFLAGS="$old_CFLAGS"])
1238  
1239  AS_IF([test x$use_parallel_mark != xno],
1240        [AC_DEFINE(PARALLEL_MARK)])
1241  AS_IF([test x$use_thread_local_alloc != xno],
1242        [AC_DEFINE(THREAD_LOCAL_ALLOC)])
1243  AM_CONDITIONAL(THREAD_LOCAL_ALLOC, test x$use_thread_local_alloc != xno)
1244  
1245  AC_ARG_ENABLE(handle-fork,
1246      [AS_HELP_STRING([--enable-handle-fork[=yes|no|auto|manual]],
1247                      [attempt to ensure a usable collector after fork()
1248                       in multi-threaded programs (default: auto;
1249                       manual: GC_atfork_prepare/parent/child should be
1250                       called by the client)])])
1251  if test "${enable_handle_fork}" = yes; then
1252      AC_DEFINE(HANDLE_FORK, 1,
1253                [Define to install `pthread_atfork` handlers by default.])
1254  elif test "${enable_handle_fork}" = no; then
1255      AC_DEFINE(NO_HANDLE_FORK, 1,
1256                [Prohibit installation of `pthread_atfork` handlers.])
1257  elif test "${enable_handle_fork}" != manual -a x$THREADS = xposix; then
1258      # If the option is omitted, `pthread_atfork` handlers are installed
1259      # by default for the targets where `pthread_atfork` is known to work.
1260      case "$host" in
1261        *-*-aix* | *-*-android* | *-*-cygwin* | *-*-darwin* | *-*-freebsd* | \
1262        *-*-haiku* | *-*-hpux11* | *-*-irix* | *-*-kfreebsd*-gnu | \
1263        *-*-*linux* | *-*-netbsd* | *-*-openbsd* | *-*-osf* | *-*-solaris*)
1264          AC_DEFINE(HANDLE_FORK)
1265          ;;
1266      esac
1267  fi
1268  
1269  dnl Produce the Files
1270  dnl -----------------
1271  
1272  AC_CONFIG_FILES([Makefile bdw-gc.pc])
1273  
1274  AC_CONFIG_COMMANDS([default],,
1275     [srcdir="${srcdir}"
1276      host=${host}
1277      CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
1278      CC="${CC}"
1279      DEFS="$DEFS"])
1280  
1281  AC_OUTPUT
1282