]> git.saurik.com Git - apple/libdispatch.git/blob - configure.ac
libdispatch-703.50.37.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], [https://bugs.swift.org], [libdispatch], [https://github.com/apple/swift-corelibs-libdispatch])
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 #
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
17 #
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]
22 )
23 AS_CASE([$dispatch_build_variant],
24 [debug], [
25 default_compiler_flags="-g -O0"
26 dispatch_enable_asserts=true
27 dispatch_enable_optimization=false
28 ],
29 [release], [
30 default_compiler_flags="-O2"
31 dispatch_enable_asserts=false
32 dispatch_enable_optimization=true
33 ],
34 [releaseassert], [
35 default_compiler_flags="-O2"
36 dispatch_enable_asserts=true
37 dispatch_enable_optimization=true
38 ],
39 [releasedebuginfo], [
40 default_compiler_flags="-g -O2"
41 dispatch_enable_asserts=false
42 dispatch_enable_optimization=true
43 ],
44 [AC_MSG_ERROR("invalid build-variant $dispatch_build_variant")]
45 )
46 AM_CONDITIONAL(DISPATCH_ENABLE_ASSERTS, $dispatch_enable_asserts)
47 AM_CONDITIONAL(DISPATCH_ENABLE_OPTIMIZATION, $dispatch_enable_optimization)
48
49 : ${CFLAGS=$default_compiler_flags}
50 : ${CXXFLAGS=$default_compiler_flags}
51 : ${OBJCFLAGS=$default_compiler_flags}
52 : ${OBJCXXFLAGS=$default_compiler_flags}
53
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++])
58
59 #
60 # On Mac OS X, some required header files come from other source packages;
61 # allow specifying where those are.
62 #
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"
68 ])
69
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"
75 ])
76
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"
82 ])
83
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 "
93 ])
94
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
99 ])
100
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])]
104 )
105 AS_IF([test "x$dispatch_cv_system_privateheaders" != "xno"],
106 [CPPFLAGS="$CPPFLAGS -isystem /System/Library/Frameworks/System.framework/PrivateHeaders"]
107 )
108
109 #
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.
113 #
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])]
119 )
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])]
123 )
124
125 #
126 # On Mac OS X libdispatch can use the non-portable direct pthread TSD functions
127 #
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.])]
131 )
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)])]
135 )
136
137 AC_CANONICAL_TARGET
138
139 #
140 # Enable building Swift overlay support into libdispatch
141 #
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"
147 case $target_os in
148 linux*)
149 os_string="linux"
150 case $target_cpu in
151 armv7l*)
152 target_cpu="armv7"
153 ;;
154 *)
155 esac
156 ;;
157 *)
158 os_string=$target_os
159 ;;
160 esac
161 SWIFT_LIBDIR="$swift_toolchain_path/lib/swift/$os_string/$target_cpu"
162 have_swift=true],
163 [have_swift=false]
164 )
165 AM_CONDITIONAL(HAVE_SWIFT, $have_swift)
166 AC_SUBST([SWIFTC])
167 AC_SUBST([SWIFT_LIBDIR])
168
169 #
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
173 #
174 AC_CHECK_PROG(use_gold_linker, ld.gold, true, false)
175 AM_CONDITIONAL(USE_GOLD_LINKER, $use_gold_linker)
176
177 #
178 # Enable __thread based TSD on platforms where it is efficient
179 # Allow override based on command line argument to configure
180 #
181 AC_ARG_ENABLE([thread-local-storage],
182 [AS_HELP_STRING([--enable-thread-local-storage],
183 [Enable usage of thread local storage via __thread])],,
184 [case $target_os in
185 linux*)
186 enable_thread_local_storage=yes
187 ;;
188 *)
189 enable_thread_local_storage=no
190 esac]
191 )
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])]
195 )
196
197 AC_USE_SYSTEM_EXTENSIONS
198 AM_INIT_AUTOMAKE([foreign no-dependencies subdir-objects])
199 LT_INIT([disable-static])
200
201 AC_PROG_INSTALL
202 AC_PATH_PROGS(MIG, mig)
203 AC_PATH_PROG(DTRACE, dtrace)
204 AS_IF([test "x$DTRACE" != "x"], [use_dtrace=true],[
205 use_dtrace=false
206 CPPFLAGS="$CPPFLAGS -DDISPATCH_USE_DTRACE=0"
207 ])
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])
212 have_leaks=true],
213 [have_leaks=false]
214 )
215 AM_CONDITIONAL(HAVE_LEAKS, $have_leaks)
216
217 DISPATCH_C_ATOMIC_BUILTINS
218
219 case $dispatch_cv_atomic in
220 yes) ;;
221 -march*) MARCH_FLAGS="$dispatch_cv_atomic"
222 AC_SUBST([MARCH_FLAGS]) ;;
223 *) AC_MSG_ERROR([No gcc builtin atomic operations available]) ;;
224 esac
225
226 #
227 # Find libraries we will need
228 #
229 AC_SEARCH_LIBS(clock_gettime, rt)
230 AC_SEARCH_LIBS(pthread_create, pthread)
231
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)]
240 )
241 ]
242 )
243 AM_CONDITIONAL(BUILD_OWN_KQUEUES, $build_own_kqueues)
244
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>]
250 )
251
252 #
253 # Checks for header files.
254 #
255 AC_HEADER_STDC
256 AC_CHECK_HEADERS([TargetConditionals.h pthread_np.h malloc/malloc.h libkern/OSCrossEndian.h libkern/OSAtomic.h sys/guarded.h fcntl.h])
257
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
266 ])
267 AC_CHECK_HEADERS([pthread_machdep.h pthread/qos.h])
268
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]
283 )]
284 )
285 AM_CONDITIONAL(BUILD_OWN_PTHREAD_WORKQUEUES, $build_own_pthread_workqueues)
286 AM_CONDITIONAL(HAVE_PTHREAD_WORKQUEUES, $have_pthread_workqueues)
287
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"])
305 ])
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"
309 ])
310
311 #
312 # Check for CoreFoundation, Foundation and objc
313 #
314 AC_CHECK_HEADER([CoreFoundation/CoreFoundation.h],
315 [have_corefoundation=true], [have_corefoundation=false]
316 )
317 AM_CONDITIONAL(HAVE_COREFOUNDATION, $have_corefoundation)
318
319 AC_LANG_PUSH([Objective C])
320 AC_CHECK_HEADER([Foundation/Foundation.h],
321 [have_foundation=true], [have_foundation=false]
322 )
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
329 ])
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>]
334 )
335 AS_IF([test -n "$apple_objc4_source_runtime_path"], [
336 rm -f objc
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"])
341 ])
342 AM_CONDITIONAL(USE_OBJC, $have_objc)
343 AC_LANG_POP([Objective C])
344
345 #
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.
348 #
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]
353 )
354 AM_CONDITIONAL(USE_MIG, $have_mach)
355 AC_CHECK_FUNCS([mach_port_construct])
356
357 #
358 # Find functions and declarations we care about.
359 #
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])
369
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>]]
373 )
374 AM_CONDITIONAL(HAVE_POSIX_SPAWN_START_SUSPENDED, $have_posix_spawn_start_suspended)
375
376 AC_CHECK_FUNC([sem_init],
377 [have_sem_init=true], [have_sem_init=false]
378 )
379
380 #
381 # We support both Mach semaphores and POSIX semaphores; if the former are
382 # available, prefer them.
383 #
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])]
392 )
393
394 AC_CHECK_HEADERS([sys/cdefs.h], [], [],
395 [#ifdef HAVE_SYS_CDEFS_H
396 #include <sys/cdefs.h>
397 #endif])
398
399 DISPATCH_C_BLOCKS
400
401 AC_CACHE_CHECK([for -fvisibility=hidden], [dispatch_cv_cc_visibility_hidden], [
402 saveCFLAGS="$CFLAGS"
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"])
407 CFLAGS="$saveCFLAGS"
408 ])
409 AS_IF([test "x$dispatch_cv_cc_visibility_hidden" != "xno"], [
410 VISIBILITY_FLAGS="-fvisibility=hidden"
411 ])
412 AC_SUBST([VISIBILITY_FLAGS])
413
414 AC_CACHE_CHECK([for -momit-leaf-frame-pointer], [dispatch_cv_cc_omit_leaf_fp], [
415 saveCFLAGS="$CFLAGS"
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"])
420 CFLAGS="$saveCFLAGS"
421 ])
422 AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
423 OMIT_LEAF_FP_FLAGS="-momit-leaf-frame-pointer"
424 ])
425 AC_SUBST([OMIT_LEAF_FP_FLAGS])
426
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"
435 ])
436 ])
437 AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])
438
439 #
440 # symlink platform-specific module.modulemap files
441 #
442 AS_CASE([$target_os],
443 [darwin*], [ dispatch_module_map_os=darwin ],
444 [ dispatch_module_map_os=generic ]
445 )
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
449 ],
450 [dispatch_module_map_os="$dispatch_module_map_os"]
451 )
452
453 #
454 # Temporary: some versions of clang do not mark __builtin_trap() as
455 # __attribute__((__noreturn__)). Detect and add if required.
456 #
457 AC_COMPILE_IFELSE(
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])]
460 )
461
462 #
463 # Generate Makefiles.
464 #
465 AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Makefile src/Makefile tests/Makefile])
466
467 #
468 # Generate testsuite links
469 #
470 AC_CONFIG_LINKS([tests/dispatch:$ac_top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])
471
472 AC_OUTPUT