1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2015, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
7 AC_INIT([tor],[0.2.8.1-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])
16 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
17 AC_CONFIG_HEADERS([orconfig.h])
23 if test -f "/etc/redhat-release"; then
24 if test -f "/usr/kerberos/include"; then
25 CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
29 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
30 # the += operator on it in src/or/Makefile.am
31 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
33 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
34 AC_ARG_ENABLE(openbsd-malloc,
35 AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
36 AC_ARG_ENABLE(instrument-downloads,
37 AS_HELP_STRING(--enable-instrument-downloads, [instrument downloads of directory resources etc.]))
38 AC_ARG_ENABLE(static-openssl,
39 AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
40 AC_ARG_ENABLE(static-libevent,
41 AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
42 AC_ARG_ENABLE(static-zlib,
43 AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
44 AC_ARG_ENABLE(static-tor,
45 AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
46 AC_ARG_ENABLE(unittests,
47 AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
48 AC_ARG_ENABLE(coverage,
49 AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
50 AC_ARG_ENABLE(asserts-in-tests,
51 AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
52 AC_ARG_ENABLE(system-torrc,
53 AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
55 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
56 AC_MSG_ERROR([Can't disable assertions outside of coverage build])
59 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
60 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
61 AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
62 AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
63 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
65 if test "$enable_static_tor" = "yes"; then
66 enable_static_libevent="yes";
67 enable_static_openssl="yes";
68 enable_static_zlib="yes";
69 CFLAGS="$CFLAGS -static"
72 if test "$enable_system_torrc" = "no"; then
73 AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
74 [Defined if we're not going to look for a torrc in SYSCONF])
77 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
78 if test "x$enable_instrument_downloads" = "xyes"; then
79 AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
80 [Defined if we want to keep track of how much of each kind of resource we download.])
83 AC_ARG_ENABLE(transparent,
84 AS_HELP_STRING(--disable-transparent, [disable transparent proxy support]),
85 [case "${enableval}" in
86 "yes") transparent=true ;;
87 "no") transparent=false ;;
88 *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
89 esac], [transparent=true])
91 AC_ARG_ENABLE(asciidoc,
92 AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
93 [case "${enableval}" in
94 "yes") asciidoc=true ;;
95 "no") asciidoc=false ;;
96 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
97 esac], [asciidoc=true])
99 # systemd notify support
100 AC_ARG_ENABLE(systemd,
101 AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
102 [case "${enableval}" in
103 "yes") systemd=true ;;
104 "no") systemd=false ;;
105 * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
106 esac], [systemd=auto])
111 if test "x$enable_systemd" = "xno"; then
114 PKG_CHECK_MODULES(SYSTEMD,
118 if test "x$have_systemd" = "xno"; then
119 AC_MSG_NOTICE([Okay, checking for systemd a different way...])
120 PKG_CHECK_MODULES(SYSTEMD,
127 if test "x$have_systemd" = "xyes"; then
128 AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
129 TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
130 TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
131 PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
132 [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
134 AC_SUBST(TOR_SYSTEMD_CFLAGS)
135 AC_SUBST(TOR_SYSTEMD_LIBS)
137 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
138 AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
143 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
147 AC_ARG_ENABLE(gcc-warnings,
148 AS_HELP_STRING(--enable-gcc-warnings, [enable verbose warnings]))
149 AC_ARG_ENABLE(gcc-warnings-advisory,
150 AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
152 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
153 AC_ARG_ENABLE(gcc-hardening,
154 AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
156 AC_ARG_ENABLE(expensive-hardening,
157 AS_HELP_STRING(--enable-expensive-hardening, [enable more expensive compiler hardening; makes Tor slower]))
159 dnl Linker hardening options
160 dnl Currently these options are ELF specific - you can't use this with MacOSX
161 AC_ARG_ENABLE(linker-hardening,
162 AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
164 AC_ARG_ENABLE(local-appdata,
165 AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
166 if test "$enable_local_appdata" = "yes"; then
167 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
168 [Defined if we default to host local appdata paths on Windows])
172 AC_ARG_ENABLE(tor2web-mode,
173 AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
174 [if test "x$enableval" = "xyes"; then
175 CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
178 AC_ARG_ENABLE(bufferevents,
179 AS_HELP_STRING(--enable-bufferevents, [use Libevent's buffered IO]))
181 AC_ARG_ENABLE(tool-name-check,
182 AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
184 AC_ARG_ENABLE(seccomp,
185 AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
187 AC_ARG_ENABLE(libscrypt,
188 AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
190 dnl check for the correct "ar" when cross-compiling
191 AN_MAKEVAR([AR], [AC_PROG_AR])
192 AN_PROGRAM([ar], [AC_PROG_AR])
193 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
196 dnl Check whether the above macro has settled for a simply named tool even
197 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
198 dnl because that will find any cc on the system, not only the cross-compiler,
199 dnl and then verify that a binary built with this compiler runs on the
200 dnl build system. It will then come to the false conclusion that we're not
202 if test "x$enable_tool_name_check" != "xno"; then
203 if test "x$ac_tool_warned" = "xyes"; then
204 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.)])
205 elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
206 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.)])
215 AC_PATH_PROG([PERL], [perl])
217 dnl autoconf 2.59 appears not to support AC_PROG_SED
218 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
220 dnl check for asciidoc and a2x
221 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
222 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
224 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
226 AM_CONDITIONAL(USE_FW_HELPER, test "x$natpmp" = "xtrue" || test "x$upnp" = "xtrue")
227 AM_CONDITIONAL(NAT_PMP, test "x$natpmp" = "xtrue")
228 AM_CONDITIONAL(MINIUPNPC, test "x$upnp" = "xtrue")
232 AC_ARG_VAR([PYTHON], [path to Python binary])
233 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
234 if test "x$PYTHON" = "x"; then
235 AC_MSG_WARN([Python unavailable; some tests will not be run.])
237 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
239 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
240 AC_C_FLEXIBLE_ARRAY_MEMBER
242 dnl Maybe we've got an old autoconf...
243 AC_CACHE_CHECK([for flexible array members],
247 struct abc { int a; char b[]; };
249 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
252 [tor_cv_c_flexarray=yes],
253 [tor_cv_c_flexarray=no])])
254 if test "$tor_cv_flexarray" = "yes"; then
255 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
257 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
261 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
264 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
265 [tor_cv_c_c99_decl=yes],
266 [tor_cv_c_c99_decl=no] )])
267 if test "$tor_cv_c_c99_decl" != "yes"; then
268 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
271 AC_CACHE_CHECK([for working C99 designated initializers],
272 tor_cv_c_c99_designated_init,
274 [AC_LANG_PROGRAM([struct s { int a; int b; };],
275 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
276 [tor_cv_c_c99_designated_init=yes],
277 [tor_cv_c_c99_designated_init=no] )])
279 if test "$tor_cv_c_c99_designated_init" != "yes"; then
280 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
284 AC_ARG_WITH(tor-user,
285 AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
293 AC_ARG_WITH(tor-group,
294 AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
302 dnl If _WIN32 is defined and non-zero, we are building for win32
303 AC_MSG_CHECKING([for win32])
304 AC_RUN_IFELSE([AC_LANG_SOURCE([
305 int main(int c, char **v) {
316 bwin32=true; AC_MSG_RESULT([yes]),
317 bwin32=false; AC_MSG_RESULT([no]),
318 bwin32=cross; AC_MSG_RESULT([cross])
321 if test "$bwin32" = "cross"; then
322 AC_MSG_CHECKING([for win32 (cross)])
323 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
325 int main(int c, char **v) {return 0;}
328 int main(int c, char **v) {return x(y);}
331 bwin32=true; AC_MSG_RESULT([yes]),
332 bwin32=false; AC_MSG_RESULT([no]))
337 /* Defined to access windows functions and definitions for >=WinXP */
339 # define WINVER 0x0501
342 /* Defined to access _other_ windows functions and definitions for >=WinXP */
343 # ifndef _WIN32_WINNT
344 # define _WIN32_WINNT 0x0501
347 /* Defined to avoid including some windows headers as part of Windows.h */
348 # ifndef WIN32_LEAN_AND_MEAN
349 # define WIN32_LEAN_AND_MEAN 1
355 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
357 dnl Enable C99 when compiling with MIPSpro
358 AC_MSG_CHECKING([for MIPSpro compiler])
359 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
360 #if (defined(__sgi) && defined(_COMPILER_VERSION))
365 bmipspro=false; AC_MSG_RESULT(no),
366 bmipspro=true; AC_MSG_RESULT(yes))
368 if test "$bmipspro" = "true"; then
369 CFLAGS="$CFLAGS -c99"
374 AC_SEARCH_LIBS(socket, [socket network])
375 AC_SEARCH_LIBS(gethostbyname, [nsl])
376 AC_SEARCH_LIBS(dlopen, [dl])
377 AC_SEARCH_LIBS(inet_aton, [resolv])
378 AC_SEARCH_LIBS(backtrace, [execinfo])
380 AC_SEARCH_LIBS([clock_gettime], [rt])
381 if test "$LIBS" != "$saved_LIBS"; then
382 # Looks like we need -lrt for clock_gettime().
386 AC_SEARCH_LIBS(pthread_create, [pthread])
387 AC_SEARCH_LIBS(pthread_detach, [pthread])
389 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
390 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
394 RtlSecureZeroMemory \
398 backtrace_symbols_fd \
443 if test "$bwin32" != "true"; then
444 AC_CHECK_HEADERS(pthread.h)
445 AC_CHECK_FUNCS(pthread_create)
446 AC_CHECK_FUNCS(pthread_condattr_setclock)
449 if test "$bwin32" = "true"; then
450 AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
457 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
458 test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
460 dnl ------------------------------------------------------
461 dnl Where do you live, libevent? And how do we call you?
463 if test "$bwin32" = "true"; then
464 TOR_LIB_WS32=-lws2_32
465 TOR_LIB_IPHLPAPI=-liphlpapi
466 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
467 # think it's actually necessary.
473 AC_SUBST(TOR_LIB_WS32)
474 AC_SUBST(TOR_LIB_GDI)
475 AC_SUBST(TOR_LIB_IPHLPAPI)
477 tor_libevent_pkg_redhat="libevent"
478 tor_libevent_pkg_debian="libevent-dev"
479 tor_libevent_devpkg_redhat="libevent-devel"
480 tor_libevent_devpkg_debian="libevent-dev"
482 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
483 dnl linking for static builds.
484 STATIC_LIBEVENT_FLAGS=""
485 if test "$enable_static_libevent" = "yes"; then
486 if test "$have_rt" = "yes"; then
487 STATIC_LIBEVENT_FLAGS=" -lrt "
491 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
493 #include <winsock2.h>
496 #include <sys/time.h>
497 #include <sys/types.h>
498 #include <event.h>], [
500 #include <winsock2.h>
502 void exit(int); void *event_init(void);],
505 {WSADATA d; WSAStartup(0x101,&d); }
507 event_init(); exit(0);
508 ], [--with-libevent-dir], [/opt/libevent])
510 dnl Now check for particular libevent functions.
512 save_LDFLAGS="$LDFLAGS"
513 save_CPPFLAGS="$CPPFLAGS"
514 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
515 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
516 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
517 AC_CHECK_FUNCS([event_get_version_number \
518 evutil_secure_rng_set_urandom_device_file \
519 evutil_secure_rng_init \
521 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
525 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
527 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
529 AM_CONDITIONAL(USE_EXTERNAL_EVDNS,
530 test "x$ac_cv_header_event2_dns_h" = "xyes")
532 if test "$enable_static_libevent" = "yes"; then
533 if test "$tor_cv_library_libevent_dir" = "(system)"; then
534 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
536 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
539 if test "x$ac_cv_header_event2_event_h" = "xyes"; then
540 AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
541 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"))
543 if test "$ac_cv_search_event_new" != "none required"; then
544 TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
546 if test "$ac_cv_search_evdns_base_new" != "none required"; then
547 TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
550 TOR_LIBEVENT_LIBS="-levent"
555 LDFLAGS="$save_LDFLAGS"
556 CPPFLAGS="$save_CPPFLAGS"
558 dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
559 dnl we can do much better.
560 if test "$enable_bufferevents" = "yes"; then
561 if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes"; then
562 AC_MSG_ERROR([You've asked for bufferevent support, but you're using a version of Libevent without SSL support. This won't work. We need Libevent 2.0.8-rc or later, and you don't seem to even have Libevent 2.0.3-alpha.])
565 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
567 # Check for the right version. First see if version detection works.
568 AC_MSG_CHECKING([whether we can detect the Libevent version])
569 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
570 #include <event2/event.h>
571 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
577 ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
578 [event_version_number_works=no; AC_MSG_RESULT([no])])
579 if test "$event_version_number_works" != "yes"; then
580 AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
582 AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
583 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
584 #include <event2/event.h>
585 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
591 ])], [ AC_MSG_RESULT([yes]) ],
592 [ AC_MSG_RESULT([no])
593 AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
599 LDFLAGS="$save_LDFLAGS"
600 CPPFLAGS="$save_CPPFLAGS"
602 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
603 if test "$enable_bufferevents" = "yes"; then
604 AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
605 if test "$enable_static_libevent" = "yes"; then
606 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
608 TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
611 AC_SUBST(TOR_LIBEVENT_LIBS)
613 dnl ------------------------------------------------------
614 dnl Where do you live, libm?
616 dnl On some platforms (Haiku/BeOS) the math library is
617 dnl part of libroot. In which case don't link against lm
620 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
621 if test "$ac_cv_search_pow" != "none required"; then
622 TOR_LIB_MATH="$ac_cv_search_pow"
625 AC_SUBST(TOR_LIB_MATH)
627 dnl ------------------------------------------------------
628 dnl Where do you live, openssl? And how do we call you?
630 tor_openssl_pkg_redhat="openssl"
631 tor_openssl_pkg_debian="libssl-dev"
632 tor_openssl_devpkg_redhat="openssl-devel"
633 tor_openssl_devpkg_debian="libssl-dev"
635 ALT_openssl_WITHVAL=""
637 AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
639 if test "x$withval" != "xno" && test "x$withval" != "x"; then
640 ALT_openssl_WITHVAL="$withval"
644 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
645 [#include <openssl/rand.h>],
646 [void RAND_add(const void *buf, int num, double entropy);],
647 [RAND_add((void*)0,0,0); exit(0);], [],
648 [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
650 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
652 if test "$enable_static_openssl" = "yes"; then
653 if test "$tor_cv_library_openssl_dir" = "(system)"; then
654 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
656 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
659 TOR_OPENSSL_LIBS="-lssl -lcrypto"
661 AC_SUBST(TOR_OPENSSL_LIBS)
663 dnl Now check for particular openssl functions.
665 save_LDFLAGS="$LDFLAGS"
666 save_CPPFLAGS="$CPPFLAGS"
667 LIBS="$TOR_OPENSSL_LIBS $LIBS"
668 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
669 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
672 #include <openssl/opensslv.h>
673 #if OPENSSL_VERSION_NUMBER < 0x1000000fL
678 [ AC_ERROR([OpenSSL is too old. We require 1.0.0 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
681 #include <openssl/opensslv.h>
682 #include <openssl/evp.h>
683 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
686 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
687 #error "curves unavailable"
691 [ AC_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.]) ])
693 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
694 [#include <openssl/ssl.h>
698 SSL_SESSION_get_master_key \
699 SSL_get_server_random \
700 SSL_get_client_ciphers \
701 SSL_get_client_random \
706 dnl Check if OpenSSL has scrypt implementation.
707 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
710 LDFLAGS="$save_LDFLAGS"
711 CPPFLAGS="$save_CPPFLAGS"
713 dnl ------------------------------------------------------
714 dnl Where do you live, zlib? And how do we call you?
716 tor_zlib_pkg_redhat="zlib"
717 tor_zlib_pkg_debian="zlib1g"
718 tor_zlib_devpkg_redhat="zlib-devel"
719 tor_zlib_devpkg_debian="zlib1g-dev"
721 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
723 [const char * zlibVersion(void);],
724 [zlibVersion(); exit(0);], [--with-zlib-dir],
727 if test "$enable_static_zlib" = "yes"; then
728 if test "$tor_cv_library_zlib_dir" = "(system)"; then
729 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
730 using --enable-static-zlib")
732 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
737 AC_SUBST(TOR_ZLIB_LIBS)
739 dnl ----------------------------------------------------------------------
740 dnl Check if libcap is available for capabilities.
742 tor_cap_pkg_debian="libcap2"
743 tor_cap_pkg_redhat="libcap"
744 tor_cap_devpkg_debian="libcap-dev"
745 tor_cap_devpkg_redhat="libcap-devel"
747 AC_CHECK_LIB([cap], [cap_init], [],
748 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
750 AC_CHECK_FUNCS(cap_set_proc)
752 dnl ---------------------------------------------------------------------
753 dnl Now that we know about our major libraries, we can check for compiler
754 dnl and linker hardening options. We need to do this with the libraries known,
755 dnl since sometimes the linker will like an option but not be willing to
756 dnl use it with a build of a library.
758 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
759 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"
761 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
762 #if !defined(__clang__)
764 #endif])], have_clang=yes, have_clang=no)
766 if test "x$enable_gcc_hardening" != "xno"; then
767 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
768 if test "x$have_clang" = "xyes"; then
769 TOR_CHECK_CFLAGS(-Qunused-arguments)
771 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
772 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
773 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
774 m4_ifdef([AS_VAR_IF],[
775 AS_VAR_IF(can_compile, [yes],
776 AS_VAR_IF(can_link, [yes],
778 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.)]))
780 AS_VAR_POPDEF([can_link])
781 AS_VAR_POPDEF([can_compile])
782 TOR_CHECK_CFLAGS(-Wstack-protector)
783 TOR_CHECK_CFLAGS(-fwrapv)
784 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
785 if test "$bwin32" = "false"; then
786 TOR_CHECK_CFLAGS(-fPIE)
787 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
791 if test "x$enable_expensive_hardening" = "xyes"; then
792 TOR_CHECK_CFLAGS([-fsanitize=address])
793 TOR_CHECK_CFLAGS([-fsanitize=undefined])
794 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
797 if test "x$enable_linker_hardening" != "xno"; then
798 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
801 # For backtrace support
802 TOR_CHECK_LDFLAGS(-rdynamic)
804 dnl ------------------------------------------------------
805 dnl Now see if we have a -fomit-frame-pointer compiler option.
807 saved_CFLAGS="$CFLAGS"
808 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
809 F_OMIT_FRAME_POINTER=''
810 if test "$saved_CFLAGS" != "$CFLAGS"; then
811 if test "x$enable_expensive_hardening" != "xyes"; then
812 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
815 CFLAGS="$saved_CFLAGS"
816 AC_SUBST(F_OMIT_FRAME_POINTER)
818 dnl ------------------------------------------------------
819 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
820 dnl for us, as GCC 4.6 and later do at many optimization levels), then
821 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
823 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
825 dnl ============================================================
826 dnl Check for libseccomp
828 if test "x$enable_seccomp" != "xno"; then
829 AC_CHECK_HEADERS([seccomp.h])
830 AC_SEARCH_LIBS(seccomp_init, [seccomp])
833 dnl ============================================================
834 dnl Check for libscrypt
836 if test "x$enable_libscrypt" != "xno"; then
837 AC_CHECK_HEADERS([libscrypt.h])
838 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
841 dnl ============================================================
842 dnl We need an implementation of curve25519.
844 dnl set these defaults.
845 build_curve25519_donna=no
846 build_curve25519_donna_c64=no
847 use_curve25519_donna=no
848 use_curve25519_nacl=no
851 dnl The best choice is using curve25519-donna-c64, but that requires
853 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
854 tor_cv_can_use_curve25519_donna_c64,
856 [AC_LANG_PROGRAM([dnl
858 typedef unsigned uint128_t __attribute__((mode(TI)));
859 int func(uint64_t a, uint64_t b) {
860 uint128_t c = ((uint128_t)a) * b;
861 int ok = ((uint64_t)(c>>96)) == 522859 &&
862 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
863 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
864 (((uint64_t)(c))&0xffffffffL) == 0;
868 int ok = func( ((uint64_t)2000000000) * 1000000000,
869 ((uint64_t)1234567890) << 24);
872 [tor_cv_can_use_curve25519_donna_c64=yes],
873 [tor_cv_can_use_curve25519_donna_c64=no],
875 [AC_LANG_PROGRAM([dnl
877 typedef unsigned uint128_t __attribute__((mode(TI)));
878 int func(uint64_t a, uint64_t b) {
879 uint128_t c = ((uint128_t)a) * b;
880 int ok = ((uint64_t)(c>>96)) == 522859 &&
881 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
882 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
883 (((uint64_t)(c))&0xffffffffL) == 0;
887 int ok = func( ((uint64_t)2000000000) * 1000000000,
888 ((uint64_t)1234567890) << 24);
891 [tor_cv_can_use_curve25519_donna_c64=cross],
892 [tor_cv_can_use_curve25519_donna_c64=no])])])
894 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
895 nacl/crypto_scalarmult_curve25519.h])
897 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
898 tor_cv_can_use_curve25519_nacl,
899 [tor_saved_LIBS="$LIBS"
902 [AC_LANG_PROGRAM([dnl
903 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
904 #include <crypto_scalarmult_curve25519.h>
905 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
906 #include <nacl/crypto_scalarmult_curve25519.h>
908 #ifdef crypto_scalarmult_curve25519_ref_BYTES
909 #error Hey, this is the reference implementation! That's not fast.
912 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
913 ])], [tor_cv_can_use_curve25519_nacl=yes],
914 [tor_cv_can_use_curve25519_nacl=no])
915 LIBS="$tor_saved_LIBS" ])
917 dnl Okay, now we need to figure out which one to actually use. Fall back
918 dnl to curve25519-donna.c
920 if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
921 build_curve25519_donna_c64=yes
922 use_curve25519_donna=yes
923 elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
924 use_curve25519_nacl=yes
925 CURVE25519_LIBS=-lnacl
927 build_curve25519_donna=yes
928 use_curve25519_donna=yes
931 if test "x$use_curve25519_donna" = "xyes"; then
932 AC_DEFINE(USE_CURVE25519_DONNA, 1,
933 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
935 if test "x$use_curve25519_nacl" = "xyes"; then
936 AC_DEFINE(USE_CURVE25519_NACL, 1,
937 [Defined if we should use a curve25519 from nacl])
939 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
940 test "x$build_curve25519_donna" = "xyes")
941 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
942 test "x$build_curve25519_donna_c64" = "xyes")
943 AC_SUBST(CURVE25519_LIBS)
945 dnl Make sure to enable support for large off_t if available.
961 , , AC_MSG_WARN(Some headers were not found, compilation may fail. If compilation succeeds, please send your orconfig.h to the developers so we can fix this warning.))
963 dnl These headers are not essential
1007 AC_CHECK_HEADERS(sys/param.h)
1009 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1010 [#ifdef HAVE_SYS_TYPES_H
1011 #include <sys/types.h>
1013 #ifdef HAVE_SYS_SOCKET_H
1014 #include <sys/socket.h>
1016 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1017 [#ifdef HAVE_SYS_TYPES_H
1018 #include <sys/types.h>
1020 #ifdef HAVE_SYS_SOCKET_H
1021 #include <sys/socket.h>
1023 #ifdef HAVE_NET_IF_H
1026 #ifdef HAVE_NETINET_IN_H
1027 #include <netinet/in.h>
1030 AC_CHECK_HEADERS(linux/if.h,[],[],
1032 #ifdef HAVE_SYS_SOCKET_H
1033 #include <sys/socket.h>
1037 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1038 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1039 [#ifdef HAVE_SYS_TYPES_H
1040 #include <sys/types.h>
1042 #ifdef HAVE_SYS_SOCKET_H
1043 #include <sys/socket.h>
1045 #ifdef HAVE_LIMITS_H
1048 #ifdef HAVE_LINUX_TYPES_H
1049 #include <linux/types.h>
1051 #ifdef HAVE_NETINET_IN6_H
1052 #include <netinet/in6.h>
1054 #ifdef HAVE_NETINET_IN_H
1055 #include <netinet/in.h>
1058 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1059 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1060 [#ifdef HAVE_SYS_TYPES_H
1061 #include <sys/types.h>
1063 #ifdef HAVE_SYS_SOCKET_H
1064 #include <sys/socket.h>
1066 #ifdef HAVE_LIMITS_H
1069 #ifdef HAVE_LINUX_TYPES_H
1070 #include <linux/types.h>
1072 #ifdef HAVE_NETINET_IN6_H
1073 #include <netinet/in6.h>
1075 #ifdef HAVE_NETINET_IN_H
1076 #include <netinet/in.h>
1078 #ifdef HAVE_LINUX_IF_H
1079 #include <linux/if.h>
1082 if test "x$transparent" = "xtrue"; then
1084 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1087 if test "x$linux_netfilter_ipv4" = "x1"; then
1090 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1093 if test "x$transparent_ok" = "x1"; then
1094 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1096 *-*-openbsd* | *-*-bitrig*)
1097 AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
1100 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1104 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1105 [#ifdef HAVE_SYS_TYPES_H
1106 #include <sys/types.h>
1108 #ifdef HAVE_SYS_TIME_H
1109 #include <sys/time.h>
1112 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1115 AC_CHECK_SIZEOF(int8_t)
1116 AC_CHECK_SIZEOF(int16_t)
1117 AC_CHECK_SIZEOF(int32_t)
1118 AC_CHECK_SIZEOF(int64_t)
1119 AC_CHECK_SIZEOF(uint8_t)
1120 AC_CHECK_SIZEOF(uint16_t)
1121 AC_CHECK_SIZEOF(uint32_t)
1122 AC_CHECK_SIZEOF(uint64_t)
1123 AC_CHECK_SIZEOF(intptr_t)
1124 AC_CHECK_SIZEOF(uintptr_t)
1126 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1128 AC_CHECK_SIZEOF(char)
1129 AC_CHECK_SIZEOF(short)
1130 AC_CHECK_SIZEOF(int)
1131 AC_CHECK_SIZEOF(long)
1132 AC_CHECK_SIZEOF(long long)
1133 AC_CHECK_SIZEOF(__int64)
1134 AC_CHECK_SIZEOF(void *)
1135 AC_CHECK_SIZEOF(time_t)
1136 AC_CHECK_SIZEOF(size_t)
1137 AC_CHECK_SIZEOF(pid_t)
1139 AC_CHECK_TYPES([uint, u_char, ssize_t])
1141 AC_PC_FROM_UCONTEXT([:])
1143 dnl used to include sockaddr_storage, but everybody has that.
1144 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1145 [#ifdef HAVE_SYS_TYPES_H
1146 #include <sys/types.h>
1148 #ifdef HAVE_NETINET_IN_H
1149 #include <netinet/in.h>
1151 #ifdef HAVE_NETINET_IN6_H
1152 #include <netinet/in6.h>
1154 #ifdef HAVE_SYS_SOCKET_H
1155 #include <sys/socket.h>
1158 #define _WIN32_WINNT 0x0501
1159 #define WIN32_LEAN_AND_MEAN
1160 #include <winsock2.h>
1161 #include <ws2tcpip.h>
1164 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1165 [#ifdef HAVE_SYS_TYPES_H
1166 #include <sys/types.h>
1168 #ifdef HAVE_NETINET_IN_H
1169 #include <netinet/in.h>
1171 #ifdef HAVE_NETINET_IN6_H
1172 #include <netinet/in6.h>
1174 #ifdef HAVE_SYS_SOCKET_H
1175 #include <sys/socket.h>
1178 #define _WIN32_WINNT 0x0501
1179 #define WIN32_LEAN_AND_MEAN
1180 #include <winsock2.h>
1181 #include <ws2tcpip.h>
1185 AC_CHECK_TYPES([rlim_t], , ,
1186 [#ifdef HAVE_SYS_TYPES_H
1187 #include <sys/types.h>
1189 #ifdef HAVE_SYS_TIME_H
1190 #include <sys/time.h>
1192 #ifdef HAVE_SYS_RESOURCE_H
1193 #include <sys/resource.h>
1197 AX_CHECK_SIGN([time_t],
1200 #ifdef HAVE_SYS_TYPES_H
1201 #include <sys/types.h>
1203 #ifdef HAVE_SYS_TIME_H
1204 #include <sys/time.h>
1211 if test "$ax_cv_decl_time_t_signed" = "no"; then
1212 AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1215 AX_CHECK_SIGN([size_t],
1216 [ tor_cv_size_t_signed=yes ],
1217 [ tor_cv_size_t_signed=no ], [
1218 #ifdef HAVE_SYS_TYPES_H
1219 #include <sys/types.h>
1223 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1224 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1227 AX_CHECK_SIGN([enum always],
1228 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1230 enum always { AAA, BBB, CCC };
1233 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1234 #ifdef HAVE_SYS_SOCKET_H
1235 #include <sys/socket.h>
1239 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1241 AC_CHECK_SIZEOF(cell_t)
1243 # Now make sure that NULL can be represented as zero bytes.
1244 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1245 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1246 [[#include <stdlib.h>
1249 #ifdef HAVE_STDDEF_H
1252 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1253 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1254 [tor_cv_null_is_zero=yes],
1255 [tor_cv_null_is_zero=no],
1256 [tor_cv_null_is_zero=cross])])
1258 if test "$tor_cv_null_is_zero" = "cross"; then
1259 # Cross-compiling; let's hope that the target isn't raving mad.
1260 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1263 if test "$tor_cv_null_is_zero" != "no"; then
1264 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1265 [Define to 1 iff memset(0) sets pointers to NULL])
1268 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1269 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1270 [[#include <stdlib.h>
1273 #ifdef HAVE_STDDEF_H
1276 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1277 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1278 [tor_cv_dbl0_is_zero=yes],
1279 [tor_cv_dbl0_is_zero=no],
1280 [tor_cv_dbl0_is_zero=cross])])
1282 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1283 # Cross-compiling; let's hope that the target isn't raving mad.
1284 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1287 if test "$tor_cv_dbl0_is_zero" != "no"; then
1288 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1289 [Define to 1 iff memset(0) sets doubles to 0.0])
1292 # And what happens when we malloc zero?
1293 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1294 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1295 [[#include <stdlib.h>
1298 #ifdef HAVE_STDDEF_H
1301 int main () { return malloc(0)?0:1; }]])],
1302 [tor_cv_malloc_zero_works=yes],
1303 [tor_cv_malloc_zero_works=no],
1304 [tor_cv_malloc_zero_works=cross])])
1306 if test "$tor_cv_malloc_zero_works" = "cross"; then
1307 # Cross-compiling; let's hope that the target isn't raving mad.
1308 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1311 if test "$tor_cv_malloc_zero_works" = "yes"; then
1312 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1313 [Define to 1 iff malloc(0) returns a pointer])
1316 # whether we seem to be in a 2s-complement world.
1317 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1318 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1319 [[int main () { int problem = ((-99) != (~99)+1);
1320 return problem ? 1 : 0; }]])],
1321 [tor_cv_twos_complement=yes],
1322 [tor_cv_twos_complement=no],
1323 [tor_cv_twos_complement=cross])])
1325 if test "$tor_cv_twos_complement" = "cross"; then
1326 # Cross-compiling; let's hope that the target isn't raving mad.
1327 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1330 if test "$tor_cv_twos_complement" != "no"; then
1331 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1332 [Define to 1 iff we represent negative integers with
1336 # What does shifting a negative value do?
1337 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1338 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1339 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1340 [tor_cv_sign_extend=yes],
1341 [tor_cv_sign_extend=no],
1342 [tor_cv_sign_extend=cross])])
1344 if test "$tor_cv_sign_extend" = "cross"; then
1345 # Cross-compiling; let's hope that the target isn't raving mad.
1346 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1349 if test "$tor_cv_sign_extend" != "no"; then
1350 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1351 [Define to 1 iff right-shifting a negative value performs sign-extension])
1354 # Whether we should use the dmalloc memory allocation debugging library.
1355 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1356 AC_ARG_WITH(dmalloc,
1357 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1358 [if [[ "$withval" = "yes" ]]; then
1364 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1367 if [[ $dmalloc -eq 1 ]]; then
1368 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1369 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1370 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1371 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1374 AC_ARG_WITH(tcmalloc,
1375 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1376 [ tcmalloc=yes ], [ tcmalloc=no ])
1378 if test "x$tcmalloc" = "xyes"; then
1379 LDFLAGS="-ltcmalloc $LDFLAGS"
1382 using_custom_malloc=no
1383 if test "x$enable_openbsd_malloc" = "xyes"; then
1384 using_custom_malloc=yes
1386 if test "x$tcmalloc" = "xyes"; then
1387 using_custom_malloc=yes
1389 if test "$using_custom_malloc" = "no"; then
1390 AC_CHECK_FUNCS(mallinfo)
1393 # By default, we're going to assume we don't have mlockall()
1394 # bionic and other platforms have various broken mlockall subsystems.
1395 # Some systems don't have a working mlockall, some aren't linkable,
1396 # and some have it but don't declare it.
1397 AC_CHECK_FUNCS(mlockall)
1398 AC_CHECK_DECLS([mlockall], , , [
1399 #ifdef HAVE_SYS_MMAN_H
1400 #include <sys/mman.h>
1403 # Allow user to specify an alternate syslog facility
1404 AC_ARG_WITH(syslog-facility,
1405 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1406 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1407 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1408 AC_SUBST(LOGFACILITY)
1410 # Check if we have getresuid and getresgid
1411 AC_CHECK_FUNCS(getresuid getresgid)
1413 # Check for gethostbyname_r in all its glorious incompatible versions.
1414 # (This logic is based on that in Python's configure.in)
1415 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1416 [Define this if you have any gethostbyname_r()])
1418 AC_CHECK_FUNC(gethostbyname_r, [
1419 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1421 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1422 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1426 struct hostent *h1, *h2;
1428 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1430 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1431 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1432 [Define this if gethostbyname_r takes 6 arguments])
1441 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1443 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1444 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1445 [Define this if gethostbyname_r takes 5 arguments])
1453 struct hostent_data hd;
1454 (void) gethostbyname_r(cp1,h1,&hd);
1456 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1457 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1458 [Define this if gethostbyname_r takes 3 arguments])
1468 AC_CACHE_CHECK([whether the C compiler supports __func__],
1469 tor_cv_have_func_macro,
1470 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1472 int main(int c, char **v) { puts(__func__); }])],
1473 tor_cv_have_func_macro=yes,
1474 tor_cv_have_func_macro=no))
1476 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1477 tor_cv_have_FUNC_macro,
1478 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1480 int main(int c, char **v) { puts(__FUNC__); }])],
1481 tor_cv_have_FUNC_macro=yes,
1482 tor_cv_have_FUNC_macro=no))
1484 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1485 tor_cv_have_FUNCTION_macro,
1486 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1488 int main(int c, char **v) { puts(__FUNCTION__); }])],
1489 tor_cv_have_FUNCTION_macro=yes,
1490 tor_cv_have_FUNCTION_macro=no))
1492 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1493 tor_cv_have_environ_declared,
1494 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1495 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1496 * Without it environ doesn't get declared. */
1498 #ifdef HAVE_UNISTD_H
1502 int main(int c, char **v) { char **t = environ; }])],
1503 tor_cv_have_environ_declared=yes,
1504 tor_cv_have_environ_declared=no))
1506 if test "$tor_cv_have_func_macro" = "yes"; then
1507 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1510 if test "$tor_cv_have_FUNC_macro" = "yes"; then
1511 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1514 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
1515 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1516 [Defined if the compiler supports __FUNCTION__])
1519 if test "$tor_cv_have_environ_declared" = "yes"; then
1520 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1521 [Defined if we have extern char **environ already declared])
1524 # $prefix stores the value of the --prefix command line option, or
1525 # NONE if the option wasn't set. In the case that it wasn't set, make
1526 # it be the default, so that we can use it to expand directories now.
1527 if test "x$prefix" = "xNONE"; then
1528 prefix=$ac_default_prefix
1531 # and similarly for $exec_prefix
1532 if test "x$exec_prefix" = "xNONE"; then
1536 if test "x$BUILDDIR" = "x"; then
1540 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1541 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1543 if test "x$CONFDIR" = "x"; then
1544 CONFDIR=`eval echo $sysconfdir/tor`
1547 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1548 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1550 BINDIR=`eval echo $bindir`
1552 LOCALSTATEDIR=`eval echo $localstatedir`
1553 AC_SUBST(LOCALSTATEDIR)
1555 if test "$bwin32" = "true"; then
1556 # Test if the linker supports the --nxcompat and --dynamicbase options
1558 save_LDFLAGS="$LDFLAGS"
1559 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1560 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1561 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1562 [AC_MSG_RESULT([yes])]
1563 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1564 [AC_MSG_RESULT([no])]
1566 LDFLAGS="$save_LDFLAGS"
1569 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1570 # than autoconf's macros like.
1571 if test "$GCC" = "yes"; then
1572 # Disable GCC's strict aliasing checks. They are an hours-to-debug
1573 # accident waiting to happen.
1574 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1576 # Override optimization level for non-gcc compilers
1578 enable_gcc_warnings=no
1579 enable_gcc_warnings_advisory=no
1582 # OS X Lion started deprecating the system openssl. Let's just disable
1583 # all deprecation warnings on OS X. Also, to potentially make the binary
1584 # a little smaller, let's enable dead_strip.
1588 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1589 LDFLAGS="$LDFLAGS -dead_strip" ;;
1592 # Add some more warnings which we use in development but not in the
1593 # released versions. (Some relevant gcc versions can't handle these.)
1594 if test "x$enable_gcc_warnings" = "xyes" ||
1595 test "x$enable_gcc_warnings_advisory" = "xyes"; then
1597 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1598 #if !defined(__GNUC__) || (__GNUC__ < 4)
1600 #endif])], have_gcc4=yes, have_gcc4=no)
1602 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1603 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1605 #endif])], have_gcc42=yes, have_gcc42=no)
1607 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1608 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1610 #endif])], have_gcc43=yes, have_gcc43=no)
1612 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1613 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1615 #endif])], have_gcc46=yes, have_gcc46=no)
1618 save_CFLAGS="$CFLAGS"
1619 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1620 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1621 have_shorten64_flag=no)
1622 CFLAGS="$save_CFLAGS"
1625 *-*-openbsd* | *-*-bitrig*)
1626 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1627 # That's fine, except that the headers don't pass -Wredundant-decls.
1628 # Therefore, let's disable -Wsystem-headers when we're building
1629 # with maximal warnings on OpenBSD.
1630 CFLAGS="$CFLAGS -Wno-system-headers" ;;
1633 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1634 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1635 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1636 CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1637 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1639 if test "x$enable_gcc_warnings" = "xyes"; then
1640 CFLAGS="$CFLAGS -Werror"
1643 # Disabled, so we can use mallinfo(): -Waggregate-return
1645 if test "x$have_gcc4" = "xyes"; then
1646 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1647 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
1650 if test "x$have_gcc42" = "xyes"; then
1651 # These warnings break gcc 4.0.2 and work on gcc 4.2
1652 # XXXX020 See if any of these work with earlier versions.
1653 CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1655 # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1658 if test "x$have_gcc42" = "xyes" && test "x$have_clang" = "xno"; then
1659 # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1660 CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1663 if test "x$have_gcc43" = "xyes"; then
1664 # These warnings break gcc 4.2 and work on gcc 4.3
1665 # XXXX020 See if any of these work with earlier versions.
1666 CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1669 if test "x$have_gcc46" = "xyes"; then
1670 # This warning was added in gcc 4.3, but it appears to generate
1671 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
1672 CFLAGS="$CFLAGS -Wlogical-op"
1675 if test "x$have_shorten64_flag" = "xyes"; then
1676 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1681 ##This will break the world on some 64-bit architectures
1682 # CFLAGS="$CFLAGS -Winline"
1685 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
1688 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-profiling.])
1692 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1697 contrib/dist/suse/tor.sh
1698 contrib/operator-tools/tor.logrotate
1701 contrib/dist/tor.service
1702 src/config/torrc.sample
1703 src/config/torrc.minimal
1704 scripts/maint/checkOptionDocs.pl
1705 scripts/maint/updateVersions.pl
1708 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
1709 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1710 for file in $regular_mans ; do
1711 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1712 echo "==================================";
1714 echo "Building Tor has failed since manpages cannot be built.";
1716 echo "You need asciidoc installed to be able to build the manpages.";
1717 echo "To build without manpages, use the --disable-asciidoc argument";
1718 echo "when calling configure.";
1720 echo "==================================";