1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2013, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT([tor],[0.2.6.0-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])
15 if test -f /etc/redhat-release ; then
16 if test -f /usr/kerberos/include ; then
17 CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
21 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
22 # the += operator on it in src/or/Makefile.am
23 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
25 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
26 AC_ARG_ENABLE(buf-freelists,
27 AS_HELP_STRING(--enable-buf-freelists, enable freelists for buffer RAM))
28 AC_ARG_ENABLE(mempools,
29 AS_HELP_STRING(--enable-mempools, enable mempools for relay cells))
30 AC_ARG_ENABLE(openbsd-malloc,
31 AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd. Linux only))
32 AC_ARG_ENABLE(instrument-downloads,
33 AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
34 AC_ARG_ENABLE(static-openssl,
35 AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
36 AC_ARG_ENABLE(static-libevent,
37 AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
38 AC_ARG_ENABLE(static-zlib,
39 AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
40 AC_ARG_ENABLE(static-tor,
41 AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir))
42 AC_ARG_ENABLE(curve25519,
43 AS_HELP_STRING(--disable-curve25519, Build Tor with no curve25519 elliptic-curve crypto support))
44 AC_ARG_ENABLE(unittests,
45 AS_HELP_STRING(--disable-unittests, [Don't build unit tests for Tor. Risky!]))
46 AC_ARG_ENABLE(coverage,
47 AS_HELP_STRING(--enable-coverage, [Enable coverage support in the unit-test build]))
49 AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
50 AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
52 if test "$enable_static_tor" = "yes"; then
53 enable_static_libevent="yes";
54 enable_static_openssl="yes";
55 enable_static_zlib="yes";
56 CFLAGS="$CFLAGS -static"
59 if test x$enable_buf_freelists = xyes; then
60 AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
61 [Defined if we try to use freelists for buffer RAM chunks])
64 AM_CONDITIONAL(USE_MEMPOOLS, test x$enable_mempools = xyes)
65 if test x$enable_mempools = xyes; then
66 AC_DEFINE(ENABLE_MEMPOOLS, 1,
67 [Defined if we try to use mempools for cells being relayed])
70 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
71 if test x$enable_instrument_downloads = xyes; then
72 AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
73 [Defined if we want to keep track of how much of each kind of resource we download.])
76 AC_ARG_ENABLE(transparent,
77 AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
78 [case "${enableval}" in
79 yes) transparent=true ;;
80 no) transparent=false ;;
81 *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
82 esac], [transparent=true])
84 AC_ARG_ENABLE(asciidoc,
85 AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
86 [case "${enableval}" in
89 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
90 esac], [asciidoc=true])
92 # By default, we're not ready to ship a NAT-PMP aware Tor
93 AC_ARG_ENABLE(nat-pmp,
94 AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
95 [case "${enableval}" in
98 * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
99 esac], [natpmp=false])
101 # By default, we're not ready to ship a UPnP aware Tor
103 AS_HELP_STRING(--enable-upnp, enable UPnP support),
104 [case "${enableval}" in
107 * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
112 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
116 AC_ARG_ENABLE(gcc-warnings,
117 AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
118 AC_ARG_ENABLE(gcc-warnings-advisory,
119 AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
121 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
122 AC_ARG_ENABLE(gcc-hardening,
123 AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
125 AC_ARG_ENABLE(expensive-hardening,
126 AS_HELP_STRING(--enable-expensive-hardening, enable more expensive compiler hardening; makes Tor slower))
128 dnl Linker hardening options
129 dnl Currently these options are ELF specific - you can't use this with MacOSX
130 AC_ARG_ENABLE(linker-hardening,
131 AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
133 AC_ARG_ENABLE(local-appdata,
134 AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
135 if test "$enable_local_appdata" = "yes"; then
136 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
137 [Defined if we default to host local appdata paths on Windows])
141 AC_ARG_ENABLE(tor2web-mode,
142 AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
143 [if test x$enableval = xyes; then
144 CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
147 AC_ARG_ENABLE(bufferevents,
148 AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
150 AC_ARG_ENABLE(tool-name-check,
151 AS_HELP_STRING(--disable-tool-name-check, check for sanely named toolchain when cross-compiling))
153 AC_ARG_ENABLE(seccomp,
154 AS_HELP_STRING(--disable-seccomp, do not attempt to use libseccomp))
156 AC_ARG_ENABLE(libscrypt,
157 AS_HELP_STRING(--disable-libscrypt, do not attempt to use libscrypt))
159 dnl check for the correct "ar" when cross-compiling
160 AN_MAKEVAR([AR], [AC_PROG_AR])
161 AN_PROGRAM([ar], [AC_PROG_AR])
162 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
165 dnl Check whether the above macro has settled for a simply named tool even
166 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
167 dnl because that will find any cc on the system, not only the cross-compiler,
168 dnl and then verify that a binary built with this compiler runs on the
169 dnl build system. It will then come to the false conclusion that we're not
171 if test x$enable_tool_name_check != xno; then
172 if test x$ac_tool_warned = xyes; then
173 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.)])
174 elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
175 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.)])
184 dnl autoconf 2.59 appears not to support AC_PROG_SED
185 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
187 dnl check for asciidoc and a2x
188 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
189 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
191 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
193 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
194 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
195 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
200 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
201 if test "x$PYTHON" = "x"; then
202 AC_MSG_WARN([Python unavailable; some tests will not be run.])
204 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
206 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
207 AC_C_FLEXIBLE_ARRAY_MEMBER
209 dnl Maybe we've got an old autoconf...
210 AC_CACHE_CHECK([for flexible array members],
214 struct abc { int a; char b[]; };
216 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
219 [tor_cv_c_flexarray=yes],
220 [tor_cv_c_flexarray=no])])
221 if test $tor_cv_flexarray = yes ; then
222 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
224 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
228 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
231 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
232 [tor_cv_c_c99_decl=yes],
233 [tor_cv_c_c99_decl=no] )])
234 if test "$tor_cv_c_c99_decl" != "yes"; then
235 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
238 AC_CACHE_CHECK([for working C99 designated initializers],
239 tor_cv_c_c99_designated_init,
241 [AC_LANG_PROGRAM([struct s { int a; int b; };],
242 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
243 [tor_cv_c_c99_designated_init=yes],
244 [tor_cv_c_c99_designated_init=no] )])
246 if test "$tor_cv_c_c99_designated_init" != "yes"; then
247 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
250 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
251 AC_PATH_PROG([OPENSSL], [openssl], none)
254 AC_ARG_WITH(tor-user,
255 [ --with-tor-user=NAME Specify username for tor daemon ],
263 AC_ARG_WITH(tor-group,
264 [ --with-tor-group=NAME Specify group name for tor daemon ],
272 dnl If _WIN32 is defined and non-zero, we are building for win32
273 AC_MSG_CHECKING([for win32])
274 AC_RUN_IFELSE([AC_LANG_SOURCE([
275 int main(int c, char **v) {
286 bwin32=true; AC_MSG_RESULT([yes]),
287 bwin32=false; AC_MSG_RESULT([no]),
288 bwin32=cross; AC_MSG_RESULT([cross])
291 if test "$bwin32" = cross; then
292 AC_MSG_CHECKING([for win32 (cross)])
293 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
295 int main(int c, char **v) {return 0;}
298 int main(int c, char **v) {return x(y);}
301 bwin32=true; AC_MSG_RESULT([yes]),
302 bwin32=false; AC_MSG_RESULT([no]))
305 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
307 dnl Enable C99 when compiling with MIPSpro
308 AC_MSG_CHECKING([for MIPSpro compiler])
309 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
310 #if (defined(__sgi) && defined(_COMPILER_VERSION))
315 bmipspro=false; AC_MSG_RESULT(no),
316 bmipspro=true; AC_MSG_RESULT(yes))
318 if test "$bmipspro" = true; then
319 CFLAGS="$CFLAGS -c99"
324 AC_SEARCH_LIBS(socket, [socket network])
325 AC_SEARCH_LIBS(gethostbyname, [nsl])
326 AC_SEARCH_LIBS(dlopen, [dl])
327 AC_SEARCH_LIBS(inet_aton, [resolv])
329 AC_SEARCH_LIBS([clock_gettime], [rt])
330 if test "$LIBS" != "$saved_LIBS"; then
331 # Looks like we need -lrt for clock_gettime().
335 AC_SEARCH_LIBS(pthread_create, [pthread])
336 AC_SEARCH_LIBS(pthread_detach, [pthread])
338 dnl -------------------------------------------------------------------
339 dnl Check for functions before libevent, since libevent-1.2 apparently
340 dnl exports strlcpy without defining it in a header.
346 backtrace_symbols_fd \
379 if test "$bwin32" != true; then
380 AC_CHECK_HEADERS(pthread.h)
381 AC_CHECK_FUNCS(pthread_create)
384 dnl ------------------------------------------------------
385 dnl Where do you live, libevent? And how do we call you?
387 if test "$bwin32" = true; then
388 TOR_LIB_WS32=-lws2_32
389 TOR_LIB_IPHLPAPI=-liphlpapi
390 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
391 # think it's actually necessary.
397 AC_SUBST(TOR_LIB_WS32)
398 AC_SUBST(TOR_LIB_GDI)
399 AC_SUBST(TOR_LIB_IPHLPAPI)
401 dnl We need to do this before we try our disgusting hack below.
402 AC_CHECK_HEADERS([sys/types.h])
404 dnl This is a disgusting hack so we safely include older libevent headers.
405 AC_CHECK_TYPE(u_int64_t, unsigned long long)
406 AC_CHECK_TYPE(u_int32_t, unsigned long)
407 AC_CHECK_TYPE(u_int16_t, unsigned short)
408 AC_CHECK_TYPE(u_int8_t, unsigned char)
410 tor_libevent_pkg_redhat="libevent"
411 tor_libevent_pkg_debian="libevent-dev"
412 tor_libevent_devpkg_redhat="libevent-devel"
413 tor_libevent_devpkg_debian="libevent-dev"
415 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
416 dnl linking for static builds.
417 STATIC_LIBEVENT_FLAGS=""
418 if test "$enable_static_libevent" = "yes"; then
419 if test "$have_rt" = yes; then
420 STATIC_LIBEVENT_FLAGS=" -lrt "
424 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
426 #include <winsock2.h>
429 #include <sys/time.h>
430 #include <sys/types.h>
431 #include <event.h>], [
433 #include <winsock2.h>
435 void exit(int); void *event_init(void);],
438 {WSADATA d; WSAStartup(0x101,&d); }
440 event_init(); exit(0);
441 ], [--with-libevent-dir], [/opt/libevent])
443 dnl Now check for particular libevent functions.
445 save_LDFLAGS="$LDFLAGS"
446 save_CPPFLAGS="$CPPFLAGS"
447 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
448 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
449 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
450 AC_CHECK_FUNCS([event_get_version \
451 event_get_version_number \
453 event_set_log_callback \
454 evutil_secure_rng_set_urandom_device_file \
455 evutil_secure_rng_init \
456 event_base_loopexit])
457 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
461 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
464 LDFLAGS="$save_LDFLAGS"
465 CPPFLAGS="$save_CPPFLAGS"
468 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
470 if test "$enable_static_libevent" = "yes"; then
471 if test "$tor_cv_library_libevent_dir" = "(system)"; then
472 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
474 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
477 TOR_LIBEVENT_LIBS="-levent"
480 dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
481 dnl we can do much better.
482 if test "$enable_bufferevents" = "yes" ; then
483 if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
484 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.])
487 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
489 # Check for the right version. First see if version detection works.
490 AC_MSG_CHECKING([whether we can detect the Libevent version])
491 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
492 #include <event2/event.h>
493 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
499 ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
500 [event_version_number_works=no; AC_MSG_RESULT([no])])
501 if test "$event_version_number_works" != 'yes'; then
502 AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
504 AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
505 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
506 #include <event2/event.h>
507 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
513 ])], [ AC_MSG_RESULT([yes]) ],
514 [ AC_MSG_RESULT([no])
515 AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
521 LDFLAGS="$save_LDFLAGS"
522 CPPFLAGS="$save_CPPFLAGS"
524 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
525 if test "$enable_bufferevents" = "yes"; then
526 AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
527 if test "$enable_static_libevent" = "yes"; then
528 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
530 TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
533 AC_SUBST(TOR_LIBEVENT_LIBS)
535 dnl ------------------------------------------------------
536 dnl Where do you live, libm?
538 dnl On some platforms (Haiku/BeOS) the math library is
539 dnl part of libroot. In which case don't link against lm
542 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
543 if test "$ac_cv_search_pow" != "none required"; then
544 TOR_LIB_MATH="$ac_cv_search_pow"
547 AC_SUBST(TOR_LIB_MATH)
549 dnl ------------------------------------------------------
550 dnl Where do you live, openssl? And how do we call you?
552 tor_openssl_pkg_redhat="openssl"
553 tor_openssl_pkg_debian="libssl-dev"
554 tor_openssl_devpkg_redhat="openssl-devel"
555 tor_openssl_devpkg_debian="libssl-dev"
557 ALT_openssl_WITHVAL=""
559 [ --with-ssl-dir=PATH Obsolete alias for --with-openssl-dir ],
561 if test "x$withval" != xno && test "x$withval" != "x" ; then
562 ALT_openssl_WITHVAL="$withval"
566 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
567 [#include <openssl/rand.h>],
568 [void RAND_add(const void *buf, int num, double entropy);],
569 [RAND_add((void*)0,0,0); exit(0);], [],
570 [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
572 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
574 if test "$enable_static_openssl" = "yes"; then
575 if test "$tor_cv_library_openssl_dir" = "(system)"; then
576 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
578 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
581 TOR_OPENSSL_LIBS="-lssl -lcrypto"
583 AC_SUBST(TOR_OPENSSL_LIBS)
585 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
586 [#include <openssl/ssl.h>
589 dnl ------------------------------------------------------
590 dnl Where do you live, zlib? And how do we call you?
592 tor_zlib_pkg_redhat="zlib"
593 tor_zlib_pkg_debian="zlib1g"
594 tor_zlib_devpkg_redhat="zlib-devel"
595 tor_zlib_devpkg_debian="zlib1g-dev"
597 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
599 [const char * zlibVersion(void);],
600 [zlibVersion(); exit(0);], [--with-zlib-dir],
603 if test "$enable_static_zlib" = "yes"; then
604 if test "$tor_cv_library_zlib_dir" = "(system)"; then
605 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
606 using --enable-static-zlib")
608 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
613 AC_SUBST(TOR_ZLIB_LIBS)
615 dnl ---------------------------------------------------------------------
616 dnl Now that we know about our major libraries, we can check for compiler
617 dnl and linker hardening options. We need to do this with the libraries known,
618 dnl since sometimes the linker will like an option but not be willing to
619 dnl use it with a build of a library.
621 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
622 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
624 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
625 #if !defined(__clang__)
627 #endif])], have_clang=yes, have_clang=no)
629 if test x$enable_gcc_hardening != xno; then
630 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
631 if test x$have_clang = xyes; then
632 TOR_CHECK_CFLAGS(-Qunused-arguments)
634 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
635 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
636 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
637 m4_ifdef([AS_VAR_IF],[
638 AS_VAR_IF(can_compile, [yes],
639 AS_VAR_IF(can_link, [yes],
641 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.)]))
643 AS_VAR_POPDEF([can_link])
644 AS_VAR_POPDEF([can_compile])
645 TOR_CHECK_CFLAGS(-Wstack-protector)
646 TOR_CHECK_CFLAGS(-fwrapv)
647 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
648 if test "$bwin32" = "false"; then
649 TOR_CHECK_CFLAGS(-fPIE)
650 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
654 if test x$enable_expensive_hardening = xyes ; then
655 TOR_CHECK_CFLAGS([-fsanitize=address])
656 TOR_CHECK_CFLAGS([-fsanitize=undefined])
657 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
660 if test x$enable_linker_hardening != xno; then
661 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
664 # For backtrace support
665 TOR_CHECK_LDFLAGS(-rdynamic)
667 dnl ------------------------------------------------------
668 dnl Now see if we have a -fomit-frame-pointer compiler option.
670 saved_CFLAGS="$CFLAGS"
671 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
672 F_OMIT_FRAME_POINTER=''
673 if test "$saved_CFLAGS" != "$CFLAGS"; then
674 if test x$enable_expensive_hardening != xyes ; then
675 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
678 CFLAGS="$saved_CFLAGS"
679 AC_SUBST(F_OMIT_FRAME_POINTER)
681 dnl ------------------------------------------------------
682 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
683 dnl for us, as GCC 4.6 and later do at many optimization levels), then
684 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
686 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
688 dnl ------------------------------------------------------
689 dnl Where do you live, libnatpmp? And how do we call you?
690 dnl There are no packages for Debian or Redhat as of this patch
692 if test "$natpmp" = "true"; then
693 AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
694 TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
695 [#include <natpmp.h>],
699 #include <natpmp.h>],
702 natpmpresp_t response;
703 r = initnatpmp(&natpmp, 0, 0);],
704 [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
706 [--with-libnatpmp-dir],
711 dnl ------------------------------------------------------
712 dnl Where do you live, libminiupnpc? And how do we call you?
713 dnl There are no packages for Debian or Redhat as of this patch
715 if test "$upnp" = "true"; then
716 AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
718 dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
719 dnl to see if we have miniupnpc-1.5 or -1.6
720 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
721 [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
723 if test "$miniupnpc15" = "true" ; then
724 AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
725 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
726 [#include <miniupnpc/miniwget.h>
727 #include <miniupnpc/miniupnpc.h>
728 #include <miniupnpc/upnpcommands.h>],
729 [void upnpDiscover(int delay, const char * multicastif,
730 const char * minissdpdsock, int sameport);],
731 [upnpDiscover(1, 0, 0, 0); exit(0);],
732 [--with-libminiupnpc-dir],
735 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
736 [#include <miniupnpc/miniwget.h>
737 #include <miniupnpc/miniupnpc.h>
738 #include <miniupnpc/upnpcommands.h>],
739 [void upnpDiscover(int delay, const char * multicastif,
740 const char * minissdpdsock, int sameport, int ipv6, int * error);],
741 [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
742 [--with-libminiupnpc-dir],
747 dnl ============================================================
748 dnl Check for libseccomp
750 if test "x$enable_seccomp" != "xno"; then
751 AC_CHECK_HEADERS([seccomp.h])
752 AC_SEARCH_LIBS(seccomp_init, [seccomp])
755 dnl ============================================================
756 dnl Check for libscrypt
758 if test "x$enable_libscrypt" != "xno"; then
759 AC_CHECK_HEADERS([libscrypt.h])
760 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
763 dnl ============================================================
764 dnl We need an implementation of curve25519.
766 dnl set these defaults.
768 build_curve25519_donna=no
769 build_curve25519_donna_c64=no
770 use_curve25519_donna=no
771 use_curve25519_nacl=no
774 if test x$enable_curve25519 != xno; then
776 dnl The best choice is using curve25519-donna-c64, but that requires
778 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
779 tor_cv_can_use_curve25519_donna_c64,
781 [AC_LANG_PROGRAM([dnl
783 typedef unsigned uint128_t __attribute__((mode(TI)));
784 int func(uint64_t a, uint64_t b) {
785 uint128_t c = ((uint128_t)a) * b;
786 int ok = ((uint64_t)(c>>96)) == 522859 &&
787 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
788 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
789 (((uint64_t)(c))&0xffffffffL) == 0;
793 int ok = func( ((uint64_t)2000000000) * 1000000000,
794 ((uint64_t)1234567890) << 24);
797 [tor_cv_can_use_curve25519_donna_c64=yes],
798 [tor_cv_can_use_curve25519_donna_c64=no],
800 [AC_LANG_PROGRAM([dnl
802 typedef unsigned uint128_t __attribute__((mode(TI)));
803 int func(uint64_t a, uint64_t b) {
804 uint128_t c = ((uint128_t)a) * b;
805 int ok = ((uint64_t)(c>>96)) == 522859 &&
806 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
807 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
808 (((uint64_t)(c))&0xffffffffL) == 0;
812 int ok = func( ((uint64_t)2000000000) * 1000000000,
813 ((uint64_t)1234567890) << 24);
816 [tor_cv_can_use_curve25519_donna_c64=cross],
817 [tor_cv_can_use_curve25519_donna_c64=no])])])
819 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
820 nacl/crypto_scalarmult_curve25519.h])
822 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
823 tor_cv_can_use_curve25519_nacl,
824 [tor_saved_LIBS="$LIBS"
827 [AC_LANG_PROGRAM([dnl
828 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
829 #include <crypto_scalarmult_curve25519.h>
830 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
831 #include <nacl/crypto_scalarmult_curve25519.h>
833 #ifdef crypto_scalarmult_curve25519_ref_BYTES
834 #error Hey, this is the reference implementation! That's not fast.
837 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
838 ])], [tor_cv_can_use_curve25519_nacl=yes],
839 [tor_cv_can_use_curve25519_nacl=no])
840 LIBS="$tor_saved_LIBS" ])
842 dnl Okay, now we need to figure out which one to actually use. Fall back
843 dnl to curve25519-donna.c
845 if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
846 build_curve25519_donna_c64=yes
847 use_curve25519_donna=yes
848 elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
849 use_curve25519_nacl=yes
850 CURVE25519_LIBS=-lnacl
852 build_curve25519_donna=yes
853 use_curve25519_donna=yes
855 have_a_curve25519=yes
858 if test x$have_a_curve25519 = xyes; then
859 AC_DEFINE(CURVE25519_ENABLED, 1,
860 [Defined if we have a curve25519 implementation])
862 if test x$use_curve25519_donna = xyes; then
863 AC_DEFINE(USE_CURVE25519_DONNA, 1,
864 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
866 if test x$use_curve25519_nacl = xyes; then
867 AC_DEFINE(USE_CURVE25519_NACL, 1,
868 [Defined if we should use a curve25519 from nacl])
870 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
871 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
872 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
873 AC_SUBST(CURVE25519_LIBS)
875 dnl Make sure to enable support for large off_t if available.
890 , , 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.))
892 dnl These headers are not essential
932 AC_CHECK_HEADERS(sys/param.h)
934 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
935 [#ifdef HAVE_SYS_TYPES_H
936 #include <sys/types.h>
938 #ifdef HAVE_SYS_SOCKET_H
939 #include <sys/socket.h>
941 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
942 [#ifdef HAVE_SYS_TYPES_H
943 #include <sys/types.h>
945 #ifdef HAVE_SYS_SOCKET_H
946 #include <sys/socket.h>
951 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
952 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
953 [#ifdef HAVE_SYS_TYPES_H
954 #include <sys/types.h>
956 #ifdef HAVE_SYS_SOCKET_H
957 #include <sys/socket.h>
962 #ifdef HAVE_LINUX_TYPES_H
963 #include <linux/types.h>
965 #ifdef HAVE_NETINET_IN6_H
966 #include <netinet/in6.h>
968 #ifdef HAVE_NETINET_IN_H
969 #include <netinet/in.h>
972 if test x$transparent = xtrue ; then
974 if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
977 if test x$linux_netfilter_ipv4 = x1 ; then
980 if test x$transparent_ok = x1 ; then
981 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
983 *-*-openbsd* | *-*-bitrig*)
984 AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
987 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
991 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
992 [#ifdef HAVE_SYS_TYPES_H
993 #include <sys/types.h>
995 #ifdef HAVE_SYS_TIME_H
996 #include <sys/time.h>
999 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1002 AC_CHECK_SIZEOF(int8_t)
1003 AC_CHECK_SIZEOF(int16_t)
1004 AC_CHECK_SIZEOF(int32_t)
1005 AC_CHECK_SIZEOF(int64_t)
1006 AC_CHECK_SIZEOF(uint8_t)
1007 AC_CHECK_SIZEOF(uint16_t)
1008 AC_CHECK_SIZEOF(uint32_t)
1009 AC_CHECK_SIZEOF(uint64_t)
1010 AC_CHECK_SIZEOF(intptr_t)
1011 AC_CHECK_SIZEOF(uintptr_t)
1013 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1015 AC_CHECK_SIZEOF(char)
1016 AC_CHECK_SIZEOF(short)
1017 AC_CHECK_SIZEOF(int)
1018 AC_CHECK_SIZEOF(long)
1019 AC_CHECK_SIZEOF(long long)
1020 AC_CHECK_SIZEOF(__int64)
1021 AC_CHECK_SIZEOF(void *)
1022 AC_CHECK_SIZEOF(time_t)
1023 AC_CHECK_SIZEOF(size_t)
1024 AC_CHECK_SIZEOF(pid_t)
1026 AC_CHECK_TYPES([uint, u_char, ssize_t])
1028 AC_PC_FROM_UCONTEXT([/bin/true])
1030 dnl used to include sockaddr_storage, but everybody has that.
1031 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1032 [#ifdef HAVE_SYS_TYPES_H
1033 #include <sys/types.h>
1035 #ifdef HAVE_NETINET_IN_H
1036 #include <netinet/in.h>
1038 #ifdef HAVE_NETINET_IN6_H
1039 #include <netinet/in6.h>
1041 #ifdef HAVE_SYS_SOCKET_H
1042 #include <sys/socket.h>
1045 #define _WIN32_WINNT 0x0501
1046 #define WIN32_LEAN_AND_MEAN
1047 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1048 #include <winsock.h>
1050 #include <winsock2.h>
1051 #include <ws2tcpip.h>
1055 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1056 [#ifdef HAVE_SYS_TYPES_H
1057 #include <sys/types.h>
1059 #ifdef HAVE_NETINET_IN_H
1060 #include <netinet/in.h>
1062 #ifdef HAVE_NETINET_IN6_H
1063 #include <netinet/in6.h>
1065 #ifdef HAVE_SYS_SOCKET_H
1066 #include <sys/socket.h>
1069 #define _WIN32_WINNT 0x0501
1070 #define WIN32_LEAN_AND_MEAN
1071 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1072 #include <winsock.h>
1074 #include <winsock2.h>
1075 #include <ws2tcpip.h>
1080 AC_CHECK_TYPES([rlim_t], , ,
1081 [#ifdef HAVE_SYS_TYPES_H
1082 #include <sys/types.h>
1084 #ifdef HAVE_SYS_TIME_H
1085 #include <sys/time.h>
1087 #ifdef HAVE_SYS_RESOURCE_H
1088 #include <sys/resource.h>
1092 AX_CHECK_SIGN([time_t],
1093 [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1095 #ifdef HAVE_SYS_TYPES_H
1096 #include <sys/types.h>
1098 #ifdef HAVE_SYS_TIME_H
1099 #include <sys/time.h>
1106 if test "$ax_cv_decl_time_t_signed" = no; then
1107 AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1110 AX_CHECK_SIGN([size_t],
1111 [ tor_cv_size_t_signed=yes ],
1112 [ tor_cv_size_t_signed=no ], [
1113 #ifdef HAVE_SYS_TYPES_H
1114 #include <sys/types.h>
1118 if test "$ax_cv_decl_size_t_signed" = yes; then
1119 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1122 AX_CHECK_SIGN([enum always],
1123 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1125 enum always { AAA, BBB, CCC };
1128 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1129 #ifdef HAVE_SYS_SOCKET_H
1130 #include <sys/socket.h>
1134 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1136 AC_CHECK_SIZEOF(cell_t)
1138 # Now make sure that NULL can be represented as zero bytes.
1139 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1140 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1141 [[#include <stdlib.h>
1144 #ifdef HAVE_STDDEF_H
1147 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1148 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1149 [tor_cv_null_is_zero=yes],
1150 [tor_cv_null_is_zero=no],
1151 [tor_cv_null_is_zero=cross])])
1153 if test "$tor_cv_null_is_zero" = cross ; then
1154 # Cross-compiling; let's hope that the target isn't raving mad.
1155 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1158 if test "$tor_cv_null_is_zero" != no; then
1159 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1160 [Define to 1 iff memset(0) sets pointers to NULL])
1163 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1164 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1165 [[#include <stdlib.h>
1168 #ifdef HAVE_STDDEF_H
1171 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1172 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1173 [tor_cv_dbl0_is_zero=yes],
1174 [tor_cv_dbl0_is_zero=no],
1175 [tor_cv_dbl0_is_zero=cross])])
1177 if test "$tor_cv_dbl0_is_zero" = cross ; then
1178 # Cross-compiling; let's hope that the target isn't raving mad.
1179 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1182 if test "$tor_cv_dbl0_is_zero" != no; then
1183 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1184 [Define to 1 iff memset(0) sets doubles to 0.0])
1187 # And what happens when we malloc zero?
1188 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1189 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1190 [[#include <stdlib.h>
1193 #ifdef HAVE_STDDEF_H
1196 int main () { return malloc(0)?0:1; }]])],
1197 [tor_cv_malloc_zero_works=yes],
1198 [tor_cv_malloc_zero_works=no],
1199 [tor_cv_malloc_zero_works=cross])])
1201 if test "$tor_cv_malloc_zero_works" = cross; then
1202 # Cross-compiling; let's hope that the target isn't raving mad.
1203 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1206 if test "$tor_cv_malloc_zero_works" = yes; then
1207 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1208 [Define to 1 iff malloc(0) returns a pointer])
1211 # whether we seem to be in a 2s-complement world.
1212 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1213 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1214 [[int main () { int problem = ((-99) != (~99)+1);
1215 return problem ? 1 : 0; }]])],
1216 [tor_cv_twos_complement=yes],
1217 [tor_cv_twos_complement=no],
1218 [tor_cv_twos_complement=cross])])
1220 if test "$tor_cv_twos_complement" = cross ; then
1221 # Cross-compiling; let's hope that the target isn't raving mad.
1222 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1225 if test "$tor_cv_twos_complement" != no ; then
1226 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1227 [Define to 1 iff we represent negative integers with two's complement])
1230 # What does shifting a negative value do?
1231 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1232 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1233 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1234 [tor_cv_sign_extend=yes],
1235 [tor_cv_sign_extend=no],
1236 [tor_cv_sign_extend=cross])])
1238 if test "$tor_cv_sign_extend" = cross ; then
1239 # Cross-compiling; let's hope that the target isn't raving mad.
1240 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1243 if test "$tor_cv_sign_extend" != no ; then
1244 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1245 [Define to 1 iff right-shifting a negative value performs sign-extension])
1248 # Whether we should use the dmalloc memory allocation debugging library.
1249 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1250 AC_ARG_WITH(dmalloc,
1251 [ --with-dmalloc Use debug memory allocation library. ],
1252 [if [[ "$withval" = "yes" ]]; then
1258 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1261 if [[ $dmalloc -eq 1 ]]; then
1262 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1263 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1264 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1265 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1268 AC_ARG_WITH(tcmalloc,
1269 [ --with-tcmalloc Use tcmalloc memory allocation library. ],
1270 [ tcmalloc=yes ], [ tcmalloc=no ])
1272 if test x$tcmalloc = xyes ; then
1273 LDFLAGS="-ltcmalloc $LDFLAGS"
1276 using_custom_malloc=no
1277 if test x$enable_openbsd_malloc = xyes ; then
1278 using_custom_malloc=yes
1280 if test x$tcmalloc = xyes ; then
1281 using_custom_malloc=yes
1283 if test $using_custom_malloc = no ; then
1284 AC_CHECK_FUNCS(mallinfo)
1287 # By default, we're going to assume we don't have mlockall()
1288 # bionic and other platforms have various broken mlockall subsystems.
1289 # Some systems don't have a working mlockall, some aren't linkable,
1290 # and some have it but don't declare it.
1291 AC_CHECK_FUNCS(mlockall)
1292 AC_CHECK_DECLS([mlockall], , , [
1293 #ifdef HAVE_SYS_MMAN_H
1294 #include <sys/mman.h>
1297 # Allow user to specify an alternate syslog facility
1298 AC_ARG_WITH(syslog-facility,
1299 [ --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1300 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1301 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1302 AC_SUBST(LOGFACILITY)
1304 # Check if we have getresuid and getresgid
1305 AC_CHECK_FUNCS(getresuid getresgid)
1307 # Check for gethostbyname_r in all its glorious incompatible versions.
1308 # (This logic is based on that in Python's configure.in)
1309 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1310 [Define this if you have any gethostbyname_r()])
1312 AC_CHECK_FUNC(gethostbyname_r, [
1313 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1315 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1316 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1320 struct hostent *h1, *h2;
1322 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1324 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1325 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1326 [Define this if gethostbyname_r takes 6 arguments])
1335 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1337 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1338 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1339 [Define this if gethostbyname_r takes 5 arguments])
1347 struct hostent_data hd;
1348 (void) gethostbyname_r(cp1,h1,&hd);
1350 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1351 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1352 [Define this if gethostbyname_r takes 3 arguments])
1362 AC_CACHE_CHECK([whether the C compiler supports __func__],
1363 tor_cv_have_func_macro,
1364 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1366 int main(int c, char **v) { puts(__func__); }])],
1367 tor_cv_have_func_macro=yes,
1368 tor_cv_have_func_macro=no))
1370 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1371 tor_cv_have_FUNC_macro,
1372 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1374 int main(int c, char **v) { puts(__FUNC__); }])],
1375 tor_cv_have_FUNC_macro=yes,
1376 tor_cv_have_FUNC_macro=no))
1378 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1379 tor_cv_have_FUNCTION_macro,
1380 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1382 int main(int c, char **v) { puts(__FUNCTION__); }])],
1383 tor_cv_have_FUNCTION_macro=yes,
1384 tor_cv_have_FUNCTION_macro=no))
1386 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1387 tor_cv_have_environ_declared,
1388 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1389 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1390 * Without it environ doesn't get declared. */
1392 #ifdef HAVE_UNISTD_H
1396 int main(int c, char **v) { char **t = environ; }])],
1397 tor_cv_have_environ_declared=yes,
1398 tor_cv_have_environ_declared=no))
1400 if test "$tor_cv_have_func_macro" = 'yes'; then
1401 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1404 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1405 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1408 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1409 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1410 [Defined if the compiler supports __FUNCTION__])
1413 if test "$tor_cv_have_environ_declared" = 'yes'; then
1414 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1415 [Defined if we have extern char **environ already declared])
1418 # $prefix stores the value of the --prefix command line option, or
1419 # NONE if the option wasn't set. In the case that it wasn't set, make
1420 # it be the default, so that we can use it to expand directories now.
1421 if test "x$prefix" = "xNONE"; then
1422 prefix=$ac_default_prefix
1425 # and similarly for $exec_prefix
1426 if test "x$exec_prefix" = "xNONE"; then
1430 if test "x$BUILDDIR" = "x"; then
1434 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1435 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1437 if test "x$CONFDIR" = "x"; then
1438 CONFDIR=`eval echo $sysconfdir/tor`
1441 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1442 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1444 BINDIR=`eval echo $bindir`
1446 LOCALSTATEDIR=`eval echo $localstatedir`
1447 AC_SUBST(LOCALSTATEDIR)
1449 if test "$bwin32" = true; then
1450 # Test if the linker supports the --nxcompat and --dynamicbase options
1452 save_LDFLAGS="$LDFLAGS"
1453 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1454 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1455 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1456 [AC_MSG_RESULT([yes])]
1457 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1458 [AC_MSG_RESULT([no])]
1460 LDFLAGS="$save_LDFLAGS"
1463 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1464 # than autoconf's macros like.
1465 if test "$GCC" = yes; then
1466 # Disable GCC's strict aliasing checks. They are an hours-to-debug
1467 # accident waiting to happen.
1468 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1470 # Autoconf sets -g -O2 by default. Override optimization level
1471 # for non-gcc compilers
1473 enable_gcc_warnings=no
1474 enable_gcc_warnings_advisory=no
1477 # OS X Lion started deprecating the system openssl. Let's just disable
1478 # all deprecation warnings on OS X. Also, to potentially make the binary
1479 # a little smaller, let's enable dead_strip.
1483 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1484 LDFLAGS="$LDFLAGS -dead_strip" ;;
1487 # Add some more warnings which we use in development but not in the
1488 # released versions. (Some relevant gcc versions can't handle these.)
1489 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1491 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1492 #if !defined(__GNUC__) || (__GNUC__ < 4)
1494 #endif])], have_gcc4=yes, have_gcc4=no)
1496 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1497 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1499 #endif])], have_gcc42=yes, have_gcc42=no)
1501 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1502 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1504 #endif])], have_gcc43=yes, have_gcc43=no)
1506 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1507 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1509 #endif])], have_gcc46=yes, have_gcc46=no)
1512 save_CFLAGS="$CFLAGS"
1513 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1514 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1515 have_shorten64_flag=no)
1516 CFLAGS="$save_CFLAGS"
1519 *-*-openbsd* | *-*-bitrig*)
1520 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1521 # That's fine, except that the headers don't pass -Wredundant-decls.
1522 # Therefore, let's disable -Wsystem-headers when we're building
1523 # with maximal warnings on OpenBSD.
1524 CFLAGS="$CFLAGS -Wno-system-headers" ;;
1527 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1528 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1529 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1530 CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1531 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1533 if test x$enable_gcc_warnings = xyes; then
1534 CFLAGS="$CFLAGS -Werror"
1537 # Disabled, so we can use mallinfo(): -Waggregate-return
1539 if test x$have_gcc4 = xyes ; then
1540 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1541 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
1544 if test x$have_gcc42 = xyes ; then
1545 # These warnings break gcc 4.0.2 and work on gcc 4.2
1546 # XXXX020 See if any of these work with earlier versions.
1547 CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1549 # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1552 if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1553 # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1554 CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1557 if test x$have_gcc43 = xyes ; then
1558 # These warnings break gcc 4.2 and work on gcc 4.3
1559 # XXXX020 See if any of these work with earlier versions.
1560 CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1563 if test x$have_gcc46 = xyes ; then
1564 # This warning was added in gcc 4.3, but it appears to generate
1565 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
1566 CFLAGS="$CFLAGS -Wlogical-op"
1569 if test x$have_shorten64_flag = xyes ; then
1570 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1575 ##This will break the world on some 64-bit architectures
1576 # CFLAGS="$CFLAGS -Winline"
1579 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1582 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.])
1586 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1591 contrib/dist/suse/tor.sh
1592 contrib/operator-tools/tor.logrotate
1595 contrib/dist/tor.service
1596 src/config/torrc.sample
1597 src/config/torrc.minimal
1600 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1601 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1602 for file in $regular_mans ; do
1603 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1604 echo "==================================";
1606 echo "Building Tor has failed since manpages cannot be built.";
1608 echo "You need asciidoc installed to be able to build the manpages.";
1609 echo "To build without manpages, use the --disable-asciidoc argument";
1610 echo "when calling configure.";
1612 echo "==================================";
1620 if test -x /usr/bin/perl && test -x ./scripts/maint/updateVersions.pl ; then
1621 ./scripts/maint/updateVersions.pl