better comments and mild refactoring
[tor.git] / configure.ac
blob4092d10af656b54a4c179c92b6bb1ddc1e24bf6e
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.2.0-alpha-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.]))
63 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
64     AC_MSG_ERROR([Can't disable assertions outside of coverage build])
67 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
68 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
69 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
70 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
71 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
72 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
74 if test "$enable_static_tor" = "yes"; then
75   enable_static_libevent="yes";
76   enable_static_openssl="yes";
77   enable_static_zlib="yes";
78   CFLAGS="$CFLAGS -static"
81 if test "$enable_system_torrc" = "no"; then
82   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
83             [Defined if we're not going to look for a torrc in SYSCONF])
86 if test "$enable_memory_sentinels" = "no"; then
87   AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
88            [Defined if we're turning off memory safety code to look for bugs])
91 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
93 AC_ARG_ENABLE(asciidoc,
94      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
95      [case "${enableval}" in
96         "yes") asciidoc=true ;;
97         "no")  asciidoc=false ;;
98         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
99       esac], [asciidoc=true])
101 # systemd notify support
102 AC_ARG_ENABLE(systemd,
103       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
104       [case "${enableval}" in
105         "yes") systemd=true ;;
106         "no")  systemd=false ;;
107         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
108       esac], [systemd=auto])
112 # systemd support
113 if test "x$enable_systemd" = "xno"; then
114     have_systemd=no;
115 else
116     PKG_CHECK_MODULES(SYSTEMD,
117         [libsystemd-daemon],
118         have_systemd=yes,
119         have_systemd=no)
120     if test "x$have_systemd" = "xno"; then
121         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
122         PKG_CHECK_MODULES(SYSTEMD,
123             [libsystemd],
124             have_systemd=yes,
125             have_systemd=no)
126     fi
129 if test "x$have_systemd" = "xyes"; then
130     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
131     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
132     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
133     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
134          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
136 AC_SUBST(TOR_SYSTEMD_CFLAGS)
137 AC_SUBST(TOR_SYSTEMD_LIBS)
139 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
140     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
143 case "$host" in
144    *-*-solaris* )
145      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
146      ;;
147 esac
149 AC_ARG_ENABLE(gcc-warnings,
150      AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
151 AC_ARG_ENABLE(fatal-warnings,
152      AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
153 AC_ARG_ENABLE(gcc-warnings-advisory,
154      AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
156 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
157 AC_ARG_ENABLE(gcc-hardening,
158     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
160 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
161 AC_ARG_ENABLE(expensive-hardening,
162     AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
163 AC_ARG_ENABLE(fragile-hardening,
164     AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
165 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
166   fragile_hardening="yes"
169 dnl Linker hardening options
170 dnl Currently these options are ELF specific - you can't use this with MacOSX
171 AC_ARG_ENABLE(linker-hardening,
172     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
174 AC_ARG_ENABLE(local-appdata,
175    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
176 if test "$enable_local_appdata" = "yes"; then
177   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
178             [Defined if we default to host local appdata paths on Windows])
181 # Tor2web mode flag
182 AC_ARG_ENABLE(tor2web-mode,
183      AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
184 [if test "x$enableval" = "xyes"; then
185     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
186 fi])
188 AC_ARG_ENABLE(tool-name-check,
189      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
191 AC_ARG_ENABLE(seccomp,
192      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
194 AC_ARG_ENABLE(libscrypt,
195      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
197 dnl Enable event tracing which are transformed to debug log statement.
198 AC_ARG_ENABLE(event-tracing-debug,
199      AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
200 AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
202 if test x$enable_event_tracing_debug = xyes; then
203   AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
204   AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
207 dnl check for the correct "ar" when cross-compiling.
208 dnl   (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
209 dnl    so kludge up a replacement for the case where it isn't there yet.)
210 m4_ifdef([AM_PROG_AR],
211          [AM_PROG_AR],
212          [AN_MAKEVAR([AR], [AC_PROG_AR])
213           AN_PROGRAM([ar], [AC_PROG_AR])
214           AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
215           AC_PROG_AR])
217 dnl Check whether the above macro has settled for a simply named tool even
218 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
219 dnl because that will find any cc on the system, not only the cross-compiler,
220 dnl and then verify that a binary built with this compiler runs on the
221 dnl build system. It will then come to the false conclusion that we're not
222 dnl cross-compiling.
223 if test "x$enable_tool_name_check" != "xno"; then
224     if test "x$ac_tool_warned" = "xyes"; then
225         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.)])
226         elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
227                 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.)])
228         fi
231 AC_PROG_CC
232 AC_PROG_CPP
233 AC_PROG_MAKE_SET
234 AC_PROG_RANLIB
235 AC_PROG_SED
237 AC_ARG_VAR([PERL], [path to Perl binary])
238 AC_CHECK_PROGS([PERL], [perl])
239 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
241 dnl check for asciidoc and a2x
242 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
243 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
245 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
247 AM_PROG_CC_C_O
248 AC_PROG_CC_C99
250 AC_ARG_VAR([PYTHON], [path to Python binary])
251 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
252 if test "x$PYTHON" = "x"; then
253   AC_MSG_WARN([Python unavailable; some tests will not be run.])
255 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
257 dnl List all external rust crates we depend on here. Include the version
258 rust_crates="libc-0.2.22"
259 AC_SUBST(rust_crates)
261 if test "x$enable_rust" = "xyes"; then
262   AC_ARG_VAR([RUSTC], [path to the rustc binary])
263   AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
264   if test "x$RUSTC" = "xno"; then
265     AC_MSG_ERROR([rustc unavailable but rust integration requested.])
266   fi
268   AC_ARG_VAR([CARGO], [path to the cargo binary])
269   AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
270   if test "x$CARGO" = "xno"; then
271     AC_MSG_ERROR([cargo unavailable but rust integration requested.])
272   fi
274   AC_DEFINE([HAVE_RUST], 1, [have Rust])
275   if test "x$enable_cargo_online_mode" = "xyes"; then
276     CARGO_ONLINE=
277     RUST_DL=#
278   else
279     CARGO_ONLINE=--frozen
280     RUST_DL=
282     dnl When we're not allowed to touch the network, we need crate dependencies
283     dnl locally available.
284     AC_MSG_CHECKING([rust crate dependencies])
285     AC_ARG_VAR([RUST_DEPENDENCIES], [path to directory with local crate mirror])
286     if test "x$RUST_DEPENDENCIES" = "x"; then
287       RUST_DEPENDENCIES="$srcdir/src/ext/rust/"
288       NEED_MOD=1
289     fi
290     if test ! -d "$RUST_DEPENDENCIES"; then
291       AC_MSG_ERROR([Rust dependency directory $RUST_DEPENDENCIES does not exist. Specify a dependency directory using the RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
292     fi
293     for dep in $rust_crates; do
294       if test ! -d "$RUST_DEPENDENCIES"/"$dep"; then
295         AC_MSG_ERROR([Failure to find rust dependency $RUST_DEPENDENCIES/$dep. Specify a dependency directory using the RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
296       fi
297     done
298     if test "x$NEED_MOD" = "x1"; then
299       dnl When looking for dependencies from cargo, pick right directory
300       RUST_DEPENDENCIES="../../src/ext/rust"
301     fi
302   fi
304   AC_SUBST(CARGO_ONLINE)
305   AC_SUBST(RUST_DL)
307 dnl Let's check the rustc version, too
308   AC_MSG_CHECKING([rust version])
309   RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
310   RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
311   if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
312     AC_MSG_ERROR([rustc version couldn't be identified])
313   fi
314   if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
315     AC_MSG_ERROR([rustc must be at least version 1.14])
316   fi
319 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
320 AC_C_FLEXIBLE_ARRAY_MEMBER
321 ], [
322  dnl Maybe we've got an old autoconf...
323  AC_CACHE_CHECK([for flexible array members],
324      tor_cv_c_flexarray,
325      [AC_COMPILE_IFELSE(
326        AC_LANG_PROGRAM([
327  struct abc { int a; char b[]; };
328 ], [
329  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
330  def->b[0] = 33;
332   [tor_cv_c_flexarray=yes],
333   [tor_cv_c_flexarray=no])])
334  if test "$tor_cv_flexarray" = "yes"; then
335    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
336  else
337    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
338  fi
341 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
342       tor_cv_c_c99_decl,
343       [AC_COMPILE_IFELSE(
344          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
345          [tor_cv_c_c99_decl=yes],
346          [tor_cv_c_c99_decl=no] )])
347 if test "$tor_cv_c_c99_decl" != "yes"; then
348   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
351 AC_CACHE_CHECK([for working C99 designated initializers],
352       tor_cv_c_c99_designated_init,
353       [AC_COMPILE_IFELSE(
354          [AC_LANG_PROGRAM([struct s { int a; int b; };],
355                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
356          [tor_cv_c_c99_designated_init=yes],
357          [tor_cv_c_c99_designated_init=no] )])
359 if test "$tor_cv_c_c99_designated_init" != "yes"; then
360   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
363 TORUSER=_tor
364 AC_ARG_WITH(tor-user,
365         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
366         [
367            TORUSER=$withval
368         ]
370 AC_SUBST(TORUSER)
372 TORGROUP=_tor
373 AC_ARG_WITH(tor-group,
374         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
375         [
376            TORGROUP=$withval
377         ]
379 AC_SUBST(TORGROUP)
382 dnl If _WIN32 is defined and non-zero, we are building for win32
383 AC_MSG_CHECKING([for win32])
384 AC_RUN_IFELSE([AC_LANG_SOURCE([
385 int main(int c, char **v) {
386 #ifdef _WIN32
387 #if _WIN32
388   return 0;
389 #else
390   return 1;
391 #endif
392 #else
393   return 2;
394 #endif
395 }])],
396 bwin32=true; AC_MSG_RESULT([yes]),
397 bwin32=false; AC_MSG_RESULT([no]),
398 bwin32=cross; AC_MSG_RESULT([cross])
401 if test "$bwin32" = "cross"; then
402 AC_MSG_CHECKING([for win32 (cross)])
403 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
404 #ifdef _WIN32
405 int main(int c, char **v) {return 0;}
406 #else
407 #error
408 int main(int c, char **v) {return x(y);}
409 #endif
410 ])],
411 bwin32=true; AC_MSG_RESULT([yes]),
412 bwin32=false; AC_MSG_RESULT([no]))
415 AH_BOTTOM([
416 #ifdef _WIN32
417 /* Defined to access windows functions and definitions for >=WinXP */
418 # ifndef WINVER
419 #  define WINVER 0x0501
420 # endif
422 /* Defined to access _other_ windows functions and definitions for >=WinXP */
423 # ifndef _WIN32_WINNT
424 #  define _WIN32_WINNT 0x0501
425 # endif
427 /* Defined to avoid including some windows headers as part of Windows.h */
428 # ifndef WIN32_LEAN_AND_MEAN
429 #  define WIN32_LEAN_AND_MEAN 1
430 # endif
431 #endif
435 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
437 dnl Enable C99 when compiling with MIPSpro
438 AC_MSG_CHECKING([for MIPSpro compiler])
439 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
440 #if (defined(__sgi) && defined(_COMPILER_VERSION))
441 #error
442   return x(y);
443 #endif
444 ])],
445 bmipspro=false; AC_MSG_RESULT(no),
446 bmipspro=true; AC_MSG_RESULT(yes))
448 if test "$bmipspro" = "true"; then
449   CFLAGS="$CFLAGS -c99"
452 AC_C_BIGENDIAN
454 AC_SEARCH_LIBS(socket, [socket network])
455 AC_SEARCH_LIBS(gethostbyname, [nsl])
456 AC_SEARCH_LIBS(dlopen, [dl])
457 AC_SEARCH_LIBS(inet_aton, [resolv])
458 AC_SEARCH_LIBS(backtrace, [execinfo])
459 saved_LIBS="$LIBS"
460 AC_SEARCH_LIBS([clock_gettime], [rt])
461 if test "$LIBS" != "$saved_LIBS"; then
462    # Looks like we need -lrt for clock_gettime().
463    have_rt=yes
466 AC_SEARCH_LIBS(pthread_create, [pthread])
467 AC_SEARCH_LIBS(pthread_detach, [pthread])
469 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
470 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
472 AC_CHECK_FUNCS(
473         _NSGetEnviron \
474         RtlSecureZeroMemory \
475         SecureZeroMemory \
476         accept4 \
477         backtrace \
478         backtrace_symbols_fd \
479         eventfd \
480         explicit_bzero \
481         timingsafe_memcmp \
482         flock \
483         ftime \
484         getaddrinfo \
485         getifaddrs \
486         getpass \
487         getrlimit \
488         gettimeofday \
489         gmtime_r \
490         htonll \
491         inet_aton \
492         ioctl \
493         issetugid \
494         llround \
495         localtime_r \
496         lround \
497         memmem \
498         memset_s \
499         pipe \
500         pipe2 \
501         prctl \
502         readpassphrase \
503         rint \
504         sigaction \
505         socketpair \
506         statvfs \
507         strlcat \
508         strlcpy \
509         strnlen \
510         strptime \
511         strtok_r \
512         strtoull \
513         sysconf \
514         sysctl \
515         truncate \
516         uname \
517         usleep \
518         vasprintf \
519         _vscprintf
522 # Apple messed up when they added two functions functions in Sierra: they
523 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
524 # checks. So we should only probe for those functions if we are sure that we
525 # are not targetting OSX 10.11 or earlier.
526 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
527 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
528 #ifdef __APPLE__
529 #  include <AvailabilityMacros.h>
530 #  ifndef MAC_OS_X_VERSION_10_12
531 #    define MAC_OS_X_VERSION_10_12 101200
532 #  endif
533 #  if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
534 #    if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
535 #      error "Running on Mac OSX 10.11 or earlier"
536 #    endif
537 #  endif
538 #endif
539 ]], [[]])],
540    [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
541    [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
543 if test "$on_macos_pre_10_12" = "no"; then
544   AC_CHECK_FUNCS(
545         clock_gettime \
546         getentropy \
547   )
550 if test "$bwin32" != "true"; then
551   AC_CHECK_HEADERS(pthread.h)
552   AC_CHECK_FUNCS(pthread_create)
553   AC_CHECK_FUNCS(pthread_condattr_setclock)
556 if test "$bwin32" = "true"; then
557   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
558 #include <windows.h>
559 #include <conio.h>
560 #include <wchar.h>
561                  ])
564 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
565   test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
567 dnl ------------------------------------------------------
568 dnl Where do you live, libevent?  And how do we call you?
570 if test "$bwin32" = "true"; then
571   TOR_LIB_WS32=-lws2_32
572   TOR_LIB_IPHLPAPI=-liphlpapi
573   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
574   # think it's actually necessary.
575   TOR_LIB_GDI=-lgdi32
576 else
577   TOR_LIB_WS32=
578   TOR_LIB_GDI=
580 AC_SUBST(TOR_LIB_WS32)
581 AC_SUBST(TOR_LIB_GDI)
582 AC_SUBST(TOR_LIB_IPHLPAPI)
584 tor_libevent_pkg_redhat="libevent"
585 tor_libevent_pkg_debian="libevent-dev"
586 tor_libevent_devpkg_redhat="libevent-devel"
587 tor_libevent_devpkg_debian="libevent-dev"
589 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
590 dnl linking for static builds.
591 STATIC_LIBEVENT_FLAGS=""
592 if test "$enable_static_libevent" = "yes"; then
593     if test "$have_rt" = "yes"; then
594       STATIC_LIBEVENT_FLAGS=" -lrt "
595     fi
598 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
599 #ifdef _WIN32
600 #include <winsock2.h>
601 #endif
602 #include <sys/time.h>
603 #include <sys/types.h>
604 #include <event2/event.h>], [
605 #ifdef _WIN32
606 #include <winsock2.h>
607 #endif
608 struct event_base;
609 struct event_base *event_base_new(void);],
610     [
611 #ifdef _WIN32
612 {WSADATA d; WSAStartup(0x101,&d); }
613 #endif
614 event_base_new();
615 ], [--with-libevent-dir], [/opt/libevent])
617 dnl Determine the incantation needed to link libevent.
618 save_LIBS="$LIBS"
619 save_LDFLAGS="$LDFLAGS"
620 save_CPPFLAGS="$CPPFLAGS"
622 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
623 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
624 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
626 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
628 if test "$enable_static_libevent" = "yes"; then
629    if test "$tor_cv_library_libevent_dir" = "(system)"; then
630      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
631    else
632      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
633    fi
634 else
635      if test "x$ac_cv_header_event2_event_h" = "xyes"; then
636        AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
637        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"))
639        if test "$ac_cv_search_event_new" != "none required"; then
640          TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
641        fi
642        if test "$ac_cv_search_evdns_base_new" != "none required"; then
643          TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
644        fi
645      else
646        AC_MSG_ERROR("libevent2 is required but the headers could not be found")
647      fi
650 dnl Now check for particular libevent functions.
651 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
652                 evutil_secure_rng_add_bytes \
655 LIBS="$save_LIBS"
656 LDFLAGS="$save_LDFLAGS"
657 CPPFLAGS="$save_CPPFLAGS"
659 dnl Check that libevent is at least at version 2.0.10, the first stable
660 dnl release of its series
661 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
662 AC_MSG_CHECKING([whether Libevent is new enough])
663 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
664 #include <event2/event.h>
665 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
666 #error
667 int x = y(zz);
668 #else
669 int x = 1;
670 #endif
671 ])], [ AC_MSG_RESULT([yes]) ],
672    [ AC_MSG_RESULT([no])
673      AC_MSG_ERROR([Libevent is not new enough.  We require 2.0.10-stable or later]) ] )
675 LIBS="$save_LIBS"
676 LDFLAGS="$save_LDFLAGS"
677 CPPFLAGS="$save_CPPFLAGS"
679 AC_SUBST(TOR_LIBEVENT_LIBS)
681 dnl ------------------------------------------------------
682 dnl Where do you live, libm?
684 dnl On some platforms (Haiku/BeOS) the math library is
685 dnl part of libroot. In which case don't link against lm
686 TOR_LIB_MATH=""
687 save_LIBS="$LIBS"
688 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
689 if test "$ac_cv_search_pow" != "none required"; then
690     TOR_LIB_MATH="$ac_cv_search_pow"
692 LIBS="$save_LIBS"
693 AC_SUBST(TOR_LIB_MATH)
695 dnl ------------------------------------------------------
696 dnl Where do you live, openssl?  And how do we call you?
698 tor_openssl_pkg_redhat="openssl"
699 tor_openssl_pkg_debian="libssl-dev"
700 tor_openssl_devpkg_redhat="openssl-devel"
701 tor_openssl_devpkg_debian="libssl-dev"
703 ALT_openssl_WITHVAL=""
704 AC_ARG_WITH(ssl-dir,
705   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
706   [
707       if test "x$withval" != "xno" && test "x$withval" != "x"; then
708          ALT_openssl_WITHVAL="$withval"
709       fi
710   ])
712 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
713     [#include <openssl/rand.h>],
714     [void RAND_add(const void *buf, int num, double entropy);],
715     [RAND_add((void*)0,0,0);], [],
716     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
718 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
720 if test "$enable_static_openssl" = "yes"; then
721    if test "$tor_cv_library_openssl_dir" = "(system)"; then
722      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
723    else
724      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
725    fi
726 else
727      TOR_OPENSSL_LIBS="-lssl -lcrypto"
729 AC_SUBST(TOR_OPENSSL_LIBS)
731 dnl Now check for particular openssl functions.
732 save_LIBS="$LIBS"
733 save_LDFLAGS="$LDFLAGS"
734 save_CPPFLAGS="$CPPFLAGS"
735 LIBS="$TOR_OPENSSL_LIBS $LIBS"
736 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
737 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
739 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
740 #include <openssl/opensslv.h>
741 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
742 #error "too old"
743 #endif
744    ]], [[]])],
745    [ : ],
746    [ 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.]) ])
748 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
749 #include <openssl/opensslv.h>
750 #include <openssl/evp.h>
751 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
752 #error "no ECC"
753 #endif
754 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
755 #error "curves unavailable"
756 #endif
757    ]], [[]])],
758    [ : ],
759    [ 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.]) ])
761 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
762 [#include <openssl/ssl.h>
765 AC_CHECK_FUNCS([ \
766                 SSL_SESSION_get_master_key \
767                 SSL_get_server_random \
768                 SSL_get_client_ciphers \
769                 SSL_get_client_random \
770                 SSL_CIPHER_find \
771                 TLS_method
772                ])
774 dnl Check if OpenSSL has scrypt implementation.
775 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
777 dnl Check if OpenSSL structures are opaque
778 AC_CHECK_MEMBERS([SSL.state], , ,
779 [#include <openssl/ssl.h>
782 LIBS="$save_LIBS"
783 LDFLAGS="$save_LDFLAGS"
784 CPPFLAGS="$save_CPPFLAGS"
786 dnl ------------------------------------------------------
787 dnl Where do you live, zlib?  And how do we call you?
789 tor_zlib_pkg_redhat="zlib"
790 tor_zlib_pkg_debian="zlib1g"
791 tor_zlib_devpkg_redhat="zlib-devel"
792 tor_zlib_devpkg_debian="zlib1g-dev"
794 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
795     [#include <zlib.h>],
796     [const char * zlibVersion(void);],
797     [zlibVersion();], [--with-zlib-dir],
798     [/opt/zlib])
800 if test "$enable_static_zlib" = "yes"; then
801    if test "$tor_cv_library_zlib_dir" = "(system)"; then
802      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
803  using --enable-static-zlib")
804    else
805      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
806    fi
807 else
808      TOR_ZLIB_LIBS="-lz"
810 AC_SUBST(TOR_ZLIB_LIBS)
812 dnl ------------------------------------------------------
813 dnl Where we do we find lzma?
815 AC_ARG_ENABLE(lzma,
816       AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
817       [case "${enableval}" in
818         "yes") lzma=true ;;
819         "no")  lzma=false ;;
820         * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
821       esac], [lzma=auto])
823 if test "x$enable_lzma" = "xno"; then
824     have_lzma=no;
825 else
826     PKG_CHECK_MODULES([LZMA],
827                       [liblzma],
828                       have_lzma=yes,
829                       have_lzma=no)
831     if test "x$have_lzma" = "xno" ; then
832         AC_MSG_WARN([Unable to find liblzma.])
833     fi
836 if test "x$have_lzma" = "xyes"; then
837     AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
838     TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
839     TOR_LZMA_LIBS="${LZMA_LIBS}"
841 AC_SUBST(TOR_LZMA_CFLAGS)
842 AC_SUBST(TOR_LZMA_LIBS)
844 dnl ------------------------------------------------------
845 dnl Where we do we find zstd?
847 AC_ARG_ENABLE(zstd,
848       AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
849       [case "${enableval}" in
850         "yes") zstd=true ;;
851         "no")  zstd=false ;;
852         * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
853       esac], [zstd=auto])
855 if test "x$enable_zstd" = "xno"; then
856     have_zstd=no;
857 else
858     PKG_CHECK_MODULES([ZSTD],
859                       [libzstd >= 1.1],
860                       have_zstd=yes,
861                       have_zstd=no)
863     if test "x$have_zstd" = "xno" ; then
864         AC_MSG_WARN([Unable to find libzstd.])
865     fi
868 if test "x$have_zstd" = "xyes"; then
869     AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
870     TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
871     TOR_ZSTD_LIBS="${ZSTD_LIBS}"
873 AC_SUBST(TOR_ZSTD_CFLAGS)
874 AC_SUBST(TOR_ZSTD_LIBS)
876 dnl ----------------------------------------------------------------------
877 dnl Check if libcap is available for capabilities.
879 tor_cap_pkg_debian="libcap2"
880 tor_cap_pkg_redhat="libcap"
881 tor_cap_devpkg_debian="libcap-dev"
882 tor_cap_devpkg_redhat="libcap-devel"
884 AC_CHECK_LIB([cap], [cap_init], [],
885   AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
887 AC_CHECK_FUNCS(cap_set_proc)
889 dnl ---------------------------------------------------------------------
890 dnl Now that we know about our major libraries, we can check for compiler
891 dnl and linker hardening options.  We need to do this with the libraries known,
892 dnl since sometimes the linker will like an option but not be willing to
893 dnl use it with a build of a library.
895 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
896 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_CAP_LIBS"
898 CFLAGS_FTRAPV=
899 CFLAGS_FWRAPV=
900 CFLAGS_ASAN=
901 CFLAGS_UBSAN=
904 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
905 #if !defined(__clang__)
906 #error
907 #endif])], have_clang=yes, have_clang=no)
909 if test "x$enable_gcc_hardening" != "xno"; then
910     CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
911     if test "x$have_clang" = "xyes"; then
912         TOR_CHECK_CFLAGS(-Qunused-arguments)
913     fi
914     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
915     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
916     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
917 m4_ifdef([AS_VAR_IF],[
918     AS_VAR_IF(can_compile, [yes],
919         AS_VAR_IF(can_link, [yes],
920                   [],
921                   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.)]))
922         )])
923     AS_VAR_POPDEF([can_link])
924     AS_VAR_POPDEF([can_compile])
925     TOR_CHECK_CFLAGS(-Wstack-protector)
926     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
927     if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
928        TOR_CHECK_CFLAGS(-fPIE)
929        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
930     fi
931     TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
934 if test "$fragile_hardening" = "yes"; then
935     TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
936    if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
937       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.])
938    fi
940    if test "$tor_cv_cflags__ftrapv" != "yes"; then
941      AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
942    fi
944    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
945     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
946       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.so, and with Clang you need libclang_rt.ubsan*])
947     fi
949    TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
950     if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
951       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.so, and with Clang you need libclang_rt.ubsan*])
952     fi
954 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
957 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
958 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
960 mulodi_fixes_ftrapv=no
961 if test "$have_clang" = "yes"; then
962   saved_CFLAGS="$CFLAGS"
963   CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
964   AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
965   AC_LINK_IFELSE([
966       AC_LANG_SOURCE([[
967           #include <stdint.h>
968           #include <stdlib.h>
969           int main(int argc, char **argv)
970           {
971             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
972                         * (int64_t)atoi(argv[3]);
973             return x == 9;
974           } ]])],
975           [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
976           [ftrapv_can_link=no; AC_MSG_RESULT([no])])
977   if test "$ftrapv_can_link" = "no"; then
978     AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
979     AC_LINK_IFELSE([
980       AC_LANG_SOURCE([[
981           #include <stdint.h>
982           #include <stdlib.h>
983           int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
984              *overflow=0;
985              return a;
986           }
987           int main(int argc, char **argv)
988           {
989             int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
990                         * (int64_t)atoi(argv[3]);
991             return x == 9;
992           } ]])],
993           [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
994           [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
995   fi
996   CFLAGS="$saved_CFLAGS"
999 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1001 dnl These cflags add bunches of branches, and we haven't been able to
1002 dnl persuade ourselves that they're suitable for code that needs to be
1003 dnl constant time.
1004 AC_SUBST(CFLAGS_BUGTRAP)
1005 dnl These cflags are variant ones sutable for code that needs to be
1006 dnl constant-time.
1007 AC_SUBST(CFLAGS_CONSTTIME)
1009 if test "x$enable_linker_hardening" != "xno"; then
1010     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1013 # For backtrace support
1014 TOR_CHECK_LDFLAGS(-rdynamic)
1016 dnl ------------------------------------------------------
1017 dnl Now see if we have a -fomit-frame-pointer compiler option.
1019 saved_CFLAGS="$CFLAGS"
1020 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1021 F_OMIT_FRAME_POINTER=''
1022 if test "$saved_CFLAGS" != "$CFLAGS"; then
1023   if test "$fragile_hardening" = "yes"; then
1024     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1025   fi
1027 CFLAGS="$saved_CFLAGS"
1028 AC_SUBST(F_OMIT_FRAME_POINTER)
1030 dnl ------------------------------------------------------
1031 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1032 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1033 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1034 dnl code will work.
1035 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1037 dnl ============================================================
1038 dnl Check for libseccomp
1040 if test "x$enable_seccomp" != "xno"; then
1041   AC_CHECK_HEADERS([seccomp.h])
1042   AC_SEARCH_LIBS(seccomp_init, [seccomp])
1045 dnl ============================================================
1046 dnl Check for libscrypt
1048 if test "x$enable_libscrypt" != "xno"; then
1049   AC_CHECK_HEADERS([libscrypt.h])
1050   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1051   AC_CHECK_FUNCS([libscrypt_scrypt])
1054 dnl ============================================================
1055 dnl We need an implementation of curve25519.
1057 dnl set these defaults.
1058 build_curve25519_donna=no
1059 build_curve25519_donna_c64=no
1060 use_curve25519_donna=no
1061 use_curve25519_nacl=no
1062 CURVE25519_LIBS=
1064 dnl The best choice is using curve25519-donna-c64, but that requires
1065 dnl that we
1066 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1067   tor_cv_can_use_curve25519_donna_c64,
1068   [AC_RUN_IFELSE(
1069     [AC_LANG_PROGRAM([dnl
1070       #include <stdint.h>
1071       typedef unsigned uint128_t __attribute__((mode(TI)));
1072   int func(uint64_t a, uint64_t b) {
1073            uint128_t c = ((uint128_t)a) * b;
1074            int ok = ((uint64_t)(c>>96)) == 522859 &&
1075              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1076                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1077                  (((uint64_t)(c))&0xffffffffL) == 0;
1078            return ok;
1079       }
1080   ], [dnl
1081     int ok = func( ((uint64_t)2000000000) * 1000000000,
1082                    ((uint64_t)1234567890) << 24);
1083         return !ok;
1084       ])],
1085   [tor_cv_can_use_curve25519_donna_c64=yes],
1086       [tor_cv_can_use_curve25519_donna_c64=no],
1087   [AC_LINK_IFELSE(
1088         [AC_LANG_PROGRAM([dnl
1089       #include <stdint.h>
1090       typedef unsigned uint128_t __attribute__((mode(TI)));
1091   int func(uint64_t a, uint64_t b) {
1092            uint128_t c = ((uint128_t)a) * b;
1093            int ok = ((uint64_t)(c>>96)) == 522859 &&
1094              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1095                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1096                  (((uint64_t)(c))&0xffffffffL) == 0;
1097            return ok;
1098       }
1099   ], [dnl
1100     int ok = func( ((uint64_t)2000000000) * 1000000000,
1101                  ((uint64_t)1234567890) << 24);
1102         return !ok;
1103       ])],
1104           [tor_cv_can_use_curve25519_donna_c64=cross],
1105       [tor_cv_can_use_curve25519_donna_c64=no])])])
1107 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1108                   nacl/crypto_scalarmult_curve25519.h])
1110 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1111   tor_cv_can_use_curve25519_nacl,
1112   [tor_saved_LIBS="$LIBS"
1113    LIBS="$LIBS -lnacl"
1114    AC_LINK_IFELSE(
1115      [AC_LANG_PROGRAM([dnl
1116        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1117        #include <crypto_scalarmult_curve25519.h>
1118    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1119    #include <nacl/crypto_scalarmult_curve25519.h>
1120    #endif
1121        #ifdef crypto_scalarmult_curve25519_ref_BYTES
1122    #error Hey, this is the reference implementation! That's not fast.
1123    #endif
1124      ], [
1125    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1126      ])], [tor_cv_can_use_curve25519_nacl=yes],
1127      [tor_cv_can_use_curve25519_nacl=no])
1128    LIBS="$tor_saved_LIBS" ])
1130  dnl Okay, now we need to figure out which one to actually use. Fall back
1131  dnl to curve25519-donna.c
1133  if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1134    build_curve25519_donna_c64=yes
1135    use_curve25519_donna=yes
1136  elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1137    use_curve25519_nacl=yes
1138    CURVE25519_LIBS=-lnacl
1139  else
1140    build_curve25519_donna=yes
1141    use_curve25519_donna=yes
1142  fi
1144 if test "x$use_curve25519_donna" = "xyes"; then
1145   AC_DEFINE(USE_CURVE25519_DONNA, 1,
1146             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1148 if test "x$use_curve25519_nacl" = "xyes"; then
1149   AC_DEFINE(USE_CURVE25519_NACL, 1,
1150             [Defined if we should use a curve25519 from nacl])
1152 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1153   test "x$build_curve25519_donna" = "xyes")
1154 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1155   test "x$build_curve25519_donna_c64" = "xyes")
1156 AC_SUBST(CURVE25519_LIBS)
1158 dnl Make sure to enable support for large off_t if available.
1159 AC_SYS_LARGEFILE
1161 AC_CHECK_HEADERS([assert.h \
1162                   errno.h \
1163                   fcntl.h \
1164                   signal.h \
1165                   string.h \
1166                   sys/capability.h \
1167                   sys/fcntl.h \
1168                   sys/stat.h \
1169                   sys/time.h \
1170                   sys/types.h \
1171                   time.h \
1172                   unistd.h \
1173                   arpa/inet.h \
1174                   crt_externs.h \
1175                   execinfo.h \
1176                   grp.h \
1177                   ifaddrs.h \
1178                   inttypes.h \
1179                   limits.h \
1180                   linux/types.h \
1181                   machine/limits.h \
1182                   malloc.h \
1183                   malloc/malloc.h \
1184                   malloc_np.h \
1185                   netdb.h \
1186                   netinet/in.h \
1187                   netinet/in6.h \
1188                   pwd.h \
1189                   readpassphrase.h \
1190                   stdint.h \
1191                   sys/eventfd.h \
1192                   sys/file.h \
1193                   sys/ioctl.h \
1194                   sys/limits.h \
1195                   sys/mman.h \
1196                   sys/param.h \
1197                   sys/prctl.h \
1198                   sys/random.h \
1199                   sys/resource.h \
1200                   sys/select.h \
1201                   sys/socket.h \
1202                   sys/statvfs.h \
1203                   sys/syscall.h \
1204                   sys/sysctl.h \
1205                   sys/syslimits.h \
1206                   sys/time.h \
1207                   sys/types.h \
1208                   sys/un.h \
1209                   sys/utime.h \
1210                   sys/wait.h \
1211                   syslog.h \
1212                   utime.h])
1214 AC_CHECK_HEADERS(sys/param.h)
1216 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1217 [#ifdef HAVE_SYS_TYPES_H
1218 #include <sys/types.h>
1219 #endif
1220 #ifdef HAVE_SYS_SOCKET_H
1221 #include <sys/socket.h>
1222 #endif])
1223 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1224 [#ifdef HAVE_SYS_TYPES_H
1225 #include <sys/types.h>
1226 #endif
1227 #ifdef HAVE_SYS_SOCKET_H
1228 #include <sys/socket.h>
1229 #endif
1230 #ifdef HAVE_NET_IF_H
1231 #include <net/if.h>
1232 #endif
1233 #ifdef HAVE_NETINET_IN_H
1234 #include <netinet/in.h>
1235 #endif])
1237 AC_CHECK_HEADERS(linux/if.h,[],[],
1239 #ifdef HAVE_SYS_SOCKET_H
1240 #include <sys/socket.h>
1241 #endif
1244 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1245         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1246 [#ifdef HAVE_SYS_TYPES_H
1247 #include <sys/types.h>
1248 #endif
1249 #ifdef HAVE_SYS_SOCKET_H
1250 #include <sys/socket.h>
1251 #endif
1252 #ifdef HAVE_LIMITS_H
1253 #include <limits.h>
1254 #endif
1255 #ifdef HAVE_LINUX_TYPES_H
1256 #include <linux/types.h>
1257 #endif
1258 #ifdef HAVE_NETINET_IN6_H
1259 #include <netinet/in6.h>
1260 #endif
1261 #ifdef HAVE_NETINET_IN_H
1262 #include <netinet/in.h>
1263 #endif])
1265 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1266         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1267 [#ifdef HAVE_SYS_TYPES_H
1268 #include <sys/types.h>
1269 #endif
1270 #ifdef HAVE_SYS_SOCKET_H
1271 #include <sys/socket.h>
1272 #endif
1273 #ifdef HAVE_LIMITS_H
1274 #include <limits.h>
1275 #endif
1276 #ifdef HAVE_LINUX_TYPES_H
1277 #include <linux/types.h>
1278 #endif
1279 #ifdef HAVE_NETINET_IN6_H
1280 #include <netinet/in6.h>
1281 #endif
1282 #ifdef HAVE_NETINET_IN_H
1283 #include <netinet/in.h>
1284 #endif
1285 #ifdef HAVE_LINUX_IF_H
1286 #include <linux/if.h>
1287 #endif])
1289 transparent_ok=0
1290 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1291   transparent_ok=1
1293 if test "x$linux_netfilter_ipv4" = "x1"; then
1294   transparent_ok=1
1296 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1297   transparent_ok=1
1299 if test "x$transparent_ok" = "x1"; then
1300   AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1301 else
1302   AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1305 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1306 [#ifdef HAVE_SYS_TYPES_H
1307 #include <sys/types.h>
1308 #endif
1309 #ifdef HAVE_SYS_TIME_H
1310 #include <sys/time.h>
1311 #endif])
1313 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1314 dnl Watch out.
1316 AC_CHECK_SIZEOF(int8_t)
1317 AC_CHECK_SIZEOF(int16_t)
1318 AC_CHECK_SIZEOF(int32_t)
1319 AC_CHECK_SIZEOF(int64_t)
1320 AC_CHECK_SIZEOF(uint8_t)
1321 AC_CHECK_SIZEOF(uint16_t)
1322 AC_CHECK_SIZEOF(uint32_t)
1323 AC_CHECK_SIZEOF(uint64_t)
1324 AC_CHECK_SIZEOF(intptr_t)
1325 AC_CHECK_SIZEOF(uintptr_t)
1327 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1329 AC_CHECK_SIZEOF(char)
1330 AC_CHECK_SIZEOF(short)
1331 AC_CHECK_SIZEOF(int)
1332 AC_CHECK_SIZEOF(long)
1333 AC_CHECK_SIZEOF(long long)
1334 AC_CHECK_SIZEOF(__int64)
1335 AC_CHECK_SIZEOF(void *)
1336 AC_CHECK_SIZEOF(time_t)
1337 AC_CHECK_SIZEOF(size_t)
1338 AC_CHECK_SIZEOF(pid_t)
1340 AC_CHECK_TYPES([uint, u_char, ssize_t])
1342 AC_PC_FROM_UCONTEXT([:])
1344 dnl used to include sockaddr_storage, but everybody has that.
1345 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1346 [#ifdef HAVE_SYS_TYPES_H
1347 #include <sys/types.h>
1348 #endif
1349 #ifdef HAVE_NETINET_IN_H
1350 #include <netinet/in.h>
1351 #endif
1352 #ifdef HAVE_NETINET_IN6_H
1353 #include <netinet/in6.h>
1354 #endif
1355 #ifdef HAVE_SYS_SOCKET_H
1356 #include <sys/socket.h>
1357 #endif
1358 #ifdef _WIN32
1359 #define _WIN32_WINNT 0x0501
1360 #define WIN32_LEAN_AND_MEAN
1361 #include <winsock2.h>
1362 #include <ws2tcpip.h>
1363 #endif
1365 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1366 [#ifdef HAVE_SYS_TYPES_H
1367 #include <sys/types.h>
1368 #endif
1369 #ifdef HAVE_NETINET_IN_H
1370 #include <netinet/in.h>
1371 #endif
1372 #ifdef HAVE_NETINET_IN6_H
1373 #include <netinet/in6.h>
1374 #endif
1375 #ifdef HAVE_SYS_SOCKET_H
1376 #include <sys/socket.h>
1377 #endif
1378 #ifdef _WIN32
1379 #define _WIN32_WINNT 0x0501
1380 #define WIN32_LEAN_AND_MEAN
1381 #include <winsock2.h>
1382 #include <ws2tcpip.h>
1383 #endif
1386 AC_CHECK_TYPES([rlim_t], , ,
1387 [#ifdef HAVE_SYS_TYPES_H
1388 #include <sys/types.h>
1389 #endif
1390 #ifdef HAVE_SYS_TIME_H
1391 #include <sys/time.h>
1392 #endif
1393 #ifdef HAVE_SYS_RESOURCE_H
1394 #include <sys/resource.h>
1395 #endif
1398 AX_CHECK_SIGN([time_t],
1399        [ : ],
1400        [ : ], [
1401 #ifdef HAVE_SYS_TYPES_H
1402 #include <sys/types.h>
1403 #endif
1404 #ifdef HAVE_SYS_TIME_H
1405 #include <sys/time.h>
1406 #endif
1407 #ifdef HAVE_TIME_H
1408 #include <time.h>
1409 #endif
1412 if test "$ax_cv_decl_time_t_signed" = "no"; then
1413   AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1416 AX_CHECK_SIGN([size_t],
1417        [ tor_cv_size_t_signed=yes ],
1418        [ tor_cv_size_t_signed=no ], [
1419 #ifdef HAVE_SYS_TYPES_H
1420 #include <sys/types.h>
1421 #endif
1424 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1425   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1428 AX_CHECK_SIGN([enum always],
1429        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1430        [ : ], [
1431  enum always { AAA, BBB, CCC };
1434 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1435 #ifdef HAVE_SYS_SOCKET_H
1436 #include <sys/socket.h>
1437 #endif
1440 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1442 AC_CHECK_SIZEOF(cell_t)
1444 # Now make sure that NULL can be represented as zero bytes.
1445 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1446 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1447 [[#include <stdlib.h>
1448 #include <string.h>
1449 #include <stdio.h>
1450 #ifdef HAVE_STDDEF_H
1451 #include <stddef.h>
1452 #endif
1453 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1454 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1455        [tor_cv_null_is_zero=yes],
1456        [tor_cv_null_is_zero=no],
1457        [tor_cv_null_is_zero=cross])])
1459 if test "$tor_cv_null_is_zero" = "cross"; then
1460   # Cross-compiling; let's hope that the target isn't raving mad.
1461   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1464 if test "$tor_cv_null_is_zero" != "no"; then
1465   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1466             [Define to 1 iff memset(0) sets pointers to NULL])
1469 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1470 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1471 [[#include <stdlib.h>
1472 #include <string.h>
1473 #include <stdio.h>
1474 #ifdef HAVE_STDDEF_H
1475 #include <stddef.h>
1476 #endif
1477 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1478 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1479        [tor_cv_dbl0_is_zero=yes],
1480        [tor_cv_dbl0_is_zero=no],
1481        [tor_cv_dbl0_is_zero=cross])])
1483 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1484   # Cross-compiling; let's hope that the target isn't raving mad.
1485   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1488 if test "$tor_cv_dbl0_is_zero" != "no"; then
1489   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1490             [Define to 1 iff memset(0) sets doubles to 0.0])
1493 # And what happens when we malloc zero?
1494 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1495 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1496 [[#include <stdlib.h>
1497 #include <string.h>
1498 #include <stdio.h>
1499 #ifdef HAVE_STDDEF_H
1500 #include <stddef.h>
1501 #endif
1502 int main () { return malloc(0)?0:1; }]])],
1503        [tor_cv_malloc_zero_works=yes],
1504        [tor_cv_malloc_zero_works=no],
1505        [tor_cv_malloc_zero_works=cross])])
1507 if test "$tor_cv_malloc_zero_works" = "cross"; then
1508   # Cross-compiling; let's hope that the target isn't raving mad.
1509   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1512 if test "$tor_cv_malloc_zero_works" = "yes"; then
1513   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1514             [Define to 1 iff malloc(0) returns a pointer])
1517 # whether we seem to be in a 2s-complement world.
1518 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1519 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1520 [[int main () { int problem = ((-99) != (~99)+1);
1521 return problem ? 1 : 0; }]])],
1522        [tor_cv_twos_complement=yes],
1523        [tor_cv_twos_complement=no],
1524        [tor_cv_twos_complement=cross])])
1526 if test "$tor_cv_twos_complement" = "cross"; then
1527   # Cross-compiling; let's hope that the target isn't raving mad.
1528   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1531 if test "$tor_cv_twos_complement" != "no"; then
1532   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1533             [Define to 1 iff we represent negative integers with
1534              two's complement])
1537 # What does shifting a negative value do?
1538 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1539 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1540 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1541        [tor_cv_sign_extend=yes],
1542        [tor_cv_sign_extend=no],
1543        [tor_cv_sign_extend=cross])])
1545 if test "$tor_cv_sign_extend" = "cross"; then
1546   # Cross-compiling; let's hope that the target isn't raving mad.
1547   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1550 if test "$tor_cv_sign_extend" != "no"; then
1551   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1552             [Define to 1 iff right-shifting a negative value performs sign-extension])
1555 # Is uint8_t the same type as unsigned char?
1556 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1557 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1558 #include <stdint.h>
1559 extern uint8_t c;
1560 unsigned char c;]])],
1561        [tor_cv_uint8_uchar=yes],
1562        [tor_cv_uint8_uchar=no],
1563        [tor_cv_uint8_uchar=cross])])
1565 if test "$tor_cv_uint8_uchar" = "cross"; then
1566   AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1569 if test "$tor_cv_uint8_uchar" = "no"; then
1570   AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1573 # Whether we should use the dmalloc memory allocation debugging library.
1574 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1575 AC_ARG_WITH(dmalloc,
1576 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1577 [if [[ "$withval" = "yes" ]]; then
1578   dmalloc=1
1579   AC_MSG_RESULT(yes)
1580 else
1581   dmalloc=1
1582   AC_MSG_RESULT(no)
1583 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1586 if [[ $dmalloc -eq 1 ]]; then
1587   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1588   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1589   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1590   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1593 AC_ARG_WITH(tcmalloc,
1594 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1595 [ tcmalloc=yes ], [ tcmalloc=no ])
1597 if test "x$tcmalloc" = "xyes"; then
1598    LDFLAGS="-ltcmalloc $LDFLAGS"
1601 using_custom_malloc=no
1602 if test "x$enable_openbsd_malloc" = "xyes"; then
1603    using_custom_malloc=yes
1605 if test "x$tcmalloc" = "xyes"; then
1606    using_custom_malloc=yes
1608 if test "$using_custom_malloc" = "no"; then
1609    AC_CHECK_FUNCS(mallinfo)
1612 # By default, we're going to assume we don't have mlockall()
1613 # bionic and other platforms have various broken mlockall subsystems.
1614 # Some systems don't have a working mlockall, some aren't linkable,
1615 # and some have it but don't declare it.
1616 AC_CHECK_FUNCS(mlockall)
1617 AC_CHECK_DECLS([mlockall], , , [
1618 #ifdef HAVE_SYS_MMAN_H
1619 #include <sys/mman.h>
1620 #endif])
1622 # Some MinGW environments don't have getpagesize in unistd.h. We don't use
1623 # AC_CHECK_FUNCS(getpagesize), because other environments rename getpagesize
1624 # using macros
1625 AC_CHECK_DECLS([getpagesize], , , [
1626 #ifdef HAVE_UNISTD_H
1627 #include <unistd.h>
1628 #endif])
1630 # Allow user to specify an alternate syslog facility
1631 AC_ARG_WITH(syslog-facility,
1632 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1633 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1634 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1635 AC_SUBST(LOGFACILITY)
1637 # Check if we have getresuid and getresgid
1638 AC_CHECK_FUNCS(getresuid getresgid)
1640 # Check for gethostbyname_r in all its glorious incompatible versions.
1641 #   (This logic is based on that in Python's configure.in)
1642 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1643   [Define this if you have any gethostbyname_r()])
1645 AC_CHECK_FUNC(gethostbyname_r, [
1646   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1647   OLD_CFLAGS=$CFLAGS
1648   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1649   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1650 #include <netdb.h>
1651   ]], [[
1652     char *cp1, *cp2;
1653     struct hostent *h1, *h2;
1654     int i1, i2;
1655     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1656   ]])],[
1657     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1658     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1659      [Define this if gethostbyname_r takes 6 arguments])
1660     AC_MSG_RESULT(6)
1661   ], [
1662     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1663 #include <netdb.h>
1664     ]], [[
1665       char *cp1, *cp2;
1666       struct hostent *h1;
1667       int i1, i2;
1668       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1669     ]])], [
1670       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1671       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1672         [Define this if gethostbyname_r takes 5 arguments])
1673       AC_MSG_RESULT(5)
1674    ], [
1675       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1676 #include <netdb.h>
1677      ]], [[
1678        char *cp1;
1679        struct hostent *h1;
1680        struct hostent_data hd;
1681        (void) gethostbyname_r(cp1,h1,&hd);
1682      ]])], [
1683        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1684        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1685          [Define this if gethostbyname_r takes 3 arguments])
1686        AC_MSG_RESULT(3)
1687      ], [
1688        AC_MSG_RESULT(0)
1689      ])
1690   ])
1691  ])
1692  CFLAGS=$OLD_CFLAGS
1695 AC_CACHE_CHECK([whether the C compiler supports __func__],
1696   tor_cv_have_func_macro,
1697   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1698 #include <stdio.h>
1699 int main(int c, char **v) { puts(__func__); }])],
1700   tor_cv_have_func_macro=yes,
1701   tor_cv_have_func_macro=no))
1703 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1704   tor_cv_have_FUNC_macro,
1705   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1706 #include <stdio.h>
1707 int main(int c, char **v) { puts(__FUNC__); }])],
1708   tor_cv_have_FUNC_macro=yes,
1709   tor_cv_have_FUNC_macro=no))
1711 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1712   tor_cv_have_FUNCTION_macro,
1713   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1714 #include <stdio.h>
1715 int main(int c, char **v) { puts(__FUNCTION__); }])],
1716   tor_cv_have_FUNCTION_macro=yes,
1717   tor_cv_have_FUNCTION_macro=no))
1719 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1720   tor_cv_have_environ_declared,
1721   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1722 #ifdef HAVE_UNISTD_H
1723 #include <unistd.h>
1724 #endif
1725 #include <stdlib.h>
1726 int main(int c, char **v) { char **t = environ; }])],
1727   tor_cv_have_environ_declared=yes,
1728   tor_cv_have_environ_declared=no))
1730 if test "$tor_cv_have_func_macro" = "yes"; then
1731   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1734 if test "$tor_cv_have_FUNC_macro" = "yes"; then
1735   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1738 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
1739   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1740            [Defined if the compiler supports __FUNCTION__])
1743 if test "$tor_cv_have_environ_declared" = "yes"; then
1744   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1745            [Defined if we have extern char **environ already declared])
1748 # $prefix stores the value of the --prefix command line option, or
1749 # NONE if the option wasn't set.  In the case that it wasn't set, make
1750 # it be the default, so that we can use it to expand directories now.
1751 if test "x$prefix" = "xNONE"; then
1752   prefix=$ac_default_prefix
1755 # and similarly for $exec_prefix
1756 if test "x$exec_prefix" = "xNONE"; then
1757   exec_prefix=$prefix
1760 if test "x$BUILDDIR" = "x"; then
1761   BUILDDIR=`pwd`
1763 AC_SUBST(BUILDDIR)
1764 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1765 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1767 if test "x$CONFDIR" = "x"; then
1768   CONFDIR=`eval echo $sysconfdir/tor`
1770 AC_SUBST(CONFDIR)
1771 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1772 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1774 BINDIR=`eval echo $bindir`
1775 AC_SUBST(BINDIR)
1776 LOCALSTATEDIR=`eval echo $localstatedir`
1777 AC_SUBST(LOCALSTATEDIR)
1779 if test "$bwin32" = "true"; then
1780   # Test if the linker supports the --nxcompat and --dynamicbase options
1781   # for Windows
1782   save_LDFLAGS="$LDFLAGS"
1783   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1784   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1785   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1786     [AC_MSG_RESULT([yes])]
1787     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1788     [AC_MSG_RESULT([no])]
1789   )
1790   LDFLAGS="$save_LDFLAGS"
1793 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1794 # than autoconf's macros like.
1795 if test "$GCC" = "yes"; then
1796   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1797   # accident waiting to happen.
1798   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1799 else
1800   # Override optimization level for non-gcc compilers
1801   CFLAGS="$CFLAGS -O"
1802   enable_gcc_warnings=no
1803   enable_gcc_warnings_advisory=no
1806 # Warnings implies advisory-warnings and -Werror.
1807 if test "$enable_gcc_warnings" = "yes"; then
1808   enable_gcc_warnings_advisory=yes
1809   enable_fatal_warnings=yes
1812 # OS X Lion started deprecating the system openssl. Let's just disable
1813 # all deprecation warnings on OS X. Also, to potentially make the binary
1814 # a little smaller, let's enable dead_strip.
1815 case "$host_os" in
1817  darwin*)
1818     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1819     LDFLAGS="$LDFLAGS -dead_strip" ;;
1820 esac
1822 # Add some more warnings which we use in development but not in the
1823 # released versions.  (Some relevant gcc versions can't handle these.)
1825 # Note that we have to do this near the end  of the autoconf process, or
1826 # else we may run into problems when these warnings hit on the testing C
1827 # programs that autoconf wants to build.
1828 if test "x$enable_gcc_warnings_advisory" != "xno"; then
1830   case "$host" in
1831     *-*-openbsd* | *-*-bitrig*)
1832       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1833       # That's fine, except that the headers don't pass -Wredundant-decls.
1834       # Therefore, let's disable -Wsystem-headers when we're building
1835       # with maximal warnings on OpenBSD.
1836       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1837   esac
1839   # GCC4.3 users once report trouble with -Wstrict-overflow=5.  GCC5 users
1840   # have it work better.
1841   # CFLAGS="$CFLAGS -Wstrict-overflow=1"
1843   # This warning was added in gcc 4.3, but it appears to generate
1844   # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
1845   #CFLAGS="$CFLAGS -Wlogical-op"
1847   m4_foreach_w([warning_flag], [
1848      -Waddress
1849      -Waddress-of-array-temporary
1850      -Waddress-of-temporary
1851      -Wambiguous-macro
1852      -Wanonymous-pack-parens
1853      -Warc
1854      -Warc-abi
1855      -Warc-bridge-casts-disallowed-in-nonarc
1856      -Warc-maybe-repeated-use-of-weak
1857      -Warc-performSelector-leaks
1858      -Warc-repeated-use-of-weak
1859      -Warray-bounds
1860      -Warray-bounds-pointer-arithmetic
1861      -Wasm
1862      -Wasm-operand-widths
1863      -Watomic-properties
1864      -Watomic-property-with-user-defined-accessor
1865      -Wauto-import
1866      -Wauto-storage-class
1867      -Wauto-var-id
1868      -Wavailability
1869      -Wbackslash-newline-escape
1870      -Wbad-array-new-length
1871      -Wbind-to-temporary-copy
1872      -Wbitfield-constant-conversion
1873      -Wbool-conversion
1874      -Wbool-conversions
1875      -Wbuiltin-requires-header
1876      -Wchar-align
1877      -Wcompare-distinct-pointer-types
1878      -Wcomplex-component-init
1879      -Wconditional-type-mismatch
1880      -Wconfig-macros
1881      -Wconstant-conversion
1882      -Wconstant-logical-operand
1883      -Wconstexpr-not-const
1884      -Wcustom-atomic-properties
1885      -Wdangling-field
1886      -Wdangling-initializer-list
1887      -Wdate-time
1888      -Wdelegating-ctor-cycles
1889      -Wdeprecated-implementations
1890      -Wdeprecated-register
1891      -Wdirect-ivar-access
1892      -Wdiscard-qual
1893      -Wdistributed-object-modifiers
1894      -Wdivision-by-zero
1895      -Wdollar-in-identifier-extension
1896      -Wdouble-promotion
1897      -Wduplicate-decl-specifier
1898      -Wduplicate-enum
1899      -Wduplicate-method-arg
1900      -Wduplicate-method-match
1901      -Wduplicated-cond
1902      -Wdynamic-class-memaccess
1903      -Wembedded-directive
1904      -Wempty-translation-unit
1905      -Wenum-conversion
1906      -Wexit-time-destructors
1907      -Wexplicit-ownership-type
1908      -Wextern-initializer
1909      -Wextra
1910      -Wextra-semi
1911      -Wextra-tokens
1912      -Wflexible-array-extensions
1913      -Wfloat-conversion
1914      -Wformat-non-iso
1915      -Wfour-char-constants
1916      -Wgcc-compat
1917      -Wglobal-constructors
1918      -Wgnu-array-member-paren-init
1919      -Wgnu-designator
1920      -Wgnu-static-float-init
1921      -Wheader-guard
1922      -Wheader-hygiene
1923      -Widiomatic-parentheses
1924      -Wignored-attributes
1925      -Wimplicit-atomic-properties
1926      -Wimplicit-conversion-floating-point-to-bool
1927      -Wimplicit-exception-spec-mismatch
1928      -Wimplicit-fallthrough
1929      -Wimplicit-fallthrough-per-function
1930      -Wimplicit-retain-self
1931      -Wimport-preprocessor-directive-pedantic
1932      -Wincompatible-library-redeclaration
1933      -Wincompatible-pointer-types-discards-qualifiers
1934      -Wincomplete-implementation
1935      -Wincomplete-module
1936      -Wincomplete-umbrella
1937      -Winit-self
1938      -Wint-conversions
1939      -Wint-to-void-pointer-cast
1940      -Winteger-overflow
1941      -Winvalid-constexpr
1942      -Winvalid-iboutlet
1943      -Winvalid-noreturn
1944      -Winvalid-pp-token
1945      -Winvalid-source-encoding
1946      -Winvalid-token-paste
1947      -Wknr-promoted-parameter
1948      -Wlanguage-extension-token
1949      -Wlarge-by-value-copy
1950      -Wliteral-conversion
1951      -Wliteral-range
1952      -Wlocal-type-template-args
1953      -Wlogical-op
1954      -Wloop-analysis
1955      -Wmain-return-type
1956      -Wmalformed-warning-check
1957      -Wmethod-signatures
1958      -Wmicrosoft
1959      -Wmicrosoft-exists
1960      -Wmismatched-parameter-types
1961      -Wmismatched-return-types
1962      -Wmissing-field-initializers
1963      -Wmissing-format-attribute
1964      -Wmissing-noreturn
1965      -Wmissing-selector-name
1966      -Wmissing-sysroot
1967      -Wmissing-variable-declarations
1968      -Wmodule-conflict
1969      -Wnested-anon-types
1970      -Wnewline-eof
1971      -Wnon-literal-null-conversion
1972      -Wnon-pod-varargs
1973      -Wnonportable-cfstrings
1974      -Wnormalized=id
1975      -Wnull-arithmetic
1976      -Wnull-character
1977      -Wnull-conversion
1978      -Wnull-dereference
1979      -Wout-of-line-declaration
1980      -Wover-aligned
1981      -Woverlength-strings
1982      -Woverride-init
1983      -Woverriding-method-mismatch
1984      -Wpointer-type-mismatch
1985      -Wpredefined-identifier-outside-function
1986      -Wprotocol-property-synthesis-ambiguity
1987      -Wreadonly-iboutlet-property
1988      -Wreadonly-setter-attrs
1989      -Wreceiver-expr
1990      -Wreceiver-forward-class
1991      -Wreceiver-is-weak
1992      -Wreinterpret-base-class
1993      -Wrequires-super-attribute
1994      -Wreserved-user-defined-literal
1995      -Wreturn-stack-address
1996      -Wsection
1997      -Wselector-type-mismatch
1998      -Wsentinel
1999      -Wserialized-diagnostics
2000      -Wshadow
2001      -Wshift-count-negative
2002      -Wshift-count-overflow
2003      -Wshift-negative-value
2004      -Wshift-overflow=2
2005      -Wshift-sign-overflow
2006      -Wshorten-64-to-32
2007      -Wsizeof-array-argument
2008      -Wsource-uses-openmp
2009      -Wstatic-float-init
2010      -Wstatic-in-inline
2011      -Wstatic-local-in-inline
2012      -Wstrict-overflow=1
2013      -Wstring-compare
2014      -Wstring-conversion
2015      -Wstrlcpy-strlcat-size
2016      -Wstrncat-size
2017      -Wsuggest-attribute=format
2018      -Wsuggest-attribute=noreturn
2019      -Wsuper-class-method-mismatch
2020      -Wswitch-bool
2021      -Wsync-nand
2022      -Wtautological-constant-out-of-range-compare
2023      -Wtentative-definition-incomplete-type
2024      -Wtrampolines
2025      -Wtype-safety
2026      -Wtypedef-redefinition
2027      -Wtypename-missing
2028      -Wundefined-inline
2029      -Wundefined-internal
2030      -Wundefined-reinterpret-cast
2031      -Wunicode
2032      -Wunicode-whitespace
2033      -Wunknown-warning-option
2034      -Wunnamed-type-template-args
2035      -Wunneeded-member-function
2036      -Wunsequenced
2037      -Wunsupported-visibility
2038      -Wunused-but-set-parameter
2039      -Wunused-but-set-variable
2040      -Wunused-command-line-argument
2041      -Wunused-const-variable=2
2042      -Wunused-exception-parameter
2043      -Wunused-local-typedefs
2044      -Wunused-member-function
2045      -Wunused-sanitize-argument
2046      -Wunused-volatile-lvalue
2047      -Wuser-defined-literals
2048      -Wvariadic-macros
2049      -Wvector-conversion
2050      -Wvector-conversions
2051      -Wvexing-parse
2052      -Wvisibility
2053      -Wvla-extension
2054      -Wzero-length-array
2055   ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
2057 dnl    We should re-enable this in some later version.  Clang doesn't
2058 dnl    mind, but it causes trouble with GCC.
2059 dnl     -Wstrict-overflow=2
2061 dnl    These seem to require annotations that we don't currently use,
2062 dnl    and they give false positives in our pthreads wrappers. (Clang 4)
2063 dnl     -Wthread-safety
2064 dnl     -Wthread-safety-analysis
2065 dnl     -Wthread-safety-attributes
2066 dnl     -Wthread-safety-beta
2067 dnl     -Wthread-safety-precise
2069   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2070   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2071   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2072   CFLAGS="$CFLAGS -Wwrite-strings"
2073   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2074   CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
2075   CFLAGS="$CFLAGS -Wunused-parameter "
2076   # These interfere with building main() { return 0; }, which autoconf
2077   # likes to use as its default program.
2078   CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
2080   if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2081     AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2082   fi
2083   if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2084     AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2085   fi
2087   if test "x$enable_fatal_warnings" = "xyes"; then
2088     # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2089     # default autoconf programs are full of errors.
2090     CFLAGS="$CFLAGS -Werror"
2091   fi
2095 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2096    case "$host_os" in
2097     darwin*)
2098       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.])
2099    esac
2102 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2104 AC_CONFIG_FILES([
2105         Doxyfile
2106         Makefile
2107         contrib/dist/suse/tor.sh
2108         contrib/operator-tools/tor.logrotate
2109         contrib/dist/tor.sh
2110         contrib/dist/torctl
2111         contrib/dist/tor.service
2112         src/config/torrc.sample
2113         src/config/torrc.minimal
2114         src/rust/.cargo/config
2115         scripts/maint/checkOptionDocs.pl
2116         scripts/maint/updateVersions.pl
2119 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2120   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2121   for file in $regular_mans ; do
2122     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2123       echo "==================================";
2124       echo;
2125       echo "Building Tor has failed since manpages cannot be built.";
2126       echo;
2127       echo "You need asciidoc installed to be able to build the manpages.";
2128       echo "To build without manpages, use the --disable-asciidoc argument";
2129       echo "when calling configure.";
2130       echo;
2131       echo "==================================";
2132       exit 1;
2133     fi
2134   done
2137 if test "$fragile_hardening" = "yes"; then
2138   AC_MSG_WARN([
2140 ============
2141 Warning!  Building Tor with --enable-fragile-hardening (also known as
2142 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2143 other kinds of attacks easier. A Tor instance build with this option will be
2144 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2145 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2146 denial of service attacks. For more information, see
2147 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
2148 ============
2149   ])
2152 AC_OUTPUT