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
6 AC_INIT([tor],[0.2.8.1-alpha-dev])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AC_CONFIG_MACRO_DIR([m4])
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AC_CONFIG_HEADERS([orconfig.h])
17 if test -f /etc/redhat-release ; then
18 if test -f /usr/kerberos/include ; then
19 CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
23 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
24 # the += operator on it in src/or/Makefile.am
25 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
27 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
28 AC_ARG_ENABLE(openbsd-malloc,
29 AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
30 AC_ARG_ENABLE(instrument-downloads,
31 AS_HELP_STRING(--enable-instrument-downloads, [instrument downloads of directory resources etc.]))
32 AC_ARG_ENABLE(static-openssl,
33 AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
34 AC_ARG_ENABLE(static-libevent,
35 AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
36 AC_ARG_ENABLE(static-zlib,
37 AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
38 AC_ARG_ENABLE(static-tor,
39 AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
40 AC_ARG_ENABLE(unittests,
41 AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
42 AC_ARG_ENABLE(coverage,
43 AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
44 AC_ARG_ENABLE(system-torrc,
45 AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
47 AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
48 AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
50 if test "$enable_static_tor" = "yes"; then
51 enable_static_libevent="yes";
52 enable_static_openssl="yes";
53 enable_static_zlib="yes";
54 CFLAGS="$CFLAGS -static"
57 if test "$enable_system_torrc" = "no"; then
58 AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
59 [Defined if we're not going to look for a torrc in SYSCONF])
62 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
63 if test x$enable_instrument_downloads = xyes; then
64 AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
65 [Defined if we want to keep track of how much of each kind of resource we download.])
68 AC_ARG_ENABLE(transparent,
69 AS_HELP_STRING(--disable-transparent, [disable transparent proxy support]),
70 [case "${enableval}" in
71 yes) transparent=true ;;
72 no) transparent=false ;;
73 *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
74 esac], [transparent=true])
76 AC_ARG_ENABLE(asciidoc,
77 AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
78 [case "${enableval}" in
81 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
82 esac], [asciidoc=true])
84 # systemd notify support
85 AC_ARG_ENABLE(systemd,
86 AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
87 [case "${enableval}" in
90 * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
91 esac], [systemd=auto])
96 if test x$enable_systemd = xno ; then
99 PKG_CHECK_MODULES(SYSTEMD,
103 if test x$have_systemd=xno; then
104 AC_MSG_NOTICE([Okay, checking for systemd a different way...])
105 PKG_CHECK_MODULES(SYSTEMD,
112 if test x$have_systemd = xyes; then
113 AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
114 TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
115 TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
116 PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
117 [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
119 AC_SUBST(TOR_SYSTEMD_CFLAGS)
120 AC_SUBST(TOR_SYSTEMD_LIBS)
122 if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
123 AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
128 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
132 AC_ARG_ENABLE(gcc-warnings,
133 AS_HELP_STRING(--enable-gcc-warnings, [enable verbose warnings]))
134 AC_ARG_ENABLE(gcc-warnings-advisory,
135 AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
137 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
138 AC_ARG_ENABLE(gcc-hardening,
139 AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
141 AC_ARG_ENABLE(expensive-hardening,
142 AS_HELP_STRING(--enable-expensive-hardening, [enable more expensive compiler hardening; makes Tor slower]))
144 dnl Linker hardening options
145 dnl Currently these options are ELF specific - you can't use this with MacOSX
146 AC_ARG_ENABLE(linker-hardening,
147 AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
149 AC_ARG_ENABLE(local-appdata,
150 AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
151 if test "$enable_local_appdata" = "yes"; then
152 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
153 [Defined if we default to host local appdata paths on Windows])
157 AC_ARG_ENABLE(tor2web-mode,
158 AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
159 [if test x$enableval = xyes; then
160 CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
163 AC_ARG_ENABLE(bufferevents,
164 AS_HELP_STRING(--enable-bufferevents, [use Libevent's buffered IO]))
166 AC_ARG_ENABLE(tool-name-check,
167 AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
169 AC_ARG_ENABLE(seccomp,
170 AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
172 AC_ARG_ENABLE(libscrypt,
173 AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
175 dnl check for the correct "ar" when cross-compiling
176 AN_MAKEVAR([AR], [AC_PROG_AR])
177 AN_PROGRAM([ar], [AC_PROG_AR])
178 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
181 dnl Check whether the above macro has settled for a simply named tool even
182 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
183 dnl because that will find any cc on the system, not only the cross-compiler,
184 dnl and then verify that a binary built with this compiler runs on the
185 dnl build system. It will then come to the false conclusion that we're not
187 if test x$enable_tool_name_check != xno; then
188 if test x$ac_tool_warned = xyes; then
189 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.)])
190 elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
191 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.)])
200 AC_PATH_PROG([PERL], [perl])
202 dnl autoconf 2.59 appears not to support AC_PROG_SED
203 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
205 dnl check for asciidoc and a2x
206 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
207 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
209 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
211 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
212 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
213 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
217 AC_ARG_VAR([PYTHON], [path to Python binary])
218 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
219 if test "x$PYTHON" = "x"; then
220 AC_MSG_WARN([Python unavailable; some tests will not be run.])
222 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
224 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
225 AC_C_FLEXIBLE_ARRAY_MEMBER
227 dnl Maybe we've got an old autoconf...
228 AC_CACHE_CHECK([for flexible array members],
232 struct abc { int a; char b[]; };
234 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
237 [tor_cv_c_flexarray=yes],
238 [tor_cv_c_flexarray=no])])
239 if test $tor_cv_flexarray = yes ; then
240 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
242 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
246 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
249 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
250 [tor_cv_c_c99_decl=yes],
251 [tor_cv_c_c99_decl=no] )])
252 if test "$tor_cv_c_c99_decl" != "yes"; then
253 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
256 AC_CACHE_CHECK([for working C99 designated initializers],
257 tor_cv_c_c99_designated_init,
259 [AC_LANG_PROGRAM([struct s { int a; int b; };],
260 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
261 [tor_cv_c_c99_designated_init=yes],
262 [tor_cv_c_c99_designated_init=no] )])
264 if test "$tor_cv_c_c99_designated_init" != "yes"; then
265 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
269 AC_ARG_WITH(tor-user,
270 AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
278 AC_ARG_WITH(tor-group,
279 AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
287 dnl If _WIN32 is defined and non-zero, we are building for win32
288 AC_MSG_CHECKING([for win32])
289 AC_RUN_IFELSE([AC_LANG_SOURCE([
290 int main(int c, char **v) {
301 bwin32=true; AC_MSG_RESULT([yes]),
302 bwin32=false; AC_MSG_RESULT([no]),
303 bwin32=cross; AC_MSG_RESULT([cross])
306 if test "$bwin32" = cross; then
307 AC_MSG_CHECKING([for win32 (cross)])
308 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
310 int main(int c, char **v) {return 0;}
313 int main(int c, char **v) {return x(y);}
316 bwin32=true; AC_MSG_RESULT([yes]),
317 bwin32=false; AC_MSG_RESULT([no]))
322 /* Defined to access windows functions and definitions for >=WinXP */
324 # define WINVER 0x0501
327 /* Defined to access _other_ windows functions and definitions for >=WinXP */
328 # ifndef _WIN32_WINNT
329 # define _WIN32_WINNT 0x0501
332 /* Defined to avoid including some windows headers as part of Windows.h */
333 # ifndef WIN32_LEAN_AND_MEAN
334 # define WIN32_LEAN_AND_MEAN 1
340 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
342 dnl Enable C99 when compiling with MIPSpro
343 AC_MSG_CHECKING([for MIPSpro compiler])
344 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
345 #if (defined(__sgi) && defined(_COMPILER_VERSION))
350 bmipspro=false; AC_MSG_RESULT(no),
351 bmipspro=true; AC_MSG_RESULT(yes))
353 if test "$bmipspro" = true; then
354 CFLAGS="$CFLAGS -c99"
359 AC_SEARCH_LIBS(socket, [socket network])
360 AC_SEARCH_LIBS(gethostbyname, [nsl])
361 AC_SEARCH_LIBS(dlopen, [dl])
362 AC_SEARCH_LIBS(inet_aton, [resolv])
363 AC_SEARCH_LIBS(backtrace, [execinfo])
365 AC_SEARCH_LIBS([clock_gettime], [rt])
366 if test "$LIBS" != "$saved_LIBS"; then
367 # Looks like we need -lrt for clock_gettime().
371 AC_SEARCH_LIBS(pthread_create, [pthread])
372 AC_SEARCH_LIBS(pthread_detach, [pthread])
374 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
375 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
379 RtlSecureZeroMemory \
383 backtrace_symbols_fd \
428 if test "$bwin32" != true; then
429 AC_CHECK_HEADERS(pthread.h)
430 AC_CHECK_FUNCS(pthread_create)
431 AC_CHECK_FUNCS(pthread_condattr_setclock)
434 if test "$bwin32" = true; then
435 AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
442 AM_CONDITIONAL(BUILD_READPASSPHRASE_C, test x$ac_cv_func_readpassphrase = xno && test $bwin32 = false)
444 dnl ------------------------------------------------------
445 dnl Where do you live, libevent? And how do we call you?
447 if test "$bwin32" = true; then
448 TOR_LIB_WS32=-lws2_32
449 TOR_LIB_IPHLPAPI=-liphlpapi
450 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
451 # think it's actually necessary.
457 AC_SUBST(TOR_LIB_WS32)
458 AC_SUBST(TOR_LIB_GDI)
459 AC_SUBST(TOR_LIB_IPHLPAPI)
461 tor_libevent_pkg_redhat="libevent"
462 tor_libevent_pkg_debian="libevent-dev"
463 tor_libevent_devpkg_redhat="libevent-devel"
464 tor_libevent_devpkg_debian="libevent-dev"
466 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
467 dnl linking for static builds.
468 STATIC_LIBEVENT_FLAGS=""
469 if test "$enable_static_libevent" = "yes"; then
470 if test "$have_rt" = yes; then
471 STATIC_LIBEVENT_FLAGS=" -lrt "
475 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
477 #include <winsock2.h>
480 #include <sys/time.h>
481 #include <sys/types.h>
482 #include <event.h>], [
484 #include <winsock2.h>
486 void exit(int); void *event_init(void);],
489 {WSADATA d; WSAStartup(0x101,&d); }
491 event_init(); exit(0);
492 ], [--with-libevent-dir], [/opt/libevent])
494 dnl Now check for particular libevent functions.
496 save_LDFLAGS="$LDFLAGS"
497 save_CPPFLAGS="$CPPFLAGS"
498 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
499 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
500 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
501 AC_CHECK_FUNCS([event_get_version_number \
502 evutil_secure_rng_set_urandom_device_file \
503 evutil_secure_rng_init \
505 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
509 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
511 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
513 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
515 if test "$enable_static_libevent" = "yes"; then
516 if test "$tor_cv_library_libevent_dir" = "(system)"; then
517 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
519 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
522 if test "x$ac_cv_header_event2_event_h" = "xyes"; then
523 AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
524 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"))
526 if test "$ac_cv_search_event_new" != "none required"; then
527 TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
529 if test "$ac_cv_search_evdns_base_new" != "none required"; then
530 TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
533 TOR_LIBEVENT_LIBS="-levent"
538 LDFLAGS="$save_LDFLAGS"
539 CPPFLAGS="$save_CPPFLAGS"
541 dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
542 dnl we can do much better.
543 if test "$enable_bufferevents" = "yes" ; then
544 if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
545 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.])
548 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
550 # Check for the right version. First see if version detection works.
551 AC_MSG_CHECKING([whether we can detect the Libevent version])
552 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
553 #include <event2/event.h>
554 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
560 ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
561 [event_version_number_works=no; AC_MSG_RESULT([no])])
562 if test "$event_version_number_works" != 'yes'; then
563 AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
565 AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
566 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
567 #include <event2/event.h>
568 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
574 ])], [ AC_MSG_RESULT([yes]) ],
575 [ AC_MSG_RESULT([no])
576 AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
582 LDFLAGS="$save_LDFLAGS"
583 CPPFLAGS="$save_CPPFLAGS"
585 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
586 if test "$enable_bufferevents" = "yes"; then
587 AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
588 if test "$enable_static_libevent" = "yes"; then
589 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
591 TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
594 AC_SUBST(TOR_LIBEVENT_LIBS)
596 dnl ------------------------------------------------------
597 dnl Where do you live, libm?
599 dnl On some platforms (Haiku/BeOS) the math library is
600 dnl part of libroot. In which case don't link against lm
603 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
604 if test "$ac_cv_search_pow" != "none required"; then
605 TOR_LIB_MATH="$ac_cv_search_pow"
608 AC_SUBST(TOR_LIB_MATH)
610 dnl ------------------------------------------------------
611 dnl Where do you live, openssl? And how do we call you?
613 tor_openssl_pkg_redhat="openssl"
614 tor_openssl_pkg_debian="libssl-dev"
615 tor_openssl_devpkg_redhat="openssl-devel"
616 tor_openssl_devpkg_debian="libssl-dev"
618 ALT_openssl_WITHVAL=""
620 AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
622 if test "x$withval" != xno && test "x$withval" != "x" ; then
623 ALT_openssl_WITHVAL="$withval"
627 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
628 [#include <openssl/rand.h>],
629 [void RAND_add(const void *buf, int num, double entropy);],
630 [RAND_add((void*)0,0,0); exit(0);], [],
631 [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
633 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
635 if test "$enable_static_openssl" = "yes"; then
636 if test "$tor_cv_library_openssl_dir" = "(system)"; then
637 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
639 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
642 TOR_OPENSSL_LIBS="-lssl -lcrypto"
644 AC_SUBST(TOR_OPENSSL_LIBS)
646 dnl Now check for particular openssl functions.
648 save_LDFLAGS="$LDFLAGS"
649 save_CPPFLAGS="$CPPFLAGS"
650 LIBS="$TOR_OPENSSL_LIBS $LIBS"
651 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
652 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
655 #include <openssl/opensslv.h>
656 #if OPENSSL_VERSION_NUMBER < 0x1000000fL
661 [ 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.]) ])
664 #include <openssl/opensslv.h>
665 #include <openssl/evp.h>
666 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
669 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
670 #error "curves unavailable"
674 [ 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.]) ])
676 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
677 [#include <openssl/ssl.h>
681 SSL_SESSION_get_master_key \
682 SSL_get_server_random \
683 SSL_get_client_ciphers \
684 SSL_get_client_random \
689 dnl Check if OpenSSL has scrypt implementation.
690 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
693 LDFLAGS="$save_LDFLAGS"
694 CPPFLAGS="$save_CPPFLAGS"
696 dnl ------------------------------------------------------
697 dnl Where do you live, zlib? And how do we call you?
699 tor_zlib_pkg_redhat="zlib"
700 tor_zlib_pkg_debian="zlib1g"
701 tor_zlib_devpkg_redhat="zlib-devel"
702 tor_zlib_devpkg_debian="zlib1g-dev"
704 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
706 [const char * zlibVersion(void);],
707 [zlibVersion(); exit(0);], [--with-zlib-dir],
710 if test "$enable_static_zlib" = "yes"; then
711 if test "$tor_cv_library_zlib_dir" = "(system)"; then
712 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
713 using --enable-static-zlib")
715 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
720 AC_SUBST(TOR_ZLIB_LIBS)
722 dnl ----------------------------------------------------------------------
723 dnl Check if libcap is available for capabilities.
725 tor_cap_pkg_debian="libcap2"
726 tor_cap_pkg_redhat="libcap"
727 tor_cap_devpkg_debian="libcap-dev"
728 tor_cap_devpkg_redhat="libcap-devel"
730 AC_CHECK_LIB([cap], [cap_init], [],
731 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
733 AC_CHECK_FUNCS(cap_set_proc)
735 dnl ---------------------------------------------------------------------
736 dnl Now that we know about our major libraries, we can check for compiler
737 dnl and linker hardening options. We need to do this with the libraries known,
738 dnl since sometimes the linker will like an option but not be willing to
739 dnl use it with a build of a library.
741 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
742 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"
744 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
745 #if !defined(__clang__)
747 #endif])], have_clang=yes, have_clang=no)
749 if test x$enable_gcc_hardening != xno; then
750 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
751 if test x$have_clang = xyes; then
752 TOR_CHECK_CFLAGS(-Qunused-arguments)
754 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
755 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
756 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
757 m4_ifdef([AS_VAR_IF],[
758 AS_VAR_IF(can_compile, [yes],
759 AS_VAR_IF(can_link, [yes],
761 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.)]))
763 AS_VAR_POPDEF([can_link])
764 AS_VAR_POPDEF([can_compile])
765 TOR_CHECK_CFLAGS(-Wstack-protector)
766 TOR_CHECK_CFLAGS(-fwrapv)
767 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
768 if test "$bwin32" = "false"; then
769 TOR_CHECK_CFLAGS(-fPIE)
770 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
774 if test x$enable_expensive_hardening = xyes ; then
775 TOR_CHECK_CFLAGS([-fsanitize=address])
776 TOR_CHECK_CFLAGS([-fsanitize=undefined])
777 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
780 if test x$enable_linker_hardening != xno; then
781 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
784 # For backtrace support
785 TOR_CHECK_LDFLAGS(-rdynamic)
787 dnl ------------------------------------------------------
788 dnl Now see if we have a -fomit-frame-pointer compiler option.
790 saved_CFLAGS="$CFLAGS"
791 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
792 F_OMIT_FRAME_POINTER=''
793 if test "$saved_CFLAGS" != "$CFLAGS"; then
794 if test x$enable_expensive_hardening != xyes ; then
795 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
798 CFLAGS="$saved_CFLAGS"
799 AC_SUBST(F_OMIT_FRAME_POINTER)
801 dnl ------------------------------------------------------
802 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
803 dnl for us, as GCC 4.6 and later do at many optimization levels), then
804 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
806 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
808 dnl ============================================================
809 dnl Check for libseccomp
811 if test "x$enable_seccomp" != "xno"; then
812 AC_CHECK_HEADERS([seccomp.h])
813 AC_SEARCH_LIBS(seccomp_init, [seccomp])
816 dnl ============================================================
817 dnl Check for libscrypt
819 if test "x$enable_libscrypt" != "xno"; then
820 AC_CHECK_HEADERS([libscrypt.h])
821 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
824 dnl ============================================================
825 dnl We need an implementation of curve25519.
827 dnl set these defaults.
828 build_curve25519_donna=no
829 build_curve25519_donna_c64=no
830 use_curve25519_donna=no
831 use_curve25519_nacl=no
834 dnl The best choice is using curve25519-donna-c64, but that requires
836 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
837 tor_cv_can_use_curve25519_donna_c64,
839 [AC_LANG_PROGRAM([dnl
841 typedef unsigned uint128_t __attribute__((mode(TI)));
842 int func(uint64_t a, uint64_t b) {
843 uint128_t c = ((uint128_t)a) * b;
844 int ok = ((uint64_t)(c>>96)) == 522859 &&
845 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
846 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
847 (((uint64_t)(c))&0xffffffffL) == 0;
851 int ok = func( ((uint64_t)2000000000) * 1000000000,
852 ((uint64_t)1234567890) << 24);
855 [tor_cv_can_use_curve25519_donna_c64=yes],
856 [tor_cv_can_use_curve25519_donna_c64=no],
858 [AC_LANG_PROGRAM([dnl
860 typedef unsigned uint128_t __attribute__((mode(TI)));
861 int func(uint64_t a, uint64_t b) {
862 uint128_t c = ((uint128_t)a) * b;
863 int ok = ((uint64_t)(c>>96)) == 522859 &&
864 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
865 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
866 (((uint64_t)(c))&0xffffffffL) == 0;
870 int ok = func( ((uint64_t)2000000000) * 1000000000,
871 ((uint64_t)1234567890) << 24);
874 [tor_cv_can_use_curve25519_donna_c64=cross],
875 [tor_cv_can_use_curve25519_donna_c64=no])])])
877 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
878 nacl/crypto_scalarmult_curve25519.h])
880 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
881 tor_cv_can_use_curve25519_nacl,
882 [tor_saved_LIBS="$LIBS"
885 [AC_LANG_PROGRAM([dnl
886 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
887 #include <crypto_scalarmult_curve25519.h>
888 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
889 #include <nacl/crypto_scalarmult_curve25519.h>
891 #ifdef crypto_scalarmult_curve25519_ref_BYTES
892 #error Hey, this is the reference implementation! That's not fast.
895 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
896 ])], [tor_cv_can_use_curve25519_nacl=yes],
897 [tor_cv_can_use_curve25519_nacl=no])
898 LIBS="$tor_saved_LIBS" ])
900 dnl Okay, now we need to figure out which one to actually use. Fall back
901 dnl to curve25519-donna.c
903 if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
904 build_curve25519_donna_c64=yes
905 use_curve25519_donna=yes
906 elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
907 use_curve25519_nacl=yes
908 CURVE25519_LIBS=-lnacl
910 build_curve25519_donna=yes
911 use_curve25519_donna=yes
914 if test x$use_curve25519_donna = xyes; then
915 AC_DEFINE(USE_CURVE25519_DONNA, 1,
916 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
918 if test x$use_curve25519_nacl = xyes; then
919 AC_DEFINE(USE_CURVE25519_NACL, 1,
920 [Defined if we should use a curve25519 from nacl])
922 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
923 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
924 AC_SUBST(CURVE25519_LIBS)
926 dnl Make sure to enable support for large off_t if available.
942 , , 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.))
944 dnl These headers are not essential
988 AC_CHECK_HEADERS(sys/param.h)
990 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
991 [#ifdef HAVE_SYS_TYPES_H
992 #include <sys/types.h>
994 #ifdef HAVE_SYS_SOCKET_H
995 #include <sys/socket.h>
997 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
998 [#ifdef HAVE_SYS_TYPES_H
999 #include <sys/types.h>
1001 #ifdef HAVE_SYS_SOCKET_H
1002 #include <sys/socket.h>
1004 #ifdef HAVE_NET_IF_H
1007 #ifdef HAVE_NETINET_IN_H
1008 #include <netinet/in.h>
1011 AC_CHECK_HEADERS(linux/if.h,[],[],
1013 #ifdef HAVE_SYS_SOCKET_H
1014 #include <sys/socket.h>
1018 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1019 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1020 [#ifdef HAVE_SYS_TYPES_H
1021 #include <sys/types.h>
1023 #ifdef HAVE_SYS_SOCKET_H
1024 #include <sys/socket.h>
1026 #ifdef HAVE_LIMITS_H
1029 #ifdef HAVE_LINUX_TYPES_H
1030 #include <linux/types.h>
1032 #ifdef HAVE_NETINET_IN6_H
1033 #include <netinet/in6.h>
1035 #ifdef HAVE_NETINET_IN_H
1036 #include <netinet/in.h>
1039 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1040 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1041 [#ifdef HAVE_SYS_TYPES_H
1042 #include <sys/types.h>
1044 #ifdef HAVE_SYS_SOCKET_H
1045 #include <sys/socket.h>
1047 #ifdef HAVE_LIMITS_H
1050 #ifdef HAVE_LINUX_TYPES_H
1051 #include <linux/types.h>
1053 #ifdef HAVE_NETINET_IN6_H
1054 #include <netinet/in6.h>
1056 #ifdef HAVE_NETINET_IN_H
1057 #include <netinet/in.h>
1059 #ifdef HAVE_LINUX_IF_H
1060 #include <linux/if.h>
1063 if test x$transparent = xtrue ; then
1065 if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
1068 if test x$linux_netfilter_ipv4 = x1 ; then
1071 if test x$linux_netfilter_ipv6_ip6_tables = x1 ; then
1074 if test x$transparent_ok = x1 ; then
1075 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1077 *-*-openbsd* | *-*-bitrig*)
1078 AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
1081 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1085 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1086 [#ifdef HAVE_SYS_TYPES_H
1087 #include <sys/types.h>
1089 #ifdef HAVE_SYS_TIME_H
1090 #include <sys/time.h>
1093 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1096 AC_CHECK_SIZEOF(int8_t)
1097 AC_CHECK_SIZEOF(int16_t)
1098 AC_CHECK_SIZEOF(int32_t)
1099 AC_CHECK_SIZEOF(int64_t)
1100 AC_CHECK_SIZEOF(uint8_t)
1101 AC_CHECK_SIZEOF(uint16_t)
1102 AC_CHECK_SIZEOF(uint32_t)
1103 AC_CHECK_SIZEOF(uint64_t)
1104 AC_CHECK_SIZEOF(intptr_t)
1105 AC_CHECK_SIZEOF(uintptr_t)
1107 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1109 AC_CHECK_SIZEOF(char)
1110 AC_CHECK_SIZEOF(short)
1111 AC_CHECK_SIZEOF(int)
1112 AC_CHECK_SIZEOF(long)
1113 AC_CHECK_SIZEOF(long long)
1114 AC_CHECK_SIZEOF(__int64)
1115 AC_CHECK_SIZEOF(void *)
1116 AC_CHECK_SIZEOF(time_t)
1117 AC_CHECK_SIZEOF(size_t)
1118 AC_CHECK_SIZEOF(pid_t)
1120 AC_CHECK_TYPES([uint, u_char, ssize_t])
1122 AC_PC_FROM_UCONTEXT([:])
1124 dnl used to include sockaddr_storage, but everybody has that.
1125 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1126 [#ifdef HAVE_SYS_TYPES_H
1127 #include <sys/types.h>
1129 #ifdef HAVE_NETINET_IN_H
1130 #include <netinet/in.h>
1132 #ifdef HAVE_NETINET_IN6_H
1133 #include <netinet/in6.h>
1135 #ifdef HAVE_SYS_SOCKET_H
1136 #include <sys/socket.h>
1139 #define _WIN32_WINNT 0x0501
1140 #define WIN32_LEAN_AND_MEAN
1141 #include <winsock2.h>
1142 #include <ws2tcpip.h>
1145 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1146 [#ifdef HAVE_SYS_TYPES_H
1147 #include <sys/types.h>
1149 #ifdef HAVE_NETINET_IN_H
1150 #include <netinet/in.h>
1152 #ifdef HAVE_NETINET_IN6_H
1153 #include <netinet/in6.h>
1155 #ifdef HAVE_SYS_SOCKET_H
1156 #include <sys/socket.h>
1159 #define _WIN32_WINNT 0x0501
1160 #define WIN32_LEAN_AND_MEAN
1161 #include <winsock2.h>
1162 #include <ws2tcpip.h>
1166 AC_CHECK_TYPES([rlim_t], , ,
1167 [#ifdef HAVE_SYS_TYPES_H
1168 #include <sys/types.h>
1170 #ifdef HAVE_SYS_TIME_H
1171 #include <sys/time.h>
1173 #ifdef HAVE_SYS_RESOURCE_H
1174 #include <sys/resource.h>
1178 AX_CHECK_SIGN([time_t],
1179 [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1181 #ifdef HAVE_SYS_TYPES_H
1182 #include <sys/types.h>
1184 #ifdef HAVE_SYS_TIME_H
1185 #include <sys/time.h>
1192 if test "$ax_cv_decl_time_t_signed" = no; then
1193 AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1196 AX_CHECK_SIGN([size_t],
1197 [ tor_cv_size_t_signed=yes ],
1198 [ tor_cv_size_t_signed=no ], [
1199 #ifdef HAVE_SYS_TYPES_H
1200 #include <sys/types.h>
1204 if test "$ax_cv_decl_size_t_signed" = yes; then
1205 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1208 AX_CHECK_SIGN([enum always],
1209 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1211 enum always { AAA, BBB, CCC };
1214 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1215 #ifdef HAVE_SYS_SOCKET_H
1216 #include <sys/socket.h>
1220 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1222 AC_CHECK_SIZEOF(cell_t)
1224 # Now make sure that NULL can be represented as zero bytes.
1225 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1226 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1227 [[#include <stdlib.h>
1230 #ifdef HAVE_STDDEF_H
1233 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1234 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1235 [tor_cv_null_is_zero=yes],
1236 [tor_cv_null_is_zero=no],
1237 [tor_cv_null_is_zero=cross])])
1239 if test "$tor_cv_null_is_zero" = cross ; then
1240 # Cross-compiling; let's hope that the target isn't raving mad.
1241 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1244 if test "$tor_cv_null_is_zero" != no; then
1245 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1246 [Define to 1 iff memset(0) sets pointers to NULL])
1249 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1250 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1251 [[#include <stdlib.h>
1254 #ifdef HAVE_STDDEF_H
1257 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1258 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1259 [tor_cv_dbl0_is_zero=yes],
1260 [tor_cv_dbl0_is_zero=no],
1261 [tor_cv_dbl0_is_zero=cross])])
1263 if test "$tor_cv_dbl0_is_zero" = cross ; then
1264 # Cross-compiling; let's hope that the target isn't raving mad.
1265 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1268 if test "$tor_cv_dbl0_is_zero" != no; then
1269 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1270 [Define to 1 iff memset(0) sets doubles to 0.0])
1273 # And what happens when we malloc zero?
1274 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1275 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1276 [[#include <stdlib.h>
1279 #ifdef HAVE_STDDEF_H
1282 int main () { return malloc(0)?0:1; }]])],
1283 [tor_cv_malloc_zero_works=yes],
1284 [tor_cv_malloc_zero_works=no],
1285 [tor_cv_malloc_zero_works=cross])])
1287 if test "$tor_cv_malloc_zero_works" = cross; then
1288 # Cross-compiling; let's hope that the target isn't raving mad.
1289 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1292 if test "$tor_cv_malloc_zero_works" = yes; then
1293 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1294 [Define to 1 iff malloc(0) returns a pointer])
1297 # whether we seem to be in a 2s-complement world.
1298 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1299 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1300 [[int main () { int problem = ((-99) != (~99)+1);
1301 return problem ? 1 : 0; }]])],
1302 [tor_cv_twos_complement=yes],
1303 [tor_cv_twos_complement=no],
1304 [tor_cv_twos_complement=cross])])
1306 if test "$tor_cv_twos_complement" = 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 negative integers are represented with two's complement.])
1311 if test "$tor_cv_twos_complement" != no ; then
1312 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1313 [Define to 1 iff we represent negative integers with two's complement])
1316 # What does shifting a negative value do?
1317 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1318 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1319 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1320 [tor_cv_sign_extend=yes],
1321 [tor_cv_sign_extend=no],
1322 [tor_cv_sign_extend=cross])])
1324 if test "$tor_cv_sign_extend" = cross ; then
1325 # Cross-compiling; let's hope that the target isn't raving mad.
1326 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1329 if test "$tor_cv_sign_extend" != no ; then
1330 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1331 [Define to 1 iff right-shifting a negative value performs sign-extension])
1334 # Whether we should use the dmalloc memory allocation debugging library.
1335 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1336 AC_ARG_WITH(dmalloc,
1337 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1338 [if [[ "$withval" = "yes" ]]; then
1344 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1347 if [[ $dmalloc -eq 1 ]]; then
1348 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1349 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1350 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1351 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1354 AC_ARG_WITH(tcmalloc,
1355 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1356 [ tcmalloc=yes ], [ tcmalloc=no ])
1358 if test x$tcmalloc = xyes ; then
1359 LDFLAGS="-ltcmalloc $LDFLAGS"
1362 using_custom_malloc=no
1363 if test x$enable_openbsd_malloc = xyes ; then
1364 using_custom_malloc=yes
1366 if test x$tcmalloc = xyes ; then
1367 using_custom_malloc=yes
1369 if test $using_custom_malloc = no ; then
1370 AC_CHECK_FUNCS(mallinfo)
1373 # By default, we're going to assume we don't have mlockall()
1374 # bionic and other platforms have various broken mlockall subsystems.
1375 # Some systems don't have a working mlockall, some aren't linkable,
1376 # and some have it but don't declare it.
1377 AC_CHECK_FUNCS(mlockall)
1378 AC_CHECK_DECLS([mlockall], , , [
1379 #ifdef HAVE_SYS_MMAN_H
1380 #include <sys/mman.h>
1383 # Allow user to specify an alternate syslog facility
1384 AC_ARG_WITH(syslog-facility,
1385 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1386 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1387 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1388 AC_SUBST(LOGFACILITY)
1390 # Check if we have getresuid and getresgid
1391 AC_CHECK_FUNCS(getresuid getresgid)
1393 # Check for gethostbyname_r in all its glorious incompatible versions.
1394 # (This logic is based on that in Python's configure.in)
1395 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1396 [Define this if you have any gethostbyname_r()])
1398 AC_CHECK_FUNC(gethostbyname_r, [
1399 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1401 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1402 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1406 struct hostent *h1, *h2;
1408 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1410 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1411 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1412 [Define this if gethostbyname_r takes 6 arguments])
1421 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1423 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1424 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1425 [Define this if gethostbyname_r takes 5 arguments])
1433 struct hostent_data hd;
1434 (void) gethostbyname_r(cp1,h1,&hd);
1436 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1437 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1438 [Define this if gethostbyname_r takes 3 arguments])
1448 AC_CACHE_CHECK([whether the C compiler supports __func__],
1449 tor_cv_have_func_macro,
1450 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1452 int main(int c, char **v) { puts(__func__); }])],
1453 tor_cv_have_func_macro=yes,
1454 tor_cv_have_func_macro=no))
1456 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1457 tor_cv_have_FUNC_macro,
1458 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1460 int main(int c, char **v) { puts(__FUNC__); }])],
1461 tor_cv_have_FUNC_macro=yes,
1462 tor_cv_have_FUNC_macro=no))
1464 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1465 tor_cv_have_FUNCTION_macro,
1466 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1468 int main(int c, char **v) { puts(__FUNCTION__); }])],
1469 tor_cv_have_FUNCTION_macro=yes,
1470 tor_cv_have_FUNCTION_macro=no))
1472 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1473 tor_cv_have_environ_declared,
1474 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1475 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1476 * Without it environ doesn't get declared. */
1478 #ifdef HAVE_UNISTD_H
1482 int main(int c, char **v) { char **t = environ; }])],
1483 tor_cv_have_environ_declared=yes,
1484 tor_cv_have_environ_declared=no))
1486 if test "$tor_cv_have_func_macro" = 'yes'; then
1487 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1490 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1491 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1494 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1495 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1496 [Defined if the compiler supports __FUNCTION__])
1499 if test "$tor_cv_have_environ_declared" = 'yes'; then
1500 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1501 [Defined if we have extern char **environ already declared])
1504 # $prefix stores the value of the --prefix command line option, or
1505 # NONE if the option wasn't set. In the case that it wasn't set, make
1506 # it be the default, so that we can use it to expand directories now.
1507 if test "x$prefix" = "xNONE"; then
1508 prefix=$ac_default_prefix
1511 # and similarly for $exec_prefix
1512 if test "x$exec_prefix" = "xNONE"; then
1516 if test "x$BUILDDIR" = "x"; then
1520 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1521 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1523 if test "x$CONFDIR" = "x"; then
1524 CONFDIR=`eval echo $sysconfdir/tor`
1527 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1528 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1530 BINDIR=`eval echo $bindir`
1532 LOCALSTATEDIR=`eval echo $localstatedir`
1533 AC_SUBST(LOCALSTATEDIR)
1535 if test "$bwin32" = true; then
1536 # Test if the linker supports the --nxcompat and --dynamicbase options
1538 save_LDFLAGS="$LDFLAGS"
1539 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1540 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1541 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1542 [AC_MSG_RESULT([yes])]
1543 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1544 [AC_MSG_RESULT([no])]
1546 LDFLAGS="$save_LDFLAGS"
1549 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1550 # than autoconf's macros like.
1551 if test "$GCC" = yes; then
1552 # Disable GCC's strict aliasing checks. They are an hours-to-debug
1553 # accident waiting to happen.
1554 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1556 # Override optimization level for non-gcc compilers
1558 enable_gcc_warnings=no
1559 enable_gcc_warnings_advisory=no
1562 # OS X Lion started deprecating the system openssl. Let's just disable
1563 # all deprecation warnings on OS X. Also, to potentially make the binary
1564 # a little smaller, let's enable dead_strip.
1568 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1569 LDFLAGS="$LDFLAGS -dead_strip" ;;
1572 # Add some more warnings which we use in development but not in the
1573 # released versions. (Some relevant gcc versions can't handle these.)
1574 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1576 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1577 #if !defined(__GNUC__) || (__GNUC__ < 4)
1579 #endif])], have_gcc4=yes, have_gcc4=no)
1581 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1582 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1584 #endif])], have_gcc42=yes, have_gcc42=no)
1586 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1587 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1589 #endif])], have_gcc43=yes, have_gcc43=no)
1591 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1592 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1594 #endif])], have_gcc46=yes, have_gcc46=no)
1597 save_CFLAGS="$CFLAGS"
1598 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1599 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1600 have_shorten64_flag=no)
1601 CFLAGS="$save_CFLAGS"
1604 *-*-openbsd* | *-*-bitrig*)
1605 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1606 # That's fine, except that the headers don't pass -Wredundant-decls.
1607 # Therefore, let's disable -Wsystem-headers when we're building
1608 # with maximal warnings on OpenBSD.
1609 CFLAGS="$CFLAGS -Wno-system-headers" ;;
1612 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1613 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1614 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1615 CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1616 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1618 if test x$enable_gcc_warnings = xyes; then
1619 CFLAGS="$CFLAGS -Werror"
1622 # Disabled, so we can use mallinfo(): -Waggregate-return
1624 if test x$have_gcc4 = xyes ; then
1625 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1626 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
1629 if test x$have_gcc42 = xyes ; then
1630 # These warnings break gcc 4.0.2 and work on gcc 4.2
1631 # XXXX020 See if any of these work with earlier versions.
1632 CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1634 # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1637 if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1638 # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1639 CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1642 if test x$have_gcc43 = xyes ; then
1643 # These warnings break gcc 4.2 and work on gcc 4.3
1644 # XXXX020 See if any of these work with earlier versions.
1645 CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1648 if test x$have_gcc46 = xyes ; then
1649 # This warning was added in gcc 4.3, but it appears to generate
1650 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
1651 CFLAGS="$CFLAGS -Wlogical-op"
1654 if test x$have_shorten64_flag = xyes ; then
1655 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1660 ##This will break the world on some 64-bit architectures
1661 # CFLAGS="$CFLAGS -Winline"
1664 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1667 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.])
1671 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1676 contrib/dist/suse/tor.sh
1677 contrib/operator-tools/tor.logrotate
1680 contrib/dist/tor.service
1681 src/config/torrc.sample
1682 src/config/torrc.minimal
1683 scripts/maint/checkOptionDocs.pl
1684 scripts/maint/updateVersions.pl
1687 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1688 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1689 for file in $regular_mans ; do
1690 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1691 echo "==================================";
1693 echo "Building Tor has failed since manpages cannot be built.";
1695 echo "You need asciidoc installed to be able to build the manpages.";
1696 echo "To build without manpages, use the --disable-asciidoc argument";
1697 echo "when calling configure.";
1699 echo "==================================";