2 # When this file changes, rerun autogen.sh.
6 AC_INIT([libdispatch], [1.1], [libdispatch@macosforge.org], [libdispatch])
8 AC_CONFIG_AUX_DIR(config)
9 AC_CONFIG_HEADER([config/config.h])
10 AC_CONFIG_MACRO_DIR([m4])
11 ac_clean_files=a.out.dSYM
14 AC_PROG_CC([clang gcc cc])
15 AC_PROG_CXX([clang++ g++ c++])
16 AC_PROG_OBJC([clang gcc cc])
19 # On Mac OS X, some required header files come from other source packages;
20 # allow specifying where those are.
22 AC_ARG_WITH([apple-libc-source],
23 [AS_HELP_STRING([--with-apple-libc-source],
24 [Specify path to Apple Libc source])], [
25 apple_libc_source_pthreads_path=${withval}/pthreads
26 CPPFLAGS="$CPPFLAGS -I$apple_libc_source_pthreads_path"
29 AC_ARG_WITH([apple-libclosure-source],
30 [AS_HELP_STRING([--with-apple-libclosure-source],
31 [Specify path to Apple libclosure source])], [
32 apple_libclosure_source_path=${withval}
33 CPPFLAGS="$CPPFLAGS -I$apple_libclosure_source_path"
36 AC_ARG_WITH([apple-xnu-source],
37 [AS_HELP_STRING([--with-apple-xnu-source],
38 [Specify path to Apple XNU source])], [
39 apple_xnu_source_libkern_path=${withval}/libkern
40 apple_xnu_source_osfmk_path=${withval}/osfmk
41 CPPFLAGS="$CPPFLAGS -I$apple_xnu_source_libkern_path"
44 AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders,
45 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders],
46 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])]
48 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
49 [CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/System.framework/PrivateHeaders"]
53 # On Mac OS X, libdispatch_init is automatically invoked during libSystem
54 # process initialization. On other systems, it is tagged as a library
55 # constructor to be run by automatically by the runtime linker.
57 AC_ARG_ENABLE([libdispatch-init-constructor],
58 [AS_HELP_STRING([--disable-libdispatch-init-constructor],
59 [Disable libdispatch_init as a constructor])],,
60 [AS_IF([test -f /usr/lib/system/libdispatch.dylib],
61 [enable_libdispatch_init_constructor=no])]
63 AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"],
64 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1,
65 [Define to tag libdispatch_init as a constructor])]
69 # On Mac OS X libdispatch can use the non-portable direct pthread TSD functions
71 AC_ARG_ENABLE([apple-tsd-optimizations],
72 [AS_HELP_STRING([--enable-apple-tsd-optimizations],
73 [Use non-portable pthread TSD optimizations for Mac OS X.])]
75 AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
76 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1,
77 [Define to use non-portable pthread TSD optimizations for Mac OS X)])]
80 AC_USE_SYSTEM_EXTENSIONS
83 AC_PATH_PROGS(MIG, mig)
85 AC_PATH_PROG(LEAKS, leaks)
86 AS_IF([test "x$LEAKS" != "x"],
87 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])]
90 AM_INIT_AUTOMAKE([foreign])
92 DISPATCH_C_ATOMIC_BUILTINS
94 case $dispatch_cv_atomic in
96 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
97 AC_SUBST([MARCH_FLAGS]) ;;
98 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
102 # Find libraries we will need
104 AC_SEARCH_LIBS(clock_gettime, rt)
105 AC_SEARCH_LIBS(pthread_create, pthread)
108 # Prefer native kqueue(2); otherwise use libkqueue if present.
110 AC_CHECK_HEADER(sys/event.h, [],
111 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
115 # Checks for header files.
118 AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h])
120 # hack for pthread_machdep.h's #include <System/machine/cpu_capabilities.h>
121 AS_IF([test -n "$apple_xnu_source_osfmk_path"], [
122 saveCPPFLAGS="$CPPFLAGS"
123 CPPFLAGS="$CPPFLAGS -I."
124 ln -fsh "$apple_xnu_source_osfmk_path" System
126 AC_CHECK_HEADERS([pthread_machdep.h])
127 AS_IF([test -n "$apple_xnu_source_osfmk_path"], [
129 CPPFLAGS="$saveCPPFLAGS"
130 AC_CONFIG_COMMANDS([src/System],
131 [ln -fsh "$apple_xnu_source_osfmk_path" src/System],
132 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
136 # Parts of the testsuite use CoreFoundation and Foundation
138 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
139 [have_corefoundation=true], [have_corefoundation=false]
141 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
142 AC_LANG_PUSH([Objective C])
143 AC_CHECK_HEADER([Foundation/Foundation.h], [
144 AC_DEFINE(USE_OBJC, 1, [Define to use Objective-C runtime])
145 have_foundation=true], [have_foundation=false]
147 AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation)
148 AC_LANG_POP([Objective C])
151 # We use the availability of mach.h to decide whether to compile in all sorts
152 # of Machisms, including using Mach ports as event sources, etc.
154 AC_CHECK_HEADER([mach/mach.h], [
155 AC_DEFINE(HAVE_MACH, 1, [Define if mach is present])
156 AC_DEFINE(__DARWIN_NON_CANCELABLE, 1, [Define if using Darwin $NOCANCEL])
157 have_mach=true], [have_mach=false]
159 AM_CONDITIONAL(USE_MIG, $have_mach)
162 # We use the availability of pthread_workqueue.h to decide whether to compile
163 # in support for pthread work queues.
165 AC_CHECK_HEADER([pthread_workqueue.h],
166 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])]
168 AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np])
171 # Find functions and declarations we care about.
173 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
174 [[#include <time.h>]])
175 AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_SIGNAL], [], [],
176 [[#include <sys/event.h>]])
177 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
178 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
179 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]])
180 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
181 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
183 AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
184 [have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],
185 [[#include <sys/spawn.h>]]
187 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
189 AC_CHECK_FUNC([sem_init],
190 [have_sem_init=true], [have_sem_init=false]
194 # We support both Mach semaphores and POSIX semaphores; if the former are
195 # available, prefer them.
197 AC_MSG_CHECKING([what semaphore type to use]);
198 AS_IF([test "x$have_mach" = "xtrue"],
199 [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
200 AC_MSG_RESULT([Mach semaphores])],
201 [test "x$have_sem_init" = "xtrue"],
202 [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
203 AC_MSG_RESULT([POSIX semaphores])],
204 [AC_MSG_ERROR([no supported semaphore type])]
207 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
208 [#ifdef HAVE_SYS_CDEFS_H
209 #include <sys/cdefs.h>
214 AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [
216 CFLAGS="$CFLAGS -fvisibility=hidden"
217 AC_LINK_IFELSE([AC_LANG_PROGRAM([
218 extern __attribute__ ((visibility ("default"))) int foo; int foo;], [foo = 0;])],
219 [dispatch_cv_cc_visibility_hidden="yes"], [dispatch_cv_cc_visibility_hidden="no"])
222 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
223 VISIBILITY_FLAGS="-fvisibility=hidden"
225 AC_SUBST([VISIBILITY_FLAGS])
227 AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [
229 CFLAGS="$CFLAGS -momit-leaf-frame-pointer"
230 AC_LINK_IFELSE([AC_LANG_PROGRAM([
231 extern int foo(void); int foo(void) {return 1;}], [foo();])],
232 [dispatch_cv_cc_omit_leaf_fp="yes"], [dispatch_cv_cc_omit_leaf_fp="no"])
235 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
236 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
238 AC_SUBST([OMIT_LEAF_FP_FLAGS])
240 AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
241 saveLDFLAGS="$LDFLAGS"
242 LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6"
243 AC_LINK_IFELSE([AC_LANG_PROGRAM([
244 extern int foo; int foo;], [foo = 0;])],
245 [dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
246 LDFLAGS="$saveLDFLAGS"
248 AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"])
251 # Temporary: some versions of clang do not mark __builtin_trap() as
252 # __attribute__((__noreturn__)). Detect and add if required.
255 [AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])],
256 [AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1, [Define if __builtin_trap marked noreturn])]
260 # Generate Makefiles.
262 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile private/Makefile src/Makefile])