metrics: Add a reset store helper function
[tor.git] / configure.ac
blob912c2f2dfe0328c1a0bac13b949b885e322a4a9a
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
6 AC_PREREQ([2.63])
7 AC_INIT([tor],[0.4.7.0-alpha-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
11 configure_flags="$*"
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, ["2021-04-15"], # for 0.4.7.0-alpha-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])
29 tor_ac_n_warnings=0
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
38 AC_CANONICAL_HOST
40 PKG_PROG_PKG_CONFIG
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.])
45 else
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(rust,
79    AS_HELP_STRING(--enable-rust, [enable rust integration]))
80 AC_ARG_ENABLE(cargo-online-mode,
81    AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
82 AC_ARG_ENABLE(restart-debugging,
83    AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
84 AC_ARG_ENABLE(zstd-advanced-apis,
85    AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
86 AC_ARG_ENABLE(nss,
87    AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
88 AC_ARG_ENABLE(pic,
89    AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
91 AC_ARG_ENABLE(missing-doc-warnings,
92    AS_HELP_STRING(--enable-missing-doc-warnings, [Tell doxygen to warn about missing documentation. Makes doxygen warnings nonfatal.]))
94 if test "$enable_missing_doc_warnings" = "yes"; then
95    DOXYGEN_FATAL_WARNINGS=NO
96    DOXYGEN_WARN_ON_MISSING=YES
97 elif test "$enable_fatal_warnings" = "yes"; then
98    # Fatal warnings from doxygen are nice, but not if we're warning about
99    # missing documentation.
100    DOXYGEN_FATAL_WARNINGS=YES
101    DOXYGEN_WARN_ON_MISSING=NO
102 else
103    DOXYGEN_FATAL_WARNINGS=NO
104    DOXYGEN_WARN_ON_MISSING=NO
106 AC_SUBST(DOXYGEN_FATAL_WARNINGS)
107 AC_SUBST(DOXYGEN_WARN_ON_MISSING)
109 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
110     AC_MSG_ERROR([Can't disable assertions outside of coverage build])
113 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
114 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
115 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
116 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
117 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
118 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
119 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
120 AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
122 if test "x$enable_nss" = "xyes"; then
123   AC_DEFINE(ENABLE_NSS, 1,
124             [Defined if we're building with NSS.])
125 else
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.])
181 # systemd support
182 if test "x$enable_systemd" = "xno"; then
183     have_systemd=no;
184 else
185     PKG_CHECK_MODULES(SYSTEMD,
186         [libsystemd-daemon],
187         have_systemd=yes,
188         have_systemd=no)
189     if test "x$have_systemd" = "xno"; then
190         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
191         PKG_CHECK_MODULES(SYSTEMD,
192             [libsystemd],
193             have_systemd=yes,
194             have_systemd=no)
195     fi
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.])
212 case "$host" in
213    *-*-solaris* )
214      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
215      ;;
216 esac
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(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
239 AC_ARG_ENABLE(all-bugs-are-fatal,
240    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]))
242 if test "x$enable_all_bugs_are_fatal" = "xyes"; then
243   AC_DEFINE(ALL_BUGS_ARE_FATAL, 1, [All assert failures are fatal])
246 dnl Linker hardening options
247 dnl Currently these options are ELF specific - you can't use this with MacOSX
248 AC_ARG_ENABLE(linker-hardening,
249     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
251 AC_ARG_ENABLE(local-appdata,
252    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
253 if test "$enable_local_appdata" = "yes"; then
254   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
255             [Defined if we default to host local appdata paths on Windows])
258 AC_ARG_ENABLE(tool-name-check,
259      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
261 AC_ARG_ENABLE(seccomp,
262      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
264 AC_ARG_ENABLE(libscrypt,
265      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
267 dnl --- Tracing Options. ---
269 TOR_TRACE_LIBS=
271 dnl LTTng instrumentation option.
272 AC_ARG_ENABLE(tracing-instrumentation-lttng,
273               AS_HELP_STRING([--enable-tracing-instrumentation-lttng],
274                              [build with LTTng-UST instrumentation]))
275 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LTTNG],
276                [test "x$enable_tracing_instrumentation_lttng" = "xyes"])
278 if test "x$enable_tracing_instrumentation_lttng" = "xyes"; then
279   AC_CHECK_HEADERS([lttng/tracepoint.h], [],
280                    [AC_MSG_ERROR([LTTng instrumentation headers not found.
281                                   On Debian, apt install liblttng-ust-dev"])], [])
282   AC_DEFINE([USE_TRACING_INSTRUMENTATION_LTTNG], [1], [Using LTTng instrumentation])
283   TOR_TRACE_LIBS="-llttng-ust -ldl"
284   have_tracing=1
287 dnl USDT instrumentation option.
288 AC_ARG_ENABLE(tracing-instrumentation-usdt,
289               AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
290                              [build with tracing USDT instrumentation]))
291 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
292                [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
294 if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
295   AC_CHECK_HEADERS([sys/sdt.h], [],
296                    [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
297                                   On Debian, apt install systemtap-sdt-dev])], [])
298   AC_MSG_CHECKING([STAP_PROBEV()])
299   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
300     #define SDT_USE_VARIADIC
301     #include <sys/sdt.h>
302     void test(void)
303     {
304       STAP_PROBEV(p, n, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
305     }
306   ]])], [
307     AC_MSG_RESULT([yes])
308     dnl LTTng generates USDT probes if the UST library was built with
309     dnl --with-sdt. There is unfortunately no way to check that so we always
310     dnl build the USDT probes even though LTTng instrumentation was requested.
311     AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
312     have_tracing=1
313   ], [
314     AC_MSG_RESULT([no])
315     AC_MSG_ERROR([USDT tracing support requires STAP_PROBEV()])
316   ])
319 dnl Tracepoints event to debug logs.
320 AC_ARG_ENABLE(tracing-instrumentation-log-debug,
321      AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
322                     [build with tracing event to debug log]),
323      AC_DEFINE([USE_TRACING_INSTRUMENTATION_LOG_DEBUG], [1],
324                [Tracepoints to log debug]), [])
325 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
326                [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
327 if test "x$enable_tracing_instrumentation_log_debug" = "xyes"; then
328   have_tracing=1
331 dnl Define that tracing is supported if any instrumentation is used.
332 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
333            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
334 AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
335            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
336 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LTTNG],
337            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
338 AM_CONDITIONAL([USE_TRACING], [test "x$have_tracing" = x1 ])
340 dnl Finally, define the trace libs.
341 AC_SUBST([TOR_TRACE_LIBS])
343 dnl -- End Tracing Options. --
345 dnl Enable Android only features.
346 AC_ARG_ENABLE(android,
347      AS_HELP_STRING(--enable-android, [build with Android features enabled]))
348 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
350 if test "x$enable_android" = "xyes"; then
351   AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
355 dnl ---
356 dnl Tor modules options. These options are namespaced with --disable-module-XXX
357 dnl ---
359 dnl All our modules.
360 m4_define(MODULES, relay dirauth dircache)
362 # Some modules are only disabled through another option. For those, we don't
363 # want to print the help in the summary at the end of the configure. Any entry
364 # in the following set will not print the "--disable-module-NAME" command in
365 # the summary.
366 m4_set_add_all([MODULES_WITH_NO_OPTIONS], [dircache])
368 dnl Relay module.
369 AC_ARG_ENABLE([module-relay],
370               AS_HELP_STRING([--disable-module-relay],
371                              [Build tor without the Relay modules: tor can not run as a relay, bridge, or authority. Implies --disable-module-dirauth]))
372 AM_CONDITIONAL(BUILD_MODULE_RELAY, [test "x$enable_module_relay" != "xno"])
373 AM_COND_IF(BUILD_MODULE_RELAY,
374            AC_DEFINE([HAVE_MODULE_RELAY], [1],
375                      [Compile with Relay feature support]))
377 dnl Dircache module.  (This cannot be enabled or disabled independently of
378 dnl the relay module.  It is not listed by --list-modules for this reason.)
379 AM_CONDITIONAL(BUILD_MODULE_DIRCACHE,
380                [test "x$enable_module_relay" != "xno"])
381 AM_COND_IF(BUILD_MODULE_DIRCACHE,
382            AC_DEFINE([HAVE_MODULE_DIRCACHE], [1],
383                      [Compile with directory cache support]))
385 dnl Directory Authority module.
386 AC_ARG_ENABLE([module-dirauth],
387               AS_HELP_STRING([--disable-module-dirauth],
388                              [Build tor without the Directory Authority module: tor can not run as a directory authority or bridge authority]))
389 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH,[test "x$enable_module_dirauth" != "xno" && test "x$enable_module_relay" != "xno"])
390 AM_COND_IF(BUILD_MODULE_DIRAUTH,
391            AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
392                      [Compile with Directory Authority feature support]))
394 dnl Helper variables.
395 TOR_MODULES_ALL_ENABLED=
396 AC_DEFUN([ADD_MODULE], [
397     MODULE=m4_toupper($1)
398     TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
400 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
401 AC_SUBST(TOR_MODULES_ALL_ENABLED)
403 dnl check for the correct "ar" when cross-compiling.
404 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
405 dnl    so kludge up a replacement for the case where it isn't there yet.)
406 m4_ifdef([AM_PROG_AR],
407          [AM_PROG_AR],
408          [AN_MAKEVAR([AR], [AC_PROG_AR])
409           AN_PROGRAM([ar], [AC_PROG_AR])
410           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
411           AC_PROG_AR])
413 dnl Check whether the above macro has settled for a simply named tool even
414 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
415 dnl because that will find any cc on the system, not only the cross-compiler,
416 dnl and then verify that a binary built with this compiler runs on the
417 dnl build system. It will then come to the false conclusion that we're not
418 dnl cross-compiling.
419 if test "x$enable_tool_name_check" != "xno"; then
420     if test "x$ac_tool_warned" = "xyes"; then
421         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.)])
422         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
423                 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.)])
424         fi
427 AC_PROG_CC
428 AC_PROG_CPP
429 AC_PROG_MAKE_SET
430 AC_PROG_RANLIB
431 AC_PROG_SED
433 AX_COMPILER_VERSION
434 AX_COMPILER_VENDOR
436 AC_DEFINE_UNQUOTED([COMPILER_VERSION],["$ax_cv_c_compiler_version"], [Compiler version])
437 AC_DEFINE_UNQUOTED([COMPILER_VENDOR],["$ax_cv_c_compiler_vendor"], [Compiler vendor])
439 AS_CASE($ax_cv_c_compiler_vendor,
440         [gnu], AC_DEFINE([COMPILER],["GCC"],[Compiler name]),
441         AC_DEFINE([COMPILER],[],[Compiler name])
444 AC_ARG_VAR([PERL], [path to Perl binary])
445 AC_CHECK_PROGS([PERL], [perl])
446 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
448 dnl check for asciidoc and a2x
449 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
450 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
452 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
453 AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
454 AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
456 AM_PROG_CC_C_O
458 dnl Before autoconf 2.70, AC_PROG_CC_C99 is supposedly necessary for some
459 dnl compilers if you wan't C99 support. Starting with 2.70, it is obsolete and
460 dnl forbidden.
461 m4_version_prereq([2.70], [:], [AC_PROG_CC_C99])
463 AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
464    [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
465         python3 \
466         python3.8 python3.7 python3.6 python3.5 python3.4 \
467         python ],
468    [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
469 AC_SUBST([PYTHON], [$tor_cv_PYTHON])
471 PYTHON="$tor_cv_PYTHON"
473 if test "x$PYTHON" = "x"; then
474   tor_incr_n_warnings
475   AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
478 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
480 dnl List all external rust crates we depend on here. Include the version
481 rust_crates=" \
482     digest-0.7.2 \
483     libc-0.2.39 \
485 AC_SUBST(rust_crates)
487 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
488 AC_C_FLEXIBLE_ARRAY_MEMBER
489 ], [
490  dnl Maybe we've got an old autoconf...
491  AC_CACHE_CHECK([for flexible array members],
492      tor_cv_c_flexarray,
493      [AC_COMPILE_IFELSE(
494        AC_LANG_PROGRAM([
495  struct abc { int a; char b[]; };
496 ], [
497  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
498  def->b[0] = 33;
500   [tor_cv_c_flexarray=yes],
501   [tor_cv_c_flexarray=no])])
502  if test "$tor_cv_flexarray" = "yes"; then
503    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
504  else
505    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
506  fi
509 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
510       tor_cv_c_c99_decl,
511       [AC_COMPILE_IFELSE(
512          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
513          [tor_cv_c_c99_decl=yes],
514          [tor_cv_c_c99_decl=no] )])
515 if test "$tor_cv_c_c99_decl" != "yes"; then
516   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
519 AC_CACHE_CHECK([for working C99 designated initializers],
520       tor_cv_c_c99_designated_init,
521       [AC_COMPILE_IFELSE(
522          [AC_LANG_PROGRAM([struct s { int a; int b; };],
523                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
524          [tor_cv_c_c99_designated_init=yes],
525          [tor_cv_c_c99_designated_init=no] )])
527 if test "$tor_cv_c_c99_designated_init" != "yes"; then
528   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
531 saved_CFLAGS="$CFLAGS"
532 CFLAGS="$CFLAGS -Werror"
533 AC_CACHE_CHECK([for __attribute__((fallthrough))],
534       tor_cv_c_attr_fallthrough,
535       [AC_COMPILE_IFELSE(
536          [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
537                [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
538                                case 2: fn(); break; } ]])],
539          [tor_cv_c_attr_fallthrough=yes],
540          [tor_cv_c_attr_fallthrough=no] )])
541 CFLAGS="$saved_CFLAGS"
543 if test "$tor_cv_c_attr_fallthrough" = "yes"; then
544   AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
547 TORUSER=_tor
548 AC_ARG_WITH(tor-user,
549         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
550         [
551            TORUSER=$withval
552         ]
554 AC_SUBST(TORUSER)
556 TORGROUP=_tor
557 AC_ARG_WITH(tor-group,
558         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
559         [
560            TORGROUP=$withval
561         ]
563 AC_SUBST(TORGROUP)
566 dnl If _WIN32 is defined and non-zero, we are building for win32
567 AC_MSG_CHECKING([for win32])
568 AC_RUN_IFELSE([AC_LANG_SOURCE([
569 int main(int c, char **v) {
570 #ifdef _WIN32
571 #if _WIN32
572   return 0;
573 #else
574   return 1;
575 #endif
576 #else
577   return 2;
578 #endif
579 }])],
580 bwin32=true; AC_MSG_RESULT([yes]),
581 bwin32=false; AC_MSG_RESULT([no]),
582 bwin32=cross; AC_MSG_RESULT([cross])
585 if test "$bwin32" = "cross"; then
586 AC_MSG_CHECKING([for win32 (cross)])
587 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
588 #ifdef _WIN32
589 int main(int c, char **v) {return 0;}
590 #else
591 #error
592 int main(int c, char **v) {return x(y);}
593 #endif
594 ])],
595 bwin32=true; AC_MSG_RESULT([yes]),
596 bwin32=false; AC_MSG_RESULT([no]))
599 AH_BOTTOM([
600 #ifdef _WIN32
601 /* Defined to access windows functions and definitions for >=WinVista */
602 # ifndef WINVER
603 #  define WINVER 0x0600
604 # endif
606 /* Defined to access _other_ windows functions and definitions for >=WinVista */
607 # ifndef _WIN32_WINNT
608 #  define _WIN32_WINNT 0x0600
609 # endif
611 /* Defined to avoid including some windows headers as part of Windows.h */
612 # ifndef WIN32_LEAN_AND_MEAN
613 #  define WIN32_LEAN_AND_MEAN 1
614 # endif
615 #endif
618 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
619 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
620 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
622 dnl Enable C99 when compiling with MIPSpro
623 AC_MSG_CHECKING([for MIPSpro compiler])
624 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
625 #if (defined(__sgi) && defined(_COMPILER_VERSION))
626 #error
627   return x(y);
628 #endif
629 ])],
630 bmipspro=false; AC_MSG_RESULT(no),
631 bmipspro=true; AC_MSG_RESULT(yes))
633 if test "$bmipspro" = "true"; then
634   CFLAGS="$CFLAGS -c99"
637 AC_C_BIGENDIAN
639 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
641 if test "x$enable_rust" = "xyes"; then
642   AC_ARG_VAR([RUSTC], [path to the rustc binary])
643   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
644   if test "x$RUSTC" = "xno"; then
645     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
646   fi
648   AC_ARG_VAR([CARGO], [path to the cargo binary])
649   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
650   if test "x$CARGO" = "xno"; then
651     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
652   fi
654   AC_DEFINE([HAVE_RUST], 1, [have Rust])
655   if test "x$enable_fatal_warnings" = "xyes"; then
656     RUST_WARN=
657   else
658     RUST_WARN=#
659   fi
660   if test "x$enable_cargo_online_mode" = "xyes"; then
661     CARGO_ONLINE=
662     RUST_DL=#
663   else
664     CARGO_ONLINE=--frozen
665     RUST_DL=
667     dnl When we're not allowed to touch the network, we need crate dependencies
668     dnl locally available.
669     AC_MSG_CHECKING([rust crate dependencies])
670     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
671     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
672       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
673     fi
674     dnl Check whether the path exists before we try to cd into it.
675     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
676       AC_MSG_ERROR([Rust dependency directory $TOR_RUST_DEPENDENCIES does not exist. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
677       ERRORED=1
678     fi
679     dnl Make the path absolute, since we'll be using it from within a
680     dnl subdirectory.
681     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
683     for dep in $rust_crates; do
684       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
685         AC_MSG_ERROR([Failure to find rust dependency $TOR_RUST_DEPENDENCIES/$dep. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
686         ERRORED=1
687       fi
688     done
689     if test "x$ERRORED" = "x"; then
690       AC_MSG_RESULT([yes])
691     fi
692   fi
694   dnl For now both MSVC and MinGW rust libraries will output static libs with
695   dnl the MSVC naming convention.
696   if test "$bwin32" = "true"; then
697     tor_rust_static_name=tor_rust.lib
698   else
699     tor_rust_static_name=libtor_rust.a
700   fi
702   AC_CANONICAL_BUILD
704   if test -n "$TOR_RUST_TARGET"; then
705     if test "$host" = "$build"; then
706       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
707     fi
708     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
709     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
710   else
711     if test "$host" != "$build"; then
712       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
713     fi
714     RUST_TARGET_PROP=
715     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
716   fi
718   AC_SUBST(RUST_TARGET_PROP)
719   AC_SUBST(TOR_RUST_LIB_PATH)
720   AC_SUBST(CARGO_ONLINE)
721   AC_SUBST(RUST_WARN)
722   AC_SUBST(RUST_DL)
724   dnl Let's check the rustc version, too
725   AC_MSG_CHECKING([rust version])
726   RUSTC_VERSION=`$RUSTC --version`
727   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
728   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
729   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
730     AC_MSG_ERROR([rustc version couldn't be identified])
731   fi
732   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 31; then
733     AC_MSG_ERROR([rustc must be at least version 1.31.0])
734   fi
735   AC_MSG_RESULT([$RUSTC_VERSION])
738 AC_SEARCH_LIBS(socket, [socket network])
739 AC_SEARCH_LIBS(gethostbyname, [nsl])
740 AC_SEARCH_LIBS(dlopen, [dl])
741 AC_SEARCH_LIBS(inet_aton, [resolv])
742 AC_SEARCH_LIBS(backtrace, [execinfo])
743 saved_LIBS="$LIBS"
744 AC_SEARCH_LIBS([clock_gettime], [rt])
745 if test "$LIBS" != "$saved_LIBS"; then
746    # Looks like we need -lrt for clock_gettime().
747    have_rt=yes
750 if test "$bwin32" = "false"; then
751   AC_SEARCH_LIBS(pthread_create, [pthread])
752   AC_SEARCH_LIBS(pthread_detach, [pthread])
755 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
756 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
758 AC_CHECK_FUNCS(
759         _NSGetEnviron \
760         RtlSecureZeroMemory \
761         SecureZeroMemory \
762         accept4 \
763         backtrace \
764         backtrace_symbols_fd \
765         eventfd \
766         explicit_bzero \
767         timingsafe_memcmp \
768         flock \
769         fsync \
770         ftime \
771         get_current_dir_name \
772         getaddrinfo \
773         getdelim \
774         getifaddrs \
775         getline \
776         getrlimit \
777         gettimeofday \
778         gmtime_r \
779         gnu_get_libc_version \
780         inet_aton \
781         ioctl \
782         issetugid \
783         llround \
784         localtime_r \
785         lround \
786         madvise \
787         memmem \
788         memset_s \
789         minherit \
790         mmap \
791         pipe \
792         pipe2 \
793         prctl \
794         readpassphrase \
795         rint \
796         sigaction \
797         socketpair \
798         statvfs \
799         strncasecmp \
800         strcasecmp \
801         strlcat \
802         strlcpy \
803         strnlen \
804         strptime \
805         strtok_r \
806         strtoull \
807         sysconf \
808         sysctl \
809         truncate \
810         uname \
811         usleep \
812         vasprintf \
813         _vscprintf
816 # Apple messed up when they added some functions: they
817 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
818 # checks.
820 # We should only probe for these functions if we are sure that we
821 # are not targeting OS X 10.9 or earlier.
822 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
823 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
824 #ifdef __APPLE__
825 #  include <AvailabilityMacros.h>
826 #  ifndef MAC_OS_X_VERSION_10_10
827 #    define MAC_OS_X_VERSION_10_10 101000
828 #  endif
829 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
830 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
831 #      error "Running on Mac OS X 10.9 or earlier"
832 #    endif
833 #  endif
834 #endif
835 ]], [[]])],
836    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
837    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
839 if test "$on_macos_pre_10_10" = "no"; then
840   AC_CHECK_FUNCS(
841         mach_approximate_time \
842   )
845 # We should only probe for these functions if we are sure that we
846 # are not targeting OSX 10.11 or earlier.
847 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
848 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
849 #ifdef __APPLE__
850 #  include <AvailabilityMacros.h>
851 #  ifndef MAC_OS_X_VERSION_10_12
852 #    define MAC_OS_X_VERSION_10_12 101200
853 #  endif
854 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
855 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
856 #      error "Running on Mac OSX 10.11 or earlier"
857 #    endif
858 #  endif
859 #endif
860 ]], [[]])],
861    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
862    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
864 if test "$on_macos_pre_10_12" = "no"; then
865   AC_CHECK_FUNCS(
866         clock_gettime \
867         getentropy \
868   )
871 if test "$bwin32" != "true"; then
872   AC_CHECK_HEADERS(pthread.h)
873   AC_CHECK_FUNCS(pthread_create)
874   AC_CHECK_FUNCS(pthread_condattr_setclock)
877 if test "$bwin32" = "true"; then
878   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
879 #include <windows.h>
880 #include <conio.h>
881 #include <wchar.h>
882                  ])
885 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
886   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
888 AC_CHECK_FUNCS(glob)
890 AC_MSG_CHECKING([whether free(NULL) works])
891 AC_RUN_IFELSE([AC_LANG_PROGRAM([
892   #include <stdlib.h>
893 ], [
894 char *p = NULL;
895 free(p);
896 ])],
897 [free_null_ok=true; AC_MSG_RESULT(yes)],
898 [free_null_ok=false; AC_MSG_RESULT(no)],
899 [free_null_ok=cross; AC_MSG_RESULT(cross)])
901 if test "$free_null_ok" = "false"; then
902    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
905 dnl ------------------------------------------------------
906 dnl Where do you live, libevent?  And how do we call you?
908 if test "$bwin32" = "true"; then
909   TOR_LIB_WS32=-lws2_32
910   TOR_LIB_IPHLPAPI=-liphlpapi
911   TOR_LIB_SHLWAPI=-lshlwapi
912   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
913   # think it's actually necessary.
914   TOR_LIB_GDI=-lgdi32
915   TOR_LIB_USERENV=-luserenv
916   TOR_LIB_BCRYPT=-lbcrypt
917   TOR_LIB_CRYPT32=-lcrypt32
918 else
919   TOR_LIB_WS32=
920   TOR_LIB_GDI=
921   TOR_LIB_USERENV=
923 AC_SUBST(TOR_LIB_WS32)
924 AC_SUBST(TOR_LIB_GDI)
925 AC_SUBST(TOR_LIB_IPHLPAPI)
926 AC_SUBST(TOR_LIB_BCRYPT)
927 AC_SUBST(TOR_LIB_CRYPT32)
928 AC_SUBST(TOR_LIB_SHLWAPI)
929 AC_SUBST(TOR_LIB_USERENV)
931 tor_libevent_pkg_redhat="libevent"
932 tor_libevent_pkg_debian="libevent-dev"
933 tor_libevent_devpkg_redhat="libevent-devel"
934 tor_libevent_devpkg_debian="libevent-dev"
936 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
937 dnl linking for static builds.
938 STATIC_LIBEVENT_FLAGS=""
939 if test "$enable_static_libevent" = "yes"; then
940     if test "$have_rt" = "yes"; then
941       STATIC_LIBEVENT_FLAGS=" -lrt "
942     fi
945 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_IPHLPAPI $TOR_LIB_BCRYPT $TOR_LIB_WS32], [
946 #ifdef _WIN32
947 #include <winsock2.h>
948 #endif
949 #include <sys/time.h>
950 #include <sys/types.h>
951 #include <event2/event.h>], [
952 #ifdef _WIN32
953 #include <winsock2.h>
954 #endif
955 struct event_base;
956 struct event_base *event_base_new(void);
957 void event_base_free(struct event_base *);],
958     [
959 #ifdef _WIN32
960 {WSADATA d; WSAStartup(0x101,&d); }
961 #endif
962 event_base_free(event_base_new());
963 ], [--with-libevent-dir], [/opt/libevent])
965 dnl Determine the incantation needed to link libevent.
966 save_LIBS="$LIBS"
967 save_LDFLAGS="$LDFLAGS"
968 save_CPPFLAGS="$CPPFLAGS"
970 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
971 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
972 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
974 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
976 if test "$enable_static_libevent" = "yes"; then
977    if test "$tor_cv_library_libevent_dir" = "(system)"; then
978      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
979    else
980      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
981    fi
982 else
983      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
984        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
985        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"))
987        if test "$ac_cv_search_event_new" != "none required"; then
988          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
989        fi
990        if test "$ac_cv_search_evdns_base_new" != "none required"; then
991          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
992        fi
993      else
994        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
995      fi
998 dnl Now check for particular libevent functions.
999 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
1000                 evutil_secure_rng_add_bytes \
1001                 evdns_base_get_nameserver_addr \
1005 LIBS="$save_LIBS"
1006 LDFLAGS="$save_LDFLAGS"
1007 CPPFLAGS="$save_CPPFLAGS"
1009 dnl Check that libevent is at least at version 2.0.10, the first stable
1010 dnl release of its series
1011 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
1012 AC_MSG_CHECKING([whether Libevent is new enough])
1013 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1014 #include <event2/event.h>
1015 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
1016 #error
1017 int x = y(zz);
1018 #else
1019 int x = 1;
1020 #endif
1021 ])], [ AC_MSG_RESULT([yes]) ],
1022    [ AC_MSG_RESULT([no])
1023      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
1025 LIBS="$save_LIBS"
1026 LDFLAGS="$save_LDFLAGS"
1027 CPPFLAGS="$save_CPPFLAGS"
1029 AC_SUBST(TOR_LIBEVENT_LIBS)
1031 dnl ------------------------------------------------------
1032 dnl Where do you live, libm?
1034 dnl On some platforms (Haiku/BeOS) the math library is
1035 dnl part of libroot. In which case don't link against lm
1036 TOR_LIB_MATH=""
1037 save_LIBS="$LIBS"
1038 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
1039 if test "$ac_cv_search_pow" != "none required"; then
1040     TOR_LIB_MATH="$ac_cv_search_pow"
1042 LIBS="$save_LIBS"
1043 AC_SUBST(TOR_LIB_MATH)
1045 dnl ------------------------------------------------------
1046 dnl Hello, NSS.  You're new around here.
1047 if test "x$enable_nss" = "xyes"; then
1048   PKG_CHECK_MODULES(NSS,
1049      [nss],
1050      [have_nss=yes],
1051      [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.])])
1052   AC_SUBST(NSS_CFLAGS)
1053   AC_SUBST(NSS_LIBS)
1056 dnl ------------------------------------------------------
1057 dnl Where do you live, openssl?  And how do we call you?
1059 if test "x$enable_nss" != "xyes"; then
1061 tor_openssl_pkg_redhat="openssl"
1062 tor_openssl_pkg_debian="libssl-dev"
1063 tor_openssl_devpkg_redhat="openssl-devel"
1064 tor_openssl_devpkg_debian="libssl-dev"
1066 ALT_openssl_WITHVAL=""
1067 AC_ARG_WITH(ssl-dir,
1068   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
1069   [
1070       if test "x$withval" != "xno" && test "x$withval" != "x"; then
1071          ALT_openssl_WITHVAL="$withval"
1072       fi
1073   ])
1075 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
1076 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32 $TOR_LIB_CRYPT32],
1077     [#include <openssl/ssl.h>
1078      char *getenv(const char *);],
1079     [struct ssl_cipher_st;
1080      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
1081      char *getenv(const char *);],
1082     dnl This funny-looking test program calls getenv, so that the compiler
1083     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
1084     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
1085     dnl We look for SSL_cipher_get_id() because it is present in
1086     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
1087     dnl depends on it.
1088     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
1089     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
1091 if test "$enable_static_openssl" = "yes"; then
1092    if test "$tor_cv_library_openssl_dir" = "(system)"; then
1093      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
1094    else
1095      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a $TOR_LIB_WS32 $TOR_LIB_CRYPT32 $TOR_LIB_BCRYPT"
1096    fi
1097 else
1098      TOR_OPENSSL_LIBS="-lssl -lcrypto"
1100 AC_SUBST(TOR_OPENSSL_LIBS)
1102 dnl Now validate openssl, and check for particular openssl functions.
1103 save_LIBS="$LIBS"
1104 save_LDFLAGS="$LDFLAGS"
1105 save_CPPFLAGS="$CPPFLAGS"
1106 LIBS="$TOR_OPENSSL_LIBS $LIBS"
1107 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
1108 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
1110 dnl Tor currently uses a number of APIs that are deprecated in OpenSSL 3.0.0
1111 dnl and later.  We want to migrate away from them, but that will be a lot of
1112 dnl work. (See ticket tor#40166.)  For now, we disable the deprecation
1113 dnl warnings.
1115 AC_MSG_CHECKING([for OpenSSL >= 3.0.0])
1116 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1117 #include <openssl/opensslv.h>
1118 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER <= 0x30000000L
1119 #error "you_have_version_3"
1120 #endif
1121    ]], [[]])],
1122    [ AC_MSG_RESULT([no]) ],
1123    [ AC_MSG_RESULT([yes]);
1124      AC_DEFINE(OPENSSL_SUPPRESS_DEPRECATED, 1, [disable openssl deprecated-function warnings]) ])
1126 AC_MSG_CHECKING([for OpenSSL < 1.0.1])
1127 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1128 #include <openssl/opensslv.h>
1129 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
1130 #error "too old"
1131 #endif
1132    ]], [[]])],
1133    [ AC_MSG_RESULT([no]) ],
1134    [ 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.]) ])
1136 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1137 #include <openssl/opensslv.h>
1138 #include <openssl/evp.h>
1139 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
1140 #error "no ECC"
1141 #endif
1142 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
1143 #error "curves unavailable"
1144 #endif
1145    ]], [[]])],
1146    [ : ],
1147    [ 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.]) ])
1149 dnl Let's see if we have a version mismatch between includes and libs.
1150 AC_MSG_CHECKING([for significant mismatch between openssl headers and libraries])
1151 ac_retval=foo
1152 AC_RUN_IFELSE([AC_LANG_SOURCE([AC_LANG_PROGRAM([[
1153  #include <openssl/opensslv.h>
1154  #include <openssl/crypto.h>
1155 ]], [[
1156   /* Include major, minor, and fix, but not patch or status. */
1157   unsigned long mask = 0xfffff000;
1158   unsigned long linking = OpenSSL_version_num() & mask;
1159   unsigned long running = OPENSSL_VERSION_NUMBER & mask;
1160   return !(linking==running);
1161 ]])])], [openssl_ver_mismatch=no], [
1162    # This is a kludge to figure out whether compilation failed, or whether
1163    # running the program failed.
1164    if test "$ac_retval" = "1"; then
1165       openssl_ver_mismatch=inconclusive
1166    else
1167       openssl_ver_mismatch=yes
1168    fi], [openssl_ver_mismatch=cross])
1169 AC_MSG_RESULT([$openssl_ver_mismatch])
1171 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
1172 [#include <openssl/ssl.h>
1175 dnl OpenSSL functions which we might not have.  In theory, we could just
1176 dnl check the openssl version number, but in practice that gets pretty
1177 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
1178 dnl to them.
1179 AC_CHECK_FUNCS([ \
1180                 ERR_load_KDF_strings \
1181                 EVP_PBE_scrypt \
1182                 SSL_CIPHER_find \
1183                 SSL_CTX_set1_groups_list \
1184                 SSL_CTX_set_security_level \
1185                 SSL_SESSION_get_master_key \
1186                 SSL_get_client_ciphers \
1187                 SSL_get_client_random \
1188                 SSL_get_server_random \
1189                 TLS_method \
1190                ])
1192 dnl Check if OpenSSL structures are opaque
1193 AC_CHECK_MEMBERS([SSL.state], , ,
1194 [#include <openssl/ssl.h>
1197 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
1198 #include <openssl/sha.h>
1201 fi # enable_nss
1203 dnl We will someday make KECCAK_TINY optional, but for now we still need
1204 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
1205 dnl once.  See comment in the definition of crypto_xof_t.
1207 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
1208 dnl   test "x$ac_cv_func_EVP_sha3_256" != "xyes")
1210 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
1212 dnl ======================================================================
1213 dnl Can we use KIST?
1215 dnl Define the set of checks for KIST scheduler support.
1216 AC_DEFUN([CHECK_KIST_SUPPORT],[
1217   dnl KIST needs struct tcp_info and for certain members to exist.
1218   AC_CHECK_MEMBERS(
1219     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1220     , ,[[#include <netinet/tcp.h>]])
1221   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1222   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1223                      #include <linux/sockios.h>
1224                      #ifndef SIOCOUTQNSD
1225                      #error
1226                      #endif
1227                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1228   if test "x$have_siocoutqnsd" = "xyes"; then
1229     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1230       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1231         have_kist_support=yes
1232       fi
1233     fi
1234   fi
1236 dnl Now, trigger the check.
1237 CHECK_KIST_SUPPORT
1238 AS_IF([test "x$have_kist_support" = "xyes"],
1239       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1240                                         on this system])],
1241       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1243 LIBS="$save_LIBS"
1244 LDFLAGS="$save_LDFLAGS"
1245 CPPFLAGS="$save_CPPFLAGS"
1247 dnl ------------------------------------------------------
1248 dnl Where do you live, zlib?  And how do we call you?
1250 tor_zlib_pkg_redhat="zlib"
1251 tor_zlib_pkg_debian="zlib1g"
1252 tor_zlib_devpkg_redhat="zlib-devel"
1253 tor_zlib_devpkg_debian="zlib1g-dev"
1255 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1256     [#include <zlib.h>],
1257     [const char * zlibVersion(void);],
1258     [zlibVersion();], [--with-zlib-dir],
1259     [/opt/zlib])
1261 if test "$enable_static_zlib" = "yes"; then
1262    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1263      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1264  using --enable-static-zlib")
1265    else
1266      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1267    fi
1268 else
1269      TOR_ZLIB_LIBS="-lz"
1271 AC_SUBST(TOR_ZLIB_LIBS)
1273 dnl ------------------------------------------------------
1274 dnl Where we do we find lzma?
1276 AC_ARG_ENABLE(lzma,
1277       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1278       [case "${enableval}" in
1279         "yes") ;;
1280         "no")  ;;
1281         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1282       esac], [enable_lzma=auto])
1284 if test "x$enable_lzma" = "xno"; then
1285     have_lzma=no;
1286 else
1287     PKG_CHECK_MODULES([LZMA],
1288                       [liblzma],
1289                       have_lzma=yes,
1290                       have_lzma=no)
1292     if test "x$have_lzma" = "xno" ; then
1293         tor_incr_n_warnings
1294         AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
1295     fi
1298 if test "x$have_lzma" = "xyes"; then
1299     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1300     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1301     TOR_LZMA_LIBS="${LZMA_LIBS}"
1303 AC_SUBST(TOR_LZMA_CFLAGS)
1304 AC_SUBST(TOR_LZMA_LIBS)
1306 dnl ------------------------------------------------------
1307 dnl Where we do we find zstd?
1309 AC_ARG_ENABLE(zstd,
1310       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1311       [case "${enableval}" in
1312         "yes") ;;
1313         "no")  ;;
1314         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1315       esac], [enable_zstd=auto])
1317 if test "x$enable_zstd" = "xno"; then
1318     have_zstd=no;
1319 else
1320     PKG_CHECK_MODULES([ZSTD],
1321                       [libzstd >= 1.1],
1322                       have_zstd=yes,
1323                       have_zstd=no)
1325     if test "x$have_zstd" = "xno" ; then
1326         tor_incr_n_warnings
1327         AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
1328     fi
1331 if test "x$have_zstd" = "xyes"; then
1332     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1333     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1334     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1336     dnl now check for zstd functions
1337     save_LIBS="$LIBS"
1338     save_CFLAGS="$CFLAGS"
1339     LIBS="$LIBS $ZSTD_LIBS"
1340     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1341     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1342                    ZSTD_estimateDCtxSize)
1343     LIBS="$save_LIBS"
1344     CFLAGS="$save_CFLAGS"
1346 AC_SUBST(TOR_ZSTD_CFLAGS)
1347 AC_SUBST(TOR_ZSTD_LIBS)
1349 dnl ----------------------------------------------------------------------
1350 dnl Check if libcap is available for capabilities.
1352 tor_cap_pkg_debian="libcap2"
1353 tor_cap_pkg_redhat="libcap"
1354 tor_cap_devpkg_debian="libcap-dev"
1355 tor_cap_devpkg_redhat="libcap-devel"
1357 AC_CHECK_LIB([cap], [cap_init], [],
1358   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1360 AC_CHECK_FUNCS(cap_set_proc)
1362 dnl ---------------------------------------------------------------------
1363 dnl Now that we know about our major libraries, we can check for compiler
1364 dnl and linker hardening options.  We need to do this with the libraries known,
1365 dnl since sometimes the linker will like an option but not be willing to
1366 dnl use it with a build of a library.
1368 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1369 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"
1371 CFLAGS_FTRAPV=
1372 CFLAGS_FWRAPV=
1373 CFLAGS_ASAN=
1374 CFLAGS_UBSAN=
1377 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1378 #if !defined(__clang__)
1379 #error
1380 #endif])], have_clang=yes, have_clang=no)
1382 if test "x$enable_pic" = "xyes"; then
1383     TOR_CHECK_CFLAGS(-fPIC)
1386 if test "x$enable_gcc_hardening" != "xno"; then
1387     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1388     if test "x$have_clang" = "xyes"; then
1389         TOR_CHECK_CFLAGS(-Qunused-arguments)
1390     fi
1391     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1392     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1393     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1394 m4_ifdef([AS_VAR_IF],[
1395     AS_VAR_IF(can_compile, [yes],
1396         AS_VAR_IF(can_link, [yes],
1397                   [],
1398                   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.)]))
1399         )])
1400     AS_VAR_POPDEF([can_link])
1401     AS_VAR_POPDEF([can_compile])
1402     TOR_CHECK_CFLAGS(-Wstack-protector)
1403     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1404     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1405        if test "$enable_pic" != "yes"; then
1406            # If we have already enabled -fPIC, then we don't also need to
1407            # compile with -fPIE...
1408            TOR_CHECK_CFLAGS(-fPIE)
1409        fi
1410        # ... but we want to link our executables with -pie in any case, since
1411        # they're executables, not a library.
1412        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1413     fi
1414     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1416    AC_MSG_CHECKING([whether we can run hardened binaries])
1417    AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1418         [AC_MSG_RESULT([yes])],
1419         [AC_MSG_RESULT([no])
1420          AC_MSG_ERROR([dnl
1421  We can link with compiler hardening options, but we can't run with them.
1422  That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1423  configure, but it would be better to figure out what the underlying problem
1424  is.])],
1425         [AC_MSG_RESULT([cross])])
1428 if test "$fragile_hardening" = "yes"; then
1429     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1430    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1431       tor_incr_n_warnings
1432       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.])
1433    fi
1435    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1436      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1437    fi
1439    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1440     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1441       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*])
1442     fi
1444    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1445     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1446       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*])
1447     fi
1449    TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1450     if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1451       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*])
1452     fi
1454 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1457 dnl Find the correct libraries to add in order to use the sanitizers.
1459 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1460 dnl option, which will prevent the compiler from linking the sanitizer
1461 dnl libraries it needs.  We need to specify them manually.
1463 dnl What's more, we need to specify them in a linker script rather than
1464 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1465 dnl variable.
1466 RUST_LINKER_OPTIONS=""
1467 if test "x$have_clang" = "xyes"; then
1468         if test "x$CFLAGS_ASAN" != "x"; then
1469                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
1470         fi
1471         if test "x$CFLAGS_UBSAN" != "x"; then
1472                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
1473         fi
1474 else
1475         if test "x$CFLAGS_ASAN" != "x"; then
1476                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
1477         fi
1478         if test "x$CFLAGS_UBSAN" != "x"; then
1479                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
1480         fi
1482 AC_SUBST(RUST_LINKER_OPTIONS)
1484 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1485 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1487 mulodi_fixes_ftrapv=no
1488 if test "$have_clang" = "yes"; then
1489   saved_CFLAGS="$CFLAGS"
1490   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1491   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1492   AC_LINK_IFELSE([
1493       AC_LANG_SOURCE([[
1494           #include <stdint.h>
1495           #include <stdlib.h>
1496           int main(int argc, char **argv)
1497           {
1498             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1499                         * (int64_t)atoi(argv[3]);
1500             return x == 9;
1501           } ]])],
1502           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1503           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1504   if test "$ftrapv_can_link" = "no"; then
1505     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1506     AC_LINK_IFELSE([
1507       AC_LANG_SOURCE([[
1508           #include <stdint.h>
1509           #include <stdlib.h>
1510           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1511              *overflow=0;
1512              return a;
1513           }
1514           int main(int argc, char **argv)
1515           {
1516             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1517                         * (int64_t)atoi(argv[3]);
1518             return x == 9;
1519           } ]])],
1520           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1521           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1522   fi
1523   CFLAGS="$saved_CFLAGS"
1526 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1528 dnl These cflags add bunches of branches, and we haven't been able to
1529 dnl persuade ourselves that they're suitable for code that needs to be
1530 dnl constant time.
1531 AC_SUBST(CFLAGS_BUGTRAP)
1532 dnl These cflags are variant ones suitable for code that needs to be
1533 dnl constant-time.
1534 AC_SUBST(CFLAGS_CONSTTIME)
1536 if test "x$enable_linker_hardening" != "xno"; then
1537     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1540 # For backtrace support
1541 TOR_CHECK_LDFLAGS(-rdynamic)
1543 dnl ------------------------------------------------------
1544 dnl Now see if we have a -fomit-frame-pointer compiler option.
1546 saved_CFLAGS="$CFLAGS"
1547 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1548 F_OMIT_FRAME_POINTER=''
1549 if test "$saved_CFLAGS" != "$CFLAGS"; then
1550   if test "$fragile_hardening" = "yes"; then
1551     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1552   fi
1554 CFLAGS="$saved_CFLAGS"
1555 AC_SUBST(F_OMIT_FRAME_POINTER)
1557 dnl ------------------------------------------------------
1558 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1559 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1560 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1561 dnl code will work.
1562 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1564 dnl ============================================================
1565 dnl Check for libseccomp
1567 if test "x$enable_seccomp" != "xno"; then
1568   AC_CHECK_HEADERS([seccomp.h])
1569   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1572 dnl ============================================================
1573 dnl Check for libscrypt
1575 if test "x$enable_libscrypt" != "xno"; then
1576   AC_CHECK_HEADERS([libscrypt.h])
1577   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1578   AC_CHECK_FUNCS([libscrypt_scrypt])
1581 dnl ============================================================
1582 dnl We need an implementation of curve25519.
1584 dnl set these defaults.
1585 build_curve25519_donna=no
1586 build_curve25519_donna_c64=no
1587 use_curve25519_donna=no
1588 use_curve25519_nacl=no
1589 CURVE25519_LIBS=
1591 dnl The best choice is using curve25519-donna-c64, but that requires
1592 dnl that we
1593 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1594   tor_cv_can_use_curve25519_donna_c64,
1595   [AC_RUN_IFELSE(
1596     [AC_LANG_PROGRAM([dnl
1597       #include <stdint.h>
1598       typedef unsigned uint128_t __attribute__((mode(TI)));
1599   int func(uint64_t a, uint64_t b) {
1600            uint128_t c = ((uint128_t)a) * b;
1601            int ok = ((uint64_t)(c>>96)) == 522859 &&
1602              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1603                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1604                  (((uint64_t)(c))&0xffffffffL) == 0;
1605            return ok;
1606       }
1607   ], [dnl
1608     int ok = func( ((uint64_t)2000000000) * 1000000000,
1609                    ((uint64_t)1234567890) << 24);
1610         return !ok;
1611       ])],
1612   [tor_cv_can_use_curve25519_donna_c64=yes],
1613       [tor_cv_can_use_curve25519_donna_c64=no],
1614   [AC_LINK_IFELSE(
1615         [AC_LANG_PROGRAM([dnl
1616       #include <stdint.h>
1617       typedef unsigned uint128_t __attribute__((mode(TI)));
1618   int func(uint64_t a, uint64_t b) {
1619            uint128_t c = ((uint128_t)a) * b;
1620            int ok = ((uint64_t)(c>>96)) == 522859 &&
1621              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1622                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1623                  (((uint64_t)(c))&0xffffffffL) == 0;
1624            return ok;
1625       }
1626   ], [dnl
1627     int ok = func( ((uint64_t)2000000000) * 1000000000,
1628                  ((uint64_t)1234567890) << 24);
1629         return !ok;
1630       ])],
1631           [tor_cv_can_use_curve25519_donna_c64=cross],
1632       [tor_cv_can_use_curve25519_donna_c64=no])])])
1634 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1635                   nacl/crypto_scalarmult_curve25519.h])
1637 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1638   tor_cv_can_use_curve25519_nacl,
1639   [tor_saved_LIBS="$LIBS"
1640    LIBS="$LIBS -lnacl"
1641    AC_LINK_IFELSE(
1642      [AC_LANG_PROGRAM([dnl
1643        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1644        #include <crypto_scalarmult_curve25519.h>
1645    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1646    #include <nacl/crypto_scalarmult_curve25519.h>
1647    #endif
1648        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1649    #error Hey, this is the reference implementation! That's not fast.
1650    #endif
1651      ], [
1652    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1653      ])], [tor_cv_can_use_curve25519_nacl=yes],
1654      [tor_cv_can_use_curve25519_nacl=no])
1655    LIBS="$tor_saved_LIBS" ])
1657  dnl Okay, now we need to figure out which one to actually use. Fall back
1658  dnl to curve25519-donna.c
1660  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1661    build_curve25519_donna_c64=yes
1662    use_curve25519_donna=yes
1663  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1664    use_curve25519_nacl=yes
1665    CURVE25519_LIBS=-lnacl
1666  else
1667    build_curve25519_donna=yes
1668    use_curve25519_donna=yes
1669  fi
1671 if test "x$use_curve25519_donna" = "xyes"; then
1672   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1673             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1675 if test "x$use_curve25519_nacl" = "xyes"; then
1676   AC_DEFINE(USE_CURVE25519_NACL, 1,
1677             [Defined if we should use a curve25519 from nacl])
1679 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1680   test "x$build_curve25519_donna" = "xyes")
1681 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1682   test "x$build_curve25519_donna_c64" = "xyes")
1683 AC_SUBST(CURVE25519_LIBS)
1685 dnl Make sure to enable support for large off_t if available.
1686 AC_SYS_LARGEFILE
1688 AC_CHECK_HEADERS([errno.h \
1689                   fcntl.h \
1690                   signal.h \
1691                   string.h \
1692                   sys/capability.h \
1693                   sys/fcntl.h \
1694                   sys/stat.h \
1695                   sys/time.h \
1696                   sys/types.h \
1697                   time.h \
1698                   unistd.h \
1699                   arpa/inet.h \
1700                   crt_externs.h \
1701                   execinfo.h \
1702                   gnu/libc-version.h \
1703                   grp.h \
1704                   ifaddrs.h \
1705                   inttypes.h \
1706                   limits.h \
1707                   linux/types.h \
1708                   mach/vm_inherit.h \
1709                   machine/limits.h \
1710                   malloc.h \
1711                   netdb.h \
1712                   netinet/in.h \
1713                   netinet/in6.h \
1714                   pwd.h \
1715                   readpassphrase.h \
1716                   stdatomic.h \
1717                   sys/eventfd.h \
1718                   sys/file.h \
1719                   sys/ioctl.h \
1720                   sys/limits.h \
1721                   sys/mman.h \
1722                   sys/param.h \
1723                   sys/prctl.h \
1724                   sys/random.h \
1725                   sys/resource.h \
1726                   sys/select.h \
1727                   sys/socket.h \
1728                   sys/statvfs.h \
1729                   sys/syscall.h \
1730                   sys/sysctl.h \
1731                   sys/time.h \
1732                   sys/types.h \
1733                   sys/un.h \
1734                   sys/utime.h \
1735                   sys/wait.h \
1736                   syslog.h \
1737                   utime.h \
1738                   glob.h])
1740 AC_CHECK_HEADERS(sys/param.h)
1742 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1743 [#ifdef HAVE_SYS_TYPES_H
1744 #include <sys/types.h>
1745 #endif
1746 #ifdef HAVE_SYS_SOCKET_H
1747 #include <sys/socket.h>
1748 #endif])
1749 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1750 [#ifdef HAVE_SYS_TYPES_H
1751 #include <sys/types.h>
1752 #endif
1753 #ifdef HAVE_SYS_SOCKET_H
1754 #include <sys/socket.h>
1755 #endif
1756 #ifdef HAVE_NET_IF_H
1757 #include <net/if.h>
1758 #endif
1759 #ifdef HAVE_NETINET_IN_H
1760 #include <netinet/in.h>
1761 #endif])
1763 AC_CHECK_HEADERS(linux/if.h,[],[],
1765 #ifdef HAVE_SYS_SOCKET_H
1766 #include <sys/socket.h>
1767 #endif
1770 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1771         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1772 [#ifdef HAVE_SYS_TYPES_H
1773 #include <sys/types.h>
1774 #endif
1775 #ifdef HAVE_SYS_SOCKET_H
1776 #include <sys/socket.h>
1777 #endif
1778 #ifdef HAVE_LIMITS_H
1779 #include <limits.h>
1780 #endif
1781 #ifdef HAVE_LINUX_TYPES_H
1782 #include <linux/types.h>
1783 #endif
1784 #ifdef HAVE_NETINET_IN6_H
1785 #include <netinet/in6.h>
1786 #endif
1787 #ifdef HAVE_NETINET_IN_H
1788 #include <netinet/in.h>
1789 #endif])
1791 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1792         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1793 [#ifdef HAVE_SYS_TYPES_H
1794 #include <sys/types.h>
1795 #endif
1796 #ifdef HAVE_SYS_SOCKET_H
1797 #include <sys/socket.h>
1798 #endif
1799 #ifdef HAVE_LIMITS_H
1800 #include <limits.h>
1801 #endif
1802 #ifdef HAVE_LINUX_TYPES_H
1803 #include <linux/types.h>
1804 #endif
1805 #ifdef HAVE_NETINET_IN6_H
1806 #include <netinet/in6.h>
1807 #endif
1808 #ifdef HAVE_NETINET_IN_H
1809 #include <netinet/in.h>
1810 #endif
1811 #ifdef HAVE_LINUX_IF_H
1812 #include <linux/if.h>
1813 #endif])
1815 transparent_ok=0
1816 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1817   transparent_ok=1
1819 if test "x$linux_netfilter_ipv4" = "x1"; then
1820   transparent_ok=1
1822 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1823   transparent_ok=1
1825 if test "x$transparent_ok" = "x1"; then
1826   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1827 else
1828   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1831 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1832 [#ifdef HAVE_SYS_TYPES_H
1833 #include <sys/types.h>
1834 #endif
1835 #ifdef HAVE_SYS_TIME_H
1836 #include <sys/time.h>
1837 #endif])
1839 AC_CHECK_SIZEOF(char)
1840 AC_CHECK_SIZEOF(short)
1841 AC_CHECK_SIZEOF(int)
1842 AC_CHECK_SIZEOF(unsigned int)
1843 AC_CHECK_SIZEOF(long)
1844 AC_CHECK_SIZEOF(long long)
1845 AC_CHECK_SIZEOF(__int64)
1846 AC_CHECK_SIZEOF(void *)
1847 AC_CHECK_SIZEOF(time_t)
1848 AC_CHECK_SIZEOF(size_t)
1849 AC_CHECK_SIZEOF(pid_t)
1851 AC_CHECK_TYPES([uint, u_char, ssize_t])
1853 AC_PC_FROM_UCONTEXT([:])
1855 dnl used to include sockaddr_storage, but everybody has that.
1856 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1857 [#ifdef HAVE_SYS_TYPES_H
1858 #include <sys/types.h>
1859 #endif
1860 #ifdef HAVE_NETINET_IN_H
1861 #include <netinet/in.h>
1862 #endif
1863 #ifdef HAVE_NETINET_IN6_H
1864 #include <netinet/in6.h>
1865 #endif
1866 #ifdef HAVE_SYS_SOCKET_H
1867 #include <sys/socket.h>
1868 #endif
1869 #ifdef _WIN32
1870 #define _WIN32_WINNT 0x0501
1871 #define WIN32_LEAN_AND_MEAN
1872 #include <winsock2.h>
1873 #include <ws2tcpip.h>
1874 #endif
1876 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1877 [#ifdef HAVE_SYS_TYPES_H
1878 #include <sys/types.h>
1879 #endif
1880 #ifdef HAVE_NETINET_IN_H
1881 #include <netinet/in.h>
1882 #endif
1883 #ifdef HAVE_NETINET_IN6_H
1884 #include <netinet/in6.h>
1885 #endif
1886 #ifdef HAVE_SYS_SOCKET_H
1887 #include <sys/socket.h>
1888 #endif
1889 #ifdef _WIN32
1890 #define _WIN32_WINNT 0x0501
1891 #define WIN32_LEAN_AND_MEAN
1892 #include <winsock2.h>
1893 #include <ws2tcpip.h>
1894 #endif
1897 AC_CHECK_TYPES([rlim_t], , ,
1898 [#ifdef HAVE_SYS_TYPES_H
1899 #include <sys/types.h>
1900 #endif
1901 #ifdef HAVE_SYS_TIME_H
1902 #include <sys/time.h>
1903 #endif
1904 #ifdef HAVE_SYS_RESOURCE_H
1905 #include <sys/resource.h>
1906 #endif
1909 AX_CHECK_SIGN([time_t],
1910        [ : ],
1911        [ : ], [
1912 #ifdef HAVE_SYS_TYPES_H
1913 #include <sys/types.h>
1914 #endif
1915 #ifdef HAVE_SYS_TIME_H
1916 #include <sys/time.h>
1917 #endif
1918 #ifdef HAVE_TIME_H
1919 #include <time.h>
1920 #endif
1923 if test "$ax_cv_decl_time_t_signed" = "no"; then
1924   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1927 AX_CHECK_SIGN([size_t],
1928        [ tor_cv_size_t_signed=yes ],
1929        [ tor_cv_size_t_signed=no ], [
1930 #ifdef HAVE_SYS_TYPES_H
1931 #include <sys/types.h>
1932 #endif
1935 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1936   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1939 AX_CHECK_SIGN([enum always],
1940        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1941        [ : ], [
1942  enum always { AAA, BBB, CCC };
1945 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1946 #ifdef HAVE_SYS_SOCKET_H
1947 #include <sys/socket.h>
1948 #endif
1951 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1953 AC_CHECK_SIZEOF(cell_t)
1955 # Let's see if stdatomic works. (There are some debian clangs that screw it
1956 # up; see Tor bug #26779 and debian bug 903709.)
1957 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1958                tor_cv_stdatomic_works,
1959 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1960 #include <stdatomic.h>
1961 struct x { atomic_size_t y; };
1962 void try_atomic_init(struct x *xx)
1964   atomic_init(&xx->y, 99);
1965   atomic_fetch_add(&xx->y, 1);
1967 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1969 if test "$tor_cv_stdatomic_works" = "yes"; then
1970    AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1971 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1972    tor_incr_n_warnings
1973    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 ])
1976 # Now make sure that NULL can be represented as zero bytes.
1977 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1978 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1979 [[#include <stdlib.h>
1980 #include <string.h>
1981 #include <stdio.h>
1982 #ifdef HAVE_STDDEF_H
1983 #include <stddef.h>
1984 #endif
1985 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1986 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1987        [tor_cv_null_is_zero=yes],
1988        [tor_cv_null_is_zero=no],
1989        [tor_cv_null_is_zero=cross])])
1991 if test "$tor_cv_null_is_zero" = "cross"; then
1992   # Cross-compiling; let's hope that the target isn't raving mad.
1993   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1996 if test "$tor_cv_null_is_zero" != "no"; then
1997   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1998             [Define to 1 iff memset(0) sets pointers to NULL])
2001 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
2002 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2003 [[#include <stdlib.h>
2004 #include <string.h>
2005 #include <stdio.h>
2006 #ifdef HAVE_STDDEF_H
2007 #include <stddef.h>
2008 #endif
2009 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
2010 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
2011        [tor_cv_dbl0_is_zero=yes],
2012        [tor_cv_dbl0_is_zero=no],
2013        [tor_cv_dbl0_is_zero=cross])])
2015 if test "$tor_cv_dbl0_is_zero" = "cross"; then
2016   # Cross-compiling; let's hope that the target isn't raving mad.
2017   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
2020 if test "$tor_cv_dbl0_is_zero" != "no"; then
2021   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
2022             [Define to 1 iff memset(0) sets doubles to 0.0])
2025 # And what happens when we malloc zero?
2026 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
2027 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2028 [[#include <stdlib.h>
2029 #include <string.h>
2030 #include <stdio.h>
2031 #ifdef HAVE_STDDEF_H
2032 #include <stddef.h>
2033 #endif
2034 int main () { return malloc(0)?0:1; }]])],
2035        [tor_cv_malloc_zero_works=yes],
2036        [tor_cv_malloc_zero_works=no],
2037        [tor_cv_malloc_zero_works=cross])])
2039 if test "$tor_cv_malloc_zero_works" = "cross"; then
2040   # Cross-compiling; let's hope that the target isn't raving mad.
2041   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
2044 if test "$tor_cv_malloc_zero_works" = "yes"; then
2045   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
2046             [Define to 1 iff malloc(0) returns a pointer])
2049 # whether we seem to be in a 2s-complement world.
2050 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
2051 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2052 [[int main () { int problem = ((-99) != (~99)+1);
2053 return problem ? 1 : 0; }]])],
2054        [tor_cv_twos_complement=yes],
2055        [tor_cv_twos_complement=no],
2056        [tor_cv_twos_complement=cross])])
2058 if test "$tor_cv_twos_complement" = "cross"; then
2059   # Cross-compiling; let's hope that the target isn't raving mad.
2060   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
2063 if test "$tor_cv_twos_complement" != "no"; then
2064   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
2065             [Define to 1 iff we represent negative integers with
2066              two's complement])
2069 # What does shifting a negative value do?
2070 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
2071 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2072 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
2073        [tor_cv_sign_extend=yes],
2074        [tor_cv_sign_extend=no],
2075        [tor_cv_sign_extend=cross])])
2077 if test "$tor_cv_sign_extend" = "cross"; then
2078   # Cross-compiling; let's hope that the target isn't raving mad.
2079   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
2082 if test "$tor_cv_sign_extend" != "no"; then
2083   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
2084             [Define to 1 iff right-shifting a negative value performs sign-extension])
2087 # Is uint8_t the same type as unsigned char?
2088 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
2089 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2090 #include <stdint.h>
2091 extern uint8_t c;
2092 unsigned char c;]])],
2093        [tor_cv_uint8_uchar=yes],
2094        [tor_cv_uint8_uchar=no],
2095        [tor_cv_uint8_uchar=cross])])
2097 if test "$tor_cv_uint8_uchar" = "cross"; then
2098   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
2101 if test "$tor_cv_uint8_uchar" = "no"; then
2102   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
2105 AC_ARG_WITH(tcmalloc,
2106 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
2108 default_malloc=system
2110 if test "x$enable_openbsd_malloc" = "xyes" ; then
2111   AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
2112   default_malloc=openbsd
2115 if test "x$with_tcmalloc" = "xyes"; then
2116   AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
2117   default_malloc=tcmalloc
2120 AC_ARG_WITH(malloc,
2121    AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
2122                   [select special malloc implementation [system]]),
2123    [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
2125 AS_CASE([$malloc],
2126   [tcmalloc], [
2127       PKG_CHECK_MODULES([TCMALLOC],
2128                         [libtcmalloc],
2129                         have_tcmalloc=yes,
2130                         have_tcmalloc=no)
2132       if test "x$have_tcmalloc" = "xno" ; then
2133           AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
2134       fi
2136       CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
2137       LIBS="$TCMALLOC_LIBS $LIBS"
2138   ],
2140   [jemalloc], [
2141       PKG_CHECK_MODULES([JEMALLOC],
2142                         [jemalloc],
2143                         have_jemalloc=yes,
2144                         have_jemalloc=no)
2146       if test "x$have_jemalloc" = "xno" ; then
2147           AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
2148       fi
2150       CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
2151       LIBS="$JEMALLOC_LIBS $LIBS"
2152       using_custom_malloc=yes
2153   ],
2155   [openbsd], [
2156     tor_incr_n_warnings
2157     AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
2158     enable_openbsd_malloc=yes
2159   ],
2161   [system], [
2162      # handle this later, including the jemalloc fallback
2163   ],
2165   [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
2168 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
2170 if test "$malloc" != "system"; then
2171   # Tell the C compiler not to use the system allocator functions.
2172   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2174 if test "$using_custom_malloc" = "yes"; then
2175   # Tell the C compiler not to use the system allocator functions.
2176   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2179 # By default, we're going to assume we don't have mlockall()
2180 # bionic and other platforms have various broken mlockall subsystems.
2181 # Some systems don't have a working mlockall, some aren't linkable,
2182 # and some have it but don't declare it.
2183 AC_CHECK_FUNCS(mlockall)
2184 AC_CHECK_DECLS([mlockall], , , [
2185 #ifdef HAVE_SYS_MMAN_H
2186 #include <sys/mman.h>
2187 #endif])
2189 # Allow user to specify an alternate syslog facility
2190 AC_ARG_WITH(syslog-facility,
2191 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
2192 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
2193 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
2194 AC_SUBST(LOGFACILITY)
2196 # Check if we have getresuid and getresgid
2197 AC_CHECK_FUNCS(getresuid getresgid)
2199 # Check for gethostbyname_r in all its glorious incompatible versions.
2200 #   (This logic is based on that in Python's configure.in)
2201 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
2202   [Define this if you have any gethostbyname_r()])
2204 AC_CHECK_FUNC(gethostbyname_r, [
2205   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
2206   OLD_CFLAGS=$CFLAGS
2207   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
2208   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2209 #include <netdb.h>
2210   ]], [[
2211     char *cp1, *cp2;
2212     struct hostent *h1, *h2;
2213     int i1, i2;
2214     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2215   ]])],[
2216     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2217     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2218      [Define this if gethostbyname_r takes 6 arguments])
2219     AC_MSG_RESULT(6)
2220   ], [
2221     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2222 #include <netdb.h>
2223     ]], [[
2224       char *cp1, *cp2;
2225       struct hostent *h1;
2226       int i1, i2;
2227       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2228     ]])], [
2229       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2230       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2231         [Define this if gethostbyname_r takes 5 arguments])
2232       AC_MSG_RESULT(5)
2233    ], [
2234       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2235 #include <netdb.h>
2236      ]], [[
2237        char *cp1;
2238        struct hostent *h1;
2239        struct hostent_data hd;
2240        (void) gethostbyname_r(cp1,h1,&hd);
2241      ]])], [
2242        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2243        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2244          [Define this if gethostbyname_r takes 3 arguments])
2245        AC_MSG_RESULT(3)
2246      ], [
2247        AC_MSG_RESULT(0)
2248      ])
2249   ])
2250  ])
2251  CFLAGS=$OLD_CFLAGS
2254 AC_CACHE_CHECK([whether the C compiler supports __func__],
2255   tor_cv_have_func_macro,
2256   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2257 #include <stdio.h>
2258 int main(int c, char **v) { puts(__func__); }])],
2259   tor_cv_have_func_macro=yes,
2260   tor_cv_have_func_macro=no))
2262 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2263   tor_cv_have_FUNC_macro,
2264   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2265 #include <stdio.h>
2266 int main(int c, char **v) { puts(__FUNC__); }])],
2267   tor_cv_have_FUNC_macro=yes,
2268   tor_cv_have_FUNC_macro=no))
2270 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2271   tor_cv_have_FUNCTION_macro,
2272   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2273 #include <stdio.h>
2274 int main(int c, char **v) { puts(__FUNCTION__); }])],
2275   tor_cv_have_FUNCTION_macro=yes,
2276   tor_cv_have_FUNCTION_macro=no))
2278 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2279   tor_cv_have_environ_declared,
2280   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2281 #ifdef HAVE_UNISTD_H
2282 #include <unistd.h>
2283 #endif
2284 #include <stdlib.h>
2285 int main(int c, char **v) { char **t = environ; }])],
2286   tor_cv_have_environ_declared=yes,
2287   tor_cv_have_environ_declared=no))
2289 if test "$tor_cv_have_func_macro" = "yes"; then
2290   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2293 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2294   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2297 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2298   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2299            [Defined if the compiler supports __FUNCTION__])
2302 if test "$tor_cv_have_environ_declared" = "yes"; then
2303   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2304            [Defined if we have extern char **environ already declared])
2307 # $prefix stores the value of the --prefix command line option, or
2308 # NONE if the option wasn't set.  In the case that it wasn't set, make
2309 # it be the default, so that we can use it to expand directories now.
2310 if test "x$prefix" = "xNONE"; then
2311   prefix=$ac_default_prefix
2314 # and similarly for $exec_prefix
2315 if test "x$exec_prefix" = "xNONE"; then
2316   exec_prefix=$prefix
2319 if test "x$BUILDDIR" = "x"; then
2320   BUILDDIR=`pwd`
2322 AC_SUBST(BUILDDIR)
2323 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2324 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2326 if test "x$SRCDIR" = "x"; then
2327   SRCDIR=$(cd "$srcdir"; pwd)
2329 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2330 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2332 if test "x$CONFDIR" = "x"; then
2333   CONFDIR=`eval echo $sysconfdir/tor`
2335 AC_SUBST(CONFDIR)
2336 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2337 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2339 BINDIR=`eval echo $bindir`
2340 AC_SUBST(BINDIR)
2341 LOCALSTATEDIR=`eval echo $localstatedir`
2342 AC_SUBST(LOCALSTATEDIR)
2344 if test "$bwin32" = "true"; then
2345   # Test if the linker supports the --nxcompat and --dynamicbase options
2346   # for Windows
2347   save_LDFLAGS="$LDFLAGS"
2348   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2349   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2350   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2351     [AC_MSG_RESULT([yes])]
2352     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2353     [AC_MSG_RESULT([no])]
2354   )
2355   LDFLAGS="$save_LDFLAGS"
2358 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2359 # than autoconf's macros like.
2360 if test "$GCC" = "yes"; then
2361   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2362   # accident waiting to happen.
2363   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2364 else
2365   # Override optimization level for non-gcc compilers
2366   CFLAGS="$CFLAGS -O"
2367   enable_gcc_warnings=no
2368   enable_gcc_warnings_advisory=no
2371 # Warnings implies advisory-warnings and -Werror.
2372 if test "$enable_gcc_warnings" = "yes"; then
2373   enable_gcc_warnings_advisory=yes
2374   enable_fatal_warnings=yes
2377 # OS X Lion started deprecating the system openssl. Let's just disable
2378 # all deprecation warnings on OS X. Also, to potentially make the binary
2379 # a little smaller, let's enable dead_strip.
2380 case "$host_os" in
2382  darwin*)
2383     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2384     LDFLAGS="$LDFLAGS -dead_strip" ;;
2385 esac
2387 TOR_WARNING_FLAGS=""
2389 # Add some more warnings which we use in development but not in the
2390 # released versions.  (Some relevant gcc versions can't handle these.)
2392 # Note that we have to do this near the end  of the autoconf process, or
2393 # else we may run into problems when these warnings hit on the testing C
2394 # programs that autoconf wants to build.
2395 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2397   case "$host" in
2398     *-*-openbsd* | *-*-bitrig*)
2399       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2400       # That's fine, except that the headers don't pass -Wredundant-decls.
2401       # Therefore, let's disable -Wsystem-headers when we're building
2402       # with maximal warnings on OpenBSD.
2403       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2404   esac
2406   CFLAGS_NOWARNINGS="$CFLAGS"
2408   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2409   # have it work better.
2410   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2412   # This warning was added in gcc 4.3, but it appears to generate
2413   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2414   #CFLAGS="$CFLAGS -Wlogical-op"
2416   m4_foreach_w([warning_flag], [
2417      -Waddress
2418      -Waddress-of-array-temporary
2419      -Waddress-of-temporary
2420      -Wambiguous-macro
2421      -Wanonymous-pack-parens
2422      -Warc
2423      -Warc-abi
2424      -Warc-bridge-casts-disallowed-in-nonarc
2425      -Warc-maybe-repeated-use-of-weak
2426      -Warc-performSelector-leaks
2427      -Warc-repeated-use-of-weak
2428      -Warray-bounds
2429      -Warray-bounds-pointer-arithmetic
2430      -Wasm
2431      -Wasm-operand-widths
2432      -Watomic-properties
2433      -Watomic-property-with-user-defined-accessor
2434      -Wauto-import
2435      -Wauto-storage-class
2436      -Wauto-var-id
2437      -Wavailability
2438      -Wbackslash-newline-escape
2439      -Wbad-array-new-length
2440      -Wbind-to-temporary-copy
2441      -Wbitfield-constant-conversion
2442      -Wbool-conversion
2443      -Wbool-conversions
2444      -Wbuiltin-requires-header
2445      -Wchar-align
2446      -Wcompare-distinct-pointer-types
2447      -Wcomplex-component-init
2448      -Wconditional-type-mismatch
2449      -Wconfig-macros
2450      -Wconstant-conversion
2451      -Wconstant-logical-operand
2452      -Wconstexpr-not-const
2453      -Wcustom-atomic-properties
2454      -Wdangling-field
2455      -Wdangling-initializer-list
2456      -Wdate-time
2457      -Wdelegating-ctor-cycles
2458      -Wdeprecated-implementations
2459      -Wdeprecated-register
2460      -Wdirect-ivar-access
2461      -Wdiscard-qual
2462      -Wdistributed-object-modifiers
2463      -Wdivision-by-zero
2464      -Wdollar-in-identifier-extension
2465      -Wdouble-promotion
2466      -Wduplicate-decl-specifier
2467      -Wduplicate-enum
2468      -Wduplicate-method-arg
2469      -Wduplicate-method-match
2470      -Wduplicated-cond
2471      -Wdynamic-class-memaccess
2472      -Wembedded-directive
2473      -Wempty-translation-unit
2474      -Wenum-conversion
2475      -Wexit-time-destructors
2476      -Wexplicit-ownership-type
2477      -Wextern-initializer
2478      -Wextra
2479      -Wextra-semi
2480      -Wextra-tokens
2481      -Wflexible-array-extensions
2482      -Wfloat-conversion
2483      -Wformat-non-iso
2484      -Wfour-char-constants
2485      -Wgcc-compat
2486      -Wglobal-constructors
2487      -Wgnu-array-member-paren-init
2488      -Wgnu-designator
2489      -Wgnu-static-float-init
2490      -Wheader-guard
2491      -Wheader-hygiene
2492      -Widiomatic-parentheses
2493      -Wignored-attributes
2494      -Wimplicit-atomic-properties
2495      -Wimplicit-conversion-floating-point-to-bool
2496      -Wimplicit-exception-spec-mismatch
2497      -Wimplicit-fallthrough
2498      -Wimplicit-fallthrough-per-function
2499      -Wimplicit-retain-self
2500      -Wimport-preprocessor-directive-pedantic
2501      -Wincompatible-library-redeclaration
2502      -Wincompatible-pointer-types-discards-qualifiers
2503      -Wincomplete-implementation
2504      -Wincomplete-module
2505      -Wincomplete-umbrella
2506      -Winit-self
2507      -Wint-conversions
2508      -Wint-to-void-pointer-cast
2509      -Winteger-overflow
2510      -Winvalid-constexpr
2511      -Winvalid-iboutlet
2512      -Winvalid-noreturn
2513      -Winvalid-pp-token
2514      -Winvalid-source-encoding
2515      -Winvalid-token-paste
2516      -Wknr-promoted-parameter
2517      -Wlarge-by-value-copy
2518      -Wliteral-conversion
2519      -Wliteral-range
2520      -Wlocal-type-template-args
2521      -Wlogical-op
2522      -Wloop-analysis
2523      -Wmain-return-type
2524      -Wmalformed-warning-check
2525      -Wmethod-signatures
2526      -Wmicrosoft
2527      -Wmicrosoft-exists
2528      -Wmismatched-parameter-types
2529      -Wmismatched-return-types
2530      -Wmissing-field-initializers
2531      -Wmissing-format-attribute
2532      -Wmissing-noreturn
2533      -Wmissing-selector-name
2534      -Wmissing-sysroot
2535      -Wmissing-variable-declarations
2536      -Wmodule-conflict
2537      -Wnested-anon-types
2538      -Wnewline-eof
2539      -Wnon-literal-null-conversion
2540      -Wnon-pod-varargs
2541      -Wnonportable-cfstrings
2542      -Wnormalized=nfkc
2543      -Wnull-arithmetic
2544      -Wnull-character
2545      -Wnull-conversion
2546      -Wnull-dereference
2547      -Wout-of-line-declaration
2548      -Wover-aligned
2549      -Woverlength-strings
2550      -Woverride-init
2551      -Woverriding-method-mismatch
2552      -Wpointer-type-mismatch
2553      -Wpredefined-identifier-outside-function
2554      -Wprotocol-property-synthesis-ambiguity
2555      -Wreadonly-iboutlet-property
2556      -Wreadonly-setter-attrs
2557      -Wreceiver-expr
2558      -Wreceiver-forward-class
2559      -Wreceiver-is-weak
2560      -Wreinterpret-base-class
2561      -Wrequires-super-attribute
2562      -Wreserved-user-defined-literal
2563      -Wreturn-stack-address
2564      -Wsection
2565      -Wselector-type-mismatch
2566      -Wsentinel
2567      -Wserialized-diagnostics
2568      -Wshadow
2569      -Wshift-count-negative
2570      -Wshift-count-overflow
2571      -Wshift-negative-value
2572      -Wshift-overflow=2
2573      -Wshift-sign-overflow
2574      -Wshorten-64-to-32
2575      -Wsizeof-array-argument
2576      -Wsource-uses-openmp
2577      -Wstatic-float-init
2578      -Wstatic-in-inline
2579      -Wstatic-local-in-inline
2580      -Wstrict-overflow=1
2581      -Wstring-compare
2582      -Wstring-conversion
2583      -Wstrlcpy-strlcat-size
2584      -Wstrncat-size
2585      -Wsuggest-attribute=format
2586      -Wsuggest-attribute=noreturn
2587      -Wsuper-class-method-mismatch
2588      -Wswitch-bool
2589      -Wsync-nand
2590      -Wtautological-constant-out-of-range-compare
2591      -Wtentative-definition-incomplete-type
2592      -Wtrampolines
2593      -Wtype-safety
2594      -Wtypedef-redefinition
2595      -Wtypename-missing
2596      -Wundefined-inline
2597      -Wundefined-internal
2598      -Wundefined-reinterpret-cast
2599      -Wunicode
2600      -Wunicode-whitespace
2601      -Wunknown-warning-option
2602      -Wunnamed-type-template-args
2603      -Wunneeded-member-function
2604      -Wunsequenced
2605      -Wunsupported-visibility
2606      -Wunused-but-set-parameter
2607      -Wunused-but-set-variable
2608      -Wunused-command-line-argument
2609      -Wunused-const-variable=2
2610      -Wunused-exception-parameter
2611      -Wunused-local-typedefs
2612      -Wunused-member-function
2613      -Wunused-sanitize-argument
2614      -Wunused-volatile-lvalue
2615      -Wuser-defined-literals
2616      -Wvariadic-macros
2617      -Wvector-conversion
2618      -Wvector-conversions
2619      -Wvexing-parse
2620      -Wvisibility
2621      -Wvla-extension
2622      -Wzero-length-array
2623   ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2624               [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2625      ])
2627 dnl    We should re-enable this in some later version.  Clang doesn't
2628 dnl    mind, but it causes trouble with GCC.
2629 dnl     -Wstrict-overflow=2
2631 dnl    These seem to require annotations that we don't currently use,
2632 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2633 dnl     -Wthread-safety
2634 dnl     -Wthread-safety-analysis
2635 dnl     -Wthread-safety-attributes
2636 dnl     -Wthread-safety-beta
2637 dnl     -Wthread-safety-precise
2639   W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2640   W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2641   W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2642   W_FLAGS="$W_FLAGS -Wwrite-strings"
2643   W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2644   W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2645   W_FLAGS="$W_FLAGS -Wunused-parameter "
2646   # These interfere with building main() { return 0; }, which autoconf
2647   # likes to use as its default program.
2648   W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2650   TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2651   CFLAGS="$CFLAGS $W_FLAGS"
2653   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2654     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2655   fi
2656   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2657     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2658   fi
2659   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2660     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2661   fi
2663   CFLAGS="$CFLAGS_NOWARNINGS"
2665   if test "x$enable_fatal_warnings" = "xyes"; then
2666     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2667     # default autoconf programs are full of errors.
2668     CFLAGS="$CFLAGS -Werror"
2669   fi
2673 AC_SUBST(TOR_WARNING_FLAGS)
2675 echo "$TOR_WARNING_FLAGS">warning_flags
2677 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2678                             CFLAGS="$CFLAGS @warning_flags",
2679                             CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2681 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2682    case "$host_os" in
2683     darwin*)
2684       tor_incr_n_warnings
2685       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.])
2686    esac
2689 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2691 AC_CONFIG_FILES([
2692         Doxyfile
2693         Makefile
2694         config.rust
2695         contrib/operator-tools/tor.logrotate
2696         src/config/torrc.sample
2697         src/config/torrc.minimal
2698         src/rust/.cargo/config
2699         scripts/maint/checkOptionDocs.pl
2700         warning_flags
2703 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2704   regular_mans="doc/man/tor doc/man/tor-gencert doc/man/tor-resolve doc/man/torify"
2705   for file in $regular_mans ; do
2706     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2707       echo "==================================";
2708       echo;
2709       echo "Building Tor has failed since manpages cannot be built.";
2710       echo;
2711       echo "You need asciidoc installed to be able to build the manpages.";
2712       echo "To build without manpages, use the --disable-asciidoc argument";
2713       echo "when calling configure.";
2714       echo;
2715       echo "==================================";
2716       exit 1;
2717     fi
2718   done
2721 if test "$fragile_hardening" = "yes"; then
2722   tor_incr_n_warnings
2723   AC_MSG_WARN([
2725 ============
2726 Warning!  Building Tor with --enable-fragile-hardening (also known as
2727 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2728 other kinds of attacks easier. A Tor instance build with this option will be
2729 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2730 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2731 denial of service attacks. For more information, see
2732 https://gitlab.torproject.org/tpo/core/team/-/wikis/TorFragileHardening
2733 ============
2734   ])
2737 AC_OUTPUT
2739 if test "$openssl_ver_mismatch" = "yes"; then
2740    tor_incr_n_warnings
2741    AC_MSG_WARN([
2742 ============
2743 Warning! The version OpenSSL headers we get from compiling with
2744     "${TOR_CPPFLAGS_OPENSSL:-(no extra options)}"
2745 do not match version of the OpenSSL library we get when linking with
2746     "$TOR_LDFLAGS_OPENSSL $TOR_OPENSSL_LIBS".
2747 This might cause compilation to fail. Try using --with-openssl-dir to specify
2748 the exact OpenSSL path you want.
2749 ============
2754 # Mini-report on what will be built.
2757 PPRINT_INIT
2758 PPRINT_SET_INDENT(1)
2759 PPRINT_SET_TS(65)
2761 AS_ECHO
2762 AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
2763 AS_ECHO
2765 PPRINT_SUBTITLE([Build Features])
2767 PPRINT_PROP_STRING([Compiler], [$CC])
2768 PPRINT_PROP_STRING([Host OS], [$host_os])
2769 AS_ECHO
2771 test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
2772 PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
2774 test "x$enable_rust" = "xyes" && value=1 || value=0
2775 PPRINT_PROP_BOOL([Rust support (--enable-rust)], $value)
2777 test "x$enable_cargo_online_mode" = "xyes" && value=1 || value=0
2778 PPRINT_PROP_BOOL([Cargo Online Fetch (--enable-cargo-online-mode)], $value)
2780 test "x$enable_android" = "xyes" && value=1 || value=0
2781 PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
2783 AS_ECHO
2784 PPRINT_SUBTITLE([Static Build])
2786 test "x$enable_static_tor" = "xyes" && value=1 || value=0
2787 PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
2789 if test "x$enable_static_libevent" = "xyes"; then
2790   PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
2791 else
2792   PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
2795 if test "x$enable_static_openssl" = "xyes"; then
2796   PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
2797 else
2798   PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
2801 if test "x$enable_static_zlib" = "xyes"; then
2802   PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
2803 else
2804   PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
2807 AS_ECHO
2808 PPRINT_SUBTITLE([Optional Libraries])
2810 test "x$enable_nss" = "xyes" && value=1 || value=0
2811 PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
2813 test "x$enable_seccomp" != "xno" && value=1 || value=0
2814 PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
2816 test "x$enable_libscrypt" != "xno" && value=1 || value=0
2817 PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
2819 test "x$enable_systemd" = "xyes" && value=1 || value=0
2820 PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
2822 test "x$have_lzma" = "xyes" && value=1 || value=0
2823 PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
2825 test "x$have_zstd" = "xyes" && value=1 || value=0
2826 PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
2828 AS_ECHO
2829 PPRINT_SUBTITLE([Hardening])
2831 test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
2832 PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
2834 test "x$enable_linker_hardening" != "xno" && value=1 || value=0
2835 PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
2837 test "x$fragile_hardening" = "xyes" && value=1 || value=0
2838 PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
2840 AS_ECHO
2841 PPRINT_SUBTITLE([Modules])
2843 m4_foreach_w([mname], MODULES,
2844   [
2845     AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
2846     m4_set_contains([MODULES_WITH_NO_OPTIONS], mname,
2847                     PPRINT_PROP_BOOL([mname], $value),
2848                     PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value))
2849   ]
2852 AS_ECHO
2853 PPRINT_SUBTITLE([Documentation])
2855 test "x$enable_asciidoc" != "xno" && value=1 || value=0
2856 PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
2858 test "x$enable_manpage" != "xno" && value=1 || value=0
2859 PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
2861 test "x$enable_html_manual" != "xno" && value=1 || value=0
2862 PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
2864 AS_ECHO
2865 PPRINT_SUBTITLE([Tests])
2867 test "x$enable_unittests" != "xno" && value=1 || value=0
2868 PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
2870 test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
2871 PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
2873 test "x$enable_coverage" = "xyes" && value=1 || value=0
2874 PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
2876 test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
2877 PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
2879 test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
2880 PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
2882 AS_ECHO
2883 PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
2885 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
2886 PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
2888 test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
2889 PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
2891 test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
2892 PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
2894 AS_ECHO
2895 PPRINT_SUBTITLE([Install Directories])
2897 report_mandir="`eval eval echo $mandir`"
2898 PPRINT_PROP_STRING([Binaries], [$BINDIR])
2899 PPRINT_PROP_STRING([Configuration], [$CONFDIR])
2900 PPRINT_PROP_STRING([Man Pages], [$report_mandir])
2902 AS_ECHO
2903 AS_ECHO(["Configure Line: ./configure $configure_flags"])
2905 if test "$tor_ac_n_warnings" != "0"; then
2906   AS_ECHO
2907   PPRINT_WARN([
2908 Encountered $tor_ac_n_warnings warning(s). See messages above for more info.
2909   ])