Changes file for autoconf improvements in 40138
[tor.git] / configure.ac
blob4cbb43794de96586a64dad1131e576518d12d4ca
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.5.0-alpha-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
11 configure_flags="$*"
13 # DO NOT EDIT THIS DEFINITION BY HAND UNLESS YOU KNOW WHAT YOU'RE DOING.
15 # The update_versions.py script updates this definition when the
16 # version number changes.  Tor uses it to make sure that it
17 # only shuts down for missing "required protocols" when those protocols
18 # are listed as required by a consensus after this date.
19 AC_DEFINE(APPROX_RELEASE_DATE, ["2020-06-09"], # for 0.4.5.0-alpha-dev
20           [Approximate date when this software was released. (Updated when the version changes.)])
22 # "foreign" means we don't follow GNU package layout standards
23 # "1.11" means we require automake version 1.11 or newer
24 # "subdir-objects" means put .o files in the same directory as the .c files
25 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
27 tor_ac_n_warnings=0
28 tor_incr_n_warnings() {
29   tor_ac_n_warnings=`expr $tor_ac_n_warnings + 1`
32 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
33 AC_CONFIG_HEADERS([orconfig.h])
35 AC_USE_SYSTEM_EXTENSIONS
36 AC_CANONICAL_HOST
38 PKG_PROG_PKG_CONFIG
39 if test "x$PKG_CONFIG" = "x" ; then
40     pkg_config_user_action="install pkg-config, and check the PKG_CONFIG_PATH environment variable"
41     AC_MSG_NOTICE([Some libraries need pkg-config, including systemd, nss, lzma, zstd, and custom mallocs.])
42     AC_MSG_NOTICE([To use those libraries, $pkg_config_user_action.])
43 else
44     pkg_config_user_action="check the PKG_CONFIG_PATH environment variable"
47 if test "x$PKG_CONFIG_PATH" = "x" && test "x$prefix" != "xNONE" && test "$host" != "$build"; then
48    export PKG_CONFIG_PATH=$prefix/lib/pkgconfig
49    AC_MSG_NOTICE([set PKG_CONFIG_PATH=$PKG_CONFIG_PATH to support cross-compiling])
52 AC_ARG_ENABLE(openbsd-malloc,
53    AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD.  Linux only. Deprecated: see --with-malloc]))
54 AC_ARG_ENABLE(static-openssl,
55    AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
56 AC_ARG_ENABLE(static-libevent,
57    AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
58 AC_ARG_ENABLE(static-zlib,
59    AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
60 AC_ARG_ENABLE(static-tor,
61    AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
62 AC_ARG_ENABLE(unittests,
63    AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
64 AC_ARG_ENABLE(coverage,
65    AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
66 AC_ARG_ENABLE(asserts-in-tests,
67    AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
68 AC_ARG_ENABLE(system-torrc,
69    AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
70 AC_ARG_ENABLE(libfuzzer,
71    AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
72 AC_ARG_ENABLE(oss-fuzz,
73    AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
74 AC_ARG_ENABLE(memory-sentinels,
75    AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
76 AC_ARG_ENABLE(rust,
77    AS_HELP_STRING(--enable-rust, [enable rust integration]))
78 AC_ARG_ENABLE(cargo-online-mode,
79    AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
80 AC_ARG_ENABLE(restart-debugging,
81    AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
82 AC_ARG_ENABLE(zstd-advanced-apis,
83    AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
84 AC_ARG_ENABLE(nss,
85    AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
86 AC_ARG_ENABLE(pic,
87    AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
89 AC_ARG_ENABLE(missing-doc-warnings,
90    AS_HELP_STRING(--enable-missing-doc-warnings, [Tell doxygen to warn about missing documentation. Makes doxygen warnings nonfatal.]))
92 if test "$enable_missing_doc_warnings" = "yes"; then
93    DOXYGEN_FATAL_WARNINGS=NO
94    DOXYGEN_WARN_ON_MISSING=YES
95 elif test "$enable_fatal_warnings" = "yes"; then
96    # Fatal warnings from doxygen are nice, but not if we're warning about
97    # missing documentation.
98    DOXYGEN_FATAL_WARNINGS=YES
99    DOXYGEN_WARN_ON_MISSING=NO
100 else
101    DOXYGEN_FATAL_WARNINGS=NO
102    DOXYGEN_WARN_ON_MISSING=NO
104 AC_SUBST(DOXYGEN_FATAL_WARNINGS)
105 AC_SUBST(DOXYGEN_WARN_ON_MISSING)
107 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
108     AC_MSG_ERROR([Can't disable assertions outside of coverage build])
111 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
112 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
113 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
114 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
115 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
116 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
117 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
118 AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
120 if test "x$enable_nss" = "xyes"; then
121   AC_DEFINE(ENABLE_NSS, 1,
122             [Defined if we're building with NSS.])
123 else
124   AC_DEFINE(ENABLE_OPENSSL, 1,
125             [Defined if we're building with OpenSSL or LibreSSL])
128 if test "$enable_static_tor" = "yes"; then
129   enable_static_libevent="yes";
130   enable_static_openssl="yes";
131   enable_static_zlib="yes";
132   CFLAGS="$CFLAGS -static"
135 if test "$enable_system_torrc" = "no"; then
136   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
137             [Defined if we're not going to look for a torrc in SYSCONF])
140 if test "$enable_memory_sentinels" = "no"; then
141   AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
142            [Defined if we're turning off memory safety code to look for bugs])
145 AC_ARG_ENABLE(manpage,
146               AS_HELP_STRING(--disable-manpage, [Disable manpage generation.]))
148 AC_ARG_ENABLE(html-manual,
149               AS_HELP_STRING(--disable-html-manual, [Disable HTML documentation.]))
151 AC_ARG_ENABLE(asciidoc,
152      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
153      [case "${enableval}" in
154         "yes") asciidoc=true ;;
155         "no")  asciidoc=false ;;
156         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
157       esac], [asciidoc=true])
159 # systemd notify support
160 AC_ARG_ENABLE(systemd,
161       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
162       [case "${enableval}" in
163         "yes") systemd=true ;;
164         "no")  systemd=false ;;
165         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
166       esac], [systemd=auto])
168 if test "$enable_restart_debugging" = "yes"; then
169   AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
170             [Defined if we're building with support for in-process restart debugging.])
173 if test "$enable_zstd_advanced_apis" != "no"; then
174    AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
175              [Defined if we're going to try to use zstd's "static-only" APIs.])
178 # systemd support
179 if test "x$enable_systemd" = "xno"; then
180     have_systemd=no;
181 else
182     PKG_CHECK_MODULES(SYSTEMD,
183         [libsystemd-daemon],
184         have_systemd=yes,
185         have_systemd=no)
186     if test "x$have_systemd" = "xno"; then
187         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
188         PKG_CHECK_MODULES(SYSTEMD,
189             [libsystemd],
190             have_systemd=yes,
191             have_systemd=no)
192     fi
195 if test "x$have_systemd" = "xyes"; then
196     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
197     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
198     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
199     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
200          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or greater])], [])
202 AC_SUBST(TOR_SYSTEMD_CFLAGS)
203 AC_SUBST(TOR_SYSTEMD_LIBS)
205 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
206     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found, $pkg_config_user_action, or set SYSTEMD_CFLAGS and SYSTEMD_LIBS.])
209 case "$host" in
210    *-*-solaris* )
211      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
212      ;;
213 esac
215 AC_ARG_ENABLE(gcc-warnings,
216      AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
217 AC_ARG_ENABLE(fatal-warnings,
218      AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
219 AC_ARG_ENABLE(gcc-warnings-advisory,
220      AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
222 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
223 AC_ARG_ENABLE(gcc-hardening,
224     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
226 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
227 AC_ARG_ENABLE(expensive-hardening,
228     AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
229 AC_ARG_ENABLE(fragile-hardening,
230     AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
231 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
232   fragile_hardening="yes"
233   AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
236 AC_ARG_ENABLE(all-bugs-are-fatal,
237    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]))
239 if test "x$enable_all_bugs_are_fatal" = "xyes"; then
240   AC_DEFINE(ALL_BUGS_ARE_FATAL, 1, [All assert failures are fatal])
243 dnl Linker hardening options
244 dnl Currently these options are ELF specific - you can't use this with MacOSX
245 AC_ARG_ENABLE(linker-hardening,
246     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
248 AC_ARG_ENABLE(local-appdata,
249    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
250 if test "$enable_local_appdata" = "yes"; then
251   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
252             [Defined if we default to host local appdata paths on Windows])
255 AC_ARG_ENABLE(tool-name-check,
256      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
258 AC_ARG_ENABLE(seccomp,
259      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
261 AC_ARG_ENABLE(libscrypt,
262      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
264 dnl --- Tracing Options. ---
266 TOR_TRACE_LIBS=
268 dnl LTTng instrumentation option.
269 AC_ARG_ENABLE(tracing-instrumentation-lttng,
270               AS_HELP_STRING([--enable-tracing-instrumentation-lttng],
271                              [build with LTTng-UST instrumentation]))
272 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LTTNG],
273                [test "x$enable_tracing_instrumentation_lttng" = "xyes"])
275 if test "x$enable_tracing_instrumentation_lttng" = "xyes"; then
276   AC_CHECK_HEADERS([lttng/tracepoint.h], [],
277                    [AC_MSG_ERROR([LTTng instrumentation headers not found.
278                                   On Debian, apt install liblttng-ust-dev"])], [])
279   AC_DEFINE([USE_TRACING_INSTRUMENTATION_LTTNG], [1], [Using LTTng instrumentation])
280   TOR_TRACE_LIBS="-llttng-ust -ldl"
281   have_tracing=1
284 dnl USDT instrumentation option.
285 AC_ARG_ENABLE(tracing-instrumentation-usdt,
286               AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
287                              [build with tracing USDT instrumentation]))
288 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
289                [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
291 if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
292   AC_CHECK_HEADERS([sys/sdt.h], [],
293                    [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
294                                   On Debian, apt install systemtap-sdt-dev])], [])
295   dnl LTTng generates USDT probes if the UST library was built with
296   dnl --with-sdt. There is unfortunately no way to check that so we always
297   dnl build the USDT probes even though LTTng instrumentation was requested.
298   AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
299   have_tracing=1
302 dnl Tracepoints event to debug logs.
303 AC_ARG_ENABLE(tracing-instrumentation-log-debug,
304      AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
305                     [build with tracing event to debug log]),
306      AC_DEFINE([USE_TRACING_INSTRUMENTATION_LOG_DEBUG], [1],
307                [Tracepoints to log debug]), [])
308 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
309                [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
310 if test "x$enable_tracing_instrumentation_log_debug" = "xyes"; then
311   have_tracing=1
314 dnl Define that tracing is supported if any instrumentation is used.
315 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
316            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
317 AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
318            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
319 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LTTNG],
320            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
321 AM_CONDITIONAL([USE_TRACING], [test "x$have_tracing" = x1 ])
323 dnl Finally, define the trace libs.
324 AC_SUBST([TOR_TRACE_LIBS])
326 dnl -- End Tracing Options. --
328 dnl Enable Android only features.
329 AC_ARG_ENABLE(android,
330      AS_HELP_STRING(--enable-android, [build with Android features enabled]))
331 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
333 if test "x$enable_android" = "xyes"; then
334   AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
336   dnl Check if the Android log library is available.
337   AC_CHECK_HEADERS([android/log.h])
338   AC_SEARCH_LIBS(__android_log_write, [log])
342 dnl ---
343 dnl Tor modules options. These options are namespaced with --disable-module-XXX
344 dnl ---
346 dnl All our modules.
347 m4_define(MODULES, relay dirauth dircache)
349 dnl Relay module.
350 AC_ARG_ENABLE([module-relay],
351               AS_HELP_STRING([--disable-module-relay],
352                              [Build tor without the Relay modules: tor can not run as a relay, bridge, or authority. Implies --disable-module-dirauth]))
353 AM_CONDITIONAL(BUILD_MODULE_RELAY, [test "x$enable_module_relay" != "xno"])
354 AM_COND_IF(BUILD_MODULE_RELAY,
355            AC_DEFINE([HAVE_MODULE_RELAY], [1],
356                      [Compile with Relay feature support]))
358 dnl Dircache module.  (This cannot be enabled or disabled independently of
359 dnl the relay module.  It is not listed by --list-modules for this reason.)
360 AM_CONDITIONAL(BUILD_MODULE_DIRCACHE,
361                [test "x$enable_module_relay" != "xno"])
362 AM_COND_IF(BUILD_MODULE_DIRCACHE,
363            AC_DEFINE([HAVE_MODULE_DIRCACHE], [1],
364                      [Compile with directory cache support]))
366 dnl Directory Authority module.
367 AC_ARG_ENABLE([module-dirauth],
368               AS_HELP_STRING([--disable-module-dirauth],
369                              [Build tor without the Directory Authority module: tor can not run as a directory authority or bridge authority]))
370 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH,[test "x$enable_module_dirauth" != "xno" && test "x$enable_module_relay" != "xno"])
371 AM_COND_IF(BUILD_MODULE_DIRAUTH,
372            AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
373                      [Compile with Directory Authority feature support]))
375 dnl Helper variables.
376 TOR_MODULES_ALL_ENABLED=
377 AC_DEFUN([ADD_MODULE], [
378     MODULE=m4_toupper($1)
379     TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
381 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
382 AC_SUBST(TOR_MODULES_ALL_ENABLED)
384 dnl check for the correct "ar" when cross-compiling.
385 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
386 dnl    so kludge up a replacement for the case where it isn't there yet.)
387 m4_ifdef([AM_PROG_AR],
388          [AM_PROG_AR],
389          [AN_MAKEVAR([AR], [AC_PROG_AR])
390           AN_PROGRAM([ar], [AC_PROG_AR])
391           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
392           AC_PROG_AR])
394 dnl Check whether the above macro has settled for a simply named tool even
395 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
396 dnl because that will find any cc on the system, not only the cross-compiler,
397 dnl and then verify that a binary built with this compiler runs on the
398 dnl build system. It will then come to the false conclusion that we're not
399 dnl cross-compiling.
400 if test "x$enable_tool_name_check" != "xno"; then
401     if test "x$ac_tool_warned" = "xyes"; then
402         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.)])
403         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
404                 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.)])
405         fi
408 AC_PROG_CC
409 AC_PROG_CPP
410 AC_PROG_MAKE_SET
411 AC_PROG_RANLIB
412 AC_PROG_SED
414 AC_ARG_VAR([PERL], [path to Perl binary])
415 AC_CHECK_PROGS([PERL], [perl])
416 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
418 dnl check for asciidoc and a2x
419 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
420 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
422 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
423 AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
424 AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
426 AM_PROG_CC_C_O
427 AC_PROG_CC_C99
429 AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
430    [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
431         python3 \
432         python3.8 python3.7 python3.6 python3.5 python3.4 \
433         python ],
434    [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
435 AC_SUBST([PYTHON], [$tor_cv_PYTHON])
437 PYTHON="$tor_cv_PYTHON"
439 if test "x$PYTHON" = "x"; then
440   tor_incr_n_warnings
441   AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
444 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
446 dnl List all external rust crates we depend on here. Include the version
447 rust_crates=" \
448     digest-0.7.2 \
449     libc-0.2.39 \
451 AC_SUBST(rust_crates)
453 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
454 AC_C_FLEXIBLE_ARRAY_MEMBER
455 ], [
456  dnl Maybe we've got an old autoconf...
457  AC_CACHE_CHECK([for flexible array members],
458      tor_cv_c_flexarray,
459      [AC_COMPILE_IFELSE(
460        AC_LANG_PROGRAM([
461  struct abc { int a; char b[]; };
462 ], [
463  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
464  def->b[0] = 33;
466   [tor_cv_c_flexarray=yes],
467   [tor_cv_c_flexarray=no])])
468  if test "$tor_cv_flexarray" = "yes"; then
469    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
470  else
471    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
472  fi
475 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
476       tor_cv_c_c99_decl,
477       [AC_COMPILE_IFELSE(
478          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
479          [tor_cv_c_c99_decl=yes],
480          [tor_cv_c_c99_decl=no] )])
481 if test "$tor_cv_c_c99_decl" != "yes"; then
482   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
485 AC_CACHE_CHECK([for working C99 designated initializers],
486       tor_cv_c_c99_designated_init,
487       [AC_COMPILE_IFELSE(
488          [AC_LANG_PROGRAM([struct s { int a; int b; };],
489                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
490          [tor_cv_c_c99_designated_init=yes],
491          [tor_cv_c_c99_designated_init=no] )])
493 if test "$tor_cv_c_c99_designated_init" != "yes"; then
494   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
497 saved_CFLAGS="$CFLAGS"
498 CFLAGS="$CFLAGS -Werror"
499 AC_CACHE_CHECK([for __attribute__((fallthrough))],
500       tor_cv_c_attr_fallthrough,
501       [AC_COMPILE_IFELSE(
502          [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
503                [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
504                                case 2: fn(); break; } ]])],
505          [tor_cv_c_attr_fallthrough=yes],
506          [tor_cv_c_attr_fallthrough=no] )])
507 CFLAGS="$saved_CFLAGS"
509 if test "$tor_cv_c_attr_fallthrough" = "yes"; then
510   AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
513 TORUSER=_tor
514 AC_ARG_WITH(tor-user,
515         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
516         [
517            TORUSER=$withval
518         ]
520 AC_SUBST(TORUSER)
522 TORGROUP=_tor
523 AC_ARG_WITH(tor-group,
524         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
525         [
526            TORGROUP=$withval
527         ]
529 AC_SUBST(TORGROUP)
532 dnl If _WIN32 is defined and non-zero, we are building for win32
533 AC_MSG_CHECKING([for win32])
534 AC_RUN_IFELSE([AC_LANG_SOURCE([
535 int main(int c, char **v) {
536 #ifdef _WIN32
537 #if _WIN32
538   return 0;
539 #else
540   return 1;
541 #endif
542 #else
543   return 2;
544 #endif
545 }])],
546 bwin32=true; AC_MSG_RESULT([yes]),
547 bwin32=false; AC_MSG_RESULT([no]),
548 bwin32=cross; AC_MSG_RESULT([cross])
551 if test "$bwin32" = "cross"; then
552 AC_MSG_CHECKING([for win32 (cross)])
553 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
554 #ifdef _WIN32
555 int main(int c, char **v) {return 0;}
556 #else
557 #error
558 int main(int c, char **v) {return x(y);}
559 #endif
560 ])],
561 bwin32=true; AC_MSG_RESULT([yes]),
562 bwin32=false; AC_MSG_RESULT([no]))
565 AH_BOTTOM([
566 #ifdef _WIN32
567 /* Defined to access windows functions and definitions for >=WinXP */
568 # ifndef WINVER
569 #  define WINVER 0x0501
570 # endif
572 /* Defined to access _other_ windows functions and definitions for >=WinXP */
573 # ifndef _WIN32_WINNT
574 #  define _WIN32_WINNT 0x0501
575 # endif
577 /* Defined to avoid including some windows headers as part of Windows.h */
578 # ifndef WIN32_LEAN_AND_MEAN
579 #  define WIN32_LEAN_AND_MEAN 1
580 # endif
581 #endif
584 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
585 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
586 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
588 dnl Enable C99 when compiling with MIPSpro
589 AC_MSG_CHECKING([for MIPSpro compiler])
590 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
591 #if (defined(__sgi) && defined(_COMPILER_VERSION))
592 #error
593   return x(y);
594 #endif
595 ])],
596 bmipspro=false; AC_MSG_RESULT(no),
597 bmipspro=true; AC_MSG_RESULT(yes))
599 if test "$bmipspro" = "true"; then
600   CFLAGS="$CFLAGS -c99"
603 AC_C_BIGENDIAN
605 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
607 if test "x$enable_rust" = "xyes"; then
608   AC_ARG_VAR([RUSTC], [path to the rustc binary])
609   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
610   if test "x$RUSTC" = "xno"; then
611     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
612   fi
614   AC_ARG_VAR([CARGO], [path to the cargo binary])
615   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
616   if test "x$CARGO" = "xno"; then
617     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
618   fi
620   AC_DEFINE([HAVE_RUST], 1, [have Rust])
621   if test "x$enable_fatal_warnings" = "xyes"; then
622     RUST_WARN=
623   else
624     RUST_WARN=#
625   fi
626   if test "x$enable_cargo_online_mode" = "xyes"; then
627     CARGO_ONLINE=
628     RUST_DL=#
629   else
630     CARGO_ONLINE=--frozen
631     RUST_DL=
633     dnl When we're not allowed to touch the network, we need crate dependencies
634     dnl locally available.
635     AC_MSG_CHECKING([rust crate dependencies])
636     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
637     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
638       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
639     fi
640     dnl Check whether the path exists before we try to cd into it.
641     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
642       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.])
643       ERRORED=1
644     fi
645     dnl Make the path absolute, since we'll be using it from within a
646     dnl subdirectory.
647     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
649     for dep in $rust_crates; do
650       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
651         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.])
652         ERRORED=1
653       fi
654     done
655     if test "x$ERRORED" = "x"; then
656       AC_MSG_RESULT([yes])
657     fi
658   fi
660   dnl For now both MSVC and MinGW rust libraries will output static libs with
661   dnl the MSVC naming convention.
662   if test "$bwin32" = "true"; then
663     tor_rust_static_name=tor_rust.lib
664   else
665     tor_rust_static_name=libtor_rust.a
666   fi
668   AC_CANONICAL_BUILD
670   if test -n "$TOR_RUST_TARGET"; then
671     if test "$host" = "$build"; then
672       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
673     fi
674     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
675     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
676   else
677     if test "$host" != "$build"; then
678       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
679     fi
680     RUST_TARGET_PROP=
681     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
682   fi
684   AC_SUBST(RUST_TARGET_PROP)
685   AC_SUBST(TOR_RUST_LIB_PATH)
686   AC_SUBST(CARGO_ONLINE)
687   AC_SUBST(RUST_WARN)
688   AC_SUBST(RUST_DL)
690   dnl Let's check the rustc version, too
691   AC_MSG_CHECKING([rust version])
692   RUSTC_VERSION=`$RUSTC --version`
693   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
694   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
695   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
696     AC_MSG_ERROR([rustc version couldn't be identified])
697   fi
698   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 31; then
699     AC_MSG_ERROR([rustc must be at least version 1.31.0])
700   fi
701   AC_MSG_RESULT([$RUSTC_VERSION])
704 AC_SEARCH_LIBS(socket, [socket network])
705 AC_SEARCH_LIBS(gethostbyname, [nsl])
706 AC_SEARCH_LIBS(dlopen, [dl])
707 AC_SEARCH_LIBS(inet_aton, [resolv])
708 AC_SEARCH_LIBS(backtrace, [execinfo])
709 saved_LIBS="$LIBS"
710 AC_SEARCH_LIBS([clock_gettime], [rt])
711 if test "$LIBS" != "$saved_LIBS"; then
712    # Looks like we need -lrt for clock_gettime().
713    have_rt=yes
716 if test "$bwin32" = "false"; then
717   AC_SEARCH_LIBS(pthread_create, [pthread])
718   AC_SEARCH_LIBS(pthread_detach, [pthread])
721 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
722 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
724 AC_CHECK_FUNCS(
725         _NSGetEnviron \
726         RtlSecureZeroMemory \
727         SecureZeroMemory \
728         accept4 \
729         backtrace \
730         backtrace_symbols_fd \
731         eventfd \
732         explicit_bzero \
733         timingsafe_memcmp \
734         flock \
735         fsync \
736         ftime \
737         get_current_dir_name \
738         getaddrinfo \
739         getdelim \
740         getifaddrs \
741         getline \
742         getrlimit \
743         gettimeofday \
744         gmtime_r \
745         gnu_get_libc_version \
746         inet_aton \
747         ioctl \
748         issetugid \
749         llround \
750         localtime_r \
751         lround \
752         madvise \
753         memmem \
754         memset_s \
755         minherit \
756         mmap \
757         pipe \
758         pipe2 \
759         prctl \
760         readpassphrase \
761         rint \
762         sigaction \
763         socketpair \
764         statvfs \
765         strncasecmp \
766         strcasecmp \
767         strlcat \
768         strlcpy \
769         strnlen \
770         strptime \
771         strtok_r \
772         strtoull \
773         sysconf \
774         sysctl \
775         truncate \
776         uname \
777         usleep \
778         vasprintf \
779         _vscprintf
782 # Apple messed up when they added some functions: they
783 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
784 # checks.
786 # We should only probe for these functions if we are sure that we
787 # are not targeting OS X 10.9 or earlier.
788 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
789 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
790 #ifdef __APPLE__
791 #  include <AvailabilityMacros.h>
792 #  ifndef MAC_OS_X_VERSION_10_10
793 #    define MAC_OS_X_VERSION_10_10 101000
794 #  endif
795 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
796 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
797 #      error "Running on Mac OS X 10.9 or earlier"
798 #    endif
799 #  endif
800 #endif
801 ]], [[]])],
802    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
803    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
805 if test "$on_macos_pre_10_10" = "no"; then
806   AC_CHECK_FUNCS(
807         mach_approximate_time \
808   )
811 # We should only probe for these functions if we are sure that we
812 # are not targeting OSX 10.11 or earlier.
813 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
814 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
815 #ifdef __APPLE__
816 #  include <AvailabilityMacros.h>
817 #  ifndef MAC_OS_X_VERSION_10_12
818 #    define MAC_OS_X_VERSION_10_12 101200
819 #  endif
820 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
821 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
822 #      error "Running on Mac OSX 10.11 or earlier"
823 #    endif
824 #  endif
825 #endif
826 ]], [[]])],
827    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
828    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
830 if test "$on_macos_pre_10_12" = "no"; then
831   AC_CHECK_FUNCS(
832         clock_gettime \
833         getentropy \
834   )
837 if test "$bwin32" != "true"; then
838   AC_CHECK_HEADERS(pthread.h)
839   AC_CHECK_FUNCS(pthread_create)
840   AC_CHECK_FUNCS(pthread_condattr_setclock)
843 if test "$bwin32" = "true"; then
844   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
845 #include <windows.h>
846 #include <conio.h>
847 #include <wchar.h>
848                  ])
851 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
852   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
854 AC_CHECK_FUNCS(glob)
856 AC_MSG_CHECKING([whether free(NULL) works])
857 AC_RUN_IFELSE([AC_LANG_PROGRAM([
858   #include <stdlib.h>
859 ], [
860 char *p = NULL;
861 free(p);
862 ])],
863 [free_null_ok=true; AC_MSG_RESULT(yes)],
864 [free_null_ok=false; AC_MSG_RESULT(no)],
865 [free_null_ok=cross; AC_MSG_RESULT(cross)])
867 if test "$free_null_ok" = "false"; then
868    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
871 dnl ------------------------------------------------------
872 dnl Where do you live, libevent?  And how do we call you?
874 if test "$bwin32" = "true"; then
875   TOR_LIB_WS32=-lws2_32
876   TOR_LIB_IPHLPAPI=-liphlpapi
877   TOR_LIB_SHLWAPI=-lshlwapi
878   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
879   # think it's actually necessary.
880   TOR_LIB_GDI=-lgdi32
881   TOR_LIB_USERENV=-luserenv
882 else
883   TOR_LIB_WS32=
884   TOR_LIB_GDI=
885   TOR_LIB_USERENV=
887 AC_SUBST(TOR_LIB_WS32)
888 AC_SUBST(TOR_LIB_GDI)
889 AC_SUBST(TOR_LIB_IPHLPAPI)
890 AC_SUBST(TOR_LIB_SHLWAPI)
891 AC_SUBST(TOR_LIB_USERENV)
893 tor_libevent_pkg_redhat="libevent"
894 tor_libevent_pkg_debian="libevent-dev"
895 tor_libevent_devpkg_redhat="libevent-devel"
896 tor_libevent_devpkg_debian="libevent-dev"
898 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
899 dnl linking for static builds.
900 STATIC_LIBEVENT_FLAGS=""
901 if test "$enable_static_libevent" = "yes"; then
902     if test "$have_rt" = "yes"; then
903       STATIC_LIBEVENT_FLAGS=" -lrt "
904     fi
907 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
908 #ifdef _WIN32
909 #include <winsock2.h>
910 #endif
911 #include <sys/time.h>
912 #include <sys/types.h>
913 #include <event2/event.h>], [
914 #ifdef _WIN32
915 #include <winsock2.h>
916 #endif
917 struct event_base;
918 struct event_base *event_base_new(void);
919 void event_base_free(struct event_base *);],
920     [
921 #ifdef _WIN32
922 {WSADATA d; WSAStartup(0x101,&d); }
923 #endif
924 event_base_free(event_base_new());
925 ], [--with-libevent-dir], [/opt/libevent])
927 dnl Determine the incantation needed to link libevent.
928 save_LIBS="$LIBS"
929 save_LDFLAGS="$LDFLAGS"
930 save_CPPFLAGS="$CPPFLAGS"
932 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
933 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
934 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
936 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
938 if test "$enable_static_libevent" = "yes"; then
939    if test "$tor_cv_library_libevent_dir" = "(system)"; then
940      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
941    else
942      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
943    fi
944 else
945      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
946        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
947        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"))
949        if test "$ac_cv_search_event_new" != "none required"; then
950          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
951        fi
952        if test "$ac_cv_search_evdns_base_new" != "none required"; then
953          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
954        fi
955      else
956        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
957      fi
960 dnl Now check for particular libevent functions.
961 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
962                 evutil_secure_rng_add_bytes \
963                 evdns_base_get_nameserver_addr \
967 LIBS="$save_LIBS"
968 LDFLAGS="$save_LDFLAGS"
969 CPPFLAGS="$save_CPPFLAGS"
971 dnl Check that libevent is at least at version 2.0.10, the first stable
972 dnl release of its series
973 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
974 AC_MSG_CHECKING([whether Libevent is new enough])
975 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
976 #include <event2/event.h>
977 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
978 #error
979 int x = y(zz);
980 #else
981 int x = 1;
982 #endif
983 ])], [ AC_MSG_RESULT([yes]) ],
984    [ AC_MSG_RESULT([no])
985      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
987 LIBS="$save_LIBS"
988 LDFLAGS="$save_LDFLAGS"
989 CPPFLAGS="$save_CPPFLAGS"
991 AC_SUBST(TOR_LIBEVENT_LIBS)
993 dnl ------------------------------------------------------
994 dnl Where do you live, libm?
996 dnl On some platforms (Haiku/BeOS) the math library is
997 dnl part of libroot. In which case don't link against lm
998 TOR_LIB_MATH=""
999 save_LIBS="$LIBS"
1000 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
1001 if test "$ac_cv_search_pow" != "none required"; then
1002     TOR_LIB_MATH="$ac_cv_search_pow"
1004 LIBS="$save_LIBS"
1005 AC_SUBST(TOR_LIB_MATH)
1007 dnl ------------------------------------------------------
1008 dnl Hello, NSS.  You're new around here.
1009 if test "x$enable_nss" = "xyes"; then
1010   PKG_CHECK_MODULES(NSS,
1011      [nss],
1012      [have_nss=yes],
1013      [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.])])
1014   AC_SUBST(NSS_CFLAGS)
1015   AC_SUBST(NSS_LIBS)
1018 dnl ------------------------------------------------------
1019 dnl Where do you live, openssl?  And how do we call you?
1021 if test "x$enable_nss" != "xyes"; then
1023 tor_openssl_pkg_redhat="openssl"
1024 tor_openssl_pkg_debian="libssl-dev"
1025 tor_openssl_devpkg_redhat="openssl-devel"
1026 tor_openssl_devpkg_debian="libssl-dev"
1028 ALT_openssl_WITHVAL=""
1029 AC_ARG_WITH(ssl-dir,
1030   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
1031   [
1032       if test "x$withval" != "xno" && test "x$withval" != "x"; then
1033          ALT_openssl_WITHVAL="$withval"
1034       fi
1035   ])
1037 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
1038 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
1039     [#include <openssl/ssl.h>
1040      char *getenv(const char *);],
1041     [struct ssl_cipher_st;
1042      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
1043      char *getenv(const char *);],
1044     dnl This funny-looking test program calls getenv, so that the compiler
1045     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
1046     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
1047     dnl We look for SSL_cipher_get_id() because it is present in
1048     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
1049     dnl depends on it.
1050     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
1051     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
1053 if test "$enable_static_openssl" = "yes"; then
1054    if test "$tor_cv_library_openssl_dir" = "(system)"; then
1055      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
1056    else
1057      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
1058    fi
1059 else
1060      TOR_OPENSSL_LIBS="-lssl -lcrypto"
1062 AC_SUBST(TOR_OPENSSL_LIBS)
1064 dnl Now validate openssl, and check for particular openssl functions.
1065 save_LIBS="$LIBS"
1066 save_LDFLAGS="$LDFLAGS"
1067 save_CPPFLAGS="$CPPFLAGS"
1068 LIBS="$TOR_OPENSSL_LIBS $LIBS"
1069 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
1070 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
1072 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1073 #include <openssl/opensslv.h>
1074 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
1075 #error "too old"
1076 #endif
1077    ]], [[]])],
1078    [ : ],
1079    [ 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.]) ])
1081 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1082 #include <openssl/opensslv.h>
1083 #include <openssl/evp.h>
1084 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
1085 #error "no ECC"
1086 #endif
1087 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
1088 #error "curves unavailable"
1089 #endif
1090    ]], [[]])],
1091    [ : ],
1092    [ 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.]) ])
1094 dnl Let's see if we have a version mismatch between includes and libs.
1095 AC_MSG_CHECKING([for significant mismatch between openssl headers and libraries])
1096 ac_retval=foo
1097 AC_TRY_RUN(AC_LANG_PROGRAM([[
1098  #include <openssl/opensslv.h>
1099  #include <openssl/crypto.h>
1100 ]], [[
1101   /* Include major, minor, and fix, but not patch or status. */
1102   unsigned long mask = 0xfffff000;
1103   unsigned long linking = OpenSSL_version_num() & mask;
1104   unsigned long running = OPENSSL_VERSION_NUMBER & mask;
1105   return !(linking==running);
1106 ]]), [openssl_ver_mismatch=no], [
1107    # This is a kludge to figure out whether compilation failed, or whether
1108    # running the program failed.
1109    if test "$ac_retval" == "1"; then
1110       openssl_ver_mismatch=inconclusive
1111    else
1112       openssl_ver_mismatch=yes
1113    fi], [openssl_ver_mismatch=cross])
1114 AC_MSG_RESULT([$openssl_ver_mismatch])
1116 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
1117 [#include <openssl/ssl.h>
1120 dnl OpenSSL functions which we might not have.  In theory, we could just
1121 dnl check the openssl version number, but in practice that gets pretty
1122 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
1123 dnl to them.
1124 AC_CHECK_FUNCS([ \
1125                 ERR_load_KDF_strings \
1126                 EVP_PBE_scrypt \
1127                 SSL_CIPHER_find \
1128                 SSL_CTX_set1_groups_list \
1129                 SSL_CTX_set_security_level \
1130                 SSL_SESSION_get_master_key \
1131                 SSL_get_client_ciphers \
1132                 SSL_get_client_random \
1133                 SSL_get_server_random \
1134                 TLS_method \
1135                ])
1137 dnl Check if OpenSSL structures are opaque
1138 AC_CHECK_MEMBERS([SSL.state], , ,
1139 [#include <openssl/ssl.h>
1142 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
1143 #include <openssl/sha.h>
1146 fi # enable_nss
1148 dnl We will someday make KECCAK_TINY optional, but for now we still need
1149 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
1150 dnl once.  See comment in the definition of crypto_xof_t.
1152 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
1153 dnl   test "x$ac_cv_func_EVP_sha3_256" != "xyes")
1155 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
1157 dnl ======================================================================
1158 dnl Can we use KIST?
1160 dnl Define the set of checks for KIST scheduler support.
1161 AC_DEFUN([CHECK_KIST_SUPPORT],[
1162   dnl KIST needs struct tcp_info and for certain members to exist.
1163   AC_CHECK_MEMBERS(
1164     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1165     , ,[[#include <netinet/tcp.h>]])
1166   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1167   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1168                      #include <linux/sockios.h>
1169                      #ifndef SIOCOUTQNSD
1170                      #error
1171                      #endif
1172                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1173   if test "x$have_siocoutqnsd" = "xyes"; then
1174     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1175       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1176         have_kist_support=yes
1177       fi
1178     fi
1179   fi
1181 dnl Now, trigger the check.
1182 CHECK_KIST_SUPPORT
1183 AS_IF([test "x$have_kist_support" = "xyes"],
1184       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1185                                         on this system])],
1186       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1188 LIBS="$save_LIBS"
1189 LDFLAGS="$save_LDFLAGS"
1190 CPPFLAGS="$save_CPPFLAGS"
1192 dnl ------------------------------------------------------
1193 dnl Where do you live, zlib?  And how do we call you?
1195 tor_zlib_pkg_redhat="zlib"
1196 tor_zlib_pkg_debian="zlib1g"
1197 tor_zlib_devpkg_redhat="zlib-devel"
1198 tor_zlib_devpkg_debian="zlib1g-dev"
1200 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1201     [#include <zlib.h>],
1202     [const char * zlibVersion(void);],
1203     [zlibVersion();], [--with-zlib-dir],
1204     [/opt/zlib])
1206 if test "$enable_static_zlib" = "yes"; then
1207    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1208      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1209  using --enable-static-zlib")
1210    else
1211      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1212    fi
1213 else
1214      TOR_ZLIB_LIBS="-lz"
1216 AC_SUBST(TOR_ZLIB_LIBS)
1218 dnl ------------------------------------------------------
1219 dnl Where we do we find lzma?
1221 AC_ARG_ENABLE(lzma,
1222       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1223       [case "${enableval}" in
1224         "yes") ;;
1225         "no")  ;;
1226         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1227       esac], [enable_lzma=auto])
1229 if test "x$enable_lzma" = "xno"; then
1230     have_lzma=no;
1231 else
1232     PKG_CHECK_MODULES([LZMA],
1233                       [liblzma],
1234                       have_lzma=yes,
1235                       have_lzma=no)
1237     if test "x$have_lzma" = "xno" ; then
1238         tor_incr_n_warnings
1239         AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
1240     fi
1243 if test "x$have_lzma" = "xyes"; then
1244     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1245     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1246     TOR_LZMA_LIBS="${LZMA_LIBS}"
1248 AC_SUBST(TOR_LZMA_CFLAGS)
1249 AC_SUBST(TOR_LZMA_LIBS)
1251 dnl ------------------------------------------------------
1252 dnl Where we do we find zstd?
1254 AC_ARG_ENABLE(zstd,
1255       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1256       [case "${enableval}" in
1257         "yes") ;;
1258         "no")  ;;
1259         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1260       esac], [enable_zstd=auto])
1262 if test "x$enable_zstd" = "xno"; then
1263     have_zstd=no;
1264 else
1265     PKG_CHECK_MODULES([ZSTD],
1266                       [libzstd >= 1.1],
1267                       have_zstd=yes,
1268                       have_zstd=no)
1270     if test "x$have_zstd" = "xno" ; then
1271         tor_incr_n_warnings
1272         AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
1273     fi
1276 if test "x$have_zstd" = "xyes"; then
1277     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1278     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1279     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1281     dnl now check for zstd functions
1282     save_LIBS="$LIBS"
1283     save_CFLAGS="$CFLAGS"
1284     LIBS="$LIBS $ZSTD_LIBS"
1285     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1286     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1287                    ZSTD_estimateDCtxSize)
1288     LIBS="$save_LIBS"
1289     CFLAGS="$save_CFLAGS"
1291 AC_SUBST(TOR_ZSTD_CFLAGS)
1292 AC_SUBST(TOR_ZSTD_LIBS)
1294 dnl ----------------------------------------------------------------------
1295 dnl Check if libcap is available for capabilities.
1297 tor_cap_pkg_debian="libcap2"
1298 tor_cap_pkg_redhat="libcap"
1299 tor_cap_devpkg_debian="libcap-dev"
1300 tor_cap_devpkg_redhat="libcap-devel"
1302 AC_CHECK_LIB([cap], [cap_init], [],
1303   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1305 AC_CHECK_FUNCS(cap_set_proc)
1307 dnl ---------------------------------------------------------------------
1308 dnl Now that we know about our major libraries, we can check for compiler
1309 dnl and linker hardening options.  We need to do this with the libraries known,
1310 dnl since sometimes the linker will like an option but not be willing to
1311 dnl use it with a build of a library.
1313 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1314 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"
1316 CFLAGS_FTRAPV=
1317 CFLAGS_FWRAPV=
1318 CFLAGS_ASAN=
1319 CFLAGS_UBSAN=
1322 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1323 #if !defined(__clang__)
1324 #error
1325 #endif])], have_clang=yes, have_clang=no)
1327 if test "x$enable_pic" = "xyes"; then
1328     TOR_CHECK_CFLAGS(-fPIC)
1331 if test "x$enable_gcc_hardening" != "xno"; then
1332     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1333     if test "x$have_clang" = "xyes"; then
1334         TOR_CHECK_CFLAGS(-Qunused-arguments)
1335     fi
1336     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1337     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1338     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1339 m4_ifdef([AS_VAR_IF],[
1340     AS_VAR_IF(can_compile, [yes],
1341         AS_VAR_IF(can_link, [yes],
1342                   [],
1343                   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.)]))
1344         )])
1345     AS_VAR_POPDEF([can_link])
1346     AS_VAR_POPDEF([can_compile])
1347     TOR_CHECK_CFLAGS(-Wstack-protector)
1348     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1349     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1350        if test "$enable_pic" != "yes"; then
1351            # If we have already enabled -fPIC, then we don't also need to
1352            # compile with -fPIE...
1353            TOR_CHECK_CFLAGS(-fPIE)
1354        fi
1355        # ... but we want to link our executables with -pie in any case, since
1356        # they're executables, not a library.
1357        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1358     fi
1359     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1361    AC_MSG_CHECKING([whether we can run hardened binaries])
1362    AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1363         [AC_MSG_RESULT([yes])],
1364         [AC_MSG_RESULT([no])
1365          AC_MSG_ERROR([dnl
1366  We can link with compiler hardening options, but we can't run with them.
1367  That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1368  configure, but it would be better to figure out what the underlying problem
1369  is.])],
1370         [AC_MSG_RESULT([cross])])
1373 if test "$fragile_hardening" = "yes"; then
1374     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1375    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1376       tor_incr_n_warnings
1377       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.])
1378    fi
1380    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1381      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1382    fi
1384    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1385     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1386       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*])
1387     fi
1389    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1390     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1391       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*])
1392     fi
1394    TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1395     if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1396       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*])
1397     fi
1399 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1402 dnl Find the correct libraries to add in order to use the sanitizers.
1404 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1405 dnl option, which will prevent the compiler from linking the sanitizer
1406 dnl libraries it needs.  We need to specify them manually.
1408 dnl What's more, we need to specify them in a linker script rather than
1409 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1410 dnl variable.
1411 RUST_LINKER_OPTIONS=""
1412 if test "x$have_clang" = "xyes"; then
1413         if test "x$CFLAGS_ASAN" != "x"; then
1414                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
1415         fi
1416         if test "x$CFLAGS_UBSAN" != "x"; then
1417                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
1418         fi
1419 else
1420         if test "x$CFLAGS_ASAN" != "x"; then
1421                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
1422         fi
1423         if test "x$CFLAGS_UBSAN" != "x"; then
1424                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
1425         fi
1427 AC_SUBST(RUST_LINKER_OPTIONS)
1429 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1430 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1432 mulodi_fixes_ftrapv=no
1433 if test "$have_clang" = "yes"; then
1434   saved_CFLAGS="$CFLAGS"
1435   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1436   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1437   AC_LINK_IFELSE([
1438       AC_LANG_SOURCE([[
1439           #include <stdint.h>
1440           #include <stdlib.h>
1441           int main(int argc, char **argv)
1442           {
1443             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1444                         * (int64_t)atoi(argv[3]);
1445             return x == 9;
1446           } ]])],
1447           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1448           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1449   if test "$ftrapv_can_link" = "no"; then
1450     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1451     AC_LINK_IFELSE([
1452       AC_LANG_SOURCE([[
1453           #include <stdint.h>
1454           #include <stdlib.h>
1455           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1456              *overflow=0;
1457              return a;
1458           }
1459           int main(int argc, char **argv)
1460           {
1461             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1462                         * (int64_t)atoi(argv[3]);
1463             return x == 9;
1464           } ]])],
1465           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1466           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1467   fi
1468   CFLAGS="$saved_CFLAGS"
1471 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1473 dnl These cflags add bunches of branches, and we haven't been able to
1474 dnl persuade ourselves that they're suitable for code that needs to be
1475 dnl constant time.
1476 AC_SUBST(CFLAGS_BUGTRAP)
1477 dnl These cflags are variant ones sutable for code that needs to be
1478 dnl constant-time.
1479 AC_SUBST(CFLAGS_CONSTTIME)
1481 if test "x$enable_linker_hardening" != "xno"; then
1482     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1485 # For backtrace support
1486 TOR_CHECK_LDFLAGS(-rdynamic)
1488 dnl ------------------------------------------------------
1489 dnl Now see if we have a -fomit-frame-pointer compiler option.
1491 saved_CFLAGS="$CFLAGS"
1492 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1493 F_OMIT_FRAME_POINTER=''
1494 if test "$saved_CFLAGS" != "$CFLAGS"; then
1495   if test "$fragile_hardening" = "yes"; then
1496     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1497   fi
1499 CFLAGS="$saved_CFLAGS"
1500 AC_SUBST(F_OMIT_FRAME_POINTER)
1502 dnl ------------------------------------------------------
1503 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1504 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1505 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1506 dnl code will work.
1507 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1509 dnl ============================================================
1510 dnl Check for libseccomp
1512 if test "x$enable_seccomp" != "xno"; then
1513   AC_CHECK_HEADERS([seccomp.h])
1514   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1517 dnl ============================================================
1518 dnl Check for libscrypt
1520 if test "x$enable_libscrypt" != "xno"; then
1521   AC_CHECK_HEADERS([libscrypt.h])
1522   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1523   AC_CHECK_FUNCS([libscrypt_scrypt])
1526 dnl ============================================================
1527 dnl We need an implementation of curve25519.
1529 dnl set these defaults.
1530 build_curve25519_donna=no
1531 build_curve25519_donna_c64=no
1532 use_curve25519_donna=no
1533 use_curve25519_nacl=no
1534 CURVE25519_LIBS=
1536 dnl The best choice is using curve25519-donna-c64, but that requires
1537 dnl that we
1538 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1539   tor_cv_can_use_curve25519_donna_c64,
1540   [AC_RUN_IFELSE(
1541     [AC_LANG_PROGRAM([dnl
1542       #include <stdint.h>
1543       typedef unsigned uint128_t __attribute__((mode(TI)));
1544   int func(uint64_t a, uint64_t b) {
1545            uint128_t c = ((uint128_t)a) * b;
1546            int ok = ((uint64_t)(c>>96)) == 522859 &&
1547              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1548                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1549                  (((uint64_t)(c))&0xffffffffL) == 0;
1550            return ok;
1551       }
1552   ], [dnl
1553     int ok = func( ((uint64_t)2000000000) * 1000000000,
1554                    ((uint64_t)1234567890) << 24);
1555         return !ok;
1556       ])],
1557   [tor_cv_can_use_curve25519_donna_c64=yes],
1558       [tor_cv_can_use_curve25519_donna_c64=no],
1559   [AC_LINK_IFELSE(
1560         [AC_LANG_PROGRAM([dnl
1561       #include <stdint.h>
1562       typedef unsigned uint128_t __attribute__((mode(TI)));
1563   int func(uint64_t a, uint64_t b) {
1564            uint128_t c = ((uint128_t)a) * b;
1565            int ok = ((uint64_t)(c>>96)) == 522859 &&
1566              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1567                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1568                  (((uint64_t)(c))&0xffffffffL) == 0;
1569            return ok;
1570       }
1571   ], [dnl
1572     int ok = func( ((uint64_t)2000000000) * 1000000000,
1573                  ((uint64_t)1234567890) << 24);
1574         return !ok;
1575       ])],
1576           [tor_cv_can_use_curve25519_donna_c64=cross],
1577       [tor_cv_can_use_curve25519_donna_c64=no])])])
1579 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1580                   nacl/crypto_scalarmult_curve25519.h])
1582 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1583   tor_cv_can_use_curve25519_nacl,
1584   [tor_saved_LIBS="$LIBS"
1585    LIBS="$LIBS -lnacl"
1586    AC_LINK_IFELSE(
1587      [AC_LANG_PROGRAM([dnl
1588        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1589        #include <crypto_scalarmult_curve25519.h>
1590    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1591    #include <nacl/crypto_scalarmult_curve25519.h>
1592    #endif
1593        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1594    #error Hey, this is the reference implementation! That's not fast.
1595    #endif
1596      ], [
1597    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1598      ])], [tor_cv_can_use_curve25519_nacl=yes],
1599      [tor_cv_can_use_curve25519_nacl=no])
1600    LIBS="$tor_saved_LIBS" ])
1602  dnl Okay, now we need to figure out which one to actually use. Fall back
1603  dnl to curve25519-donna.c
1605  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1606    build_curve25519_donna_c64=yes
1607    use_curve25519_donna=yes
1608  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1609    use_curve25519_nacl=yes
1610    CURVE25519_LIBS=-lnacl
1611  else
1612    build_curve25519_donna=yes
1613    use_curve25519_donna=yes
1614  fi
1616 if test "x$use_curve25519_donna" = "xyes"; then
1617   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1618             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1620 if test "x$use_curve25519_nacl" = "xyes"; then
1621   AC_DEFINE(USE_CURVE25519_NACL, 1,
1622             [Defined if we should use a curve25519 from nacl])
1624 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1625   test "x$build_curve25519_donna" = "xyes")
1626 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1627   test "x$build_curve25519_donna_c64" = "xyes")
1628 AC_SUBST(CURVE25519_LIBS)
1630 dnl Make sure to enable support for large off_t if available.
1631 AC_SYS_LARGEFILE
1633 AC_CHECK_HEADERS([errno.h \
1634                   fcntl.h \
1635                   signal.h \
1636                   string.h \
1637                   sys/capability.h \
1638                   sys/fcntl.h \
1639                   sys/stat.h \
1640                   sys/time.h \
1641                   sys/types.h \
1642                   time.h \
1643                   unistd.h \
1644                   arpa/inet.h \
1645                   crt_externs.h \
1646                   execinfo.h \
1647                   gnu/libc-version.h \
1648                   grp.h \
1649                   ifaddrs.h \
1650                   inttypes.h \
1651                   limits.h \
1652                   linux/types.h \
1653                   mach/vm_inherit.h \
1654                   machine/limits.h \
1655                   malloc.h \
1656                   netdb.h \
1657                   netinet/in.h \
1658                   netinet/in6.h \
1659                   pwd.h \
1660                   readpassphrase.h \
1661                   stdatomic.h \
1662                   sys/eventfd.h \
1663                   sys/file.h \
1664                   sys/ioctl.h \
1665                   sys/limits.h \
1666                   sys/mman.h \
1667                   sys/param.h \
1668                   sys/prctl.h \
1669                   sys/random.h \
1670                   sys/resource.h \
1671                   sys/select.h \
1672                   sys/socket.h \
1673                   sys/statvfs.h \
1674                   sys/syscall.h \
1675                   sys/sysctl.h \
1676                   sys/time.h \
1677                   sys/types.h \
1678                   sys/un.h \
1679                   sys/utime.h \
1680                   sys/wait.h \
1681                   syslog.h \
1682                   utime.h \
1683                   glob.h])
1685 AC_CHECK_HEADERS(sys/param.h)
1687 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1688 [#ifdef HAVE_SYS_TYPES_H
1689 #include <sys/types.h>
1690 #endif
1691 #ifdef HAVE_SYS_SOCKET_H
1692 #include <sys/socket.h>
1693 #endif])
1694 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1695 [#ifdef HAVE_SYS_TYPES_H
1696 #include <sys/types.h>
1697 #endif
1698 #ifdef HAVE_SYS_SOCKET_H
1699 #include <sys/socket.h>
1700 #endif
1701 #ifdef HAVE_NET_IF_H
1702 #include <net/if.h>
1703 #endif
1704 #ifdef HAVE_NETINET_IN_H
1705 #include <netinet/in.h>
1706 #endif])
1708 AC_CHECK_HEADERS(linux/if.h,[],[],
1710 #ifdef HAVE_SYS_SOCKET_H
1711 #include <sys/socket.h>
1712 #endif
1715 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1716         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1717 [#ifdef HAVE_SYS_TYPES_H
1718 #include <sys/types.h>
1719 #endif
1720 #ifdef HAVE_SYS_SOCKET_H
1721 #include <sys/socket.h>
1722 #endif
1723 #ifdef HAVE_LIMITS_H
1724 #include <limits.h>
1725 #endif
1726 #ifdef HAVE_LINUX_TYPES_H
1727 #include <linux/types.h>
1728 #endif
1729 #ifdef HAVE_NETINET_IN6_H
1730 #include <netinet/in6.h>
1731 #endif
1732 #ifdef HAVE_NETINET_IN_H
1733 #include <netinet/in.h>
1734 #endif])
1736 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1737         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1738 [#ifdef HAVE_SYS_TYPES_H
1739 #include <sys/types.h>
1740 #endif
1741 #ifdef HAVE_SYS_SOCKET_H
1742 #include <sys/socket.h>
1743 #endif
1744 #ifdef HAVE_LIMITS_H
1745 #include <limits.h>
1746 #endif
1747 #ifdef HAVE_LINUX_TYPES_H
1748 #include <linux/types.h>
1749 #endif
1750 #ifdef HAVE_NETINET_IN6_H
1751 #include <netinet/in6.h>
1752 #endif
1753 #ifdef HAVE_NETINET_IN_H
1754 #include <netinet/in.h>
1755 #endif
1756 #ifdef HAVE_LINUX_IF_H
1757 #include <linux/if.h>
1758 #endif])
1760 transparent_ok=0
1761 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1762   transparent_ok=1
1764 if test "x$linux_netfilter_ipv4" = "x1"; then
1765   transparent_ok=1
1767 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1768   transparent_ok=1
1770 if test "x$transparent_ok" = "x1"; then
1771   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1772 else
1773   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1776 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1777 [#ifdef HAVE_SYS_TYPES_H
1778 #include <sys/types.h>
1779 #endif
1780 #ifdef HAVE_SYS_TIME_H
1781 #include <sys/time.h>
1782 #endif])
1784 AC_CHECK_SIZEOF(char)
1785 AC_CHECK_SIZEOF(short)
1786 AC_CHECK_SIZEOF(int)
1787 AC_CHECK_SIZEOF(unsigned int)
1788 AC_CHECK_SIZEOF(long)
1789 AC_CHECK_SIZEOF(long long)
1790 AC_CHECK_SIZEOF(__int64)
1791 AC_CHECK_SIZEOF(void *)
1792 AC_CHECK_SIZEOF(time_t)
1793 AC_CHECK_SIZEOF(size_t)
1794 AC_CHECK_SIZEOF(pid_t)
1796 AC_CHECK_TYPES([uint, u_char, ssize_t])
1798 AC_PC_FROM_UCONTEXT([:])
1800 dnl used to include sockaddr_storage, but everybody has that.
1801 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1802 [#ifdef HAVE_SYS_TYPES_H
1803 #include <sys/types.h>
1804 #endif
1805 #ifdef HAVE_NETINET_IN_H
1806 #include <netinet/in.h>
1807 #endif
1808 #ifdef HAVE_NETINET_IN6_H
1809 #include <netinet/in6.h>
1810 #endif
1811 #ifdef HAVE_SYS_SOCKET_H
1812 #include <sys/socket.h>
1813 #endif
1814 #ifdef _WIN32
1815 #define _WIN32_WINNT 0x0501
1816 #define WIN32_LEAN_AND_MEAN
1817 #include <winsock2.h>
1818 #include <ws2tcpip.h>
1819 #endif
1821 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1822 [#ifdef HAVE_SYS_TYPES_H
1823 #include <sys/types.h>
1824 #endif
1825 #ifdef HAVE_NETINET_IN_H
1826 #include <netinet/in.h>
1827 #endif
1828 #ifdef HAVE_NETINET_IN6_H
1829 #include <netinet/in6.h>
1830 #endif
1831 #ifdef HAVE_SYS_SOCKET_H
1832 #include <sys/socket.h>
1833 #endif
1834 #ifdef _WIN32
1835 #define _WIN32_WINNT 0x0501
1836 #define WIN32_LEAN_AND_MEAN
1837 #include <winsock2.h>
1838 #include <ws2tcpip.h>
1839 #endif
1842 AC_CHECK_TYPES([rlim_t], , ,
1843 [#ifdef HAVE_SYS_TYPES_H
1844 #include <sys/types.h>
1845 #endif
1846 #ifdef HAVE_SYS_TIME_H
1847 #include <sys/time.h>
1848 #endif
1849 #ifdef HAVE_SYS_RESOURCE_H
1850 #include <sys/resource.h>
1851 #endif
1854 AX_CHECK_SIGN([time_t],
1855        [ : ],
1856        [ : ], [
1857 #ifdef HAVE_SYS_TYPES_H
1858 #include <sys/types.h>
1859 #endif
1860 #ifdef HAVE_SYS_TIME_H
1861 #include <sys/time.h>
1862 #endif
1863 #ifdef HAVE_TIME_H
1864 #include <time.h>
1865 #endif
1868 if test "$ax_cv_decl_time_t_signed" = "no"; then
1869   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1872 AX_CHECK_SIGN([size_t],
1873        [ tor_cv_size_t_signed=yes ],
1874        [ tor_cv_size_t_signed=no ], [
1875 #ifdef HAVE_SYS_TYPES_H
1876 #include <sys/types.h>
1877 #endif
1880 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1881   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1884 AX_CHECK_SIGN([enum always],
1885        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1886        [ : ], [
1887  enum always { AAA, BBB, CCC };
1890 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1891 #ifdef HAVE_SYS_SOCKET_H
1892 #include <sys/socket.h>
1893 #endif
1896 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1898 AC_CHECK_SIZEOF(cell_t)
1900 # Let's see if stdatomic works. (There are some debian clangs that screw it
1901 # up; see Tor bug #26779 and debian bug 903709.)
1902 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1903                tor_cv_stdatomic_works,
1904 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1905 #include <stdatomic.h>
1906 struct x { atomic_size_t y; };
1907 void try_atomic_init(struct x *xx)
1909   atomic_init(&xx->y, 99);
1910   atomic_fetch_add(&xx->y, 1);
1912 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1914 if test "$tor_cv_stdatomic_works" = "yes"; then
1915    AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1916 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1917    tor_incr_n_warnings
1918    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 ])
1921 # Now make sure that NULL can be represented as zero bytes.
1922 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1923 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1924 [[#include <stdlib.h>
1925 #include <string.h>
1926 #include <stdio.h>
1927 #ifdef HAVE_STDDEF_H
1928 #include <stddef.h>
1929 #endif
1930 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1931 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1932        [tor_cv_null_is_zero=yes],
1933        [tor_cv_null_is_zero=no],
1934        [tor_cv_null_is_zero=cross])])
1936 if test "$tor_cv_null_is_zero" = "cross"; then
1937   # Cross-compiling; let's hope that the target isn't raving mad.
1938   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1941 if test "$tor_cv_null_is_zero" != "no"; then
1942   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1943             [Define to 1 iff memset(0) sets pointers to NULL])
1946 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1947 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1948 [[#include <stdlib.h>
1949 #include <string.h>
1950 #include <stdio.h>
1951 #ifdef HAVE_STDDEF_H
1952 #include <stddef.h>
1953 #endif
1954 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1955 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1956        [tor_cv_dbl0_is_zero=yes],
1957        [tor_cv_dbl0_is_zero=no],
1958        [tor_cv_dbl0_is_zero=cross])])
1960 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1961   # Cross-compiling; let's hope that the target isn't raving mad.
1962   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1965 if test "$tor_cv_dbl0_is_zero" != "no"; then
1966   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1967             [Define to 1 iff memset(0) sets doubles to 0.0])
1970 # And what happens when we malloc zero?
1971 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1972 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1973 [[#include <stdlib.h>
1974 #include <string.h>
1975 #include <stdio.h>
1976 #ifdef HAVE_STDDEF_H
1977 #include <stddef.h>
1978 #endif
1979 int main () { return malloc(0)?0:1; }]])],
1980        [tor_cv_malloc_zero_works=yes],
1981        [tor_cv_malloc_zero_works=no],
1982        [tor_cv_malloc_zero_works=cross])])
1984 if test "$tor_cv_malloc_zero_works" = "cross"; then
1985   # Cross-compiling; let's hope that the target isn't raving mad.
1986   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1989 if test "$tor_cv_malloc_zero_works" = "yes"; then
1990   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1991             [Define to 1 iff malloc(0) returns a pointer])
1994 # whether we seem to be in a 2s-complement world.
1995 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1996 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1997 [[int main () { int problem = ((-99) != (~99)+1);
1998 return problem ? 1 : 0; }]])],
1999        [tor_cv_twos_complement=yes],
2000        [tor_cv_twos_complement=no],
2001        [tor_cv_twos_complement=cross])])
2003 if test "$tor_cv_twos_complement" = "cross"; then
2004   # Cross-compiling; let's hope that the target isn't raving mad.
2005   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
2008 if test "$tor_cv_twos_complement" != "no"; then
2009   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
2010             [Define to 1 iff we represent negative integers with
2011              two's complement])
2014 # What does shifting a negative value do?
2015 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
2016 [AC_RUN_IFELSE([AC_LANG_SOURCE(
2017 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
2018        [tor_cv_sign_extend=yes],
2019        [tor_cv_sign_extend=no],
2020        [tor_cv_sign_extend=cross])])
2022 if test "$tor_cv_sign_extend" = "cross"; then
2023   # Cross-compiling; let's hope that the target isn't raving mad.
2024   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
2027 if test "$tor_cv_sign_extend" != "no"; then
2028   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
2029             [Define to 1 iff right-shifting a negative value performs sign-extension])
2032 # Is uint8_t the same type as unsigned char?
2033 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
2034 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2035 #include <stdint.h>
2036 extern uint8_t c;
2037 unsigned char c;]])],
2038        [tor_cv_uint8_uchar=yes],
2039        [tor_cv_uint8_uchar=no],
2040        [tor_cv_uint8_uchar=cross])])
2042 if test "$tor_cv_uint8_uchar" = "cross"; then
2043   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
2046 if test "$tor_cv_uint8_uchar" = "no"; then
2047   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
2050 AC_ARG_WITH(tcmalloc,
2051 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
2053 default_malloc=system
2055 if test "x$enable_openbsd_malloc" = "xyes" ; then
2056   AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
2057   default_malloc=openbsd
2060 if test "x$with_tcmalloc" = "xyes"; then
2061   AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
2062   default_malloc=tcmalloc
2065 AC_ARG_WITH(malloc,
2066    AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
2067                   [select special malloc implementation [system]]),
2068    [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
2070 AS_CASE([$malloc],
2071   [tcmalloc], [
2072       PKG_CHECK_MODULES([TCMALLOC],
2073                         [libtcmalloc],
2074                         have_tcmalloc=yes,
2075                         have_tcmalloc=no)
2077       if test "x$have_tcmalloc" = "xno" ; then
2078           AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
2079       fi
2081       CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
2082       LIBS="$TCMALLOC_LIBS $LIBS"
2083   ],
2085   [jemalloc], [
2086       PKG_CHECK_MODULES([JEMALLOC],
2087                         [jemalloc],
2088                         have_jemalloc=yes,
2089                         have_jemalloc=no)
2091       if test "x$have_jemalloc" = "xno" ; then
2092           AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
2093       fi
2095       CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
2096       LIBS="$JEMALLOC_LIBS $LIBS"
2097       using_custom_malloc=yes
2098   ],
2100   [openbsd], [
2101     tor_incr_n_warnings
2102     AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
2103     enable_openbsd_malloc=yes
2104   ],
2106   [system], [
2107      # handle this later, including the jemalloc fallback
2108     AC_CHECK_FUNCS(mallinfo)
2109   ],
2111   [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
2114 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
2116 if test "$malloc" != "system"; then
2117   # Tell the C compiler not to use the system allocator functions.
2118   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2120 if test "$using_custom_malloc" = "yes"; then
2121   # Tell the C compiler not to use the system allocator functions.
2122   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2125 # By default, we're going to assume we don't have mlockall()
2126 # bionic and other platforms have various broken mlockall subsystems.
2127 # Some systems don't have a working mlockall, some aren't linkable,
2128 # and some have it but don't declare it.
2129 AC_CHECK_FUNCS(mlockall)
2130 AC_CHECK_DECLS([mlockall], , , [
2131 #ifdef HAVE_SYS_MMAN_H
2132 #include <sys/mman.h>
2133 #endif])
2135 # Allow user to specify an alternate syslog facility
2136 AC_ARG_WITH(syslog-facility,
2137 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
2138 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
2139 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
2140 AC_SUBST(LOGFACILITY)
2142 # Check if we have getresuid and getresgid
2143 AC_CHECK_FUNCS(getresuid getresgid)
2145 # Check for gethostbyname_r in all its glorious incompatible versions.
2146 #   (This logic is based on that in Python's configure.in)
2147 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
2148   [Define this if you have any gethostbyname_r()])
2150 AC_CHECK_FUNC(gethostbyname_r, [
2151   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
2152   OLD_CFLAGS=$CFLAGS
2153   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
2154   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2155 #include <netdb.h>
2156   ]], [[
2157     char *cp1, *cp2;
2158     struct hostent *h1, *h2;
2159     int i1, i2;
2160     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2161   ]])],[
2162     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2163     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2164      [Define this if gethostbyname_r takes 6 arguments])
2165     AC_MSG_RESULT(6)
2166   ], [
2167     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2168 #include <netdb.h>
2169     ]], [[
2170       char *cp1, *cp2;
2171       struct hostent *h1;
2172       int i1, i2;
2173       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2174     ]])], [
2175       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2176       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2177         [Define this if gethostbyname_r takes 5 arguments])
2178       AC_MSG_RESULT(5)
2179    ], [
2180       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2181 #include <netdb.h>
2182      ]], [[
2183        char *cp1;
2184        struct hostent *h1;
2185        struct hostent_data hd;
2186        (void) gethostbyname_r(cp1,h1,&hd);
2187      ]])], [
2188        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2189        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2190          [Define this if gethostbyname_r takes 3 arguments])
2191        AC_MSG_RESULT(3)
2192      ], [
2193        AC_MSG_RESULT(0)
2194      ])
2195   ])
2196  ])
2197  CFLAGS=$OLD_CFLAGS
2200 AC_CACHE_CHECK([whether the C compiler supports __func__],
2201   tor_cv_have_func_macro,
2202   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2203 #include <stdio.h>
2204 int main(int c, char **v) { puts(__func__); }])],
2205   tor_cv_have_func_macro=yes,
2206   tor_cv_have_func_macro=no))
2208 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2209   tor_cv_have_FUNC_macro,
2210   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2211 #include <stdio.h>
2212 int main(int c, char **v) { puts(__FUNC__); }])],
2213   tor_cv_have_FUNC_macro=yes,
2214   tor_cv_have_FUNC_macro=no))
2216 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2217   tor_cv_have_FUNCTION_macro,
2218   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2219 #include <stdio.h>
2220 int main(int c, char **v) { puts(__FUNCTION__); }])],
2221   tor_cv_have_FUNCTION_macro=yes,
2222   tor_cv_have_FUNCTION_macro=no))
2224 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2225   tor_cv_have_environ_declared,
2226   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2227 #ifdef HAVE_UNISTD_H
2228 #include <unistd.h>
2229 #endif
2230 #include <stdlib.h>
2231 int main(int c, char **v) { char **t = environ; }])],
2232   tor_cv_have_environ_declared=yes,
2233   tor_cv_have_environ_declared=no))
2235 if test "$tor_cv_have_func_macro" = "yes"; then
2236   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2239 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2240   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2243 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2244   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2245            [Defined if the compiler supports __FUNCTION__])
2248 if test "$tor_cv_have_environ_declared" = "yes"; then
2249   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2250            [Defined if we have extern char **environ already declared])
2253 # $prefix stores the value of the --prefix command line option, or
2254 # NONE if the option wasn't set.  In the case that it wasn't set, make
2255 # it be the default, so that we can use it to expand directories now.
2256 if test "x$prefix" = "xNONE"; then
2257   prefix=$ac_default_prefix
2260 # and similarly for $exec_prefix
2261 if test "x$exec_prefix" = "xNONE"; then
2262   exec_prefix=$prefix
2265 if test "x$BUILDDIR" = "x"; then
2266   BUILDDIR=`pwd`
2268 AC_SUBST(BUILDDIR)
2269 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2270 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2272 if test "x$SRCDIR" = "x"; then
2273   SRCDIR=$(cd "$srcdir"; pwd)
2275 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2276 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2278 if test "x$CONFDIR" = "x"; then
2279   CONFDIR=`eval echo $sysconfdir/tor`
2281 AC_SUBST(CONFDIR)
2282 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2283 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2285 BINDIR=`eval echo $bindir`
2286 AC_SUBST(BINDIR)
2287 LOCALSTATEDIR=`eval echo $localstatedir`
2288 AC_SUBST(LOCALSTATEDIR)
2290 if test "$bwin32" = "true"; then
2291   # Test if the linker supports the --nxcompat and --dynamicbase options
2292   # for Windows
2293   save_LDFLAGS="$LDFLAGS"
2294   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2295   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2296   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2297     [AC_MSG_RESULT([yes])]
2298     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2299     [AC_MSG_RESULT([no])]
2300   )
2301   LDFLAGS="$save_LDFLAGS"
2304 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2305 # than autoconf's macros like.
2306 if test "$GCC" = "yes"; then
2307   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2308   # accident waiting to happen.
2309   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2310 else
2311   # Override optimization level for non-gcc compilers
2312   CFLAGS="$CFLAGS -O"
2313   enable_gcc_warnings=no
2314   enable_gcc_warnings_advisory=no
2317 # Warnings implies advisory-warnings and -Werror.
2318 if test "$enable_gcc_warnings" = "yes"; then
2319   enable_gcc_warnings_advisory=yes
2320   enable_fatal_warnings=yes
2323 # OS X Lion started deprecating the system openssl. Let's just disable
2324 # all deprecation warnings on OS X. Also, to potentially make the binary
2325 # a little smaller, let's enable dead_strip.
2326 case "$host_os" in
2328  darwin*)
2329     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2330     LDFLAGS="$LDFLAGS -dead_strip" ;;
2331 esac
2333 TOR_WARNING_FLAGS=""
2335 # Add some more warnings which we use in development but not in the
2336 # released versions.  (Some relevant gcc versions can't handle these.)
2338 # Note that we have to do this near the end  of the autoconf process, or
2339 # else we may run into problems when these warnings hit on the testing C
2340 # programs that autoconf wants to build.
2341 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2343   case "$host" in
2344     *-*-openbsd* | *-*-bitrig*)
2345       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2346       # That's fine, except that the headers don't pass -Wredundant-decls.
2347       # Therefore, let's disable -Wsystem-headers when we're building
2348       # with maximal warnings on OpenBSD.
2349       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2350   esac
2352   CFLAGS_NOWARNINGS="$CFLAGS"
2354   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2355   # have it work better.
2356   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2358   # This warning was added in gcc 4.3, but it appears to generate
2359   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2360   #CFLAGS="$CFLAGS -Wlogical-op"
2362   m4_foreach_w([warning_flag], [
2363      -Waddress
2364      -Waddress-of-array-temporary
2365      -Waddress-of-temporary
2366      -Wambiguous-macro
2367      -Wanonymous-pack-parens
2368      -Warc
2369      -Warc-abi
2370      -Warc-bridge-casts-disallowed-in-nonarc
2371      -Warc-maybe-repeated-use-of-weak
2372      -Warc-performSelector-leaks
2373      -Warc-repeated-use-of-weak
2374      -Warray-bounds
2375      -Warray-bounds-pointer-arithmetic
2376      -Wasm
2377      -Wasm-operand-widths
2378      -Watomic-properties
2379      -Watomic-property-with-user-defined-accessor
2380      -Wauto-import
2381      -Wauto-storage-class
2382      -Wauto-var-id
2383      -Wavailability
2384      -Wbackslash-newline-escape
2385      -Wbad-array-new-length
2386      -Wbind-to-temporary-copy
2387      -Wbitfield-constant-conversion
2388      -Wbool-conversion
2389      -Wbool-conversions
2390      -Wbuiltin-requires-header
2391      -Wchar-align
2392      -Wcompare-distinct-pointer-types
2393      -Wcomplex-component-init
2394      -Wconditional-type-mismatch
2395      -Wconfig-macros
2396      -Wconstant-conversion
2397      -Wconstant-logical-operand
2398      -Wconstexpr-not-const
2399      -Wcustom-atomic-properties
2400      -Wdangling-field
2401      -Wdangling-initializer-list
2402      -Wdate-time
2403      -Wdelegating-ctor-cycles
2404      -Wdeprecated-implementations
2405      -Wdeprecated-register
2406      -Wdirect-ivar-access
2407      -Wdiscard-qual
2408      -Wdistributed-object-modifiers
2409      -Wdivision-by-zero
2410      -Wdollar-in-identifier-extension
2411      -Wdouble-promotion
2412      -Wduplicate-decl-specifier
2413      -Wduplicate-enum
2414      -Wduplicate-method-arg
2415      -Wduplicate-method-match
2416      -Wduplicated-cond
2417      -Wdynamic-class-memaccess
2418      -Wembedded-directive
2419      -Wempty-translation-unit
2420      -Wenum-conversion
2421      -Wexit-time-destructors
2422      -Wexplicit-ownership-type
2423      -Wextern-initializer
2424      -Wextra
2425      -Wextra-semi
2426      -Wextra-tokens
2427      -Wflexible-array-extensions
2428      -Wfloat-conversion
2429      -Wformat-non-iso
2430      -Wfour-char-constants
2431      -Wgcc-compat
2432      -Wglobal-constructors
2433      -Wgnu-array-member-paren-init
2434      -Wgnu-designator
2435      -Wgnu-static-float-init
2436      -Wheader-guard
2437      -Wheader-hygiene
2438      -Widiomatic-parentheses
2439      -Wignored-attributes
2440      -Wimplicit-atomic-properties
2441      -Wimplicit-conversion-floating-point-to-bool
2442      -Wimplicit-exception-spec-mismatch
2443      -Wimplicit-fallthrough
2444      -Wimplicit-fallthrough-per-function
2445      -Wimplicit-retain-self
2446      -Wimport-preprocessor-directive-pedantic
2447      -Wincompatible-library-redeclaration
2448      -Wincompatible-pointer-types-discards-qualifiers
2449      -Wincomplete-implementation
2450      -Wincomplete-module
2451      -Wincomplete-umbrella
2452      -Winit-self
2453      -Wint-conversions
2454      -Wint-to-void-pointer-cast
2455      -Winteger-overflow
2456      -Winvalid-constexpr
2457      -Winvalid-iboutlet
2458      -Winvalid-noreturn
2459      -Winvalid-pp-token
2460      -Winvalid-source-encoding
2461      -Winvalid-token-paste
2462      -Wknr-promoted-parameter
2463      -Wlarge-by-value-copy
2464      -Wliteral-conversion
2465      -Wliteral-range
2466      -Wlocal-type-template-args
2467      -Wlogical-op
2468      -Wloop-analysis
2469      -Wmain-return-type
2470      -Wmalformed-warning-check
2471      -Wmethod-signatures
2472      -Wmicrosoft
2473      -Wmicrosoft-exists
2474      -Wmismatched-parameter-types
2475      -Wmismatched-return-types
2476      -Wmissing-field-initializers
2477      -Wmissing-format-attribute
2478      -Wmissing-noreturn
2479      -Wmissing-selector-name
2480      -Wmissing-sysroot
2481      -Wmissing-variable-declarations
2482      -Wmodule-conflict
2483      -Wnested-anon-types
2484      -Wnewline-eof
2485      -Wnon-literal-null-conversion
2486      -Wnon-pod-varargs
2487      -Wnonportable-cfstrings
2488      -Wnormalized=nfkc
2489      -Wnull-arithmetic
2490      -Wnull-character
2491      -Wnull-conversion
2492      -Wnull-dereference
2493      -Wout-of-line-declaration
2494      -Wover-aligned
2495      -Woverlength-strings
2496      -Woverride-init
2497      -Woverriding-method-mismatch
2498      -Wpointer-type-mismatch
2499      -Wpredefined-identifier-outside-function
2500      -Wprotocol-property-synthesis-ambiguity
2501      -Wreadonly-iboutlet-property
2502      -Wreadonly-setter-attrs
2503      -Wreceiver-expr
2504      -Wreceiver-forward-class
2505      -Wreceiver-is-weak
2506      -Wreinterpret-base-class
2507      -Wrequires-super-attribute
2508      -Wreserved-user-defined-literal
2509      -Wreturn-stack-address
2510      -Wsection
2511      -Wselector-type-mismatch
2512      -Wsentinel
2513      -Wserialized-diagnostics
2514      -Wshadow
2515      -Wshift-count-negative
2516      -Wshift-count-overflow
2517      -Wshift-negative-value
2518      -Wshift-overflow=2
2519      -Wshift-sign-overflow
2520      -Wshorten-64-to-32
2521      -Wsizeof-array-argument
2522      -Wsource-uses-openmp
2523      -Wstatic-float-init
2524      -Wstatic-in-inline
2525      -Wstatic-local-in-inline
2526      -Wstrict-overflow=1
2527      -Wstring-compare
2528      -Wstring-conversion
2529      -Wstrlcpy-strlcat-size
2530      -Wstrncat-size
2531      -Wsuggest-attribute=format
2532      -Wsuggest-attribute=noreturn
2533      -Wsuper-class-method-mismatch
2534      -Wswitch-bool
2535      -Wsync-nand
2536      -Wtautological-constant-out-of-range-compare
2537      -Wtentative-definition-incomplete-type
2538      -Wtrampolines
2539      -Wtype-safety
2540      -Wtypedef-redefinition
2541      -Wtypename-missing
2542      -Wundefined-inline
2543      -Wundefined-internal
2544      -Wundefined-reinterpret-cast
2545      -Wunicode
2546      -Wunicode-whitespace
2547      -Wunknown-warning-option
2548      -Wunnamed-type-template-args
2549      -Wunneeded-member-function
2550      -Wunsequenced
2551      -Wunsupported-visibility
2552      -Wunused-but-set-parameter
2553      -Wunused-but-set-variable
2554      -Wunused-command-line-argument
2555      -Wunused-const-variable=2
2556      -Wunused-exception-parameter
2557      -Wunused-local-typedefs
2558      -Wunused-member-function
2559      -Wunused-sanitize-argument
2560      -Wunused-volatile-lvalue
2561      -Wuser-defined-literals
2562      -Wvariadic-macros
2563      -Wvector-conversion
2564      -Wvector-conversions
2565      -Wvexing-parse
2566      -Wvisibility
2567      -Wvla-extension
2568      -Wzero-length-array
2569   ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2570               [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2571      ])
2573 dnl    We should re-enable this in some later version.  Clang doesn't
2574 dnl    mind, but it causes trouble with GCC.
2575 dnl     -Wstrict-overflow=2
2577 dnl    These seem to require annotations that we don't currently use,
2578 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2579 dnl     -Wthread-safety
2580 dnl     -Wthread-safety-analysis
2581 dnl     -Wthread-safety-attributes
2582 dnl     -Wthread-safety-beta
2583 dnl     -Wthread-safety-precise
2585   W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2586   W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2587   W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2588   W_FLAGS="$W_FLAGS -Wwrite-strings"
2589   W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2590   W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2591   W_FLAGS="$W_FLAGS -Wunused-parameter "
2592   # These interfere with building main() { return 0; }, which autoconf
2593   # likes to use as its default program.
2594   W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2596   TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2597   CFLAGS="$CFLAGS $W_FLAGS"
2599   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2600     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2601   fi
2602   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2603     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2604   fi
2605   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2606     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2607   fi
2609   CFLAGS="$CFLAGS_NOWARNINGS"
2611   if test "x$enable_fatal_warnings" = "xyes"; then
2612     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2613     # default autoconf programs are full of errors.
2614     CFLAGS="$CFLAGS -Werror"
2615   fi
2619 AC_SUBST(TOR_WARNING_FLAGS)
2621 echo "$TOR_WARNING_FLAGS">warning_flags
2623 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2624                             CFLAGS="$CFLAGS @warning_flags",
2625                             CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2627 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2628    case "$host_os" in
2629     darwin*)
2630       tor_incr_n_warnings
2631       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.])
2632    esac
2635 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2637 AC_CONFIG_FILES([
2638         Doxyfile
2639         Makefile
2640         config.rust
2641         contrib/operator-tools/tor.logrotate
2642         src/config/torrc.sample
2643         src/config/torrc.minimal
2644         src/rust/.cargo/config
2645         scripts/maint/checkOptionDocs.pl
2646         warning_flags
2649 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2650   regular_mans="doc/man/tor doc/man/tor-gencert doc/man/tor-resolve doc/man/torify"
2651   for file in $regular_mans ; do
2652     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2653       echo "==================================";
2654       echo;
2655       echo "Building Tor has failed since manpages cannot be built.";
2656       echo;
2657       echo "You need asciidoc installed to be able to build the manpages.";
2658       echo "To build without manpages, use the --disable-asciidoc argument";
2659       echo "when calling configure.";
2660       echo;
2661       echo "==================================";
2662       exit 1;
2663     fi
2664   done
2667 if test "$fragile_hardening" = "yes"; then
2668   tor_incr_n_warnings
2669   AC_MSG_WARN([
2671 ============
2672 Warning!  Building Tor with --enable-fragile-hardening (also known as
2673 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2674 other kinds of attacks easier. A Tor instance build with this option will be
2675 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2676 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2677 denial of service attacks. For more information, see
2678 https://gitlab.torproject.org/tpo/core/team/-/wikis/TorFragileHardening
2679 ============
2680   ])
2683 AC_OUTPUT
2685 if test "$openssl_ver_mismatch" = "yes"; then
2686    tor_incr_n_warnings
2687    AC_MSG_WARN([
2688 ============
2689 Warning! The version OpenSSL headers we get from compiling with
2690     "${TOR_CPPFLAGS_OPENSSL:-(no extra options)}"
2691 do not match version of the OpenSSL library we get when linking with
2692     "$TOR_LDFLAGS_OPENSSL $TOR_OPENSSL_LIBS".
2693 This might cause compilation to fail. Try using --with-openssl-dir to specify
2694 the exact OpenSSL path you want.
2695 ============
2700 # Mini-report on what will be built.
2703 PPRINT_INIT
2704 PPRINT_SET_INDENT(1)
2705 PPRINT_SET_TS(65)
2707 AS_ECHO
2708 AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
2709 AS_ECHO
2711 PPRINT_SUBTITLE([Build Features])
2713 PPRINT_PROP_STRING([Compiler], [$CC])
2714 PPRINT_PROP_STRING([Host OS], [$host_os])
2715 AS_ECHO
2717 test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
2718 PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
2720 test "x$enable_rust" = "xyes" && value=1 || value=0
2721 PPRINT_PROP_BOOL([Rust support (--enable-rust)], $value)
2723 test "x$enable_cargo_online_mode" = "xyes" && value=1 || value=0
2724 PPRINT_PROP_BOOL([Cargo Online Fetch (--enable-cargo-online-mode)], $value)
2726 test "x$enable_android" = "xyes" && value=1 || value=0
2727 PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
2729 AS_ECHO
2730 PPRINT_SUBTITLE([Static Build])
2732 test "x$enable_static_tor" = "xyes" && value=1 || value=0
2733 PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
2735 if test "x$enable_static_libevent" = "xyes"; then
2736   PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
2737 else
2738   PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
2741 if test "x$enable_static_openssl" = "xyes"; then
2742   PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
2743 else
2744   PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
2747 if test "x$enable_static_zlib" = "xyes"; then
2748   PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
2749 else
2750   PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
2753 AS_ECHO
2754 PPRINT_SUBTITLE([Optional Libraries])
2756 test "x$enable_nss" = "xyes" && value=1 || value=0
2757 PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
2759 test "x$enable_seccomp" != "xno" && value=1 || value=0
2760 PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
2762 test "x$enable_libscrypt" != "xno" && value=1 || value=0
2763 PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
2765 test "x$enable_systemd" = "xyes" && value=1 || value=0
2766 PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
2768 test "x$enable_lzma" = "xyes" && value=1 || value=0
2769 PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
2771 test "x$enable_zstd" = "xyes" && value=1 || value=0
2772 PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
2774 AS_ECHO
2775 PPRINT_SUBTITLE([Hardening])
2777 test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
2778 PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
2780 test "x$enable_linker_hardening" != "xno" && value=1 || value=0
2781 PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
2783 test "x$fragile_hardening" = "xyes" && value=1 || value=0
2784 PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
2786 AS_ECHO
2787 PPRINT_SUBTITLE([Modules])
2789 m4_foreach_w([mname], MODULES,
2790   [
2791     AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
2792     PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value)
2793   ]
2796 AS_ECHO
2797 PPRINT_SUBTITLE([Documentation])
2799 test "x$enable_asciidoc" != "xno" && value=1 || value=0
2800 PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
2802 test "x$enable_manpage" != "xno" && value=1 || value=0
2803 PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
2805 test "x$enable_html_manual" != "xno" && value=1 || value=0
2806 PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
2808 AS_ECHO
2809 PPRINT_SUBTITLE([Tests])
2811 test "x$enable_unittests" != "xno" && value=1 || value=0
2812 PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
2814 test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
2815 PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
2817 test "x$enable_coverage" = "xyes" && value=1 || value=0
2818 PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
2820 test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
2821 PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
2823 test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
2824 PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
2826 AS_ECHO
2827 PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
2829 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
2830 PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
2832 test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
2833 PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
2835 test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
2836 PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
2838 AS_ECHO
2839 PPRINT_SUBTITLE([Install Directories])
2841 report_mandir="`eval eval echo $mandir`"
2842 PPRINT_PROP_STRING([Binaries], [$BINDIR])
2843 PPRINT_PROP_STRING([Configuration], [$CONFDIR])
2844 PPRINT_PROP_STRING([Man Pages], [$report_mandir])
2846 AS_ECHO
2847 AS_ECHO(["Configure Line: ./configure $configure_flags"])
2849 if test "$tor_ac_n_warnings" != "0"; then
2850   AS_ECHO
2851   PPRINT_WARN([
2852 Encountered $tor_ac_n_warnings warning(s). See messages above for more info.
2853   ])