1# 2# When this file changes, rerun autogen.sh. 3# 4 5AC_PREREQ(2.59) 6AC_INIT([libdispatch], [1.2], [libdispatch@macosforge.org], [libdispatch]) 7AC_REVISION([$$]) 8AC_CONFIG_AUX_DIR(config) 9AC_CONFIG_HEADER([config/config.h]) 10AC_CONFIG_MACRO_DIR([m4]) 11ac_clean_files=a.out.dSYM 12AM_MAINTAINER_MODE 13 14AC_PROG_CC([clang gcc cc]) 15AC_PROG_CXX([clang++ g++ c++]) 16AC_PROG_OBJC([clang gcc cc]) 17 18# 19# On Mac OS X, some required header files come from other source packages; 20# allow specifying where those are. 21# 22AC_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" 27]) 28 29AC_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" 34]) 35 36AC_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_bsd_path=${withval}/bsd 41 apple_xnu_source_osfmk_path=${withval}/osfmk 42 CPPFLAGS="$CPPFLAGS -idirafter $apple_xnu_source_libkern_path -isystem $apple_xnu_source_bsd_path" 43]) 44 45AC_ARG_WITH([apple-objc4-source], 46 [AS_HELP_STRING([--with-apple-objc4-source], 47 [Specify path to Apple objc4 source])], [ 48 apple_objc4_source_runtime_path=${withval}/runtime 49]) 50 51AC_ARG_WITH([apple-libauto-source], 52 [AS_HELP_STRING([--with-apple-libauto-source], 53 [Specify path to Apple libauto source])], [ 54 apple_libauto_source_path=${withval} 55 CPPFLAGS="$CPPFLAGS -I$apple_libauto_source_path" 56]) 57 58AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders, 59 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders], 60 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])] 61) 62AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"], 63 [CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/System.framework/PrivateHeaders"] 64) 65 66# 67# On Mac OS X, libdispatch_init is automatically invoked during libSystem 68# process initialization. On other systems, it is tagged as a library 69# constructor to be run by automatically by the runtime linker. 70# 71AC_ARG_ENABLE([libdispatch-init-constructor], 72 [AS_HELP_STRING([--disable-libdispatch-init-constructor], 73 [Disable libdispatch_init as a constructor])],, 74 [AS_IF([test -f /usr/lib/system/libdispatch.dylib], 75 [enable_libdispatch_init_constructor=no])] 76) 77AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"], 78 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1, 79 [Define to tag libdispatch_init as a constructor])] 80) 81 82# 83# On Mac OS X libdispatch can use the non-portable direct pthread TSD functions 84# 85AC_ARG_ENABLE([apple-tsd-optimizations], 86 [AS_HELP_STRING([--enable-apple-tsd-optimizations], 87 [Use non-portable pthread TSD optimizations for Mac OS X.])] 88) 89AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"], 90 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1, 91 [Define to use non-portable pthread TSD optimizations for Mac OS X)])] 92) 93 94AC_USE_SYSTEM_EXTENSIONS 95AM_INIT_AUTOMAKE([foreign no-dependencies]) 96LT_INIT([disable-static]) 97 98AC_PROG_INSTALL 99AC_PATH_PROGS(MIG, mig) 100AC_PATH_PROG(LEAKS, leaks) 101AS_IF([test "x$LEAKS" != "x"], 102 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])] 103) 104 105DISPATCH_C_ATOMIC_BUILTINS 106 107case $dispatch_cv_atomic in 108 yes) ;; 109 -march*) MARCH_FLAGS="$dispatch_cv_atomic" 110 AC_SUBST([MARCH_FLAGS]) ;; 111 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;; 112esac 113 114# 115# Find libraries we will need 116# 117AC_SEARCH_LIBS(clock_gettime, rt) 118AC_SEARCH_LIBS(pthread_create, pthread) 119 120# 121# Prefer native kqueue(2); otherwise use libkqueue if present. 122# 123AC_CHECK_HEADER(sys/event.h, [], 124 [PKG_CHECK_MODULES(KQUEUE, libkqueue)] 125) 126 127# 128# Checks for header files. 129# 130AC_HEADER_STDC 131AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h sys/guarded.h libproc_internal.h]) 132 133# hack for pthread_machdep.h's #include <System/machine/cpu_capabilities.h> 134AS_IF([test -n "$apple_xnu_source_osfmk_path"], [ 135 saveCPPFLAGS="$CPPFLAGS" 136 CPPFLAGS="$CPPFLAGS -I." 137 ln -fsh "$apple_xnu_source_osfmk_path" System 138]) 139AC_CHECK_HEADERS([pthread_machdep.h]) 140AS_IF([test -n "$apple_xnu_source_osfmk_path"], [ 141 rm -f System 142 CPPFLAGS="$saveCPPFLAGS" 143 AC_CONFIG_COMMANDS([src/System], 144 [ln -fsh "$apple_xnu_source_osfmk_path" src/System], 145 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"]) 146]) 147# hack for xnu/bsd/sys/event.h EVFILT_SOCK declaration 148AS_IF([test -n "$apple_xnu_source_bsd_path"], [ 149 CPPFLAGS="$CPPFLAGS -DPRIVATE=1" 150]) 151 152# 153# Check for CoreFoundation, Foundation and objc 154# 155AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h], 156 [have_corefoundation=true], [have_corefoundation=false] 157) 158AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation) 159 160AC_LANG_PUSH([Objective C]) 161AC_CHECK_HEADER([Foundation/Foundation.h], 162 [have_foundation=true], [have_foundation=false] 163) 164AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation) 165# hack for objc4/runtime/objc-internal.h 166AS_IF([test -n "$apple_objc4_source_runtime_path"], [ 167 saveCPPFLAGS="$CPPFLAGS" 168 CPPFLAGS="$CPPFLAGS -I." 169 ln -fsh "$apple_objc4_source_runtime_path" objc 170]) 171AC_CHECK_HEADER([objc/objc-internal.h], [ 172 AC_DEFINE(HAVE_OBJC, 1, [Define if you have the Objective-C runtime]) 173 have_objc=true], [have_objc=false], 174 [#include <objc/runtime.h>] 175) 176AS_IF([test -n "$apple_objc4_source_runtime_path"], [ 177 rm -f objc 178 CPPFLAGS="$saveCPPFLAGS" 179 AC_CONFIG_COMMANDS([src/objc], 180 [ln -fsh "$apple_objc4_source_runtime_path" src/objc], 181 [apple_objc4_source_runtime_path="$apple_objc4_source_runtime_path"]) 182]) 183AM_CONDITIONAL(USE_OBJC, $have_objc) 184AC_LANG_POP([Objective C]) 185 186# 187# We use the availability of mach.h to decide whether to compile in all sorts 188# of Machisms, including using Mach ports as event sources, etc. 189# 190AC_CHECK_HEADER([mach/mach.h], [ 191 AC_DEFINE(HAVE_MACH, 1, [Define if mach is present]) 192 AC_DEFINE(__DARWIN_NON_CANCELABLE, 1, [Define if using Darwin $NOCANCEL]) 193 have_mach=true], [have_mach=false] 194) 195AM_CONDITIONAL(USE_MIG, $have_mach) 196 197# 198# We use the availability of pthread_workqueue.h to decide whether to compile 199# in support for pthread work queues. 200# 201AC_CHECK_HEADER([pthread_workqueue.h], 202 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])] 203) 204AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np]) 205 206# 207# Find functions and declarations we care about. 208# 209AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [], 210 [[#include <time.h>]]) 211AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_SIGNAL], [], [], 212 [[#include <sys/event.h>]]) 213AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]]) 214AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]]) 215AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]]) 216AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]]) 217AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname]) 218 219AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED], 220 [have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false], 221 [[#include <sys/spawn.h>]] 222) 223AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended) 224 225AC_CHECK_FUNC([sem_init], 226 [have_sem_init=true], [have_sem_init=false] 227) 228 229# 230# We support both Mach semaphores and POSIX semaphores; if the former are 231# available, prefer them. 232# 233AC_MSG_CHECKING([what semaphore type to use]); 234AS_IF([test "x$have_mach" = "xtrue"], 235 [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores]) 236 AC_MSG_RESULT([Mach semaphores])], 237 [test "x$have_sem_init" = "xtrue"], 238 [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores]) 239 AC_MSG_RESULT([POSIX semaphores])], 240 [AC_MSG_ERROR([no supported semaphore type])] 241) 242 243AC_CHECK_HEADERS([sys/cdefs.h], [], [], 244 [#ifdef HAVE_SYS_CDEFS_H 245 #include <sys/cdefs.h> 246 #endif]) 247 248DISPATCH_C_BLOCKS 249 250AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [ 251 saveCFLAGS="$CFLAGS" 252 CFLAGS="$CFLAGS -fvisibility=hidden" 253 AC_LINK_IFELSE([AC_LANG_PROGRAM([ 254 extern __attribute__ ((visibility ("default"))) int foo; int foo;], [foo = 0;])], 255 [dispatch_cv_cc_visibility_hidden="yes"], [dispatch_cv_cc_visibility_hidden="no"]) 256 CFLAGS="$saveCFLAGS" 257]) 258AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [ 259 VISIBILITY_FLAGS="-fvisibility=hidden" 260]) 261AC_SUBST([VISIBILITY_FLAGS]) 262 263AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [ 264 saveCFLAGS="$CFLAGS" 265 CFLAGS="$CFLAGS -momit-leaf-frame-pointer" 266 AC_LINK_IFELSE([AC_LANG_PROGRAM([ 267 extern int foo(void); int foo(void) {return 1;}], [foo();])], 268 [dispatch_cv_cc_omit_leaf_fp="yes"], [dispatch_cv_cc_omit_leaf_fp="no"]) 269 CFLAGS="$saveCFLAGS" 270]) 271AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [ 272 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer" 273]) 274AC_SUBST([OMIT_LEAF_FP_FLAGS]) 275 276AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [ 277 saveLDFLAGS="$LDFLAGS" 278 LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip" 279 AC_LINK_IFELSE([AC_LANG_PROGRAM([ 280 extern int foo; int foo;], [foo = 0;])], 281 [dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"]) 282 LDFLAGS="$saveLDFLAGS" 283]) 284AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"]) 285 286# 287# Temporary: some versions of clang do not mark __builtin_trap() as 288# __attribute__((__noreturn__)). Detect and add if required. 289# 290AC_COMPILE_IFELSE( 291 [AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])], 292 [AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1, [Define if __builtin_trap marked noreturn])] 293) 294 295# 296# Generate Makefiles. 297# 298AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile]) 299AC_OUTPUT 300