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