]> git.saurik.com Git - apple/libdispatch.git/blob - configure.ac
libdispatch-228.18.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.1], [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_osfmk_path=${withval}/osfmk
41 CPPFLAGS="$CPPFLAGS -I$apple_xnu_source_libkern_path"
42 ])
43
44 AC_CACHE_CHECK([for System.framework/PrivateHeaders], dispatch_cv_system_privateheaders,
45 [AS_IF([test -d /System/Library/Frameworks/System.framework/PrivateHeaders],
46 [dispatch_cv_system_privateheaders=yes], [dispatch_cv_system_privateheaders=no])]
47 )
48 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
49 [CPPFLAGS="$CPPFLAGS -I/System/Library/Frameworks/System.framework/PrivateHeaders"]
50 )
51
52 #
53 # On Mac OS X, libdispatch_init is automatically invoked during libSystem
54 # process initialization. On other systems, it is tagged as a library
55 # constructor to be run by automatically by the runtime linker.
56 #
57 AC_ARG_ENABLE([libdispatch-init-constructor],
58 [AS_HELP_STRING([--disable-libdispatch-init-constructor],
59 [Disable libdispatch_init as a constructor])],,
60 [AS_IF([test -f /usr/lib/system/libdispatch.dylib],
61 [enable_libdispatch_init_constructor=no])]
62 )
63 AS_IF([test "x$enable_libdispatch_init_constructor" != "xno"],
64 [AC_DEFINE(USE_LIBDISPATCH_INIT_CONSTRUCTOR, 1,
65 [Define to tag libdispatch_init as a constructor])]
66 )
67
68 #
69 # On Mac OS X libdispatch can use the non-portable direct pthread TSD functions
70 #
71 AC_ARG_ENABLE([apple-tsd-optimizations],
72 [AS_HELP_STRING([--enable-apple-tsd-optimizations],
73 [Use non-portable pthread TSD optimizations for Mac OS X.])]
74 )
75 AS_IF([test "x$enable_apple_tsd_optimizations" = "xyes"],
76 [AC_DEFINE(USE_APPLE_TSD_OPTIMIZATIONS, 1,
77 [Define to use non-portable pthread TSD optimizations for Mac OS X)])]
78 )
79
80 AC_USE_SYSTEM_EXTENSIONS
81 AC_PROG_INSTALL
82 AC_PROG_LIBTOOL
83 AC_PATH_PROGS(MIG, mig)
84
85 AC_PATH_PROG(LEAKS, leaks)
86 AS_IF([test "x$LEAKS" != "x"],
87 [AC_DEFINE(HAVE_LEAKS, 1, [Define if Apple leaks program is present])]
88 )
89
90 AM_INIT_AUTOMAKE([foreign])
91
92 DISPATCH_C_ATOMIC_BUILTINS
93
94 case $dispatch_cv_atomic in
95 yes) ;;
96 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
97 AC_SUBST([MARCH_FLAGS]) ;;
98 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
99 esac
100
101 #
102 # Find libraries we will need
103 #
104 AC_SEARCH_LIBS(clock_gettime, rt)
105 AC_SEARCH_LIBS(pthread_create, pthread)
106
107 #
108 # Prefer native kqueue(2); otherwise use libkqueue if present.
109 #
110 AC_CHECK_HEADER(sys/event.h, [],
111 [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
112 )
113
114 #
115 # Checks for header files.
116 #
117 AC_HEADER_STDC
118 AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h])
119
120 # hack for pthread_machdep.h's #include <System/machine/cpu_capabilities.h>
121 AS_IF([test -n "$apple_xnu_source_osfmk_path"], [
122 saveCPPFLAGS="$CPPFLAGS"
123 CPPFLAGS="$CPPFLAGS -I."
124 ln -fsh "$apple_xnu_source_osfmk_path" System
125 ])
126 AC_CHECK_HEADERS([pthread_machdep.h])
127 AS_IF([test -n "$apple_xnu_source_osfmk_path"], [
128 rm -f System
129 CPPFLAGS="$saveCPPFLAGS"
130 AC_CONFIG_COMMANDS([src/System],
131 [ln -fsh "$apple_xnu_source_osfmk_path" src/System],
132 [apple_xnu_source_osfmk_path="$apple_xnu_source_osfmk_path"])
133 ])
134
135 #
136 # Parts of the testsuite use CoreFoundation and Foundation
137 #
138 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
139 [have_corefoundation=true], [have_corefoundation=false]
140 )
141 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
142 AC_LANG_PUSH([Objective C])
143 AC_CHECK_HEADER([Foundation/Foundation.h], [
144 AC_DEFINE(USE_OBJC, 1, [Define to use Objective-C runtime])
145 have_foundation=true], [have_foundation=false]
146 )
147 AM_CONDITIONAL(HAVE_FOUNDATION, $have_foundation)
148 AC_LANG_POP([Objective C])
149
150 #
151 # We use the availability of mach.h to decide whether to compile in all sorts
152 # of Machisms, including using Mach ports as event sources, etc.
153 #
154 AC_CHECK_HEADER([mach/mach.h], [
155 AC_DEFINE(HAVE_MACH, 1, [Define if mach is present])
156 AC_DEFINE(__DARWIN_NON_CANCELABLE, 1, [Define if using Darwin $NOCANCEL])
157 have_mach=true], [have_mach=false]
158 )
159 AM_CONDITIONAL(USE_MIG, $have_mach)
160
161 #
162 # We use the availability of pthread_workqueue.h to decide whether to compile
163 # in support for pthread work queues.
164 #
165 AC_CHECK_HEADER([pthread_workqueue.h],
166 [AC_DEFINE(HAVE_PTHREAD_WORKQUEUES, 1, [Define if pthread work queues are present])]
167 )
168 AC_CHECK_FUNCS([pthread_workqueue_setdispatch_np])
169
170 #
171 # Find functions and declarations we care about.
172 #
173 AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
174 [[#include <time.h>]])
175 AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_SIGNAL], [], [],
176 [[#include <sys/event.h>]])
177 AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
178 AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
179 AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]])
180 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
181 AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
182
183 AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
184 [have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],
185 [[#include <sys/spawn.h>]]
186 )
187 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
188
189 AC_CHECK_FUNC([sem_init],
190 [have_sem_init=true], [have_sem_init=false]
191 )
192
193 #
194 # We support both Mach semaphores and POSIX semaphores; if the former are
195 # available, prefer them.
196 #
197 AC_MSG_CHECKING([what semaphore type to use]);
198 AS_IF([test "x$have_mach" = "xtrue"],
199 [AC_DEFINE(USE_MACH_SEM, 1, [Define to use Mach semaphores])
200 AC_MSG_RESULT([Mach semaphores])],
201 [test "x$have_sem_init" = "xtrue"],
202 [AC_DEFINE(USE_POSIX_SEM, 1, [Define to use POSIX semaphores])
203 AC_MSG_RESULT([POSIX semaphores])],
204 [AC_MSG_ERROR([no supported semaphore type])]
205 )
206
207 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
208 [#ifdef HAVE_SYS_CDEFS_H
209 #include <sys/cdefs.h>
210 #endif])
211
212 DISPATCH_C_BLOCKS
213
214 AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [
215 saveCFLAGS="$CFLAGS"
216 CFLAGS="$CFLAGS -fvisibility=hidden"
217 AC_LINK_IFELSE([AC_LANG_PROGRAM([
218 extern __attribute__ ((visibility ("default"))) int foo; int foo;], [foo = 0;])],
219 [dispatch_cv_cc_visibility_hidden="yes"], [dispatch_cv_cc_visibility_hidden="no"])
220 CFLAGS="$saveCFLAGS"
221 ])
222 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
223 VISIBILITY_FLAGS="-fvisibility=hidden"
224 ])
225 AC_SUBST([VISIBILITY_FLAGS])
226
227 AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [
228 saveCFLAGS="$CFLAGS"
229 CFLAGS="$CFLAGS -momit-leaf-frame-pointer"
230 AC_LINK_IFELSE([AC_LANG_PROGRAM([
231 extern int foo(void); int foo(void) {return 1;}], [foo();])],
232 [dispatch_cv_cc_omit_leaf_fp="yes"], [dispatch_cv_cc_omit_leaf_fp="no"])
233 CFLAGS="$saveCFLAGS"
234 ])
235 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
236 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
237 ])
238 AC_SUBST([OMIT_LEAF_FP_FLAGS])
239
240 AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
241 saveLDFLAGS="$LDFLAGS"
242 LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6"
243 AC_LINK_IFELSE([AC_LANG_PROGRAM([
244 extern int foo; int foo;], [foo = 0;])],
245 [dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
246 LDFLAGS="$saveLDFLAGS"
247 ])
248 AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"])
249
250 #
251 # Temporary: some versions of clang do not mark __builtin_trap() as
252 # __attribute__((__noreturn__)). Detect and add if required.
253 #
254 AC_COMPILE_IFELSE(
255 [AC_LANG_PROGRAM([void __attribute__((__noreturn__)) temp(void) { __builtin_trap(); }], [])],
256 [AC_DEFINE(HAVE_NORETURN_BUILTIN_TRAP, 1, [Define if __builtin_trap marked noreturn])]
257 )
258
259 #
260 # Generate Makefiles.
261 #
262 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile private/Makefile src/Makefile])
263 AC_OUTPUT