When RunAsDaemon is set, crypto_postfork() as needed
[tor.git] / configure.ac
blobaa9b2ba6bdb96df8b8c135fb5112fc9006be69b7
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2018, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_PREREQ([2.63])
7 AC_INIT([tor],[0.3.5.0-alpha-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
11 # "foreign" means we don't follow GNU package layout standards
12 # "1.11" means we require automake version 1.11 or newer
13 # "subdir-objects" means put .o files in the same directory as the .c files
14 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
16 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
17 AC_CONFIG_HEADERS([orconfig.h])
19 AC_USE_SYSTEM_EXTENSIONS
20 AC_CANONICAL_HOST
22 PKG_PROG_PKG_CONFIG
24 AC_ARG_ENABLE(openbsd-malloc,
25    AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD.  Linux only]))
26 AC_ARG_ENABLE(static-openssl,
27    AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
28 AC_ARG_ENABLE(static-libevent,
29    AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
30 AC_ARG_ENABLE(static-zlib,
31    AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
32 AC_ARG_ENABLE(static-tor,
33    AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
34 AC_ARG_ENABLE(unittests,
35    AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
36 AC_ARG_ENABLE(coverage,
37    AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
38 AC_ARG_ENABLE(asserts-in-tests,
39    AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
40 AC_ARG_ENABLE(system-torrc,
41    AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
42 AC_ARG_ENABLE(libfuzzer,
43    AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
44 AC_ARG_ENABLE(oss-fuzz,
45    AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
46 AC_ARG_ENABLE(memory-sentinels,
47    AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
48 AC_ARG_ENABLE(rust,
49    AS_HELP_STRING(--enable-rust, [enable rust integration]))
50 AC_ARG_ENABLE(cargo-online-mode,
51    AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
52 AC_ARG_ENABLE(restart-debugging,
53    AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
54 AC_ARG_ENABLE(zstd-advanced-apis,
55    AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
56 AC_ARG_ENABLE(nss,
57    AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
59 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
60     AC_MSG_ERROR([Can't disable assertions outside of coverage build])
63 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
64 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
65 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
66 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
67 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
68 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
69 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
70 AM_CONDITIONAL(USE_OPENSSL, true)
72 if test "x$enable_nss" = "xyes"; then
73   AC_DEFINE(ENABLE_NSS, 1,
74             [Defined if we're building with NSS in addition to OpenSSL.])
76 AC_DEFINE(ENABLE_OPENSSL, 1,
77           [Defined if we're building with OpenSSL or LibreSSL])
79 if test "$enable_static_tor" = "yes"; then
80   enable_static_libevent="yes";
81   enable_static_openssl="yes";
82   enable_static_zlib="yes";
83   CFLAGS="$CFLAGS -static"
86 if test "$enable_system_torrc" = "no"; then
87   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
88             [Defined if we're not going to look for a torrc in SYSCONF])
91 if test "$enable_memory_sentinels" = "no"; then
92   AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
93            [Defined if we're turning off memory safety code to look for bugs])
96 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
98 AC_ARG_ENABLE(asciidoc,
99      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
100      [case "${enableval}" in
101         "yes") asciidoc=true ;;
102         "no")  asciidoc=false ;;
103         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
104       esac], [asciidoc=true])
106 # systemd notify support
107 AC_ARG_ENABLE(systemd,
108       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
109       [case "${enableval}" in
110         "yes") systemd=true ;;
111         "no")  systemd=false ;;
112         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
113       esac], [systemd=auto])
115 if test "$enable_restart_debugging" = "yes"; then
116   AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
117             [Defined if we're building with support for in-process restart debugging.])
120 if test "$enable_zstd_advanced_apis" != "no"; then
121    AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
122              [Defined if we're going to try to use zstd's "static-only" APIs.])
125 # systemd support
126 if test "x$enable_systemd" = "xno"; then
127     have_systemd=no;
128 else
129     PKG_CHECK_MODULES(SYSTEMD,
130         [libsystemd-daemon],
131         have_systemd=yes,
132         have_systemd=no)
133     if test "x$have_systemd" = "xno"; then
134         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
135         PKG_CHECK_MODULES(SYSTEMD,
136             [libsystemd],
137             have_systemd=yes,
138             have_systemd=no)
139     fi
142 if test "x$have_systemd" = "xyes"; then
143     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
144     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
145     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
146     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
147          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
149 AC_SUBST(TOR_SYSTEMD_CFLAGS)
150 AC_SUBST(TOR_SYSTEMD_LIBS)
152 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
153     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
156 case "$host" in
157    *-*-solaris* )
158      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
159      ;;
160 esac
162 AC_ARG_ENABLE(gcc-warnings,
163      AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
164 AC_ARG_ENABLE(fatal-warnings,
165      AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
166 AC_ARG_ENABLE(gcc-warnings-advisory,
167      AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
169 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
170 AC_ARG_ENABLE(gcc-hardening,
171     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
173 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
174 AC_ARG_ENABLE(expensive-hardening,
175     AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
176 AC_ARG_ENABLE(fragile-hardening,
177     AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
178 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
179   fragile_hardening="yes"
180   AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
183 dnl Linker hardening options
184 dnl Currently these options are ELF specific - you can't use this with MacOSX
185 AC_ARG_ENABLE(linker-hardening,
186     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
188 AC_ARG_ENABLE(local-appdata,
189    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
190 if test "$enable_local_appdata" = "yes"; then
191   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
192             [Defined if we default to host local appdata paths on Windows])
195 # Tor2web mode flag
196 AC_ARG_ENABLE(tor2web-mode,
197      AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
198 [if test "x$enableval" = "xyes"; then
199     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
200 fi])
202 AC_ARG_ENABLE(tool-name-check,
203      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
205 AC_ARG_ENABLE(seccomp,
206      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
208 AC_ARG_ENABLE(libscrypt,
209      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
211 dnl Enable event tracing which are transformed to debug log statement.
212 AC_ARG_ENABLE(event-tracing-debug,
213      AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
214 AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
216 if test x$enable_event_tracing_debug = xyes; then
217   AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
218   AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
221 dnl Enable Android only features.
222 AC_ARG_ENABLE(android,
223      AS_HELP_STRING(--enable-android, [build with Android features enabled]))
224 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
226 if test "x$enable_android" = "xyes"; then
227   AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
229   dnl Check if the Android log library is available.
230   AC_CHECK_HEADERS([android/log.h])
231   AC_SEARCH_LIBS(__android_log_write, [log])
235 dnl ---
236 dnl Tor modules options. These options are namespaced with --disable-module-XXX
237 dnl ---
239 dnl All our modules.
240 m4_define(MODULES, dirauth)
242 dnl Directory Authority module.
243 AC_ARG_ENABLE([module-dirauth],
244               AS_HELP_STRING([--disable-module-dirauth],
245                              [Do not build tor with the dirauth module]),
246               [], dnl Action if-given
247               AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
248                         [Compile with Directory Authority feature support]))
249 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH, [test "x$enable_module_dirauth" != "xno"])
251 dnl Helper variables.
252 TOR_MODULES_ALL_ENABLED=
253 AC_DEFUN([ADD_MODULE], [
254     MODULE=m4_toupper($1)
255     TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
257 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
258 AC_SUBST(TOR_MODULES_ALL_ENABLED)
260 dnl check for the correct "ar" when cross-compiling.
261 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
262 dnl    so kludge up a replacement for the case where it isn't there yet.)
263 m4_ifdef([AM_PROG_AR],
264          [AM_PROG_AR],
265          [AN_MAKEVAR([AR], [AC_PROG_AR])
266           AN_PROGRAM([ar], [AC_PROG_AR])
267           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
268           AC_PROG_AR])
270 dnl Check whether the above macro has settled for a simply named tool even
271 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
272 dnl because that will find any cc on the system, not only the cross-compiler,
273 dnl and then verify that a binary built with this compiler runs on the
274 dnl build system. It will then come to the false conclusion that we're not
275 dnl cross-compiling.
276 if test "x$enable_tool_name_check" != "xno"; then
277     if test "x$ac_tool_warned" = "xyes"; then
278         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.)])
279         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
280                 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.)])
281         fi
284 AC_PROG_CC
285 AC_PROG_CPP
286 AC_PROG_MAKE_SET
287 AC_PROG_RANLIB
288 AC_PROG_SED
290 AC_ARG_VAR([PERL], [path to Perl binary])
291 AC_CHECK_PROGS([PERL], [perl])
292 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
294 dnl check for asciidoc and a2x
295 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
296 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
298 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
300 AM_PROG_CC_C_O
301 AC_PROG_CC_C99
303 AC_ARG_VAR([PYTHON], [path to Python binary])
304 AC_CHECK_PROGS(PYTHON, [ \
305         python3 \
306         python3.8 python3.7 python3.6 python3.5 python3.4 \
307         python \
308         python2 python2.7])
309 if test "x$PYTHON" = "x"; then
310   AC_MSG_WARN([Python unavailable; some tests will not be run.])
312 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
314 dnl List all external rust crates we depend on here. Include the version
315 rust_crates=" \
316     digest-0.7.2 \
317     libc-0.2.39 \
319 AC_SUBST(rust_crates)
321 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
322 AC_C_FLEXIBLE_ARRAY_MEMBER
323 ], [
324  dnl Maybe we've got an old autoconf...
325  AC_CACHE_CHECK([for flexible array members],
326      tor_cv_c_flexarray,
327      [AC_COMPILE_IFELSE(
328        AC_LANG_PROGRAM([
329  struct abc { int a; char b[]; };
330 ], [
331  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
332  def->b[0] = 33;
334   [tor_cv_c_flexarray=yes],
335   [tor_cv_c_flexarray=no])])
336  if test "$tor_cv_flexarray" = "yes"; then
337    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
338  else
339    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
340  fi
343 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
344       tor_cv_c_c99_decl,
345       [AC_COMPILE_IFELSE(
346          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
347          [tor_cv_c_c99_decl=yes],
348          [tor_cv_c_c99_decl=no] )])
349 if test "$tor_cv_c_c99_decl" != "yes"; then
350   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
353 AC_CACHE_CHECK([for working C99 designated initializers],
354       tor_cv_c_c99_designated_init,
355       [AC_COMPILE_IFELSE(
356          [AC_LANG_PROGRAM([struct s { int a; int b; };],
357                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
358          [tor_cv_c_c99_designated_init=yes],
359          [tor_cv_c_c99_designated_init=no] )])
361 if test "$tor_cv_c_c99_designated_init" != "yes"; then
362   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
365 TORUSER=_tor
366 AC_ARG_WITH(tor-user,
367         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
368         [
369            TORUSER=$withval
370         ]
372 AC_SUBST(TORUSER)
374 TORGROUP=_tor
375 AC_ARG_WITH(tor-group,
376         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
377         [
378            TORGROUP=$withval
379         ]
381 AC_SUBST(TORGROUP)
384 dnl If _WIN32 is defined and non-zero, we are building for win32
385 AC_MSG_CHECKING([for win32])
386 AC_RUN_IFELSE([AC_LANG_SOURCE([
387 int main(int c, char **v) {
388 #ifdef _WIN32
389 #if _WIN32
390   return 0;
391 #else
392   return 1;
393 #endif
394 #else
395   return 2;
396 #endif
397 }])],
398 bwin32=true; AC_MSG_RESULT([yes]),
399 bwin32=false; AC_MSG_RESULT([no]),
400 bwin32=cross; AC_MSG_RESULT([cross])
403 if test "$bwin32" = "cross"; then
404 AC_MSG_CHECKING([for win32 (cross)])
405 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
406 #ifdef _WIN32
407 int main(int c, char **v) {return 0;}
408 #else
409 #error
410 int main(int c, char **v) {return x(y);}
411 #endif
412 ])],
413 bwin32=true; AC_MSG_RESULT([yes]),
414 bwin32=false; AC_MSG_RESULT([no]))
417 AH_BOTTOM([
418 #ifdef _WIN32
419 /* Defined to access windows functions and definitions for >=WinXP */
420 # ifndef WINVER
421 #  define WINVER 0x0501
422 # endif
424 /* Defined to access _other_ windows functions and definitions for >=WinXP */
425 # ifndef _WIN32_WINNT
426 #  define _WIN32_WINNT 0x0501
427 # endif
429 /* Defined to avoid including some windows headers as part of Windows.h */
430 # ifndef WIN32_LEAN_AND_MEAN
431 #  define WIN32_LEAN_AND_MEAN 1
432 # endif
433 #endif
436 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
437 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
438 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
440 dnl Enable C99 when compiling with MIPSpro
441 AC_MSG_CHECKING([for MIPSpro compiler])
442 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
443 #if (defined(__sgi) && defined(_COMPILER_VERSION))
444 #error
445   return x(y);
446 #endif
447 ])],
448 bmipspro=false; AC_MSG_RESULT(no),
449 bmipspro=true; AC_MSG_RESULT(yes))
451 if test "$bmipspro" = "true"; then
452   CFLAGS="$CFLAGS -c99"
455 AC_C_BIGENDIAN
457 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
459 if test "x$enable_rust" = "xyes"; then
460   AC_ARG_VAR([RUSTC], [path to the rustc binary])
461   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
462   if test "x$RUSTC" = "xno"; then
463     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
464   fi
466   AC_ARG_VAR([CARGO], [path to the cargo binary])
467   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
468   if test "x$CARGO" = "xno"; then
469     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
470   fi
472   AC_DEFINE([HAVE_RUST], 1, [have Rust])
473   if test "x$enable_fatal_warnings" = "xyes"; then
474     RUST_WARN=
475   else
476     RUST_WARN=#
477   fi
478   if test "x$enable_cargo_online_mode" = "xyes"; then
479     CARGO_ONLINE=
480     RUST_DL=#
481   else
482     CARGO_ONLINE=--frozen
483     RUST_DL=
485     dnl When we're not allowed to touch the network, we need crate dependencies
486     dnl locally available.
487     AC_MSG_CHECKING([rust crate dependencies])
488     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
489     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
490       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
491     fi
492     dnl Check whether the path exists before we try to cd into it.
493     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
494       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.])
495       ERRORED=1
496     fi
497     dnl Make the path absolute, since we'll be using it from within a
498     dnl subdirectory.
499     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
501     for dep in $rust_crates; do
502       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
503         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.])
504         ERRORED=1
505       fi
506     done
507     if test "x$ERRORED" = "x"; then
508       AC_MSG_RESULT([yes])
509     fi
510   fi
512   dnl This is a workaround for #46797
513   dnl (a.k.a https://github.com/rust-lang/rust/issues/46797 ).  Once the
514   dnl upstream bug is fixed, we can remove this workaround.
515   case "$host_os" in
516       darwin*)
517         TOR_RUST_EXTRA_LIBS="-lresolv"
518         ;;
519   esac
521   dnl For now both MSVC and MinGW rust libraries will output static libs with
522   dnl the MSVC naming convention.
523   if test "$bwin32" = "true"; then
524     tor_rust_static_name=tor_rust.lib
525   else
526     tor_rust_static_name=libtor_rust.a
527   fi
529   AC_CANONICAL_BUILD
531   if test -n "$TOR_RUST_TARGET"; then
532     if test "$host" = "$build"; then
533       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
534     fi
535     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
536     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
537   else
538     if test "$host" != "$build"; then
539       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
540     fi
541     RUST_TARGET_PROP=
542     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
543   fi
545   AC_SUBST(RUST_TARGET_PROP)
546   AC_SUBST(TOR_RUST_LIB_PATH)
547   AC_SUBST(CARGO_ONLINE)
548   AC_SUBST(RUST_WARN)
549   AC_SUBST(RUST_DL)
551   dnl Let's check the rustc version, too
552   AC_MSG_CHECKING([rust version])
553   RUSTC_VERSION=`$RUSTC --version`
554   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
555   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
556   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
557     AC_MSG_ERROR([rustc version couldn't be identified])
558   fi
559   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
560     AC_MSG_ERROR([rustc must be at least version 1.14])
561   fi
562   AC_MSG_RESULT([$RUSTC_VERSION])
565 AC_SUBST(TOR_RUST_EXTRA_LIBS)
567 AC_SEARCH_LIBS(socket, [socket network])
568 AC_SEARCH_LIBS(gethostbyname, [nsl])
569 AC_SEARCH_LIBS(dlopen, [dl])
570 AC_SEARCH_LIBS(inet_aton, [resolv])
571 AC_SEARCH_LIBS(backtrace, [execinfo])
572 saved_LIBS="$LIBS"
573 AC_SEARCH_LIBS([clock_gettime], [rt])
574 if test "$LIBS" != "$saved_LIBS"; then
575    # Looks like we need -lrt for clock_gettime().
576    have_rt=yes
579 AC_SEARCH_LIBS(pthread_create, [pthread])
580 AC_SEARCH_LIBS(pthread_detach, [pthread])
582 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
583 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
585 AC_CHECK_FUNCS(
586         _NSGetEnviron \
587         RtlSecureZeroMemory \
588         SecureZeroMemory \
589         accept4 \
590         backtrace \
591         backtrace_symbols_fd \
592         eventfd \
593         explicit_bzero \
594         timingsafe_memcmp \
595         flock \
596         ftime \
597         get_current_dir_name \
598         getaddrinfo \
599         getdelim \
600         getifaddrs \
601         getline \
602         getpass \
603         getrlimit \
604         gettimeofday \
605         gmtime_r \
606         gnu_get_libc_version \
607         htonll \
608         inet_aton \
609         ioctl \
610         issetugid \
611         llround \
612         localtime_r \
613         lround \
614         memmem \
615         memset_s \
616         mmap \
617         pipe \
618         pipe2 \
619         prctl \
620         readpassphrase \
621         rint \
622         sigaction \
623         socketpair \
624         statvfs \
625         strncasecmp \
626         strcasecmp \
627         strlcat \
628         strlcpy \
629         strnlen \
630         strptime \
631         strtok_r \
632         strtoull \
633         sysconf \
634         sysctl \
635         truncate \
636         uname \
637         usleep \
638         vasprintf \
639         _vscprintf
642 # Apple messed up when they added some functions: they
643 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
644 # checks.
646 # We should only probe for these functions if we are sure that we
647 # are not targeting OS X 10.9 or earlier.
648 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
649 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
650 #ifdef __APPLE__
651 #  include <AvailabilityMacros.h>
652 #  ifndef MAC_OS_X_VERSION_10_10
653 #    define MAC_OS_X_VERSION_10_10 101000
654 #  endif
655 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
656 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
657 #      error "Running on Mac OS X 10.9 or earlier"
658 #    endif
659 #  endif
660 #endif
661 ]], [[]])],
662    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
663    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
665 if test "$on_macos_pre_10_10" = "no"; then
666   AC_CHECK_FUNCS(
667         mach_approximate_time \
668   )
671 # We should only probe for these functions if we are sure that we
672 # are not targeting OSX 10.11 or earlier.
673 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
674 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
675 #ifdef __APPLE__
676 #  include <AvailabilityMacros.h>
677 #  ifndef MAC_OS_X_VERSION_10_12
678 #    define MAC_OS_X_VERSION_10_12 101200
679 #  endif
680 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
681 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
682 #      error "Running on Mac OSX 10.11 or earlier"
683 #    endif
684 #  endif
685 #endif
686 ]], [[]])],
687    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
688    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
690 if test "$on_macos_pre_10_12" = "no"; then
691   AC_CHECK_FUNCS(
692         clock_gettime \
693         getentropy \
694   )
697 if test "$bwin32" != "true"; then
698   AC_CHECK_HEADERS(pthread.h)
699   AC_CHECK_FUNCS(pthread_create)
700   AC_CHECK_FUNCS(pthread_condattr_setclock)
703 if test "$bwin32" = "true"; then
704   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
705 #include <windows.h>
706 #include <conio.h>
707 #include <wchar.h>
708                  ])
711 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
712   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
714 AC_MSG_CHECKING([whether free(NULL) works])
715 AC_RUN_IFELSE([AC_LANG_PROGRAM([
716   #include <stdlib.h>
717 ], [
718 char *p = NULL;
719 free(p);
720 ])],
721 [free_null_ok=true; AC_MSG_RESULT(yes)],
722 [free_null_ok=false; AC_MSG_RESULT(no)],
723 [free_null_ok=cross; AC_MSG_RESULT(cross)])
725 if test "$free_null_ok" = "false"; then
726    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
729 dnl ------------------------------------------------------
730 dnl Where do you live, libevent?  And how do we call you?
732 if test "$bwin32" = "true"; then
733   TOR_LIB_WS32=-lws2_32
734   TOR_LIB_IPHLPAPI=-liphlpapi
735   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
736   # think it's actually necessary.
737   TOR_LIB_GDI=-lgdi32
738   TOR_LIB_USERENV=-luserenv
739 else
740   TOR_LIB_WS32=
741   TOR_LIB_GDI=
742   TOR_LIB_USERENV=
744 AC_SUBST(TOR_LIB_WS32)
745 AC_SUBST(TOR_LIB_GDI)
746 AC_SUBST(TOR_LIB_IPHLPAPI)
747 AC_SUBST(TOR_LIB_USERENV)
749 tor_libevent_pkg_redhat="libevent"
750 tor_libevent_pkg_debian="libevent-dev"
751 tor_libevent_devpkg_redhat="libevent-devel"
752 tor_libevent_devpkg_debian="libevent-dev"
754 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
755 dnl linking for static builds.
756 STATIC_LIBEVENT_FLAGS=""
757 if test "$enable_static_libevent" = "yes"; then
758     if test "$have_rt" = "yes"; then
759       STATIC_LIBEVENT_FLAGS=" -lrt "
760     fi
763 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
764 #ifdef _WIN32
765 #include <winsock2.h>
766 #endif
767 #include <sys/time.h>
768 #include <sys/types.h>
769 #include <event2/event.h>], [
770 #ifdef _WIN32
771 #include <winsock2.h>
772 #endif
773 struct event_base;
774 struct event_base *event_base_new(void);
775 void event_base_free(struct event_base *);],
776     [
777 #ifdef _WIN32
778 {WSADATA d; WSAStartup(0x101,&d); }
779 #endif
780 event_base_free(event_base_new());
781 ], [--with-libevent-dir], [/opt/libevent])
783 dnl Determine the incantation needed to link libevent.
784 save_LIBS="$LIBS"
785 save_LDFLAGS="$LDFLAGS"
786 save_CPPFLAGS="$CPPFLAGS"
788 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
789 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
790 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
792 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
794 if test "$enable_static_libevent" = "yes"; then
795    if test "$tor_cv_library_libevent_dir" = "(system)"; then
796      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
797    else
798      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
799    fi
800 else
801      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
802        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
803        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"))
805        if test "$ac_cv_search_event_new" != "none required"; then
806          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
807        fi
808        if test "$ac_cv_search_evdns_base_new" != "none required"; then
809          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
810        fi
811      else
812        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
813      fi
816 dnl Now check for particular libevent functions.
817 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
818                 evutil_secure_rng_add_bytes \
821 LIBS="$save_LIBS"
822 LDFLAGS="$save_LDFLAGS"
823 CPPFLAGS="$save_CPPFLAGS"
825 dnl Check that libevent is at least at version 2.0.10, the first stable
826 dnl release of its series
827 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
828 AC_MSG_CHECKING([whether Libevent is new enough])
829 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
830 #include <event2/event.h>
831 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
832 #error
833 int x = y(zz);
834 #else
835 int x = 1;
836 #endif
837 ])], [ AC_MSG_RESULT([yes]) ],
838    [ AC_MSG_RESULT([no])
839      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
841 LIBS="$save_LIBS"
842 LDFLAGS="$save_LDFLAGS"
843 CPPFLAGS="$save_CPPFLAGS"
845 AC_SUBST(TOR_LIBEVENT_LIBS)
847 dnl ------------------------------------------------------
848 dnl Where do you live, libm?
850 dnl On some platforms (Haiku/BeOS) the math library is
851 dnl part of libroot. In which case don't link against lm
852 TOR_LIB_MATH=""
853 save_LIBS="$LIBS"
854 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
855 if test "$ac_cv_search_pow" != "none required"; then
856     TOR_LIB_MATH="$ac_cv_search_pow"
858 LIBS="$save_LIBS"
859 AC_SUBST(TOR_LIB_MATH)
861 dnl ------------------------------------------------------
862 dnl Hello, NSS.  You're new around here.
863 if test "x$enable_nss" = "xyes"; then
864   PKG_CHECK_MODULES(NSS,
865      [nss],
866      [have_nss=yes],
867      [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it.])])
868   AC_SUBST(NSS_CFLAGS)
869   AC_SUBST(NSS_LIBS)
872 dnl ------------------------------------------------------
873 dnl Where do you live, openssl?  And how do we call you?
875 tor_openssl_pkg_redhat="openssl"
876 tor_openssl_pkg_debian="libssl-dev"
877 tor_openssl_devpkg_redhat="openssl-devel"
878 tor_openssl_devpkg_debian="libssl-dev"
880 ALT_openssl_WITHVAL=""
881 AC_ARG_WITH(ssl-dir,
882   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
883   [
884       if test "x$withval" != "xno" && test "x$withval" != "x"; then
885          ALT_openssl_WITHVAL="$withval"
886       fi
887   ])
889 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
890 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
891     [#include <openssl/ssl.h>
892      char *getenv(const char *);],
893     [struct ssl_cipher_st;
894      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
895      char *getenv(const char *);],
896     dnl This funny-looking test program calls getenv, so that the compiler
897     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
898     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
899     dnl We look for SSL_cipher_get_id() because it is present in
900     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
901     dnl depends on it.
902     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
903     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
905 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
907 if test "$enable_static_openssl" = "yes"; then
908    if test "$tor_cv_library_openssl_dir" = "(system)"; then
909      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
910    else
911      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
912    fi
913 else
914      TOR_OPENSSL_LIBS="-lssl -lcrypto"
916 AC_SUBST(TOR_OPENSSL_LIBS)
918 dnl Now check for particular openssl functions.
919 save_LIBS="$LIBS"
920 save_LDFLAGS="$LDFLAGS"
921 save_CPPFLAGS="$CPPFLAGS"
922 LIBS="$TOR_OPENSSL_LIBS $LIBS"
923 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
924 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
926 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
927 #include <openssl/opensslv.h>
928 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
929 #error "too old"
930 #endif
931    ]], [[]])],
932    [ : ],
933    [ 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.]) ])
935 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
936 #include <openssl/opensslv.h>
937 #include <openssl/evp.h>
938 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
939 #error "no ECC"
940 #endif
941 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
942 #error "curves unavailable"
943 #endif
944    ]], [[]])],
945    [ : ],
946    [ 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.]) ])
948 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
949 [#include <openssl/ssl.h>
952 AC_CHECK_FUNCS([ \
953                 ERR_load_KDF_strings \
954                 SSL_SESSION_get_master_key \
955                 SSL_get_server_random \
956                 SSL_get_client_ciphers \
957                 SSL_get_client_random \
958                 SSL_CIPHER_find \
959                 TLS_method
960                ])
962 dnl Check if OpenSSL has scrypt implementation.
963 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
965 dnl Check if OpenSSL structures are opaque
966 AC_CHECK_MEMBERS([SSL.state], , ,
967 [#include <openssl/ssl.h>
970 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
971 #include <openssl/sha.h>
974 dnl Define the set of checks for KIST scheduler support.
975 AC_DEFUN([CHECK_KIST_SUPPORT],[
976   dnl KIST needs struct tcp_info and for certain members to exist.
977   AC_CHECK_MEMBERS(
978     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
979     , ,[[#include <netinet/tcp.h>]])
980   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
981   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
982                      #include <linux/sockios.h>
983                      #ifndef SIOCOUTQNSD
984                      #error
985                      #endif
986                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
987   if test "x$have_siocoutqnsd" = "xyes"; then
988     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
989       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
990         have_kist_support=yes
991       fi
992     fi
993   fi
995 dnl Now, trigger the check.
996 CHECK_KIST_SUPPORT
997 AS_IF([test "x$have_kist_support" = "xyes"],
998       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
999                                         on this system])],
1000       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1002 LIBS="$save_LIBS"
1003 LDFLAGS="$save_LDFLAGS"
1004 CPPFLAGS="$save_CPPFLAGS"
1006 dnl ------------------------------------------------------
1007 dnl Where do you live, zlib?  And how do we call you?
1009 tor_zlib_pkg_redhat="zlib"
1010 tor_zlib_pkg_debian="zlib1g"
1011 tor_zlib_devpkg_redhat="zlib-devel"
1012 tor_zlib_devpkg_debian="zlib1g-dev"
1014 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1015     [#include <zlib.h>],
1016     [const char * zlibVersion(void);],
1017     [zlibVersion();], [--with-zlib-dir],
1018     [/opt/zlib])
1020 if test "$enable_static_zlib" = "yes"; then
1021    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1022      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1023  using --enable-static-zlib")
1024    else
1025      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1026    fi
1027 else
1028      TOR_ZLIB_LIBS="-lz"
1030 AC_SUBST(TOR_ZLIB_LIBS)
1032 dnl ------------------------------------------------------
1033 dnl Where we do we find lzma?
1035 AC_ARG_ENABLE(lzma,
1036       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1037       [case "${enableval}" in
1038         "yes") lzma=true ;;
1039         "no")  lzma=false ;;
1040         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1041       esac], [lzma=auto])
1043 if test "x$enable_lzma" = "xno"; then
1044     have_lzma=no;
1045 else
1046     PKG_CHECK_MODULES([LZMA],
1047                       [liblzma],
1048                       have_lzma=yes,
1049                       have_lzma=no)
1051     if test "x$have_lzma" = "xno" ; then
1052         AC_MSG_WARN([Unable to find liblzma.])
1053     fi
1056 if test "x$have_lzma" = "xyes"; then
1057     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1058     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1059     TOR_LZMA_LIBS="${LZMA_LIBS}"
1061 AC_SUBST(TOR_LZMA_CFLAGS)
1062 AC_SUBST(TOR_LZMA_LIBS)
1064 dnl ------------------------------------------------------
1065 dnl Where we do we find zstd?
1067 AC_ARG_ENABLE(zstd,
1068       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1069       [case "${enableval}" in
1070         "yes") zstd=true ;;
1071         "no")  zstd=false ;;
1072         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1073       esac], [zstd=auto])
1075 if test "x$enable_zstd" = "xno"; then
1076     have_zstd=no;
1077 else
1078     PKG_CHECK_MODULES([ZSTD],
1079                       [libzstd >= 1.1],
1080                       have_zstd=yes,
1081                       have_zstd=no)
1083     if test "x$have_zstd" = "xno" ; then
1084         AC_MSG_WARN([Unable to find libzstd.])
1085     fi
1088 if test "x$have_zstd" = "xyes"; then
1089     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1090     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1091     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1093     dnl now check for zstd functions
1094     save_LIBS="$LIBS"
1095     save_CFLAGS="$CFLAGS"
1096     LIBS="$LIBS $ZSTD_LIBS"
1097     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1098     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1099                    ZSTD_estimateDCtxSize)
1100     LIBS="$save_LIBS"
1101     CFLAGS="$save_CFLAGS"
1103 AC_SUBST(TOR_ZSTD_CFLAGS)
1104 AC_SUBST(TOR_ZSTD_LIBS)
1106 dnl ----------------------------------------------------------------------
1107 dnl Check if libcap is available for capabilities.
1109 tor_cap_pkg_debian="libcap2"
1110 tor_cap_pkg_redhat="libcap"
1111 tor_cap_devpkg_debian="libcap-dev"
1112 tor_cap_devpkg_redhat="libcap-devel"
1114 AC_CHECK_LIB([cap], [cap_init], [],
1115   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1117 AC_CHECK_FUNCS(cap_set_proc)
1119 dnl ---------------------------------------------------------------------
1120 dnl Now that we know about our major libraries, we can check for compiler
1121 dnl and linker hardening options.  We need to do this with the libraries known,
1122 dnl since sometimes the linker will like an option but not be willing to
1123 dnl use it with a build of a library.
1125 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1126 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"
1128 CFLAGS_FTRAPV=
1129 CFLAGS_FWRAPV=
1130 CFLAGS_ASAN=
1131 CFLAGS_UBSAN=
1134 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1135 #if !defined(__clang__)
1136 #error
1137 #endif])], have_clang=yes, have_clang=no)
1139 if test "x$enable_gcc_hardening" != "xno"; then
1140     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1141     if test "x$have_clang" = "xyes"; then
1142         TOR_CHECK_CFLAGS(-Qunused-arguments)
1143     fi
1144     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1145     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1146     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1147 m4_ifdef([AS_VAR_IF],[
1148     AS_VAR_IF(can_compile, [yes],
1149         AS_VAR_IF(can_link, [yes],
1150                   [],
1151                   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.)]))
1152         )])
1153     AS_VAR_POPDEF([can_link])
1154     AS_VAR_POPDEF([can_compile])
1155     TOR_CHECK_CFLAGS(-Wstack-protector)
1156     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1157     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1158        TOR_CHECK_CFLAGS(-fPIE)
1159        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1160     fi
1161     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1164 if test "$fragile_hardening" = "yes"; then
1165     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1166    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1167       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.])
1168    fi
1170    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1171      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1172    fi
1174    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1175     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1176       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*])
1177     fi
1179    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1180     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1181       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*])
1182     fi
1184 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1187 dnl Find the correct libraries to add in order to use the sanitizers.
1189 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1190 dnl option, which will prevent the compiler from linking the sanitizer
1191 dnl libraries it needs.  We need to specify them manually.
1193 dnl What's more, we need to specify them in a linker script rather than
1194 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1195 dnl variable.
1196 RUST_LINKER_OPTIONS=""
1197 if test "x$have_clang" = "xyes"; then
1198         if test "x$CFLAGS_ASAN" != "x"; then
1199                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_ASAN"
1200         fi
1201         if test "x$CFLAGS_UBSAN" != "x"; then
1202                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_UBSAN"
1203         fi
1204 else
1205         if test "x$CFLAGS_ASAN" != "x"; then
1206                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lasan"
1207         fi
1208         if test "x$CFLAGS_UBSAN" != "x"; then
1209                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lubsan"
1210         fi
1212 AC_SUBST(RUST_LINKER_OPTIONS)
1214 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1215 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1217 mulodi_fixes_ftrapv=no
1218 if test "$have_clang" = "yes"; then
1219   saved_CFLAGS="$CFLAGS"
1220   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1221   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1222   AC_LINK_IFELSE([
1223       AC_LANG_SOURCE([[
1224           #include <stdint.h>
1225           #include <stdlib.h>
1226           int main(int argc, char **argv)
1227           {
1228             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1229                         * (int64_t)atoi(argv[3]);
1230             return x == 9;
1231           } ]])],
1232           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1233           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1234   if test "$ftrapv_can_link" = "no"; then
1235     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1236     AC_LINK_IFELSE([
1237       AC_LANG_SOURCE([[
1238           #include <stdint.h>
1239           #include <stdlib.h>
1240           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1241              *overflow=0;
1242              return a;
1243           }
1244           int main(int argc, char **argv)
1245           {
1246             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1247                         * (int64_t)atoi(argv[3]);
1248             return x == 9;
1249           } ]])],
1250           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1251           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1252   fi
1253   CFLAGS="$saved_CFLAGS"
1256 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1258 dnl These cflags add bunches of branches, and we haven't been able to
1259 dnl persuade ourselves that they're suitable for code that needs to be
1260 dnl constant time.
1261 AC_SUBST(CFLAGS_BUGTRAP)
1262 dnl These cflags are variant ones sutable for code that needs to be
1263 dnl constant-time.
1264 AC_SUBST(CFLAGS_CONSTTIME)
1266 if test "x$enable_linker_hardening" != "xno"; then
1267     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1270 # For backtrace support
1271 TOR_CHECK_LDFLAGS(-rdynamic)
1273 dnl ------------------------------------------------------
1274 dnl Now see if we have a -fomit-frame-pointer compiler option.
1276 saved_CFLAGS="$CFLAGS"
1277 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1278 F_OMIT_FRAME_POINTER=''
1279 if test "$saved_CFLAGS" != "$CFLAGS"; then
1280   if test "$fragile_hardening" = "yes"; then
1281     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1282   fi
1284 CFLAGS="$saved_CFLAGS"
1285 AC_SUBST(F_OMIT_FRAME_POINTER)
1287 dnl ------------------------------------------------------
1288 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1289 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1290 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1291 dnl code will work.
1292 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1294 dnl ============================================================
1295 dnl Check for libseccomp
1297 if test "x$enable_seccomp" != "xno"; then
1298   AC_CHECK_HEADERS([seccomp.h])
1299   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1302 dnl ============================================================
1303 dnl Check for libscrypt
1305 if test "x$enable_libscrypt" != "xno"; then
1306   AC_CHECK_HEADERS([libscrypt.h])
1307   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1308   AC_CHECK_FUNCS([libscrypt_scrypt])
1311 dnl ============================================================
1312 dnl We need an implementation of curve25519.
1314 dnl set these defaults.
1315 build_curve25519_donna=no
1316 build_curve25519_donna_c64=no
1317 use_curve25519_donna=no
1318 use_curve25519_nacl=no
1319 CURVE25519_LIBS=
1321 dnl The best choice is using curve25519-donna-c64, but that requires
1322 dnl that we
1323 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1324   tor_cv_can_use_curve25519_donna_c64,
1325   [AC_RUN_IFELSE(
1326     [AC_LANG_PROGRAM([dnl
1327       #include <stdint.h>
1328       typedef unsigned uint128_t __attribute__((mode(TI)));
1329   int func(uint64_t a, uint64_t b) {
1330            uint128_t c = ((uint128_t)a) * b;
1331            int ok = ((uint64_t)(c>>96)) == 522859 &&
1332              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1333                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1334                  (((uint64_t)(c))&0xffffffffL) == 0;
1335            return ok;
1336       }
1337   ], [dnl
1338     int ok = func( ((uint64_t)2000000000) * 1000000000,
1339                    ((uint64_t)1234567890) << 24);
1340         return !ok;
1341       ])],
1342   [tor_cv_can_use_curve25519_donna_c64=yes],
1343       [tor_cv_can_use_curve25519_donna_c64=no],
1344   [AC_LINK_IFELSE(
1345         [AC_LANG_PROGRAM([dnl
1346       #include <stdint.h>
1347       typedef unsigned uint128_t __attribute__((mode(TI)));
1348   int func(uint64_t a, uint64_t b) {
1349            uint128_t c = ((uint128_t)a) * b;
1350            int ok = ((uint64_t)(c>>96)) == 522859 &&
1351              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1352                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1353                  (((uint64_t)(c))&0xffffffffL) == 0;
1354            return ok;
1355       }
1356   ], [dnl
1357     int ok = func( ((uint64_t)2000000000) * 1000000000,
1358                  ((uint64_t)1234567890) << 24);
1359         return !ok;
1360       ])],
1361           [tor_cv_can_use_curve25519_donna_c64=cross],
1362       [tor_cv_can_use_curve25519_donna_c64=no])])])
1364 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1365                   nacl/crypto_scalarmult_curve25519.h])
1367 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1368   tor_cv_can_use_curve25519_nacl,
1369   [tor_saved_LIBS="$LIBS"
1370    LIBS="$LIBS -lnacl"
1371    AC_LINK_IFELSE(
1372      [AC_LANG_PROGRAM([dnl
1373        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1374        #include <crypto_scalarmult_curve25519.h>
1375    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1376    #include <nacl/crypto_scalarmult_curve25519.h>
1377    #endif
1378        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1379    #error Hey, this is the reference implementation! That's not fast.
1380    #endif
1381      ], [
1382    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1383      ])], [tor_cv_can_use_curve25519_nacl=yes],
1384      [tor_cv_can_use_curve25519_nacl=no])
1385    LIBS="$tor_saved_LIBS" ])
1387  dnl Okay, now we need to figure out which one to actually use. Fall back
1388  dnl to curve25519-donna.c
1390  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1391    build_curve25519_donna_c64=yes
1392    use_curve25519_donna=yes
1393  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1394    use_curve25519_nacl=yes
1395    CURVE25519_LIBS=-lnacl
1396  else
1397    build_curve25519_donna=yes
1398    use_curve25519_donna=yes
1399  fi
1401 if test "x$use_curve25519_donna" = "xyes"; then
1402   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1403             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1405 if test "x$use_curve25519_nacl" = "xyes"; then
1406   AC_DEFINE(USE_CURVE25519_NACL, 1,
1407             [Defined if we should use a curve25519 from nacl])
1409 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1410   test "x$build_curve25519_donna" = "xyes")
1411 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1412   test "x$build_curve25519_donna_c64" = "xyes")
1413 AC_SUBST(CURVE25519_LIBS)
1415 dnl Make sure to enable support for large off_t if available.
1416 AC_SYS_LARGEFILE
1418 AC_CHECK_HEADERS([errno.h \
1419                   fcntl.h \
1420                   signal.h \
1421                   string.h \
1422                   sys/capability.h \
1423                   sys/fcntl.h \
1424                   sys/stat.h \
1425                   sys/time.h \
1426                   sys/types.h \
1427                   time.h \
1428                   unistd.h \
1429                   arpa/inet.h \
1430                   crt_externs.h \
1431                   execinfo.h \
1432                   gnu/libc-version.h \
1433                   grp.h \
1434                   ifaddrs.h \
1435                   inttypes.h \
1436                   limits.h \
1437                   linux/types.h \
1438                   machine/limits.h \
1439                   malloc.h \
1440                   malloc/malloc.h \
1441                   malloc_np.h \
1442                   netdb.h \
1443                   netinet/in.h \
1444                   netinet/in6.h \
1445                   pwd.h \
1446                   readpassphrase.h \
1447                   stdatomic.h \
1448                   sys/eventfd.h \
1449                   sys/file.h \
1450                   sys/ioctl.h \
1451                   sys/limits.h \
1452                   sys/mman.h \
1453                   sys/param.h \
1454                   sys/prctl.h \
1455                   sys/random.h \
1456                   sys/resource.h \
1457                   sys/select.h \
1458                   sys/socket.h \
1459                   sys/statvfs.h \
1460                   sys/syscall.h \
1461                   sys/sysctl.h \
1462                   sys/syslimits.h \
1463                   sys/time.h \
1464                   sys/types.h \
1465                   sys/un.h \
1466                   sys/utime.h \
1467                   sys/wait.h \
1468                   syslog.h \
1469                   utime.h])
1471 AC_CHECK_HEADERS(sys/param.h)
1473 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1474 [#ifdef HAVE_SYS_TYPES_H
1475 #include <sys/types.h>
1476 #endif
1477 #ifdef HAVE_SYS_SOCKET_H
1478 #include <sys/socket.h>
1479 #endif])
1480 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1481 [#ifdef HAVE_SYS_TYPES_H
1482 #include <sys/types.h>
1483 #endif
1484 #ifdef HAVE_SYS_SOCKET_H
1485 #include <sys/socket.h>
1486 #endif
1487 #ifdef HAVE_NET_IF_H
1488 #include <net/if.h>
1489 #endif
1490 #ifdef HAVE_NETINET_IN_H
1491 #include <netinet/in.h>
1492 #endif])
1494 AC_CHECK_HEADERS(linux/if.h,[],[],
1496 #ifdef HAVE_SYS_SOCKET_H
1497 #include <sys/socket.h>
1498 #endif
1501 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1502         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1503 [#ifdef HAVE_SYS_TYPES_H
1504 #include <sys/types.h>
1505 #endif
1506 #ifdef HAVE_SYS_SOCKET_H
1507 #include <sys/socket.h>
1508 #endif
1509 #ifdef HAVE_LIMITS_H
1510 #include <limits.h>
1511 #endif
1512 #ifdef HAVE_LINUX_TYPES_H
1513 #include <linux/types.h>
1514 #endif
1515 #ifdef HAVE_NETINET_IN6_H
1516 #include <netinet/in6.h>
1517 #endif
1518 #ifdef HAVE_NETINET_IN_H
1519 #include <netinet/in.h>
1520 #endif])
1522 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1523         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1524 [#ifdef HAVE_SYS_TYPES_H
1525 #include <sys/types.h>
1526 #endif
1527 #ifdef HAVE_SYS_SOCKET_H
1528 #include <sys/socket.h>
1529 #endif
1530 #ifdef HAVE_LIMITS_H
1531 #include <limits.h>
1532 #endif
1533 #ifdef HAVE_LINUX_TYPES_H
1534 #include <linux/types.h>
1535 #endif
1536 #ifdef HAVE_NETINET_IN6_H
1537 #include <netinet/in6.h>
1538 #endif
1539 #ifdef HAVE_NETINET_IN_H
1540 #include <netinet/in.h>
1541 #endif
1542 #ifdef HAVE_LINUX_IF_H
1543 #include <linux/if.h>
1544 #endif])
1546 transparent_ok=0
1547 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1548   transparent_ok=1
1550 if test "x$linux_netfilter_ipv4" = "x1"; then
1551   transparent_ok=1
1553 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1554   transparent_ok=1
1556 if test "x$transparent_ok" = "x1"; then
1557   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1558 else
1559   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1562 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1563 [#ifdef HAVE_SYS_TYPES_H
1564 #include <sys/types.h>
1565 #endif
1566 #ifdef HAVE_SYS_TIME_H
1567 #include <sys/time.h>
1568 #endif])
1570 AC_CHECK_SIZEOF(char)
1571 AC_CHECK_SIZEOF(short)
1572 AC_CHECK_SIZEOF(int)
1573 AC_CHECK_SIZEOF(long)
1574 AC_CHECK_SIZEOF(long long)
1575 AC_CHECK_SIZEOF(__int64)
1576 AC_CHECK_SIZEOF(void *)
1577 AC_CHECK_SIZEOF(time_t)
1578 AC_CHECK_SIZEOF(size_t)
1579 AC_CHECK_SIZEOF(pid_t)
1581 AC_CHECK_TYPES([uint, u_char, ssize_t])
1583 AC_PC_FROM_UCONTEXT([:])
1585 dnl used to include sockaddr_storage, but everybody has that.
1586 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1587 [#ifdef HAVE_SYS_TYPES_H
1588 #include <sys/types.h>
1589 #endif
1590 #ifdef HAVE_NETINET_IN_H
1591 #include <netinet/in.h>
1592 #endif
1593 #ifdef HAVE_NETINET_IN6_H
1594 #include <netinet/in6.h>
1595 #endif
1596 #ifdef HAVE_SYS_SOCKET_H
1597 #include <sys/socket.h>
1598 #endif
1599 #ifdef _WIN32
1600 #define _WIN32_WINNT 0x0501
1601 #define WIN32_LEAN_AND_MEAN
1602 #include <winsock2.h>
1603 #include <ws2tcpip.h>
1604 #endif
1606 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1607 [#ifdef HAVE_SYS_TYPES_H
1608 #include <sys/types.h>
1609 #endif
1610 #ifdef HAVE_NETINET_IN_H
1611 #include <netinet/in.h>
1612 #endif
1613 #ifdef HAVE_NETINET_IN6_H
1614 #include <netinet/in6.h>
1615 #endif
1616 #ifdef HAVE_SYS_SOCKET_H
1617 #include <sys/socket.h>
1618 #endif
1619 #ifdef _WIN32
1620 #define _WIN32_WINNT 0x0501
1621 #define WIN32_LEAN_AND_MEAN
1622 #include <winsock2.h>
1623 #include <ws2tcpip.h>
1624 #endif
1627 AC_CHECK_TYPES([rlim_t], , ,
1628 [#ifdef HAVE_SYS_TYPES_H
1629 #include <sys/types.h>
1630 #endif
1631 #ifdef HAVE_SYS_TIME_H
1632 #include <sys/time.h>
1633 #endif
1634 #ifdef HAVE_SYS_RESOURCE_H
1635 #include <sys/resource.h>
1636 #endif
1639 AX_CHECK_SIGN([time_t],
1640        [ : ],
1641        [ : ], [
1642 #ifdef HAVE_SYS_TYPES_H
1643 #include <sys/types.h>
1644 #endif
1645 #ifdef HAVE_SYS_TIME_H
1646 #include <sys/time.h>
1647 #endif
1648 #ifdef HAVE_TIME_H
1649 #include <time.h>
1650 #endif
1653 if test "$ax_cv_decl_time_t_signed" = "no"; then
1654   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1657 AX_CHECK_SIGN([size_t],
1658        [ tor_cv_size_t_signed=yes ],
1659        [ tor_cv_size_t_signed=no ], [
1660 #ifdef HAVE_SYS_TYPES_H
1661 #include <sys/types.h>
1662 #endif
1665 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1666   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1669 AX_CHECK_SIGN([enum always],
1670        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1671        [ : ], [
1672  enum always { AAA, BBB, CCC };
1675 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1676 #ifdef HAVE_SYS_SOCKET_H
1677 #include <sys/socket.h>
1678 #endif
1681 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1683 AC_CHECK_SIZEOF(cell_t)
1685 # Now make sure that NULL can be represented as zero bytes.
1686 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1687 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1688 [[#include <stdlib.h>
1689 #include <string.h>
1690 #include <stdio.h>
1691 #ifdef HAVE_STDDEF_H
1692 #include <stddef.h>
1693 #endif
1694 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1695 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1696        [tor_cv_null_is_zero=yes],
1697        [tor_cv_null_is_zero=no],
1698        [tor_cv_null_is_zero=cross])])
1700 if test "$tor_cv_null_is_zero" = "cross"; then
1701   # Cross-compiling; let's hope that the target isn't raving mad.
1702   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1705 if test "$tor_cv_null_is_zero" != "no"; then
1706   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1707             [Define to 1 iff memset(0) sets pointers to NULL])
1710 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1711 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1712 [[#include <stdlib.h>
1713 #include <string.h>
1714 #include <stdio.h>
1715 #ifdef HAVE_STDDEF_H
1716 #include <stddef.h>
1717 #endif
1718 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1719 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1720        [tor_cv_dbl0_is_zero=yes],
1721        [tor_cv_dbl0_is_zero=no],
1722        [tor_cv_dbl0_is_zero=cross])])
1724 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1725   # Cross-compiling; let's hope that the target isn't raving mad.
1726   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1729 if test "$tor_cv_dbl0_is_zero" != "no"; then
1730   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1731             [Define to 1 iff memset(0) sets doubles to 0.0])
1734 # And what happens when we malloc zero?
1735 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1736 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1737 [[#include <stdlib.h>
1738 #include <string.h>
1739 #include <stdio.h>
1740 #ifdef HAVE_STDDEF_H
1741 #include <stddef.h>
1742 #endif
1743 int main () { return malloc(0)?0:1; }]])],
1744        [tor_cv_malloc_zero_works=yes],
1745        [tor_cv_malloc_zero_works=no],
1746        [tor_cv_malloc_zero_works=cross])])
1748 if test "$tor_cv_malloc_zero_works" = "cross"; then
1749   # Cross-compiling; let's hope that the target isn't raving mad.
1750   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1753 if test "$tor_cv_malloc_zero_works" = "yes"; then
1754   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1755             [Define to 1 iff malloc(0) returns a pointer])
1758 # whether we seem to be in a 2s-complement world.
1759 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1760 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1761 [[int main () { int problem = ((-99) != (~99)+1);
1762 return problem ? 1 : 0; }]])],
1763        [tor_cv_twos_complement=yes],
1764        [tor_cv_twos_complement=no],
1765        [tor_cv_twos_complement=cross])])
1767 if test "$tor_cv_twos_complement" = "cross"; then
1768   # Cross-compiling; let's hope that the target isn't raving mad.
1769   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1772 if test "$tor_cv_twos_complement" != "no"; then
1773   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1774             [Define to 1 iff we represent negative integers with
1775              two's complement])
1778 # What does shifting a negative value do?
1779 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1780 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1781 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1782        [tor_cv_sign_extend=yes],
1783        [tor_cv_sign_extend=no],
1784        [tor_cv_sign_extend=cross])])
1786 if test "$tor_cv_sign_extend" = "cross"; then
1787   # Cross-compiling; let's hope that the target isn't raving mad.
1788   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1791 if test "$tor_cv_sign_extend" != "no"; then
1792   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1793             [Define to 1 iff right-shifting a negative value performs sign-extension])
1796 # Is uint8_t the same type as unsigned char?
1797 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1798 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1799 #include <stdint.h>
1800 extern uint8_t c;
1801 unsigned char c;]])],
1802        [tor_cv_uint8_uchar=yes],
1803        [tor_cv_uint8_uchar=no],
1804        [tor_cv_uint8_uchar=cross])])
1806 if test "$tor_cv_uint8_uchar" = "cross"; then
1807   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1810 if test "$tor_cv_uint8_uchar" = "no"; then
1811   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1814 AC_ARG_WITH(tcmalloc,
1815 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1816 [ tcmalloc=yes ], [ tcmalloc=no ])
1818 if test "x$tcmalloc" = "xyes"; then
1819    LDFLAGS="-ltcmalloc $LDFLAGS"
1822 using_custom_malloc=no
1823 if test "x$enable_openbsd_malloc" = "xyes"; then
1824    using_custom_malloc=yes
1826 if test "x$tcmalloc" = "xyes"; then
1827    using_custom_malloc=yes
1829 if test "$using_custom_malloc" = "no"; then
1830    AC_CHECK_FUNCS(mallinfo)
1833 # By default, we're going to assume we don't have mlockall()
1834 # bionic and other platforms have various broken mlockall subsystems.
1835 # Some systems don't have a working mlockall, some aren't linkable,
1836 # and some have it but don't declare it.
1837 AC_CHECK_FUNCS(mlockall)
1838 AC_CHECK_DECLS([mlockall], , , [
1839 #ifdef HAVE_SYS_MMAN_H
1840 #include <sys/mman.h>
1841 #endif])
1843 # Allow user to specify an alternate syslog facility
1844 AC_ARG_WITH(syslog-facility,
1845 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1846 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1847 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1848 AC_SUBST(LOGFACILITY)
1850 # Check if we have getresuid and getresgid
1851 AC_CHECK_FUNCS(getresuid getresgid)
1853 # Check for gethostbyname_r in all its glorious incompatible versions.
1854 #   (This logic is based on that in Python's configure.in)
1855 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1856   [Define this if you have any gethostbyname_r()])
1858 AC_CHECK_FUNC(gethostbyname_r, [
1859   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1860   OLD_CFLAGS=$CFLAGS
1861   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1862   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1863 #include <netdb.h>
1864   ]], [[
1865     char *cp1, *cp2;
1866     struct hostent *h1, *h2;
1867     int i1, i2;
1868     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1869   ]])],[
1870     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1871     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1872      [Define this if gethostbyname_r takes 6 arguments])
1873     AC_MSG_RESULT(6)
1874   ], [
1875     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1876 #include <netdb.h>
1877     ]], [[
1878       char *cp1, *cp2;
1879       struct hostent *h1;
1880       int i1, i2;
1881       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1882     ]])], [
1883       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1884       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1885         [Define this if gethostbyname_r takes 5 arguments])
1886       AC_MSG_RESULT(5)
1887    ], [
1888       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1889 #include <netdb.h>
1890      ]], [[
1891        char *cp1;
1892        struct hostent *h1;
1893        struct hostent_data hd;
1894        (void) gethostbyname_r(cp1,h1,&hd);
1895      ]])], [
1896        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1897        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1898          [Define this if gethostbyname_r takes 3 arguments])
1899        AC_MSG_RESULT(3)
1900      ], [
1901        AC_MSG_RESULT(0)
1902      ])
1903   ])
1904  ])
1905  CFLAGS=$OLD_CFLAGS
1908 AC_CACHE_CHECK([whether the C compiler supports __func__],
1909   tor_cv_have_func_macro,
1910   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1911 #include <stdio.h>
1912 int main(int c, char **v) { puts(__func__); }])],
1913   tor_cv_have_func_macro=yes,
1914   tor_cv_have_func_macro=no))
1916 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1917   tor_cv_have_FUNC_macro,
1918   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1919 #include <stdio.h>
1920 int main(int c, char **v) { puts(__FUNC__); }])],
1921   tor_cv_have_FUNC_macro=yes,
1922   tor_cv_have_FUNC_macro=no))
1924 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1925   tor_cv_have_FUNCTION_macro,
1926   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1927 #include <stdio.h>
1928 int main(int c, char **v) { puts(__FUNCTION__); }])],
1929   tor_cv_have_FUNCTION_macro=yes,
1930   tor_cv_have_FUNCTION_macro=no))
1932 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1933   tor_cv_have_environ_declared,
1934   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1935 #ifdef HAVE_UNISTD_H
1936 #include <unistd.h>
1937 #endif
1938 #include <stdlib.h>
1939 int main(int c, char **v) { char **t = environ; }])],
1940   tor_cv_have_environ_declared=yes,
1941   tor_cv_have_environ_declared=no))
1943 if test "$tor_cv_have_func_macro" = "yes"; then
1944   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1947 if test "$tor_cv_have_FUNC_macro" = "yes"; then
1948   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1951 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
1952   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1953            [Defined if the compiler supports __FUNCTION__])
1956 if test "$tor_cv_have_environ_declared" = "yes"; then
1957   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1958            [Defined if we have extern char **environ already declared])
1961 # $prefix stores the value of the --prefix command line option, or
1962 # NONE if the option wasn't set.  In the case that it wasn't set, make
1963 # it be the default, so that we can use it to expand directories now.
1964 if test "x$prefix" = "xNONE"; then
1965   prefix=$ac_default_prefix
1968 # and similarly for $exec_prefix
1969 if test "x$exec_prefix" = "xNONE"; then
1970   exec_prefix=$prefix
1973 if test "x$BUILDDIR" = "x"; then
1974   BUILDDIR=`pwd`
1976 AC_SUBST(BUILDDIR)
1977 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1978 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1980 if test "x$SRCDIR" = "x"; then
1981   SRCDIR=$(cd "$srcdir"; pwd)
1983 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
1984 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
1986 if test "x$CONFDIR" = "x"; then
1987   CONFDIR=`eval echo $sysconfdir/tor`
1989 AC_SUBST(CONFDIR)
1990 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1991 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1993 BINDIR=`eval echo $bindir`
1994 AC_SUBST(BINDIR)
1995 LOCALSTATEDIR=`eval echo $localstatedir`
1996 AC_SUBST(LOCALSTATEDIR)
1998 if test "$bwin32" = "true"; then
1999   # Test if the linker supports the --nxcompat and --dynamicbase options
2000   # for Windows
2001   save_LDFLAGS="$LDFLAGS"
2002   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2003   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2004   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2005     [AC_MSG_RESULT([yes])]
2006     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2007     [AC_MSG_RESULT([no])]
2008   )
2009   LDFLAGS="$save_LDFLAGS"
2012 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2013 # than autoconf's macros like.
2014 if test "$GCC" = "yes"; then
2015   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2016   # accident waiting to happen.
2017   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2018 else
2019   # Override optimization level for non-gcc compilers
2020   CFLAGS="$CFLAGS -O"
2021   enable_gcc_warnings=no
2022   enable_gcc_warnings_advisory=no
2025 # Warnings implies advisory-warnings and -Werror.
2026 if test "$enable_gcc_warnings" = "yes"; then
2027   enable_gcc_warnings_advisory=yes
2028   enable_fatal_warnings=yes
2031 # OS X Lion started deprecating the system openssl. Let's just disable
2032 # all deprecation warnings on OS X. Also, to potentially make the binary
2033 # a little smaller, let's enable dead_strip.
2034 case "$host_os" in
2036  darwin*)
2037     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2038     LDFLAGS="$LDFLAGS -dead_strip" ;;
2039 esac
2041 # Add some more warnings which we use in development but not in the
2042 # released versions.  (Some relevant gcc versions can't handle these.)
2044 # Note that we have to do this near the end  of the autoconf process, or
2045 # else we may run into problems when these warnings hit on the testing C
2046 # programs that autoconf wants to build.
2047 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2049   case "$host" in
2050     *-*-openbsd* | *-*-bitrig*)
2051       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2052       # That's fine, except that the headers don't pass -Wredundant-decls.
2053       # Therefore, let's disable -Wsystem-headers when we're building
2054       # with maximal warnings on OpenBSD.
2055       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2056   esac
2058   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2059   # have it work better.
2060   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2062   # This warning was added in gcc 4.3, but it appears to generate
2063   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2064   #CFLAGS="$CFLAGS -Wlogical-op"
2066   m4_foreach_w([warning_flag], [
2067      -Waddress
2068      -Waddress-of-array-temporary
2069      -Waddress-of-temporary
2070      -Wambiguous-macro
2071      -Wanonymous-pack-parens
2072      -Warc
2073      -Warc-abi
2074      -Warc-bridge-casts-disallowed-in-nonarc
2075      -Warc-maybe-repeated-use-of-weak
2076      -Warc-performSelector-leaks
2077      -Warc-repeated-use-of-weak
2078      -Warray-bounds
2079      -Warray-bounds-pointer-arithmetic
2080      -Wasm
2081      -Wasm-operand-widths
2082      -Watomic-properties
2083      -Watomic-property-with-user-defined-accessor
2084      -Wauto-import
2085      -Wauto-storage-class
2086      -Wauto-var-id
2087      -Wavailability
2088      -Wbackslash-newline-escape
2089      -Wbad-array-new-length
2090      -Wbind-to-temporary-copy
2091      -Wbitfield-constant-conversion
2092      -Wbool-conversion
2093      -Wbool-conversions
2094      -Wbuiltin-requires-header
2095      -Wchar-align
2096      -Wcompare-distinct-pointer-types
2097      -Wcomplex-component-init
2098      -Wconditional-type-mismatch
2099      -Wconfig-macros
2100      -Wconstant-conversion
2101      -Wconstant-logical-operand
2102      -Wconstexpr-not-const
2103      -Wcustom-atomic-properties
2104      -Wdangling-field
2105      -Wdangling-initializer-list
2106      -Wdate-time
2107      -Wdelegating-ctor-cycles
2108      -Wdeprecated-implementations
2109      -Wdeprecated-register
2110      -Wdirect-ivar-access
2111      -Wdiscard-qual
2112      -Wdistributed-object-modifiers
2113      -Wdivision-by-zero
2114      -Wdollar-in-identifier-extension
2115      -Wdouble-promotion
2116      -Wduplicate-decl-specifier
2117      -Wduplicate-enum
2118      -Wduplicate-method-arg
2119      -Wduplicate-method-match
2120      -Wduplicated-cond
2121      -Wdynamic-class-memaccess
2122      -Wembedded-directive
2123      -Wempty-translation-unit
2124      -Wenum-conversion
2125      -Wexit-time-destructors
2126      -Wexplicit-ownership-type
2127      -Wextern-initializer
2128      -Wextra
2129      -Wextra-semi
2130      -Wextra-tokens
2131      -Wflexible-array-extensions
2132      -Wfloat-conversion
2133      -Wformat-non-iso
2134      -Wfour-char-constants
2135      -Wgcc-compat
2136      -Wglobal-constructors
2137      -Wgnu-array-member-paren-init
2138      -Wgnu-designator
2139      -Wgnu-static-float-init
2140      -Wheader-guard
2141      -Wheader-hygiene
2142      -Widiomatic-parentheses
2143      -Wignored-attributes
2144      -Wimplicit-atomic-properties
2145      -Wimplicit-conversion-floating-point-to-bool
2146      -Wimplicit-exception-spec-mismatch
2147      -Wimplicit-fallthrough
2148      -Wimplicit-fallthrough-per-function
2149      -Wimplicit-retain-self
2150      -Wimport-preprocessor-directive-pedantic
2151      -Wincompatible-library-redeclaration
2152      -Wincompatible-pointer-types-discards-qualifiers
2153      -Wincomplete-implementation
2154      -Wincomplete-module
2155      -Wincomplete-umbrella
2156      -Winit-self
2157      -Wint-conversions
2158      -Wint-to-void-pointer-cast
2159      -Winteger-overflow
2160      -Winvalid-constexpr
2161      -Winvalid-iboutlet
2162      -Winvalid-noreturn
2163      -Winvalid-pp-token
2164      -Winvalid-source-encoding
2165      -Winvalid-token-paste
2166      -Wknr-promoted-parameter
2167      -Wlarge-by-value-copy
2168      -Wliteral-conversion
2169      -Wliteral-range
2170      -Wlocal-type-template-args
2171      -Wlogical-op
2172      -Wloop-analysis
2173      -Wmain-return-type
2174      -Wmalformed-warning-check
2175      -Wmethod-signatures
2176      -Wmicrosoft
2177      -Wmicrosoft-exists
2178      -Wmismatched-parameter-types
2179      -Wmismatched-return-types
2180      -Wmissing-field-initializers
2181      -Wmissing-format-attribute
2182      -Wmissing-noreturn
2183      -Wmissing-selector-name
2184      -Wmissing-sysroot
2185      -Wmissing-variable-declarations
2186      -Wmodule-conflict
2187      -Wnested-anon-types
2188      -Wnewline-eof
2189      -Wnon-literal-null-conversion
2190      -Wnon-pod-varargs
2191      -Wnonportable-cfstrings
2192      -Wnormalized=nfkc
2193      -Wnull-arithmetic
2194      -Wnull-character
2195      -Wnull-conversion
2196      -Wnull-dereference
2197      -Wout-of-line-declaration
2198      -Wover-aligned
2199      -Woverlength-strings
2200      -Woverride-init
2201      -Woverriding-method-mismatch
2202      -Wpointer-type-mismatch
2203      -Wpredefined-identifier-outside-function
2204      -Wprotocol-property-synthesis-ambiguity
2205      -Wreadonly-iboutlet-property
2206      -Wreadonly-setter-attrs
2207      -Wreceiver-expr
2208      -Wreceiver-forward-class
2209      -Wreceiver-is-weak
2210      -Wreinterpret-base-class
2211      -Wrequires-super-attribute
2212      -Wreserved-user-defined-literal
2213      -Wreturn-stack-address
2214      -Wsection
2215      -Wselector-type-mismatch
2216      -Wsentinel
2217      -Wserialized-diagnostics
2218      -Wshadow
2219      -Wshift-count-negative
2220      -Wshift-count-overflow
2221      -Wshift-negative-value
2222      -Wshift-overflow=2
2223      -Wshift-sign-overflow
2224      -Wshorten-64-to-32
2225      -Wsizeof-array-argument
2226      -Wsource-uses-openmp
2227      -Wstatic-float-init
2228      -Wstatic-in-inline
2229      -Wstatic-local-in-inline
2230      -Wstrict-overflow=1
2231      -Wstring-compare
2232      -Wstring-conversion
2233      -Wstrlcpy-strlcat-size
2234      -Wstrncat-size
2235      -Wsuggest-attribute=format
2236      -Wsuggest-attribute=noreturn
2237      -Wsuper-class-method-mismatch
2238      -Wswitch-bool
2239      -Wsync-nand
2240      -Wtautological-constant-out-of-range-compare
2241      -Wtentative-definition-incomplete-type
2242      -Wtrampolines
2243      -Wtype-safety
2244      -Wtypedef-redefinition
2245      -Wtypename-missing
2246      -Wundefined-inline
2247      -Wundefined-internal
2248      -Wundefined-reinterpret-cast
2249      -Wunicode
2250      -Wunicode-whitespace
2251      -Wunknown-warning-option
2252      -Wunnamed-type-template-args
2253      -Wunneeded-member-function
2254      -Wunsequenced
2255      -Wunsupported-visibility
2256      -Wunused-but-set-parameter
2257      -Wunused-but-set-variable
2258      -Wunused-command-line-argument
2259      -Wunused-const-variable=2
2260      -Wunused-exception-parameter
2261      -Wunused-local-typedefs
2262      -Wunused-member-function
2263      -Wunused-sanitize-argument
2264      -Wunused-volatile-lvalue
2265      -Wuser-defined-literals
2266      -Wvariadic-macros
2267      -Wvector-conversion
2268      -Wvector-conversions
2269      -Wvexing-parse
2270      -Wvisibility
2271      -Wvla-extension
2272      -Wzero-length-array
2273   ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
2275 dnl    We should re-enable this in some later version.  Clang doesn't
2276 dnl    mind, but it causes trouble with GCC.
2277 dnl     -Wstrict-overflow=2
2279 dnl    These seem to require annotations that we don't currently use,
2280 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2281 dnl     -Wthread-safety
2282 dnl     -Wthread-safety-analysis
2283 dnl     -Wthread-safety-attributes
2284 dnl     -Wthread-safety-beta
2285 dnl     -Wthread-safety-precise
2287   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2288   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2289   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2290   CFLAGS="$CFLAGS -Wwrite-strings"
2291   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2292   CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
2293   CFLAGS="$CFLAGS -Wunused-parameter "
2294   # These interfere with building main() { return 0; }, which autoconf
2295   # likes to use as its default program.
2296   CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
2298   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2299     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2300   fi
2301   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2302     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2303   fi
2304   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2305     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2306   fi
2308   if test "x$enable_fatal_warnings" = "xyes"; then
2309     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2310     # default autoconf programs are full of errors.
2311     CFLAGS="$CFLAGS -Werror"
2312   fi
2316 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2317    case "$host_os" in
2318     darwin*)
2319       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.])
2320    esac
2323 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2325 AC_CONFIG_FILES([
2326         Doxyfile
2327         Makefile
2328         config.rust
2329         link_rust.sh
2330         contrib/dist/suse/tor.sh
2331         contrib/operator-tools/tor.logrotate
2332         contrib/dist/tor.sh
2333         contrib/dist/torctl
2334         contrib/dist/tor.service
2335         src/config/torrc.sample
2336         src/config/torrc.minimal
2337         src/rust/.cargo/config
2338         scripts/maint/checkOptionDocs.pl
2339         scripts/maint/updateVersions.pl
2342 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2343   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2344   for file in $regular_mans ; do
2345     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2346       echo "==================================";
2347       echo;
2348       echo "Building Tor has failed since manpages cannot be built.";
2349       echo;
2350       echo "You need asciidoc installed to be able to build the manpages.";
2351       echo "To build without manpages, use the --disable-asciidoc argument";
2352       echo "when calling configure.";
2353       echo;
2354       echo "==================================";
2355       exit 1;
2356     fi
2357   done
2360 if test "$fragile_hardening" = "yes"; then
2361   AC_MSG_WARN([
2363 ============
2364 Warning!  Building Tor with --enable-fragile-hardening (also known as
2365 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2366 other kinds of attacks easier. A Tor instance build with this option will be
2367 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2368 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2369 denial of service attacks. For more information, see
2370 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
2371 ============
2372   ])
2375 AC_OUTPUT