]> git.saurik.com Git - apple/libdispatch.git/blob - configure.ac
libdispatch-501.40.12.tar.gz
[apple/libdispatch.git] / configure.ac
1 #
2 # When this file changes, rerun autogen.sh.
3 #
4
5 AC_PREREQ(2.59)
6 AC_INIT([libdispatch], [1.2], [libdispatch@macosforge.org], [libdispatch])
7 AC_REVISION([$$])
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
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
18 #
19 # On Mac OS X, some required header files come from other source packages;
20 # allow specifying where those are.
21 #
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"
27 ])
28
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"
34 ])
35
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_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
45 AC_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
51 AC_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
58 AC_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 )
62 AS_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 #
71 AC_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 )
77 AS_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 #
85 AC_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 )
89 AS_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
94 AC_USE_SYSTEM_EXTENSIONS
95 AM_INIT_AUTOMAKE([foreign no-dependencies])
96 LT_INIT([disable-static])
97
98 AC_PROG_INSTALL
99 AC_PATH_PROGS(MIG, mig)
100 AC_PATH_PROG(LEAKS, leaks)
101 AS_IF([test "x$LEAKS" != "x"],
102 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])]
103 )
104
105 DISPATCH_C_ATOMIC_BUILTINS
106
107 case $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]) ;;
112 esac
113
114 #
115 # Find libraries we will need
116 #
117 AC_SEARCH_LIBS(clock_gettime, rt)
118 AC_SEARCH_LIBS(pthread_create, pthread)
119
120 #
121 # Prefer native kqueue(2); otherwise use libkqueue if present.
122 #
123 AC_CHECK_HEADER(sys/event.h, [],
124 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
125 )
126
127 #
128 # Checks for header files.
129 #
130 AC_HEADER_STDC
131 AC_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>
134 AS_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 ])
139 AC_CHECK_HEADERS([pthread_machdep.h])
140 AS_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
148 AS_IF([test -n "$apple_xnu_source_bsd_path"], [
149 CPPFLAGS="$CPPFLAGS -DPRIVATE=1"
150 ])
151
152 #
153 # Check for CoreFoundation, Foundation and objc
154 #
155 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
156 [have_corefoundation=true], [have_corefoundation=false]
157 )
158 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
159
160 AC_LANG_PUSH([Objective C])
161 AC_CHECK_HEADER([Foundation/Foundation.h],
162 [have_foundation=true], [have_foundation=false]
163 )
164 AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation)
165 # hack for objc4/runtime/objc-internal.h
166 AS_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 ])
171 AC_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 )
176 AS_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 ])
183 AM_CONDITIONAL(USE_OBJC, $have_objc)
184 AC_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 #
190 AC_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 )
195 AM_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 #
201 AC_CHECK_HEADER([pthread_workqueue.h],
202 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])]
203 )
204 AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np])
205
206 #
207 # Find functions and declarations we care about.
208 #
209 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
210 [[#include <time.h>]])
211 AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_SIGNAL], [], [],
212 [[#include <sys/event.h>]])
213 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
214 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
215 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK, VQ_QUOTA], [], [], [[#include <sys/mount.h>]])
216 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
217 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
218
219 AC_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 )
223 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
224
225 AC_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 #
233 AC_MSG_CHECKING([what semaphore type to use]);
234 AS_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
243 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
244 [#ifdef HAVE_SYS_CDEFS_H
245 #include <sys/cdefs.h>
246 #endif])
247
248 DISPATCH_C_BLOCKS
249
250 AC_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 ])
258 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
259 VISIBILITY_FLAGS="-fvisibility=hidden"
260 ])
261 AC_SUBST([VISIBILITY_FLAGS])
262
263 AC_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 ])
271 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
272 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
273 ])
274 AC_SUBST([OMIT_LEAF_FP_FLAGS])
275
276 AC_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 ])
284 AM_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 #
290 AC_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 #
298 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile])
299 AC_OUTPUT