Space out first connection_edge_process_relay_cell() line in circuit_receive_relay_cell()
[tor.git] / configure.ac
blob9ec123f51e2af92699f43858db1a7104938e7341
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2019, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_PREREQ([2.63])
7 AC_INIT([tor],[0.4.2.0-alpha-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
11 # DO NOT EDIT THIS DEFINITION BY HAND UNLESS YOU KNOW WHAT YOU'RE DOING.
13 # The update_versions.py script updates this definition when the
14 # version number changes.  Tor uses it to make sure that it
15 # only shuts down for missing "required protocols" when those protocols
16 # are listed as required by a consensus after this date.
17 AC_DEFINE(APPROX_RELEASE_DATE, ["2019-06-10"], # for 0.4.2.0-alpha-dev
18           [Approximate date when this software was released. (Updated when the version changes.)])
20 # "foreign" means we don't follow GNU package layout standards
21 # "1.11" means we require automake version 1.11 or newer
22 # "subdir-objects" means put .o files in the same directory as the .c files
23 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
25 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
26 AC_CONFIG_HEADERS([orconfig.h])
28 AC_USE_SYSTEM_EXTENSIONS
29 AC_CANONICAL_HOST
31 PKG_PROG_PKG_CONFIG
33 AC_ARG_ENABLE(openbsd-malloc,
34    AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD.  Linux only. Deprecated: see --with-malloc]))
35 AC_ARG_ENABLE(static-openssl,
36    AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
37 AC_ARG_ENABLE(static-libevent,
38    AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
39 AC_ARG_ENABLE(static-zlib,
40    AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
41 AC_ARG_ENABLE(static-tor,
42    AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
43 AC_ARG_ENABLE(unittests,
44    AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
45 AC_ARG_ENABLE(coverage,
46    AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
47 AC_ARG_ENABLE(asserts-in-tests,
48    AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
49 AC_ARG_ENABLE(system-torrc,
50    AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
51 AC_ARG_ENABLE(libfuzzer,
52    AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
53 AC_ARG_ENABLE(oss-fuzz,
54    AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
55 AC_ARG_ENABLE(memory-sentinels,
56    AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
57 AC_ARG_ENABLE(rust,
58    AS_HELP_STRING(--enable-rust, [enable rust integration]))
59 AC_ARG_ENABLE(cargo-online-mode,
60    AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
61 AC_ARG_ENABLE(restart-debugging,
62    AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
63 AC_ARG_ENABLE(zstd-advanced-apis,
64    AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
65 AC_ARG_ENABLE(nss,
66    AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
67 AC_ARG_ENABLE(pic,
68    AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
70 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
71     AC_MSG_ERROR([Can't disable assertions outside of coverage build])
74 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
75 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
76 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
77 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
78 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
79 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
80 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
81 AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
83 if test "x$enable_nss" = "xyes"; then
84   AC_DEFINE(ENABLE_NSS, 1,
85             [Defined if we're building with NSS.])
86 else
87   AC_DEFINE(ENABLE_OPENSSL, 1,
88             [Defined if we're building with OpenSSL or LibreSSL])
91 if test "$enable_static_tor" = "yes"; then
92   enable_static_libevent="yes";
93   enable_static_openssl="yes";
94   enable_static_zlib="yes";
95   CFLAGS="$CFLAGS -static"
98 if test "$enable_system_torrc" = "no"; then
99   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
100             [Defined if we're not going to look for a torrc in SYSCONF])
103 if test "$enable_memory_sentinels" = "no"; then
104   AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
105            [Defined if we're turning off memory safety code to look for bugs])
108 AC_ARG_ENABLE(manpage,
109               AS_HELP_STRING(--disable-manpage, [Disable manpage generation.]))
111 AC_ARG_ENABLE(html-manual,
112               AS_HELP_STRING(--disable-html-manual, [Disable HTML documentation.]))
114 AC_ARG_ENABLE(asciidoc,
115      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
116      [case "${enableval}" in
117         "yes") asciidoc=true ;;
118         "no")  asciidoc=false ;;
119         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
120       esac], [asciidoc=true])
122 # systemd notify support
123 AC_ARG_ENABLE(systemd,
124       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
125       [case "${enableval}" in
126         "yes") systemd=true ;;
127         "no")  systemd=false ;;
128         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
129       esac], [systemd=auto])
131 if test "$enable_restart_debugging" = "yes"; then
132   AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
133             [Defined if we're building with support for in-process restart debugging.])
136 if test "$enable_zstd_advanced_apis" != "no"; then
137    AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
138              [Defined if we're going to try to use zstd's "static-only" APIs.])
141 # systemd support
142 if test "x$enable_systemd" = "xno"; then
143     have_systemd=no;
144 else
145     PKG_CHECK_MODULES(SYSTEMD,
146         [libsystemd-daemon],
147         have_systemd=yes,
148         have_systemd=no)
149     if test "x$have_systemd" = "xno"; then
150         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
151         PKG_CHECK_MODULES(SYSTEMD,
152             [libsystemd],
153             have_systemd=yes,
154             have_systemd=no)
155     fi
158 if test "x$have_systemd" = "xyes"; then
159     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
160     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
161     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
162     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
163          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
165 AC_SUBST(TOR_SYSTEMD_CFLAGS)
166 AC_SUBST(TOR_SYSTEMD_LIBS)
168 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
169     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
172 case "$host" in
173    *-*-solaris* )
174      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
175      ;;
176 esac
178 AC_ARG_ENABLE(gcc-warnings,
179      AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
180 AC_ARG_ENABLE(fatal-warnings,
181      AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
182 AC_ARG_ENABLE(gcc-warnings-advisory,
183      AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
185 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
186 AC_ARG_ENABLE(gcc-hardening,
187     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
189 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
190 AC_ARG_ENABLE(expensive-hardening,
191     AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
192 AC_ARG_ENABLE(fragile-hardening,
193     AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
194 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
195   fragile_hardening="yes"
196   AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
199 dnl Linker hardening options
200 dnl Currently these options are ELF specific - you can't use this with MacOSX
201 AC_ARG_ENABLE(linker-hardening,
202     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
204 AC_ARG_ENABLE(local-appdata,
205    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
206 if test "$enable_local_appdata" = "yes"; then
207   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
208             [Defined if we default to host local appdata paths on Windows])
211 AC_ARG_ENABLE(tool-name-check,
212      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
214 AC_ARG_ENABLE(seccomp,
215      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
217 AC_ARG_ENABLE(libscrypt,
218      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
220 dnl Enable event tracing which are transformed to debug log statement.
221 AC_ARG_ENABLE(event-tracing-debug,
222      AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
223 AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
225 if test x$enable_event_tracing_debug = xyes; then
226   AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
227   AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
230 dnl Enable Android only features.
231 AC_ARG_ENABLE(android,
232      AS_HELP_STRING(--enable-android, [build with Android features enabled]))
233 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
235 if test "x$enable_android" = "xyes"; then
236   AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
238   dnl Check if the Android log library is available.
239   AC_CHECK_HEADERS([android/log.h])
240   AC_SEARCH_LIBS(__android_log_write, [log])
244 dnl ---
245 dnl Tor modules options. These options are namespaced with --disable-module-XXX
246 dnl ---
248 dnl All our modules.
249 m4_define(MODULES, dirauth)
251 dnl Directory Authority module.
252 AC_ARG_ENABLE([module-dirauth],
253               AS_HELP_STRING([--disable-module-dirauth],
254                              [Do not build tor with the dirauth module]),
255               [], dnl Action if-given
256               AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
257                         [Compile with Directory Authority feature support]))
258 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH, [test "x$enable_module_dirauth" != "xno"])
260 dnl Helper variables.
261 TOR_MODULES_ALL_ENABLED=
262 AC_DEFUN([ADD_MODULE], [
263     MODULE=m4_toupper($1)
264     TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
266 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
267 AC_SUBST(TOR_MODULES_ALL_ENABLED)
269 dnl check for the correct "ar" when cross-compiling.
270 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
271 dnl    so kludge up a replacement for the case where it isn't there yet.)
272 m4_ifdef([AM_PROG_AR],
273          [AM_PROG_AR],
274          [AN_MAKEVAR([AR], [AC_PROG_AR])
275           AN_PROGRAM([ar], [AC_PROG_AR])
276           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
277           AC_PROG_AR])
279 dnl Check whether the above macro has settled for a simply named tool even
280 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
281 dnl because that will find any cc on the system, not only the cross-compiler,
282 dnl and then verify that a binary built with this compiler runs on the
283 dnl build system. It will then come to the false conclusion that we're not
284 dnl cross-compiling.
285 if test "x$enable_tool_name_check" != "xno"; then
286     if test "x$ac_tool_warned" = "xyes"; then
287         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.)])
288         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
289                 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.)])
290         fi
293 AC_PROG_CC
294 AC_PROG_CPP
295 AC_PROG_MAKE_SET
296 AC_PROG_RANLIB
297 AC_PROG_SED
299 AC_ARG_VAR([PERL], [path to Perl binary])
300 AC_CHECK_PROGS([PERL], [perl])
301 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
303 dnl check for asciidoc and a2x
304 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
305 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
307 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
308 AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
309 AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
311 AM_PROG_CC_C_O
312 AC_PROG_CC_C99
314 AC_ARG_VAR([PYTHON], [path to Python binary])
315 AC_CHECK_PROGS(PYTHON, [ \
316         python3 \
317         python3.8 python3.7 python3.6 python3.5 python3.4 \
318         python \
319         python2 python2.7])
320 if test "x$PYTHON" = "x"; then
321   AC_MSG_WARN([Python unavailable; some tests will not be run.])
323 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
325 dnl List all external rust crates we depend on here. Include the version
326 rust_crates=" \
327     digest-0.7.2 \
328     libc-0.2.39 \
330 AC_SUBST(rust_crates)
332 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
333 AC_C_FLEXIBLE_ARRAY_MEMBER
334 ], [
335  dnl Maybe we've got an old autoconf...
336  AC_CACHE_CHECK([for flexible array members],
337      tor_cv_c_flexarray,
338      [AC_COMPILE_IFELSE(
339        AC_LANG_PROGRAM([
340  struct abc { int a; char b[]; };
341 ], [
342  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
343  def->b[0] = 33;
345   [tor_cv_c_flexarray=yes],
346   [tor_cv_c_flexarray=no])])
347  if test "$tor_cv_flexarray" = "yes"; then
348    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
349  else
350    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
351  fi
354 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
355       tor_cv_c_c99_decl,
356       [AC_COMPILE_IFELSE(
357          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
358          [tor_cv_c_c99_decl=yes],
359          [tor_cv_c_c99_decl=no] )])
360 if test "$tor_cv_c_c99_decl" != "yes"; then
361   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
364 AC_CACHE_CHECK([for working C99 designated initializers],
365       tor_cv_c_c99_designated_init,
366       [AC_COMPILE_IFELSE(
367          [AC_LANG_PROGRAM([struct s { int a; int b; };],
368                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
369          [tor_cv_c_c99_designated_init=yes],
370          [tor_cv_c_c99_designated_init=no] )])
372 if test "$tor_cv_c_c99_designated_init" != "yes"; then
373   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
376 TORUSER=_tor
377 AC_ARG_WITH(tor-user,
378         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
379         [
380            TORUSER=$withval
381         ]
383 AC_SUBST(TORUSER)
385 TORGROUP=_tor
386 AC_ARG_WITH(tor-group,
387         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
388         [
389            TORGROUP=$withval
390         ]
392 AC_SUBST(TORGROUP)
395 dnl If _WIN32 is defined and non-zero, we are building for win32
396 AC_MSG_CHECKING([for win32])
397 AC_RUN_IFELSE([AC_LANG_SOURCE([
398 int main(int c, char **v) {
399 #ifdef _WIN32
400 #if _WIN32
401   return 0;
402 #else
403   return 1;
404 #endif
405 #else
406   return 2;
407 #endif
408 }])],
409 bwin32=true; AC_MSG_RESULT([yes]),
410 bwin32=false; AC_MSG_RESULT([no]),
411 bwin32=cross; AC_MSG_RESULT([cross])
414 if test "$bwin32" = "cross"; then
415 AC_MSG_CHECKING([for win32 (cross)])
416 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
417 #ifdef _WIN32
418 int main(int c, char **v) {return 0;}
419 #else
420 #error
421 int main(int c, char **v) {return x(y);}
422 #endif
423 ])],
424 bwin32=true; AC_MSG_RESULT([yes]),
425 bwin32=false; AC_MSG_RESULT([no]))
428 AH_BOTTOM([
429 #ifdef _WIN32
430 /* Defined to access windows functions and definitions for >=WinXP */
431 # ifndef WINVER
432 #  define WINVER 0x0501
433 # endif
435 /* Defined to access _other_ windows functions and definitions for >=WinXP */
436 # ifndef _WIN32_WINNT
437 #  define _WIN32_WINNT 0x0501
438 # endif
440 /* Defined to avoid including some windows headers as part of Windows.h */
441 # ifndef WIN32_LEAN_AND_MEAN
442 #  define WIN32_LEAN_AND_MEAN 1
443 # endif
444 #endif
447 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
448 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
449 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
451 dnl Enable C99 when compiling with MIPSpro
452 AC_MSG_CHECKING([for MIPSpro compiler])
453 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
454 #if (defined(__sgi) && defined(_COMPILER_VERSION))
455 #error
456   return x(y);
457 #endif
458 ])],
459 bmipspro=false; AC_MSG_RESULT(no),
460 bmipspro=true; AC_MSG_RESULT(yes))
462 if test "$bmipspro" = "true"; then
463   CFLAGS="$CFLAGS -c99"
466 AC_C_BIGENDIAN
468 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
470 if test "x$enable_rust" = "xyes"; then
471   AC_ARG_VAR([RUSTC], [path to the rustc binary])
472   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
473   if test "x$RUSTC" = "xno"; then
474     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
475   fi
477   AC_ARG_VAR([CARGO], [path to the cargo binary])
478   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
479   if test "x$CARGO" = "xno"; then
480     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
481   fi
483   AC_DEFINE([HAVE_RUST], 1, [have Rust])
484   if test "x$enable_fatal_warnings" = "xyes"; then
485     RUST_WARN=
486   else
487     RUST_WARN=#
488   fi
489   if test "x$enable_cargo_online_mode" = "xyes"; then
490     CARGO_ONLINE=
491     RUST_DL=#
492   else
493     CARGO_ONLINE=--frozen
494     RUST_DL=
496     dnl When we're not allowed to touch the network, we need crate dependencies
497     dnl locally available.
498     AC_MSG_CHECKING([rust crate dependencies])
499     AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
500     if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
501       TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
502     fi
503     dnl Check whether the path exists before we try to cd into it.
504     if test ! -d "$TOR_RUST_DEPENDENCIES"; then
505       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.])
506       ERRORED=1
507     fi
508     dnl Make the path absolute, since we'll be using it from within a
509     dnl subdirectory.
510     TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
512     for dep in $rust_crates; do
513       if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
514         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.])
515         ERRORED=1
516       fi
517     done
518     if test "x$ERRORED" = "x"; then
519       AC_MSG_RESULT([yes])
520     fi
521   fi
523   dnl For now both MSVC and MinGW rust libraries will output static libs with
524   dnl the MSVC naming convention.
525   if test "$bwin32" = "true"; then
526     tor_rust_static_name=tor_rust.lib
527   else
528     tor_rust_static_name=libtor_rust.a
529   fi
531   AC_CANONICAL_BUILD
533   if test -n "$TOR_RUST_TARGET"; then
534     if test "$host" = "$build"; then
535       AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
536     fi
537     RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
538     TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
539   else
540     if test "$host" != "$build"; then
541       AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
542     fi
543     RUST_TARGET_PROP=
544     TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
545   fi
547   AC_SUBST(RUST_TARGET_PROP)
548   AC_SUBST(TOR_RUST_LIB_PATH)
549   AC_SUBST(CARGO_ONLINE)
550   AC_SUBST(RUST_WARN)
551   AC_SUBST(RUST_DL)
553   dnl Let's check the rustc version, too
554   AC_MSG_CHECKING([rust version])
555   RUSTC_VERSION=`$RUSTC --version`
556   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
557   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
558   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
559     AC_MSG_ERROR([rustc version couldn't be identified])
560   fi
561   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
562     AC_MSG_ERROR([rustc must be at least version 1.14])
563   fi
564   AC_MSG_RESULT([$RUSTC_VERSION])
567 AC_SEARCH_LIBS(socket, [socket network])
568 AC_SEARCH_LIBS(gethostbyname, [nsl])
569 AC_SEARCH_LIBS(dlopen, [dl])
570 AC_SEARCH_LIBS(inet_aton, [resolv])
571 AC_SEARCH_LIBS(backtrace, [execinfo])
572 saved_LIBS="$LIBS"
573 AC_SEARCH_LIBS([clock_gettime], [rt])
574 if test "$LIBS" != "$saved_LIBS"; then
575    # Looks like we need -lrt for clock_gettime().
576    have_rt=yes
579 if test "$bwin32" = "false"; then
580   AC_SEARCH_LIBS(pthread_create, [pthread])
581   AC_SEARCH_LIBS(pthread_detach, [pthread])
584 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
585 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
587 AC_CHECK_FUNCS(
588         _NSGetEnviron \
589         RtlSecureZeroMemory \
590         SecureZeroMemory \
591         accept4 \
592         backtrace \
593         backtrace_symbols_fd \
594         eventfd \
595         explicit_bzero \
596         timingsafe_memcmp \
597         flock \
598         ftime \
599         get_current_dir_name \
600         getaddrinfo \
601         getdelim \
602         getifaddrs \
603         getline \
604         getpass \
605         getrlimit \
606         gettimeofday \
607         gmtime_r \
608         gnu_get_libc_version \
609         htonll \
610         inet_aton \
611         ioctl \
612         issetugid \
613         llround \
614         localtime_r \
615         lround \
616         madvise \
617         memmem \
618         memset_s \
619         minherit \
620         mmap \
621         pipe \
622         pipe2 \
623         prctl \
624         readpassphrase \
625         rint \
626         sigaction \
627         socketpair \
628         statvfs \
629         strncasecmp \
630         strcasecmp \
631         strlcat \
632         strlcpy \
633         strnlen \
634         strptime \
635         strtok_r \
636         strtoull \
637         sysconf \
638         sysctl \
639         truncate \
640         uname \
641         usleep \
642         vasprintf \
643         _vscprintf
646 # Apple messed up when they added some functions: they
647 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
648 # checks.
650 # We should only probe for these functions if we are sure that we
651 # are not targeting OS X 10.9 or earlier.
652 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
653 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
654 #ifdef __APPLE__
655 #  include <AvailabilityMacros.h>
656 #  ifndef MAC_OS_X_VERSION_10_10
657 #    define MAC_OS_X_VERSION_10_10 101000
658 #  endif
659 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
660 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
661 #      error "Running on Mac OS X 10.9 or earlier"
662 #    endif
663 #  endif
664 #endif
665 ]], [[]])],
666    [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
667    [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
669 if test "$on_macos_pre_10_10" = "no"; then
670   AC_CHECK_FUNCS(
671         mach_approximate_time \
672   )
675 # We should only probe for these functions if we are sure that we
676 # are not targeting OSX 10.11 or earlier.
677 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
678 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
679 #ifdef __APPLE__
680 #  include <AvailabilityMacros.h>
681 #  ifndef MAC_OS_X_VERSION_10_12
682 #    define MAC_OS_X_VERSION_10_12 101200
683 #  endif
684 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
685 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
686 #      error "Running on Mac OSX 10.11 or earlier"
687 #    endif
688 #  endif
689 #endif
690 ]], [[]])],
691    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
692    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
694 if test "$on_macos_pre_10_12" = "no"; then
695   AC_CHECK_FUNCS(
696         clock_gettime \
697         getentropy \
698   )
701 if test "$bwin32" != "true"; then
702   AC_CHECK_HEADERS(pthread.h)
703   AC_CHECK_FUNCS(pthread_create)
704   AC_CHECK_FUNCS(pthread_condattr_setclock)
707 if test "$bwin32" = "true"; then
708   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
709 #include <windows.h>
710 #include <conio.h>
711 #include <wchar.h>
712                  ])
715 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
716   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
718 AC_MSG_CHECKING([whether free(NULL) works])
719 AC_RUN_IFELSE([AC_LANG_PROGRAM([
720   #include <stdlib.h>
721 ], [
722 char *p = NULL;
723 free(p);
724 ])],
725 [free_null_ok=true; AC_MSG_RESULT(yes)],
726 [free_null_ok=false; AC_MSG_RESULT(no)],
727 [free_null_ok=cross; AC_MSG_RESULT(cross)])
729 if test "$free_null_ok" = "false"; then
730    AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
733 dnl ------------------------------------------------------
734 dnl Where do you live, libevent?  And how do we call you?
736 if test "$bwin32" = "true"; then
737   TOR_LIB_WS32=-lws2_32
738   TOR_LIB_IPHLPAPI=-liphlpapi
739   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
740   # think it's actually necessary.
741   TOR_LIB_GDI=-lgdi32
742   TOR_LIB_USERENV=-luserenv
743 else
744   TOR_LIB_WS32=
745   TOR_LIB_GDI=
746   TOR_LIB_USERENV=
748 AC_SUBST(TOR_LIB_WS32)
749 AC_SUBST(TOR_LIB_GDI)
750 AC_SUBST(TOR_LIB_IPHLPAPI)
751 AC_SUBST(TOR_LIB_USERENV)
753 tor_libevent_pkg_redhat="libevent"
754 tor_libevent_pkg_debian="libevent-dev"
755 tor_libevent_devpkg_redhat="libevent-devel"
756 tor_libevent_devpkg_debian="libevent-dev"
758 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
759 dnl linking for static builds.
760 STATIC_LIBEVENT_FLAGS=""
761 if test "$enable_static_libevent" = "yes"; then
762     if test "$have_rt" = "yes"; then
763       STATIC_LIBEVENT_FLAGS=" -lrt "
764     fi
767 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
768 #ifdef _WIN32
769 #include <winsock2.h>
770 #endif
771 #include <sys/time.h>
772 #include <sys/types.h>
773 #include <event2/event.h>], [
774 #ifdef _WIN32
775 #include <winsock2.h>
776 #endif
777 struct event_base;
778 struct event_base *event_base_new(void);
779 void event_base_free(struct event_base *);],
780     [
781 #ifdef _WIN32
782 {WSADATA d; WSAStartup(0x101,&d); }
783 #endif
784 event_base_free(event_base_new());
785 ], [--with-libevent-dir], [/opt/libevent])
787 dnl Determine the incantation needed to link libevent.
788 save_LIBS="$LIBS"
789 save_LDFLAGS="$LDFLAGS"
790 save_CPPFLAGS="$CPPFLAGS"
792 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
793 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
794 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
796 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
798 if test "$enable_static_libevent" = "yes"; then
799    if test "$tor_cv_library_libevent_dir" = "(system)"; then
800      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
801    else
802      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
803    fi
804 else
805      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
806        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
807        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"))
809        if test "$ac_cv_search_event_new" != "none required"; then
810          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
811        fi
812        if test "$ac_cv_search_evdns_base_new" != "none required"; then
813          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
814        fi
815      else
816        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
817      fi
820 dnl Now check for particular libevent functions.
821 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
822                 evutil_secure_rng_add_bytes \
823                 evdns_base_get_nameserver_addr \
827 LIBS="$save_LIBS"
828 LDFLAGS="$save_LDFLAGS"
829 CPPFLAGS="$save_CPPFLAGS"
831 dnl Check that libevent is at least at version 2.0.10, the first stable
832 dnl release of its series
833 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
834 AC_MSG_CHECKING([whether Libevent is new enough])
835 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
836 #include <event2/event.h>
837 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
838 #error
839 int x = y(zz);
840 #else
841 int x = 1;
842 #endif
843 ])], [ AC_MSG_RESULT([yes]) ],
844    [ AC_MSG_RESULT([no])
845      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
847 LIBS="$save_LIBS"
848 LDFLAGS="$save_LDFLAGS"
849 CPPFLAGS="$save_CPPFLAGS"
851 AC_SUBST(TOR_LIBEVENT_LIBS)
853 dnl ------------------------------------------------------
854 dnl Where do you live, libm?
856 dnl On some platforms (Haiku/BeOS) the math library is
857 dnl part of libroot. In which case don't link against lm
858 TOR_LIB_MATH=""
859 save_LIBS="$LIBS"
860 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
861 if test "$ac_cv_search_pow" != "none required"; then
862     TOR_LIB_MATH="$ac_cv_search_pow"
864 LIBS="$save_LIBS"
865 AC_SUBST(TOR_LIB_MATH)
867 dnl ------------------------------------------------------
868 dnl Hello, NSS.  You're new around here.
869 if test "x$enable_nss" = "xyes"; then
870   PKG_CHECK_MODULES(NSS,
871      [nss],
872      [have_nss=yes],
873      [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it.])])
874   AC_SUBST(NSS_CFLAGS)
875   AC_SUBST(NSS_LIBS)
878 dnl ------------------------------------------------------
879 dnl Where do you live, openssl?  And how do we call you?
881 if test "x$enable_nss" != "xyes"; then
883 tor_openssl_pkg_redhat="openssl"
884 tor_openssl_pkg_debian="libssl-dev"
885 tor_openssl_devpkg_redhat="openssl-devel"
886 tor_openssl_devpkg_debian="libssl-dev"
888 ALT_openssl_WITHVAL=""
889 AC_ARG_WITH(ssl-dir,
890   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
891   [
892       if test "x$withval" != "xno" && test "x$withval" != "x"; then
893          ALT_openssl_WITHVAL="$withval"
894       fi
895   ])
897 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
898 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
899     [#include <openssl/ssl.h>
900      char *getenv(const char *);],
901     [struct ssl_cipher_st;
902      unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
903      char *getenv(const char *);],
904     dnl This funny-looking test program calls getenv, so that the compiler
905     dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
906     dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
907     dnl We look for SSL_cipher_get_id() because it is present in
908     dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
909     dnl depends on it.
910     [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
911     [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
913 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
915 if test "$enable_static_openssl" = "yes"; then
916    if test "$tor_cv_library_openssl_dir" = "(system)"; then
917      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
918    else
919      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
920    fi
921 else
922      TOR_OPENSSL_LIBS="-lssl -lcrypto"
924 AC_SUBST(TOR_OPENSSL_LIBS)
926 dnl Now check for particular openssl functions.
927 save_LIBS="$LIBS"
928 save_LDFLAGS="$LDFLAGS"
929 save_CPPFLAGS="$CPPFLAGS"
930 LIBS="$TOR_OPENSSL_LIBS $LIBS"
931 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
932 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
934 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
935 #include <openssl/opensslv.h>
936 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
937 #error "too old"
938 #endif
939    ]], [[]])],
940    [ : ],
941    [ 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.]) ])
943 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
944 #include <openssl/opensslv.h>
945 #include <openssl/evp.h>
946 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
947 #error "no ECC"
948 #endif
949 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
950 #error "curves unavailable"
951 #endif
952    ]], [[]])],
953    [ : ],
954    [ 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.]) ])
956 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
957 [#include <openssl/ssl.h>
960 dnl OpenSSL functions which we might not have.  In theory, we could just
961 dnl check the openssl version number, but in practice that gets pretty
962 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
963 dnl to them.
964 AC_CHECK_FUNCS([ \
965                 ERR_load_KDF_strings \
966                 EVP_PBE_scrypt \
967                 EVP_sha3_256 \
968                 SSL_CIPHER_find \
969                 SSL_CTX_set1_groups_list \
970                 SSL_CTX_set_security_level \
971                 SSL_SESSION_get_master_key \
972                 SSL_get_client_ciphers \
973                 SSL_get_client_random \
974                 SSL_get_server_random \
975                 TLS_method \
976                ])
978 dnl Check if OpenSSL structures are opaque
979 AC_CHECK_MEMBERS([SSL.state], , ,
980 [#include <openssl/ssl.h>
983 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
984 #include <openssl/sha.h>
987 fi # enable_nss
989 dnl We will someday make KECCAK_TINY optional, but for now we still need
990 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
991 dnl once.  See comment in the definition of crypto_xof_t.
993 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
994 dnl   test "x$ac_cv_func_EVP_sha3_256" != "xyes")
996 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
998 dnl ======================================================================
999 dnl Can we use KIST?
1001 dnl Define the set of checks for KIST scheduler support.
1002 AC_DEFUN([CHECK_KIST_SUPPORT],[
1003   dnl KIST needs struct tcp_info and for certain members to exist.
1004   AC_CHECK_MEMBERS(
1005     [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1006     , ,[[#include <netinet/tcp.h>]])
1007   dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1008   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1009                      #include <linux/sockios.h>
1010                      #ifndef SIOCOUTQNSD
1011                      #error
1012                      #endif
1013                      ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1014   if test "x$have_siocoutqnsd" = "xyes"; then
1015     if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1016       if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1017         have_kist_support=yes
1018       fi
1019     fi
1020   fi
1022 dnl Now, trigger the check.
1023 CHECK_KIST_SUPPORT
1024 AS_IF([test "x$have_kist_support" = "xyes"],
1025       [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1026                                         on this system])],
1027       [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1029 LIBS="$save_LIBS"
1030 LDFLAGS="$save_LDFLAGS"
1031 CPPFLAGS="$save_CPPFLAGS"
1033 dnl ------------------------------------------------------
1034 dnl Where do you live, zlib?  And how do we call you?
1036 tor_zlib_pkg_redhat="zlib"
1037 tor_zlib_pkg_debian="zlib1g"
1038 tor_zlib_devpkg_redhat="zlib-devel"
1039 tor_zlib_devpkg_debian="zlib1g-dev"
1041 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1042     [#include <zlib.h>],
1043     [const char * zlibVersion(void);],
1044     [zlibVersion();], [--with-zlib-dir],
1045     [/opt/zlib])
1047 if test "$enable_static_zlib" = "yes"; then
1048    if test "$tor_cv_library_zlib_dir" = "(system)"; then
1049      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1050  using --enable-static-zlib")
1051    else
1052      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1053    fi
1054 else
1055      TOR_ZLIB_LIBS="-lz"
1057 AC_SUBST(TOR_ZLIB_LIBS)
1059 dnl ------------------------------------------------------
1060 dnl Where we do we find lzma?
1062 AC_ARG_ENABLE(lzma,
1063       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1064       [case "${enableval}" in
1065         "yes") lzma=true ;;
1066         "no")  lzma=false ;;
1067         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1068       esac], [lzma=auto])
1070 if test "x$enable_lzma" = "xno"; then
1071     have_lzma=no;
1072 else
1073     PKG_CHECK_MODULES([LZMA],
1074                       [liblzma],
1075                       have_lzma=yes,
1076                       have_lzma=no)
1078     if test "x$have_lzma" = "xno" ; then
1079         AC_MSG_WARN([Unable to find liblzma.])
1080     fi
1083 if test "x$have_lzma" = "xyes"; then
1084     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1085     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1086     TOR_LZMA_LIBS="${LZMA_LIBS}"
1088 AC_SUBST(TOR_LZMA_CFLAGS)
1089 AC_SUBST(TOR_LZMA_LIBS)
1091 dnl ------------------------------------------------------
1092 dnl Where we do we find zstd?
1094 AC_ARG_ENABLE(zstd,
1095       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1096       [case "${enableval}" in
1097         "yes") zstd=true ;;
1098         "no")  zstd=false ;;
1099         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1100       esac], [zstd=auto])
1102 if test "x$enable_zstd" = "xno"; then
1103     have_zstd=no;
1104 else
1105     PKG_CHECK_MODULES([ZSTD],
1106                       [libzstd >= 1.1],
1107                       have_zstd=yes,
1108                       have_zstd=no)
1110     if test "x$have_zstd" = "xno" ; then
1111         AC_MSG_WARN([Unable to find libzstd.])
1112     fi
1115 if test "x$have_zstd" = "xyes"; then
1116     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1117     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1118     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1120     dnl now check for zstd functions
1121     save_LIBS="$LIBS"
1122     save_CFLAGS="$CFLAGS"
1123     LIBS="$LIBS $ZSTD_LIBS"
1124     CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1125     AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1126                    ZSTD_estimateDCtxSize)
1127     LIBS="$save_LIBS"
1128     CFLAGS="$save_CFLAGS"
1130 AC_SUBST(TOR_ZSTD_CFLAGS)
1131 AC_SUBST(TOR_ZSTD_LIBS)
1133 dnl ----------------------------------------------------------------------
1134 dnl Check if libcap is available for capabilities.
1136 tor_cap_pkg_debian="libcap2"
1137 tor_cap_pkg_redhat="libcap"
1138 tor_cap_devpkg_debian="libcap-dev"
1139 tor_cap_devpkg_redhat="libcap-devel"
1141 AC_CHECK_LIB([cap], [cap_init], [],
1142   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1144 AC_CHECK_FUNCS(cap_set_proc)
1146 dnl ---------------------------------------------------------------------
1147 dnl Now that we know about our major libraries, we can check for compiler
1148 dnl and linker hardening options.  We need to do this with the libraries known,
1149 dnl since sometimes the linker will like an option but not be willing to
1150 dnl use it with a build of a library.
1152 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1153 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"
1155 CFLAGS_FTRAPV=
1156 CFLAGS_FWRAPV=
1157 CFLAGS_ASAN=
1158 CFLAGS_UBSAN=
1161 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1162 #if !defined(__clang__)
1163 #error
1164 #endif])], have_clang=yes, have_clang=no)
1166 if test "x$enable_pic" = "xyes"; then
1167     TOR_CHECK_CFLAGS(-fPIC)
1170 if test "x$enable_gcc_hardening" != "xno"; then
1171     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1172     if test "x$have_clang" = "xyes"; then
1173         TOR_CHECK_CFLAGS(-Qunused-arguments)
1174     fi
1175     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1176     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1177     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1178 m4_ifdef([AS_VAR_IF],[
1179     AS_VAR_IF(can_compile, [yes],
1180         AS_VAR_IF(can_link, [yes],
1181                   [],
1182                   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.)]))
1183         )])
1184     AS_VAR_POPDEF([can_link])
1185     AS_VAR_POPDEF([can_compile])
1186     TOR_CHECK_CFLAGS(-Wstack-protector)
1187     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1188     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1189        if test "$enable_pic" != "yes"; then
1190            # If we have already enabled -fPIC, then we don't also need to
1191            # compile with -fPIE...
1192            TOR_CHECK_CFLAGS(-fPIE)
1193        fi
1194        # ... but we want to link our executables with -pie in any case, since
1195        # they're executables, not a library.
1196        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1197     fi
1198     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1200    AC_MSG_CHECKING([whether we can run hardened binaries])
1201    AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1202         [AC_MSG_RESULT([yes])],
1203         [AC_MSG_RESULT([no])
1204          AC_MSG_ERROR([dnl
1205  We can link with compiler hardening options, but we can't run with them.
1206  That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1207  configure, but it would be better to figure out what the underlying problem
1208  is.])],
1209         [AC_MSG_RESULT([cross])])
1212 if test "$fragile_hardening" = "yes"; then
1213     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1214    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1215       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.])
1216    fi
1218    if test "$tor_cv_cflags__ftrapv" != "yes"; then
1219      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1220    fi
1222    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1223     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1224       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*])
1225     fi
1227    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1228     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1229       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*])
1230     fi
1232    TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1233     if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1234       AC_MSG_ERROR([The compiler supports -fno-sanitize=float-divide-by-zero, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.*, and with Clang you need libclang_rt.ubsan*])
1235     fi
1237 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1240 dnl Find the correct libraries to add in order to use the sanitizers.
1242 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1243 dnl option, which will prevent the compiler from linking the sanitizer
1244 dnl libraries it needs.  We need to specify them manually.
1246 dnl What's more, we need to specify them in a linker script rather than
1247 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1248 dnl variable.
1249 RUST_LINKER_OPTIONS=""
1250 if test "x$have_clang" = "xyes"; then
1251         if test "x$CFLAGS_ASAN" != "x"; then
1252                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
1253         fi
1254         if test "x$CFLAGS_UBSAN" != "x"; then
1255                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
1256         fi
1257 else
1258         if test "x$CFLAGS_ASAN" != "x"; then
1259                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
1260         fi
1261         if test "x$CFLAGS_UBSAN" != "x"; then
1262                 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
1263         fi
1265 AC_SUBST(RUST_LINKER_OPTIONS)
1267 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1268 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1270 mulodi_fixes_ftrapv=no
1271 if test "$have_clang" = "yes"; then
1272   saved_CFLAGS="$CFLAGS"
1273   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1274   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1275   AC_LINK_IFELSE([
1276       AC_LANG_SOURCE([[
1277           #include <stdint.h>
1278           #include <stdlib.h>
1279           int main(int argc, char **argv)
1280           {
1281             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1282                         * (int64_t)atoi(argv[3]);
1283             return x == 9;
1284           } ]])],
1285           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1286           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1287   if test "$ftrapv_can_link" = "no"; then
1288     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1289     AC_LINK_IFELSE([
1290       AC_LANG_SOURCE([[
1291           #include <stdint.h>
1292           #include <stdlib.h>
1293           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1294              *overflow=0;
1295              return a;
1296           }
1297           int main(int argc, char **argv)
1298           {
1299             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1300                         * (int64_t)atoi(argv[3]);
1301             return x == 9;
1302           } ]])],
1303           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1304           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1305   fi
1306   CFLAGS="$saved_CFLAGS"
1309 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1311 dnl These cflags add bunches of branches, and we haven't been able to
1312 dnl persuade ourselves that they're suitable for code that needs to be
1313 dnl constant time.
1314 AC_SUBST(CFLAGS_BUGTRAP)
1315 dnl These cflags are variant ones sutable for code that needs to be
1316 dnl constant-time.
1317 AC_SUBST(CFLAGS_CONSTTIME)
1319 if test "x$enable_linker_hardening" != "xno"; then
1320     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1323 # For backtrace support
1324 TOR_CHECK_LDFLAGS(-rdynamic)
1326 dnl ------------------------------------------------------
1327 dnl Now see if we have a -fomit-frame-pointer compiler option.
1329 saved_CFLAGS="$CFLAGS"
1330 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1331 F_OMIT_FRAME_POINTER=''
1332 if test "$saved_CFLAGS" != "$CFLAGS"; then
1333   if test "$fragile_hardening" = "yes"; then
1334     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1335   fi
1337 CFLAGS="$saved_CFLAGS"
1338 AC_SUBST(F_OMIT_FRAME_POINTER)
1340 dnl ------------------------------------------------------
1341 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1342 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1343 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1344 dnl code will work.
1345 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1347 dnl ============================================================
1348 dnl Check for libseccomp
1350 if test "x$enable_seccomp" != "xno"; then
1351   AC_CHECK_HEADERS([seccomp.h])
1352   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1355 dnl ============================================================
1356 dnl Check for libscrypt
1358 if test "x$enable_libscrypt" != "xno"; then
1359   AC_CHECK_HEADERS([libscrypt.h])
1360   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1361   AC_CHECK_FUNCS([libscrypt_scrypt])
1364 dnl ============================================================
1365 dnl We need an implementation of curve25519.
1367 dnl set these defaults.
1368 build_curve25519_donna=no
1369 build_curve25519_donna_c64=no
1370 use_curve25519_donna=no
1371 use_curve25519_nacl=no
1372 CURVE25519_LIBS=
1374 dnl The best choice is using curve25519-donna-c64, but that requires
1375 dnl that we
1376 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1377   tor_cv_can_use_curve25519_donna_c64,
1378   [AC_RUN_IFELSE(
1379     [AC_LANG_PROGRAM([dnl
1380       #include <stdint.h>
1381       typedef unsigned uint128_t __attribute__((mode(TI)));
1382   int func(uint64_t a, uint64_t b) {
1383            uint128_t c = ((uint128_t)a) * b;
1384            int ok = ((uint64_t)(c>>96)) == 522859 &&
1385              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1386                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1387                  (((uint64_t)(c))&0xffffffffL) == 0;
1388            return ok;
1389       }
1390   ], [dnl
1391     int ok = func( ((uint64_t)2000000000) * 1000000000,
1392                    ((uint64_t)1234567890) << 24);
1393         return !ok;
1394       ])],
1395   [tor_cv_can_use_curve25519_donna_c64=yes],
1396       [tor_cv_can_use_curve25519_donna_c64=no],
1397   [AC_LINK_IFELSE(
1398         [AC_LANG_PROGRAM([dnl
1399       #include <stdint.h>
1400       typedef unsigned uint128_t __attribute__((mode(TI)));
1401   int func(uint64_t a, uint64_t b) {
1402            uint128_t c = ((uint128_t)a) * b;
1403            int ok = ((uint64_t)(c>>96)) == 522859 &&
1404              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1405                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1406                  (((uint64_t)(c))&0xffffffffL) == 0;
1407            return ok;
1408       }
1409   ], [dnl
1410     int ok = func( ((uint64_t)2000000000) * 1000000000,
1411                  ((uint64_t)1234567890) << 24);
1412         return !ok;
1413       ])],
1414           [tor_cv_can_use_curve25519_donna_c64=cross],
1415       [tor_cv_can_use_curve25519_donna_c64=no])])])
1417 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1418                   nacl/crypto_scalarmult_curve25519.h])
1420 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1421   tor_cv_can_use_curve25519_nacl,
1422   [tor_saved_LIBS="$LIBS"
1423    LIBS="$LIBS -lnacl"
1424    AC_LINK_IFELSE(
1425      [AC_LANG_PROGRAM([dnl
1426        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1427        #include <crypto_scalarmult_curve25519.h>
1428    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1429    #include <nacl/crypto_scalarmult_curve25519.h>
1430    #endif
1431        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1432    #error Hey, this is the reference implementation! That's not fast.
1433    #endif
1434      ], [
1435    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1436      ])], [tor_cv_can_use_curve25519_nacl=yes],
1437      [tor_cv_can_use_curve25519_nacl=no])
1438    LIBS="$tor_saved_LIBS" ])
1440  dnl Okay, now we need to figure out which one to actually use. Fall back
1441  dnl to curve25519-donna.c
1443  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1444    build_curve25519_donna_c64=yes
1445    use_curve25519_donna=yes
1446  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1447    use_curve25519_nacl=yes
1448    CURVE25519_LIBS=-lnacl
1449  else
1450    build_curve25519_donna=yes
1451    use_curve25519_donna=yes
1452  fi
1454 if test "x$use_curve25519_donna" = "xyes"; then
1455   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1456             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1458 if test "x$use_curve25519_nacl" = "xyes"; then
1459   AC_DEFINE(USE_CURVE25519_NACL, 1,
1460             [Defined if we should use a curve25519 from nacl])
1462 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1463   test "x$build_curve25519_donna" = "xyes")
1464 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1465   test "x$build_curve25519_donna_c64" = "xyes")
1466 AC_SUBST(CURVE25519_LIBS)
1468 dnl Make sure to enable support for large off_t if available.
1469 AC_SYS_LARGEFILE
1471 AC_CHECK_HEADERS([errno.h \
1472                   fcntl.h \
1473                   signal.h \
1474                   string.h \
1475                   sys/capability.h \
1476                   sys/fcntl.h \
1477                   sys/stat.h \
1478                   sys/time.h \
1479                   sys/types.h \
1480                   time.h \
1481                   unistd.h \
1482                   arpa/inet.h \
1483                   crt_externs.h \
1484                   execinfo.h \
1485                   gnu/libc-version.h \
1486                   grp.h \
1487                   ifaddrs.h \
1488                   inttypes.h \
1489                   limits.h \
1490                   linux/types.h \
1491                   mach/vm_inherit.h \
1492                   machine/limits.h \
1493                   malloc.h \
1494                   malloc/malloc.h \
1495                   malloc_np.h \
1496                   netdb.h \
1497                   netinet/in.h \
1498                   netinet/in6.h \
1499                   pwd.h \
1500                   readpassphrase.h \
1501                   stdatomic.h \
1502                   sys/eventfd.h \
1503                   sys/file.h \
1504                   sys/ioctl.h \
1505                   sys/limits.h \
1506                   sys/mman.h \
1507                   sys/param.h \
1508                   sys/prctl.h \
1509                   sys/random.h \
1510                   sys/resource.h \
1511                   sys/select.h \
1512                   sys/socket.h \
1513                   sys/statvfs.h \
1514                   sys/syscall.h \
1515                   sys/sysctl.h \
1516                   sys/syslimits.h \
1517                   sys/time.h \
1518                   sys/types.h \
1519                   sys/un.h \
1520                   sys/utime.h \
1521                   sys/wait.h \
1522                   syslog.h \
1523                   utime.h])
1525 AC_CHECK_HEADERS(sys/param.h)
1527 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1528 [#ifdef HAVE_SYS_TYPES_H
1529 #include <sys/types.h>
1530 #endif
1531 #ifdef HAVE_SYS_SOCKET_H
1532 #include <sys/socket.h>
1533 #endif])
1534 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1535 [#ifdef HAVE_SYS_TYPES_H
1536 #include <sys/types.h>
1537 #endif
1538 #ifdef HAVE_SYS_SOCKET_H
1539 #include <sys/socket.h>
1540 #endif
1541 #ifdef HAVE_NET_IF_H
1542 #include <net/if.h>
1543 #endif
1544 #ifdef HAVE_NETINET_IN_H
1545 #include <netinet/in.h>
1546 #endif])
1548 AC_CHECK_HEADERS(linux/if.h,[],[],
1550 #ifdef HAVE_SYS_SOCKET_H
1551 #include <sys/socket.h>
1552 #endif
1555 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1556         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1557 [#ifdef HAVE_SYS_TYPES_H
1558 #include <sys/types.h>
1559 #endif
1560 #ifdef HAVE_SYS_SOCKET_H
1561 #include <sys/socket.h>
1562 #endif
1563 #ifdef HAVE_LIMITS_H
1564 #include <limits.h>
1565 #endif
1566 #ifdef HAVE_LINUX_TYPES_H
1567 #include <linux/types.h>
1568 #endif
1569 #ifdef HAVE_NETINET_IN6_H
1570 #include <netinet/in6.h>
1571 #endif
1572 #ifdef HAVE_NETINET_IN_H
1573 #include <netinet/in.h>
1574 #endif])
1576 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1577         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1578 [#ifdef HAVE_SYS_TYPES_H
1579 #include <sys/types.h>
1580 #endif
1581 #ifdef HAVE_SYS_SOCKET_H
1582 #include <sys/socket.h>
1583 #endif
1584 #ifdef HAVE_LIMITS_H
1585 #include <limits.h>
1586 #endif
1587 #ifdef HAVE_LINUX_TYPES_H
1588 #include <linux/types.h>
1589 #endif
1590 #ifdef HAVE_NETINET_IN6_H
1591 #include <netinet/in6.h>
1592 #endif
1593 #ifdef HAVE_NETINET_IN_H
1594 #include <netinet/in.h>
1595 #endif
1596 #ifdef HAVE_LINUX_IF_H
1597 #include <linux/if.h>
1598 #endif])
1600 transparent_ok=0
1601 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1602   transparent_ok=1
1604 if test "x$linux_netfilter_ipv4" = "x1"; then
1605   transparent_ok=1
1607 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1608   transparent_ok=1
1610 if test "x$transparent_ok" = "x1"; then
1611   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1612 else
1613   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1616 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1617 [#ifdef HAVE_SYS_TYPES_H
1618 #include <sys/types.h>
1619 #endif
1620 #ifdef HAVE_SYS_TIME_H
1621 #include <sys/time.h>
1622 #endif])
1624 AC_CHECK_SIZEOF(char)
1625 AC_CHECK_SIZEOF(short)
1626 AC_CHECK_SIZEOF(int)
1627 AC_CHECK_SIZEOF(unsigned int)
1628 AC_CHECK_SIZEOF(long)
1629 AC_CHECK_SIZEOF(long long)
1630 AC_CHECK_SIZEOF(__int64)
1631 AC_CHECK_SIZEOF(void *)
1632 AC_CHECK_SIZEOF(time_t)
1633 AC_CHECK_SIZEOF(size_t)
1634 AC_CHECK_SIZEOF(pid_t)
1636 AC_CHECK_TYPES([uint, u_char, ssize_t])
1638 AC_PC_FROM_UCONTEXT([:])
1640 dnl used to include sockaddr_storage, but everybody has that.
1641 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1642 [#ifdef HAVE_SYS_TYPES_H
1643 #include <sys/types.h>
1644 #endif
1645 #ifdef HAVE_NETINET_IN_H
1646 #include <netinet/in.h>
1647 #endif
1648 #ifdef HAVE_NETINET_IN6_H
1649 #include <netinet/in6.h>
1650 #endif
1651 #ifdef HAVE_SYS_SOCKET_H
1652 #include <sys/socket.h>
1653 #endif
1654 #ifdef _WIN32
1655 #define _WIN32_WINNT 0x0501
1656 #define WIN32_LEAN_AND_MEAN
1657 #include <winsock2.h>
1658 #include <ws2tcpip.h>
1659 #endif
1661 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1662 [#ifdef HAVE_SYS_TYPES_H
1663 #include <sys/types.h>
1664 #endif
1665 #ifdef HAVE_NETINET_IN_H
1666 #include <netinet/in.h>
1667 #endif
1668 #ifdef HAVE_NETINET_IN6_H
1669 #include <netinet/in6.h>
1670 #endif
1671 #ifdef HAVE_SYS_SOCKET_H
1672 #include <sys/socket.h>
1673 #endif
1674 #ifdef _WIN32
1675 #define _WIN32_WINNT 0x0501
1676 #define WIN32_LEAN_AND_MEAN
1677 #include <winsock2.h>
1678 #include <ws2tcpip.h>
1679 #endif
1682 AC_CHECK_TYPES([rlim_t], , ,
1683 [#ifdef HAVE_SYS_TYPES_H
1684 #include <sys/types.h>
1685 #endif
1686 #ifdef HAVE_SYS_TIME_H
1687 #include <sys/time.h>
1688 #endif
1689 #ifdef HAVE_SYS_RESOURCE_H
1690 #include <sys/resource.h>
1691 #endif
1694 AX_CHECK_SIGN([time_t],
1695        [ : ],
1696        [ : ], [
1697 #ifdef HAVE_SYS_TYPES_H
1698 #include <sys/types.h>
1699 #endif
1700 #ifdef HAVE_SYS_TIME_H
1701 #include <sys/time.h>
1702 #endif
1703 #ifdef HAVE_TIME_H
1704 #include <time.h>
1705 #endif
1708 if test "$ax_cv_decl_time_t_signed" = "no"; then
1709   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1712 AX_CHECK_SIGN([size_t],
1713        [ tor_cv_size_t_signed=yes ],
1714        [ tor_cv_size_t_signed=no ], [
1715 #ifdef HAVE_SYS_TYPES_H
1716 #include <sys/types.h>
1717 #endif
1720 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1721   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1724 AX_CHECK_SIGN([enum always],
1725        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1726        [ : ], [
1727  enum always { AAA, BBB, CCC };
1730 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1731 #ifdef HAVE_SYS_SOCKET_H
1732 #include <sys/socket.h>
1733 #endif
1736 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1738 AC_CHECK_SIZEOF(cell_t)
1740 # Let's see if stdatomic works. (There are some debian clangs that screw it
1741 # up; see Tor bug #26779 and debian bug 903709.)
1742 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1743                tor_cv_stdatomic_works,
1744 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1745 #include <stdatomic.h>
1746 struct x { atomic_size_t y; };
1747 void try_atomic_init(struct x *xx)
1749   atomic_init(&xx->y, 99);
1750   atomic_fetch_add(&xx->y, 1);
1752 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1754 if test "$tor_cv_stdatomic_works" = "yes"; then
1755    AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1756 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1757    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 ])
1760 # Now make sure that NULL can be represented as zero bytes.
1761 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1762 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1763 [[#include <stdlib.h>
1764 #include <string.h>
1765 #include <stdio.h>
1766 #ifdef HAVE_STDDEF_H
1767 #include <stddef.h>
1768 #endif
1769 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1770 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1771        [tor_cv_null_is_zero=yes],
1772        [tor_cv_null_is_zero=no],
1773        [tor_cv_null_is_zero=cross])])
1775 if test "$tor_cv_null_is_zero" = "cross"; then
1776   # Cross-compiling; let's hope that the target isn't raving mad.
1777   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1780 if test "$tor_cv_null_is_zero" != "no"; then
1781   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1782             [Define to 1 iff memset(0) sets pointers to NULL])
1785 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1786 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1787 [[#include <stdlib.h>
1788 #include <string.h>
1789 #include <stdio.h>
1790 #ifdef HAVE_STDDEF_H
1791 #include <stddef.h>
1792 #endif
1793 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1794 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1795        [tor_cv_dbl0_is_zero=yes],
1796        [tor_cv_dbl0_is_zero=no],
1797        [tor_cv_dbl0_is_zero=cross])])
1799 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1800   # Cross-compiling; let's hope that the target isn't raving mad.
1801   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1804 if test "$tor_cv_dbl0_is_zero" != "no"; then
1805   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1806             [Define to 1 iff memset(0) sets doubles to 0.0])
1809 # And what happens when we malloc zero?
1810 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1811 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1812 [[#include <stdlib.h>
1813 #include <string.h>
1814 #include <stdio.h>
1815 #ifdef HAVE_STDDEF_H
1816 #include <stddef.h>
1817 #endif
1818 int main () { return malloc(0)?0:1; }]])],
1819        [tor_cv_malloc_zero_works=yes],
1820        [tor_cv_malloc_zero_works=no],
1821        [tor_cv_malloc_zero_works=cross])])
1823 if test "$tor_cv_malloc_zero_works" = "cross"; then
1824   # Cross-compiling; let's hope that the target isn't raving mad.
1825   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1828 if test "$tor_cv_malloc_zero_works" = "yes"; then
1829   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1830             [Define to 1 iff malloc(0) returns a pointer])
1833 # whether we seem to be in a 2s-complement world.
1834 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1835 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1836 [[int main () { int problem = ((-99) != (~99)+1);
1837 return problem ? 1 : 0; }]])],
1838        [tor_cv_twos_complement=yes],
1839        [tor_cv_twos_complement=no],
1840        [tor_cv_twos_complement=cross])])
1842 if test "$tor_cv_twos_complement" = "cross"; then
1843   # Cross-compiling; let's hope that the target isn't raving mad.
1844   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1847 if test "$tor_cv_twos_complement" != "no"; then
1848   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1849             [Define to 1 iff we represent negative integers with
1850              two's complement])
1853 # What does shifting a negative value do?
1854 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1855 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1856 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1857        [tor_cv_sign_extend=yes],
1858        [tor_cv_sign_extend=no],
1859        [tor_cv_sign_extend=cross])])
1861 if test "$tor_cv_sign_extend" = "cross"; then
1862   # Cross-compiling; let's hope that the target isn't raving mad.
1863   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1866 if test "$tor_cv_sign_extend" != "no"; then
1867   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1868             [Define to 1 iff right-shifting a negative value performs sign-extension])
1871 # Is uint8_t the same type as unsigned char?
1872 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1873 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1874 #include <stdint.h>
1875 extern uint8_t c;
1876 unsigned char c;]])],
1877        [tor_cv_uint8_uchar=yes],
1878        [tor_cv_uint8_uchar=no],
1879        [tor_cv_uint8_uchar=cross])])
1881 if test "$tor_cv_uint8_uchar" = "cross"; then
1882   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1885 if test "$tor_cv_uint8_uchar" = "no"; then
1886   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1889 AC_ARG_WITH(tcmalloc,
1890 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]),
1891 [ tcmalloc=yes ], [ tcmalloc=no ])
1893 default_malloc=system
1895 if test "x$enable_openbsd_malloc" = "xyes" ; then
1896   AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
1897   default_malloc=openbsd
1900 if test "x$tcmalloc" = "xyes"; then
1901   AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
1902   default_malloc=tcmalloc
1905 AC_ARG_WITH(malloc,
1906    AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
1907                   [select special malloc implementation [system]]),
1908    [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
1910 AS_CASE([$malloc],
1911   [tcmalloc], [
1912       PKG_CHECK_MODULES([TCMALLOC],
1913                         [libtcmalloc],
1914                         have_tcmalloc=yes,
1915                         have_tcmalloc=no)
1917       if test "x$have_tcmalloc" = "xno" ; then
1918           AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc.])
1919       fi
1921       CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
1922       LIBS="$TCMALLOC_LIBS $LIBS"
1923   ],
1925   [jemalloc], [
1926       PKG_CHECK_MODULES([JEMALLOC],
1927                         [jemalloc],
1928                         have_jemalloc=yes,
1929                         have_jemalloc=no)
1931       if test "x$have_tcmalloc" = "xno" ; then
1932           AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc.])
1933       fi
1935       CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
1936       LIBS="$JEMALLOC_LIBS $LIBS"
1937       using_custom_malloc=yes
1938   ],
1940   [openbsd], [
1941     AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
1942     enable_openbsd_malloc=yes
1943   ],
1945   [system], [
1946      # handle this later, including the jemalloc fallback
1947     AC_CHECK_FUNCS(mallinfo)
1948   ],
1950   [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
1953 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
1955 if test "$malloc" != "system"; then
1956   # Tell the C compiler not to use the system allocator functions.
1957   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1959 if test "$using_custom_malloc" = "yes"; then
1960   # Tell the C compiler not to use the system allocator functions.
1961   TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1964 # By default, we're going to assume we don't have mlockall()
1965 # bionic and other platforms have various broken mlockall subsystems.
1966 # Some systems don't have a working mlockall, some aren't linkable,
1967 # and some have it but don't declare it.
1968 AC_CHECK_FUNCS(mlockall)
1969 AC_CHECK_DECLS([mlockall], , , [
1970 #ifdef HAVE_SYS_MMAN_H
1971 #include <sys/mman.h>
1972 #endif])
1974 # Allow user to specify an alternate syslog facility
1975 AC_ARG_WITH(syslog-facility,
1976 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1977 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1978 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1979 AC_SUBST(LOGFACILITY)
1981 # Check if we have getresuid and getresgid
1982 AC_CHECK_FUNCS(getresuid getresgid)
1984 # Check for gethostbyname_r in all its glorious incompatible versions.
1985 #   (This logic is based on that in Python's configure.in)
1986 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1987   [Define this if you have any gethostbyname_r()])
1989 AC_CHECK_FUNC(gethostbyname_r, [
1990   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1991   OLD_CFLAGS=$CFLAGS
1992   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1993   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1994 #include <netdb.h>
1995   ]], [[
1996     char *cp1, *cp2;
1997     struct hostent *h1, *h2;
1998     int i1, i2;
1999     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2000   ]])],[
2001     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2002     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2003      [Define this if gethostbyname_r takes 6 arguments])
2004     AC_MSG_RESULT(6)
2005   ], [
2006     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2007 #include <netdb.h>
2008     ]], [[
2009       char *cp1, *cp2;
2010       struct hostent *h1;
2011       int i1, i2;
2012       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2013     ]])], [
2014       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2015       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2016         [Define this if gethostbyname_r takes 5 arguments])
2017       AC_MSG_RESULT(5)
2018    ], [
2019       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2020 #include <netdb.h>
2021      ]], [[
2022        char *cp1;
2023        struct hostent *h1;
2024        struct hostent_data hd;
2025        (void) gethostbyname_r(cp1,h1,&hd);
2026      ]])], [
2027        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2028        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2029          [Define this if gethostbyname_r takes 3 arguments])
2030        AC_MSG_RESULT(3)
2031      ], [
2032        AC_MSG_RESULT(0)
2033      ])
2034   ])
2035  ])
2036  CFLAGS=$OLD_CFLAGS
2039 AC_CACHE_CHECK([whether the C compiler supports __func__],
2040   tor_cv_have_func_macro,
2041   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2042 #include <stdio.h>
2043 int main(int c, char **v) { puts(__func__); }])],
2044   tor_cv_have_func_macro=yes,
2045   tor_cv_have_func_macro=no))
2047 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2048   tor_cv_have_FUNC_macro,
2049   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2050 #include <stdio.h>
2051 int main(int c, char **v) { puts(__FUNC__); }])],
2052   tor_cv_have_FUNC_macro=yes,
2053   tor_cv_have_FUNC_macro=no))
2055 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2056   tor_cv_have_FUNCTION_macro,
2057   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2058 #include <stdio.h>
2059 int main(int c, char **v) { puts(__FUNCTION__); }])],
2060   tor_cv_have_FUNCTION_macro=yes,
2061   tor_cv_have_FUNCTION_macro=no))
2063 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2064   tor_cv_have_environ_declared,
2065   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2066 #ifdef HAVE_UNISTD_H
2067 #include <unistd.h>
2068 #endif
2069 #include <stdlib.h>
2070 int main(int c, char **v) { char **t = environ; }])],
2071   tor_cv_have_environ_declared=yes,
2072   tor_cv_have_environ_declared=no))
2074 if test "$tor_cv_have_func_macro" = "yes"; then
2075   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2078 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2079   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2082 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2083   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2084            [Defined if the compiler supports __FUNCTION__])
2087 if test "$tor_cv_have_environ_declared" = "yes"; then
2088   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2089            [Defined if we have extern char **environ already declared])
2092 # $prefix stores the value of the --prefix command line option, or
2093 # NONE if the option wasn't set.  In the case that it wasn't set, make
2094 # it be the default, so that we can use it to expand directories now.
2095 if test "x$prefix" = "xNONE"; then
2096   prefix=$ac_default_prefix
2099 # and similarly for $exec_prefix
2100 if test "x$exec_prefix" = "xNONE"; then
2101   exec_prefix=$prefix
2104 if test "x$BUILDDIR" = "x"; then
2105   BUILDDIR=`pwd`
2107 AC_SUBST(BUILDDIR)
2108 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2109 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2111 if test "x$SRCDIR" = "x"; then
2112   SRCDIR=$(cd "$srcdir"; pwd)
2114 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2115 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2117 if test "x$CONFDIR" = "x"; then
2118   CONFDIR=`eval echo $sysconfdir/tor`
2120 AC_SUBST(CONFDIR)
2121 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2122 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2124 BINDIR=`eval echo $bindir`
2125 AC_SUBST(BINDIR)
2126 LOCALSTATEDIR=`eval echo $localstatedir`
2127 AC_SUBST(LOCALSTATEDIR)
2129 if test "$bwin32" = "true"; then
2130   # Test if the linker supports the --nxcompat and --dynamicbase options
2131   # for Windows
2132   save_LDFLAGS="$LDFLAGS"
2133   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2134   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2135   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2136     [AC_MSG_RESULT([yes])]
2137     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2138     [AC_MSG_RESULT([no])]
2139   )
2140   LDFLAGS="$save_LDFLAGS"
2143 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2144 # than autoconf's macros like.
2145 if test "$GCC" = "yes"; then
2146   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
2147   # accident waiting to happen.
2148   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2149 else
2150   # Override optimization level for non-gcc compilers
2151   CFLAGS="$CFLAGS -O"
2152   enable_gcc_warnings=no
2153   enable_gcc_warnings_advisory=no
2156 # Warnings implies advisory-warnings and -Werror.
2157 if test "$enable_gcc_warnings" = "yes"; then
2158   enable_gcc_warnings_advisory=yes
2159   enable_fatal_warnings=yes
2162 # OS X Lion started deprecating the system openssl. Let's just disable
2163 # all deprecation warnings on OS X. Also, to potentially make the binary
2164 # a little smaller, let's enable dead_strip.
2165 case "$host_os" in
2167  darwin*)
2168     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2169     LDFLAGS="$LDFLAGS -dead_strip" ;;
2170 esac
2172 TOR_WARNING_FLAGS=""
2174 # Add some more warnings which we use in development but not in the
2175 # released versions.  (Some relevant gcc versions can't handle these.)
2177 # Note that we have to do this near the end  of the autoconf process, or
2178 # else we may run into problems when these warnings hit on the testing C
2179 # programs that autoconf wants to build.
2180 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2182   case "$host" in
2183     *-*-openbsd* | *-*-bitrig*)
2184       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2185       # That's fine, except that the headers don't pass -Wredundant-decls.
2186       # Therefore, let's disable -Wsystem-headers when we're building
2187       # with maximal warnings on OpenBSD.
2188       CFLAGS="$CFLAGS -Wno-system-headers" ;;
2189   esac
2191   CFLAGS_NOWARNINGS="$CFLAGS"
2193   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
2194   # have it work better.
2195   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2197   # This warning was added in gcc 4.3, but it appears to generate
2198   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
2199   #CFLAGS="$CFLAGS -Wlogical-op"
2201   m4_foreach_w([warning_flag], [
2202      -Waddress
2203      -Waddress-of-array-temporary
2204      -Waddress-of-temporary
2205      -Wambiguous-macro
2206      -Wanonymous-pack-parens
2207      -Warc
2208      -Warc-abi
2209      -Warc-bridge-casts-disallowed-in-nonarc
2210      -Warc-maybe-repeated-use-of-weak
2211      -Warc-performSelector-leaks
2212      -Warc-repeated-use-of-weak
2213      -Warray-bounds
2214      -Warray-bounds-pointer-arithmetic
2215      -Wasm
2216      -Wasm-operand-widths
2217      -Watomic-properties
2218      -Watomic-property-with-user-defined-accessor
2219      -Wauto-import
2220      -Wauto-storage-class
2221      -Wauto-var-id
2222      -Wavailability
2223      -Wbackslash-newline-escape
2224      -Wbad-array-new-length
2225      -Wbind-to-temporary-copy
2226      -Wbitfield-constant-conversion
2227      -Wbool-conversion
2228      -Wbool-conversions
2229      -Wbuiltin-requires-header
2230      -Wchar-align
2231      -Wcompare-distinct-pointer-types
2232      -Wcomplex-component-init
2233      -Wconditional-type-mismatch
2234      -Wconfig-macros
2235      -Wconstant-conversion
2236      -Wconstant-logical-operand
2237      -Wconstexpr-not-const
2238      -Wcustom-atomic-properties
2239      -Wdangling-field
2240      -Wdangling-initializer-list
2241      -Wdate-time
2242      -Wdelegating-ctor-cycles
2243      -Wdeprecated-implementations
2244      -Wdeprecated-register
2245      -Wdirect-ivar-access
2246      -Wdiscard-qual
2247      -Wdistributed-object-modifiers
2248      -Wdivision-by-zero
2249      -Wdollar-in-identifier-extension
2250      -Wdouble-promotion
2251      -Wduplicate-decl-specifier
2252      -Wduplicate-enum
2253      -Wduplicate-method-arg
2254      -Wduplicate-method-match
2255      -Wduplicated-cond
2256      -Wdynamic-class-memaccess
2257      -Wembedded-directive
2258      -Wempty-translation-unit
2259      -Wenum-conversion
2260      -Wexit-time-destructors
2261      -Wexplicit-ownership-type
2262      -Wextern-initializer
2263      -Wextra
2264      -Wextra-semi
2265      -Wextra-tokens
2266      -Wflexible-array-extensions
2267      -Wfloat-conversion
2268      -Wformat-non-iso
2269      -Wfour-char-constants
2270      -Wgcc-compat
2271      -Wglobal-constructors
2272      -Wgnu-array-member-paren-init
2273      -Wgnu-designator
2274      -Wgnu-static-float-init
2275      -Wheader-guard
2276      -Wheader-hygiene
2277      -Widiomatic-parentheses
2278      -Wignored-attributes
2279      -Wimplicit-atomic-properties
2280      -Wimplicit-conversion-floating-point-to-bool
2281      -Wimplicit-exception-spec-mismatch
2282      -Wimplicit-fallthrough
2283      -Wimplicit-fallthrough-per-function
2284      -Wimplicit-retain-self
2285      -Wimport-preprocessor-directive-pedantic
2286      -Wincompatible-library-redeclaration
2287      -Wincompatible-pointer-types-discards-qualifiers
2288      -Wincomplete-implementation
2289      -Wincomplete-module
2290      -Wincomplete-umbrella
2291      -Winit-self
2292      -Wint-conversions
2293      -Wint-to-void-pointer-cast
2294      -Winteger-overflow
2295      -Winvalid-constexpr
2296      -Winvalid-iboutlet
2297      -Winvalid-noreturn
2298      -Winvalid-pp-token
2299      -Winvalid-source-encoding
2300      -Winvalid-token-paste
2301      -Wknr-promoted-parameter
2302      -Wlarge-by-value-copy
2303      -Wliteral-conversion
2304      -Wliteral-range
2305      -Wlocal-type-template-args
2306      -Wlogical-op
2307      -Wloop-analysis
2308      -Wmain-return-type
2309      -Wmalformed-warning-check
2310      -Wmethod-signatures
2311      -Wmicrosoft
2312      -Wmicrosoft-exists
2313      -Wmismatched-parameter-types
2314      -Wmismatched-return-types
2315      -Wmissing-field-initializers
2316      -Wmissing-format-attribute
2317      -Wmissing-noreturn
2318      -Wmissing-selector-name
2319      -Wmissing-sysroot
2320      -Wmissing-variable-declarations
2321      -Wmodule-conflict
2322      -Wnested-anon-types
2323      -Wnewline-eof
2324      -Wnon-literal-null-conversion
2325      -Wnon-pod-varargs
2326      -Wnonportable-cfstrings
2327      -Wnormalized=nfkc
2328      -Wnull-arithmetic
2329      -Wnull-character
2330      -Wnull-conversion
2331      -Wnull-dereference
2332      -Wout-of-line-declaration
2333      -Wover-aligned
2334      -Woverlength-strings
2335      -Woverride-init
2336      -Woverriding-method-mismatch
2337      -Wpointer-type-mismatch
2338      -Wpredefined-identifier-outside-function
2339      -Wprotocol-property-synthesis-ambiguity
2340      -Wreadonly-iboutlet-property
2341      -Wreadonly-setter-attrs
2342      -Wreceiver-expr
2343      -Wreceiver-forward-class
2344      -Wreceiver-is-weak
2345      -Wreinterpret-base-class
2346      -Wrequires-super-attribute
2347      -Wreserved-user-defined-literal
2348      -Wreturn-stack-address
2349      -Wsection
2350      -Wselector-type-mismatch
2351      -Wsentinel
2352      -Wserialized-diagnostics
2353      -Wshadow
2354      -Wshift-count-negative
2355      -Wshift-count-overflow
2356      -Wshift-negative-value
2357      -Wshift-overflow=2
2358      -Wshift-sign-overflow
2359      -Wshorten-64-to-32
2360      -Wsizeof-array-argument
2361      -Wsource-uses-openmp
2362      -Wstatic-float-init
2363      -Wstatic-in-inline
2364      -Wstatic-local-in-inline
2365      -Wstrict-overflow=1
2366      -Wstring-compare
2367      -Wstring-conversion
2368      -Wstrlcpy-strlcat-size
2369      -Wstrncat-size
2370      -Wsuggest-attribute=format
2371      -Wsuggest-attribute=noreturn
2372      -Wsuper-class-method-mismatch
2373      -Wswitch-bool
2374      -Wsync-nand
2375      -Wtautological-constant-out-of-range-compare
2376      -Wtentative-definition-incomplete-type
2377      -Wtrampolines
2378      -Wtype-safety
2379      -Wtypedef-redefinition
2380      -Wtypename-missing
2381      -Wundefined-inline
2382      -Wundefined-internal
2383      -Wundefined-reinterpret-cast
2384      -Wunicode
2385      -Wunicode-whitespace
2386      -Wunknown-warning-option
2387      -Wunnamed-type-template-args
2388      -Wunneeded-member-function
2389      -Wunsequenced
2390      -Wunsupported-visibility
2391      -Wunused-but-set-parameter
2392      -Wunused-but-set-variable
2393      -Wunused-command-line-argument
2394      -Wunused-const-variable=2
2395      -Wunused-exception-parameter
2396      -Wunused-local-typedefs
2397      -Wunused-member-function
2398      -Wunused-sanitize-argument
2399      -Wunused-volatile-lvalue
2400      -Wuser-defined-literals
2401      -Wvariadic-macros
2402      -Wvector-conversion
2403      -Wvector-conversions
2404      -Wvexing-parse
2405      -Wvisibility
2406      -Wvla-extension
2407      -Wzero-length-array
2408   ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2409               [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2410      ])
2412 dnl    We should re-enable this in some later version.  Clang doesn't
2413 dnl    mind, but it causes trouble with GCC.
2414 dnl     -Wstrict-overflow=2
2416 dnl    These seem to require annotations that we don't currently use,
2417 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2418 dnl     -Wthread-safety
2419 dnl     -Wthread-safety-analysis
2420 dnl     -Wthread-safety-attributes
2421 dnl     -Wthread-safety-beta
2422 dnl     -Wthread-safety-precise
2424   W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2425   W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2426   W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2427   W_FLAGS="$W_FLAGS -Wwrite-strings"
2428   W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2429   W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2430   W_FLAGS="$W_FLAGS -Wunused-parameter "
2431   # These interfere with building main() { return 0; }, which autoconf
2432   # likes to use as its default program.
2433   W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2435   TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2436   CFLAGS="$CFLAGS $W_FLAGS"
2438   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2439     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2440   fi
2441   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2442     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2443   fi
2444   if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2445     AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2446   fi
2448   CFLAGS="$CFLAGS_NOWARNINGS"
2450   if test "x$enable_fatal_warnings" = "xyes"; then
2451     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2452     # default autoconf programs are full of errors.
2453     CFLAGS="$CFLAGS -Werror"
2454   fi
2458 AC_SUBST(TOR_WARNING_FLAGS)
2460 echo "$TOR_WARNING_FLAGS">warning_flags
2462 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2463                             CFLAGS="$CFLAGS @warning_flags",
2464                             CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2466 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2467    case "$host_os" in
2468     darwin*)
2469       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.])
2470    esac
2473 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2475 AC_CONFIG_FILES([
2476         Doxyfile
2477         Makefile
2478         config.rust
2479         contrib/operator-tools/tor.logrotate
2480         contrib/dist/tor.service
2481         src/config/torrc.sample
2482         src/config/torrc.minimal
2483         src/rust/.cargo/config
2484         scripts/maint/checkOptionDocs.pl
2485         warning_flags
2488 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2489   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2490   for file in $regular_mans ; do
2491     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2492       echo "==================================";
2493       echo;
2494       echo "Building Tor has failed since manpages cannot be built.";
2495       echo;
2496       echo "You need asciidoc installed to be able to build the manpages.";
2497       echo "To build without manpages, use the --disable-asciidoc argument";
2498       echo "when calling configure.";
2499       echo;
2500       echo "==================================";
2501       exit 1;
2502     fi
2503   done
2506 if test "$fragile_hardening" = "yes"; then
2507   AC_MSG_WARN([
2509 ============
2510 Warning!  Building Tor with --enable-fragile-hardening (also known as
2511 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2512 other kinds of attacks easier. A Tor instance build with this option will be
2513 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2514 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2515 denial of service attacks. For more information, see
2516 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
2517 ============
2518   ])
2521 AC_OUTPUT