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