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