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
7 AC_INIT([tor],[0.4.5.0-alpha-dev])
8 AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
9 AC_CONFIG_MACRO_DIR([m4])
13 # DO NOT EDIT THIS DEFINITION BY HAND UNLESS YOU KNOW WHAT YOU'RE DOING.
15 # The update_versions.py script updates this definition when the
16 # version number changes. Tor uses it to make sure that it
17 # only shuts down for missing "required protocols" when those protocols
18 # are listed as required by a consensus after this date.
19 AC_DEFINE(APPROX_RELEASE_DATE, ["2020-06-09"], # for 0.4.5.0-alpha-dev
20 [Approximate date when this software was released. (Updated when the version changes.)])
22 # "foreign" means we don't follow GNU package layout standards
23 # "1.11" means we require automake version 1.11 or newer
24 # "subdir-objects" means put .o files in the same directory as the .c files
25 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
27 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
28 AC_CONFIG_HEADERS([orconfig.h])
30 AC_USE_SYSTEM_EXTENSIONS
34 if test "x$PKG_CONFIG" = "x" ; then
35 pkg_config_user_action="install pkg-config, and check the PKG_CONFIG_PATH environment variable"
36 AC_MSG_NOTICE([Some libraries need pkg-config, including systemd, nss, lzma, zstd, and custom mallocs.])
37 AC_MSG_NOTICE([To use those libraries, $pkg_config_user_action.])
39 pkg_config_user_action="check the PKG_CONFIG_PATH environment variable"
42 if test "x$PKG_CONFIG_PATH" = "x" && test "x$prefix" != "xNONE" && test "$host" != "$build"; then
43 export PKG_CONFIG_PATH=$prefix/lib/pkgconfig
44 AC_MSG_NOTICE([set PKG_CONFIG_PATH=$PKG_CONFIG_PATH to support cross-compiling])
47 AC_ARG_ENABLE(openbsd-malloc,
48 AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only. Deprecated: see --with-malloc]))
49 AC_ARG_ENABLE(static-openssl,
50 AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
51 AC_ARG_ENABLE(static-libevent,
52 AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
53 AC_ARG_ENABLE(static-zlib,
54 AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
55 AC_ARG_ENABLE(static-tor,
56 AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
57 AC_ARG_ENABLE(unittests,
58 AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
59 AC_ARG_ENABLE(coverage,
60 AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
61 AC_ARG_ENABLE(asserts-in-tests,
62 AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
63 AC_ARG_ENABLE(system-torrc,
64 AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
65 AC_ARG_ENABLE(libfuzzer,
66 AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
67 AC_ARG_ENABLE(oss-fuzz,
68 AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
69 AC_ARG_ENABLE(memory-sentinels,
70 AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
72 AS_HELP_STRING(--enable-rust, [enable rust integration]))
73 AC_ARG_ENABLE(cargo-online-mode,
74 AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
75 AC_ARG_ENABLE(restart-debugging,
76 AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
77 AC_ARG_ENABLE(zstd-advanced-apis,
78 AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
80 AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
82 AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
84 AC_ARG_ENABLE(missing-doc-warnings,
85 AS_HELP_STRING(--enable-missing-doc-warnings, [Tell doxygen to warn about missing documentation. Makes doxygen warnings nonfatal.]))
87 if test "$enable_missing_doc_warnings" = "yes"; then
88 DOXYGEN_FATAL_WARNINGS=NO
89 DOXYGEN_WARN_ON_MISSING=YES
90 elif test "$enable_fatal_warnings" = "yes"; then
91 # Fatal warnings from doxygen are nice, but not if we're warning about
92 # missing documentation.
93 DOXYGEN_FATAL_WARNINGS=YES
94 DOXYGEN_WARN_ON_MISSING=NO
96 DOXYGEN_FATAL_WARNINGS=NO
97 DOXYGEN_WARN_ON_MISSING=NO
99 AC_SUBST(DOXYGEN_FATAL_WARNINGS)
100 AC_SUBST(DOXYGEN_WARN_ON_MISSING)
102 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
103 AC_MSG_ERROR([Can't disable assertions outside of coverage build])
106 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
107 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
108 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
109 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
110 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
111 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
112 AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
113 AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
115 if test "x$enable_nss" = "xyes"; then
116 AC_DEFINE(ENABLE_NSS, 1,
117 [Defined if we're building with NSS.])
119 AC_DEFINE(ENABLE_OPENSSL, 1,
120 [Defined if we're building with OpenSSL or LibreSSL])
123 if test "$enable_static_tor" = "yes"; then
124 enable_static_libevent="yes";
125 enable_static_openssl="yes";
126 enable_static_zlib="yes";
127 CFLAGS="$CFLAGS -static"
130 if test "$enable_system_torrc" = "no"; then
131 AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
132 [Defined if we're not going to look for a torrc in SYSCONF])
135 if test "$enable_memory_sentinels" = "no"; then
136 AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
137 [Defined if we're turning off memory safety code to look for bugs])
140 AC_ARG_ENABLE(manpage,
141 AS_HELP_STRING(--disable-manpage, [Disable manpage generation.]))
143 AC_ARG_ENABLE(html-manual,
144 AS_HELP_STRING(--disable-html-manual, [Disable HTML documentation.]))
146 AC_ARG_ENABLE(asciidoc,
147 AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
148 [case "${enableval}" in
149 "yes") asciidoc=true ;;
150 "no") asciidoc=false ;;
151 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
152 esac], [asciidoc=true])
154 # systemd notify support
155 AC_ARG_ENABLE(systemd,
156 AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
157 [case "${enableval}" in
158 "yes") systemd=true ;;
159 "no") systemd=false ;;
160 * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
161 esac], [systemd=auto])
163 if test "$enable_restart_debugging" = "yes"; then
164 AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
165 [Defined if we're building with support for in-process restart debugging.])
168 if test "$enable_zstd_advanced_apis" != "no"; then
169 AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
170 [Defined if we're going to try to use zstd's "static-only" APIs.])
174 if test "x$enable_systemd" = "xno"; then
177 PKG_CHECK_MODULES(SYSTEMD,
181 if test "x$have_systemd" = "xno"; then
182 AC_MSG_NOTICE([Okay, checking for systemd a different way...])
183 PKG_CHECK_MODULES(SYSTEMD,
190 if test "x$have_systemd" = "xyes"; then
191 AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
192 TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
193 TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
194 PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
195 [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or greater])], [])
197 AC_SUBST(TOR_SYSTEMD_CFLAGS)
198 AC_SUBST(TOR_SYSTEMD_LIBS)
200 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
201 AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found, $pkg_config_user_action, or set SYSTEMD_CFLAGS and SYSTEMD_LIBS.])
206 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
210 AC_ARG_ENABLE(gcc-warnings,
211 AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
212 AC_ARG_ENABLE(fatal-warnings,
213 AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
214 AC_ARG_ENABLE(gcc-warnings-advisory,
215 AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
217 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
218 AC_ARG_ENABLE(gcc-hardening,
219 AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
221 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
222 AC_ARG_ENABLE(expensive-hardening,
223 AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
224 AC_ARG_ENABLE(fragile-hardening,
225 AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
226 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
227 fragile_hardening="yes"
228 AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
231 AC_ARG_ENABLE(all-bugs-are-fatal,
232 AS_HELP_STRING(--enable-all-bugs-are-fatal, [force all soft asserts in Tor codebase (tor_assert_nonfatal(), BUG(), etc.) to act as hard asserts (tor_assert() and equivalents); makes Tor fragile; only recommended for dev builds]))
234 if test "x$enable_all_bugs_are_fatal" = "xyes"; then
235 AC_DEFINE(ALL_BUGS_ARE_FATAL, 1, [All assert failures are fatal])
238 dnl Linker hardening options
239 dnl Currently these options are ELF specific - you can't use this with MacOSX
240 AC_ARG_ENABLE(linker-hardening,
241 AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
243 AC_ARG_ENABLE(local-appdata,
244 AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
245 if test "$enable_local_appdata" = "yes"; then
246 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
247 [Defined if we default to host local appdata paths on Windows])
250 AC_ARG_ENABLE(tool-name-check,
251 AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
253 AC_ARG_ENABLE(seccomp,
254 AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
256 AC_ARG_ENABLE(libscrypt,
257 AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
259 dnl --- Tracing Options. ---
263 dnl LTTng instrumentation option.
264 AC_ARG_ENABLE(tracing-instrumentation-lttng,
265 AS_HELP_STRING([--enable-tracing-instrumentation-lttng],
266 [build with LTTng-UST instrumentation]))
267 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LTTNG],
268 [test "x$enable_tracing_instrumentation_lttng" = "xyes"])
270 if test "x$enable_tracing_instrumentation_lttng" = "xyes"; then
271 AC_CHECK_HEADERS([lttng/tracepoint.h], [],
272 [AC_MSG_ERROR([LTTng instrumentation headers not found.
273 On Debian, apt install liblttng-ust-dev"])], [])
274 AC_DEFINE([USE_TRACING_INSTRUMENTATION_LTTNG], [1], [Using LTTng instrumentation])
275 TOR_TRACE_LIBS="-llttng-ust -ldl"
279 dnl USDT instrumentation option.
280 AC_ARG_ENABLE(tracing-instrumentation-usdt,
281 AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
282 [build with tracing USDT instrumentation]))
283 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
284 [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
286 if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
287 AC_CHECK_HEADERS([sys/sdt.h], [],
288 [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
289 On Debian, apt install systemtap-sdt-dev])], [])
290 dnl LTTng generates USDT probes if the UST library was built with
291 dnl --with-sdt. There is unfortunately no way to check that so we always
292 dnl build the USDT probes even though LTTng instrumentation was requested.
293 AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
296 dnl Tracepoints event to debug logs.
297 AC_ARG_ENABLE(tracing-instrumentation-log-debug,
298 AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
299 [build with tracing event to debug log]),
300 AC_DEFINE([USE_TRACING_INSTRUMENTATION_LOG_DEBUG], [1],
301 [Tracepoints to log debug]), [])
302 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
303 [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
305 dnl Define that tracing is supported if any instrumentation is used.
306 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
307 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
308 AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
309 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
310 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LTTNG],
311 AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
313 dnl Finally, define the trace libs.
314 AC_SUBST([TOR_TRACE_LIBS])
316 dnl -- End Tracing Options. --
318 dnl Enable Android only features.
319 AC_ARG_ENABLE(android,
320 AS_HELP_STRING(--enable-android, [build with Android features enabled]))
321 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
323 if test "x$enable_android" = "xyes"; then
324 AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
326 dnl Check if the Android log library is available.
327 AC_CHECK_HEADERS([android/log.h])
328 AC_SEARCH_LIBS(__android_log_write, [log])
333 dnl Tor modules options. These options are namespaced with --disable-module-XXX
337 m4_define(MODULES, relay dirauth dircache)
340 AC_ARG_ENABLE([module-relay],
341 AS_HELP_STRING([--disable-module-relay],
342 [Build tor without the Relay modules: tor can not run as a relay, bridge, or authority. Implies --disable-module-dirauth]))
343 AM_CONDITIONAL(BUILD_MODULE_RELAY, [test "x$enable_module_relay" != "xno"])
344 AM_COND_IF(BUILD_MODULE_RELAY,
345 AC_DEFINE([HAVE_MODULE_RELAY], [1],
346 [Compile with Relay feature support]))
348 dnl Dircache module. (This cannot be enabled or disabled independently of
349 dnl the relay module. It is not listed by --list-modules for this reason.)
350 AM_CONDITIONAL(BUILD_MODULE_DIRCACHE,
351 [test "x$enable_module_relay" != "xno"])
352 AM_COND_IF(BUILD_MODULE_DIRCACHE,
353 AC_DEFINE([HAVE_MODULE_DIRCACHE], [1],
354 [Compile with directory cache support]))
356 dnl Directory Authority module.
357 AC_ARG_ENABLE([module-dirauth],
358 AS_HELP_STRING([--disable-module-dirauth],
359 [Build tor without the Directory Authority module: tor can not run as a directory authority or bridge authority]))
360 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH,[test "x$enable_module_dirauth" != "xno" && test "x$enable_module_relay" != "xno"])
361 AM_COND_IF(BUILD_MODULE_DIRAUTH,
362 AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
363 [Compile with Directory Authority feature support]))
365 dnl Helper variables.
366 TOR_MODULES_ALL_ENABLED=
367 AC_DEFUN([ADD_MODULE], [
368 MODULE=m4_toupper($1)
369 TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
371 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
372 AC_SUBST(TOR_MODULES_ALL_ENABLED)
374 dnl check for the correct "ar" when cross-compiling.
375 dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
376 dnl so kludge up a replacement for the case where it isn't there yet.)
377 m4_ifdef([AM_PROG_AR],
379 [AN_MAKEVAR([AR], [AC_PROG_AR])
380 AN_PROGRAM([ar], [AC_PROG_AR])
381 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
384 dnl Check whether the above macro has settled for a simply named tool even
385 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
386 dnl because that will find any cc on the system, not only the cross-compiler,
387 dnl and then verify that a binary built with this compiler runs on the
388 dnl build system. It will then come to the false conclusion that we're not
390 if test "x$enable_tool_name_check" != "xno"; then
391 if test "x$ac_tool_warned" = "xyes"; then
392 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.)])
393 elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
394 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.)])
404 AC_ARG_VAR([PERL], [path to Perl binary])
405 AC_CHECK_PROGS([PERL], [perl])
406 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
408 dnl check for asciidoc and a2x
409 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
410 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
412 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
413 AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
414 AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
419 AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
420 [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
422 python3.8 python3.7 python3.6 python3.5 python3.4 \
424 [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
425 AC_SUBST([PYTHON], [$tor_cv_PYTHON])
427 PYTHON="$tor_cv_PYTHON"
429 if test "x$PYTHON" = "x"; then
430 AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
433 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
435 dnl List all external rust crates we depend on here. Include the version
440 AC_SUBST(rust_crates)
442 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
443 AC_C_FLEXIBLE_ARRAY_MEMBER
445 dnl Maybe we've got an old autoconf...
446 AC_CACHE_CHECK([for flexible array members],
450 struct abc { int a; char b[]; };
452 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
455 [tor_cv_c_flexarray=yes],
456 [tor_cv_c_flexarray=no])])
457 if test "$tor_cv_flexarray" = "yes"; then
458 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
460 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
464 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
467 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
468 [tor_cv_c_c99_decl=yes],
469 [tor_cv_c_c99_decl=no] )])
470 if test "$tor_cv_c_c99_decl" != "yes"; then
471 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
474 AC_CACHE_CHECK([for working C99 designated initializers],
475 tor_cv_c_c99_designated_init,
477 [AC_LANG_PROGRAM([struct s { int a; int b; };],
478 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
479 [tor_cv_c_c99_designated_init=yes],
480 [tor_cv_c_c99_designated_init=no] )])
482 if test "$tor_cv_c_c99_designated_init" != "yes"; then
483 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
486 saved_CFLAGS="$CFLAGS"
487 CFLAGS="$CFLAGS -Werror"
488 AC_CACHE_CHECK([for __attribute__((fallthrough))],
489 tor_cv_c_attr_fallthrough,
491 [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
492 [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
493 case 2: fn(); break; } ]])],
494 [tor_cv_c_attr_fallthrough=yes],
495 [tor_cv_c_attr_fallthrough=no] )])
496 CFLAGS="$saved_CFLAGS"
498 if test "$tor_cv_c_attr_fallthrough" = "yes"; then
499 AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
503 AC_ARG_WITH(tor-user,
504 AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
512 AC_ARG_WITH(tor-group,
513 AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
521 dnl If _WIN32 is defined and non-zero, we are building for win32
522 AC_MSG_CHECKING([for win32])
523 AC_RUN_IFELSE([AC_LANG_SOURCE([
524 int main(int c, char **v) {
535 bwin32=true; AC_MSG_RESULT([yes]),
536 bwin32=false; AC_MSG_RESULT([no]),
537 bwin32=cross; AC_MSG_RESULT([cross])
540 if test "$bwin32" = "cross"; then
541 AC_MSG_CHECKING([for win32 (cross)])
542 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
544 int main(int c, char **v) {return 0;}
547 int main(int c, char **v) {return x(y);}
550 bwin32=true; AC_MSG_RESULT([yes]),
551 bwin32=false; AC_MSG_RESULT([no]))
556 /* Defined to access windows functions and definitions for >=WinXP */
558 # define WINVER 0x0501
561 /* Defined to access _other_ windows functions and definitions for >=WinXP */
562 # ifndef _WIN32_WINNT
563 # define _WIN32_WINNT 0x0501
566 /* Defined to avoid including some windows headers as part of Windows.h */
567 # ifndef WIN32_LEAN_AND_MEAN
568 # define WIN32_LEAN_AND_MEAN 1
573 AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
574 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
575 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
577 dnl Enable C99 when compiling with MIPSpro
578 AC_MSG_CHECKING([for MIPSpro compiler])
579 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
580 #if (defined(__sgi) && defined(_COMPILER_VERSION))
585 bmipspro=false; AC_MSG_RESULT(no),
586 bmipspro=true; AC_MSG_RESULT(yes))
588 if test "$bmipspro" = "true"; then
589 CFLAGS="$CFLAGS -c99"
594 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
596 if test "x$enable_rust" = "xyes"; then
597 AC_ARG_VAR([RUSTC], [path to the rustc binary])
598 AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
599 if test "x$RUSTC" = "xno"; then
600 AC_MSG_ERROR([rustc unavailable but rust integration requested.])
603 AC_ARG_VAR([CARGO], [path to the cargo binary])
604 AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
605 if test "x$CARGO" = "xno"; then
606 AC_MSG_ERROR([cargo unavailable but rust integration requested.])
609 AC_DEFINE([HAVE_RUST], 1, [have Rust])
610 if test "x$enable_fatal_warnings" = "xyes"; then
615 if test "x$enable_cargo_online_mode" = "xyes"; then
619 CARGO_ONLINE=--frozen
622 dnl When we're not allowed to touch the network, we need crate dependencies
623 dnl locally available.
624 AC_MSG_CHECKING([rust crate dependencies])
625 AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
626 if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
627 TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
629 dnl Check whether the path exists before we try to cd into it.
630 if test ! -d "$TOR_RUST_DEPENDENCIES"; then
631 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.])
634 dnl Make the path absolute, since we'll be using it from within a
636 TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
638 for dep in $rust_crates; do
639 if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
640 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.])
644 if test "x$ERRORED" = "x"; then
649 dnl For now both MSVC and MinGW rust libraries will output static libs with
650 dnl the MSVC naming convention.
651 if test "$bwin32" = "true"; then
652 tor_rust_static_name=tor_rust.lib
654 tor_rust_static_name=libtor_rust.a
659 if test -n "$TOR_RUST_TARGET"; then
660 if test "$host" = "$build"; then
661 AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
663 RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
664 TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
666 if test "$host" != "$build"; then
667 AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
670 TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
673 AC_SUBST(RUST_TARGET_PROP)
674 AC_SUBST(TOR_RUST_LIB_PATH)
675 AC_SUBST(CARGO_ONLINE)
679 dnl Let's check the rustc version, too
680 AC_MSG_CHECKING([rust version])
681 RUSTC_VERSION=`$RUSTC --version`
682 RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
683 RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
684 if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
685 AC_MSG_ERROR([rustc version couldn't be identified])
687 if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 31; then
688 AC_MSG_ERROR([rustc must be at least version 1.31.0])
690 AC_MSG_RESULT([$RUSTC_VERSION])
693 AC_SEARCH_LIBS(socket, [socket network])
694 AC_SEARCH_LIBS(gethostbyname, [nsl])
695 AC_SEARCH_LIBS(dlopen, [dl])
696 AC_SEARCH_LIBS(inet_aton, [resolv])
697 AC_SEARCH_LIBS(backtrace, [execinfo])
699 AC_SEARCH_LIBS([clock_gettime], [rt])
700 if test "$LIBS" != "$saved_LIBS"; then
701 # Looks like we need -lrt for clock_gettime().
705 if test "$bwin32" = "false"; then
706 AC_SEARCH_LIBS(pthread_create, [pthread])
707 AC_SEARCH_LIBS(pthread_detach, [pthread])
710 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
711 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
715 RtlSecureZeroMemory \
719 backtrace_symbols_fd \
726 get_current_dir_name \
734 gnu_get_libc_version \
771 # Apple messed up when they added some functions: they
772 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
775 # We should only probe for these functions if we are sure that we
776 # are not targeting OS X 10.9 or earlier.
777 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
778 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
780 # include <AvailabilityMacros.h>
781 # ifndef MAC_OS_X_VERSION_10_10
782 # define MAC_OS_X_VERSION_10_10 101000
784 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
785 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
786 # error "Running on Mac OS X 10.9 or earlier"
791 [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
792 [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
794 if test "$on_macos_pre_10_10" = "no"; then
796 mach_approximate_time \
800 # We should only probe for these functions if we are sure that we
801 # are not targeting OSX 10.11 or earlier.
802 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
803 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
805 # include <AvailabilityMacros.h>
806 # ifndef MAC_OS_X_VERSION_10_12
807 # define MAC_OS_X_VERSION_10_12 101200
809 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
810 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
811 # error "Running on Mac OSX 10.11 or earlier"
816 [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
817 [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
819 if test "$on_macos_pre_10_12" = "no"; then
826 if test "$bwin32" != "true"; then
827 AC_CHECK_HEADERS(pthread.h)
828 AC_CHECK_FUNCS(pthread_create)
829 AC_CHECK_FUNCS(pthread_condattr_setclock)
832 if test "$bwin32" = "true"; then
833 AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
840 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
841 test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
843 AC_MSG_CHECKING([whether free(NULL) works])
844 AC_RUN_IFELSE([AC_LANG_PROGRAM([
850 [free_null_ok=true; AC_MSG_RESULT(yes)],
851 [free_null_ok=false; AC_MSG_RESULT(no)],
852 [free_null_ok=cross; AC_MSG_RESULT(cross)])
854 if test "$free_null_ok" = "false"; then
855 AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
858 dnl ------------------------------------------------------
859 dnl Where do you live, libevent? And how do we call you?
861 if test "$bwin32" = "true"; then
862 TOR_LIB_WS32=-lws2_32
863 TOR_LIB_IPHLPAPI=-liphlpapi
864 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
865 # think it's actually necessary.
867 TOR_LIB_USERENV=-luserenv
873 AC_SUBST(TOR_LIB_WS32)
874 AC_SUBST(TOR_LIB_GDI)
875 AC_SUBST(TOR_LIB_IPHLPAPI)
876 AC_SUBST(TOR_LIB_USERENV)
878 tor_libevent_pkg_redhat="libevent"
879 tor_libevent_pkg_debian="libevent-dev"
880 tor_libevent_devpkg_redhat="libevent-devel"
881 tor_libevent_devpkg_debian="libevent-dev"
883 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
884 dnl linking for static builds.
885 STATIC_LIBEVENT_FLAGS=""
886 if test "$enable_static_libevent" = "yes"; then
887 if test "$have_rt" = "yes"; then
888 STATIC_LIBEVENT_FLAGS=" -lrt "
892 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
894 #include <winsock2.h>
896 #include <sys/time.h>
897 #include <sys/types.h>
898 #include <event2/event.h>], [
900 #include <winsock2.h>
903 struct event_base *event_base_new(void);
904 void event_base_free(struct event_base *);],
907 {WSADATA d; WSAStartup(0x101,&d); }
909 event_base_free(event_base_new());
910 ], [--with-libevent-dir], [/opt/libevent])
912 dnl Determine the incantation needed to link libevent.
914 save_LDFLAGS="$LDFLAGS"
915 save_CPPFLAGS="$CPPFLAGS"
917 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
918 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
919 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
921 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
923 if test "$enable_static_libevent" = "yes"; then
924 if test "$tor_cv_library_libevent_dir" = "(system)"; then
925 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
927 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
930 if test "x$ac_cv_header_event2_event_h" = "xyes"; then
931 AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
932 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"))
934 if test "$ac_cv_search_event_new" != "none required"; then
935 TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
937 if test "$ac_cv_search_evdns_base_new" != "none required"; then
938 TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
941 AC_MSG_ERROR("libevent2 is required but the headers could not be found")
945 dnl Now check for particular libevent functions.
946 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
947 evutil_secure_rng_add_bytes \
948 evdns_base_get_nameserver_addr \
953 LDFLAGS="$save_LDFLAGS"
954 CPPFLAGS="$save_CPPFLAGS"
956 dnl Check that libevent is at least at version 2.0.10, the first stable
957 dnl release of its series
958 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
959 AC_MSG_CHECKING([whether Libevent is new enough])
960 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
961 #include <event2/event.h>
962 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
968 ])], [ AC_MSG_RESULT([yes]) ],
969 [ AC_MSG_RESULT([no])
970 AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
973 LDFLAGS="$save_LDFLAGS"
974 CPPFLAGS="$save_CPPFLAGS"
976 AC_SUBST(TOR_LIBEVENT_LIBS)
978 dnl ------------------------------------------------------
979 dnl Where do you live, libm?
981 dnl On some platforms (Haiku/BeOS) the math library is
982 dnl part of libroot. In which case don't link against lm
985 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
986 if test "$ac_cv_search_pow" != "none required"; then
987 TOR_LIB_MATH="$ac_cv_search_pow"
990 AC_SUBST(TOR_LIB_MATH)
992 dnl ------------------------------------------------------
993 dnl Hello, NSS. You're new around here.
994 if test "x$enable_nss" = "xyes"; then
995 PKG_CHECK_MODULES(NSS,
998 [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it, $pkg_config_user_action, or set NSS_CFLAGS and NSS_LIBS.])])
1003 dnl ------------------------------------------------------
1004 dnl Where do you live, openssl? And how do we call you?
1006 if test "x$enable_nss" != "xyes"; then
1008 tor_openssl_pkg_redhat="openssl"
1009 tor_openssl_pkg_debian="libssl-dev"
1010 tor_openssl_devpkg_redhat="openssl-devel"
1011 tor_openssl_devpkg_debian="libssl-dev"
1013 ALT_openssl_WITHVAL=""
1014 AC_ARG_WITH(ssl-dir,
1015 AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
1017 if test "x$withval" != "xno" && test "x$withval" != "x"; then
1018 ALT_openssl_WITHVAL="$withval"
1022 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
1023 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
1024 [#include <openssl/ssl.h>
1025 char *getenv(const char *);],
1026 [struct ssl_cipher_st;
1027 unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
1028 char *getenv(const char *);],
1029 dnl This funny-looking test program calls getenv, so that the compiler
1030 dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
1031 dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
1032 dnl We look for SSL_cipher_get_id() because it is present in
1033 dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
1035 [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
1036 [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
1038 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
1040 if test "$enable_static_openssl" = "yes"; then
1041 if test "$tor_cv_library_openssl_dir" = "(system)"; then
1042 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
1044 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
1047 TOR_OPENSSL_LIBS="-lssl -lcrypto"
1049 AC_SUBST(TOR_OPENSSL_LIBS)
1051 dnl Now check for particular openssl functions.
1053 save_LDFLAGS="$LDFLAGS"
1054 save_CPPFLAGS="$CPPFLAGS"
1055 LIBS="$TOR_OPENSSL_LIBS $LIBS"
1056 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
1057 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
1059 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1060 #include <openssl/opensslv.h>
1061 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
1066 [ 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.]) ])
1068 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1069 #include <openssl/opensslv.h>
1070 #include <openssl/evp.h>
1071 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
1074 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
1075 #error "curves unavailable"
1079 [ 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.]) ])
1081 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
1082 [#include <openssl/ssl.h>
1085 dnl OpenSSL functions which we might not have. In theory, we could just
1086 dnl check the openssl version number, but in practice that gets pretty
1087 dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
1090 ERR_load_KDF_strings \
1093 SSL_CTX_set1_groups_list \
1094 SSL_CTX_set_security_level \
1095 SSL_SESSION_get_master_key \
1096 SSL_get_client_ciphers \
1097 SSL_get_client_random \
1098 SSL_get_server_random \
1102 dnl Check if OpenSSL structures are opaque
1103 AC_CHECK_MEMBERS([SSL.state], , ,
1104 [#include <openssl/ssl.h>
1107 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
1108 #include <openssl/sha.h>
1113 dnl We will someday make KECCAK_TINY optional, but for now we still need
1114 dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
1115 dnl once. See comment in the definition of crypto_xof_t.
1117 dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
1118 dnl test "x$ac_cv_func_EVP_sha3_256" != "xyes")
1120 AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
1122 dnl ======================================================================
1123 dnl Can we use KIST?
1125 dnl Define the set of checks for KIST scheduler support.
1126 AC_DEFUN([CHECK_KIST_SUPPORT],[
1127 dnl KIST needs struct tcp_info and for certain members to exist.
1129 [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
1130 , ,[[#include <netinet/tcp.h>]])
1131 dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
1132 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1133 #include <linux/sockios.h>
1137 ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
1138 if test "x$have_siocoutqnsd" = "xyes"; then
1139 if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
1140 if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
1141 have_kist_support=yes
1146 dnl Now, trigger the check.
1148 AS_IF([test "x$have_kist_support" = "xyes"],
1149 [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
1151 [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
1154 LDFLAGS="$save_LDFLAGS"
1155 CPPFLAGS="$save_CPPFLAGS"
1157 dnl ------------------------------------------------------
1158 dnl Where do you live, zlib? And how do we call you?
1160 tor_zlib_pkg_redhat="zlib"
1161 tor_zlib_pkg_debian="zlib1g"
1162 tor_zlib_devpkg_redhat="zlib-devel"
1163 tor_zlib_devpkg_debian="zlib1g-dev"
1165 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1166 [#include <zlib.h>],
1167 [const char * zlibVersion(void);],
1168 [zlibVersion();], [--with-zlib-dir],
1171 if test "$enable_static_zlib" = "yes"; then
1172 if test "$tor_cv_library_zlib_dir" = "(system)"; then
1173 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1174 using --enable-static-zlib")
1176 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1181 AC_SUBST(TOR_ZLIB_LIBS)
1183 dnl ------------------------------------------------------
1184 dnl Where we do we find lzma?
1187 AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1188 [case "${enableval}" in
1191 * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1192 esac], [enable_lzma=auto])
1194 if test "x$enable_lzma" = "xno"; then
1197 PKG_CHECK_MODULES([LZMA],
1202 if test "x$have_lzma" = "xno" ; then
1203 AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
1207 if test "x$have_lzma" = "xyes"; then
1208 AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1209 TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1210 TOR_LZMA_LIBS="${LZMA_LIBS}"
1212 AC_SUBST(TOR_LZMA_CFLAGS)
1213 AC_SUBST(TOR_LZMA_LIBS)
1215 dnl ------------------------------------------------------
1216 dnl Where we do we find zstd?
1219 AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1220 [case "${enableval}" in
1223 * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1224 esac], [enable_zstd=auto])
1226 if test "x$enable_zstd" = "xno"; then
1229 PKG_CHECK_MODULES([ZSTD],
1234 if test "x$have_zstd" = "xno" ; then
1235 AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
1239 if test "x$have_zstd" = "xyes"; then
1240 AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1241 TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1242 TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1244 dnl now check for zstd functions
1246 save_CFLAGS="$CFLAGS"
1247 LIBS="$LIBS $ZSTD_LIBS"
1248 CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1249 AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1250 ZSTD_estimateDCtxSize)
1252 CFLAGS="$save_CFLAGS"
1254 AC_SUBST(TOR_ZSTD_CFLAGS)
1255 AC_SUBST(TOR_ZSTD_LIBS)
1257 dnl ----------------------------------------------------------------------
1258 dnl Check if libcap is available for capabilities.
1260 tor_cap_pkg_debian="libcap2"
1261 tor_cap_pkg_redhat="libcap"
1262 tor_cap_devpkg_debian="libcap-dev"
1263 tor_cap_devpkg_redhat="libcap-devel"
1265 AC_CHECK_LIB([cap], [cap_init], [],
1266 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1268 AC_CHECK_FUNCS(cap_set_proc)
1270 dnl ---------------------------------------------------------------------
1271 dnl Now that we know about our major libraries, we can check for compiler
1272 dnl and linker hardening options. We need to do this with the libraries known,
1273 dnl since sometimes the linker will like an option but not be willing to
1274 dnl use it with a build of a library.
1276 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1277 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"
1285 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1286 #if !defined(__clang__)
1288 #endif])], have_clang=yes, have_clang=no)
1290 if test "x$enable_pic" = "xyes"; then
1291 TOR_CHECK_CFLAGS(-fPIC)
1294 if test "x$enable_gcc_hardening" != "xno"; then
1295 CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1296 if test "x$have_clang" = "xyes"; then
1297 TOR_CHECK_CFLAGS(-Qunused-arguments)
1299 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1300 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1301 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1302 m4_ifdef([AS_VAR_IF],[
1303 AS_VAR_IF(can_compile, [yes],
1304 AS_VAR_IF(can_link, [yes],
1306 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.)]))
1308 AS_VAR_POPDEF([can_link])
1309 AS_VAR_POPDEF([can_compile])
1310 TOR_CHECK_CFLAGS(-Wstack-protector)
1311 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1312 if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1313 if test "$enable_pic" != "yes"; then
1314 # If we have already enabled -fPIC, then we don't also need to
1315 # compile with -fPIE...
1316 TOR_CHECK_CFLAGS(-fPIE)
1318 # ... but we want to link our executables with -pie in any case, since
1319 # they're executables, not a library.
1320 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1322 TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1324 AC_MSG_CHECKING([whether we can run hardened binaries])
1325 AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
1326 [AC_MSG_RESULT([yes])],
1327 [AC_MSG_RESULT([no])
1329 We can link with compiler hardening options, but we can't run with them.
1330 That's a bad sign! If you must, you can pass --disable-gcc-hardening to
1331 configure, but it would be better to figure out what the underlying problem
1333 [AC_MSG_RESULT([cross])])
1336 if test "$fragile_hardening" = "yes"; then
1337 TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1338 if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1339 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.])
1342 if test "$tor_cv_cflags__ftrapv" != "yes"; then
1343 AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1346 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1347 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1348 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*])
1351 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1352 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1353 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*])
1356 TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
1357 if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
1358 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*])
1361 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1364 dnl Find the correct libraries to add in order to use the sanitizers.
1366 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1367 dnl option, which will prevent the compiler from linking the sanitizer
1368 dnl libraries it needs. We need to specify them manually.
1370 dnl What's more, we need to specify them in a linker script rather than
1371 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1373 RUST_LINKER_OPTIONS=""
1374 if test "x$have_clang" = "xyes"; then
1375 if test "x$CFLAGS_ASAN" != "x"; then
1376 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
1378 if test "x$CFLAGS_UBSAN" != "x"; then
1379 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
1382 if test "x$CFLAGS_ASAN" != "x"; then
1383 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
1385 if test "x$CFLAGS_UBSAN" != "x"; then
1386 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
1389 AC_SUBST(RUST_LINKER_OPTIONS)
1391 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1392 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1394 mulodi_fixes_ftrapv=no
1395 if test "$have_clang" = "yes"; then
1396 saved_CFLAGS="$CFLAGS"
1397 CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1398 AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1403 int main(int argc, char **argv)
1405 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1406 * (int64_t)atoi(argv[3]);
1409 [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1410 [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1411 if test "$ftrapv_can_link" = "no"; then
1412 AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1417 int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1421 int main(int argc, char **argv)
1423 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1424 * (int64_t)atoi(argv[3]);
1427 [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1428 [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1430 CFLAGS="$saved_CFLAGS"
1433 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1435 dnl These cflags add bunches of branches, and we haven't been able to
1436 dnl persuade ourselves that they're suitable for code that needs to be
1438 AC_SUBST(CFLAGS_BUGTRAP)
1439 dnl These cflags are variant ones sutable for code that needs to be
1441 AC_SUBST(CFLAGS_CONSTTIME)
1443 if test "x$enable_linker_hardening" != "xno"; then
1444 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1447 # For backtrace support
1448 TOR_CHECK_LDFLAGS(-rdynamic)
1450 dnl ------------------------------------------------------
1451 dnl Now see if we have a -fomit-frame-pointer compiler option.
1453 saved_CFLAGS="$CFLAGS"
1454 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1455 F_OMIT_FRAME_POINTER=''
1456 if test "$saved_CFLAGS" != "$CFLAGS"; then
1457 if test "$fragile_hardening" = "yes"; then
1458 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1461 CFLAGS="$saved_CFLAGS"
1462 AC_SUBST(F_OMIT_FRAME_POINTER)
1464 dnl ------------------------------------------------------
1465 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1466 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1467 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1469 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1471 dnl ============================================================
1472 dnl Check for libseccomp
1474 if test "x$enable_seccomp" != "xno"; then
1475 AC_CHECK_HEADERS([seccomp.h])
1476 AC_SEARCH_LIBS(seccomp_init, [seccomp])
1479 dnl ============================================================
1480 dnl Check for libscrypt
1482 if test "x$enable_libscrypt" != "xno"; then
1483 AC_CHECK_HEADERS([libscrypt.h])
1484 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1485 AC_CHECK_FUNCS([libscrypt_scrypt])
1488 dnl ============================================================
1489 dnl We need an implementation of curve25519.
1491 dnl set these defaults.
1492 build_curve25519_donna=no
1493 build_curve25519_donna_c64=no
1494 use_curve25519_donna=no
1495 use_curve25519_nacl=no
1498 dnl The best choice is using curve25519-donna-c64, but that requires
1500 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1501 tor_cv_can_use_curve25519_donna_c64,
1503 [AC_LANG_PROGRAM([dnl
1505 typedef unsigned uint128_t __attribute__((mode(TI)));
1506 int func(uint64_t a, uint64_t b) {
1507 uint128_t c = ((uint128_t)a) * b;
1508 int ok = ((uint64_t)(c>>96)) == 522859 &&
1509 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1510 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1511 (((uint64_t)(c))&0xffffffffL) == 0;
1515 int ok = func( ((uint64_t)2000000000) * 1000000000,
1516 ((uint64_t)1234567890) << 24);
1519 [tor_cv_can_use_curve25519_donna_c64=yes],
1520 [tor_cv_can_use_curve25519_donna_c64=no],
1522 [AC_LANG_PROGRAM([dnl
1524 typedef unsigned uint128_t __attribute__((mode(TI)));
1525 int func(uint64_t a, uint64_t b) {
1526 uint128_t c = ((uint128_t)a) * b;
1527 int ok = ((uint64_t)(c>>96)) == 522859 &&
1528 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1529 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1530 (((uint64_t)(c))&0xffffffffL) == 0;
1534 int ok = func( ((uint64_t)2000000000) * 1000000000,
1535 ((uint64_t)1234567890) << 24);
1538 [tor_cv_can_use_curve25519_donna_c64=cross],
1539 [tor_cv_can_use_curve25519_donna_c64=no])])])
1541 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1542 nacl/crypto_scalarmult_curve25519.h])
1544 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1545 tor_cv_can_use_curve25519_nacl,
1546 [tor_saved_LIBS="$LIBS"
1549 [AC_LANG_PROGRAM([dnl
1550 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1551 #include <crypto_scalarmult_curve25519.h>
1552 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1553 #include <nacl/crypto_scalarmult_curve25519.h>
1555 #ifdef crypto_scalarmult_curve25519_ref_BYTES
1556 #error Hey, this is the reference implementation! That's not fast.
1559 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1560 ])], [tor_cv_can_use_curve25519_nacl=yes],
1561 [tor_cv_can_use_curve25519_nacl=no])
1562 LIBS="$tor_saved_LIBS" ])
1564 dnl Okay, now we need to figure out which one to actually use. Fall back
1565 dnl to curve25519-donna.c
1567 if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1568 build_curve25519_donna_c64=yes
1569 use_curve25519_donna=yes
1570 elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1571 use_curve25519_nacl=yes
1572 CURVE25519_LIBS=-lnacl
1574 build_curve25519_donna=yes
1575 use_curve25519_donna=yes
1578 if test "x$use_curve25519_donna" = "xyes"; then
1579 AC_DEFINE(USE_CURVE25519_DONNA, 1,
1580 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1582 if test "x$use_curve25519_nacl" = "xyes"; then
1583 AC_DEFINE(USE_CURVE25519_NACL, 1,
1584 [Defined if we should use a curve25519 from nacl])
1586 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1587 test "x$build_curve25519_donna" = "xyes")
1588 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1589 test "x$build_curve25519_donna_c64" = "xyes")
1590 AC_SUBST(CURVE25519_LIBS)
1592 dnl Make sure to enable support for large off_t if available.
1595 AC_CHECK_HEADERS([errno.h \
1609 gnu/libc-version.h \
1646 AC_CHECK_HEADERS(sys/param.h)
1648 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1649 [#ifdef HAVE_SYS_TYPES_H
1650 #include <sys/types.h>
1652 #ifdef HAVE_SYS_SOCKET_H
1653 #include <sys/socket.h>
1655 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1656 [#ifdef HAVE_SYS_TYPES_H
1657 #include <sys/types.h>
1659 #ifdef HAVE_SYS_SOCKET_H
1660 #include <sys/socket.h>
1662 #ifdef HAVE_NET_IF_H
1665 #ifdef HAVE_NETINET_IN_H
1666 #include <netinet/in.h>
1669 AC_CHECK_HEADERS(linux/if.h,[],[],
1671 #ifdef HAVE_SYS_SOCKET_H
1672 #include <sys/socket.h>
1676 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1677 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1678 [#ifdef HAVE_SYS_TYPES_H
1679 #include <sys/types.h>
1681 #ifdef HAVE_SYS_SOCKET_H
1682 #include <sys/socket.h>
1684 #ifdef HAVE_LIMITS_H
1687 #ifdef HAVE_LINUX_TYPES_H
1688 #include <linux/types.h>
1690 #ifdef HAVE_NETINET_IN6_H
1691 #include <netinet/in6.h>
1693 #ifdef HAVE_NETINET_IN_H
1694 #include <netinet/in.h>
1697 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1698 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1699 [#ifdef HAVE_SYS_TYPES_H
1700 #include <sys/types.h>
1702 #ifdef HAVE_SYS_SOCKET_H
1703 #include <sys/socket.h>
1705 #ifdef HAVE_LIMITS_H
1708 #ifdef HAVE_LINUX_TYPES_H
1709 #include <linux/types.h>
1711 #ifdef HAVE_NETINET_IN6_H
1712 #include <netinet/in6.h>
1714 #ifdef HAVE_NETINET_IN_H
1715 #include <netinet/in.h>
1717 #ifdef HAVE_LINUX_IF_H
1718 #include <linux/if.h>
1722 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1725 if test "x$linux_netfilter_ipv4" = "x1"; then
1728 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1731 if test "x$transparent_ok" = "x1"; then
1732 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1734 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1737 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1738 [#ifdef HAVE_SYS_TYPES_H
1739 #include <sys/types.h>
1741 #ifdef HAVE_SYS_TIME_H
1742 #include <sys/time.h>
1745 AC_CHECK_SIZEOF(char)
1746 AC_CHECK_SIZEOF(short)
1747 AC_CHECK_SIZEOF(int)
1748 AC_CHECK_SIZEOF(unsigned int)
1749 AC_CHECK_SIZEOF(long)
1750 AC_CHECK_SIZEOF(long long)
1751 AC_CHECK_SIZEOF(__int64)
1752 AC_CHECK_SIZEOF(void *)
1753 AC_CHECK_SIZEOF(time_t)
1754 AC_CHECK_SIZEOF(size_t)
1755 AC_CHECK_SIZEOF(pid_t)
1757 AC_CHECK_TYPES([uint, u_char, ssize_t])
1759 AC_PC_FROM_UCONTEXT([:])
1761 dnl used to include sockaddr_storage, but everybody has that.
1762 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1763 [#ifdef HAVE_SYS_TYPES_H
1764 #include <sys/types.h>
1766 #ifdef HAVE_NETINET_IN_H
1767 #include <netinet/in.h>
1769 #ifdef HAVE_NETINET_IN6_H
1770 #include <netinet/in6.h>
1772 #ifdef HAVE_SYS_SOCKET_H
1773 #include <sys/socket.h>
1776 #define _WIN32_WINNT 0x0501
1777 #define WIN32_LEAN_AND_MEAN
1778 #include <winsock2.h>
1779 #include <ws2tcpip.h>
1782 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1783 [#ifdef HAVE_SYS_TYPES_H
1784 #include <sys/types.h>
1786 #ifdef HAVE_NETINET_IN_H
1787 #include <netinet/in.h>
1789 #ifdef HAVE_NETINET_IN6_H
1790 #include <netinet/in6.h>
1792 #ifdef HAVE_SYS_SOCKET_H
1793 #include <sys/socket.h>
1796 #define _WIN32_WINNT 0x0501
1797 #define WIN32_LEAN_AND_MEAN
1798 #include <winsock2.h>
1799 #include <ws2tcpip.h>
1803 AC_CHECK_TYPES([rlim_t], , ,
1804 [#ifdef HAVE_SYS_TYPES_H
1805 #include <sys/types.h>
1807 #ifdef HAVE_SYS_TIME_H
1808 #include <sys/time.h>
1810 #ifdef HAVE_SYS_RESOURCE_H
1811 #include <sys/resource.h>
1815 AX_CHECK_SIGN([time_t],
1818 #ifdef HAVE_SYS_TYPES_H
1819 #include <sys/types.h>
1821 #ifdef HAVE_SYS_TIME_H
1822 #include <sys/time.h>
1829 if test "$ax_cv_decl_time_t_signed" = "no"; then
1830 AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1833 AX_CHECK_SIGN([size_t],
1834 [ tor_cv_size_t_signed=yes ],
1835 [ tor_cv_size_t_signed=no ], [
1836 #ifdef HAVE_SYS_TYPES_H
1837 #include <sys/types.h>
1841 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1842 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1845 AX_CHECK_SIGN([enum always],
1846 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1848 enum always { AAA, BBB, CCC };
1851 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1852 #ifdef HAVE_SYS_SOCKET_H
1853 #include <sys/socket.h>
1857 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1859 AC_CHECK_SIZEOF(cell_t)
1861 # Let's see if stdatomic works. (There are some debian clangs that screw it
1862 # up; see Tor bug #26779 and debian bug 903709.)
1863 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1864 tor_cv_stdatomic_works,
1865 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1866 #include <stdatomic.h>
1867 struct x { atomic_size_t y; };
1868 void try_atomic_init(struct x *xx)
1870 atomic_init(&xx->y, 99);
1871 atomic_fetch_add(&xx->y, 1);
1873 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1875 if test "$tor_cv_stdatomic_works" = "yes"; then
1876 AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1877 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1878 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 ])
1881 # Now make sure that NULL can be represented as zero bytes.
1882 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1883 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1884 [[#include <stdlib.h>
1887 #ifdef HAVE_STDDEF_H
1890 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1891 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1892 [tor_cv_null_is_zero=yes],
1893 [tor_cv_null_is_zero=no],
1894 [tor_cv_null_is_zero=cross])])
1896 if test "$tor_cv_null_is_zero" = "cross"; then
1897 # Cross-compiling; let's hope that the target isn't raving mad.
1898 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1901 if test "$tor_cv_null_is_zero" != "no"; then
1902 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1903 [Define to 1 iff memset(0) sets pointers to NULL])
1906 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1907 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1908 [[#include <stdlib.h>
1911 #ifdef HAVE_STDDEF_H
1914 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1915 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1916 [tor_cv_dbl0_is_zero=yes],
1917 [tor_cv_dbl0_is_zero=no],
1918 [tor_cv_dbl0_is_zero=cross])])
1920 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1921 # Cross-compiling; let's hope that the target isn't raving mad.
1922 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1925 if test "$tor_cv_dbl0_is_zero" != "no"; then
1926 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1927 [Define to 1 iff memset(0) sets doubles to 0.0])
1930 # And what happens when we malloc zero?
1931 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1932 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1933 [[#include <stdlib.h>
1936 #ifdef HAVE_STDDEF_H
1939 int main () { return malloc(0)?0:1; }]])],
1940 [tor_cv_malloc_zero_works=yes],
1941 [tor_cv_malloc_zero_works=no],
1942 [tor_cv_malloc_zero_works=cross])])
1944 if test "$tor_cv_malloc_zero_works" = "cross"; then
1945 # Cross-compiling; let's hope that the target isn't raving mad.
1946 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1949 if test "$tor_cv_malloc_zero_works" = "yes"; then
1950 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1951 [Define to 1 iff malloc(0) returns a pointer])
1954 # whether we seem to be in a 2s-complement world.
1955 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1956 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1957 [[int main () { int problem = ((-99) != (~99)+1);
1958 return problem ? 1 : 0; }]])],
1959 [tor_cv_twos_complement=yes],
1960 [tor_cv_twos_complement=no],
1961 [tor_cv_twos_complement=cross])])
1963 if test "$tor_cv_twos_complement" = "cross"; then
1964 # Cross-compiling; let's hope that the target isn't raving mad.
1965 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1968 if test "$tor_cv_twos_complement" != "no"; then
1969 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1970 [Define to 1 iff we represent negative integers with
1974 # What does shifting a negative value do?
1975 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1976 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1977 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1978 [tor_cv_sign_extend=yes],
1979 [tor_cv_sign_extend=no],
1980 [tor_cv_sign_extend=cross])])
1982 if test "$tor_cv_sign_extend" = "cross"; then
1983 # Cross-compiling; let's hope that the target isn't raving mad.
1984 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1987 if test "$tor_cv_sign_extend" != "no"; then
1988 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1989 [Define to 1 iff right-shifting a negative value performs sign-extension])
1992 # Is uint8_t the same type as unsigned char?
1993 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1994 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1997 unsigned char c;]])],
1998 [tor_cv_uint8_uchar=yes],
1999 [tor_cv_uint8_uchar=no],
2000 [tor_cv_uint8_uchar=cross])])
2002 if test "$tor_cv_uint8_uchar" = "cross"; then
2003 AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
2006 if test "$tor_cv_uint8_uchar" = "no"; then
2007 AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
2010 AC_ARG_WITH(tcmalloc,
2011 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
2013 default_malloc=system
2015 if test "x$enable_openbsd_malloc" = "xyes" ; then
2016 AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
2017 default_malloc=openbsd
2020 if test "x$with_tcmalloc" = "xyes"; then
2021 AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
2022 default_malloc=tcmalloc
2026 AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
2027 [select special malloc implementation [system]]),
2028 [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
2032 PKG_CHECK_MODULES([TCMALLOC],
2037 if test "x$have_tcmalloc" = "xno" ; then
2038 AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
2041 CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
2042 LIBS="$TCMALLOC_LIBS $LIBS"
2046 PKG_CHECK_MODULES([JEMALLOC],
2051 if test "x$have_jemalloc" = "xno" ; then
2052 AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
2055 CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
2056 LIBS="$JEMALLOC_LIBS $LIBS"
2057 using_custom_malloc=yes
2061 AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
2062 enable_openbsd_malloc=yes
2066 # handle this later, including the jemalloc fallback
2067 AC_CHECK_FUNCS(mallinfo)
2070 [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
2073 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
2075 if test "$malloc" != "system"; then
2076 # Tell the C compiler not to use the system allocator functions.
2077 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2079 if test "$using_custom_malloc" = "yes"; then
2080 # Tell the C compiler not to use the system allocator functions.
2081 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
2084 # By default, we're going to assume we don't have mlockall()
2085 # bionic and other platforms have various broken mlockall subsystems.
2086 # Some systems don't have a working mlockall, some aren't linkable,
2087 # and some have it but don't declare it.
2088 AC_CHECK_FUNCS(mlockall)
2089 AC_CHECK_DECLS([mlockall], , , [
2090 #ifdef HAVE_SYS_MMAN_H
2091 #include <sys/mman.h>
2094 # Allow user to specify an alternate syslog facility
2095 AC_ARG_WITH(syslog-facility,
2096 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
2097 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
2098 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
2099 AC_SUBST(LOGFACILITY)
2101 # Check if we have getresuid and getresgid
2102 AC_CHECK_FUNCS(getresuid getresgid)
2104 # Check for gethostbyname_r in all its glorious incompatible versions.
2105 # (This logic is based on that in Python's configure.in)
2106 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
2107 [Define this if you have any gethostbyname_r()])
2109 AC_CHECK_FUNC(gethostbyname_r, [
2110 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
2112 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
2113 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2117 struct hostent *h1, *h2;
2119 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
2121 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2122 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
2123 [Define this if gethostbyname_r takes 6 arguments])
2126 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2132 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
2134 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2135 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
2136 [Define this if gethostbyname_r takes 5 arguments])
2139 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2144 struct hostent_data hd;
2145 (void) gethostbyname_r(cp1,h1,&hd);
2147 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
2148 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
2149 [Define this if gethostbyname_r takes 3 arguments])
2159 AC_CACHE_CHECK([whether the C compiler supports __func__],
2160 tor_cv_have_func_macro,
2161 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2163 int main(int c, char **v) { puts(__func__); }])],
2164 tor_cv_have_func_macro=yes,
2165 tor_cv_have_func_macro=no))
2167 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
2168 tor_cv_have_FUNC_macro,
2169 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2171 int main(int c, char **v) { puts(__FUNC__); }])],
2172 tor_cv_have_FUNC_macro=yes,
2173 tor_cv_have_FUNC_macro=no))
2175 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
2176 tor_cv_have_FUNCTION_macro,
2177 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2179 int main(int c, char **v) { puts(__FUNCTION__); }])],
2180 tor_cv_have_FUNCTION_macro=yes,
2181 tor_cv_have_FUNCTION_macro=no))
2183 AC_CACHE_CHECK([whether we have extern char **environ already declared],
2184 tor_cv_have_environ_declared,
2185 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2186 #ifdef HAVE_UNISTD_H
2190 int main(int c, char **v) { char **t = environ; }])],
2191 tor_cv_have_environ_declared=yes,
2192 tor_cv_have_environ_declared=no))
2194 if test "$tor_cv_have_func_macro" = "yes"; then
2195 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
2198 if test "$tor_cv_have_FUNC_macro" = "yes"; then
2199 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2202 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2203 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2204 [Defined if the compiler supports __FUNCTION__])
2207 if test "$tor_cv_have_environ_declared" = "yes"; then
2208 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2209 [Defined if we have extern char **environ already declared])
2212 # $prefix stores the value of the --prefix command line option, or
2213 # NONE if the option wasn't set. In the case that it wasn't set, make
2214 # it be the default, so that we can use it to expand directories now.
2215 if test "x$prefix" = "xNONE"; then
2216 prefix=$ac_default_prefix
2219 # and similarly for $exec_prefix
2220 if test "x$exec_prefix" = "xNONE"; then
2224 if test "x$BUILDDIR" = "x"; then
2228 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2229 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2231 if test "x$SRCDIR" = "x"; then
2232 SRCDIR=$(cd "$srcdir"; pwd)
2234 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2235 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2237 if test "x$CONFDIR" = "x"; then
2238 CONFDIR=`eval echo $sysconfdir/tor`
2241 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2242 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2244 BINDIR=`eval echo $bindir`
2246 LOCALSTATEDIR=`eval echo $localstatedir`
2247 AC_SUBST(LOCALSTATEDIR)
2249 if test "$bwin32" = "true"; then
2250 # Test if the linker supports the --nxcompat and --dynamicbase options
2252 save_LDFLAGS="$LDFLAGS"
2253 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2254 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2255 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2256 [AC_MSG_RESULT([yes])]
2257 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2258 [AC_MSG_RESULT([no])]
2260 LDFLAGS="$save_LDFLAGS"
2263 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2264 # than autoconf's macros like.
2265 if test "$GCC" = "yes"; then
2266 # Disable GCC's strict aliasing checks. They are an hours-to-debug
2267 # accident waiting to happen.
2268 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2270 # Override optimization level for non-gcc compilers
2272 enable_gcc_warnings=no
2273 enable_gcc_warnings_advisory=no
2276 # Warnings implies advisory-warnings and -Werror.
2277 if test "$enable_gcc_warnings" = "yes"; then
2278 enable_gcc_warnings_advisory=yes
2279 enable_fatal_warnings=yes
2282 # OS X Lion started deprecating the system openssl. Let's just disable
2283 # all deprecation warnings on OS X. Also, to potentially make the binary
2284 # a little smaller, let's enable dead_strip.
2288 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2289 LDFLAGS="$LDFLAGS -dead_strip" ;;
2292 TOR_WARNING_FLAGS=""
2294 # Add some more warnings which we use in development but not in the
2295 # released versions. (Some relevant gcc versions can't handle these.)
2297 # Note that we have to do this near the end of the autoconf process, or
2298 # else we may run into problems when these warnings hit on the testing C
2299 # programs that autoconf wants to build.
2300 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2303 *-*-openbsd* | *-*-bitrig*)
2304 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2305 # That's fine, except that the headers don't pass -Wredundant-decls.
2306 # Therefore, let's disable -Wsystem-headers when we're building
2307 # with maximal warnings on OpenBSD.
2308 CFLAGS="$CFLAGS -Wno-system-headers" ;;
2311 CFLAGS_NOWARNINGS="$CFLAGS"
2313 # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
2314 # have it work better.
2315 # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2317 # This warning was added in gcc 4.3, but it appears to generate
2318 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
2319 #CFLAGS="$CFLAGS -Wlogical-op"
2321 m4_foreach_w([warning_flag], [
2323 -Waddress-of-array-temporary
2324 -Waddress-of-temporary
2326 -Wanonymous-pack-parens
2329 -Warc-bridge-casts-disallowed-in-nonarc
2330 -Warc-maybe-repeated-use-of-weak
2331 -Warc-performSelector-leaks
2332 -Warc-repeated-use-of-weak
2334 -Warray-bounds-pointer-arithmetic
2336 -Wasm-operand-widths
2338 -Watomic-property-with-user-defined-accessor
2340 -Wauto-storage-class
2343 -Wbackslash-newline-escape
2344 -Wbad-array-new-length
2345 -Wbind-to-temporary-copy
2346 -Wbitfield-constant-conversion
2349 -Wbuiltin-requires-header
2351 -Wcompare-distinct-pointer-types
2352 -Wcomplex-component-init
2353 -Wconditional-type-mismatch
2355 -Wconstant-conversion
2356 -Wconstant-logical-operand
2357 -Wconstexpr-not-const
2358 -Wcustom-atomic-properties
2360 -Wdangling-initializer-list
2362 -Wdelegating-ctor-cycles
2363 -Wdeprecated-implementations
2364 -Wdeprecated-register
2365 -Wdirect-ivar-access
2367 -Wdistributed-object-modifiers
2369 -Wdollar-in-identifier-extension
2371 -Wduplicate-decl-specifier
2373 -Wduplicate-method-arg
2374 -Wduplicate-method-match
2376 -Wdynamic-class-memaccess
2377 -Wembedded-directive
2378 -Wempty-translation-unit
2380 -Wexit-time-destructors
2381 -Wexplicit-ownership-type
2382 -Wextern-initializer
2386 -Wflexible-array-extensions
2389 -Wfour-char-constants
2391 -Wglobal-constructors
2392 -Wgnu-array-member-paren-init
2394 -Wgnu-static-float-init
2397 -Widiomatic-parentheses
2398 -Wignored-attributes
2399 -Wimplicit-atomic-properties
2400 -Wimplicit-conversion-floating-point-to-bool
2401 -Wimplicit-exception-spec-mismatch
2402 -Wimplicit-fallthrough
2403 -Wimplicit-fallthrough-per-function
2404 -Wimplicit-retain-self
2405 -Wimport-preprocessor-directive-pedantic
2406 -Wincompatible-library-redeclaration
2407 -Wincompatible-pointer-types-discards-qualifiers
2408 -Wincomplete-implementation
2410 -Wincomplete-umbrella
2413 -Wint-to-void-pointer-cast
2419 -Winvalid-source-encoding
2420 -Winvalid-token-paste
2421 -Wknr-promoted-parameter
2422 -Wlarge-by-value-copy
2423 -Wliteral-conversion
2425 -Wlocal-type-template-args
2429 -Wmalformed-warning-check
2433 -Wmismatched-parameter-types
2434 -Wmismatched-return-types
2435 -Wmissing-field-initializers
2436 -Wmissing-format-attribute
2438 -Wmissing-selector-name
2440 -Wmissing-variable-declarations
2444 -Wnon-literal-null-conversion
2446 -Wnonportable-cfstrings
2452 -Wout-of-line-declaration
2454 -Woverlength-strings
2456 -Woverriding-method-mismatch
2457 -Wpointer-type-mismatch
2458 -Wpredefined-identifier-outside-function
2459 -Wprotocol-property-synthesis-ambiguity
2460 -Wreadonly-iboutlet-property
2461 -Wreadonly-setter-attrs
2463 -Wreceiver-forward-class
2465 -Wreinterpret-base-class
2466 -Wrequires-super-attribute
2467 -Wreserved-user-defined-literal
2468 -Wreturn-stack-address
2470 -Wselector-type-mismatch
2472 -Wserialized-diagnostics
2474 -Wshift-count-negative
2475 -Wshift-count-overflow
2476 -Wshift-negative-value
2478 -Wshift-sign-overflow
2480 -Wsizeof-array-argument
2481 -Wsource-uses-openmp
2484 -Wstatic-local-in-inline
2488 -Wstrlcpy-strlcat-size
2490 -Wsuggest-attribute=format
2491 -Wsuggest-attribute=noreturn
2492 -Wsuper-class-method-mismatch
2495 -Wtautological-constant-out-of-range-compare
2496 -Wtentative-definition-incomplete-type
2499 -Wtypedef-redefinition
2502 -Wundefined-internal
2503 -Wundefined-reinterpret-cast
2505 -Wunicode-whitespace
2506 -Wunknown-warning-option
2507 -Wunnamed-type-template-args
2508 -Wunneeded-member-function
2510 -Wunsupported-visibility
2511 -Wunused-but-set-parameter
2512 -Wunused-but-set-variable
2513 -Wunused-command-line-argument
2514 -Wunused-const-variable=2
2515 -Wunused-exception-parameter
2516 -Wunused-local-typedefs
2517 -Wunused-member-function
2518 -Wunused-sanitize-argument
2519 -Wunused-volatile-lvalue
2520 -Wuser-defined-literals
2523 -Wvector-conversions
2528 ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
2529 [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
2532 dnl We should re-enable this in some later version. Clang doesn't
2533 dnl mind, but it causes trouble with GCC.
2534 dnl -Wstrict-overflow=2
2536 dnl These seem to require annotations that we don't currently use,
2537 dnl and they give false positives in our pthreads wrappers. (Clang 4)
2539 dnl -Wthread-safety-analysis
2540 dnl -Wthread-safety-attributes
2541 dnl -Wthread-safety-beta
2542 dnl -Wthread-safety-precise
2544 W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2545 W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2546 W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2547 W_FLAGS="$W_FLAGS -Wwrite-strings"
2548 W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2549 W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
2550 W_FLAGS="$W_FLAGS -Wunused-parameter "
2551 # These interfere with building main() { return 0; }, which autoconf
2552 # likes to use as its default program.
2553 W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
2555 TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
2556 CFLAGS="$CFLAGS $W_FLAGS"
2558 if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2559 AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2561 if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2562 AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2564 if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2565 AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2568 CFLAGS="$CFLAGS_NOWARNINGS"
2570 if test "x$enable_fatal_warnings" = "xyes"; then
2571 # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2572 # default autoconf programs are full of errors.
2573 CFLAGS="$CFLAGS -Werror"
2578 AC_SUBST(TOR_WARNING_FLAGS)
2580 echo "$TOR_WARNING_FLAGS">warning_flags
2582 TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
2583 CFLAGS="$CFLAGS @warning_flags",
2584 CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
2586 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2589 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.])
2593 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2599 contrib/operator-tools/tor.logrotate
2600 contrib/dist/tor.service
2601 src/config/torrc.sample
2602 src/config/torrc.minimal
2603 src/rust/.cargo/config
2604 scripts/maint/checkOptionDocs.pl
2608 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2609 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2610 for file in $regular_mans ; do
2611 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2612 echo "==================================";
2614 echo "Building Tor has failed since manpages cannot be built.";
2616 echo "You need asciidoc installed to be able to build the manpages.";
2617 echo "To build without manpages, use the --disable-asciidoc argument";
2618 echo "when calling configure.";
2620 echo "==================================";
2626 if test "$fragile_hardening" = "yes"; then
2630 Warning! Building Tor with --enable-fragile-hardening (also known as
2631 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2632 other kinds of attacks easier. A Tor instance build with this option will be
2633 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2634 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2635 denial of service attacks. For more information, see
2636 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
2644 # Mini-report on what will be built.
2648 PPRINT_SET_INDENT(1)
2652 AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
2655 PPRINT_SUBTITLE([Build Features])
2657 PPRINT_PROP_STRING([Compiler], [$CC])
2658 PPRINT_PROP_STRING([Host OS], [$host_os])
2661 test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
2662 PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
2664 test "x$enable_rust" = "xyes" && value=1 || value=0
2665 PPRINT_PROP_BOOL([Rust support (--enable-rust)], $value)
2667 test "x$enable_cargo_online_mode" = "xyes" && value=1 || value=0
2668 PPRINT_PROP_BOOL([Cargo Online Fetch (--enable-cargo-online-mode)], $value)
2670 test "x$enable_android" = "xyes" && value=1 || value=0
2671 PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
2674 PPRINT_SUBTITLE([Static Build])
2676 test "x$enable_static_tor" = "xyes" && value=1 || value=0
2677 PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
2679 if test "x$enable_static_libevent" = "xyes"; then
2680 PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
2682 PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
2685 if test "x$enable_static_openssl" = "xyes"; then
2686 PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
2688 PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
2691 if test "x$enable_static_zlib" = "xyes"; then
2692 PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
2694 PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
2698 PPRINT_SUBTITLE([Optional Libraries])
2700 test "x$enable_nss" = "xyes" && value=1 || value=0
2701 PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
2703 test "x$enable_seccomp" != "xno" && value=1 || value=0
2704 PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
2706 test "x$enable_libscrypt" != "xno" && value=1 || value=0
2707 PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
2709 test "x$enable_systemd" = "xyes" && value=1 || value=0
2710 PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
2712 test "x$enable_lzma" = "xyes" && value=1 || value=0
2713 PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
2715 test "x$enable_zstd" = "xyes" && value=1 || value=0
2716 PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
2719 PPRINT_SUBTITLE([Hardening])
2721 test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
2722 PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
2724 test "x$enable_linker_hardening" != "xno" && value=1 || value=0
2725 PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
2727 test "x$fragile_hardening" = "xyes" && value=1 || value=0
2728 PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
2731 PPRINT_SUBTITLE([Modules])
2733 m4_foreach_w([mname], MODULES,
2735 AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
2736 PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value)
2741 PPRINT_SUBTITLE([Documentation])
2743 test "x$enable_asciidoc" != "xno" && value=1 || value=0
2744 PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
2746 test "x$enable_manpage" != "xno" && value=1 || value=0
2747 PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
2749 test "x$enable_html_manual" != "xno" && value=1 || value=0
2750 PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
2753 PPRINT_SUBTITLE([Tests])
2755 test "x$enable_unittests" != "xno" && value=1 || value=0
2756 PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
2758 test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
2759 PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
2761 test "x$enable_coverage" = "xyes" && value=1 || value=0
2762 PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
2764 test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
2765 PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
2767 test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
2768 PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
2771 PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
2773 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
2774 PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
2776 test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
2777 PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
2779 test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
2780 PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
2783 PPRINT_SUBTITLE([Install Directories])
2785 report_mandir="`eval eval echo $mandir`"
2786 PPRINT_PROP_STRING([Binaries], [$BINDIR])
2787 PPRINT_PROP_STRING([Configuration], [$CONFDIR])
2788 PPRINT_PROP_STRING([Man Pages], [$report_mandir])
2791 AS_ECHO(["Configure Line: ./configure $configure_flags"])