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