fixup! hs-v3: Silence some logging for client authorization
[tor.git] / configure.ac
blob643068724e77c994abd3d91e9f267c805490d851
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. Deprecated: see --with-malloc]))
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, test "x$enable_nss" != "xyes")
72 if test "x$enable_nss" = "xyes"; then
73   AC_DEFINE(ENABLE_NSS, 1,
74             [Defined if we're building with NSS.])
75 else
76   AC_DEFINE(ENABLE_OPENSSL, 1,
77             [Defined if we're building with OpenSSL or LibreSSL])
80 if test "$enable_static_tor" = "yes"; then
81   enable_static_libevent="yes";
82   enable_static_openssl="yes";
83   enable_static_zlib="yes";
84   CFLAGS="$CFLAGS -static"
87 if test "$enable_system_torrc" = "no"; then
88   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
89             [Defined if we're not going to look for a torrc in SYSCONF])
92 if test "$enable_memory_sentinels" = "no"; then
93   AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
94            [Defined if we're turning off memory safety code to look for bugs])
97 AC_ARG_ENABLE(asciidoc,
98      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
99      [case "${enableval}" in
100         "yes") asciidoc=true ;;
101         "no")  asciidoc=false ;;
102         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
103       esac], [asciidoc=true])
105 # systemd notify support
106 AC_ARG_ENABLE(systemd,
107       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
108       [case "${enableval}" in
109         "yes") systemd=true ;;
110         "no")  systemd=false ;;
111         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
112       esac], [systemd=auto])
114 if test "$enable_restart_debugging" = "yes"; then
115   AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
116             [Defined if we're building with support for in-process restart debugging.])
119 if test "$enable_zstd_advanced_apis" != "no"; then
120    AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
121              [Defined if we're going to try to use zstd's "static-only" APIs.])
124 # systemd support
125 if test "x$enable_systemd" = "xno"; then
126     have_systemd=no;
127 else
128     PKG_CHECK_MODULES(SYSTEMD,
129         [libsystemd-daemon],
130         have_systemd=yes,
131         have_systemd=no)
132     if test "x$have_systemd" = "xno"; then
133         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
134         PKG_CHECK_MODULES(SYSTEMD,
135             [libsystemd],
136             have_systemd=yes,
137             have_systemd=no)
138     fi
141 if test "x$have_systemd" = "xyes"; then
142     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
143     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
144     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
145     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
146          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
148 AC_SUBST(TOR_SYSTEMD_CFLAGS)
149 AC_SUBST(TOR_SYSTEMD_LIBS)
151 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
152     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
155 case "$host" in
156    *-*-solaris* )
157      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
158      ;;
159 esac
161 AC_ARG_ENABLE(gcc-warnings,
162      AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
163 AC_ARG_ENABLE(fatal-warnings,
164      AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
165 AC_ARG_ENABLE(gcc-warnings-advisory,
166      AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
168 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
169 AC_ARG_ENABLE(gcc-hardening,
170     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
172 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
173 AC_ARG_ENABLE(expensive-hardening,
174     AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
175 AC_ARG_ENABLE(fragile-hardening,
176     AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
177 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
178   fragile_hardening="yes"
179   AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
182 dnl Linker hardening options
183 dnl Currently these options are ELF specific - you can't use this with MacOSX
184 AC_ARG_ENABLE(linker-hardening,
185     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
187 AC_ARG_ENABLE(local-appdata,
188    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
189 if test "$enable_local_appdata" = "yes"; then
190   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
191             [Defined if we default to host local appdata paths on Windows])
194 AC_ARG_ENABLE(tool-name-check,
195      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
197 AC_ARG_ENABLE(seccomp,
198      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
200 AC_ARG_ENABLE(libscrypt,
201      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
203 dnl Enable event tracing which are transformed to debug log statement.
204 AC_ARG_ENABLE(event-tracing-debug,
205      AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
206 AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
208 if test x$enable_event_tracing_debug = xyes; then
209   AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
210   AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
213 dnl Enable Android only features.
214 AC_ARG_ENABLE(android,
215      AS_HELP_STRING(--enable-android, [build with Android features enabled]))
216 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
218 if test "x$enable_android" = "xyes"; then
219   AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
221   dnl Check if the Android log library is available.
222   AC_CHECK_HEADERS([android/log.h])
223   AC_SEARCH_LIBS(__android_log_write, [log])
227 dnl ---
228 dnl Tor modules options. These options are namespaced with --disable-module-XXX
229 dnl ---
231 dnl All our modules.
232 m4_define(MODULES, dirauth)
234 dnl Directory Authority module.
235 AC_ARG_ENABLE([module-dirauth],
236               AS_HELP_STRING([--disable-module-dirauth],
237                              [Do not build tor with the dirauth module]),
238               [], dnl Action if-given
239               AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
240                         [Compile with Directory Authority feature support]))
241 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH, [test "x$enable_module_dirauth" != "xno"])
243 dnl Helper variables.
244 TOR_MODULES_ALL_ENABLED=
245 AC_DEFUN([ADD_MODULE], [
246     MODULE=m4_toupper($1)
247     TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
249 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
250 AC_SUBST(TOR_MODULES_ALL_ENABLED)
252 dnl check for the correct "ar" when cross-compiling.
253 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
254 dnl    so kludge up a replacement for the case where it isn't there yet.)
255 m4_ifdef([AM_PROG_AR],
256          [AM_PROG_AR],
257          [AN_MAKEVAR([AR], [AC_PROG_AR])
258           AN_PROGRAM([ar], [AC_PROG_AR])
259           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
260           AC_PROG_AR])
262 dnl Check whether the above macro has settled for a simply named tool even
263 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
264 dnl because that will find any cc on the system, not only the cross-compiler,
265 dnl and then verify that a binary built with this compiler runs on the
266 dnl build system. It will then come to the false conclusion that we're not
267 dnl cross-compiling.
268 if test "x$enable_tool_name_check" != "xno"; then
269     if test "x$ac_tool_warned" = "xyes"; then
270         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.)])
271         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
272                 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.)])
273         fi
276 AC_PROG_CC
277 AC_PROG_CPP
278 AC_PROG_MAKE_SET
279 AC_PROG_RANLIB
280 AC_PROG_SED
282 AC_ARG_VAR([PERL], [path to Perl binary])
283 AC_CHECK_PROGS([PERL], [perl])
284 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
286 dnl check for asciidoc and a2x
287 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
288 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
290 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
292 AM_PROG_CC_C_O
293 AC_PROG_CC_C99
295 AC_ARG_VAR([PYTHON], [path to Python binary])
296 AC_CHECK_PROGS(PYTHON, [ \
297         python3 \
298         python3.8 python3.7 python3.6 python3.5 python3.4 \
299         python \
300         python2 python2.7])
301 if test "x$PYTHON" = "x"; then
302   AC_MSG_WARN([Python unavailable; some tests will not be run.])
304 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
306 dnl List all external rust crates we depend on here. Include the version
307 rust_crates=" \
308     digest-0.7.2 \
309     libc-0.2.39 \
311 AC_SUBST(rust_crates)
313 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
314 AC_C_FLEXIBLE_ARRAY_MEMBER
315 ], [
316  dnl Maybe we've got an old autoconf...
317  AC_CACHE_CHECK([for flexible array members],
318      tor_cv_c_flexarray,
319      [AC_COMPILE_IFELSE(
320        AC_LANG_PROGRAM([
321  struct abc { int a; char b[]; };
322 ], [
323  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
324  def->b[0] = 33;
326   [tor_cv_c_flexarray=yes],
327   [tor_cv_c_flexarray=no])])
328  if test "$tor_cv_flexarray" = "yes"; then
329    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
330  else
331    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
332  fi
335 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
336       tor_cv_c_c99_decl,
337       [AC_COMPILE_IFELSE(
338          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
339          [tor_cv_c_c99_decl=yes],
340          [tor_cv_c_c99_decl=no] )])
341 if test "$tor_cv_c_c99_decl" != "yes"; then
342   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
345 AC_CACHE_CHECK([for working C99 designated initializers],
346       tor_cv_c_c99_designated_init,
347       [AC_COMPILE_IFELSE(
348          [AC_LANG_PROGRAM([struct s { int a; int b; };],
349                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
350          [tor_cv_c_c99_designated_init=yes],
351          [tor_cv_c_c99_designated_init=no] )])
353 if test "$tor_cv_c_c99_designated_init" != "yes"; then
354   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
357 TORUSER=_tor
358 AC_ARG_WITH(tor-user,
359         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
360         [
361            TORUSER=$withval
362         ]
364 AC_SUBST(TORUSER)
366 TORGROUP=_tor
367 AC_ARG_WITH(tor-group,
368         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
369         [
370            TORGROUP=$withval
371         ]
373 AC_SUBST(TORGROUP)
376 dnl If _WIN32 is defined and non-zero, we are building for win32
377 AC_MSG_CHECKING([for win32])
378 AC_RUN_IFELSE([AC_LANG_SOURCE([
379 int main(int c, char **v) {
380 #ifdef _WIN32
381 #if _WIN32
382   return 0;
383 #else
384   return 1;
385 #endif
386 #else
387   return 2;
388 #endif
389 }])],
390 bwin32=true; AC_MSG_RESULT([yes]),
391 bwin32=false; AC_MSG_RESULT([no]),
392 bwin32=cross; AC_MSG_RESULT([cross])
395 if test "$bwin32" = "cross"; then
396 AC_MSG_CHECKING([for win32 (cross)])
397 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
398 #ifdef _WIN32
399 int main(int c, char **v) {return 0;}
400 #else
401 #error
402 int main(int c, char **v) {return x(y);}
403 #endif
404 ])],
405 bwin32=true; AC_MSG_RESULT([yes]),
406 bwin32=false; AC_MSG_RESULT([no]))
409 AH_BOTTOM([
410 #ifdef _WIN32
411 /* Defined to access windows functions and definitions for >=WinXP */
412 # ifndef WINVER
413 #  define WINVER 0x0501
414 # endif
416 /* Defined to access _other_ windows functions and definitions for >=WinXP */
417 # ifndef _WIN32_WINNT
418 #  define _WIN32_WINNT 0x0501
419 # endif
421 /* Defined to avoid including some windows headers as part of Windows.h */
422 # ifndef WIN32_LEAN_AND_MEAN
423 #  define WIN32_LEAN_AND_MEAN 1
424 # endif
425 #endif
428 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
429 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
430 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
432 dnl Enable C99 when compiling with MIPSpro
433 AC_MSG_CHECKING([for MIPSpro compiler])
434 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
435 #if (defined(__sgi) && defined(_COMPILER_VERSION))
436 #error
437   return x(y);
438 #endif
439 ])],
440 bmipspro=false; AC_MSG_RESULT(no),
441 bmipspro=true; AC_MSG_RESULT(yes))
443 if test "$bmipspro" = "true"; then
444   CFLAGS="$CFLAGS -c99"
447 AC_C_BIGENDIAN
449 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
451 if test "x$enable_rust" = "xyes"; then
452   AC_ARG_VAR([RUSTC], [path to the rustc binary])
453   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
454   if test "x$RUSTC" = "xno"; then
455     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
456   fi
458   AC_ARG_VAR([CARGO], [path to the cargo binary])
459   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
460   if test "x$CARGO" = "xno"; then
461     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
462   fi
464   AC_DEFINE([HAVE_RUST], 1, [have Rust])
465   if test "x$enable_fatal_warnings" = "xyes"; then
466     RUST_WARN=
467   else
468     RUST_WARN=#
469   fi
470   if test "x$enable_cargo_online_mode" = "xyes"; then
471     CARGO_ONLINE=
472     RUST_DL=#
473   else
474     CARGO_ONLINE=--frozen
475     RUST_DL=
477     dnl When we're not allowed to touch the network, we need crate dependencies
478     dnl locally available.
479     AC_MSG_CHECKING([rust crate dependencies])
480     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
481     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
482       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
483     fi
484     dnl Check whether the path exists before we try to cd into it.
485     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
486       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.])
487       ERRORED=1
488     fi
489     dnl Make the path absolute, since we'll be using it from within a
490     dnl subdirectory.
491     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
493     for dep in $rust_crates; do
494       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
495         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.])
496         ERRORED=1
497       fi
498     done
499     if test "x$ERRORED" = "x"; then
500       AC_MSG_RESULT([yes])
501     fi
502   fi
504   dnl This is a workaround for #46797
505   dnl (a.k.a https://github.com/rust-lang/rust/issues/46797 ).  Once the
506   dnl upstream bug is fixed, we can remove this workaround.
507   case "$host_os" in
508       darwin*)
509         TOR_RUST_EXTRA_LIBS="-lresolv"
510         ;;
511   esac
513   dnl For now both MSVC and MinGW rust libraries will output static libs with
514   dnl the MSVC naming convention.
515   if test "$bwin32" = "true"; then
516     tor_rust_static_name=tor_rust.lib
517   else
518     tor_rust_static_name=libtor_rust.a
519   fi
521   AC_CANONICAL_BUILD
523   if test -n "$TOR_RUST_TARGET"; then
524     if test "$host" = "$build"; then
525       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
526     fi
527     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
528     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
529   else
530     if test "$host" != "$build"; then
531       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
532     fi
533     RUST_TARGET_PROP=
534     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
535   fi
537   AC_SUBST(RUST_TARGET_PROP)
538   AC_SUBST(TOR_RUST_LIB_PATH)
539   AC_SUBST(CARGO_ONLINE)
540   AC_SUBST(RUST_WARN)
541   AC_SUBST(RUST_DL)
543   dnl Let's check the rustc version, too
544   AC_MSG_CHECKING([rust version])
545   RUSTC_VERSION=`$RUSTC --version`
546   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
547   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
548   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
549     AC_MSG_ERROR([rustc version couldn't be identified])
550   fi
551   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
552     AC_MSG_ERROR([rustc must be at least version 1.14])
553   fi
554   AC_MSG_RESULT([$RUSTC_VERSION])
557 AC_SUBST(TOR_RUST_EXTRA_LIBS)
559 AC_SEARCH_LIBS(socket, [socket network])
560 AC_SEARCH_LIBS(gethostbyname, [nsl])
561 AC_SEARCH_LIBS(dlopen, [dl])
562 AC_SEARCH_LIBS(inet_aton, [resolv])
563 AC_SEARCH_LIBS(backtrace, [execinfo])
564 saved_LIBS="$LIBS"
565 AC_SEARCH_LIBS([clock_gettime], [rt])
566 if test "$LIBS" != "$saved_LIBS"; then
567    # Looks like we need -lrt for clock_gettime().
568    have_rt=yes
571 if test "$bwin32" = "false"; then
572   AC_SEARCH_LIBS(pthread_create, [pthread])
573   AC_SEARCH_LIBS(pthread_detach, [pthread])
576 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
577 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
579 AC_CHECK_FUNCS(
580         _NSGetEnviron \
581         RtlSecureZeroMemory \
582         SecureZeroMemory \
583         accept4 \
584         backtrace \
585         backtrace_symbols_fd \
586         eventfd \
587         explicit_bzero \
588         timingsafe_memcmp \
589         flock \
590         ftime \
591         get_current_dir_name \
592         getaddrinfo \
593         getdelim \
594         getifaddrs \
595         getline \
596         getpass \
597         getrlimit \
598         gettimeofday \
599         gmtime_r \
600         gnu_get_libc_version \
601         htonll \
602         inet_aton \
603         ioctl \
604         issetugid \
605         llround \
606         localtime_r \
607         lround \
608         memmem \
609         memset_s \
610         mmap \
611         pipe \
612         pipe2 \
613         prctl \
614         readpassphrase \
615         rint \
616         sigaction \
617         socketpair \
618         statvfs \
619         strncasecmp \
620         strcasecmp \
621         strlcat \
622         strlcpy \
623         strnlen \
624         strptime \
625         strtok_r \
626         strtoull \
627         sysconf \
628         sysctl \
629         truncate \
630         uname \
631         usleep \
632         vasprintf \
633         _vscprintf
636 # Apple messed up when they added some functions: they
637 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
638 # checks.
640 # We should only probe for these functions if we are sure that we
641 # are not targeting OS X 10.9 or earlier.
642 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
643 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
644 #ifdef __APPLE__
645 #  include <AvailabilityMacros.h>
646 #  ifndef MAC_OS_X_VERSION_10_10
647 #    define MAC_OS_X_VERSION_10_10 101000
648 #  endif
649 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
650 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
651 #      error "Running on Mac OS X 10.9 or earlier"
652 #    endif
653 #  endif
654 #endif
655 ]], [[]])],
656    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
657    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
659 if test "$on_macos_pre_10_10" = "no"; then
660   AC_CHECK_FUNCS(
661         mach_approximate_time \
662   )
665 # We should only probe for these functions if we are sure that we
666 # are not targeting OSX 10.11 or earlier.
667 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
668 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
669 #ifdef __APPLE__
670 #  include <AvailabilityMacros.h>
671 #  ifndef MAC_OS_X_VERSION_10_12
672 #    define MAC_OS_X_VERSION_10_12 101200
673 #  endif
674 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
675 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
676 #      error "Running on Mac OSX 10.11 or earlier"
677 #    endif
678 #  endif
679 #endif
680 ]], [[]])],
681    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
682    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
684 if test "$on_macos_pre_10_12" = "no"; then
685   AC_CHECK_FUNCS(
686         clock_gettime \
687         getentropy \
688   )
691 if test "$bwin32" != "true"; then
692   AC_CHECK_HEADERS(pthread.h)
693   AC_CHECK_FUNCS(pthread_create)
694   AC_CHECK_FUNCS(pthread_condattr_setclock)
697 if test "$bwin32" = "true"; then
698   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
699 #include <windows.h>
700 #include <conio.h>
701 #include <wchar.h>
702                  ])
705 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
706   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
708 AC_MSG_CHECKING([whether free(NULL) works])
709 AC_RUN_IFELSE([AC_LANG_PROGRAM([
710   #include <stdlib.h>
711 ], [
712 char *p = NULL;
713 free(p);
714 ])],
715 [free_null_ok=true; AC_MSG_RESULT(yes)],
716 [free_null_ok=false; AC_MSG_RESULT(no)],
717 [free_null_ok=cross; AC_MSG_RESULT(cross)])
719 if test "$free_null_ok" = "false"; then
720    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
723 dnl ------------------------------------------------------
724 dnl Where do you live, libevent?  And how do we call you?
726 if test "$bwin32" = "true"; then
727   TOR_LIB_WS32=-lws2_32
728   TOR_LIB_IPHLPAPI=-liphlpapi
729   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
730   # think it's actually necessary.
731   TOR_LIB_GDI=-lgdi32
732   TOR_LIB_USERENV=-luserenv
733 else
734   TOR_LIB_WS32=
735   TOR_LIB_GDI=
736   TOR_LIB_USERENV=
738 AC_SUBST(TOR_LIB_WS32)
739 AC_SUBST(TOR_LIB_GDI)
740 AC_SUBST(TOR_LIB_IPHLPAPI)
741 AC_SUBST(TOR_LIB_USERENV)
743 tor_libevent_pkg_redhat="libevent"
744 tor_libevent_pkg_debian="libevent-dev"
745 tor_libevent_devpkg_redhat="libevent-devel"
746 tor_libevent_devpkg_debian="libevent-dev"
748 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
749 dnl linking for static builds.
750 STATIC_LIBEVENT_FLAGS=""
751 if test "$enable_static_libevent" = "yes"; then
752     if test "$have_rt" = "yes"; then
753       STATIC_LIBEVENT_FLAGS=" -lrt "
754     fi
757 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
758 #ifdef _WIN32
759 #include <winsock2.h>
760 #endif
761 #include <sys/time.h>
762 #include <sys/types.h>
763 #include <event2/event.h>], [
764 #ifdef _WIN32
765 #include <winsock2.h>
766 #endif
767 struct event_base;
768 struct event_base *event_base_new(void);
769 void event_base_free(struct event_base *);],
770     [
771 #ifdef _WIN32
772 {WSADATA d; WSAStartup(0x101,&d); }
773 #endif
774 event_base_free(event_base_new());
775 ], [--with-libevent-dir], [/opt/libevent])
777 dnl Determine the incantation needed to link libevent.
778 save_LIBS="$LIBS"
779 save_LDFLAGS="$LDFLAGS"
780 save_CPPFLAGS="$CPPFLAGS"
782 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
783 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
784 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
786 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
788 if test "$enable_static_libevent" = "yes"; then
789    if test "$tor_cv_library_libevent_dir" = "(system)"; then
790      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
791    else
792      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
793    fi
794 else
795      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
796        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
797        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"))
799        if test "$ac_cv_search_event_new" != "none required"; then
800          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
801        fi
802        if test "$ac_cv_search_evdns_base_new" != "none required"; then
803          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
804        fi
805      else
806        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
807      fi
810 dnl Now check for particular libevent functions.
811 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
812                 evutil_secure_rng_add_bytes \
815 LIBS="$save_LIBS"
816 LDFLAGS="$save_LDFLAGS"
817 CPPFLAGS="$save_CPPFLAGS"
819 dnl Check that libevent is at least at version 2.0.10, the first stable
820 dnl release of its series
821 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
822 AC_MSG_CHECKING([whether Libevent is new enough])
823 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
824 #include <event2/event.h>
825 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
826 #error
827 int x = y(zz);
828 #else
829 int x = 1;
830 #endif
831 ])], [ AC_MSG_RESULT([yes]) ],
832    [ AC_MSG_RESULT([no])
833      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
835 LIBS="$save_LIBS"
836 LDFLAGS="$save_LDFLAGS"
837 CPPFLAGS="$save_CPPFLAGS"
839 AC_SUBST(TOR_LIBEVENT_LIBS)
841 dnl ------------------------------------------------------
842 dnl Where do you live, libm?
844 dnl On some platforms (Haiku/BeOS) the math library is
845 dnl part of libroot. In which case don't link against lm
846 TOR_LIB_MATH=""
847 save_LIBS="$LIBS"
848 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
849 if test "$ac_cv_search_pow" != "none required"; then
850     TOR_LIB_MATH="$ac_cv_search_pow"
852 LIBS="$save_LIBS"
853 AC_SUBST(TOR_LIB_MATH)
855 dnl ------------------------------------------------------
856 dnl Hello, NSS.  You're new around here.
857 if test "x$enable_nss" = "xyes"; then
858   PKG_CHECK_MODULES(NSS,
859      [nss],
860      [have_nss=yes],
861      [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it.])])
862   AC_SUBST(NSS_CFLAGS)
863   AC_SUBST(NSS_LIBS)
866 dnl ------------------------------------------------------
867 dnl Where do you live, openssl?  And how do we call you?
869 if test "x$enable_nss" != "xyes"; then
871 tor_openssl_pkg_redhat="openssl"
872 tor_openssl_pkg_debian="libssl-dev"
873 tor_openssl_devpkg_redhat="openssl-devel"
874 tor_openssl_devpkg_debian="libssl-dev"
876 ALT_openssl_WITHVAL=""
877 AC_ARG_WITH(ssl-dir,
878   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
879   [
880       if test "x$withval" != "xno" && test "x$withval" != "x"; then
881          ALT_openssl_WITHVAL="$withval"
882       fi
883   ])
885 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
886 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
887     [#include <openssl/ssl.h>
888      char *getenv(const char *);],
889     [struct ssl_cipher_st;
890      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
891      char *getenv(const char *);],
892     dnl This funny-looking test program calls getenv, so that the compiler
893     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
894     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
895     dnl We look for SSL_cipher_get_id() because it is present in
896     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
897     dnl depends on it.
898     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
899     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
901 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
903 if test "$enable_static_openssl" = "yes"; then
904    if test "$tor_cv_library_openssl_dir" = "(system)"; then
905      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
906    else
907      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
908    fi
909 else
910      TOR_OPENSSL_LIBS="-lssl -lcrypto"
912 AC_SUBST(TOR_OPENSSL_LIBS)
914 dnl Now check for particular openssl functions.
915 save_LIBS="$LIBS"
916 save_LDFLAGS="$LDFLAGS"
917 save_CPPFLAGS="$CPPFLAGS"
918 LIBS="$TOR_OPENSSL_LIBS $LIBS"
919 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
920 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
922 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
923 #include <openssl/opensslv.h>
924 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
925 #error "too old"
926 #endif
927    ]], [[]])],
928    [ : ],
929    [ 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.]) ])
931 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
932 #include <openssl/opensslv.h>
933 #include <openssl/evp.h>
934 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
935 #error "no ECC"
936 #endif
937 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
938 #error "curves unavailable"
939 #endif
940    ]], [[]])],
941    [ : ],
942    [ 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.]) ])
944 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
945 [#include <openssl/ssl.h>
948 AC_CHECK_FUNCS([ \
949                 ERR_load_KDF_strings \
950                 SSL_SESSION_get_master_key \
951                 SSL_get_server_random \
952                 SSL_get_client_ciphers \
953                 SSL_get_client_random \
954                 SSL_CIPHER_find \
955                 SSL_CTX_set_security_level \
956                 TLS_method
957                ])
959 dnl Check if OpenSSL has scrypt implementation.
960 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
962 dnl Check if OpenSSL structures are opaque
963 AC_CHECK_MEMBERS([SSL.state], , ,
964 [#include <openssl/ssl.h>
967 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
968 #include <openssl/sha.h>
971 fi # enable_nss
973 dnl ======================================================================
974 dnl Can we use KIST?
976 dnl Define the set of checks for KIST scheduler support.
977 AC_DEFUN([CHECK_KIST_SUPPORT],[
978   dnl KIST needs struct tcp_info and for certain members to exist.
979   AC_CHECK_MEMBERS(
980     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
981     , ,[[#include <netinet/tcp.h>]])
982   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
983   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
984                      #include <linux/sockios.h>
985                      #ifndef SIOCOUTQNSD
986                      #error
987                      #endif
988                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
989   if test "x$have_siocoutqnsd" = "xyes"; then
990     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
991       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
992         have_kist_support=yes
993       fi
994     fi
995   fi
997 dnl Now, trigger the check.
998 CHECK_KIST_SUPPORT
999 AS_IF([test "x$have_kist_support" = "xyes"],
1000       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1001                                         on this system])],
1002       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1004 LIBS="$save_LIBS"
1005 LDFLAGS="$save_LDFLAGS"
1006 CPPFLAGS="$save_CPPFLAGS"
1008 dnl ------------------------------------------------------
1009 dnl Where do you live, zlib?  And how do we call you?
1011 tor_zlib_pkg_redhat="zlib"
1012 tor_zlib_pkg_debian="zlib1g"
1013 tor_zlib_devpkg_redhat="zlib-devel"
1014 tor_zlib_devpkg_debian="zlib1g-dev"
1016 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1017     [#include <zlib.h>],
1018     [const char * zlibVersion(void);],
1019     [zlibVersion();], [--with-zlib-dir],
1020     [/opt/zlib])
1022 if test "$enable_static_zlib" = "yes"; then
1023    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1024      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1025  using --enable-static-zlib")
1026    else
1027      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1028    fi
1029 else
1030      TOR_ZLIB_LIBS="-lz"
1032 AC_SUBST(TOR_ZLIB_LIBS)
1034 dnl ------------------------------------------------------
1035 dnl Where we do we find lzma?
1037 AC_ARG_ENABLE(lzma,
1038       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1039       [case "${enableval}" in
1040         "yes") lzma=true ;;
1041         "no")  lzma=false ;;
1042         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1043       esac], [lzma=auto])
1045 if test "x$enable_lzma" = "xno"; then
1046     have_lzma=no;
1047 else
1048     PKG_CHECK_MODULES([LZMA],
1049                       [liblzma],
1050                       have_lzma=yes,
1051                       have_lzma=no)
1053     if test "x$have_lzma" = "xno" ; then
1054         AC_MSG_WARN([Unable to find liblzma.])
1055     fi
1058 if test "x$have_lzma" = "xyes"; then
1059     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1060     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1061     TOR_LZMA_LIBS="${LZMA_LIBS}"
1063 AC_SUBST(TOR_LZMA_CFLAGS)
1064 AC_SUBST(TOR_LZMA_LIBS)
1066 dnl ------------------------------------------------------
1067 dnl Where we do we find zstd?
1069 AC_ARG_ENABLE(zstd,
1070       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1071       [case "${enableval}" in
1072         "yes") zstd=true ;;
1073         "no")  zstd=false ;;
1074         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1075       esac], [zstd=auto])
1077 if test "x$enable_zstd" = "xno"; then
1078     have_zstd=no;
1079 else
1080     PKG_CHECK_MODULES([ZSTD],
1081                       [libzstd >= 1.1],
1082                       have_zstd=yes,
1083                       have_zstd=no)
1085     if test "x$have_zstd" = "xno" ; then
1086         AC_MSG_WARN([Unable to find libzstd.])
1087     fi
1090 if test "x$have_zstd" = "xyes"; then
1091     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1092     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1093     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1095     dnl now check for zstd functions
1096     save_LIBS="$LIBS"
1097     save_CFLAGS="$CFLAGS"
1098     LIBS="$LIBS $ZSTD_LIBS"
1099     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1100     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1101                    ZSTD_estimateDCtxSize)
1102     LIBS="$save_LIBS"
1103     CFLAGS="$save_CFLAGS"
1105 AC_SUBST(TOR_ZSTD_CFLAGS)
1106 AC_SUBST(TOR_ZSTD_LIBS)
1108 dnl ----------------------------------------------------------------------
1109 dnl Check if libcap is available for capabilities.
1111 tor_cap_pkg_debian="libcap2"
1112 tor_cap_pkg_redhat="libcap"
1113 tor_cap_devpkg_debian="libcap-dev"
1114 tor_cap_devpkg_redhat="libcap-devel"
1116 AC_CHECK_LIB([cap], [cap_init], [],
1117   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1119 AC_CHECK_FUNCS(cap_set_proc)
1121 dnl ---------------------------------------------------------------------
1122 dnl Now that we know about our major libraries, we can check for compiler
1123 dnl and linker hardening options.  We need to do this with the libraries known,
1124 dnl since sometimes the linker will like an option but not be willing to
1125 dnl use it with a build of a library.
1127 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1128 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"
1130 CFLAGS_FTRAPV=
1131 CFLAGS_FWRAPV=
1132 CFLAGS_ASAN=
1133 CFLAGS_UBSAN=
1136 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1137 #if !defined(__clang__)
1138 #error
1139 #endif])], have_clang=yes, have_clang=no)
1141 if test "x$enable_gcc_hardening" != "xno"; then
1142     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1143     if test "x$have_clang" = "xyes"; then
1144         TOR_CHECK_CFLAGS(-Qunused-arguments)
1145     fi
1146     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1147     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1148     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1149 m4_ifdef([AS_VAR_IF],[
1150     AS_VAR_IF(can_compile, [yes],
1151         AS_VAR_IF(can_link, [yes],
1152                   [],
1153                   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.)]))
1154         )])
1155     AS_VAR_POPDEF([can_link])
1156     AS_VAR_POPDEF([can_compile])
1157     TOR_CHECK_CFLAGS(-Wstack-protector)
1158     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1159     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1160        TOR_CHECK_CFLAGS(-fPIE)
1161        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1162     fi
1163     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1166 if test "$fragile_hardening" = "yes"; then
1167     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1168    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1169       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.])
1170    fi
1172    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1173      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1174    fi
1176    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1177     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1178       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*])
1179     fi
1181    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1182     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1183       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*])
1184     fi
1186 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1189 dnl Find the correct libraries to add in order to use the sanitizers.
1191 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1192 dnl option, which will prevent the compiler from linking the sanitizer
1193 dnl libraries it needs.  We need to specify them manually.
1195 dnl What's more, we need to specify them in a linker script rather than
1196 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1197 dnl variable.
1198 RUST_LINKER_OPTIONS=""
1199 if test "x$have_clang" = "xyes"; then
1200         if test "x$CFLAGS_ASAN" != "x"; then
1201                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_ASAN"
1202         fi
1203         if test "x$CFLAGS_UBSAN" != "x"; then
1204                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_UBSAN"
1205         fi
1206 else
1207         if test "x$CFLAGS_ASAN" != "x"; then
1208                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lasan"
1209         fi
1210         if test "x$CFLAGS_UBSAN" != "x"; then
1211                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lubsan"
1212         fi
1214 AC_SUBST(RUST_LINKER_OPTIONS)
1216 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1217 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1219 mulodi_fixes_ftrapv=no
1220 if test "$have_clang" = "yes"; then
1221   saved_CFLAGS="$CFLAGS"
1222   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1223   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1224   AC_LINK_IFELSE([
1225       AC_LANG_SOURCE([[
1226           #include <stdint.h>
1227           #include <stdlib.h>
1228           int main(int argc, char **argv)
1229           {
1230             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1231                         * (int64_t)atoi(argv[3]);
1232             return x == 9;
1233           } ]])],
1234           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1235           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1236   if test "$ftrapv_can_link" = "no"; then
1237     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1238     AC_LINK_IFELSE([
1239       AC_LANG_SOURCE([[
1240           #include <stdint.h>
1241           #include <stdlib.h>
1242           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1243              *overflow=0;
1244              return a;
1245           }
1246           int main(int argc, char **argv)
1247           {
1248             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1249                         * (int64_t)atoi(argv[3]);
1250             return x == 9;
1251           } ]])],
1252           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1253           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1254   fi
1255   CFLAGS="$saved_CFLAGS"
1258 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1260 dnl These cflags add bunches of branches, and we haven't been able to
1261 dnl persuade ourselves that they're suitable for code that needs to be
1262 dnl constant time.
1263 AC_SUBST(CFLAGS_BUGTRAP)
1264 dnl These cflags are variant ones sutable for code that needs to be
1265 dnl constant-time.
1266 AC_SUBST(CFLAGS_CONSTTIME)
1268 if test "x$enable_linker_hardening" != "xno"; then
1269     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1272 # For backtrace support
1273 TOR_CHECK_LDFLAGS(-rdynamic)
1275 dnl ------------------------------------------------------
1276 dnl Now see if we have a -fomit-frame-pointer compiler option.
1278 saved_CFLAGS="$CFLAGS"
1279 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1280 F_OMIT_FRAME_POINTER=''
1281 if test "$saved_CFLAGS" != "$CFLAGS"; then
1282   if test "$fragile_hardening" = "yes"; then
1283     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1284   fi
1286 CFLAGS="$saved_CFLAGS"
1287 AC_SUBST(F_OMIT_FRAME_POINTER)
1289 dnl ------------------------------------------------------
1290 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1291 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1292 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1293 dnl code will work.
1294 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1296 dnl ============================================================
1297 dnl Check for libseccomp
1299 if test "x$enable_seccomp" != "xno"; then
1300   AC_CHECK_HEADERS([seccomp.h])
1301   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1304 dnl ============================================================
1305 dnl Check for libscrypt
1307 if test "x$enable_libscrypt" != "xno"; then
1308   AC_CHECK_HEADERS([libscrypt.h])
1309   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1310   AC_CHECK_FUNCS([libscrypt_scrypt])
1313 dnl ============================================================
1314 dnl We need an implementation of curve25519.
1316 dnl set these defaults.
1317 build_curve25519_donna=no
1318 build_curve25519_donna_c64=no
1319 use_curve25519_donna=no
1320 use_curve25519_nacl=no
1321 CURVE25519_LIBS=
1323 dnl The best choice is using curve25519-donna-c64, but that requires
1324 dnl that we
1325 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1326   tor_cv_can_use_curve25519_donna_c64,
1327   [AC_RUN_IFELSE(
1328     [AC_LANG_PROGRAM([dnl
1329       #include <stdint.h>
1330       typedef unsigned uint128_t __attribute__((mode(TI)));
1331   int func(uint64_t a, uint64_t b) {
1332            uint128_t c = ((uint128_t)a) * b;
1333            int ok = ((uint64_t)(c>>96)) == 522859 &&
1334              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1335                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1336                  (((uint64_t)(c))&0xffffffffL) == 0;
1337            return ok;
1338       }
1339   ], [dnl
1340     int ok = func( ((uint64_t)2000000000) * 1000000000,
1341                    ((uint64_t)1234567890) << 24);
1342         return !ok;
1343       ])],
1344   [tor_cv_can_use_curve25519_donna_c64=yes],
1345       [tor_cv_can_use_curve25519_donna_c64=no],
1346   [AC_LINK_IFELSE(
1347         [AC_LANG_PROGRAM([dnl
1348       #include <stdint.h>
1349       typedef unsigned uint128_t __attribute__((mode(TI)));
1350   int func(uint64_t a, uint64_t b) {
1351            uint128_t c = ((uint128_t)a) * b;
1352            int ok = ((uint64_t)(c>>96)) == 522859 &&
1353              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1354                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1355                  (((uint64_t)(c))&0xffffffffL) == 0;
1356            return ok;
1357       }
1358   ], [dnl
1359     int ok = func( ((uint64_t)2000000000) * 1000000000,
1360                  ((uint64_t)1234567890) << 24);
1361         return !ok;
1362       ])],
1363           [tor_cv_can_use_curve25519_donna_c64=cross],
1364       [tor_cv_can_use_curve25519_donna_c64=no])])])
1366 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1367                   nacl/crypto_scalarmult_curve25519.h])
1369 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1370   tor_cv_can_use_curve25519_nacl,
1371   [tor_saved_LIBS="$LIBS"
1372    LIBS="$LIBS -lnacl"
1373    AC_LINK_IFELSE(
1374      [AC_LANG_PROGRAM([dnl
1375        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1376        #include <crypto_scalarmult_curve25519.h>
1377    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1378    #include <nacl/crypto_scalarmult_curve25519.h>
1379    #endif
1380        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1381    #error Hey, this is the reference implementation! That's not fast.
1382    #endif
1383      ], [
1384    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1385      ])], [tor_cv_can_use_curve25519_nacl=yes],
1386      [tor_cv_can_use_curve25519_nacl=no])
1387    LIBS="$tor_saved_LIBS" ])
1389  dnl Okay, now we need to figure out which one to actually use. Fall back
1390  dnl to curve25519-donna.c
1392  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1393    build_curve25519_donna_c64=yes
1394    use_curve25519_donna=yes
1395  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1396    use_curve25519_nacl=yes
1397    CURVE25519_LIBS=-lnacl
1398  else
1399    build_curve25519_donna=yes
1400    use_curve25519_donna=yes
1401  fi
1403 if test "x$use_curve25519_donna" = "xyes"; then
1404   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1405             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1407 if test "x$use_curve25519_nacl" = "xyes"; then
1408   AC_DEFINE(USE_CURVE25519_NACL, 1,
1409             [Defined if we should use a curve25519 from nacl])
1411 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1412   test "x$build_curve25519_donna" = "xyes")
1413 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1414   test "x$build_curve25519_donna_c64" = "xyes")
1415 AC_SUBST(CURVE25519_LIBS)
1417 dnl Make sure to enable support for large off_t if available.
1418 AC_SYS_LARGEFILE
1420 AC_CHECK_HEADERS([errno.h \
1421                   fcntl.h \
1422                   signal.h \
1423                   string.h \
1424                   sys/capability.h \
1425                   sys/fcntl.h \
1426                   sys/stat.h \
1427                   sys/time.h \
1428                   sys/types.h \
1429                   time.h \
1430                   unistd.h \
1431                   arpa/inet.h \
1432                   crt_externs.h \
1433                   execinfo.h \
1434                   gnu/libc-version.h \
1435                   grp.h \
1436                   ifaddrs.h \
1437                   inttypes.h \
1438                   limits.h \
1439                   linux/types.h \
1440                   machine/limits.h \
1441                   malloc.h \
1442                   malloc/malloc.h \
1443                   malloc_np.h \
1444                   netdb.h \
1445                   netinet/in.h \
1446                   netinet/in6.h \
1447                   pwd.h \
1448                   readpassphrase.h \
1449                   stdatomic.h \
1450                   sys/eventfd.h \
1451                   sys/file.h \
1452                   sys/ioctl.h \
1453                   sys/limits.h \
1454                   sys/mman.h \
1455                   sys/param.h \
1456                   sys/prctl.h \
1457                   sys/random.h \
1458                   sys/resource.h \
1459                   sys/select.h \
1460                   sys/socket.h \
1461                   sys/statvfs.h \
1462                   sys/syscall.h \
1463                   sys/sysctl.h \
1464                   sys/syslimits.h \
1465                   sys/time.h \
1466                   sys/types.h \
1467                   sys/un.h \
1468                   sys/utime.h \
1469                   sys/wait.h \
1470                   syslog.h \
1471                   utime.h])
1473 AC_CHECK_HEADERS(sys/param.h)
1475 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1476 [#ifdef HAVE_SYS_TYPES_H
1477 #include <sys/types.h>
1478 #endif
1479 #ifdef HAVE_SYS_SOCKET_H
1480 #include <sys/socket.h>
1481 #endif])
1482 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1483 [#ifdef HAVE_SYS_TYPES_H
1484 #include <sys/types.h>
1485 #endif
1486 #ifdef HAVE_SYS_SOCKET_H
1487 #include <sys/socket.h>
1488 #endif
1489 #ifdef HAVE_NET_IF_H
1490 #include <net/if.h>
1491 #endif
1492 #ifdef HAVE_NETINET_IN_H
1493 #include <netinet/in.h>
1494 #endif])
1496 AC_CHECK_HEADERS(linux/if.h,[],[],
1498 #ifdef HAVE_SYS_SOCKET_H
1499 #include <sys/socket.h>
1500 #endif
1503 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1504         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1505 [#ifdef HAVE_SYS_TYPES_H
1506 #include <sys/types.h>
1507 #endif
1508 #ifdef HAVE_SYS_SOCKET_H
1509 #include <sys/socket.h>
1510 #endif
1511 #ifdef HAVE_LIMITS_H
1512 #include <limits.h>
1513 #endif
1514 #ifdef HAVE_LINUX_TYPES_H
1515 #include <linux/types.h>
1516 #endif
1517 #ifdef HAVE_NETINET_IN6_H
1518 #include <netinet/in6.h>
1519 #endif
1520 #ifdef HAVE_NETINET_IN_H
1521 #include <netinet/in.h>
1522 #endif])
1524 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1525         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1526 [#ifdef HAVE_SYS_TYPES_H
1527 #include <sys/types.h>
1528 #endif
1529 #ifdef HAVE_SYS_SOCKET_H
1530 #include <sys/socket.h>
1531 #endif
1532 #ifdef HAVE_LIMITS_H
1533 #include <limits.h>
1534 #endif
1535 #ifdef HAVE_LINUX_TYPES_H
1536 #include <linux/types.h>
1537 #endif
1538 #ifdef HAVE_NETINET_IN6_H
1539 #include <netinet/in6.h>
1540 #endif
1541 #ifdef HAVE_NETINET_IN_H
1542 #include <netinet/in.h>
1543 #endif
1544 #ifdef HAVE_LINUX_IF_H
1545 #include <linux/if.h>
1546 #endif])
1548 transparent_ok=0
1549 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1550   transparent_ok=1
1552 if test "x$linux_netfilter_ipv4" = "x1"; then
1553   transparent_ok=1
1555 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1556   transparent_ok=1
1558 if test "x$transparent_ok" = "x1"; then
1559   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1560 else
1561   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1564 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1565 [#ifdef HAVE_SYS_TYPES_H
1566 #include <sys/types.h>
1567 #endif
1568 #ifdef HAVE_SYS_TIME_H
1569 #include <sys/time.h>
1570 #endif])
1572 AC_CHECK_SIZEOF(char)
1573 AC_CHECK_SIZEOF(short)
1574 AC_CHECK_SIZEOF(int)
1575 AC_CHECK_SIZEOF(long)
1576 AC_CHECK_SIZEOF(long long)
1577 AC_CHECK_SIZEOF(__int64)
1578 AC_CHECK_SIZEOF(void *)
1579 AC_CHECK_SIZEOF(time_t)
1580 AC_CHECK_SIZEOF(size_t)
1581 AC_CHECK_SIZEOF(pid_t)
1583 AC_CHECK_TYPES([uint, u_char, ssize_t])
1585 AC_PC_FROM_UCONTEXT([:])
1587 dnl used to include sockaddr_storage, but everybody has that.
1588 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1589 [#ifdef HAVE_SYS_TYPES_H
1590 #include <sys/types.h>
1591 #endif
1592 #ifdef HAVE_NETINET_IN_H
1593 #include <netinet/in.h>
1594 #endif
1595 #ifdef HAVE_NETINET_IN6_H
1596 #include <netinet/in6.h>
1597 #endif
1598 #ifdef HAVE_SYS_SOCKET_H
1599 #include <sys/socket.h>
1600 #endif
1601 #ifdef _WIN32
1602 #define _WIN32_WINNT 0x0501
1603 #define WIN32_LEAN_AND_MEAN
1604 #include <winsock2.h>
1605 #include <ws2tcpip.h>
1606 #endif
1608 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1609 [#ifdef HAVE_SYS_TYPES_H
1610 #include <sys/types.h>
1611 #endif
1612 #ifdef HAVE_NETINET_IN_H
1613 #include <netinet/in.h>
1614 #endif
1615 #ifdef HAVE_NETINET_IN6_H
1616 #include <netinet/in6.h>
1617 #endif
1618 #ifdef HAVE_SYS_SOCKET_H
1619 #include <sys/socket.h>
1620 #endif
1621 #ifdef _WIN32
1622 #define _WIN32_WINNT 0x0501
1623 #define WIN32_LEAN_AND_MEAN
1624 #include <winsock2.h>
1625 #include <ws2tcpip.h>
1626 #endif
1629 AC_CHECK_TYPES([rlim_t], , ,
1630 [#ifdef HAVE_SYS_TYPES_H
1631 #include <sys/types.h>
1632 #endif
1633 #ifdef HAVE_SYS_TIME_H
1634 #include <sys/time.h>
1635 #endif
1636 #ifdef HAVE_SYS_RESOURCE_H
1637 #include <sys/resource.h>
1638 #endif
1641 AX_CHECK_SIGN([time_t],
1642        [ : ],
1643        [ : ], [
1644 #ifdef HAVE_SYS_TYPES_H
1645 #include <sys/types.h>
1646 #endif
1647 #ifdef HAVE_SYS_TIME_H
1648 #include <sys/time.h>
1649 #endif
1650 #ifdef HAVE_TIME_H
1651 #include <time.h>
1652 #endif
1655 if test "$ax_cv_decl_time_t_signed" = "no"; then
1656   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1659 AX_CHECK_SIGN([size_t],
1660        [ tor_cv_size_t_signed=yes ],
1661        [ tor_cv_size_t_signed=no ], [
1662 #ifdef HAVE_SYS_TYPES_H
1663 #include <sys/types.h>
1664 #endif
1667 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1668   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1671 AX_CHECK_SIGN([enum always],
1672        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1673        [ : ], [
1674  enum always { AAA, BBB, CCC };
1677 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1678 #ifdef HAVE_SYS_SOCKET_H
1679 #include <sys/socket.h>
1680 #endif
1683 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1685 AC_CHECK_SIZEOF(cell_t)
1687 # Let's see if stdatomic works. (There are some debian clangs that screw it
1688 # up; see Tor bug #26779 and debian bug 903709.)
1689 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1690                tor_cv_stdatomic_works,
1691 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1692 #include <stdatomic.h>
1693 struct x { atomic_size_t y; };
1694 void try_atomic_init(struct x *xx)
1696   atomic_init(&xx->y, 99);
1697   atomic_fetch_add(&xx->y, 1);
1699 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1701 if test "$tor_cv_stdatomic_works" = "yes"; then
1702    AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1703 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1704    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 ])
1707 # Now make sure that NULL can be represented as zero bytes.
1708 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1709 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1710 [[#include <stdlib.h>
1711 #include <string.h>
1712 #include <stdio.h>
1713 #ifdef HAVE_STDDEF_H
1714 #include <stddef.h>
1715 #endif
1716 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1717 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1718        [tor_cv_null_is_zero=yes],
1719        [tor_cv_null_is_zero=no],
1720        [tor_cv_null_is_zero=cross])])
1722 if test "$tor_cv_null_is_zero" = "cross"; then
1723   # Cross-compiling; let's hope that the target isn't raving mad.
1724   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1727 if test "$tor_cv_null_is_zero" != "no"; then
1728   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1729             [Define to 1 iff memset(0) sets pointers to NULL])
1732 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1733 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1734 [[#include <stdlib.h>
1735 #include <string.h>
1736 #include <stdio.h>
1737 #ifdef HAVE_STDDEF_H
1738 #include <stddef.h>
1739 #endif
1740 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1741 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1742        [tor_cv_dbl0_is_zero=yes],
1743        [tor_cv_dbl0_is_zero=no],
1744        [tor_cv_dbl0_is_zero=cross])])
1746 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1747   # Cross-compiling; let's hope that the target isn't raving mad.
1748   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1751 if test "$tor_cv_dbl0_is_zero" != "no"; then
1752   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1753             [Define to 1 iff memset(0) sets doubles to 0.0])
1756 # And what happens when we malloc zero?
1757 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1758 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1759 [[#include <stdlib.h>
1760 #include <string.h>
1761 #include <stdio.h>
1762 #ifdef HAVE_STDDEF_H
1763 #include <stddef.h>
1764 #endif
1765 int main () { return malloc(0)?0:1; }]])],
1766        [tor_cv_malloc_zero_works=yes],
1767        [tor_cv_malloc_zero_works=no],
1768        [tor_cv_malloc_zero_works=cross])])
1770 if test "$tor_cv_malloc_zero_works" = "cross"; then
1771   # Cross-compiling; let's hope that the target isn't raving mad.
1772   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1775 if test "$tor_cv_malloc_zero_works" = "yes"; then
1776   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1777             [Define to 1 iff malloc(0) returns a pointer])
1780 # whether we seem to be in a 2s-complement world.
1781 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1782 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1783 [[int main () { int problem = ((-99) != (~99)+1);
1784 return problem ? 1 : 0; }]])],
1785        [tor_cv_twos_complement=yes],
1786        [tor_cv_twos_complement=no],
1787        [tor_cv_twos_complement=cross])])
1789 if test "$tor_cv_twos_complement" = "cross"; then
1790   # Cross-compiling; let's hope that the target isn't raving mad.
1791   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1794 if test "$tor_cv_twos_complement" != "no"; then
1795   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1796             [Define to 1 iff we represent negative integers with
1797              two's complement])
1800 # What does shifting a negative value do?
1801 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1802 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1803 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1804        [tor_cv_sign_extend=yes],
1805        [tor_cv_sign_extend=no],
1806        [tor_cv_sign_extend=cross])])
1808 if test "$tor_cv_sign_extend" = "cross"; then
1809   # Cross-compiling; let's hope that the target isn't raving mad.
1810   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1813 if test "$tor_cv_sign_extend" != "no"; then
1814   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1815             [Define to 1 iff right-shifting a negative value performs sign-extension])
1818 # Is uint8_t the same type as unsigned char?
1819 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1820 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1821 #include <stdint.h>
1822 extern uint8_t c;
1823 unsigned char c;]])],
1824        [tor_cv_uint8_uchar=yes],
1825        [tor_cv_uint8_uchar=no],
1826        [tor_cv_uint8_uchar=cross])])
1828 if test "$tor_cv_uint8_uchar" = "cross"; then
1829   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1832 if test "$tor_cv_uint8_uchar" = "no"; then
1833   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1836 AC_ARG_WITH(tcmalloc,
1837 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]),
1838 [ tcmalloc=yes ], [ tcmalloc=no ])
1840 default_malloc=system
1842 if test "x$enable_openbsd_malloc" = "xyes" ; then
1843   AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
1844   default_malloc=openbsd
1847 if test "x$tcmalloc" = "xyes"; then
1848   AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
1849   default_malloc=tcmalloc
1852 AC_ARG_WITH(malloc,
1853    AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
1854                   [select special malloc implementation [system]]),
1855    [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
1857 AS_CASE([$malloc],
1858   [tcmalloc], [
1859       PKG_CHECK_MODULES([TCMALLOC],
1860                         [libtcmalloc],
1861                         have_tcmalloc=yes,
1862                         have_tcmalloc=no)
1864       if test "x$have_tcmalloc" = "xno" ; then
1865           AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc.])
1866       fi
1868       CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
1869       LIBS="$TCMALLOC_LIBS $LIBS"
1870   ],
1872   [jemalloc], [
1873       PKG_CHECK_MODULES([JEMALLOC],
1874                         [jemalloc],
1875                         have_jemalloc=yes,
1876                         have_jemalloc=no)
1878       if test "x$have_tcmalloc" = "xno" ; then
1879           AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc.])
1880       fi
1882       CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
1883       LIBS="$JEMALLOC_LIBS $LIBS"
1884       using_custom_malloc=yes
1885   ],
1887   [openbsd], [
1888     AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
1889     enable_openbsd_malloc=yes
1890   ],
1892   [system], [
1893      # handle this later, including the jemalloc fallback
1894     AC_CHECK_FUNCS(mallinfo)
1895   ],
1897   [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
1900 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
1902 if test "$malloc" != "system"; then
1903   # Tell the C compiler not to use the system allocator functions.
1904   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1906 if test "$using_custom_malloc" = "yes"; then
1907   # Tell the C compiler not to use the system allocator functions.
1908   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1911 # By default, we're going to assume we don't have mlockall()
1912 # bionic and other platforms have various broken mlockall subsystems.
1913 # Some systems don't have a working mlockall, some aren't linkable,
1914 # and some have it but don't declare it.
1915 AC_CHECK_FUNCS(mlockall)
1916 AC_CHECK_DECLS([mlockall], , , [
1917 #ifdef HAVE_SYS_MMAN_H
1918 #include <sys/mman.h>
1919 #endif])
1921 # Allow user to specify an alternate syslog facility
1922 AC_ARG_WITH(syslog-facility,
1923 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1924 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1925 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1926 AC_SUBST(LOGFACILITY)
1928 # Check if we have getresuid and getresgid
1929 AC_CHECK_FUNCS(getresuid getresgid)
1931 # Check for gethostbyname_r in all its glorious incompatible versions.
1932 #   (This logic is based on that in Python's configure.in)
1933 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1934   [Define this if you have any gethostbyname_r()])
1936 AC_CHECK_FUNC(gethostbyname_r, [
1937   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1938   OLD_CFLAGS=$CFLAGS
1939   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1940   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1941 #include <netdb.h>
1942   ]], [[
1943     char *cp1, *cp2;
1944     struct hostent *h1, *h2;
1945     int i1, i2;
1946     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1947   ]])],[
1948     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1949     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1950      [Define this if gethostbyname_r takes 6 arguments])
1951     AC_MSG_RESULT(6)
1952   ], [
1953     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1954 #include <netdb.h>
1955     ]], [[
1956       char *cp1, *cp2;
1957       struct hostent *h1;
1958       int i1, i2;
1959       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1960     ]])], [
1961       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1962       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1963         [Define this if gethostbyname_r takes 5 arguments])
1964       AC_MSG_RESULT(5)
1965    ], [
1966       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1967 #include <netdb.h>
1968      ]], [[
1969        char *cp1;
1970        struct hostent *h1;
1971        struct hostent_data hd;
1972        (void) gethostbyname_r(cp1,h1,&hd);
1973      ]])], [
1974        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1975        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1976          [Define this if gethostbyname_r takes 3 arguments])
1977        AC_MSG_RESULT(3)
1978      ], [
1979        AC_MSG_RESULT(0)
1980      ])
1981   ])
1982  ])
1983  CFLAGS=$OLD_CFLAGS
1986 AC_CACHE_CHECK([whether the C compiler supports __func__],
1987   tor_cv_have_func_macro,
1988   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1989 #include <stdio.h>
1990 int main(int c, char **v) { puts(__func__); }])],
1991   tor_cv_have_func_macro=yes,
1992   tor_cv_have_func_macro=no))
1994 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1995   tor_cv_have_FUNC_macro,
1996   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1997 #include <stdio.h>
1998 int main(int c, char **v) { puts(__FUNC__); }])],
1999   tor_cv_have_FUNC_macro=yes,
2000   tor_cv_have_FUNC_macro=no))
2002 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2003   tor_cv_have_FUNCTION_macro,
2004   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2005 #include <stdio.h>
2006 int main(int c, char **v) { puts(__FUNCTION__); }])],
2007   tor_cv_have_FUNCTION_macro=yes,
2008   tor_cv_have_FUNCTION_macro=no))
2010 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2011   tor_cv_have_environ_declared,
2012   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2013 #ifdef HAVE_UNISTD_H
2014 #include <unistd.h>
2015 #endif
2016 #include <stdlib.h>
2017 int main(int c, char **v) { char **t = environ; }])],
2018   tor_cv_have_environ_declared=yes,
2019   tor_cv_have_environ_declared=no))
2021 if test "$tor_cv_have_func_macro" = "yes"; then
2022   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2025 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2026   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2029 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2030   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2031            [Defined if the compiler supports __FUNCTION__])
2034 if test "$tor_cv_have_environ_declared" = "yes"; then
2035   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2036            [Defined if we have extern char **environ already declared])
2039 # $prefix stores the value of the --prefix command line option, or
2040 # NONE if the option wasn't set.  In the case that it wasn't set, make
2041 # it be the default, so that we can use it to expand directories now.
2042 if test "x$prefix" = "xNONE"; then
2043   prefix=$ac_default_prefix
2046 # and similarly for $exec_prefix
2047 if test "x$exec_prefix" = "xNONE"; then
2048   exec_prefix=$prefix
2051 if test "x$BUILDDIR" = "x"; then
2052   BUILDDIR=`pwd`
2054 AC_SUBST(BUILDDIR)
2055 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2056 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2058 if test "x$SRCDIR" = "x"; then
2059   SRCDIR=$(cd "$srcdir"; pwd)
2061 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2062 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2064 if test "x$CONFDIR" = "x"; then
2065   CONFDIR=`eval echo $sysconfdir/tor`
2067 AC_SUBST(CONFDIR)
2068 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2069 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2071 BINDIR=`eval echo $bindir`
2072 AC_SUBST(BINDIR)
2073 LOCALSTATEDIR=`eval echo $localstatedir`
2074 AC_SUBST(LOCALSTATEDIR)
2076 if test "$bwin32" = "true"; then
2077   # Test if the linker supports the --nxcompat and --dynamicbase options
2078   # for Windows
2079   save_LDFLAGS="$LDFLAGS"
2080   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2081   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2082   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2083     [AC_MSG_RESULT([yes])]
2084     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2085     [AC_MSG_RESULT([no])]
2086   )
2087   LDFLAGS="$save_LDFLAGS"
2090 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2091 # than autoconf's macros like.
2092 if test "$GCC" = "yes"; then
2093   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2094   # accident waiting to happen.
2095   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2096 else
2097   # Override optimization level for non-gcc compilers
2098   CFLAGS="$CFLAGS -O"
2099   enable_gcc_warnings=no
2100   enable_gcc_warnings_advisory=no
2103 # Warnings implies advisory-warnings and -Werror.
2104 if test "$enable_gcc_warnings" = "yes"; then
2105   enable_gcc_warnings_advisory=yes
2106   enable_fatal_warnings=yes
2109 # OS X Lion started deprecating the system openssl. Let's just disable
2110 # all deprecation warnings on OS X. Also, to potentially make the binary
2111 # a little smaller, let's enable dead_strip.
2112 case "$host_os" in
2114  darwin*)
2115     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2116     LDFLAGS="$LDFLAGS -dead_strip" ;;
2117 esac
2119 # Add some more warnings which we use in development but not in the
2120 # released versions.  (Some relevant gcc versions can't handle these.)
2122 # Note that we have to do this near the end  of the autoconf process, or
2123 # else we may run into problems when these warnings hit on the testing C
2124 # programs that autoconf wants to build.
2125 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2127   case "$host" in
2128     *-*-openbsd* | *-*-bitrig*)
2129       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2130       # That's fine, except that the headers don't pass -Wredundant-decls.
2131       # Therefore, let's disable -Wsystem-headers when we're building
2132       # with maximal warnings on OpenBSD.
2133       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2134   esac
2136   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2137   # have it work better.
2138   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2140   # This warning was added in gcc 4.3, but it appears to generate
2141   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2142   #CFLAGS="$CFLAGS -Wlogical-op"
2144   m4_foreach_w([warning_flag], [
2145      -Waddress
2146      -Waddress-of-array-temporary
2147      -Waddress-of-temporary
2148      -Wambiguous-macro
2149      -Wanonymous-pack-parens
2150      -Warc
2151      -Warc-abi
2152      -Warc-bridge-casts-disallowed-in-nonarc
2153      -Warc-maybe-repeated-use-of-weak
2154      -Warc-performSelector-leaks
2155      -Warc-repeated-use-of-weak
2156      -Warray-bounds
2157      -Warray-bounds-pointer-arithmetic
2158      -Wasm
2159      -Wasm-operand-widths
2160      -Watomic-properties
2161      -Watomic-property-with-user-defined-accessor
2162      -Wauto-import
2163      -Wauto-storage-class
2164      -Wauto-var-id
2165      -Wavailability
2166      -Wbackslash-newline-escape
2167      -Wbad-array-new-length
2168      -Wbind-to-temporary-copy
2169      -Wbitfield-constant-conversion
2170      -Wbool-conversion
2171      -Wbool-conversions
2172      -Wbuiltin-requires-header
2173      -Wchar-align
2174      -Wcompare-distinct-pointer-types
2175      -Wcomplex-component-init
2176      -Wconditional-type-mismatch
2177      -Wconfig-macros
2178      -Wconstant-conversion
2179      -Wconstant-logical-operand
2180      -Wconstexpr-not-const
2181      -Wcustom-atomic-properties
2182      -Wdangling-field
2183      -Wdangling-initializer-list
2184      -Wdate-time
2185      -Wdelegating-ctor-cycles
2186      -Wdeprecated-implementations
2187      -Wdeprecated-register
2188      -Wdirect-ivar-access
2189      -Wdiscard-qual
2190      -Wdistributed-object-modifiers
2191      -Wdivision-by-zero
2192      -Wdollar-in-identifier-extension
2193      -Wdouble-promotion
2194      -Wduplicate-decl-specifier
2195      -Wduplicate-enum
2196      -Wduplicate-method-arg
2197      -Wduplicate-method-match
2198      -Wduplicated-cond
2199      -Wdynamic-class-memaccess
2200      -Wembedded-directive
2201      -Wempty-translation-unit
2202      -Wenum-conversion
2203      -Wexit-time-destructors
2204      -Wexplicit-ownership-type
2205      -Wextern-initializer
2206      -Wextra
2207      -Wextra-semi
2208      -Wextra-tokens
2209      -Wflexible-array-extensions
2210      -Wfloat-conversion
2211      -Wformat-non-iso
2212      -Wfour-char-constants
2213      -Wgcc-compat
2214      -Wglobal-constructors
2215      -Wgnu-array-member-paren-init
2216      -Wgnu-designator
2217      -Wgnu-static-float-init
2218      -Wheader-guard
2219      -Wheader-hygiene
2220      -Widiomatic-parentheses
2221      -Wignored-attributes
2222      -Wimplicit-atomic-properties
2223      -Wimplicit-conversion-floating-point-to-bool
2224      -Wimplicit-exception-spec-mismatch
2225      -Wimplicit-fallthrough
2226      -Wimplicit-fallthrough-per-function
2227      -Wimplicit-retain-self
2228      -Wimport-preprocessor-directive-pedantic
2229      -Wincompatible-library-redeclaration
2230      -Wincompatible-pointer-types-discards-qualifiers
2231      -Wincomplete-implementation
2232      -Wincomplete-module
2233      -Wincomplete-umbrella
2234      -Winit-self
2235      -Wint-conversions
2236      -Wint-to-void-pointer-cast
2237      -Winteger-overflow
2238      -Winvalid-constexpr
2239      -Winvalid-iboutlet
2240      -Winvalid-noreturn
2241      -Winvalid-pp-token
2242      -Winvalid-source-encoding
2243      -Winvalid-token-paste
2244      -Wknr-promoted-parameter
2245      -Wlarge-by-value-copy
2246      -Wliteral-conversion
2247      -Wliteral-range
2248      -Wlocal-type-template-args
2249      -Wlogical-op
2250      -Wloop-analysis
2251      -Wmain-return-type
2252      -Wmalformed-warning-check
2253      -Wmethod-signatures
2254      -Wmicrosoft
2255      -Wmicrosoft-exists
2256      -Wmismatched-parameter-types
2257      -Wmismatched-return-types
2258      -Wmissing-field-initializers
2259      -Wmissing-format-attribute
2260      -Wmissing-noreturn
2261      -Wmissing-selector-name
2262      -Wmissing-sysroot
2263      -Wmissing-variable-declarations
2264      -Wmodule-conflict
2265      -Wnested-anon-types
2266      -Wnewline-eof
2267      -Wnon-literal-null-conversion
2268      -Wnon-pod-varargs
2269      -Wnonportable-cfstrings
2270      -Wnormalized=nfkc
2271      -Wnull-arithmetic
2272      -Wnull-character
2273      -Wnull-conversion
2274      -Wnull-dereference
2275      -Wout-of-line-declaration
2276      -Wover-aligned
2277      -Woverlength-strings
2278      -Woverride-init
2279      -Woverriding-method-mismatch
2280      -Wpointer-type-mismatch
2281      -Wpredefined-identifier-outside-function
2282      -Wprotocol-property-synthesis-ambiguity
2283      -Wreadonly-iboutlet-property
2284      -Wreadonly-setter-attrs
2285      -Wreceiver-expr
2286      -Wreceiver-forward-class
2287      -Wreceiver-is-weak
2288      -Wreinterpret-base-class
2289      -Wrequires-super-attribute
2290      -Wreserved-user-defined-literal
2291      -Wreturn-stack-address
2292      -Wsection
2293      -Wselector-type-mismatch
2294      -Wsentinel
2295      -Wserialized-diagnostics
2296      -Wshadow
2297      -Wshift-count-negative
2298      -Wshift-count-overflow
2299      -Wshift-negative-value
2300      -Wshift-overflow=2
2301      -Wshift-sign-overflow
2302      -Wshorten-64-to-32
2303      -Wsizeof-array-argument
2304      -Wsource-uses-openmp
2305      -Wstatic-float-init
2306      -Wstatic-in-inline
2307      -Wstatic-local-in-inline
2308      -Wstrict-overflow=1
2309      -Wstring-compare
2310      -Wstring-conversion
2311      -Wstrlcpy-strlcat-size
2312      -Wstrncat-size
2313      -Wsuggest-attribute=format
2314      -Wsuggest-attribute=noreturn
2315      -Wsuper-class-method-mismatch
2316      -Wswitch-bool
2317      -Wsync-nand
2318      -Wtautological-constant-out-of-range-compare
2319      -Wtentative-definition-incomplete-type
2320      -Wtrampolines
2321      -Wtype-safety
2322      -Wtypedef-redefinition
2323      -Wtypename-missing
2324      -Wundefined-inline
2325      -Wundefined-internal
2326      -Wundefined-reinterpret-cast
2327      -Wunicode
2328      -Wunicode-whitespace
2329      -Wunknown-warning-option
2330      -Wunnamed-type-template-args
2331      -Wunneeded-member-function
2332      -Wunsequenced
2333      -Wunsupported-visibility
2334      -Wunused-but-set-parameter
2335      -Wunused-but-set-variable
2336      -Wunused-command-line-argument
2337      -Wunused-const-variable=2
2338      -Wunused-exception-parameter
2339      -Wunused-local-typedefs
2340      -Wunused-member-function
2341      -Wunused-sanitize-argument
2342      -Wunused-volatile-lvalue
2343      -Wuser-defined-literals
2344      -Wvariadic-macros
2345      -Wvector-conversion
2346      -Wvector-conversions
2347      -Wvexing-parse
2348      -Wvisibility
2349      -Wvla-extension
2350      -Wzero-length-array
2351   ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
2353 dnl    We should re-enable this in some later version.  Clang doesn't
2354 dnl    mind, but it causes trouble with GCC.
2355 dnl     -Wstrict-overflow=2
2357 dnl    These seem to require annotations that we don't currently use,
2358 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2359 dnl     -Wthread-safety
2360 dnl     -Wthread-safety-analysis
2361 dnl     -Wthread-safety-attributes
2362 dnl     -Wthread-safety-beta
2363 dnl     -Wthread-safety-precise
2365   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2366   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2367   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2368   CFLAGS="$CFLAGS -Wwrite-strings"
2369   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2370   CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
2371   CFLAGS="$CFLAGS -Wunused-parameter "
2372   # These interfere with building main() { return 0; }, which autoconf
2373   # likes to use as its default program.
2374   CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
2376   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2377     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2378   fi
2379   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2380     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2381   fi
2382   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2383     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2384   fi
2386   if test "x$enable_fatal_warnings" = "xyes"; then
2387     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2388     # default autoconf programs are full of errors.
2389     CFLAGS="$CFLAGS -Werror"
2390   fi
2394 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2395    case "$host_os" in
2396     darwin*)
2397       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.])
2398    esac
2401 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2403 AC_CONFIG_FILES([
2404         Doxyfile
2405         Makefile
2406         config.rust
2407         link_rust.sh
2408         contrib/dist/suse/tor.sh
2409         contrib/operator-tools/tor.logrotate
2410         contrib/dist/tor.sh
2411         contrib/dist/torctl
2412         contrib/dist/tor.service
2413         src/config/torrc.sample
2414         src/config/torrc.minimal
2415         src/rust/.cargo/config
2416         scripts/maint/checkOptionDocs.pl
2417         scripts/maint/updateVersions.pl
2420 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2421   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2422   for file in $regular_mans ; do
2423     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2424       echo "==================================";
2425       echo;
2426       echo "Building Tor has failed since manpages cannot be built.";
2427       echo;
2428       echo "You need asciidoc installed to be able to build the manpages.";
2429       echo "To build without manpages, use the --disable-asciidoc argument";
2430       echo "when calling configure.";
2431       echo;
2432       echo "==================================";
2433       exit 1;
2434     fi
2435   done
2438 if test "$fragile_hardening" = "yes"; then
2439   AC_MSG_WARN([
2441 ============
2442 Warning!  Building Tor with --enable-fragile-hardening (also known as
2443 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2444 other kinds of attacks easier. A Tor instance build with this option will be
2445 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2446 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2447 denial of service attacks. For more information, see
2448 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
2449 ============
2450   ])
2453 AC_OUTPUT