1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2019, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
7 AC_INIT([tor],[0.4.7.10-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
12 AC_DEFINE_UNQUOTED([CONFIG_FLAGS], ["$configure_flags"], [Flags passed to configure])
15 # DO NOT EDIT THIS DEFINITION BY HAND UNLESS YOU KNOW WHAT YOU'RE DOING.
17 # The update_versions.py script updates this definition when the
18 # version number changes. Tor uses it to make sure that it
19 # only shuts down for missing "required protocols" when those protocols
20 # are listed as required by a consensus after this date.
21 AC_DEFINE(APPROX_RELEASE_DATE, ["2022-08-12"], # for 0.4.7.10-dev
22 [Approximate date when this software was released. (Updated when the version changes.)])
24 # "foreign" means we don't follow GNU package layout standards
25 # "1.11" means we require automake version 1.11 or newer
26 # "subdir-objects" means put .o files in the same directory as the .c files
27 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
30 tor_incr_n_warnings() {
31 tor_ac_n_warnings=`expr $tor_ac_n_warnings + 1`
34 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
35 AC_CONFIG_HEADERS([orconfig.h])
37 AC_USE_SYSTEM_EXTENSIONS
41 if test "x$PKG_CONFIG" = "x" ; then
42 pkg_config_user_action="install pkg-config, and check the PKG_CONFIG_PATH environment variable"
43 AC_MSG_NOTICE([Some libraries need pkg-config, including systemd, nss, lzma, zstd, and custom mallocs.])
44 AC_MSG_NOTICE([To use those libraries, $pkg_config_user_action.])
46 pkg_config_user_action="check the PKG_CONFIG_PATH environment variable"
49 if test "x$PKG_CONFIG_PATH" = "x" && test "x$prefix" != "xNONE" && test "$host" != "$build"; then
50 export PKG_CONFIG_PATH=$prefix/lib/pkgconfig
51 AC_MSG_NOTICE([set PKG_CONFIG_PATH=$PKG_CONFIG_PATH to support cross-compiling])
54 AC_ARG_ENABLE(openbsd-malloc,
55 AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only. Deprecated: see --with-malloc]))
56 AC_ARG_ENABLE(static-openssl,
57 AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
58 AC_ARG_ENABLE(static-libevent,
59 AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
60 AC_ARG_ENABLE(static-zlib,
61 AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
62 AC_ARG_ENABLE(static-tor,
63 AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
64 AC_ARG_ENABLE(unittests,
65 AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
66 AC_ARG_ENABLE(coverage,
67 AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
68 AC_ARG_ENABLE(asserts-in-tests,
69 AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
70 AC_ARG_ENABLE(system-torrc,
71 AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
72 AC_ARG_ENABLE(libfuzzer,
73 AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
74 AC_ARG_ENABLE(oss-fuzz,
75 AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
76 AC_ARG_ENABLE(memory-sentinels,
77 AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
78 AC_ARG_ENABLE(restart-debugging,
79 AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
80 AC_ARG_ENABLE(zstd-advanced-apis,
81 AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
83 AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
85 AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
87 AC_ARG_ENABLE(missing-doc-warnings,
88 AS_HELP_STRING(--enable-missing-doc-warnings, [Tell doxygen to warn about missing documentation. Makes doxygen warnings nonfatal.]))
90 if test "$enable_missing_doc_warnings" = "yes"; then
91 DOXYGEN_FATAL_WARNINGS=NO
92 DOXYGEN_WARN_ON_MISSING=YES
93 elif test "$enable_fatal_warnings" = "yes"; then
94 # Fatal warnings from doxygen are nice, but not if we're warning about
95 # missing documentation.
96 DOXYGEN_FATAL_WARNINGS=YES
97 DOXYGEN_WARN_ON_MISSING=NO
99 DOXYGEN_FATAL_WARNINGS=NO
100 DOXYGEN_WARN_ON_MISSING=NO
102 AC_SUBST(DOXYGEN_FATAL_WARNINGS)
103 AC_SUBST(DOXYGEN_WARN_ON_MISSING)
105 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
106 AC_MSG_ERROR([Can't disable assertions outside of coverage build])
109 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
110 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
111 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
112 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
113 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
114 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
115 AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
117 if test "x$enable_coverage" = "xyes"; then
118 AC_DEFINE(ENABLE_COVERAGE, 1,
119 [Defined if coverage support is enabled for the unit tests])
122 if test "x$enable_nss" = "xyes"; then
123 AC_DEFINE(ENABLE_NSS, 1,
124 [Defined if we're building with NSS.])
126 AC_DEFINE(ENABLE_OPENSSL, 1,
127 [Defined if we're building with OpenSSL or LibreSSL])
130 if test "$enable_static_tor" = "yes"; then
131 enable_static_libevent="yes";
132 enable_static_openssl="yes";
133 enable_static_zlib="yes";
134 TOR_STATIC_LDFLAGS="-static"
136 AC_SUBST(TOR_STATIC_LDFLAGS)
138 if test "$enable_system_torrc" = "no"; then
139 AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
140 [Defined if we're not going to look for a torrc in SYSCONF])
143 if test "$enable_memory_sentinels" = "no"; then
144 AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
145 [Defined if we're turning off memory safety code to look for bugs])
148 AC_ARG_ENABLE(manpage,
149 AS_HELP_STRING(--disable-manpage, [Disable manpage generation.]))
151 AC_ARG_ENABLE(html-manual,
152 AS_HELP_STRING(--disable-html-manual, [Disable HTML documentation.]))
154 AC_ARG_ENABLE(asciidoc,
155 AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
156 [case "${enableval}" in
157 "yes") asciidoc=true ;;
158 "no") asciidoc=false ;;
159 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
160 esac], [asciidoc=true])
162 # systemd notify support
163 AC_ARG_ENABLE(systemd,
164 AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
165 [case "${enableval}" in
166 "yes") systemd=true ;;
167 "no") systemd=false ;;
168 * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
169 esac], [systemd=auto])
171 if test "$enable_restart_debugging" = "yes"; then
172 AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
173 [Defined if we're building with support for in-process restart debugging.])
176 if test "$enable_zstd_advanced_apis" != "no"; then
177 AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
178 [Defined if we're going to try to use zstd's "static-only" APIs.])
182 if test "x$enable_systemd" = "xno"; then
185 PKG_CHECK_MODULES(SYSTEMD,
189 if test "x$have_systemd" = "xno"; then
190 AC_MSG_NOTICE([Okay, checking for systemd a different way...])
191 PKG_CHECK_MODULES(SYSTEMD,
198 if test "x$have_systemd" = "xyes"; then
199 AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
200 TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
201 TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
202 PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
203 [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or greater])], [])
205 AC_SUBST(TOR_SYSTEMD_CFLAGS)
206 AC_SUBST(TOR_SYSTEMD_LIBS)
208 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
209 AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found, $pkg_config_user_action, or set SYSTEMD_CFLAGS and SYSTEMD_LIBS.])
214 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
218 AC_ARG_ENABLE(gcc-warnings,
219 AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
220 AC_ARG_ENABLE(fatal-warnings,
221 AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
222 AC_ARG_ENABLE(gcc-warnings-advisory,
223 AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
225 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
226 AC_ARG_ENABLE(gcc-hardening,
227 AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
229 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
230 AC_ARG_ENABLE(expensive-hardening,
231 AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
232 AC_ARG_ENABLE(fragile-hardening,
233 AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
234 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
235 fragile_hardening="yes"
236 AC_DEFINE(ENABLE_FRAGILE_HARDENING, 1, [Defined if we're building with additional, fragile and expensive compiler hardening])
237 AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
240 AC_ARG_ENABLE(all-bugs-are-fatal,
241 AS_HELP_STRING(--enable-all-bugs-are-fatal, [force all soft asserts in Tor codebase (tor_assert_nonfatal(), BUG(), etc.) to act as hard asserts (tor_assert() and equivalents); makes Tor fragile; only recommended for dev builds]))
243 if test "x$enable_all_bugs_are_fatal" = "xyes"; then
244 AC_DEFINE(ALL_BUGS_ARE_FATAL, 1, [All assert failures are fatal])
247 dnl Linker hardening options
248 dnl Currently these options are ELF specific - you can't use this with MacOSX
249 AC_ARG_ENABLE(linker-hardening,
250 AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
252 AC_ARG_ENABLE(local-appdata,
253 AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
254 if test "$enable_local_appdata" = "yes"; then
255 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
256 [Defined if we default to host local appdata paths on Windows])
259 AC_ARG_ENABLE(tool-name-check,
260 AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
262 AC_ARG_ENABLE(seccomp,
263 AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
265 AC_ARG_ENABLE(libscrypt,
266 AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
268 dnl --- Tracing Options. ---
272 dnl LTTng instrumentation option.
273 AC_ARG_ENABLE(tracing-instrumentation-lttng,
274 AS_HELP_STRING([--enable-tracing-instrumentation-lttng],
275 [build with LTTng-UST instrumentation]))
276 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LTTNG],
277 [test "x$enable_tracing_instrumentation_lttng" = "xyes"])
279 if test "x$enable_tracing_instrumentation_lttng" = "xyes"; then
280 AC_CHECK_HEADERS([lttng/tracepoint.h], [],
281 [AC_MSG_ERROR([LTTng instrumentation headers not found.
282 On Debian, apt install liblttng-ust-dev"])], [])
283 AC_DEFINE([USE_TRACING_INSTRUMENTATION_LTTNG], [1], [Using LTTng instrumentation])
284 TOR_TRACE_LIBS="-llttng-ust -ldl"
288 dnl USDT instrumentation option.
289 AC_ARG_ENABLE(tracing-instrumentation-usdt,
290 AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
291 [build with tracing USDT instrumentation]))
292 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
293 [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
295 if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
296 AC_CHECK_HEADERS([sys/sdt.h], [],
297 [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
298 On Debian, apt install systemtap-sdt-dev])], [])
299 AC_MSG_CHECKING([STAP_PROBEV()])
300 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
301 #define SDT_USE_VARIADIC
305 STAP_PROBEV(p, n, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
309 dnl LTTng generates USDT probes if the UST library was built with
310 dnl --with-sdt. There is unfortunately no way to check that so we always
311 dnl build the USDT probes even though LTTng instrumentation was requested.
312 AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
316 AC_MSG_ERROR([USDT tracing support requires STAP_PROBEV()])
320 dnl Tracepoints event to debug logs.
321 AC_ARG_ENABLE(tracing-instrumentation-log-debug,
322 AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
323 [build with tracing event to debug log]),
324 AC_DEFINE([USE_TRACING_INSTRUMENTATION_LOG_DEBUG], [1],
325 [Tracepoints to log debug]), [])
326 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
327 [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
328 if test "x$enable_tracing_instrumentation_log_debug" = "xyes"; then
332 dnl Define that tracing is supported if any instrumentation is used.
333 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
334 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
335 AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
336 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
337 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LTTNG],
338 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
339 AM_CONDITIONAL([USE_TRACING], [test "x$have_tracing" = x1 ])
341 dnl Finally, define the trace libs.
342 AC_SUBST([TOR_TRACE_LIBS])
344 dnl -- End Tracing Options. --
346 dnl Enable Android only features.
347 AC_ARG_ENABLE(android,
348 AS_HELP_STRING(--enable-android, [build with Android features enabled]))
349 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
351 if test "x$enable_android" = "xyes"; then
352 AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
357 dnl Tor modules options. These options are namespaced with --disable-module-XXX
361 m4_define(MODULES, relay dirauth dircache)
363 # Some modules are only disabled through another option. For those, we don't
364 # want to print the help in the summary at the end of the configure. Any entry
365 # in the following set will not print the "--disable-module-NAME" command in
367 m4_set_add_all([MODULES_WITH_NO_OPTIONS], [dircache])
370 AC_ARG_ENABLE([module-relay],
371 AS_HELP_STRING([--disable-module-relay],
372 [Build tor without the Relay modules: tor can not run as a relay, bridge, or authority. Implies --disable-module-dirauth]))
373 AM_CONDITIONAL(BUILD_MODULE_RELAY, [test "x$enable_module_relay" != "xno"])
374 AM_COND_IF(BUILD_MODULE_RELAY,
375 AC_DEFINE([HAVE_MODULE_RELAY], [1],
376 [Compile with Relay feature support]))
378 dnl Dircache module. (This cannot be enabled or disabled independently of
379 dnl the relay module. It is not listed by --list-modules for this reason.)
380 AM_CONDITIONAL(BUILD_MODULE_DIRCACHE,
381 [test "x$enable_module_relay" != "xno"])
382 AM_COND_IF(BUILD_MODULE_DIRCACHE,
383 AC_DEFINE([HAVE_MODULE_DIRCACHE], [1],
384 [Compile with directory cache support]))
386 dnl Directory Authority module.
387 AC_ARG_ENABLE([module-dirauth],
388 AS_HELP_STRING([--disable-module-dirauth],
389 [Build tor without the Directory Authority module: tor can not run as a directory authority or bridge authority]))
390 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH,[test "x$enable_module_dirauth" != "xno" && test "x$enable_module_relay" != "xno"])
391 AM_COND_IF(BUILD_MODULE_DIRAUTH,
392 AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
393 [Compile with Directory Authority feature support]))
395 dnl Helper variables.
396 TOR_MODULES_ALL_ENABLED=
397 AC_DEFUN([ADD_MODULE], [
398 MODULE=m4_toupper($1)
399 TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
401 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
402 AC_SUBST(TOR_MODULES_ALL_ENABLED)
404 dnl check for the correct "ar" when cross-compiling.
405 dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
406 dnl so kludge up a replacement for the case where it isn't there yet.)
407 m4_ifdef([AM_PROG_AR],
409 [AN_MAKEVAR([AR], [AC_PROG_AR])
410 AN_PROGRAM([ar], [AC_PROG_AR])
411 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
414 dnl Check whether the above macro has settled for a simply named tool even
415 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
416 dnl because that will find any cc on the system, not only the cross-compiler,
417 dnl and then verify that a binary built with this compiler runs on the
418 dnl build system. It will then come to the false conclusion that we're not
420 if test "x$enable_tool_name_check" != "xno"; then
421 if test "x$ac_tool_warned" = "xyes"; then
422 AC_MSG_ERROR([We are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
423 elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
424 AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
437 AC_DEFINE_UNQUOTED([COMPILER_VERSION],["$ax_cv_c_compiler_version"], [Compiler version])
438 AC_DEFINE_UNQUOTED([COMPILER_VENDOR],["$ax_cv_c_compiler_vendor"], [Compiler vendor])
440 AS_CASE($ax_cv_c_compiler_vendor,
441 [gnu], AC_DEFINE([COMPILER],["GCC"],[Compiler name]),
442 AC_DEFINE([COMPILER],[],[Compiler name])
445 AC_ARG_VAR([PERL], [path to Perl binary])
446 AC_CHECK_PROGS([PERL], [perl])
447 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
449 dnl check for asciidoc and a2x
450 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
451 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
453 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
454 AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
455 AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
459 dnl Before autoconf 2.70, AC_PROG_CC_C99 is supposedly necessary for some
460 dnl compilers if you want C99 support. Starting with 2.70, it is obsolete and
462 m4_version_prereq([2.70], [:], [AC_PROG_CC_C99])
464 AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
465 [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
467 python3.8 python3.7 python3.6 python3.5 python3.4 \
469 [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
470 AC_SUBST([PYTHON], [$tor_cv_PYTHON])
472 PYTHON="$tor_cv_PYTHON"
474 if test "x$PYTHON" = "x"; then
476 AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
479 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
481 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
482 AC_C_FLEXIBLE_ARRAY_MEMBER
484 dnl Maybe we've got an old autoconf...
485 AC_CACHE_CHECK([for flexible array members],
489 struct abc { int a; char b[]; };
491 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
494 [tor_cv_c_flexarray=yes],
495 [tor_cv_c_flexarray=no])])
496 if test "$tor_cv_flexarray" = "yes"; then
497 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
499 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
503 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
506 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
507 [tor_cv_c_c99_decl=yes],
508 [tor_cv_c_c99_decl=no] )])
509 if test "$tor_cv_c_c99_decl" != "yes"; then
510 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
513 AC_CACHE_CHECK([for working C99 designated initializers],
514 tor_cv_c_c99_designated_init,
516 [AC_LANG_PROGRAM([struct s { int a; int b; };],
517 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
518 [tor_cv_c_c99_designated_init=yes],
519 [tor_cv_c_c99_designated_init=no] )])
521 if test "$tor_cv_c_c99_designated_init" != "yes"; then
522 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
525 saved_CFLAGS="$CFLAGS"
526 CFLAGS="$CFLAGS -Werror"
527 AC_CACHE_CHECK([for __attribute__((fallthrough))],
528 tor_cv_c_attr_fallthrough,
530 [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
531 [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
532 case 2: fn(); break; } ]])],
533 [tor_cv_c_attr_fallthrough=yes],
534 [tor_cv_c_attr_fallthrough=no] )])
535 CFLAGS="$saved_CFLAGS"
537 if test "$tor_cv_c_attr_fallthrough" = "yes"; then
538 AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
542 AC_ARG_WITH(tor-user,
543 AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
551 AC_ARG_WITH(tor-group,
552 AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
560 dnl If _WIN32 is defined and non-zero, we are building for win32
561 AC_MSG_CHECKING([for win32])
562 AC_RUN_IFELSE([AC_LANG_SOURCE([
563 int main(int c, char **v) {
574 bwin32=true; AC_MSG_RESULT([yes]),
575 bwin32=false; AC_MSG_RESULT([no]),
576 bwin32=cross; AC_MSG_RESULT([cross])
579 if test "$bwin32" = "cross"; then
580 AC_MSG_CHECKING([for win32 (cross)])
581 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
583 int main(int c, char **v) {return 0;}
586 int main(int c, char **v) {return x(y);}
589 bwin32=true; AC_MSG_RESULT([yes]),
590 bwin32=false; AC_MSG_RESULT([no]))
595 /* Defined to access windows functions and definitions for >=WinVista */
597 # define WINVER 0x0600
600 /* Defined to access _other_ windows functions and definitions for >=WinVista */
601 # ifndef _WIN32_WINNT
602 # define _WIN32_WINNT 0x0600
605 /* Defined to avoid including some windows headers as part of Windows.h */
606 # ifndef WIN32_LEAN_AND_MEAN
607 # define WIN32_LEAN_AND_MEAN 1
612 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
613 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
614 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
616 dnl Enable C99 when compiling with MIPSpro
617 AC_MSG_CHECKING([for MIPSpro compiler])
618 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
619 #if (defined(__sgi) && defined(_COMPILER_VERSION))
624 bmipspro=false; AC_MSG_RESULT(no),
625 bmipspro=true; AC_MSG_RESULT(yes))
627 if test "$bmipspro" = "true"; then
628 CFLAGS="$CFLAGS -c99"
633 AC_SEARCH_LIBS(socket, [socket network])
634 AC_SEARCH_LIBS(gethostbyname, [nsl])
635 AC_SEARCH_LIBS(dlopen, [dl])
636 AC_SEARCH_LIBS(inet_aton, [resolv])
637 AC_SEARCH_LIBS(backtrace, [execinfo])
639 AC_SEARCH_LIBS([clock_gettime], [rt])
640 if test "$LIBS" != "$saved_LIBS"; then
641 # Looks like we need -lrt for clock_gettime().
645 if test "$bwin32" = "false"; then
646 AC_SEARCH_LIBS(pthread_create, [pthread])
647 AC_SEARCH_LIBS(pthread_detach, [pthread])
650 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
651 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
655 RtlSecureZeroMemory \
659 backtrace_symbols_fd \
666 get_current_dir_name \
674 gnu_get_libc_version \
714 # Apple messed up when they added some functions: they
715 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
718 # We should only probe for these functions if we are sure that we
719 # are not targeting OS X 10.9 or earlier.
720 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
721 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
723 # include <AvailabilityMacros.h>
724 # ifndef MAC_OS_X_VERSION_10_10
725 # define MAC_OS_X_VERSION_10_10 101000
727 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
728 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
729 # error "Running on Mac OS X 10.9 or earlier"
734 [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
735 [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
737 if test "$on_macos_pre_10_10" = "no"; then
739 mach_approximate_time \
743 # We should only probe for these functions if we are sure that we
744 # are not targeting OSX 10.11 or earlier.
745 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
746 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
748 # include <AvailabilityMacros.h>
749 # ifndef MAC_OS_X_VERSION_10_12
750 # define MAC_OS_X_VERSION_10_12 101200
752 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
753 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
754 # error "Running on Mac OSX 10.11 or earlier"
759 [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
760 [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
762 if test "$on_macos_pre_10_12" = "no"; then
769 if test "$bwin32" != "true"; then
770 AC_CHECK_HEADERS(pthread.h)
771 AC_CHECK_FUNCS(pthread_create)
772 AC_CHECK_FUNCS(pthread_condattr_setclock)
775 if test "$bwin32" = "true"; then
776 AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
783 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
784 test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
788 AC_MSG_CHECKING([whether free(NULL) works])
789 AC_RUN_IFELSE([AC_LANG_PROGRAM([
795 [free_null_ok=true; AC_MSG_RESULT(yes)],
796 [free_null_ok=false; AC_MSG_RESULT(no)],
797 [free_null_ok=cross; AC_MSG_RESULT(cross)])
799 if test "$free_null_ok" = "false"; then
800 AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
803 dnl ------------------------------------------------------
804 dnl Where do you live, libevent? And how do we call you?
806 if test "$bwin32" = "true"; then
807 TOR_LIB_WS32=-lws2_32
808 TOR_LIB_IPHLPAPI=-liphlpapi
809 TOR_LIB_SHLWAPI=-lshlwapi
811 TOR_LIB_USERENV=-luserenv
812 TOR_LIB_BCRYPT=-lbcrypt
813 TOR_LIB_CRYPT32=-lcrypt32
819 AC_SUBST(TOR_LIB_WS32)
820 AC_SUBST(TOR_LIB_GDI)
821 AC_SUBST(TOR_LIB_IPHLPAPI)
822 AC_SUBST(TOR_LIB_BCRYPT)
823 AC_SUBST(TOR_LIB_CRYPT32)
824 AC_SUBST(TOR_LIB_SHLWAPI)
825 AC_SUBST(TOR_LIB_USERENV)
827 tor_libevent_pkg_redhat="libevent"
828 tor_libevent_pkg_debian="libevent-dev"
829 tor_libevent_devpkg_redhat="libevent-devel"
830 tor_libevent_devpkg_debian="libevent-dev"
832 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
833 dnl linking for static builds.
834 STATIC_LIBEVENT_FLAGS=""
835 if test "$enable_static_libevent" = "yes"; then
836 if test "$have_rt" = "yes"; then
837 STATIC_LIBEVENT_FLAGS=" -lrt "
841 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_IPHLPAPI $TOR_LIB_BCRYPT $TOR_LIB_WS32], [
843 #include <winsock2.h>
845 #include <sys/time.h>
846 #include <sys/types.h>
847 #include <event2/event.h>], [
849 #include <winsock2.h>
852 struct event_base *event_base_new(void);
853 void event_base_free(struct event_base *);],
856 {WSADATA d; WSAStartup(0x101,&d); }
858 event_base_free(event_base_new());
859 ], [--with-libevent-dir], [/opt/libevent])
861 dnl Determine the incantation needed to link libevent.
863 save_LDFLAGS="$LDFLAGS"
864 save_CPPFLAGS="$CPPFLAGS"
866 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
867 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
868 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
870 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
872 if test "$enable_static_libevent" = "yes"; then
873 if test "$tor_cv_library_libevent_dir" = "(system)"; then
874 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
876 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
879 if test "x$ac_cv_header_event2_event_h" = "xyes"; then
880 AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
881 AC_SEARCH_LIBS(evdns_base_new, [event event_extra], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for evdns_base_new"))
883 if test "$ac_cv_search_event_new" != "none required"; then
884 TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
886 if test "$ac_cv_search_evdns_base_new" != "none required"; then
887 TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
890 AC_MSG_ERROR("libevent2 is required but the headers could not be found")
894 dnl Now check for particular libevent functions.
895 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
896 evutil_secure_rng_add_bytes \
897 evdns_base_get_nameserver_addr \
902 LDFLAGS="$save_LDFLAGS"
903 CPPFLAGS="$save_CPPFLAGS"
905 dnl Check that libevent is at least at version 2.0.10, the first stable
906 dnl release of its series
907 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
908 AC_MSG_CHECKING([whether Libevent is new enough])
909 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
910 #include <event2/event.h>
911 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
917 ])], [ AC_MSG_RESULT([yes]) ],
918 [ AC_MSG_RESULT([no])
919 AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
922 LDFLAGS="$save_LDFLAGS"
923 CPPFLAGS="$save_CPPFLAGS"
925 AC_SUBST(TOR_LIBEVENT_LIBS)
927 dnl ------------------------------------------------------
928 dnl Where do you live, libm?
930 dnl On some platforms (Haiku/BeOS) the math library is
931 dnl part of libroot. In which case don't link against lm
934 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
935 if test "$ac_cv_search_pow" != "none required"; then
936 TOR_LIB_MATH="$ac_cv_search_pow"
939 AC_SUBST(TOR_LIB_MATH)
941 dnl ------------------------------------------------------
942 dnl Hello, NSS. You're new around here.
943 if test "x$enable_nss" = "xyes"; then
944 PKG_CHECK_MODULES(NSS,
947 [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it, $pkg_config_user_action, or set NSS_CFLAGS and NSS_LIBS.])])
952 dnl ------------------------------------------------------
953 dnl Where do you live, openssl? And how do we call you?
955 if test "x$enable_nss" != "xyes"; then
957 tor_openssl_pkg_redhat="openssl"
958 tor_openssl_pkg_debian="libssl-dev"
959 tor_openssl_devpkg_redhat="openssl-devel"
960 tor_openssl_devpkg_debian="libssl-dev"
962 ALT_openssl_WITHVAL=""
964 AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
966 if test "x$withval" != "xno" && test "x$withval" != "x"; then
967 ALT_openssl_WITHVAL="$withval"
971 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
972 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32 $TOR_LIB_CRYPT32],
973 [#include <openssl/ssl.h>
974 char *getenv(const char *);],
975 [struct ssl_cipher_st;
976 unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
977 char *getenv(const char *);],
978 dnl This funny-looking test program calls getenv, so that the compiler
979 dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
980 dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
981 dnl We look for SSL_cipher_get_id() because it is present in
982 dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
984 [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
985 [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
987 if test "$enable_static_openssl" = "yes"; then
988 if test "$tor_cv_library_openssl_dir" = "(system)"; then
989 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
991 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a $TOR_LIB_WS32 $TOR_LIB_CRYPT32 $TOR_LIB_BCRYPT"
994 TOR_OPENSSL_LIBS="-lssl -lcrypto"
996 AC_SUBST(TOR_OPENSSL_LIBS)
998 dnl Now validate openssl, and check for particular openssl functions.
1000 save_LDFLAGS="$LDFLAGS"
1001 save_CPPFLAGS="$CPPFLAGS"
1002 LIBS="$TOR_OPENSSL_LIBS $LIBS"
1003 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
1004 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
1006 dnl Tor currently uses a number of APIs that are deprecated in OpenSSL 3.0.0
1007 dnl and later. We want to migrate away from them, but that will be a lot of
1008 dnl work. (See ticket tor#40166.) For now, we disable the deprecation
1011 AC_MSG_CHECKING([for OpenSSL >= 3.0.0])
1012 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1013 #include <openssl/opensslv.h>
1014 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L
1015 #error "you_have_version_3"
1018 [ AC_MSG_RESULT([no]) ],
1019 [ AC_MSG_RESULT([yes]);
1020 AC_DEFINE(OPENSSL_SUPPRESS_DEPRECATED, 1, [disable openssl deprecated-function warnings]) ])
1022 AC_MSG_CHECKING([for OpenSSL < 1.0.1])
1023 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1024 #include <openssl/opensslv.h>
1025 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
1029 [ AC_MSG_RESULT([no]) ],
1030 [ AC_MSG_ERROR([OpenSSL is too old. We require 1.0.1 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
1032 AC_MSG_CHECKING([whether LibreSSL TLS 1.3 APIs are busted])
1033 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1034 #include <openssl/opensslv.h>
1035 #if defined(LIBRESSL_VERSION_NUMBER) && \
1036 LIBRESSL_VERSION_NUMBER >= 0x3020100fL && \
1037 LIBRESSL_VERSION_NUMBER < 0x3040100fL
1041 [ AC_MSG_RESULT([no]) ],
1042 [ AC_MSG_ERROR([This version of LibreSSL won't work with Tor. Please upgrade to LibreSSL 3.4.1 or later. (Or downgrade to 3.2.0 if you really must.)]) ])
1044 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1045 #include <openssl/opensslv.h>
1046 #include <openssl/evp.h>
1047 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
1050 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
1051 #error "curves unavailable"
1055 [ AC_MSG_ERROR([OpenSSL is built without full ECC support, including curves P256 and P224. You can specify a path to one with ECC support with --with-openssl-dir.]) ])
1057 dnl Let's see if we have a version mismatch between includes and libs.
1058 AC_MSG_CHECKING([for significant mismatch between openssl headers and libraries])
1060 AC_RUN_IFELSE([AC_LANG_SOURCE([AC_LANG_PROGRAM([[
1061 #include <openssl/opensslv.h>
1062 #include <openssl/crypto.h>
1064 /* Include major, minor, and fix, but not patch or status. */
1065 unsigned long mask = 0xfffff000;
1066 unsigned long linking = OpenSSL_version_num() & mask;
1067 unsigned long running = OPENSSL_VERSION_NUMBER & mask;
1068 return !(linking==running);
1069 ]])])], [openssl_ver_mismatch=no], [
1070 # This is a kludge to figure out whether compilation failed, or whether
1071 # running the program failed.
1072 if test "$ac_retval" = "1"; then
1073 openssl_ver_mismatch=inconclusive
1075 openssl_ver_mismatch=yes
1076 fi], [openssl_ver_mismatch=cross])
1077 AC_MSG_RESULT([$openssl_ver_mismatch])
1079 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
1080 [#include <openssl/ssl.h>
1083 dnl OpenSSL functions which we might not have. In theory, we could just
1084 dnl check the openssl version number, but in practice that gets pretty
1085 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
1088 ERR_load_KDF_strings \
1091 SSL_CTX_set1_groups_list \
1092 SSL_CTX_set_security_level \
1093 SSL_SESSION_get_master_key \
1094 SSL_get_client_ciphers \
1095 SSL_get_client_random \
1096 SSL_get_server_random \
1100 dnl Check if OpenSSL structures are opaque
1101 AC_CHECK_MEMBERS([SSL.state], , ,
1102 [#include <openssl/ssl.h>
1105 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
1106 #include <openssl/sha.h>
1111 dnl We will someday make KECCAK_TINY optional, but for now we still need
1112 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
1113 dnl once. See comment in the definition of crypto_xof_t.
1115 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
1116 dnl test "x$ac_cv_func_EVP_sha3_256" != "xyes")
1118 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
1120 dnl ======================================================================
1121 dnl Can we use KIST?
1123 dnl Define the set of checks for KIST scheduler support.
1124 AC_DEFUN([CHECK_KIST_SUPPORT],[
1125 dnl KIST needs struct tcp_info and for certain members to exist.
1127 [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1128 , ,[[#include <netinet/tcp.h>]])
1129 dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1130 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1131 #include <linux/sockios.h>
1135 ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1136 if test "x$have_siocoutqnsd" = "xyes"; then
1137 if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1138 if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1139 have_kist_support=yes
1144 dnl Now, trigger the check.
1146 AS_IF([test "x$have_kist_support" = "xyes"],
1147 [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1149 [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1152 LDFLAGS="$save_LDFLAGS"
1153 CPPFLAGS="$save_CPPFLAGS"
1155 dnl ------------------------------------------------------
1156 dnl Where do you live, zlib? And how do we call you?
1158 tor_zlib_pkg_redhat="zlib"
1159 tor_zlib_pkg_debian="zlib1g"
1160 tor_zlib_devpkg_redhat="zlib-devel"
1161 tor_zlib_devpkg_debian="zlib1g-dev"
1163 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1164 [#include <zlib.h>],
1165 [const char * zlibVersion(void);],
1166 [zlibVersion();], [--with-zlib-dir],
1169 if test "$enable_static_zlib" = "yes"; then
1170 if test "$tor_cv_library_zlib_dir" = "(system)"; then
1171 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1172 using --enable-static-zlib")
1174 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1179 AC_SUBST(TOR_ZLIB_LIBS)
1181 dnl ------------------------------------------------------
1182 dnl Where we do we find lzma?
1185 AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1186 [case "${enableval}" in
1189 * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1190 esac], [enable_lzma=auto])
1192 if test "x$enable_lzma" = "xno"; then
1195 PKG_CHECK_MODULES([LZMA],
1200 if test "x$have_lzma" = "xno" ; then
1202 AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
1206 if test "x$have_lzma" = "xyes"; then
1207 AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1208 TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1209 TOR_LZMA_LIBS="${LZMA_LIBS}"
1211 AC_SUBST(TOR_LZMA_CFLAGS)
1212 AC_SUBST(TOR_LZMA_LIBS)
1214 dnl ------------------------------------------------------
1215 dnl Where we do we find zstd?
1218 AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1219 [case "${enableval}" in
1222 * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1223 esac], [enable_zstd=auto])
1225 if test "x$enable_zstd" = "xno"; then
1228 PKG_CHECK_MODULES([ZSTD],
1233 if test "x$have_zstd" = "xno" ; then
1235 AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
1239 if test "x$have_zstd" = "xyes"; then
1240 AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1241 TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1242 TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1244 dnl now check for zstd functions
1246 save_CFLAGS="$CFLAGS"
1247 LIBS="$LIBS $ZSTD_LIBS"
1248 CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1249 AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1250 ZSTD_estimateDCtxSize)
1252 CFLAGS="$save_CFLAGS"
1254 AC_SUBST(TOR_ZSTD_CFLAGS)
1255 AC_SUBST(TOR_ZSTD_LIBS)
1257 dnl ----------------------------------------------------------------------
1258 dnl Check if libcap is available for capabilities.
1260 tor_cap_pkg_debian="libcap2"
1261 tor_cap_pkg_redhat="libcap"
1262 tor_cap_devpkg_debian="libcap-dev"
1263 tor_cap_devpkg_redhat="libcap-devel"
1265 AC_CHECK_LIB([cap], [cap_init], [],
1266 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1268 AC_CHECK_FUNCS(cap_set_proc)
1270 dnl ---------------------------------------------------------------------
1271 dnl Now that we know about our major libraries, we can check for compiler
1272 dnl and linker hardening options. We need to do this with the libraries known,
1273 dnl since sometimes the linker will like an option but not be willing to
1274 dnl use it with a build of a library.
1276 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1277 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI $TOR_LIB_USERENV $TOR_CAP_LIBS"
1285 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1286 #if !defined(__clang__)
1288 #endif])], have_clang=yes, have_clang=no)
1290 if test "x$enable_pic" = "xyes"; then
1291 TOR_CHECK_CFLAGS(-fPIC)
1294 if test "x$enable_gcc_hardening" != "xno"; then
1295 CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1296 if test "x$have_clang" = "xyes"; then
1297 TOR_CHECK_CFLAGS(-Qunused-arguments)
1299 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1300 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1301 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1302 m4_ifdef([AS_VAR_IF],[
1303 AS_VAR_IF(can_compile, [yes],
1304 AS_VAR_IF(can_link, [yes],
1306 AC_MSG_ERROR([We tried to build with stack protection; it looks like your compiler supports it but your libc does not provide it. Are you missing libssp? (You can --disable-gcc-hardening to ignore this error.)]))
1308 AS_VAR_POPDEF([can_link])
1309 AS_VAR_POPDEF([can_compile])
1310 TOR_CHECK_CFLAGS(-Wstack-protector)
1311 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1312 if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1313 if test "$enable_pic" != "yes"; then
1314 # If we have already enabled -fPIC, then we don't also need to
1315 # compile with -fPIE...
1316 TOR_CHECK_CFLAGS(-fPIE)
1318 # ... but we want to link our executables with -pie in any case, since
1319 # they're executables, not a library.
1320 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1322 TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1324 AC_MSG_CHECKING([whether we can run hardened binaries])
1325 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1326 [AC_MSG_RESULT([yes])],
1327 [AC_MSG_RESULT([no])
1329 We can link with compiler hardening options, but we can't run with them.
1330 That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1331 configure, but it would be better to figure out what the underlying problem
1333 [AC_MSG_RESULT([cross])])
1336 if test "$fragile_hardening" = "yes"; then
1337 TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1338 if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1340 AC_MSG_WARN([The compiler supports -ftrapv, but for some reason I was not able to link with -ftrapv. Are you missing run-time support? Run-time hardening will not work as well as it should.])
1343 if test "$tor_cv_cflags__ftrapv" != "yes"; then
1344 AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1347 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1348 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1349 AC_MSG_ERROR([The compiler supports -fsanitize=address, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libubsan.*, and with Clang you need libclang_rt.ubsan*])
1352 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1353 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1354 AC_MSG_ERROR([The compiler supports -fsanitize=undefined, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.*, and with Clang you need libclang_rt.ubsan*])
1357 TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1358 if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1359 AC_MSG_ERROR([The compiler supports -fno-sanitize=float-divide-by-zero, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.*, and with Clang you need libclang_rt.ubsan*])
1362 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1365 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1366 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1368 mulodi_fixes_ftrapv=no
1369 if test "$have_clang" = "yes"; then
1370 saved_CFLAGS="$CFLAGS"
1371 CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1372 AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1377 int main(int argc, char **argv)
1379 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1380 * (int64_t)atoi(argv[3]);
1383 [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1384 [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1385 if test "$ftrapv_can_link" = "no"; then
1386 AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1391 int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1395 int main(int argc, char **argv)
1397 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1398 * (int64_t)atoi(argv[3]);
1401 [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1402 [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1404 CFLAGS="$saved_CFLAGS"
1407 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1409 dnl These cflags add bunches of branches, and we haven't been able to
1410 dnl persuade ourselves that they're suitable for code that needs to be
1412 AC_SUBST(CFLAGS_BUGTRAP)
1413 dnl These cflags are variant ones suitable for code that needs to be
1415 AC_SUBST(CFLAGS_CONSTTIME)
1417 if test "x$enable_linker_hardening" != "xno"; then
1418 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1421 # For backtrace support
1422 TOR_CHECK_LDFLAGS(-rdynamic)
1424 dnl ------------------------------------------------------
1425 dnl Now see if we have a -fomit-frame-pointer compiler option.
1427 saved_CFLAGS="$CFLAGS"
1428 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1429 F_OMIT_FRAME_POINTER=''
1430 if test "$saved_CFLAGS" != "$CFLAGS"; then
1431 if test "$fragile_hardening" = "yes"; then
1432 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1435 CFLAGS="$saved_CFLAGS"
1436 AC_SUBST(F_OMIT_FRAME_POINTER)
1438 dnl ------------------------------------------------------
1439 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1440 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1441 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1443 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1445 dnl ============================================================
1446 dnl Check for libseccomp
1448 if test "x$enable_seccomp" != "xno"; then
1449 AC_CHECK_HEADERS([seccomp.h])
1450 AC_SEARCH_LIBS(seccomp_init, [seccomp])
1453 dnl ============================================================
1454 dnl Check for libscrypt
1456 if test "x$enable_libscrypt" != "xno"; then
1457 AC_CHECK_HEADERS([libscrypt.h])
1458 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1459 AC_CHECK_FUNCS([libscrypt_scrypt])
1462 dnl ============================================================
1463 dnl We need an implementation of curve25519.
1465 dnl set these defaults.
1466 build_curve25519_donna=no
1467 build_curve25519_donna_c64=no
1468 use_curve25519_donna=no
1469 use_curve25519_nacl=no
1472 dnl The best choice is using curve25519-donna-c64, but that requires
1474 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1475 tor_cv_can_use_curve25519_donna_c64,
1477 [AC_LANG_PROGRAM([dnl
1479 typedef unsigned uint128_t __attribute__((mode(TI)));
1480 int func(uint64_t a, uint64_t b) {
1481 uint128_t c = ((uint128_t)a) * b;
1482 int ok = ((uint64_t)(c>>96)) == 522859 &&
1483 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1484 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1485 (((uint64_t)(c))&0xffffffffL) == 0;
1489 int ok = func( ((uint64_t)2000000000) * 1000000000,
1490 ((uint64_t)1234567890) << 24);
1493 [tor_cv_can_use_curve25519_donna_c64=yes],
1494 [tor_cv_can_use_curve25519_donna_c64=no],
1496 [AC_LANG_PROGRAM([dnl
1498 typedef unsigned uint128_t __attribute__((mode(TI)));
1499 int func(uint64_t a, uint64_t b) {
1500 uint128_t c = ((uint128_t)a) * b;
1501 int ok = ((uint64_t)(c>>96)) == 522859 &&
1502 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1503 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1504 (((uint64_t)(c))&0xffffffffL) == 0;
1508 int ok = func( ((uint64_t)2000000000) * 1000000000,
1509 ((uint64_t)1234567890) << 24);
1512 [tor_cv_can_use_curve25519_donna_c64=cross],
1513 [tor_cv_can_use_curve25519_donna_c64=no])])])
1515 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1516 nacl/crypto_scalarmult_curve25519.h])
1518 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1519 tor_cv_can_use_curve25519_nacl,
1520 [tor_saved_LIBS="$LIBS"
1523 [AC_LANG_PROGRAM([dnl
1524 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1525 #include <crypto_scalarmult_curve25519.h>
1526 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1527 #include <nacl/crypto_scalarmult_curve25519.h>
1529 #ifdef crypto_scalarmult_curve25519_ref_BYTES
1530 #error Hey, this is the reference implementation! That's not fast.
1533 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1534 ])], [tor_cv_can_use_curve25519_nacl=yes],
1535 [tor_cv_can_use_curve25519_nacl=no])
1536 LIBS="$tor_saved_LIBS" ])
1538 dnl Okay, now we need to figure out which one to actually use. Fall back
1539 dnl to curve25519-donna.c
1541 if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1542 build_curve25519_donna_c64=yes
1543 use_curve25519_donna=yes
1544 elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1545 use_curve25519_nacl=yes
1546 CURVE25519_LIBS=-lnacl
1548 build_curve25519_donna=yes
1549 use_curve25519_donna=yes
1552 if test "x$use_curve25519_donna" = "xyes"; then
1553 AC_DEFINE(USE_CURVE25519_DONNA, 1,
1554 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1556 if test "x$use_curve25519_nacl" = "xyes"; then
1557 AC_DEFINE(USE_CURVE25519_NACL, 1,
1558 [Defined if we should use a curve25519 from nacl])
1560 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1561 test "x$build_curve25519_donna" = "xyes")
1562 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1563 test "x$build_curve25519_donna_c64" = "xyes")
1564 AC_SUBST(CURVE25519_LIBS)
1566 dnl Make sure to enable support for large off_t if available.
1569 AC_CHECK_HEADERS([errno.h \
1583 gnu/libc-version.h \
1621 AC_CHECK_HEADERS(sys/param.h)
1623 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1624 [#ifdef HAVE_SYS_TYPES_H
1625 #include <sys/types.h>
1627 #ifdef HAVE_SYS_SOCKET_H
1628 #include <sys/socket.h>
1630 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1631 [#ifdef HAVE_SYS_TYPES_H
1632 #include <sys/types.h>
1634 #ifdef HAVE_SYS_SOCKET_H
1635 #include <sys/socket.h>
1637 #ifdef HAVE_NET_IF_H
1640 #ifdef HAVE_NETINET_IN_H
1641 #include <netinet/in.h>
1644 AC_CHECK_HEADERS(linux/if.h,[],[],
1646 #ifdef HAVE_SYS_SOCKET_H
1647 #include <sys/socket.h>
1651 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1652 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1653 [#ifdef HAVE_SYS_TYPES_H
1654 #include <sys/types.h>
1656 #ifdef HAVE_SYS_SOCKET_H
1657 #include <sys/socket.h>
1659 #ifdef HAVE_LIMITS_H
1662 #ifdef HAVE_LINUX_TYPES_H
1663 #include <linux/types.h>
1665 #ifdef HAVE_NETINET_IN6_H
1666 #include <netinet/in6.h>
1668 #ifdef HAVE_NETINET_IN_H
1669 #include <netinet/in.h>
1672 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1673 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1674 [#ifdef HAVE_SYS_TYPES_H
1675 #include <sys/types.h>
1677 #ifdef HAVE_SYS_SOCKET_H
1678 #include <sys/socket.h>
1680 #ifdef HAVE_LIMITS_H
1683 #ifdef HAVE_LINUX_TYPES_H
1684 #include <linux/types.h>
1686 #ifdef HAVE_NETINET_IN6_H
1687 #include <netinet/in6.h>
1689 #ifdef HAVE_NETINET_IN_H
1690 #include <netinet/in.h>
1692 #ifdef HAVE_LINUX_IF_H
1693 #include <linux/if.h>
1697 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1700 if test "x$linux_netfilter_ipv4" = "x1"; then
1703 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1706 if test "x$transparent_ok" = "x1"; then
1707 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1709 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1712 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1713 [#ifdef HAVE_SYS_TYPES_H
1714 #include <sys/types.h>
1716 #ifdef HAVE_SYS_TIME_H
1717 #include <sys/time.h>
1720 AC_CHECK_SIZEOF(char)
1721 AC_CHECK_SIZEOF(short)
1722 AC_CHECK_SIZEOF(int)
1723 AC_CHECK_SIZEOF(unsigned int)
1724 AC_CHECK_SIZEOF(long)
1725 AC_CHECK_SIZEOF(long long)
1726 AC_CHECK_SIZEOF(__int64)
1727 AC_CHECK_SIZEOF(void *)
1728 AC_CHECK_SIZEOF(time_t)
1729 AC_CHECK_SIZEOF(size_t)
1730 AC_CHECK_SIZEOF(pid_t)
1732 AC_CHECK_TYPES([uint, u_char, ssize_t])
1734 AC_PC_FROM_UCONTEXT([:])
1736 dnl used to include sockaddr_storage, but everybody has that.
1737 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1738 [#ifdef HAVE_SYS_TYPES_H
1739 #include <sys/types.h>
1741 #ifdef HAVE_NETINET_IN_H
1742 #include <netinet/in.h>
1744 #ifdef HAVE_NETINET_IN6_H
1745 #include <netinet/in6.h>
1747 #ifdef HAVE_SYS_SOCKET_H
1748 #include <sys/socket.h>
1751 #define _WIN32_WINNT 0x0501
1752 #define WIN32_LEAN_AND_MEAN
1753 #include <winsock2.h>
1754 #include <ws2tcpip.h>
1757 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1758 [#ifdef HAVE_SYS_TYPES_H
1759 #include <sys/types.h>
1761 #ifdef HAVE_NETINET_IN_H
1762 #include <netinet/in.h>
1764 #ifdef HAVE_NETINET_IN6_H
1765 #include <netinet/in6.h>
1767 #ifdef HAVE_SYS_SOCKET_H
1768 #include <sys/socket.h>
1771 #define _WIN32_WINNT 0x0501
1772 #define WIN32_LEAN_AND_MEAN
1773 #include <winsock2.h>
1774 #include <ws2tcpip.h>
1778 AC_CHECK_TYPES([rlim_t], , ,
1779 [#ifdef HAVE_SYS_TYPES_H
1780 #include <sys/types.h>
1782 #ifdef HAVE_SYS_TIME_H
1783 #include <sys/time.h>
1785 #ifdef HAVE_SYS_RESOURCE_H
1786 #include <sys/resource.h>
1790 AX_CHECK_SIGN([time_t],
1793 #ifdef HAVE_SYS_TYPES_H
1794 #include <sys/types.h>
1796 #ifdef HAVE_SYS_TIME_H
1797 #include <sys/time.h>
1804 if test "$ax_cv_decl_time_t_signed" = "no"; then
1805 AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1808 AX_CHECK_SIGN([size_t],
1809 [ tor_cv_size_t_signed=yes ],
1810 [ tor_cv_size_t_signed=no ], [
1811 #ifdef HAVE_SYS_TYPES_H
1812 #include <sys/types.h>
1816 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1817 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1820 AX_CHECK_SIGN([enum always],
1821 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1823 enum always { AAA, BBB, CCC };
1826 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1827 #ifdef HAVE_SYS_SOCKET_H
1828 #include <sys/socket.h>
1832 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1834 AC_CHECK_SIZEOF(cell_t)
1836 # Let's see if stdatomic works. (There are some debian clangs that screw it
1837 # up; see Tor bug #26779 and debian bug 903709.)
1838 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1839 tor_cv_stdatomic_works,
1840 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1841 #include <stdatomic.h>
1842 struct x { atomic_size_t y; };
1843 void try_atomic_init(struct x *xx)
1845 atomic_init(&xx->y, 99);
1846 atomic_fetch_add(&xx->y, 1);
1848 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1850 if test "$tor_cv_stdatomic_works" = "yes"; then
1851 AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1852 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1854 AC_MSG_WARN([Your compiler provides the stdatomic.h header, but it doesn't seem to work. I'll pretend it isn't there. If you are using Clang on Debian, maybe this is because of https://bugs.debian.org/903709 ])
1857 # Now make sure that NULL can be represented as zero bytes.
1858 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1859 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1860 [[#include <stdlib.h>
1863 #ifdef HAVE_STDDEF_H
1866 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1867 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1868 [tor_cv_null_is_zero=yes],
1869 [tor_cv_null_is_zero=no],
1870 [tor_cv_null_is_zero=cross])])
1872 if test "$tor_cv_null_is_zero" = "cross"; then
1873 # Cross-compiling; let's hope that the target isn't raving mad.
1874 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1877 if test "$tor_cv_null_is_zero" != "no"; then
1878 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1879 [Define to 1 iff memset(0) sets pointers to NULL])
1882 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1883 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1884 [[#include <stdlib.h>
1887 #ifdef HAVE_STDDEF_H
1890 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1891 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1892 [tor_cv_dbl0_is_zero=yes],
1893 [tor_cv_dbl0_is_zero=no],
1894 [tor_cv_dbl0_is_zero=cross])])
1896 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1897 # Cross-compiling; let's hope that the target isn't raving mad.
1898 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1901 if test "$tor_cv_dbl0_is_zero" != "no"; then
1902 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1903 [Define to 1 iff memset(0) sets doubles to 0.0])
1906 # And what happens when we malloc zero?
1907 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1908 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1909 [[#include <stdlib.h>
1912 #ifdef HAVE_STDDEF_H
1915 int main () { return malloc(0)?0:1; }]])],
1916 [tor_cv_malloc_zero_works=yes],
1917 [tor_cv_malloc_zero_works=no],
1918 [tor_cv_malloc_zero_works=cross])])
1920 if test "$tor_cv_malloc_zero_works" = "cross"; then
1921 # Cross-compiling; let's hope that the target isn't raving mad.
1922 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1925 if test "$tor_cv_malloc_zero_works" = "yes"; then
1926 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1927 [Define to 1 iff malloc(0) returns a pointer])
1930 # whether we seem to be in a 2s-complement world.
1931 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1932 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1933 [[int main () { int problem = ((-99) != (~99)+1);
1934 return problem ? 1 : 0; }]])],
1935 [tor_cv_twos_complement=yes],
1936 [tor_cv_twos_complement=no],
1937 [tor_cv_twos_complement=cross])])
1939 if test "$tor_cv_twos_complement" = "cross"; then
1940 # Cross-compiling; let's hope that the target isn't raving mad.
1941 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1944 if test "$tor_cv_twos_complement" != "no"; then
1945 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1946 [Define to 1 iff we represent negative integers with
1950 # What does shifting a negative value do?
1951 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1952 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1953 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1954 [tor_cv_sign_extend=yes],
1955 [tor_cv_sign_extend=no],
1956 [tor_cv_sign_extend=cross])])
1958 if test "$tor_cv_sign_extend" = "cross"; then
1959 # Cross-compiling; let's hope that the target isn't raving mad.
1960 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1963 if test "$tor_cv_sign_extend" != "no"; then
1964 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1965 [Define to 1 iff right-shifting a negative value performs sign-extension])
1968 # Is uint8_t the same type as unsigned char?
1969 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1970 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1973 unsigned char c;]])],
1974 [tor_cv_uint8_uchar=yes],
1975 [tor_cv_uint8_uchar=no],
1976 [tor_cv_uint8_uchar=cross])])
1978 if test "$tor_cv_uint8_uchar" = "cross"; then
1979 AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1982 if test "$tor_cv_uint8_uchar" = "no"; then
1983 AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1986 AC_ARG_WITH(tcmalloc,
1987 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
1989 default_malloc=system
1991 if test "x$enable_openbsd_malloc" = "xyes" ; then
1992 AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
1993 default_malloc=openbsd
1996 if test "x$with_tcmalloc" = "xyes"; then
1997 AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
1998 default_malloc=tcmalloc
2002 AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
2003 [select special malloc implementation [system]]),
2004 [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
2008 PKG_CHECK_MODULES([TCMALLOC],
2013 if test "x$have_tcmalloc" = "xno" ; then
2014 AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
2017 CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
2018 LIBS="$TCMALLOC_LIBS $LIBS"
2022 PKG_CHECK_MODULES([JEMALLOC],
2027 if test "x$have_jemalloc" = "xno" ; then
2028 AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
2031 CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
2032 LIBS="$JEMALLOC_LIBS $LIBS"
2033 using_custom_malloc=yes
2038 AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
2039 enable_openbsd_malloc=yes
2043 # handle this later, including the jemalloc fallback
2046 [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
2049 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
2051 if test "$malloc" != "system"; then
2052 # Tell the C compiler not to use the system allocator functions.
2053 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2055 if test "$using_custom_malloc" = "yes"; then
2056 # Tell the C compiler not to use the system allocator functions.
2057 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2060 # By default, we're going to assume we don't have mlockall()
2061 # bionic and other platforms have various broken mlockall subsystems.
2062 # Some systems don't have a working mlockall, some aren't linkable,
2063 # and some have it but don't declare it.
2064 AC_CHECK_FUNCS(mlockall)
2065 AC_CHECK_DECLS([mlockall], , , [
2066 #ifdef HAVE_SYS_MMAN_H
2067 #include <sys/mman.h>
2070 # Allow user to specify an alternate syslog facility
2071 AC_ARG_WITH(syslog-facility,
2072 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
2073 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
2074 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
2075 AC_SUBST(LOGFACILITY)
2077 # Check if we have getresuid and getresgid
2078 AC_CHECK_FUNCS(getresuid getresgid)
2080 # Check for gethostbyname_r in all its glorious incompatible versions.
2081 # (This logic is based on that in Python's configure.in)
2082 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
2083 [Define this if you have any gethostbyname_r()])
2085 AC_CHECK_FUNC(gethostbyname_r, [
2086 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
2088 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
2089 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2093 struct hostent *h1, *h2;
2095 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2097 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2098 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2099 [Define this if gethostbyname_r takes 6 arguments])
2102 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2108 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2110 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2111 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2112 [Define this if gethostbyname_r takes 5 arguments])
2115 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2120 struct hostent_data hd;
2121 (void) gethostbyname_r(cp1,h1,&hd);
2123 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2124 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2125 [Define this if gethostbyname_r takes 3 arguments])
2135 AC_CACHE_CHECK([whether the C compiler supports __func__],
2136 tor_cv_have_func_macro,
2137 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2139 int main(int c, char **v) { puts(__func__); }])],
2140 tor_cv_have_func_macro=yes,
2141 tor_cv_have_func_macro=no))
2143 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2144 tor_cv_have_FUNC_macro,
2145 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2147 int main(int c, char **v) { puts(__FUNC__); }])],
2148 tor_cv_have_FUNC_macro=yes,
2149 tor_cv_have_FUNC_macro=no))
2151 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2152 tor_cv_have_FUNCTION_macro,
2153 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2155 int main(int c, char **v) { puts(__FUNCTION__); }])],
2156 tor_cv_have_FUNCTION_macro=yes,
2157 tor_cv_have_FUNCTION_macro=no))
2159 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2160 tor_cv_have_environ_declared,
2161 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2162 #ifdef HAVE_UNISTD_H
2166 int main(int c, char **v) { char **t = environ; }])],
2167 tor_cv_have_environ_declared=yes,
2168 tor_cv_have_environ_declared=no))
2170 if test "$tor_cv_have_func_macro" = "yes"; then
2171 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2174 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2175 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2178 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2179 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2180 [Defined if the compiler supports __FUNCTION__])
2183 if test "$tor_cv_have_environ_declared" = "yes"; then
2184 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2185 [Defined if we have extern char **environ already declared])
2188 # $prefix stores the value of the --prefix command line option, or
2189 # NONE if the option wasn't set. In the case that it wasn't set, make
2190 # it be the default, so that we can use it to expand directories now.
2191 if test "x$prefix" = "xNONE"; then
2192 prefix=$ac_default_prefix
2195 # and similarly for $exec_prefix
2196 if test "x$exec_prefix" = "xNONE"; then
2200 if test "x$BUILDDIR" = "x"; then
2204 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2205 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2207 if test "x$SRCDIR" = "x"; then
2208 SRCDIR=$(cd "$srcdir"; pwd)
2210 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2211 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2213 if test "x$CONFDIR" = "x"; then
2214 CONFDIR=`eval echo $sysconfdir/tor`
2217 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2218 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2220 BINDIR=`eval echo $bindir`
2222 LOCALSTATEDIR=`eval echo $localstatedir`
2223 AC_SUBST(LOCALSTATEDIR)
2225 if test "$bwin32" = "true"; then
2226 # Test if the linker supports the --nxcompat and --dynamicbase options
2228 save_LDFLAGS="$LDFLAGS"
2229 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2230 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2231 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2232 [AC_MSG_RESULT([yes])]
2233 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2234 [AC_MSG_RESULT([no])]
2236 LDFLAGS="$save_LDFLAGS"
2239 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2240 # than autoconf's macros like.
2241 if test "$GCC" = "yes"; then
2242 # Disable GCC's strict aliasing checks. They are an hours-to-debug
2243 # accident waiting to happen.
2244 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2246 # Override optimization level for non-gcc compilers
2248 enable_gcc_warnings=no
2249 enable_gcc_warnings_advisory=no
2252 # Warnings implies advisory-warnings and -Werror.
2253 if test "$enable_gcc_warnings" = "yes"; then
2254 enable_gcc_warnings_advisory=yes
2255 enable_fatal_warnings=yes
2258 # OS X Lion started deprecating the system openssl. Let's just disable
2259 # all deprecation warnings on OS X. Also, to potentially make the binary
2260 # a little smaller, let's enable dead_strip.
2264 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2265 LDFLAGS="$LDFLAGS -dead_strip" ;;
2268 TOR_WARNING_FLAGS=""
2270 # Add some more warnings which we use in development but not in the
2271 # released versions. (Some relevant gcc versions can't handle these.)
2273 # Note that we have to do this near the end of the autoconf process, or
2274 # else we may run into problems when these warnings hit on the testing C
2275 # programs that autoconf wants to build.
2276 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2279 *-*-openbsd* | *-*-bitrig*)
2280 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2281 # That's fine, except that the headers don't pass -Wredundant-decls.
2282 # Therefore, let's disable -Wsystem-headers when we're building
2283 # with maximal warnings on OpenBSD.
2284 CFLAGS="$CFLAGS -Wno-system-headers" ;;
2287 CFLAGS_NOWARNINGS="$CFLAGS"
2289 # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
2290 # have it work better.
2291 # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2293 # This warning was added in gcc 4.3, but it appears to generate
2294 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
2295 #CFLAGS="$CFLAGS -Wlogical-op"
2297 m4_foreach_w([warning_flag], [
2299 -Waddress-of-array-temporary
2300 -Waddress-of-temporary
2302 -Wanonymous-pack-parens
2305 -Warc-bridge-casts-disallowed-in-nonarc
2306 -Warc-maybe-repeated-use-of-weak
2307 -Warc-performSelector-leaks
2308 -Warc-repeated-use-of-weak
2310 -Warray-bounds-pointer-arithmetic
2312 -Wasm-operand-widths
2314 -Watomic-property-with-user-defined-accessor
2316 -Wauto-storage-class
2319 -Wbackslash-newline-escape
2320 -Wbad-array-new-length
2321 -Wbind-to-temporary-copy
2322 -Wbitfield-constant-conversion
2325 -Wbuiltin-requires-header
2327 -Wcompare-distinct-pointer-types
2328 -Wcomplex-component-init
2329 -Wconditional-type-mismatch
2331 -Wconstant-conversion
2332 -Wconstant-logical-operand
2333 -Wconstexpr-not-const
2334 -Wcustom-atomic-properties
2336 -Wdangling-initializer-list
2338 -Wdelegating-ctor-cycles
2339 -Wdeprecated-implementations
2340 -Wdeprecated-register
2341 -Wdirect-ivar-access
2343 -Wdistributed-object-modifiers
2345 -Wdollar-in-identifier-extension
2347 -Wduplicate-decl-specifier
2349 -Wduplicate-method-arg
2350 -Wduplicate-method-match
2352 -Wdynamic-class-memaccess
2353 -Wembedded-directive
2354 -Wempty-translation-unit
2356 -Wexit-time-destructors
2357 -Wexplicit-ownership-type
2358 -Wextern-initializer
2362 -Wflexible-array-extensions
2365 -Wfour-char-constants
2367 -Wglobal-constructors
2368 -Wgnu-array-member-paren-init
2370 -Wgnu-static-float-init
2373 -Widiomatic-parentheses
2374 -Wignored-attributes
2375 -Wimplicit-atomic-properties
2376 -Wimplicit-conversion-floating-point-to-bool
2377 -Wimplicit-exception-spec-mismatch
2378 -Wimplicit-fallthrough
2379 -Wimplicit-fallthrough-per-function
2380 -Wimplicit-retain-self
2381 -Wimport-preprocessor-directive-pedantic
2382 -Wincompatible-library-redeclaration
2383 -Wincompatible-pointer-types-discards-qualifiers
2384 -Wincomplete-implementation
2386 -Wincomplete-umbrella
2389 -Wint-to-void-pointer-cast
2395 -Winvalid-source-encoding
2396 -Winvalid-token-paste
2397 -Wknr-promoted-parameter
2398 -Wlarge-by-value-copy
2399 -Wliteral-conversion
2401 -Wlocal-type-template-args
2405 -Wmalformed-warning-check
2409 -Wmismatched-parameter-types
2410 -Wmismatched-return-types
2411 -Wmissing-field-initializers
2412 -Wmissing-format-attribute
2414 -Wmissing-selector-name
2416 -Wmissing-variable-declarations
2420 -Wnon-literal-null-conversion
2422 -Wnonportable-cfstrings
2428 -Wout-of-line-declaration
2430 -Woverlength-strings
2432 -Woverriding-method-mismatch
2433 -Wpointer-type-mismatch
2434 -Wpredefined-identifier-outside-function
2435 -Wprotocol-property-synthesis-ambiguity
2436 -Wreadonly-iboutlet-property
2437 -Wreadonly-setter-attrs
2439 -Wreceiver-forward-class
2441 -Wreinterpret-base-class
2442 -Wrequires-super-attribute
2443 -Wreserved-user-defined-literal
2444 -Wreturn-stack-address
2446 -Wselector-type-mismatch
2448 -Wserialized-diagnostics
2450 -Wshift-count-negative
2451 -Wshift-count-overflow
2452 -Wshift-negative-value
2454 -Wshift-sign-overflow
2456 -Wsizeof-array-argument
2457 -Wsource-uses-openmp
2460 -Wstatic-local-in-inline
2464 -Wstrlcpy-strlcat-size
2466 -Wsuggest-attribute=format
2467 -Wsuggest-attribute=noreturn
2468 -Wsuper-class-method-mismatch
2471 -Wtautological-constant-out-of-range-compare
2472 -Wtentative-definition-incomplete-type
2475 -Wtypedef-redefinition
2478 -Wundefined-internal
2479 -Wundefined-reinterpret-cast
2481 -Wunicode-whitespace
2482 -Wunknown-warning-option
2483 -Wunnamed-type-template-args
2484 -Wunneeded-member-function
2486 -Wunsupported-visibility
2487 -Wunused-but-set-parameter
2488 -Wunused-but-set-variable
2489 -Wunused-command-line-argument
2490 -Wunused-const-variable=2
2491 -Wunused-exception-parameter
2492 -Wunused-local-typedefs
2493 -Wunused-member-function
2494 -Wunused-sanitize-argument
2495 -Wunused-volatile-lvalue
2496 -Wuser-defined-literals
2499 -Wvector-conversions
2504 ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2505 [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2508 dnl We should re-enable this in some later version. Clang doesn't
2509 dnl mind, but it causes trouble with GCC.
2510 dnl -Wstrict-overflow=2
2512 dnl These seem to require annotations that we don't currently use,
2513 dnl and they give false positives in our pthreads wrappers. (Clang 4)
2515 dnl -Wthread-safety-analysis
2516 dnl -Wthread-safety-attributes
2517 dnl -Wthread-safety-beta
2518 dnl -Wthread-safety-precise
2520 W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2521 W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2522 W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2523 W_FLAGS="$W_FLAGS -Wwrite-strings"
2524 W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2525 W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2526 W_FLAGS="$W_FLAGS -Wunused-parameter "
2527 # These interfere with building main() { return 0; }, which autoconf
2528 # likes to use as its default program.
2529 W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2531 TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2532 CFLAGS="$CFLAGS $W_FLAGS"
2534 if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2535 AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2537 if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2538 AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2540 if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2541 AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2544 CFLAGS="$CFLAGS_NOWARNINGS"
2546 if test "x$enable_fatal_warnings" = "xyes"; then
2547 # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2548 # default autoconf programs are full of errors.
2549 CFLAGS="$CFLAGS -Werror"
2554 AC_SUBST(TOR_WARNING_FLAGS)
2556 echo "$TOR_WARNING_FLAGS">warning_flags
2558 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2559 CFLAGS="$CFLAGS @warning_flags",
2560 CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2562 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2566 AC_MSG_WARN([Tried to enable coverage on OSX without using the clang compiler. This might not work! If coverage fails, use CC=clang when configuring with --enable-coverage.])
2570 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2575 contrib/operator-tools/tor.logrotate
2576 src/config/torrc.sample
2577 src/config/torrc.minimal
2578 scripts/maint/checkOptionDocs.pl
2582 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2583 regular_mans="doc/man/tor doc/man/tor-gencert doc/man/tor-resolve doc/man/torify"
2584 for file in $regular_mans ; do
2585 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2586 echo "==================================";
2588 echo "Building Tor has failed since manpages cannot be built.";
2590 echo "You need asciidoc installed to be able to build the manpages.";
2591 echo "To build without manpages, use the --disable-asciidoc argument";
2592 echo "when calling configure.";
2594 echo "==================================";
2600 if test "$fragile_hardening" = "yes"; then
2605 Warning! Building Tor with --enable-fragile-hardening (also known as
2606 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2607 other kinds of attacks easier. A Tor instance build with this option will be
2608 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2609 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2610 denial of service attacks. For more information, see
2611 https://gitlab.torproject.org/tpo/core/team/-/wikis/TorFragileHardening
2618 if test "$openssl_ver_mismatch" = "yes"; then
2622 Warning! The version OpenSSL headers we get from compiling with
2623 "${TOR_CPPFLAGS_OPENSSL:-(no extra options)}"
2624 do not match version of the OpenSSL library we get when linking with
2625 "$TOR_LDFLAGS_OPENSSL $TOR_OPENSSL_LIBS".
2626 This might cause compilation to fail. Try using --with-openssl-dir to specify
2627 the exact OpenSSL path you want.
2633 # Mini-report on what will be built.
2637 PPRINT_SET_INDENT(1)
2641 AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
2644 PPRINT_SUBTITLE([Build Features])
2646 PPRINT_PROP_STRING([Compiler], [$CC])
2647 PPRINT_PROP_STRING([Host OS], [$host_os])
2650 test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
2651 PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
2653 test "x$enable_android" = "xyes" && value=1 || value=0
2654 PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
2657 PPRINT_SUBTITLE([Static Build])
2659 test "x$enable_static_tor" = "xyes" && value=1 || value=0
2660 PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
2662 if test "x$enable_static_libevent" = "xyes"; then
2663 PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
2665 PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
2668 if test "x$enable_static_openssl" = "xyes"; then
2669 PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
2671 PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
2674 if test "x$enable_static_zlib" = "xyes"; then
2675 PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
2677 PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
2681 PPRINT_SUBTITLE([Optional Libraries])
2683 test "x$enable_nss" = "xyes" && value=1 || value=0
2684 PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
2686 test "x$enable_seccomp" != "xno" && value=1 || value=0
2687 PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
2689 test "x$enable_libscrypt" != "xno" && value=1 || value=0
2690 PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
2692 test "x$enable_systemd" = "xyes" && value=1 || value=0
2693 PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
2695 test "x$have_lzma" = "xyes" && value=1 || value=0
2696 PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
2698 test "x$have_zstd" = "xyes" && value=1 || value=0
2699 PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
2702 PPRINT_SUBTITLE([Hardening])
2704 test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
2705 PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
2707 test "x$enable_linker_hardening" != "xno" && value=1 || value=0
2708 PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
2710 test "x$fragile_hardening" = "xyes" && value=1 || value=0
2711 PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
2714 PPRINT_SUBTITLE([Modules])
2716 m4_foreach_w([mname], MODULES,
2718 AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
2719 m4_set_contains([MODULES_WITH_NO_OPTIONS], mname,
2720 PPRINT_PROP_BOOL([mname], $value),
2721 PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value))
2726 PPRINT_SUBTITLE([Documentation])
2728 test "x$enable_asciidoc" != "xno" && value=1 || value=0
2729 PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
2731 test "x$enable_manpage" != "xno" && value=1 || value=0
2732 PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
2734 test "x$enable_html_manual" != "xno" && value=1 || value=0
2735 PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
2738 PPRINT_SUBTITLE([Tests])
2740 test "x$enable_unittests" != "xno" && value=1 || value=0
2741 PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
2743 test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
2744 PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
2746 test "x$enable_coverage" = "xyes" && value=1 || value=0
2747 PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
2749 test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
2750 PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
2752 test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
2753 PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
2756 PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
2758 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
2759 PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
2761 test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
2762 PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
2764 test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
2765 PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
2768 PPRINT_SUBTITLE([Install Directories])
2770 report_mandir="`eval eval echo $mandir`"
2771 PPRINT_PROP_STRING([Binaries], [$BINDIR])
2772 PPRINT_PROP_STRING([Configuration], [$CONFDIR])
2773 PPRINT_PROP_STRING([Man Pages], [$report_mandir])
2776 AS_ECHO(["Configure Line: ./configure $configure_flags"])
2778 if test "$tor_ac_n_warnings" != "0"; then
2781 Encountered $tor_ac_n_warnings warning(s). See messages above for more info.