]> git.saurik.com Git - apple/libdispatch.git/blob - configure.ac
libdispatch-703.1.4.tar.gz
[apple/libdispatch.git] / configure.ac
1 #
2 # When this file changes, rerun autogen.sh.
3 #
4
5 AC_PREREQ(2.69)
6 AC_INIT([libdispatch], [1.3], [libdispatch@macosforge.org], [libdispatch], [http://libdispatch.macosforge.org])
7 AC_REVISION([$$])
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
12 AM_MAINTAINER_MODE
13
14 AC_PROG_CC([clang gcc cc])
15 AC_PROG_CXX([clang++ g++ c++])
16 AC_PROG_OBJC([clang gcc cc])
17 AC_PROG_OBJCXX([clang++ g++ c++])
18
19 #
20 # On Mac OS X, some required header files come from other source packages;
21 # allow specifying where those are.
22 #
23 AC_ARG_WITH([apple-libpthread-source],
24 [AS_HELP_STRING([--with-apple-libpthread-source],
25 [Specify path to Apple libpthread source])], [
26 apple_libpthread_source_path=${withval}
27 CPPFLAGS="$CPPFLAGS -isystem $apple_libpthread_source_path"
28 ])
29
30 AC_ARG_WITH([apple-libplatform-source],
31 [AS_HELP_STRING([--with-apple-libplatform-source],
32 [Specify path to Apple libplatform source])], [
33 apple_libplatform_source_include_path=${withval}/include
34 CPPFLAGS="$CPPFLAGS -isystem $apple_libplatform_source_include_path"
35 ])
36
37 AC_ARG_WITH([apple-libclosure-source],
38 [AS_HELP_STRING([--with-apple-libclosure-source],
39 [Specify path to Apple libclosure source])], [
40 apple_libclosure_source_path=${withval}
41 CPPFLAGS="$CPPFLAGS -isystem $apple_libclosure_source_path"
42 ])
43
44 AC_ARG_WITH([apple-xnu-source],
45 [AS_HELP_STRING([--with-apple-xnu-source],
46 [Specify path to Apple XNU source])], [
47 apple_xnu_source_libsyscall_path=${withval}/libsyscall
48 apple_xnu_source_libproc_path=${withval}/libsyscall/wrappers/libproc
49 apple_xnu_source_libkern_path=${withval}/libkern
50 apple_xnu_source_bsd_path=${withval}/bsd
51 apple_xnu_source_osfmk_path=${withval}/osfmk
52 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 "
53 ])
54
55 AC_ARG_WITH([apple-objc4-source],
56 [AS_HELP_STRING([--with-apple-objc4-source],
57 [Specify path to Apple objc4 source])], [
58 apple_objc4_source_runtime_path=${withval}/runtime
59 ])
60
61 AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders,
62 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders],
63 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])]
64 )
65 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
66 [CPPFLAGS="$CPPFLAGS -isystem /System/Library/Frameworks/System.framework/PrivateHeaders"]
67 )
68
69 #
70 # On Mac OS X, libdispatch_init is automatically invoked during libSystem
71 # process initialization. On other systems, it is tagged as a library
72 # constructor to be run by automatically by the runtime linker.
73 #
74 AC_ARG_ENABLE([libdispatch-init-constructor],
75 [AS_HELP_STRING([--disable-libdispatch-init-constructor],
76 [Disable libdispatch_init as a constructor])],,
77 [AS_IF([test -f /usr/lib/system/libdispatch.dylib],
78 [enable_libdispatch_init_constructor=no])]
79 )
80 AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"],
81 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1,
82 [Define to tag libdispatch_init as a constructor])]
83 )
84
85 #
86 # On Mac OS X libdispatch can use the non-portable direct pthread TSD functions
87 #
88 AC_ARG_ENABLE([apple-tsd-optimizations],
89 [AS_HELP_STRING([--enable-apple-tsd-optimizations],
90 [Use non-portable pthread TSD optimizations for Mac OS X.])]
91 )
92 AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
93 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1,
94 [Define to use non-portable pthread TSD optimizations for Mac OS X)])]
95 )
96
97 AC_CANONICAL_TARGET
98
99 #
100 # Enable building Swift overlay support into libdispatch
101 #
102 AC_ARG_WITH([swift-toolchain],
103 [AS_HELP_STRING([--with-swift-toolchain], [Specify path to Swift toolchain])],
104 [swift_toolchain_path=${withval}
105 AC_DEFINE(HAVE_SWIFT, 1, [Define if building for Swift])
106 SWIFTC="$swift_toolchain_path/bin/swiftc"
107 case $target_os in
108 linux*)
109 os_string="linux"
110 ;;
111 *)
112 os_string=$target_os
113 ;;
114 esac
115 SWIFT_LIBDIR="$swift_toolchain_path/lib/swift/$os_string/$target_cpu"
116 have_swift=true],
117 [have_swift=false]
118 )
119 AM_CONDITIONAL(HAVE_SWIFT, $have_swift)
120 AC_SUBST([SWIFTC])
121 AC_SUBST([SWIFT_LIBDIR])
122
123 #
124 # Enable use of gold linker when building the Swift overlay
125 # to avoid a symbol relocation issue.
126 # Ultimately the request to use gold should be passed in as an arg
127 #
128 AC_CHECK_PROG(use_gold_linker, ld.gold, true, false)
129 AM_CONDITIONAL(USE_GOLD_LINKER, $use_gold_linker)
130
131 #
132 # Enable __thread based TSD on platforms where it is efficient
133 # Allow override based on command line argument to configure
134 #
135 AC_ARG_ENABLE([thread-local-storage],
136 [AS_HELP_STRING([--enable-thread-local-storage],
137 [Enable usage of thread local storage via __thread])],,
138 [case $target_os in
139 linux*)
140 enable_thread_local_storage=yes
141 ;;
142 *)
143 enable_thread_local_storage=no
144 esac]
145 )
146 AS_IF([test "x$enable_thread_local_storage" = "xyes"],
147 [AC_DEFINE(DISPATCH_USE_THREAD_LOCAL_STORAGE, 1,
148 [Enable usage of thread local storage via __thread])]
149 )
150
151 AC_USE_SYSTEM_EXTENSIONS
152 AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects])
153 LT_INIT([disable-static])
154
155 AC_PROG_INSTALL
156 AC_PATH_PROGS(MIG, mig)
157 AC_PATH_PROG(DTRACE, dtrace)
158 AS_IF([test "x$DTRACE" != "x"], [use_dtrace=true],[
159 use_dtrace=false
160 CPPFLAGS="$CPPFLAGS -DDISPATCH_USE_DTRACE=0"
161 ])
162 AM_CONDITIONAL(USE_DTRACE, $use_dtrace)
163 AC_PATH_PROG(LEAKS, leaks)
164 AS_IF([test "x$LEAKS" != "x"],
165 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])
166 have_leaks=true],
167 [have_leaks=false]
168 )
169 AM_CONDITIONAL(HAVE_LEAKS, $have_leaks)
170
171 DISPATCH_C_ATOMIC_BUILTINS
172
173 case $dispatch_cv_atomic in
174 yes) ;;
175 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
176 AC_SUBST([MARCH_FLAGS]) ;;
177 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
178 esac
179
180 #
181 # Find libraries we will need
182 #
183 AC_SEARCH_LIBS(clock_gettime, rt)
184 AC_SEARCH_LIBS(pthread_create, pthread)
185
186 #
187 # Prefer native kqueue(2); otherwise use libkqueue if present.
188 #
189 AC_CHECK_HEADER(sys/event.h, [],
190 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
191 )
192
193 AC_CHECK_FUNCS([strlcpy getprogname], [],
194 [PKG_CHECK_MODULES(BSD_OVERLAY, libbsd-overlay,[
195 AC_DEFINE(HAVE_STRLCPY, 1, [])
196 AC_DEFINE(HAVE_GETPROGNAME, 1, [])
197 ])], [#include <string.h>]
198 )
199
200 #
201 # Checks for header files.
202 #
203 AC_HEADER_STDC
204 AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h sys/guarded.h fcntl.h])
205
206 # hack for pthread/private headers
207 AS_IF([test -n "$apple_libpthread_source_path" -a -n "$apple_xnu_source_osfmk_path"], [
208 saveCPPFLAGS="$CPPFLAGS"
209 CPPFLAGS="$CPPFLAGS -I."
210 ln -fsh "$apple_libpthread_source_path"/private/tsd_private.h pthread_machdep.h
211 ln -fsh "$apple_libpthread_source_path"/private pthread
212 ln -fsh "$apple_xnu_source_osfmk_path" System
213 mkdir -p mach && ln -fsh "$apple_xnu_source_osfmk_path"/mach/coalition.h mach
214 ])
215 AC_CHECK_HEADERS([pthread_machdep.h pthread/qos.h])
216
217 # pthread_workqueues.
218 # Look for own version first, then system version.
219 AS_IF([test -f $srcdir/libpwq/configure.ac],
220 [AC_DEFINE(BUILD_OWN_PTHREAD_WORKQUEUES, 1, [Define if building pthread work queues from source])
221 ac_configure_args="--disable-libpwq-install $ac_configure_args"
222 AC_CONFIG_SUBDIRS([libpwq])
223 build_own_pthread_workqueues=true
224 AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])
225 have_pthread_workqueues=true],
226 [build_own_pthread_workqueues=false
227 AC_CHECK_HEADERS([pthread/workqueue_private.h pthread_workqueue.h],
228 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])
229 have_pthread_workqueues=true],
230 [have_pthread_workqueues=false]
231 )]
232 )
233 AM_CONDITIONAL(BUILD_OWN_PTHREAD_WORKQUEUES, $build_own_pthread_workqueues)
234 AM_CONDITIONAL(HAVE_PTHREAD_WORKQUEUES, $have_pthread_workqueues)
235
236 AC_CHECK_HEADERS([libproc_internal.h], [], [], [#include <mach/mach.h>])
237 AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np _pthread_workqueue_init])
238 AS_IF([test -n "$apple_libpthread_source_path" -a -n "$apple_xnu_source_osfmk_path"], [
239 rm -f pthread_machdep.h pthread System mach/coalition.h
240 CPPFLAGS="$saveCPPFLAGS"
241 AC_CONFIG_COMMANDS([src/pthread_machdep.h],
242 [ln -fsh "$apple_libpthread_source_path"/private/tsd_private.h src/pthread_machdep.h],
243 [apple_libpthread_source_path="$apple_libpthread_source_path"])
244 AC_CONFIG_COMMANDS([src/pthread],
245 [ln -fsh "$apple_libpthread_source_path"/private src/pthread],
246 [apple_libpthread_source_path="$apple_libpthread_source_path"])
247 AC_CONFIG_COMMANDS([src/System],
248 [ln -fsh "$apple_xnu_source_osfmk_path" src/System],
249 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
250 AC_CONFIG_COMMANDS([src/mach/coalition.h],
251 [ln -fsh "$apple_xnu_source_osfmk_path"/mach/coalition.h src/mach],
252 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
253 ])
254 # hack for xnu/bsd/sys/event.h EVFILT_SOCK declaration
255 AS_IF([test -n "$apple_xnu_source_bsd_path"], [
256 CPPFLAGS="$CPPFLAGS -DPRIVATE=1"
257 ])
258
259 #
260 # Check for CoreFoundation, Foundation and objc
261 #
262 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
263 [have_corefoundation=true], [have_corefoundation=false]
264 )
265 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
266
267 AC_LANG_PUSH([Objective C])
268 AC_CHECK_HEADER([Foundation/Foundation.h],
269 [have_foundation=true], [have_foundation=false]
270 )
271 AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation)
272 # hack for objc4/runtime/objc-internal.h
273 AS_IF([test -n "$apple_objc4_source_runtime_path"], [
274 saveCPPFLAGS="$CPPFLAGS"
275 CPPFLAGS="$CPPFLAGS -I."
276 ln -fsh "$apple_objc4_source_runtime_path" objc
277 ])
278 AC_CHECK_HEADER([objc/objc-internal.h], [
279 AC_DEFINE(HAVE_OBJC, 1, [Define if you have the Objective-C runtime])
280 have_objc=true], [have_objc=false],
281 [#include <objc/runtime.h>]
282 )
283 AS_IF([test -n "$apple_objc4_source_runtime_path"], [
284 rm -f objc
285 CPPFLAGS="$saveCPPFLAGS"
286 AC_CONFIG_COMMANDS([src/objc],
287 [ln -fsh "$apple_objc4_source_runtime_path" src/objc],
288 [apple_objc4_source_runtime_path="$apple_objc4_source_runtime_path"])
289 ])
290 AM_CONDITIONAL(USE_OBJC, $have_objc)
291 AC_LANG_POP([Objective C])
292
293 #
294 # We use the availability of mach.h to decide whether to compile in all sorts
295 # of Machisms, including using Mach ports as event sources, etc.
296 #
297 AC_CHECK_HEADER([mach/mach.h], [
298 AC_DEFINE(HAVE_MACH, 1, [Define if mach is present])
299 AC_DEFINE(__DARWIN_NON_CANCELABLE, 1, [Define if using Darwin $NOCANCEL])
300 have_mach=true], [have_mach=false]
301 )
302 AM_CONDITIONAL(USE_MIG, $have_mach)
303 AC_CHECK_FUNCS([mach_port_construct])
304
305 #
306 # Find functions and declarations we care about.
307 #
308 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
309 [[#include <time.h>]])
310 AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL, NOTE_LOWAT], [], [],
311 [[#include <sys/event.h>]])
312 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
313 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
314 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK, VQ_QUOTA], [], [], [[#include <sys/mount.h>]])
315 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
316 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf])
317
318 AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
319 [have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],
320 [[#include <sys/spawn.h>]]
321 )
322 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
323
324 AC_CHECK_FUNC([sem_init],
325 [have_sem_init=true], [have_sem_init=false]
326 )
327
328 #
329 # We support both Mach semaphores and POSIX semaphores; if the former are
330 # available, prefer them.
331 #
332 AC_MSG_CHECKING([what semaphore type to use]);
333 AS_IF([test "x$have_mach" = "xtrue"],
334 [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
335 AC_MSG_RESULT([Mach semaphores])],
336 [test "x$have_sem_init" = "xtrue"],
337 [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
338 AC_MSG_RESULT([POSIX semaphores])],
339 [AC_MSG_ERROR([no supported semaphore type])]
340 )
341
342 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
343 [#ifdef HAVE_SYS_CDEFS_H
344 #include <sys/cdefs.h>
345 #endif])
346
347 DISPATCH_C_BLOCKS
348
349 AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [
350 saveCFLAGS="$CFLAGS"
351 CFLAGS="$CFLAGS -fvisibility=hidden"
352 AC_LINK_IFELSE([AC_LANG_PROGRAM([
353 extern __attribute__ ((visibility ("default"))) int foo; int foo;], [foo = 0;])],
354 [dispatch_cv_cc_visibility_hidden="yes"], [dispatch_cv_cc_visibility_hidden="no"])
355 CFLAGS="$saveCFLAGS"
356 ])
357 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
358 VISIBILITY_FLAGS="-fvisibility=hidden"
359 ])
360 AC_SUBST([VISIBILITY_FLAGS])
361
362 AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [
363 saveCFLAGS="$CFLAGS"
364 CFLAGS="$CFLAGS -momit-leaf-frame-pointer"
365 AC_LINK_IFELSE([AC_LANG_PROGRAM([
366 extern int foo(void); int foo(void) {return 1;}], [foo();])],
367 [dispatch_cv_cc_omit_leaf_fp="yes"], [dispatch_cv_cc_omit_leaf_fp="no"])
368 CFLAGS="$saveCFLAGS"
369 ])
370 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
371 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
372 ])
373 AC_SUBST([OMIT_LEAF_FP_FLAGS])
374
375 AS_IF([test "x$have_mach" = "xtrue"], [
376 AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
377 saveLDFLAGS="$LDFLAGS"
378 LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
379 AC_LINK_IFELSE([AC_LANG_PROGRAM([
380 extern int foo; int foo;], [foo = 0;])],
381 [dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
382 LDFLAGS="$saveLDFLAGS"
383 ])
384 ])
385 AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])
386
387 #
388 # Temporary: some versions of clang do not mark __builtin_trap() as
389 # __attribute__((__noreturn__)). Detect and add if required.
390 #
391 AC_COMPILE_IFELSE(
392 [AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])],
393 [AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1, [Define if __builtin_trap marked noreturn])]
394 )
395
396 #
397 # Generate Makefiles.
398 #
399 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile tests/Makefile])
400
401 #
402 # Generate testsuite links
403 #
404 AC_CONFIG_LINKS([tests/dispatch:$top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])
405
406 AC_OUTPUT