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