Bump to 0.4.7.0-alpha-dev
[tor.git] / configure.ac
blob563d5afaf6bb1b8ca3b7d011490aefc1381a35ca
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
457 AC_PROG_CC_C99
459 AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
460    [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
461         python3 \
462         python3.8 python3.7 python3.6 python3.5 python3.4 \
463         python ],
464    [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
465 AC_SUBST([PYTHON], [$tor_cv_PYTHON])
467 PYTHON="$tor_cv_PYTHON"
469 if test "x$PYTHON" = "x"; then
470   tor_incr_n_warnings
471   AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
474 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
476 dnl List all external rust crates we depend on here. Include the version
477 rust_crates=" \
478     digest-0.7.2 \
479     libc-0.2.39 \
481 AC_SUBST(rust_crates)
483 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
484 AC_C_FLEXIBLE_ARRAY_MEMBER
485 ], [
486  dnl Maybe we've got an old autoconf...
487  AC_CACHE_CHECK([for flexible array members],
488      tor_cv_c_flexarray,
489      [AC_COMPILE_IFELSE(
490        AC_LANG_PROGRAM([
491  struct abc { int a; char b[]; };
492 ], [
493  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
494  def->b[0] = 33;
496   [tor_cv_c_flexarray=yes],
497   [tor_cv_c_flexarray=no])])
498  if test "$tor_cv_flexarray" = "yes"; then
499    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
500  else
501    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
502  fi
505 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
506       tor_cv_c_c99_decl,
507       [AC_COMPILE_IFELSE(
508          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
509          [tor_cv_c_c99_decl=yes],
510          [tor_cv_c_c99_decl=no] )])
511 if test "$tor_cv_c_c99_decl" != "yes"; then
512   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
515 AC_CACHE_CHECK([for working C99 designated initializers],
516       tor_cv_c_c99_designated_init,
517       [AC_COMPILE_IFELSE(
518          [AC_LANG_PROGRAM([struct s { int a; int b; };],
519                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
520          [tor_cv_c_c99_designated_init=yes],
521          [tor_cv_c_c99_designated_init=no] )])
523 if test "$tor_cv_c_c99_designated_init" != "yes"; then
524   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
527 saved_CFLAGS="$CFLAGS"
528 CFLAGS="$CFLAGS -Werror"
529 AC_CACHE_CHECK([for __attribute__((fallthrough))],
530       tor_cv_c_attr_fallthrough,
531       [AC_COMPILE_IFELSE(
532          [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
533                [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
534                                case 2: fn(); break; } ]])],
535          [tor_cv_c_attr_fallthrough=yes],
536          [tor_cv_c_attr_fallthrough=no] )])
537 CFLAGS="$saved_CFLAGS"
539 if test "$tor_cv_c_attr_fallthrough" = "yes"; then
540   AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
543 TORUSER=_tor
544 AC_ARG_WITH(tor-user,
545         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
546         [
547            TORUSER=$withval
548         ]
550 AC_SUBST(TORUSER)
552 TORGROUP=_tor
553 AC_ARG_WITH(tor-group,
554         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
555         [
556            TORGROUP=$withval
557         ]
559 AC_SUBST(TORGROUP)
562 dnl If _WIN32 is defined and non-zero, we are building for win32
563 AC_MSG_CHECKING([for win32])
564 AC_RUN_IFELSE([AC_LANG_SOURCE([
565 int main(int c, char **v) {
566 #ifdef _WIN32
567 #if _WIN32
568   return 0;
569 #else
570   return 1;
571 #endif
572 #else
573   return 2;
574 #endif
575 }])],
576 bwin32=true; AC_MSG_RESULT([yes]),
577 bwin32=false; AC_MSG_RESULT([no]),
578 bwin32=cross; AC_MSG_RESULT([cross])
581 if test "$bwin32" = "cross"; then
582 AC_MSG_CHECKING([for win32 (cross)])
583 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
584 #ifdef _WIN32
585 int main(int c, char **v) {return 0;}
586 #else
587 #error
588 int main(int c, char **v) {return x(y);}
589 #endif
590 ])],
591 bwin32=true; AC_MSG_RESULT([yes]),
592 bwin32=false; AC_MSG_RESULT([no]))
595 AH_BOTTOM([
596 #ifdef _WIN32
597 /* Defined to access windows functions and definitions for >=WinVista */
598 # ifndef WINVER
599 #  define WINVER 0x0600
600 # endif
602 /* Defined to access _other_ windows functions and definitions for >=WinVista */
603 # ifndef _WIN32_WINNT
604 #  define _WIN32_WINNT 0x0600
605 # endif
607 /* Defined to avoid including some windows headers as part of Windows.h */
608 # ifndef WIN32_LEAN_AND_MEAN
609 #  define WIN32_LEAN_AND_MEAN 1
610 # endif
611 #endif
614 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
615 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
616 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
618 dnl Enable C99 when compiling with MIPSpro
619 AC_MSG_CHECKING([for MIPSpro compiler])
620 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
621 #if (defined(__sgi) && defined(_COMPILER_VERSION))
622 #error
623   return x(y);
624 #endif
625 ])],
626 bmipspro=false; AC_MSG_RESULT(no),
627 bmipspro=true; AC_MSG_RESULT(yes))
629 if test "$bmipspro" = "true"; then
630   CFLAGS="$CFLAGS -c99"
633 AC_C_BIGENDIAN
635 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
637 if test "x$enable_rust" = "xyes"; then
638   AC_ARG_VAR([RUSTC], [path to the rustc binary])
639   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
640   if test "x$RUSTC" = "xno"; then
641     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
642   fi
644   AC_ARG_VAR([CARGO], [path to the cargo binary])
645   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
646   if test "x$CARGO" = "xno"; then
647     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
648   fi
650   AC_DEFINE([HAVE_RUST], 1, [have Rust])
651   if test "x$enable_fatal_warnings" = "xyes"; then
652     RUST_WARN=
653   else
654     RUST_WARN=#
655   fi
656   if test "x$enable_cargo_online_mode" = "xyes"; then
657     CARGO_ONLINE=
658     RUST_DL=#
659   else
660     CARGO_ONLINE=--frozen
661     RUST_DL=
663     dnl When we're not allowed to touch the network, we need crate dependencies
664     dnl locally available.
665     AC_MSG_CHECKING([rust crate dependencies])
666     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
667     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
668       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
669     fi
670     dnl Check whether the path exists before we try to cd into it.
671     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
672       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.])
673       ERRORED=1
674     fi
675     dnl Make the path absolute, since we'll be using it from within a
676     dnl subdirectory.
677     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
679     for dep in $rust_crates; do
680       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
681         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.])
682         ERRORED=1
683       fi
684     done
685     if test "x$ERRORED" = "x"; then
686       AC_MSG_RESULT([yes])
687     fi
688   fi
690   dnl For now both MSVC and MinGW rust libraries will output static libs with
691   dnl the MSVC naming convention.
692   if test "$bwin32" = "true"; then
693     tor_rust_static_name=tor_rust.lib
694   else
695     tor_rust_static_name=libtor_rust.a
696   fi
698   AC_CANONICAL_BUILD
700   if test -n "$TOR_RUST_TARGET"; then
701     if test "$host" = "$build"; then
702       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
703     fi
704     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
705     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
706   else
707     if test "$host" != "$build"; then
708       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
709     fi
710     RUST_TARGET_PROP=
711     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
712   fi
714   AC_SUBST(RUST_TARGET_PROP)
715   AC_SUBST(TOR_RUST_LIB_PATH)
716   AC_SUBST(CARGO_ONLINE)
717   AC_SUBST(RUST_WARN)
718   AC_SUBST(RUST_DL)
720   dnl Let's check the rustc version, too
721   AC_MSG_CHECKING([rust version])
722   RUSTC_VERSION=`$RUSTC --version`
723   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
724   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
725   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
726     AC_MSG_ERROR([rustc version couldn't be identified])
727   fi
728   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 31; then
729     AC_MSG_ERROR([rustc must be at least version 1.31.0])
730   fi
731   AC_MSG_RESULT([$RUSTC_VERSION])
734 AC_SEARCH_LIBS(socket, [socket network])
735 AC_SEARCH_LIBS(gethostbyname, [nsl])
736 AC_SEARCH_LIBS(dlopen, [dl])
737 AC_SEARCH_LIBS(inet_aton, [resolv])
738 AC_SEARCH_LIBS(backtrace, [execinfo])
739 saved_LIBS="$LIBS"
740 AC_SEARCH_LIBS([clock_gettime], [rt])
741 if test "$LIBS" != "$saved_LIBS"; then
742    # Looks like we need -lrt for clock_gettime().
743    have_rt=yes
746 if test "$bwin32" = "false"; then
747   AC_SEARCH_LIBS(pthread_create, [pthread])
748   AC_SEARCH_LIBS(pthread_detach, [pthread])
751 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
752 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
754 AC_CHECK_FUNCS(
755         _NSGetEnviron \
756         RtlSecureZeroMemory \
757         SecureZeroMemory \
758         accept4 \
759         backtrace \
760         backtrace_symbols_fd \
761         eventfd \
762         explicit_bzero \
763         timingsafe_memcmp \
764         flock \
765         fsync \
766         ftime \
767         get_current_dir_name \
768         getaddrinfo \
769         getdelim \
770         getifaddrs \
771         getline \
772         getrlimit \
773         gettimeofday \
774         gmtime_r \
775         gnu_get_libc_version \
776         inet_aton \
777         ioctl \
778         issetugid \
779         llround \
780         localtime_r \
781         lround \
782         madvise \
783         memmem \
784         memset_s \
785         minherit \
786         mmap \
787         pipe \
788         pipe2 \
789         prctl \
790         readpassphrase \
791         rint \
792         sigaction \
793         socketpair \
794         statvfs \
795         strncasecmp \
796         strcasecmp \
797         strlcat \
798         strlcpy \
799         strnlen \
800         strptime \
801         strtok_r \
802         strtoull \
803         sysconf \
804         sysctl \
805         truncate \
806         uname \
807         usleep \
808         vasprintf \
809         _vscprintf
812 # Apple messed up when they added some functions: they
813 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
814 # checks.
816 # We should only probe for these functions if we are sure that we
817 # are not targeting OS X 10.9 or earlier.
818 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
819 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
820 #ifdef __APPLE__
821 #  include <AvailabilityMacros.h>
822 #  ifndef MAC_OS_X_VERSION_10_10
823 #    define MAC_OS_X_VERSION_10_10 101000
824 #  endif
825 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
826 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
827 #      error "Running on Mac OS X 10.9 or earlier"
828 #    endif
829 #  endif
830 #endif
831 ]], [[]])],
832    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
833    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
835 if test "$on_macos_pre_10_10" = "no"; then
836   AC_CHECK_FUNCS(
837         mach_approximate_time \
838   )
841 # We should only probe for these functions if we are sure that we
842 # are not targeting OSX 10.11 or earlier.
843 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
844 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
845 #ifdef __APPLE__
846 #  include <AvailabilityMacros.h>
847 #  ifndef MAC_OS_X_VERSION_10_12
848 #    define MAC_OS_X_VERSION_10_12 101200
849 #  endif
850 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
851 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
852 #      error "Running on Mac OSX 10.11 or earlier"
853 #    endif
854 #  endif
855 #endif
856 ]], [[]])],
857    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
858    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
860 if test "$on_macos_pre_10_12" = "no"; then
861   AC_CHECK_FUNCS(
862         clock_gettime \
863         getentropy \
864   )
867 if test "$bwin32" != "true"; then
868   AC_CHECK_HEADERS(pthread.h)
869   AC_CHECK_FUNCS(pthread_create)
870   AC_CHECK_FUNCS(pthread_condattr_setclock)
873 if test "$bwin32" = "true"; then
874   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
875 #include <windows.h>
876 #include <conio.h>
877 #include <wchar.h>
878                  ])
881 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
882   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
884 AC_CHECK_FUNCS(glob)
886 AC_MSG_CHECKING([whether free(NULL) works])
887 AC_RUN_IFELSE([AC_LANG_PROGRAM([
888   #include <stdlib.h>
889 ], [
890 char *p = NULL;
891 free(p);
892 ])],
893 [free_null_ok=true; AC_MSG_RESULT(yes)],
894 [free_null_ok=false; AC_MSG_RESULT(no)],
895 [free_null_ok=cross; AC_MSG_RESULT(cross)])
897 if test "$free_null_ok" = "false"; then
898    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
901 dnl ------------------------------------------------------
902 dnl Where do you live, libevent?  And how do we call you?
904 if test "$bwin32" = "true"; then
905   TOR_LIB_WS32=-lws2_32
906   TOR_LIB_IPHLPAPI=-liphlpapi
907   TOR_LIB_SHLWAPI=-lshlwapi
908   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
909   # think it's actually necessary.
910   TOR_LIB_GDI=-lgdi32
911   TOR_LIB_USERENV=-luserenv
912   TOR_LIB_BCRYPT=-lbcrypt
913   TOR_LIB_CRYPT32=-lcrypt32
914 else
915   TOR_LIB_WS32=
916   TOR_LIB_GDI=
917   TOR_LIB_USERENV=
919 AC_SUBST(TOR_LIB_WS32)
920 AC_SUBST(TOR_LIB_GDI)
921 AC_SUBST(TOR_LIB_IPHLPAPI)
922 AC_SUBST(TOR_LIB_BCRYPT)
923 AC_SUBST(TOR_LIB_CRYPT32)
924 AC_SUBST(TOR_LIB_SHLWAPI)
925 AC_SUBST(TOR_LIB_USERENV)
927 tor_libevent_pkg_redhat="libevent"
928 tor_libevent_pkg_debian="libevent-dev"
929 tor_libevent_devpkg_redhat="libevent-devel"
930 tor_libevent_devpkg_debian="libevent-dev"
932 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
933 dnl linking for static builds.
934 STATIC_LIBEVENT_FLAGS=""
935 if test "$enable_static_libevent" = "yes"; then
936     if test "$have_rt" = "yes"; then
937       STATIC_LIBEVENT_FLAGS=" -lrt "
938     fi
941 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_IPHLPAPI $TOR_LIB_BCRYPT $TOR_LIB_WS32], [
942 #ifdef _WIN32
943 #include <winsock2.h>
944 #endif
945 #include <sys/time.h>
946 #include <sys/types.h>
947 #include <event2/event.h>], [
948 #ifdef _WIN32
949 #include <winsock2.h>
950 #endif
951 struct event_base;
952 struct event_base *event_base_new(void);
953 void event_base_free(struct event_base *);],
954     [
955 #ifdef _WIN32
956 {WSADATA d; WSAStartup(0x101,&d); }
957 #endif
958 event_base_free(event_base_new());
959 ], [--with-libevent-dir], [/opt/libevent])
961 dnl Determine the incantation needed to link libevent.
962 save_LIBS="$LIBS"
963 save_LDFLAGS="$LDFLAGS"
964 save_CPPFLAGS="$CPPFLAGS"
966 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
967 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
968 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
970 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
972 if test "$enable_static_libevent" = "yes"; then
973    if test "$tor_cv_library_libevent_dir" = "(system)"; then
974      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
975    else
976      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
977    fi
978 else
979      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
980        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
981        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"))
983        if test "$ac_cv_search_event_new" != "none required"; then
984          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
985        fi
986        if test "$ac_cv_search_evdns_base_new" != "none required"; then
987          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
988        fi
989      else
990        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
991      fi
994 dnl Now check for particular libevent functions.
995 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
996                 evutil_secure_rng_add_bytes \
997                 evdns_base_get_nameserver_addr \
1001 LIBS="$save_LIBS"
1002 LDFLAGS="$save_LDFLAGS"
1003 CPPFLAGS="$save_CPPFLAGS"
1005 dnl Check that libevent is at least at version 2.0.10, the first stable
1006 dnl release of its series
1007 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
1008 AC_MSG_CHECKING([whether Libevent is new enough])
1009 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1010 #include <event2/event.h>
1011 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
1012 #error
1013 int x = y(zz);
1014 #else
1015 int x = 1;
1016 #endif
1017 ])], [ AC_MSG_RESULT([yes]) ],
1018    [ AC_MSG_RESULT([no])
1019      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
1021 LIBS="$save_LIBS"
1022 LDFLAGS="$save_LDFLAGS"
1023 CPPFLAGS="$save_CPPFLAGS"
1025 AC_SUBST(TOR_LIBEVENT_LIBS)
1027 dnl ------------------------------------------------------
1028 dnl Where do you live, libm?
1030 dnl On some platforms (Haiku/BeOS) the math library is
1031 dnl part of libroot. In which case don't link against lm
1032 TOR_LIB_MATH=""
1033 save_LIBS="$LIBS"
1034 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
1035 if test "$ac_cv_search_pow" != "none required"; then
1036     TOR_LIB_MATH="$ac_cv_search_pow"
1038 LIBS="$save_LIBS"
1039 AC_SUBST(TOR_LIB_MATH)
1041 dnl ------------------------------------------------------
1042 dnl Hello, NSS.  You're new around here.
1043 if test "x$enable_nss" = "xyes"; then
1044   PKG_CHECK_MODULES(NSS,
1045      [nss],
1046      [have_nss=yes],
1047      [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.])])
1048   AC_SUBST(NSS_CFLAGS)
1049   AC_SUBST(NSS_LIBS)
1052 dnl ------------------------------------------------------
1053 dnl Where do you live, openssl?  And how do we call you?
1055 if test "x$enable_nss" != "xyes"; then
1057 tor_openssl_pkg_redhat="openssl"
1058 tor_openssl_pkg_debian="libssl-dev"
1059 tor_openssl_devpkg_redhat="openssl-devel"
1060 tor_openssl_devpkg_debian="libssl-dev"
1062 ALT_openssl_WITHVAL=""
1063 AC_ARG_WITH(ssl-dir,
1064   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
1065   [
1066       if test "x$withval" != "xno" && test "x$withval" != "x"; then
1067          ALT_openssl_WITHVAL="$withval"
1068       fi
1069   ])
1071 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
1072 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32 $TOR_LIB_CRYPT32],
1073     [#include <openssl/ssl.h>
1074      char *getenv(const char *);],
1075     [struct ssl_cipher_st;
1076      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
1077      char *getenv(const char *);],
1078     dnl This funny-looking test program calls getenv, so that the compiler
1079     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
1080     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
1081     dnl We look for SSL_cipher_get_id() because it is present in
1082     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
1083     dnl depends on it.
1084     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
1085     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
1087 if test "$enable_static_openssl" = "yes"; then
1088    if test "$tor_cv_library_openssl_dir" = "(system)"; then
1089      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
1090    else
1091      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a $TOR_LIB_WS32 $TOR_LIB_CRYPT32 $TOR_LIB_BCRYPT"
1092    fi
1093 else
1094      TOR_OPENSSL_LIBS="-lssl -lcrypto"
1096 AC_SUBST(TOR_OPENSSL_LIBS)
1098 dnl Now validate openssl, and check for particular openssl functions.
1099 save_LIBS="$LIBS"
1100 save_LDFLAGS="$LDFLAGS"
1101 save_CPPFLAGS="$CPPFLAGS"
1102 LIBS="$TOR_OPENSSL_LIBS $LIBS"
1103 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
1104 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
1106 dnl Tor currently uses a number of APIs that are deprecated in OpenSSL 3.0.0
1107 dnl and later.  We want to migrate away from them, but that will be a lot of
1108 dnl work. (See ticket tor#40166.)  For now, we disable the deprecation
1109 dnl warnings.
1111 AC_MSG_CHECKING([for OpenSSL >= 3.0.0])
1112 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1113 #include <openssl/opensslv.h>
1114 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER <= 0x30000000L
1115 #error "you_have_version_3"
1116 #endif
1117    ]], [[]])],
1118    [ AC_MSG_RESULT([no]) ],
1119    [ AC_MSG_RESULT([yes]);
1120      AC_DEFINE(OPENSSL_SUPPRESS_DEPRECATED, 1, [disable openssl deprecated-function warnings]) ])
1122 AC_MSG_CHECKING([for OpenSSL < 1.0.1])
1123 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1124 #include <openssl/opensslv.h>
1125 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
1126 #error "too old"
1127 #endif
1128    ]], [[]])],
1129    [ AC_MSG_RESULT([no]) ],
1130    [ 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.]) ])
1132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1133 #include <openssl/opensslv.h>
1134 #include <openssl/evp.h>
1135 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
1136 #error "no ECC"
1137 #endif
1138 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
1139 #error "curves unavailable"
1140 #endif
1141    ]], [[]])],
1142    [ : ],
1143    [ 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.]) ])
1145 dnl Let's see if we have a version mismatch between includes and libs.
1146 AC_MSG_CHECKING([for significant mismatch between openssl headers and libraries])
1147 ac_retval=foo
1148 AC_RUN_IFELSE([AC_LANG_SOURCE([AC_LANG_PROGRAM([[
1149  #include <openssl/opensslv.h>
1150  #include <openssl/crypto.h>
1151 ]], [[
1152   /* Include major, minor, and fix, but not patch or status. */
1153   unsigned long mask = 0xfffff000;
1154   unsigned long linking = OpenSSL_version_num() & mask;
1155   unsigned long running = OPENSSL_VERSION_NUMBER & mask;
1156   return !(linking==running);
1157 ]])])], [openssl_ver_mismatch=no], [
1158    # This is a kludge to figure out whether compilation failed, or whether
1159    # running the program failed.
1160    if test "$ac_retval" = "1"; then
1161       openssl_ver_mismatch=inconclusive
1162    else
1163       openssl_ver_mismatch=yes
1164    fi], [openssl_ver_mismatch=cross])
1165 AC_MSG_RESULT([$openssl_ver_mismatch])
1167 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
1168 [#include <openssl/ssl.h>
1171 dnl OpenSSL functions which we might not have.  In theory, we could just
1172 dnl check the openssl version number, but in practice that gets pretty
1173 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
1174 dnl to them.
1175 AC_CHECK_FUNCS([ \
1176                 ERR_load_KDF_strings \
1177                 EVP_PBE_scrypt \
1178                 SSL_CIPHER_find \
1179                 SSL_CTX_set1_groups_list \
1180                 SSL_CTX_set_security_level \
1181                 SSL_SESSION_get_master_key \
1182                 SSL_get_client_ciphers \
1183                 SSL_get_client_random \
1184                 SSL_get_server_random \
1185                 TLS_method \
1186                ])
1188 dnl Check if OpenSSL structures are opaque
1189 AC_CHECK_MEMBERS([SSL.state], , ,
1190 [#include <openssl/ssl.h>
1193 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
1194 #include <openssl/sha.h>
1197 fi # enable_nss
1199 dnl We will someday make KECCAK_TINY optional, but for now we still need
1200 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
1201 dnl once.  See comment in the definition of crypto_xof_t.
1203 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
1204 dnl   test "x$ac_cv_func_EVP_sha3_256" != "xyes")
1206 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
1208 dnl ======================================================================
1209 dnl Can we use KIST?
1211 dnl Define the set of checks for KIST scheduler support.
1212 AC_DEFUN([CHECK_KIST_SUPPORT],[
1213   dnl KIST needs struct tcp_info and for certain members to exist.
1214   AC_CHECK_MEMBERS(
1215     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1216     , ,[[#include <netinet/tcp.h>]])
1217   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1218   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1219                      #include <linux/sockios.h>
1220                      #ifndef SIOCOUTQNSD
1221                      #error
1222                      #endif
1223                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1224   if test "x$have_siocoutqnsd" = "xyes"; then
1225     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1226       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1227         have_kist_support=yes
1228       fi
1229     fi
1230   fi
1232 dnl Now, trigger the check.
1233 CHECK_KIST_SUPPORT
1234 AS_IF([test "x$have_kist_support" = "xyes"],
1235       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1236                                         on this system])],
1237       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1239 LIBS="$save_LIBS"
1240 LDFLAGS="$save_LDFLAGS"
1241 CPPFLAGS="$save_CPPFLAGS"
1243 dnl ------------------------------------------------------
1244 dnl Where do you live, zlib?  And how do we call you?
1246 tor_zlib_pkg_redhat="zlib"
1247 tor_zlib_pkg_debian="zlib1g"
1248 tor_zlib_devpkg_redhat="zlib-devel"
1249 tor_zlib_devpkg_debian="zlib1g-dev"
1251 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1252     [#include <zlib.h>],
1253     [const char * zlibVersion(void);],
1254     [zlibVersion();], [--with-zlib-dir],
1255     [/opt/zlib])
1257 if test "$enable_static_zlib" = "yes"; then
1258    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1259      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1260  using --enable-static-zlib")
1261    else
1262      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1263    fi
1264 else
1265      TOR_ZLIB_LIBS="-lz"
1267 AC_SUBST(TOR_ZLIB_LIBS)
1269 dnl ------------------------------------------------------
1270 dnl Where we do we find lzma?
1272 AC_ARG_ENABLE(lzma,
1273       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1274       [case "${enableval}" in
1275         "yes") ;;
1276         "no")  ;;
1277         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1278       esac], [enable_lzma=auto])
1280 if test "x$enable_lzma" = "xno"; then
1281     have_lzma=no;
1282 else
1283     PKG_CHECK_MODULES([LZMA],
1284                       [liblzma],
1285                       have_lzma=yes,
1286                       have_lzma=no)
1288     if test "x$have_lzma" = "xno" ; then
1289         tor_incr_n_warnings
1290         AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
1291     fi
1294 if test "x$have_lzma" = "xyes"; then
1295     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1296     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1297     TOR_LZMA_LIBS="${LZMA_LIBS}"
1299 AC_SUBST(TOR_LZMA_CFLAGS)
1300 AC_SUBST(TOR_LZMA_LIBS)
1302 dnl ------------------------------------------------------
1303 dnl Where we do we find zstd?
1305 AC_ARG_ENABLE(zstd,
1306       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1307       [case "${enableval}" in
1308         "yes") ;;
1309         "no")  ;;
1310         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1311       esac], [enable_zstd=auto])
1313 if test "x$enable_zstd" = "xno"; then
1314     have_zstd=no;
1315 else
1316     PKG_CHECK_MODULES([ZSTD],
1317                       [libzstd >= 1.1],
1318                       have_zstd=yes,
1319                       have_zstd=no)
1321     if test "x$have_zstd" = "xno" ; then
1322         tor_incr_n_warnings
1323         AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
1324     fi
1327 if test "x$have_zstd" = "xyes"; then
1328     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1329     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1330     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1332     dnl now check for zstd functions
1333     save_LIBS="$LIBS"
1334     save_CFLAGS="$CFLAGS"
1335     LIBS="$LIBS $ZSTD_LIBS"
1336     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1337     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1338                    ZSTD_estimateDCtxSize)
1339     LIBS="$save_LIBS"
1340     CFLAGS="$save_CFLAGS"
1342 AC_SUBST(TOR_ZSTD_CFLAGS)
1343 AC_SUBST(TOR_ZSTD_LIBS)
1345 dnl ----------------------------------------------------------------------
1346 dnl Check if libcap is available for capabilities.
1348 tor_cap_pkg_debian="libcap2"
1349 tor_cap_pkg_redhat="libcap"
1350 tor_cap_devpkg_debian="libcap-dev"
1351 tor_cap_devpkg_redhat="libcap-devel"
1353 AC_CHECK_LIB([cap], [cap_init], [],
1354   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1356 AC_CHECK_FUNCS(cap_set_proc)
1358 dnl ---------------------------------------------------------------------
1359 dnl Now that we know about our major libraries, we can check for compiler
1360 dnl and linker hardening options.  We need to do this with the libraries known,
1361 dnl since sometimes the linker will like an option but not be willing to
1362 dnl use it with a build of a library.
1364 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1365 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"
1367 CFLAGS_FTRAPV=
1368 CFLAGS_FWRAPV=
1369 CFLAGS_ASAN=
1370 CFLAGS_UBSAN=
1373 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1374 #if !defined(__clang__)
1375 #error
1376 #endif])], have_clang=yes, have_clang=no)
1378 if test "x$enable_pic" = "xyes"; then
1379     TOR_CHECK_CFLAGS(-fPIC)
1382 if test "x$enable_gcc_hardening" != "xno"; then
1383     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1384     if test "x$have_clang" = "xyes"; then
1385         TOR_CHECK_CFLAGS(-Qunused-arguments)
1386     fi
1387     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1388     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1389     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1390 m4_ifdef([AS_VAR_IF],[
1391     AS_VAR_IF(can_compile, [yes],
1392         AS_VAR_IF(can_link, [yes],
1393                   [],
1394                   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.)]))
1395         )])
1396     AS_VAR_POPDEF([can_link])
1397     AS_VAR_POPDEF([can_compile])
1398     TOR_CHECK_CFLAGS(-Wstack-protector)
1399     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1400     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1401        if test "$enable_pic" != "yes"; then
1402            # If we have already enabled -fPIC, then we don't also need to
1403            # compile with -fPIE...
1404            TOR_CHECK_CFLAGS(-fPIE)
1405        fi
1406        # ... but we want to link our executables with -pie in any case, since
1407        # they're executables, not a library.
1408        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1409     fi
1410     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1412    AC_MSG_CHECKING([whether we can run hardened binaries])
1413    AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1414         [AC_MSG_RESULT([yes])],
1415         [AC_MSG_RESULT([no])
1416          AC_MSG_ERROR([dnl
1417  We can link with compiler hardening options, but we can't run with them.
1418  That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1419  configure, but it would be better to figure out what the underlying problem
1420  is.])],
1421         [AC_MSG_RESULT([cross])])
1424 if test "$fragile_hardening" = "yes"; then
1425     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1426    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1427       tor_incr_n_warnings
1428       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.])
1429    fi
1431    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1432      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1433    fi
1435    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1436     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1437       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*])
1438     fi
1440    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1441     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1442       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*])
1443     fi
1445    TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1446     if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1447       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*])
1448     fi
1450 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1453 dnl Find the correct libraries to add in order to use the sanitizers.
1455 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1456 dnl option, which will prevent the compiler from linking the sanitizer
1457 dnl libraries it needs.  We need to specify them manually.
1459 dnl What's more, we need to specify them in a linker script rather than
1460 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1461 dnl variable.
1462 RUST_LINKER_OPTIONS=""
1463 if test "x$have_clang" = "xyes"; then
1464         if test "x$CFLAGS_ASAN" != "x"; then
1465                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
1466         fi
1467         if test "x$CFLAGS_UBSAN" != "x"; then
1468                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
1469         fi
1470 else
1471         if test "x$CFLAGS_ASAN" != "x"; then
1472                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
1473         fi
1474         if test "x$CFLAGS_UBSAN" != "x"; then
1475                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
1476         fi
1478 AC_SUBST(RUST_LINKER_OPTIONS)
1480 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1481 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1483 mulodi_fixes_ftrapv=no
1484 if test "$have_clang" = "yes"; then
1485   saved_CFLAGS="$CFLAGS"
1486   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1487   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1488   AC_LINK_IFELSE([
1489       AC_LANG_SOURCE([[
1490           #include <stdint.h>
1491           #include <stdlib.h>
1492           int main(int argc, char **argv)
1493           {
1494             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1495                         * (int64_t)atoi(argv[3]);
1496             return x == 9;
1497           } ]])],
1498           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1499           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1500   if test "$ftrapv_can_link" = "no"; then
1501     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1502     AC_LINK_IFELSE([
1503       AC_LANG_SOURCE([[
1504           #include <stdint.h>
1505           #include <stdlib.h>
1506           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1507              *overflow=0;
1508              return a;
1509           }
1510           int main(int argc, char **argv)
1511           {
1512             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1513                         * (int64_t)atoi(argv[3]);
1514             return x == 9;
1515           } ]])],
1516           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1517           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1518   fi
1519   CFLAGS="$saved_CFLAGS"
1522 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1524 dnl These cflags add bunches of branches, and we haven't been able to
1525 dnl persuade ourselves that they're suitable for code that needs to be
1526 dnl constant time.
1527 AC_SUBST(CFLAGS_BUGTRAP)
1528 dnl These cflags are variant ones suitable for code that needs to be
1529 dnl constant-time.
1530 AC_SUBST(CFLAGS_CONSTTIME)
1532 if test "x$enable_linker_hardening" != "xno"; then
1533     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1536 # For backtrace support
1537 TOR_CHECK_LDFLAGS(-rdynamic)
1539 dnl ------------------------------------------------------
1540 dnl Now see if we have a -fomit-frame-pointer compiler option.
1542 saved_CFLAGS="$CFLAGS"
1543 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1544 F_OMIT_FRAME_POINTER=''
1545 if test "$saved_CFLAGS" != "$CFLAGS"; then
1546   if test "$fragile_hardening" = "yes"; then
1547     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1548   fi
1550 CFLAGS="$saved_CFLAGS"
1551 AC_SUBST(F_OMIT_FRAME_POINTER)
1553 dnl ------------------------------------------------------
1554 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1555 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1556 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1557 dnl code will work.
1558 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1560 dnl ============================================================
1561 dnl Check for libseccomp
1563 if test "x$enable_seccomp" != "xno"; then
1564   AC_CHECK_HEADERS([seccomp.h])
1565   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1568 dnl ============================================================
1569 dnl Check for libscrypt
1571 if test "x$enable_libscrypt" != "xno"; then
1572   AC_CHECK_HEADERS([libscrypt.h])
1573   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1574   AC_CHECK_FUNCS([libscrypt_scrypt])
1577 dnl ============================================================
1578 dnl We need an implementation of curve25519.
1580 dnl set these defaults.
1581 build_curve25519_donna=no
1582 build_curve25519_donna_c64=no
1583 use_curve25519_donna=no
1584 use_curve25519_nacl=no
1585 CURVE25519_LIBS=
1587 dnl The best choice is using curve25519-donna-c64, but that requires
1588 dnl that we
1589 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1590   tor_cv_can_use_curve25519_donna_c64,
1591   [AC_RUN_IFELSE(
1592     [AC_LANG_PROGRAM([dnl
1593       #include <stdint.h>
1594       typedef unsigned uint128_t __attribute__((mode(TI)));
1595   int func(uint64_t a, uint64_t b) {
1596            uint128_t c = ((uint128_t)a) * b;
1597            int ok = ((uint64_t)(c>>96)) == 522859 &&
1598              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1599                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1600                  (((uint64_t)(c))&0xffffffffL) == 0;
1601            return ok;
1602       }
1603   ], [dnl
1604     int ok = func( ((uint64_t)2000000000) * 1000000000,
1605                    ((uint64_t)1234567890) << 24);
1606         return !ok;
1607       ])],
1608   [tor_cv_can_use_curve25519_donna_c64=yes],
1609       [tor_cv_can_use_curve25519_donna_c64=no],
1610   [AC_LINK_IFELSE(
1611         [AC_LANG_PROGRAM([dnl
1612       #include <stdint.h>
1613       typedef unsigned uint128_t __attribute__((mode(TI)));
1614   int func(uint64_t a, uint64_t b) {
1615            uint128_t c = ((uint128_t)a) * b;
1616            int ok = ((uint64_t)(c>>96)) == 522859 &&
1617              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1618                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1619                  (((uint64_t)(c))&0xffffffffL) == 0;
1620            return ok;
1621       }
1622   ], [dnl
1623     int ok = func( ((uint64_t)2000000000) * 1000000000,
1624                  ((uint64_t)1234567890) << 24);
1625         return !ok;
1626       ])],
1627           [tor_cv_can_use_curve25519_donna_c64=cross],
1628       [tor_cv_can_use_curve25519_donna_c64=no])])])
1630 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1631                   nacl/crypto_scalarmult_curve25519.h])
1633 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1634   tor_cv_can_use_curve25519_nacl,
1635   [tor_saved_LIBS="$LIBS"
1636    LIBS="$LIBS -lnacl"
1637    AC_LINK_IFELSE(
1638      [AC_LANG_PROGRAM([dnl
1639        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1640        #include <crypto_scalarmult_curve25519.h>
1641    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1642    #include <nacl/crypto_scalarmult_curve25519.h>
1643    #endif
1644        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1645    #error Hey, this is the reference implementation! That's not fast.
1646    #endif
1647      ], [
1648    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1649      ])], [tor_cv_can_use_curve25519_nacl=yes],
1650      [tor_cv_can_use_curve25519_nacl=no])
1651    LIBS="$tor_saved_LIBS" ])
1653  dnl Okay, now we need to figure out which one to actually use. Fall back
1654  dnl to curve25519-donna.c
1656  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1657    build_curve25519_donna_c64=yes
1658    use_curve25519_donna=yes
1659  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1660    use_curve25519_nacl=yes
1661    CURVE25519_LIBS=-lnacl
1662  else
1663    build_curve25519_donna=yes
1664    use_curve25519_donna=yes
1665  fi
1667 if test "x$use_curve25519_donna" = "xyes"; then
1668   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1669             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1671 if test "x$use_curve25519_nacl" = "xyes"; then
1672   AC_DEFINE(USE_CURVE25519_NACL, 1,
1673             [Defined if we should use a curve25519 from nacl])
1675 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1676   test "x$build_curve25519_donna" = "xyes")
1677 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1678   test "x$build_curve25519_donna_c64" = "xyes")
1679 AC_SUBST(CURVE25519_LIBS)
1681 dnl Make sure to enable support for large off_t if available.
1682 AC_SYS_LARGEFILE
1684 AC_CHECK_HEADERS([errno.h \
1685                   fcntl.h \
1686                   signal.h \
1687                   string.h \
1688                   sys/capability.h \
1689                   sys/fcntl.h \
1690                   sys/stat.h \
1691                   sys/time.h \
1692                   sys/types.h \
1693                   time.h \
1694                   unistd.h \
1695                   arpa/inet.h \
1696                   crt_externs.h \
1697                   execinfo.h \
1698                   gnu/libc-version.h \
1699                   grp.h \
1700                   ifaddrs.h \
1701                   inttypes.h \
1702                   limits.h \
1703                   linux/types.h \
1704                   mach/vm_inherit.h \
1705                   machine/limits.h \
1706                   malloc.h \
1707                   netdb.h \
1708                   netinet/in.h \
1709                   netinet/in6.h \
1710                   pwd.h \
1711                   readpassphrase.h \
1712                   stdatomic.h \
1713                   sys/eventfd.h \
1714                   sys/file.h \
1715                   sys/ioctl.h \
1716                   sys/limits.h \
1717                   sys/mman.h \
1718                   sys/param.h \
1719                   sys/prctl.h \
1720                   sys/random.h \
1721                   sys/resource.h \
1722                   sys/select.h \
1723                   sys/socket.h \
1724                   sys/statvfs.h \
1725                   sys/syscall.h \
1726                   sys/sysctl.h \
1727                   sys/time.h \
1728                   sys/types.h \
1729                   sys/un.h \
1730                   sys/utime.h \
1731                   sys/wait.h \
1732                   syslog.h \
1733                   utime.h \
1734                   glob.h])
1736 AC_CHECK_HEADERS(sys/param.h)
1738 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1739 [#ifdef HAVE_SYS_TYPES_H
1740 #include <sys/types.h>
1741 #endif
1742 #ifdef HAVE_SYS_SOCKET_H
1743 #include <sys/socket.h>
1744 #endif])
1745 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1746 [#ifdef HAVE_SYS_TYPES_H
1747 #include <sys/types.h>
1748 #endif
1749 #ifdef HAVE_SYS_SOCKET_H
1750 #include <sys/socket.h>
1751 #endif
1752 #ifdef HAVE_NET_IF_H
1753 #include <net/if.h>
1754 #endif
1755 #ifdef HAVE_NETINET_IN_H
1756 #include <netinet/in.h>
1757 #endif])
1759 AC_CHECK_HEADERS(linux/if.h,[],[],
1761 #ifdef HAVE_SYS_SOCKET_H
1762 #include <sys/socket.h>
1763 #endif
1766 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1767         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1768 [#ifdef HAVE_SYS_TYPES_H
1769 #include <sys/types.h>
1770 #endif
1771 #ifdef HAVE_SYS_SOCKET_H
1772 #include <sys/socket.h>
1773 #endif
1774 #ifdef HAVE_LIMITS_H
1775 #include <limits.h>
1776 #endif
1777 #ifdef HAVE_LINUX_TYPES_H
1778 #include <linux/types.h>
1779 #endif
1780 #ifdef HAVE_NETINET_IN6_H
1781 #include <netinet/in6.h>
1782 #endif
1783 #ifdef HAVE_NETINET_IN_H
1784 #include <netinet/in.h>
1785 #endif])
1787 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1788         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1789 [#ifdef HAVE_SYS_TYPES_H
1790 #include <sys/types.h>
1791 #endif
1792 #ifdef HAVE_SYS_SOCKET_H
1793 #include <sys/socket.h>
1794 #endif
1795 #ifdef HAVE_LIMITS_H
1796 #include <limits.h>
1797 #endif
1798 #ifdef HAVE_LINUX_TYPES_H
1799 #include <linux/types.h>
1800 #endif
1801 #ifdef HAVE_NETINET_IN6_H
1802 #include <netinet/in6.h>
1803 #endif
1804 #ifdef HAVE_NETINET_IN_H
1805 #include <netinet/in.h>
1806 #endif
1807 #ifdef HAVE_LINUX_IF_H
1808 #include <linux/if.h>
1809 #endif])
1811 transparent_ok=0
1812 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1813   transparent_ok=1
1815 if test "x$linux_netfilter_ipv4" = "x1"; then
1816   transparent_ok=1
1818 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1819   transparent_ok=1
1821 if test "x$transparent_ok" = "x1"; then
1822   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1823 else
1824   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1827 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1828 [#ifdef HAVE_SYS_TYPES_H
1829 #include <sys/types.h>
1830 #endif
1831 #ifdef HAVE_SYS_TIME_H
1832 #include <sys/time.h>
1833 #endif])
1835 AC_CHECK_SIZEOF(char)
1836 AC_CHECK_SIZEOF(short)
1837 AC_CHECK_SIZEOF(int)
1838 AC_CHECK_SIZEOF(unsigned int)
1839 AC_CHECK_SIZEOF(long)
1840 AC_CHECK_SIZEOF(long long)
1841 AC_CHECK_SIZEOF(__int64)
1842 AC_CHECK_SIZEOF(void *)
1843 AC_CHECK_SIZEOF(time_t)
1844 AC_CHECK_SIZEOF(size_t)
1845 AC_CHECK_SIZEOF(pid_t)
1847 AC_CHECK_TYPES([uint, u_char, ssize_t])
1849 AC_PC_FROM_UCONTEXT([:])
1851 dnl used to include sockaddr_storage, but everybody has that.
1852 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1853 [#ifdef HAVE_SYS_TYPES_H
1854 #include <sys/types.h>
1855 #endif
1856 #ifdef HAVE_NETINET_IN_H
1857 #include <netinet/in.h>
1858 #endif
1859 #ifdef HAVE_NETINET_IN6_H
1860 #include <netinet/in6.h>
1861 #endif
1862 #ifdef HAVE_SYS_SOCKET_H
1863 #include <sys/socket.h>
1864 #endif
1865 #ifdef _WIN32
1866 #define _WIN32_WINNT 0x0501
1867 #define WIN32_LEAN_AND_MEAN
1868 #include <winsock2.h>
1869 #include <ws2tcpip.h>
1870 #endif
1872 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1873 [#ifdef HAVE_SYS_TYPES_H
1874 #include <sys/types.h>
1875 #endif
1876 #ifdef HAVE_NETINET_IN_H
1877 #include <netinet/in.h>
1878 #endif
1879 #ifdef HAVE_NETINET_IN6_H
1880 #include <netinet/in6.h>
1881 #endif
1882 #ifdef HAVE_SYS_SOCKET_H
1883 #include <sys/socket.h>
1884 #endif
1885 #ifdef _WIN32
1886 #define _WIN32_WINNT 0x0501
1887 #define WIN32_LEAN_AND_MEAN
1888 #include <winsock2.h>
1889 #include <ws2tcpip.h>
1890 #endif
1893 AC_CHECK_TYPES([rlim_t], , ,
1894 [#ifdef HAVE_SYS_TYPES_H
1895 #include <sys/types.h>
1896 #endif
1897 #ifdef HAVE_SYS_TIME_H
1898 #include <sys/time.h>
1899 #endif
1900 #ifdef HAVE_SYS_RESOURCE_H
1901 #include <sys/resource.h>
1902 #endif
1905 AX_CHECK_SIGN([time_t],
1906        [ : ],
1907        [ : ], [
1908 #ifdef HAVE_SYS_TYPES_H
1909 #include <sys/types.h>
1910 #endif
1911 #ifdef HAVE_SYS_TIME_H
1912 #include <sys/time.h>
1913 #endif
1914 #ifdef HAVE_TIME_H
1915 #include <time.h>
1916 #endif
1919 if test "$ax_cv_decl_time_t_signed" = "no"; then
1920   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1923 AX_CHECK_SIGN([size_t],
1924        [ tor_cv_size_t_signed=yes ],
1925        [ tor_cv_size_t_signed=no ], [
1926 #ifdef HAVE_SYS_TYPES_H
1927 #include <sys/types.h>
1928 #endif
1931 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1932   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1935 AX_CHECK_SIGN([enum always],
1936        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1937        [ : ], [
1938  enum always { AAA, BBB, CCC };
1941 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1942 #ifdef HAVE_SYS_SOCKET_H
1943 #include <sys/socket.h>
1944 #endif
1947 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1949 AC_CHECK_SIZEOF(cell_t)
1951 # Let's see if stdatomic works. (There are some debian clangs that screw it
1952 # up; see Tor bug #26779 and debian bug 903709.)
1953 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1954                tor_cv_stdatomic_works,
1955 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1956 #include <stdatomic.h>
1957 struct x { atomic_size_t y; };
1958 void try_atomic_init(struct x *xx)
1960   atomic_init(&xx->y, 99);
1961   atomic_fetch_add(&xx->y, 1);
1963 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1965 if test "$tor_cv_stdatomic_works" = "yes"; then
1966    AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1967 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1968    tor_incr_n_warnings
1969    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 ])
1972 # Now make sure that NULL can be represented as zero bytes.
1973 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1974 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1975 [[#include <stdlib.h>
1976 #include <string.h>
1977 #include <stdio.h>
1978 #ifdef HAVE_STDDEF_H
1979 #include <stddef.h>
1980 #endif
1981 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1982 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1983        [tor_cv_null_is_zero=yes],
1984        [tor_cv_null_is_zero=no],
1985        [tor_cv_null_is_zero=cross])])
1987 if test "$tor_cv_null_is_zero" = "cross"; then
1988   # Cross-compiling; let's hope that the target isn't raving mad.
1989   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1992 if test "$tor_cv_null_is_zero" != "no"; then
1993   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1994             [Define to 1 iff memset(0) sets pointers to NULL])
1997 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1998 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1999 [[#include <stdlib.h>
2000 #include <string.h>
2001 #include <stdio.h>
2002 #ifdef HAVE_STDDEF_H
2003 #include <stddef.h>
2004 #endif
2005 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
2006 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
2007        [tor_cv_dbl0_is_zero=yes],
2008        [tor_cv_dbl0_is_zero=no],
2009        [tor_cv_dbl0_is_zero=cross])])
2011 if test "$tor_cv_dbl0_is_zero" = "cross"; then
2012   # Cross-compiling; let's hope that the target isn't raving mad.
2013   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
2016 if test "$tor_cv_dbl0_is_zero" != "no"; then
2017   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
2018             [Define to 1 iff memset(0) sets doubles to 0.0])
2021 # And what happens when we malloc zero?
2022 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
2023 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2024 [[#include <stdlib.h>
2025 #include <string.h>
2026 #include <stdio.h>
2027 #ifdef HAVE_STDDEF_H
2028 #include <stddef.h>
2029 #endif
2030 int main () { return malloc(0)?0:1; }]])],
2031        [tor_cv_malloc_zero_works=yes],
2032        [tor_cv_malloc_zero_works=no],
2033        [tor_cv_malloc_zero_works=cross])])
2035 if test "$tor_cv_malloc_zero_works" = "cross"; then
2036   # Cross-compiling; let's hope that the target isn't raving mad.
2037   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
2040 if test "$tor_cv_malloc_zero_works" = "yes"; then
2041   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
2042             [Define to 1 iff malloc(0) returns a pointer])
2045 # whether we seem to be in a 2s-complement world.
2046 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
2047 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2048 [[int main () { int problem = ((-99) != (~99)+1);
2049 return problem ? 1 : 0; }]])],
2050        [tor_cv_twos_complement=yes],
2051        [tor_cv_twos_complement=no],
2052        [tor_cv_twos_complement=cross])])
2054 if test "$tor_cv_twos_complement" = "cross"; then
2055   # Cross-compiling; let's hope that the target isn't raving mad.
2056   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
2059 if test "$tor_cv_twos_complement" != "no"; then
2060   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
2061             [Define to 1 iff we represent negative integers with
2062              two's complement])
2065 # What does shifting a negative value do?
2066 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
2067 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2068 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
2069        [tor_cv_sign_extend=yes],
2070        [tor_cv_sign_extend=no],
2071        [tor_cv_sign_extend=cross])])
2073 if test "$tor_cv_sign_extend" = "cross"; then
2074   # Cross-compiling; let's hope that the target isn't raving mad.
2075   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
2078 if test "$tor_cv_sign_extend" != "no"; then
2079   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
2080             [Define to 1 iff right-shifting a negative value performs sign-extension])
2083 # Is uint8_t the same type as unsigned char?
2084 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
2085 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2086 #include <stdint.h>
2087 extern uint8_t c;
2088 unsigned char c;]])],
2089        [tor_cv_uint8_uchar=yes],
2090        [tor_cv_uint8_uchar=no],
2091        [tor_cv_uint8_uchar=cross])])
2093 if test "$tor_cv_uint8_uchar" = "cross"; then
2094   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
2097 if test "$tor_cv_uint8_uchar" = "no"; then
2098   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
2101 AC_ARG_WITH(tcmalloc,
2102 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
2104 default_malloc=system
2106 if test "x$enable_openbsd_malloc" = "xyes" ; then
2107   AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
2108   default_malloc=openbsd
2111 if test "x$with_tcmalloc" = "xyes"; then
2112   AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
2113   default_malloc=tcmalloc
2116 AC_ARG_WITH(malloc,
2117    AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
2118                   [select special malloc implementation [system]]),
2119    [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
2121 AS_CASE([$malloc],
2122   [tcmalloc], [
2123       PKG_CHECK_MODULES([TCMALLOC],
2124                         [libtcmalloc],
2125                         have_tcmalloc=yes,
2126                         have_tcmalloc=no)
2128       if test "x$have_tcmalloc" = "xno" ; then
2129           AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
2130       fi
2132       CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
2133       LIBS="$TCMALLOC_LIBS $LIBS"
2134   ],
2136   [jemalloc], [
2137       PKG_CHECK_MODULES([JEMALLOC],
2138                         [jemalloc],
2139                         have_jemalloc=yes,
2140                         have_jemalloc=no)
2142       if test "x$have_jemalloc" = "xno" ; then
2143           AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
2144       fi
2146       CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
2147       LIBS="$JEMALLOC_LIBS $LIBS"
2148       using_custom_malloc=yes
2149   ],
2151   [openbsd], [
2152     tor_incr_n_warnings
2153     AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
2154     enable_openbsd_malloc=yes
2155   ],
2157   [system], [
2158      # handle this later, including the jemalloc fallback
2159   ],
2161   [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
2164 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
2166 if test "$malloc" != "system"; then
2167   # Tell the C compiler not to use the system allocator functions.
2168   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2170 if test "$using_custom_malloc" = "yes"; 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])
2175 # By default, we're going to assume we don't have mlockall()
2176 # bionic and other platforms have various broken mlockall subsystems.
2177 # Some systems don't have a working mlockall, some aren't linkable,
2178 # and some have it but don't declare it.
2179 AC_CHECK_FUNCS(mlockall)
2180 AC_CHECK_DECLS([mlockall], , , [
2181 #ifdef HAVE_SYS_MMAN_H
2182 #include <sys/mman.h>
2183 #endif])
2185 # Allow user to specify an alternate syslog facility
2186 AC_ARG_WITH(syslog-facility,
2187 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
2188 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
2189 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
2190 AC_SUBST(LOGFACILITY)
2192 # Check if we have getresuid and getresgid
2193 AC_CHECK_FUNCS(getresuid getresgid)
2195 # Check for gethostbyname_r in all its glorious incompatible versions.
2196 #   (This logic is based on that in Python's configure.in)
2197 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
2198   [Define this if you have any gethostbyname_r()])
2200 AC_CHECK_FUNC(gethostbyname_r, [
2201   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
2202   OLD_CFLAGS=$CFLAGS
2203   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
2204   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2205 #include <netdb.h>
2206   ]], [[
2207     char *cp1, *cp2;
2208     struct hostent *h1, *h2;
2209     int i1, i2;
2210     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2211   ]])],[
2212     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2213     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2214      [Define this if gethostbyname_r takes 6 arguments])
2215     AC_MSG_RESULT(6)
2216   ], [
2217     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2218 #include <netdb.h>
2219     ]], [[
2220       char *cp1, *cp2;
2221       struct hostent *h1;
2222       int i1, i2;
2223       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2224     ]])], [
2225       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2226       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2227         [Define this if gethostbyname_r takes 5 arguments])
2228       AC_MSG_RESULT(5)
2229    ], [
2230       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2231 #include <netdb.h>
2232      ]], [[
2233        char *cp1;
2234        struct hostent *h1;
2235        struct hostent_data hd;
2236        (void) gethostbyname_r(cp1,h1,&hd);
2237      ]])], [
2238        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2239        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2240          [Define this if gethostbyname_r takes 3 arguments])
2241        AC_MSG_RESULT(3)
2242      ], [
2243        AC_MSG_RESULT(0)
2244      ])
2245   ])
2246  ])
2247  CFLAGS=$OLD_CFLAGS
2250 AC_CACHE_CHECK([whether the C compiler supports __func__],
2251   tor_cv_have_func_macro,
2252   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2253 #include <stdio.h>
2254 int main(int c, char **v) { puts(__func__); }])],
2255   tor_cv_have_func_macro=yes,
2256   tor_cv_have_func_macro=no))
2258 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2259   tor_cv_have_FUNC_macro,
2260   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2261 #include <stdio.h>
2262 int main(int c, char **v) { puts(__FUNC__); }])],
2263   tor_cv_have_FUNC_macro=yes,
2264   tor_cv_have_FUNC_macro=no))
2266 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2267   tor_cv_have_FUNCTION_macro,
2268   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2269 #include <stdio.h>
2270 int main(int c, char **v) { puts(__FUNCTION__); }])],
2271   tor_cv_have_FUNCTION_macro=yes,
2272   tor_cv_have_FUNCTION_macro=no))
2274 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2275   tor_cv_have_environ_declared,
2276   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2277 #ifdef HAVE_UNISTD_H
2278 #include <unistd.h>
2279 #endif
2280 #include <stdlib.h>
2281 int main(int c, char **v) { char **t = environ; }])],
2282   tor_cv_have_environ_declared=yes,
2283   tor_cv_have_environ_declared=no))
2285 if test "$tor_cv_have_func_macro" = "yes"; then
2286   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
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_FUNCTION_macro" = "yes"; then
2294   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2295            [Defined if the compiler supports __FUNCTION__])
2298 if test "$tor_cv_have_environ_declared" = "yes"; then
2299   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2300            [Defined if we have extern char **environ already declared])
2303 # $prefix stores the value of the --prefix command line option, or
2304 # NONE if the option wasn't set.  In the case that it wasn't set, make
2305 # it be the default, so that we can use it to expand directories now.
2306 if test "x$prefix" = "xNONE"; then
2307   prefix=$ac_default_prefix
2310 # and similarly for $exec_prefix
2311 if test "x$exec_prefix" = "xNONE"; then
2312   exec_prefix=$prefix
2315 if test "x$BUILDDIR" = "x"; then
2316   BUILDDIR=`pwd`
2318 AC_SUBST(BUILDDIR)
2319 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2320 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2322 if test "x$SRCDIR" = "x"; then
2323   SRCDIR=$(cd "$srcdir"; pwd)
2325 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2326 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2328 if test "x$CONFDIR" = "x"; then
2329   CONFDIR=`eval echo $sysconfdir/tor`
2331 AC_SUBST(CONFDIR)
2332 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2333 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2335 BINDIR=`eval echo $bindir`
2336 AC_SUBST(BINDIR)
2337 LOCALSTATEDIR=`eval echo $localstatedir`
2338 AC_SUBST(LOCALSTATEDIR)
2340 if test "$bwin32" = "true"; then
2341   # Test if the linker supports the --nxcompat and --dynamicbase options
2342   # for Windows
2343   save_LDFLAGS="$LDFLAGS"
2344   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2345   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2346   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2347     [AC_MSG_RESULT([yes])]
2348     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2349     [AC_MSG_RESULT([no])]
2350   )
2351   LDFLAGS="$save_LDFLAGS"
2354 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2355 # than autoconf's macros like.
2356 if test "$GCC" = "yes"; then
2357   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2358   # accident waiting to happen.
2359   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2360 else
2361   # Override optimization level for non-gcc compilers
2362   CFLAGS="$CFLAGS -O"
2363   enable_gcc_warnings=no
2364   enable_gcc_warnings_advisory=no
2367 # Warnings implies advisory-warnings and -Werror.
2368 if test "$enable_gcc_warnings" = "yes"; then
2369   enable_gcc_warnings_advisory=yes
2370   enable_fatal_warnings=yes
2373 # OS X Lion started deprecating the system openssl. Let's just disable
2374 # all deprecation warnings on OS X. Also, to potentially make the binary
2375 # a little smaller, let's enable dead_strip.
2376 case "$host_os" in
2378  darwin*)
2379     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2380     LDFLAGS="$LDFLAGS -dead_strip" ;;
2381 esac
2383 TOR_WARNING_FLAGS=""
2385 # Add some more warnings which we use in development but not in the
2386 # released versions.  (Some relevant gcc versions can't handle these.)
2388 # Note that we have to do this near the end  of the autoconf process, or
2389 # else we may run into problems when these warnings hit on the testing C
2390 # programs that autoconf wants to build.
2391 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2393   case "$host" in
2394     *-*-openbsd* | *-*-bitrig*)
2395       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2396       # That's fine, except that the headers don't pass -Wredundant-decls.
2397       # Therefore, let's disable -Wsystem-headers when we're building
2398       # with maximal warnings on OpenBSD.
2399       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2400   esac
2402   CFLAGS_NOWARNINGS="$CFLAGS"
2404   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2405   # have it work better.
2406   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2408   # This warning was added in gcc 4.3, but it appears to generate
2409   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2410   #CFLAGS="$CFLAGS -Wlogical-op"
2412   m4_foreach_w([warning_flag], [
2413      -Waddress
2414      -Waddress-of-array-temporary
2415      -Waddress-of-temporary
2416      -Wambiguous-macro
2417      -Wanonymous-pack-parens
2418      -Warc
2419      -Warc-abi
2420      -Warc-bridge-casts-disallowed-in-nonarc
2421      -Warc-maybe-repeated-use-of-weak
2422      -Warc-performSelector-leaks
2423      -Warc-repeated-use-of-weak
2424      -Warray-bounds
2425      -Warray-bounds-pointer-arithmetic
2426      -Wasm
2427      -Wasm-operand-widths
2428      -Watomic-properties
2429      -Watomic-property-with-user-defined-accessor
2430      -Wauto-import
2431      -Wauto-storage-class
2432      -Wauto-var-id
2433      -Wavailability
2434      -Wbackslash-newline-escape
2435      -Wbad-array-new-length
2436      -Wbind-to-temporary-copy
2437      -Wbitfield-constant-conversion
2438      -Wbool-conversion
2439      -Wbool-conversions
2440      -Wbuiltin-requires-header
2441      -Wchar-align
2442      -Wcompare-distinct-pointer-types
2443      -Wcomplex-component-init
2444      -Wconditional-type-mismatch
2445      -Wconfig-macros
2446      -Wconstant-conversion
2447      -Wconstant-logical-operand
2448      -Wconstexpr-not-const
2449      -Wcustom-atomic-properties
2450      -Wdangling-field
2451      -Wdangling-initializer-list
2452      -Wdate-time
2453      -Wdelegating-ctor-cycles
2454      -Wdeprecated-implementations
2455      -Wdeprecated-register
2456      -Wdirect-ivar-access
2457      -Wdiscard-qual
2458      -Wdistributed-object-modifiers
2459      -Wdivision-by-zero
2460      -Wdollar-in-identifier-extension
2461      -Wdouble-promotion
2462      -Wduplicate-decl-specifier
2463      -Wduplicate-enum
2464      -Wduplicate-method-arg
2465      -Wduplicate-method-match
2466      -Wduplicated-cond
2467      -Wdynamic-class-memaccess
2468      -Wembedded-directive
2469      -Wempty-translation-unit
2470      -Wenum-conversion
2471      -Wexit-time-destructors
2472      -Wexplicit-ownership-type
2473      -Wextern-initializer
2474      -Wextra
2475      -Wextra-semi
2476      -Wextra-tokens
2477      -Wflexible-array-extensions
2478      -Wfloat-conversion
2479      -Wformat-non-iso
2480      -Wfour-char-constants
2481      -Wgcc-compat
2482      -Wglobal-constructors
2483      -Wgnu-array-member-paren-init
2484      -Wgnu-designator
2485      -Wgnu-static-float-init
2486      -Wheader-guard
2487      -Wheader-hygiene
2488      -Widiomatic-parentheses
2489      -Wignored-attributes
2490      -Wimplicit-atomic-properties
2491      -Wimplicit-conversion-floating-point-to-bool
2492      -Wimplicit-exception-spec-mismatch
2493      -Wimplicit-fallthrough
2494      -Wimplicit-fallthrough-per-function
2495      -Wimplicit-retain-self
2496      -Wimport-preprocessor-directive-pedantic
2497      -Wincompatible-library-redeclaration
2498      -Wincompatible-pointer-types-discards-qualifiers
2499      -Wincomplete-implementation
2500      -Wincomplete-module
2501      -Wincomplete-umbrella
2502      -Winit-self
2503      -Wint-conversions
2504      -Wint-to-void-pointer-cast
2505      -Winteger-overflow
2506      -Winvalid-constexpr
2507      -Winvalid-iboutlet
2508      -Winvalid-noreturn
2509      -Winvalid-pp-token
2510      -Winvalid-source-encoding
2511      -Winvalid-token-paste
2512      -Wknr-promoted-parameter
2513      -Wlarge-by-value-copy
2514      -Wliteral-conversion
2515      -Wliteral-range
2516      -Wlocal-type-template-args
2517      -Wlogical-op
2518      -Wloop-analysis
2519      -Wmain-return-type
2520      -Wmalformed-warning-check
2521      -Wmethod-signatures
2522      -Wmicrosoft
2523      -Wmicrosoft-exists
2524      -Wmismatched-parameter-types
2525      -Wmismatched-return-types
2526      -Wmissing-field-initializers
2527      -Wmissing-format-attribute
2528      -Wmissing-noreturn
2529      -Wmissing-selector-name
2530      -Wmissing-sysroot
2531      -Wmissing-variable-declarations
2532      -Wmodule-conflict
2533      -Wnested-anon-types
2534      -Wnewline-eof
2535      -Wnon-literal-null-conversion
2536      -Wnon-pod-varargs
2537      -Wnonportable-cfstrings
2538      -Wnormalized=nfkc
2539      -Wnull-arithmetic
2540      -Wnull-character
2541      -Wnull-conversion
2542      -Wnull-dereference
2543      -Wout-of-line-declaration
2544      -Wover-aligned
2545      -Woverlength-strings
2546      -Woverride-init
2547      -Woverriding-method-mismatch
2548      -Wpointer-type-mismatch
2549      -Wpredefined-identifier-outside-function
2550      -Wprotocol-property-synthesis-ambiguity
2551      -Wreadonly-iboutlet-property
2552      -Wreadonly-setter-attrs
2553      -Wreceiver-expr
2554      -Wreceiver-forward-class
2555      -Wreceiver-is-weak
2556      -Wreinterpret-base-class
2557      -Wrequires-super-attribute
2558      -Wreserved-user-defined-literal
2559      -Wreturn-stack-address
2560      -Wsection
2561      -Wselector-type-mismatch
2562      -Wsentinel
2563      -Wserialized-diagnostics
2564      -Wshadow
2565      -Wshift-count-negative
2566      -Wshift-count-overflow
2567      -Wshift-negative-value
2568      -Wshift-overflow=2
2569      -Wshift-sign-overflow
2570      -Wshorten-64-to-32
2571      -Wsizeof-array-argument
2572      -Wsource-uses-openmp
2573      -Wstatic-float-init
2574      -Wstatic-in-inline
2575      -Wstatic-local-in-inline
2576      -Wstrict-overflow=1
2577      -Wstring-compare
2578      -Wstring-conversion
2579      -Wstrlcpy-strlcat-size
2580      -Wstrncat-size
2581      -Wsuggest-attribute=format
2582      -Wsuggest-attribute=noreturn
2583      -Wsuper-class-method-mismatch
2584      -Wswitch-bool
2585      -Wsync-nand
2586      -Wtautological-constant-out-of-range-compare
2587      -Wtentative-definition-incomplete-type
2588      -Wtrampolines
2589      -Wtype-safety
2590      -Wtypedef-redefinition
2591      -Wtypename-missing
2592      -Wundefined-inline
2593      -Wundefined-internal
2594      -Wundefined-reinterpret-cast
2595      -Wunicode
2596      -Wunicode-whitespace
2597      -Wunknown-warning-option
2598      -Wunnamed-type-template-args
2599      -Wunneeded-member-function
2600      -Wunsequenced
2601      -Wunsupported-visibility
2602      -Wunused-but-set-parameter
2603      -Wunused-but-set-variable
2604      -Wunused-command-line-argument
2605      -Wunused-const-variable=2
2606      -Wunused-exception-parameter
2607      -Wunused-local-typedefs
2608      -Wunused-member-function
2609      -Wunused-sanitize-argument
2610      -Wunused-volatile-lvalue
2611      -Wuser-defined-literals
2612      -Wvariadic-macros
2613      -Wvector-conversion
2614      -Wvector-conversions
2615      -Wvexing-parse
2616      -Wvisibility
2617      -Wvla-extension
2618      -Wzero-length-array
2619   ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2620               [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2621      ])
2623 dnl    We should re-enable this in some later version.  Clang doesn't
2624 dnl    mind, but it causes trouble with GCC.
2625 dnl     -Wstrict-overflow=2
2627 dnl    These seem to require annotations that we don't currently use,
2628 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2629 dnl     -Wthread-safety
2630 dnl     -Wthread-safety-analysis
2631 dnl     -Wthread-safety-attributes
2632 dnl     -Wthread-safety-beta
2633 dnl     -Wthread-safety-precise
2635   W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2636   W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2637   W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2638   W_FLAGS="$W_FLAGS -Wwrite-strings"
2639   W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2640   W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2641   W_FLAGS="$W_FLAGS -Wunused-parameter "
2642   # These interfere with building main() { return 0; }, which autoconf
2643   # likes to use as its default program.
2644   W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2646   TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2647   CFLAGS="$CFLAGS $W_FLAGS"
2649   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2650     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2651   fi
2652   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2653     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2654   fi
2655   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2656     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2657   fi
2659   CFLAGS="$CFLAGS_NOWARNINGS"
2661   if test "x$enable_fatal_warnings" = "xyes"; then
2662     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2663     # default autoconf programs are full of errors.
2664     CFLAGS="$CFLAGS -Werror"
2665   fi
2669 AC_SUBST(TOR_WARNING_FLAGS)
2671 echo "$TOR_WARNING_FLAGS">warning_flags
2673 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2674                             CFLAGS="$CFLAGS @warning_flags",
2675                             CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2677 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2678    case "$host_os" in
2679     darwin*)
2680       tor_incr_n_warnings
2681       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.])
2682    esac
2685 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2687 AC_CONFIG_FILES([
2688         Doxyfile
2689         Makefile
2690         config.rust
2691         contrib/operator-tools/tor.logrotate
2692         src/config/torrc.sample
2693         src/config/torrc.minimal
2694         src/rust/.cargo/config
2695         scripts/maint/checkOptionDocs.pl
2696         warning_flags
2699 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2700   regular_mans="doc/man/tor doc/man/tor-gencert doc/man/tor-resolve doc/man/torify"
2701   for file in $regular_mans ; do
2702     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2703       echo "==================================";
2704       echo;
2705       echo "Building Tor has failed since manpages cannot be built.";
2706       echo;
2707       echo "You need asciidoc installed to be able to build the manpages.";
2708       echo "To build without manpages, use the --disable-asciidoc argument";
2709       echo "when calling configure.";
2710       echo;
2711       echo "==================================";
2712       exit 1;
2713     fi
2714   done
2717 if test "$fragile_hardening" = "yes"; then
2718   tor_incr_n_warnings
2719   AC_MSG_WARN([
2721 ============
2722 Warning!  Building Tor with --enable-fragile-hardening (also known as
2723 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2724 other kinds of attacks easier. A Tor instance build with this option will be
2725 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2726 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2727 denial of service attacks. For more information, see
2728 https://gitlab.torproject.org/tpo/core/team/-/wikis/TorFragileHardening
2729 ============
2730   ])
2733 AC_OUTPUT
2735 if test "$openssl_ver_mismatch" = "yes"; then
2736    tor_incr_n_warnings
2737    AC_MSG_WARN([
2738 ============
2739 Warning! The version OpenSSL headers we get from compiling with
2740     "${TOR_CPPFLAGS_OPENSSL:-(no extra options)}"
2741 do not match version of the OpenSSL library we get when linking with
2742     "$TOR_LDFLAGS_OPENSSL $TOR_OPENSSL_LIBS".
2743 This might cause compilation to fail. Try using --with-openssl-dir to specify
2744 the exact OpenSSL path you want.
2745 ============
2750 # Mini-report on what will be built.
2753 PPRINT_INIT
2754 PPRINT_SET_INDENT(1)
2755 PPRINT_SET_TS(65)
2757 AS_ECHO
2758 AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
2759 AS_ECHO
2761 PPRINT_SUBTITLE([Build Features])
2763 PPRINT_PROP_STRING([Compiler], [$CC])
2764 PPRINT_PROP_STRING([Host OS], [$host_os])
2765 AS_ECHO
2767 test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
2768 PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
2770 test "x$enable_rust" = "xyes" && value=1 || value=0
2771 PPRINT_PROP_BOOL([Rust support (--enable-rust)], $value)
2773 test "x$enable_cargo_online_mode" = "xyes" && value=1 || value=0
2774 PPRINT_PROP_BOOL([Cargo Online Fetch (--enable-cargo-online-mode)], $value)
2776 test "x$enable_android" = "xyes" && value=1 || value=0
2777 PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
2779 AS_ECHO
2780 PPRINT_SUBTITLE([Static Build])
2782 test "x$enable_static_tor" = "xyes" && value=1 || value=0
2783 PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
2785 if test "x$enable_static_libevent" = "xyes"; then
2786   PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
2787 else
2788   PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
2791 if test "x$enable_static_openssl" = "xyes"; then
2792   PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
2793 else
2794   PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
2797 if test "x$enable_static_zlib" = "xyes"; then
2798   PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
2799 else
2800   PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
2803 AS_ECHO
2804 PPRINT_SUBTITLE([Optional Libraries])
2806 test "x$enable_nss" = "xyes" && value=1 || value=0
2807 PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
2809 test "x$enable_seccomp" != "xno" && value=1 || value=0
2810 PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
2812 test "x$enable_libscrypt" != "xno" && value=1 || value=0
2813 PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
2815 test "x$enable_systemd" = "xyes" && value=1 || value=0
2816 PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
2818 test "x$have_lzma" = "xyes" && value=1 || value=0
2819 PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
2821 test "x$have_zstd" = "xyes" && value=1 || value=0
2822 PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
2824 AS_ECHO
2825 PPRINT_SUBTITLE([Hardening])
2827 test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
2828 PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
2830 test "x$enable_linker_hardening" != "xno" && value=1 || value=0
2831 PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
2833 test "x$fragile_hardening" = "xyes" && value=1 || value=0
2834 PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
2836 AS_ECHO
2837 PPRINT_SUBTITLE([Modules])
2839 m4_foreach_w([mname], MODULES,
2840   [
2841     AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
2842     m4_set_contains([MODULES_WITH_NO_OPTIONS], mname,
2843                     PPRINT_PROP_BOOL([mname], $value),
2844                     PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value))
2845   ]
2848 AS_ECHO
2849 PPRINT_SUBTITLE([Documentation])
2851 test "x$enable_asciidoc" != "xno" && value=1 || value=0
2852 PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
2854 test "x$enable_manpage" != "xno" && value=1 || value=0
2855 PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
2857 test "x$enable_html_manual" != "xno" && value=1 || value=0
2858 PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
2860 AS_ECHO
2861 PPRINT_SUBTITLE([Tests])
2863 test "x$enable_unittests" != "xno" && value=1 || value=0
2864 PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
2866 test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
2867 PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
2869 test "x$enable_coverage" = "xyes" && value=1 || value=0
2870 PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
2872 test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
2873 PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
2875 test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
2876 PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
2878 AS_ECHO
2879 PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
2881 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
2882 PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
2884 test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
2885 PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
2887 test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
2888 PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
2890 AS_ECHO
2891 PPRINT_SUBTITLE([Install Directories])
2893 report_mandir="`eval eval echo $mandir`"
2894 PPRINT_PROP_STRING([Binaries], [$BINDIR])
2895 PPRINT_PROP_STRING([Configuration], [$CONFDIR])
2896 PPRINT_PROP_STRING([Man Pages], [$report_mandir])
2898 AS_ECHO
2899 AS_ECHO(["Configure Line: ./configure $configure_flags"])
2901 if test "$tor_ac_n_warnings" != "0"; then
2902   AS_ECHO
2903   PPRINT_WARN([
2904 Encountered $tor_ac_n_warnings warning(s). See messages above for more info.
2905   ])