2 # When this file changes, rerun autogen.sh.
6 AC_INIT([libdispatch], [1.3], [https://bugs.swift.org], [libdispatch], [https://github.com/apple/swift-corelibs-libdispatch])
8 AC_CONFIG_AUX_DIR(config)
9 AC_CONFIG_HEADER([config/config_ac.h])
10 AC_CONFIG_MACRO_DIR([m4])
11 ac_clean_files=a.out.dSYM
15 # Command line argument to specify build variant (default to release).
16 # Impacts default value of CFLAGS et al. so must come before AC_PROG_CC
18 AC_ARG_WITH([build-variant],
19 [AS_HELP_STRING([--with-build-variant=release|debug|releaseassert|releasedebuginfo], [Specify build variant [default=release]])],
20 [dispatch_build_variant=${withval}],
21 [dispatch_build_variant=release]
23 AS_CASE([$dispatch_build_variant],
25 default_compiler_flags="-g -O0"
26 dispatch_enable_asserts=true
27 dispatch_enable_optimization=false
30 default_compiler_flags="-O2"
31 dispatch_enable_asserts=false
32 dispatch_enable_optimization=true
35 default_compiler_flags="-O2"
36 dispatch_enable_asserts=true
37 dispatch_enable_optimization=true
40 default_compiler_flags="-g -O2"
41 dispatch_enable_asserts=false
42 dispatch_enable_optimization=true
44 [AC_MSG_ERROR("invalid build-variant $dispatch_build_variant")]
46 AM_CONDITIONAL(DISPATCH_ENABLE_ASSERTS, $dispatch_enable_asserts)
47 AM_CONDITIONAL(DISPATCH_ENABLE_OPTIMIZATION, $dispatch_enable_optimization)
49 : ${CFLAGS=$default_compiler_flags}
50 : ${CXXFLAGS=$default_compiler_flags}
51 : ${OBJCFLAGS=$default_compiler_flags}
52 : ${OBJCXXFLAGS=$default_compiler_flags}
54 AC_PROG_CC([clang gcc cc])
55 AC_PROG_CXX([clang++ g++ c++])
56 AC_PROG_OBJC([clang gcc cc])
57 AC_PROG_OBJCXX([clang++ g++ c++])
60 # On Mac OS X, some required header files come from other source packages;
61 # allow specifying where those are.
63 AC_ARG_WITH([apple-libpthread-source],
64 [AS_HELP_STRING([--with-apple-libpthread-source],
65 [Specify path to Apple libpthread source])], [
66 apple_libpthread_source_path=${withval}
67 CPPFLAGS="$CPPFLAGS -isystem $apple_libpthread_source_path"
70 AC_ARG_WITH([apple-libplatform-source],
71 [AS_HELP_STRING([--with-apple-libplatform-source],
72 [Specify path to Apple libplatform source])], [
73 apple_libplatform_source_include_path=${withval}/include
74 CPPFLAGS="$CPPFLAGS -isystem $apple_libplatform_source_include_path"
77 AC_ARG_WITH([apple-libclosure-source],
78 [AS_HELP_STRING([--with-apple-libclosure-source],
79 [Specify path to Apple libclosure source])], [
80 apple_libclosure_source_path=${withval}
81 CPPFLAGS="$CPPFLAGS -isystem $apple_libclosure_source_path"
84 AC_ARG_WITH([apple-xnu-source],
85 [AS_HELP_STRING([--with-apple-xnu-source],
86 [Specify path to Apple XNU source])], [
87 apple_xnu_source_libsyscall_path=${withval}/libsyscall
88 apple_xnu_source_libproc_path=${withval}/libsyscall/wrappers/libproc
89 apple_xnu_source_libkern_path=${withval}/libkern
90 apple_xnu_source_bsd_path=${withval}/bsd
91 apple_xnu_source_osfmk_path=${withval}/osfmk
92 CPPFLAGS="$CPPFLAGS -idirafter $apple_xnu_source_libkern_path -isystem $apple_xnu_source_bsd_path -isystem $apple_xnu_source_libsyscall_path -isystem $apple_xnu_source_libproc_path "
95 AC_ARG_WITH([apple-objc4-source],
96 [AS_HELP_STRING([--with-apple-objc4-source],
97 [Specify path to Apple objc4 source])], [
98 apple_objc4_source_runtime_path=${withval}/runtime
101 AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders,
102 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders],
103 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])]
105 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
106 [CPPFLAGS="$CPPFLAGS -isystem /System/Library/Frameworks/System.framework/PrivateHeaders"]
110 # On Mac OS X, libdispatch_init is automatically invoked during libSystem
111 # process initialization. On other systems, it is tagged as a library
112 # constructor to be run by automatically by the runtime linker.
114 AC_ARG_ENABLE([libdispatch-init-constructor],
115 [AS_HELP_STRING([--disable-libdispatch-init-constructor],
116 [Disable libdispatch_init as a constructor])],,
117 [AS_IF([test -f /usr/lib/system/libdispatch.dylib],
118 [enable_libdispatch_init_constructor=no])]
120 AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"],
121 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1,
122 [Define to tag libdispatch_init as a constructor])]
126 # On Mac OS X libdispatch can use the non-portable direct pthread TSD functions
128 AC_ARG_ENABLE([apple-tsd-optimizations],
129 [AS_HELP_STRING([--enable-apple-tsd-optimizations],
130 [Use non-portable pthread TSD optimizations for Mac OS X.])]
132 AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
133 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1,
134 [Define to use non-portable pthread TSD optimizations for Mac OS X)])]
140 # Enable building Swift overlay support into libdispatch
142 AC_ARG_WITH([swift-toolchain],
143 [AS_HELP_STRING([--with-swift-toolchain], [Specify path to Swift toolchain])],
144 [swift_toolchain_path=${withval}
145 AC_DEFINE(HAVE_SWIFT, 1, [Define if building for Swift])
146 SWIFTC="$swift_toolchain_path/bin/swiftc"
161 SWIFT_LIBDIR="$swift_toolchain_path/lib/swift/$os_string/$target_cpu"
165 AM_CONDITIONAL(HAVE_SWIFT, $have_swift)
167 AC_SUBST([SWIFT_LIBDIR])
170 # Enable use of gold linker when building the Swift overlay
171 # to avoid a symbol relocation issue.
172 # Ultimately the request to use gold should be passed in as an arg
174 AC_CHECK_PROG(use_gold_linker, ld.gold, true, false)
175 AM_CONDITIONAL(USE_GOLD_LINKER, $use_gold_linker)
178 # Enable __thread based TSD on platforms where it is efficient
179 # Allow override based on command line argument to configure
181 AC_ARG_ENABLE([thread-local-storage],
182 [AS_HELP_STRING([--enable-thread-local-storage],
183 [Enable usage of thread local storage via __thread])],,
186 enable_thread_local_storage=yes
189 enable_thread_local_storage=no
192 AS_IF([test "x$enable_thread_local_storage" = "xyes"],
193 [AC_DEFINE(DISPATCH_USE_THREAD_LOCAL_STORAGE, 1,
194 [Enable usage of thread local storage via __thread])]
197 AC_USE_SYSTEM_EXTENSIONS
198 AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects])
199 LT_INIT([disable-static])
202 AC_PATH_PROGS(MIG, mig)
203 AC_PATH_PROG(DTRACE, dtrace)
204 AS_IF([test "x$DTRACE" != "x"], [use_dtrace=true],[
206 CPPFLAGS="$CPPFLAGS -DDISPATCH_USE_DTRACE=0"
208 AM_CONDITIONAL(USE_DTRACE, $use_dtrace)
209 AC_PATH_PROG(LEAKS, leaks)
210 AS_IF([test "x$LEAKS" != "x"],
211 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])
215 AM_CONDITIONAL(HAVE_LEAKS, $have_leaks)
217 DISPATCH_C_ATOMIC_BUILTINS
219 case $dispatch_cv_atomic in
221 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
222 AC_SUBST([MARCH_FLAGS]) ;;
223 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
227 # Find libraries we will need
229 AC_SEARCH_LIBS(clock_gettime, rt)
230 AC_SEARCH_LIBS(pthread_create, pthread)
232 AS_IF([test -f $srcdir/libkqueue/configure.ac],
233 [AC_DEFINE(BUILD_OWN_KQUEUES, 1, [Define if building libkqueue from source])
234 ac_configure_args="--disable-libkqueue-install $ac_configure_args"
235 AC_CONFIG_SUBDIRS([libkqueue])
236 build_own_kqueues=true],
237 [build_own_kqueues=false
238 AC_CHECK_HEADER(sys/event.h, [],
239 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
243 AM_CONDITIONAL(BUILD_OWN_KQUEUES, $build_own_kqueues)
245 AC_CHECK_FUNCS([strlcpy getprogname], [],
246 [PKG_CHECK_MODULES(BSD_OVERLAY, libbsd-overlay,[
247 AC_DEFINE(HAVE_STRLCPY, 1, [])
248 AC_DEFINE(HAVE_GETPROGNAME, 1, [])
249 ])], [#include <string.h>]
253 # Checks for header files.
256 AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h sys/guarded.h fcntl.h])
258 # hack for pthread/private headers
259 AS_IF([test -n "$apple_libpthread_source_path" -a -n "$apple_xnu_source_osfmk_path"], [
260 saveCPPFLAGS="$CPPFLAGS"
261 CPPFLAGS="$CPPFLAGS -I."
262 ln -fsh "$apple_libpthread_source_path"/private/tsd_private.h pthread_machdep.h
263 ln -fsh "$apple_libpthread_source_path"/private pthread
264 ln -fsh "$apple_xnu_source_osfmk_path" System
265 mkdir -p mach && ln -fsh "$apple_xnu_source_osfmk_path"/mach/coalition.h mach
267 AC_CHECK_HEADERS([pthread_machdep.h pthread/qos.h])
269 # pthread_workqueues.
270 # Look for own version first, then system version.
271 AS_IF([test -f $srcdir/libpwq/configure.ac],
272 [AC_DEFINE(BUILD_OWN_PTHREAD_WORKQUEUES, 1, [Define if building pthread work queues from source])
273 ac_configure_args="--disable-libpwq-install $ac_configure_args"
274 AC_CONFIG_SUBDIRS([libpwq])
275 build_own_pthread_workqueues=true
276 AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])
277 have_pthread_workqueues=true],
278 [build_own_pthread_workqueues=false
279 AC_CHECK_HEADERS([pthread/workqueue_private.h pthread_workqueue.h],
280 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])
281 have_pthread_workqueues=true],
282 [have_pthread_workqueues=false]
285 AM_CONDITIONAL(BUILD_OWN_PTHREAD_WORKQUEUES, $build_own_pthread_workqueues)
286 AM_CONDITIONAL(HAVE_PTHREAD_WORKQUEUES, $have_pthread_workqueues)
288 AC_CHECK_HEADERS([libproc_internal.h], [], [], [#include <mach/mach.h>])
289 AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np _pthread_workqueue_init])
290 AS_IF([test -n "$apple_libpthread_source_path" -a -n "$apple_xnu_source_osfmk_path"], [
291 rm -f pthread_machdep.h pthread System mach/coalition.h
292 CPPFLAGS="$saveCPPFLAGS"
293 AC_CONFIG_COMMANDS([src/pthread_machdep.h],
294 [ln -fsh "$apple_libpthread_source_path"/private/tsd_private.h src/pthread_machdep.h],
295 [apple_libpthread_source_path="$apple_libpthread_source_path"])
296 AC_CONFIG_COMMANDS([src/pthread],
297 [ln -fsh "$apple_libpthread_source_path"/private src/pthread],
298 [apple_libpthread_source_path="$apple_libpthread_source_path"])
299 AC_CONFIG_COMMANDS([src/System],
300 [ln -fsh "$apple_xnu_source_osfmk_path" src/System],
301 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
302 AC_CONFIG_COMMANDS([src/mach/coalition.h],
303 [ln -fsh "$apple_xnu_source_osfmk_path"/mach/coalition.h src/mach],
304 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
306 # hack for xnu/bsd/sys/event.h EVFILT_SOCK declaration
307 AS_IF([test -n "$apple_xnu_source_bsd_path"], [
308 CPPFLAGS="$CPPFLAGS -DPRIVATE=1"
312 # Check for CoreFoundation, Foundation and objc
314 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
315 [have_corefoundation=true], [have_corefoundation=false]
317 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
319 AC_LANG_PUSH([Objective C])
320 AC_CHECK_HEADER([Foundation/Foundation.h],
321 [have_foundation=true], [have_foundation=false]
323 AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation)
324 # hack for objc4/runtime/objc-internal.h
325 AS_IF([test -n "$apple_objc4_source_runtime_path"], [
326 saveCPPFLAGS="$CPPFLAGS"
327 CPPFLAGS="$CPPFLAGS -I."
328 ln -fsh "$apple_objc4_source_runtime_path" objc
330 AC_CHECK_HEADER([objc/objc-internal.h], [
331 AC_DEFINE(HAVE_OBJC, 1, [Define if you have the Objective-C runtime])
332 have_objc=true], [have_objc=false],
333 [#include <objc/runtime.h>]
335 AS_IF([test -n "$apple_objc4_source_runtime_path"], [
337 CPPFLAGS="$saveCPPFLAGS"
338 AC_CONFIG_COMMANDS([src/objc],
339 [ln -fsh "$apple_objc4_source_runtime_path" src/objc],
340 [apple_objc4_source_runtime_path="$apple_objc4_source_runtime_path"])
342 AM_CONDITIONAL(USE_OBJC, $have_objc)
343 AC_LANG_POP([Objective C])
346 # We use the availability of mach.h to decide whether to compile in all sorts
347 # of Machisms, including using Mach ports as event sources, etc.
349 AC_CHECK_HEADER([mach/mach.h], [
350 AC_DEFINE(HAVE_MACH, 1, [Define if mach is present])
351 AC_DEFINE(__DARWIN_NON_CANCELABLE, 1, [Define if using Darwin $NOCANCEL])
352 have_mach=true], [have_mach=false]
354 AM_CONDITIONAL(USE_MIG, $have_mach)
355 AC_CHECK_FUNCS([mach_port_construct])
358 # Find functions and declarations we care about.
360 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC, CLOCK_REALTIME], [], [],
361 [[#include <time.h>]])
362 AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL, NOTE_LOWAT], [], [],
363 [[#include <sys/event.h>]])
364 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
365 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
366 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK, VQ_QUOTA, VQ_NEARLOWDISK, VQ_DESIRED_DISK], [], [], [[#include <sys/mount.h>]])
367 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
368 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf])
370 AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
371 [have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],
372 [[#include <sys/spawn.h>]]
374 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
376 AC_CHECK_FUNC([sem_init],
377 [have_sem_init=true], [have_sem_init=false]
381 # We support both Mach semaphores and POSIX semaphores; if the former are
382 # available, prefer them.
384 AC_MSG_CHECKING([what semaphore type to use]);
385 AS_IF([test "x$have_mach" = "xtrue"],
386 [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
387 AC_MSG_RESULT([Mach semaphores])],
388 [test "x$have_sem_init" = "xtrue"],
389 [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
390 AC_MSG_RESULT([POSIX semaphores])],
391 [AC_MSG_ERROR([no supported semaphore type])]
394 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
395 [#ifdef HAVE_SYS_CDEFS_H
396 #include <sys/cdefs.h>
401 AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [
403 CFLAGS="$CFLAGS -fvisibility=hidden"
404 AC_LINK_IFELSE([AC_LANG_PROGRAM([
405 extern __attribute__ ((visibility ("default"))) int foo; int foo;], [foo = 0;])],
406 [dispatch_cv_cc_visibility_hidden="yes"], [dispatch_cv_cc_visibility_hidden="no"])
409 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
410 VISIBILITY_FLAGS="-fvisibility=hidden"
412 AC_SUBST([VISIBILITY_FLAGS])
414 AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [
416 CFLAGS="$CFLAGS -momit-leaf-frame-pointer"
417 AC_LINK_IFELSE([AC_LANG_PROGRAM([
418 extern int foo(void); int foo(void) {return 1;}], [foo();])],
419 [dispatch_cv_cc_omit_leaf_fp="yes"], [dispatch_cv_cc_omit_leaf_fp="no"])
422 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
423 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
425 AC_SUBST([OMIT_LEAF_FP_FLAGS])
427 AS_IF([test "x$have_mach" = "xtrue"], [
428 AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
429 saveLDFLAGS="$LDFLAGS"
430 LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
431 AC_LINK_IFELSE([AC_LANG_PROGRAM([
432 extern int foo; int foo;], [foo = 0;])],
433 [dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
434 LDFLAGS="$saveLDFLAGS"
437 AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])
440 # symlink platform-specific module.modulemap files
442 AS_CASE([$target_os],
443 [darwin*], [ dispatch_module_map_os=darwin ],
444 [ dispatch_module_map_os=generic ]
446 AC_CONFIG_COMMANDS([modulemaps], [
447 ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/dispatch/module.modulemap
448 ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/private/module.modulemap
450 [dispatch_module_map_os="$dispatch_module_map_os"]
454 # Temporary: some versions of clang do not mark __builtin_trap() as
455 # __attribute__((__noreturn__)). Detect and add if required.
458 [AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])],
459 [AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1, [Define if __builtin_trap marked noreturn])]
463 # Generate Makefiles.
465 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile tests/Makefile])
468 # Generate testsuite links
470 AC_CONFIG_LINKS([tests/dispatch:$ac_top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])