2 # When this file changes, rerun autogen.sh.
6 AC_INIT([libdispatch], [1.0], [libdispatch@macosforge.org], [libdispatch])
8 AC_CONFIG_AUX_DIR(config)
9 AC_CONFIG_HEADER([config/config.h])
10 AC_CONFIG_MACRO_DIR([m4])
14 # On Mac OS X, some required header files come from other source packages;
15 # allow specifying where those are.
17 AC_ARG_WITH([apple-libc-source],
18 [AS_HELP_STRING([--with-apple-libc-source],
19 [Specify path to Apple Libc source])],
20 [apple_libc_source_path=${withval}/pthreads
21 APPLE_LIBC_SOURCE_PATH=-I$apple_libc_source_path
22 CPPFLAGS="$CPPFLAGS -I$apple_libc_source_path"],
23 [APPLE_LIBC_SOURCE_PATH=]
25 AC_SUBST([APPLE_LIBC_SOURCE_PATH])
27 AC_ARG_WITH([apple-xnu-source],
28 [AS_HELP_STRING([--with-apple-xnu-source],
29 [Specify path to Apple XNU source])],
30 [apple_xnu_source_path=${withval}/libkern
31 APPLE_XNU_SOURCE_PATH=-I$apple_xnu_source_path
32 CPPFLAGS="$CPPFLAGS -I$apple_xnu_source_path"],
33 [APPLE_XNU_SOURCE_PATH=]
35 AC_SUBST([APPLE_XNU_SOURCE_PATH])
37 AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders,
38 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders],
39 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])]
41 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
42 [CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/System.framework/PrivateHeaders"]
46 # Try to build the legacy API only if specifically requested.
48 AC_ARG_ENABLE([legacy-api],
49 [AS_HELP_STRING([--enable-legacy-api], [Enable legacy (deprecated) API.])]
52 AS_IF([test "x$enable_legacy_api" != "xyes"],
54 AC_DEFINE(DISPATCH_NO_LEGACY, 1,[Define to compile out legacy API])],
57 AM_CONDITIONAL(USE_LEGACY_API, $use_legacy_api)
60 # On Mac OS X Snow Leopard, libpispatch_init is automatically invoked during
61 # libsyscall process setup. On other systems, it is tagged as a library
62 # constructor to be run by automatically by the runtime linker.
64 AC_ARG_ENABLE([libdispatch-init-constructor],
65 [AS_HELP_STRING([--disable-libdispatch-init-constructor],
66 [Disable libdispatch_init as a constructor])]
69 AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"],
70 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1,
71 [Define to tag libdispatch_init as a constructor])]
75 # Whether or not to include/reference a crashreporter symbol.
77 AC_ARG_ENABLE([apple-crashreporter-info],
78 [AS_HELP_STRING([--enable-apple-crashreporter-info],
79 [Use Mac OS X crashreporter info])]
82 AS_IF([test "x$enable_apple_crashreporter_info" = "xyes"],
83 [AC_DEFINE(USE_APPLE_CRASHREPORTER_INFO, 1,
84 [Define to use Mac OS X crashreporter info])]
88 # libdispatch has micro-optimized and deeply personal knowledge of Mac OS
89 # implementation details. Only enable this if explicitly requested, as it
90 # will lead to data corruption if applied on systems violating its
93 AC_ARG_ENABLE([apple-tsd-optimizations],
94 [AS_HELP_STRING([--enable-apple-tsd-optimizations],
95 [Use non-portable pthread TSD optimizations for Mac OS X.])]
98 AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
99 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1,
100 [Define to use non-portable pthread TSD optimizations for Mac OS X)])]
103 AC_ARG_ENABLE([apple-semaphore-optimizations],
104 [AS_HELP_STRING([--enable-apple-semaphore-optimizations],
105 [Use non-portable semaphore optimizations for Mac OS X.])]
108 AS_IF([test "x$enable_apple_semaphore_optimizations" = "xyes"],
109 [AC_DEFINE(USE_APPLE_SEMAPHORE_OPTIMIZATIONS, 1,
110 [Define to use non-portablesemaphore optimizations for Mac OS X])]
113 AC_USE_SYSTEM_EXTENSIONS
118 AC_PATH_PROGS(MIG, mig)
120 AC_PATH_PROG(LEAKS, leaks)
121 AS_IF([test "x$LEAKS" != "x"],
122 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])]
125 AM_INIT_AUTOMAKE([foreign])
127 DISPATCH_C_ATOMIC_BUILTINS
129 case $dispatch_cv_atomic in
131 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
132 AC_SUBST([MARCH_FLAGS]) ;;
133 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
137 # Find libraries we will need
139 AC_SEARCH_LIBS(clock_gettime, rt)
140 AC_SEARCH_LIBS(pthread_create, pthread)
143 # Prefer native kqueue(2); otherwise use libkqueue if present.
145 AC_CHECK_HEADER(sys/event.h, [],
146 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
150 # Checks for header files.
153 AC_CHECK_HEADERS([TargetConditionals.h pthread_machdep.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h sys/sysctl.h])
156 # Core Services is tested in one of the GCD regression tests, so test for its
157 # presence using its header file.
159 AC_CHECK_HEADER([CoreServices/CoreServices.h],
160 [have_coreservices=true],
161 [have_coreservices=false]
163 AM_CONDITIONAL(HAVE_CORESERVICES, $have_coreservices)
166 # We use the availability of mach.h to decide whether to compile in all sorts
167 # of Machisms, including using Mach ports as event sources, etc.
169 AC_CHECK_HEADER([mach/mach.h],
170 [AC_DEFINE(HAVE_MACH, 1,Define if mach is present)
174 AM_CONDITIONAL(USE_MIG, $have_mach)
177 # We use the availability of pthread_workqueue.h to decide whether to compile
178 # in support for pthread work queues.
180 AC_CHECK_HEADER([pthread_workqueue.h],
181 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1,Define if pthread work queues are present)]
185 # Find functions and declarations we care about.
187 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC, CLOCK_REALTIME], [], [],
188 [[#include <time.h>]])
189 AC_CHECK_DECLS([EVFILT_LIO, EVFILT_SESSION, NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL], [], [],
190 [[#include <sys/types.h>
191 #include <sys/event.h>]])
192 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
193 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
194 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]])
195 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
196 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
198 AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
199 [have_posix_spawn_start_suspended=true],
200 [have_posix_spawn_start_suspended=false],
201 [[#include <sys/spawn.h>]]
203 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
205 AC_CHECK_FUNC([sem_init],
206 [have_sem_init=true],
207 [have_sem_init=false]
211 # We support both Mach semaphores and POSIX semaphores; if the former are
212 # available, prefer them.
214 AC_MSG_CHECKING([what semaphore type to use]);
215 AS_IF([test "x$have_mach" = "xtrue"],
216 [AC_DEFINE(USE_MACH_SEM, 1,[Define to use Mach semaphores])
217 AC_MSG_RESULT([Mach semaphores])],
218 [test "x$have_sem_init" = "xtrue"],
219 [AC_DEFINE(USE_POSIX_SEM, 1,[Define to use POSIX semaphores])
220 AC_MSG_RESULT([POSIX semaphores])],
221 [AC_MSG_ERROR([no supported semaphore type])]
224 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
225 [#ifdef HAVE_SYS_CDEFS_H
226 #include <sys/cdefs.h>
229 DISPATCH_C_PRIVATE_EXTERN
233 # Temporary: some versions of clang do not mark __builtin_trap() as
234 # __attribute__((__noreturn__)). Detect and add if required.
237 AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])], [
238 AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1,[Define if __builtin_trap marked noreturn])
242 # Generate Makefiles.
244 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile src/Makefile testing/Makefile])