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.5.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])
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(--disable-buf-freelists, disable freelists for buffer RAM))
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(curve25519,
41 AS_HELP_STRING(--disable-curve25519, Build Tor with no curve25519 elliptic-curve crypto support))
42 AC_ARG_ENABLE(unittests,
43 AS_HELP_STRING(--disable-unittests, [Don't build unit tests for Tor. Risky!]))
44 AC_ARG_ENABLE(coverage,
45 AS_HELP_STRING(--enable-coverage, [Enable coverage support in the unit-test build]))
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 x$enable_buf_freelists != xno; then
58 AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
59 [Defined if we try to use freelists for buffer RAM chunks])
61 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
62 if test x$enable_instrument_downloads = xyes; then
63 AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
64 [Defined if we want to keep track of how much of each kind of resource we download.])
67 AC_ARG_ENABLE(transparent,
68 AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
69 [case "${enableval}" in
70 yes) transparent=true ;;
71 no) transparent=false ;;
72 *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
73 esac], [transparent=true])
75 AC_ARG_ENABLE(asciidoc,
76 AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
77 [case "${enableval}" in
80 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
81 esac], [asciidoc=true])
83 # By default, we're not ready to ship a NAT-PMP aware Tor
84 AC_ARG_ENABLE(nat-pmp,
85 AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
86 [case "${enableval}" in
89 * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
90 esac], [natpmp=false])
92 # By default, we're not ready to ship a UPnP aware Tor
94 AS_HELP_STRING(--enable-upnp, enable UPnP support),
95 [case "${enableval}" in
98 * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
102 AC_ARG_ENABLE(threads,
103 AS_HELP_STRING(--disable-threads, disable multi-threading support))
105 if test x$enable_threads = x; then
108 # Don't try multithreading on solaris -- cpuworkers seem to lock.
109 AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
110 cpu workers lock up here, so I will disable threads.])
111 enable_threads="no";;
113 enable_threads="yes";;
117 if test "$enable_threads" = "yes"; then
118 AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
123 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
127 AC_ARG_ENABLE(gcc-warnings,
128 AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
129 AC_ARG_ENABLE(gcc-warnings-advisory,
130 AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
132 dnl Adam shostack suggests the following for Windows:
133 dnl -D_FORTIFY_SOURCE=2 -fstack-protector-all
134 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
135 dnl This requires that we use gcc and that we add -O2 to the CFLAGS.
136 AC_ARG_ENABLE(gcc-hardening,
137 AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
139 dnl Linker hardening options
140 dnl Currently these options are ELF specific - you can't use this with MacOSX
141 AC_ARG_ENABLE(linker-hardening,
142 AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
144 AC_ARG_ENABLE(local-appdata,
145 AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
146 if test "$enable_local_appdata" = "yes"; then
147 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
148 [Defined if we default to host local appdata paths on Windows])
152 AC_ARG_ENABLE(tor2web-mode,
153 AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
154 [if test x$enableval = xyes; then
155 CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
158 AC_ARG_ENABLE(bufferevents,
159 AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
161 AC_ARG_ENABLE(tool-name-check,
162 AS_HELP_STRING(--disable-tool-name-check, check for sanely named toolchain when cross-compiling))
164 dnl check for the correct "ar" when cross-compiling
165 AN_MAKEVAR([AR], [AC_PROG_AR])
166 AN_PROGRAM([ar], [AC_PROG_AR])
167 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
170 dnl Check whether the above macro has settled for a simply named tool even
171 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
172 dnl because that will find any cc on the system, not only the cross-compiler,
173 dnl and then verify that a binary built with this compiler runs on the
174 dnl build system. It will then come to the false conclusion that we're not
176 if test x$enable_tool_name_check != xno; then
177 if test x$ac_tool_warned = xyes; then
178 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.)])
179 elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
180 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.)])
189 dnl autoconf 2.59 appears not to support AC_PROG_SED
190 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
192 dnl check for asciidoc and a2x
193 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
194 AC_PATH_PROG([A2X], [a2x], none)
196 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
198 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
199 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
200 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
204 AC_CHECK_PROGS(PYTHON, [python python2 python3])
205 if test "x$PYTHON" = "x"; then
206 AC_MSG_WARN([Python unavailable; some tests will not be run.])
208 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
210 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
211 AC_C_FLEXIBLE_ARRAY_MEMBER
213 dnl Maybe we've got an old autoconf...
214 AC_CACHE_CHECK([for flexible array members],
218 struct abc { int a; char b[]; };
220 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
223 [tor_cv_c_flexarray=yes],
224 [tor_cv_c_flexarray=no])])
225 if test $tor_cv_flexarray = yes ; then
226 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
228 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
232 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
233 AC_PATH_PROG([OPENSSL], [openssl], none)
236 AC_ARG_WITH(tor-user,
237 [ --with-tor-user=NAME Specify username for tor daemon ],
245 AC_ARG_WITH(tor-group,
246 [ --with-tor-group=NAME Specify group name for tor daemon ],
254 dnl If _WIN32 is defined and non-zero, we are building for win32
255 AC_MSG_CHECKING([for win32])
256 AC_RUN_IFELSE([AC_LANG_SOURCE([
257 int main(int c, char **v) {
268 bwin32=true; AC_MSG_RESULT([yes]),
269 bwin32=false; AC_MSG_RESULT([no]),
270 bwin32=cross; AC_MSG_RESULT([cross])
273 if test "$bwin32" = cross; then
274 AC_MSG_CHECKING([for win32 (cross)])
275 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
277 int main(int c, char **v) {return 0;}
280 int main(int c, char **v) {return x(y);}
283 bwin32=true; AC_MSG_RESULT([yes]),
284 bwin32=false; AC_MSG_RESULT([no]))
287 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
289 dnl Enable C99 when compiling with MIPSpro
290 AC_MSG_CHECKING([for MIPSpro compiler])
291 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
292 #if (defined(__sgi) && defined(_COMPILER_VERSION))
297 bmipspro=false; AC_MSG_RESULT(no),
298 bmipspro=true; AC_MSG_RESULT(yes))
300 if test "$bmipspro" = true; then
301 CFLAGS="$CFLAGS -c99"
306 AC_SEARCH_LIBS(socket, [socket network])
307 AC_SEARCH_LIBS(gethostbyname, [nsl])
308 AC_SEARCH_LIBS(dlopen, [dl])
309 AC_SEARCH_LIBS(inet_aton, [resolv])
311 AC_SEARCH_LIBS([clock_gettime], [rt])
312 if test "$LIBS" != "$saved_LIBS"; then
313 # Looks like we need -lrt for clock_gettime().
317 if test "$enable_threads" = "yes"; then
318 AC_SEARCH_LIBS(pthread_create, [pthread])
319 AC_SEARCH_LIBS(pthread_detach, [pthread])
322 dnl -------------------------------------------------------------------
323 dnl Check for functions before libevent, since libevent-1.2 apparently
324 dnl exports strlcpy without defining it in a header.
330 backtrace_symbols_fd \
361 if test "$enable_threads" = "yes"; then
362 AC_CHECK_HEADERS(pthread.h)
363 AC_CHECK_FUNCS(pthread_create)
366 dnl ------------------------------------------------------
367 dnl Where do you live, libevent? And how do we call you?
369 if test "$bwin32" = true; then
370 TOR_LIB_WS32=-lws2_32
371 TOR_LIB_IPHLPAPI=-liphlpapi
372 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
373 # think it's actually necessary.
379 AC_SUBST(TOR_LIB_WS32)
380 AC_SUBST(TOR_LIB_GDI)
381 AC_SUBST(TOR_LIB_IPHLPAPI)
383 dnl We need to do this before we try our disgusting hack below.
384 AC_CHECK_HEADERS([sys/types.h])
386 dnl This is a disgusting hack so we safely include older libevent headers.
387 AC_CHECK_TYPE(u_int64_t, unsigned long long)
388 AC_CHECK_TYPE(u_int32_t, unsigned long)
389 AC_CHECK_TYPE(u_int16_t, unsigned short)
390 AC_CHECK_TYPE(u_int8_t, unsigned char)
392 tor_libevent_pkg_redhat="libevent"
393 tor_libevent_pkg_debian="libevent-dev"
394 tor_libevent_devpkg_redhat="libevent-devel"
395 tor_libevent_devpkg_debian="libevent-dev"
397 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
398 dnl linking for static builds.
399 STATIC_LIBEVENT_FLAGS=""
400 if test "$enable_static_libevent" = "yes"; then
401 if test "$have_rt" = yes; then
402 STATIC_LIBEVENT_FLAGS=" -lrt "
406 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
408 #include <winsock2.h>
411 #include <sys/time.h>
412 #include <sys/types.h>
413 #include <event.h>], [
415 #include <winsock2.h>
417 void exit(int); void *event_init(void);],
420 {WSADATA d; WSAStartup(0x101,&d); }
422 event_init(); exit(0);
423 ], [--with-libevent-dir], [/opt/libevent])
425 dnl Now check for particular libevent functions.
427 save_LDFLAGS="$LDFLAGS"
428 save_CPPFLAGS="$CPPFLAGS"
429 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
430 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
431 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
432 AC_CHECK_FUNCS([event_get_version \
433 event_get_version_number \
435 event_set_log_callback \
436 evdns_set_outgoing_bind_address \
437 evutil_secure_rng_set_urandom_device_file \
438 event_base_loopexit])
439 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
443 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
446 LDFLAGS="$save_LDFLAGS"
447 CPPFLAGS="$save_CPPFLAGS"
450 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
452 if test "$enable_static_libevent" = "yes"; then
453 if test "$tor_cv_library_libevent_dir" = "(system)"; then
454 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
456 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
459 TOR_LIBEVENT_LIBS="-levent"
462 dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
463 dnl we can do much better.
464 if test "$enable_bufferevents" = "yes" ; then
465 if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
466 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.])
469 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
471 # Check for the right version. First see if version detection works.
472 AC_MSG_CHECKING([whether we can detect the Libevent version])
473 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
474 #include <event2/event.h>
475 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
481 ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
482 [event_version_number_works=no; AC_MSG_RESULT([no])])
483 if test "$event_version_number_works" != 'yes'; then
484 AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
486 AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
487 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
488 #include <event2/event.h>
489 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
495 ])], [ AC_MSG_RESULT([yes]) ],
496 [ AC_MSG_RESULT([no])
497 AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
503 LDFLAGS="$save_LDFLAGS"
504 CPPFLAGS="$save_CPPFLAGS"
506 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
507 if test "$enable_bufferevents" = "yes"; then
508 AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
509 if test "$enable_static_libevent" = "yes"; then
510 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
512 TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
515 AC_SUBST(TOR_LIBEVENT_LIBS)
517 dnl ------------------------------------------------------
518 dnl Where do you live, libm?
520 dnl On some platforms (Haiku/BeOS) the math library is
521 dnl part of libroot. In which case don't link against lm
524 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
525 if test "$ac_cv_search_pow" != "none required"; then
526 TOR_LIB_MATH="$ac_cv_search_pow"
529 AC_SUBST(TOR_LIB_MATH)
531 dnl ------------------------------------------------------
532 dnl Where do you live, openssl? And how do we call you?
534 tor_openssl_pkg_redhat="openssl"
535 tor_openssl_pkg_debian="libssl-dev"
536 tor_openssl_devpkg_redhat="openssl-devel"
537 tor_openssl_devpkg_debian="libssl-dev"
539 ALT_openssl_WITHVAL=""
541 [ --with-ssl-dir=PATH Obsolete alias for --with-openssl-dir ],
543 if test "x$withval" != xno && test "x$withval" != "x" ; then
544 ALT_openssl_WITHVAL="$withval"
548 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
549 [#include <openssl/rand.h>],
550 [void RAND_add(const void *buf, int num, double entropy);],
551 [RAND_add((void*)0,0,0); exit(0);], [],
552 [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
554 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
556 if test "$enable_static_openssl" = "yes"; then
557 if test "$tor_cv_library_openssl_dir" = "(system)"; then
558 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
560 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
563 TOR_OPENSSL_LIBS="-lssl -lcrypto"
565 AC_SUBST(TOR_OPENSSL_LIBS)
567 dnl ------------------------------------------------------
568 dnl Where do you live, zlib? And how do we call you?
570 tor_zlib_pkg_redhat="zlib"
571 tor_zlib_pkg_debian="zlib1g"
572 tor_zlib_devpkg_redhat="zlib-devel"
573 tor_zlib_devpkg_debian="zlib1g-dev"
575 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
577 [const char * zlibVersion(void);],
578 [zlibVersion(); exit(0);], [--with-zlib-dir],
581 if test "$enable_static_zlib" = "yes"; then
582 if test "$tor_cv_library_zlib_dir" = "(system)"; then
583 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
584 using --enable-static-zlib")
586 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
591 AC_SUBST(TOR_ZLIB_LIBS)
593 dnl ---------------------------------------------------------------------
594 dnl Now that we know about our major libraries, we can check for compiler
595 dnl and linker hardening options. We need to do this with the libraries known,
596 dnl since sometimes the linker will like an option but not be willing to
597 dnl use it with a build of a library.
599 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
600 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
602 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
603 #if !defined(__clang__)
605 #endif])], have_clang=yes, have_clang=no)
607 if test x$enable_gcc_hardening != xno; then
608 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
609 if test x$have_clang = xyes; then
610 TOR_CHECK_CFLAGS(-Qunused-arguments)
612 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
613 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
614 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
615 AS_VAR_IF(can_compile, [yes],
616 AS_VAR_IF(can_link, [yes],
618 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.)]))
620 AS_VAR_POPDEF([can_link])
621 AS_VAR_POPDEF([can_compile])
622 TOR_CHECK_CFLAGS(-Wstack-protector)
623 TOR_CHECK_CFLAGS(-fwrapv)
624 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
625 if test "$bwin32" = "false"; then
626 TOR_CHECK_CFLAGS(-fPIE)
627 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
631 if test x$enable_linker_hardening != xno; then
632 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
635 # For backtrace support
636 TOR_CHECK_LDFLAGS(-rdynamic)
638 dnl ------------------------------------------------------
639 dnl Now see if we have a -fomit-frame-pointer compiler option.
641 saved_CFLAGS="$CFLAGS"
642 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
643 if test "$saved_CFLAGS" != "$CFLAGS"; then
644 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
646 F_OMIT_FRAME_POINTER=''
648 CFLAGS="$saved_CFLAGS"
649 AC_SUBST(F_OMIT_FRAME_POINTER)
651 dnl ------------------------------------------------------
652 dnl Where do you live, libnatpmp? And how do we call you?
653 dnl There are no packages for Debian or Redhat as of this patch
655 if test "$natpmp" = "true"; then
656 AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
657 TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
658 [#include <natpmp.h>],
662 #include <natpmp.h>],
665 natpmpresp_t response;
666 r = initnatpmp(&natpmp, 0, 0);],
667 [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
669 [--with-libnatpmp-dir],
674 dnl ------------------------------------------------------
675 dnl Where do you live, libminiupnpc? And how do we call you?
676 dnl There are no packages for Debian or Redhat as of this patch
678 if test "$upnp" = "true"; then
679 AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
681 dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
682 dnl to see if we have miniupnpc-1.5 or -1.6
683 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
684 [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
686 if test "$miniupnpc15" = "true" ; then
687 AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
688 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
689 [#include <miniupnpc/miniwget.h>
690 #include <miniupnpc/miniupnpc.h>
691 #include <miniupnpc/upnpcommands.h>],
692 [void upnpDiscover(int delay, const char * multicastif,
693 const char * minissdpdsock, int sameport);],
694 [upnpDiscover(1, 0, 0, 0); exit(0);],
695 [--with-libminiupnpc-dir],
698 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
699 [#include <miniupnpc/miniwget.h>
700 #include <miniupnpc/miniupnpc.h>
701 #include <miniupnpc/upnpcommands.h>],
702 [void upnpDiscover(int delay, const char * multicastif,
703 const char * minissdpdsock, int sameport, int ipv6, int * error);],
704 [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
705 [--with-libminiupnpc-dir],
710 dnl ============================================================
711 dnl Check for libseccomp
713 AC_CHECK_HEADERS([seccomp.h])
714 AC_SEARCH_LIBS(seccomp_init, [seccomp])
716 dnl ============================================================
717 dnl We need an implementation of curve25519.
719 dnl set these defaults.
721 build_curve25519_donna=no
722 build_curve25519_donna_c64=no
723 use_curve25519_donna=no
724 use_curve25519_nacl=no
727 if test x$enable_curve25519 != xno; then
729 dnl The best choice is using curve25519-donna-c64, but that requires
731 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
732 tor_cv_can_use_curve25519_donna_c64,
734 [AC_LANG_PROGRAM([dnl
736 typedef unsigned uint128_t __attribute__((mode(TI)));
737 int func(uint64_t a, uint64_t b) {
738 uint128_t c = ((uint128_t)a) * b;
739 int ok = ((uint64_t)(c>>96)) == 522859 &&
740 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
741 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
742 (((uint64_t)(c))&0xffffffffL) == 0;
746 int ok = func( ((uint64_t)2000000000) * 1000000000,
747 ((uint64_t)1234567890) << 24);
750 [tor_cv_can_use_curve25519_donna_c64=yes],
751 [tor_cv_can_use_curve25519_donna_c64=no],
753 [AC_LANG_PROGRAM([dnl
755 typedef unsigned uint128_t __attribute__((mode(TI)));
756 int func(uint64_t a, uint64_t b) {
757 uint128_t c = ((uint128_t)a) * b;
758 int ok = ((uint64_t)(c>>96)) == 522859 &&
759 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
760 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
761 (((uint64_t)(c))&0xffffffffL) == 0;
765 int ok = func( ((uint64_t)2000000000) * 1000000000,
766 ((uint64_t)1234567890) << 24);
769 [tor_cv_can_use_curve25519_donna_c64=cross],
770 [tor_cv_can_use_curve25519_donna_c64=no])])])
772 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
773 nacl/crypto_scalarmult_curve25519.h])
775 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
776 tor_cv_can_use_curve25519_nacl,
777 [tor_saved_LIBS="$LIBS"
780 [AC_LANG_PROGRAM([dnl
781 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
782 #include <crypto_scalarmult_curve25519.h>
783 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
784 #include <nacl/crypto_scalarmult_curve25519.h>
786 #ifdef crypto_scalarmult_curve25519_ref_BYTES
787 #error Hey, this is the reference implementation! That's not fast.
790 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
791 ])], [tor_cv_can_use_curve25519_nacl=yes],
792 [tor_cv_can_use_curve25519_nacl=no])
793 LIBS="$tor_saved_LIBS" ])
795 dnl Okay, now we need to figure out which one to actually use. Fall back
796 dnl to curve25519-donna.c
798 if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
799 build_curve25519_donna_c64=yes
800 use_curve25519_donna=yes
801 elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
802 use_curve25519_nacl=yes
803 CURVE25519_LIBS=-lnacl
805 build_curve25519_donna=yes
806 use_curve25519_donna=yes
808 have_a_curve25519=yes
811 if test x$have_a_curve25519 = xyes; then
812 AC_DEFINE(CURVE25519_ENABLED, 1,
813 [Defined if we have a curve25519 implementation])
815 if test x$use_curve25519_donna = xyes; then
816 AC_DEFINE(USE_CURVE25519_DONNA, 1,
817 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
819 if test x$use_curve25519_nacl = xyes; then
820 AC_DEFINE(USE_CURVE25519_NACL, 1,
821 [Defined if we should use a curve25519 from nacl])
823 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
824 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
825 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
826 AC_SUBST(CURVE25519_LIBS)
828 dnl Make sure to enable support for large off_t if available.
843 , , 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.))
845 dnl These headers are not essential
883 AC_CHECK_HEADERS(sys/param.h)
885 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
886 [#ifdef HAVE_SYS_TYPES_H
887 #include <sys/types.h>
889 #ifdef HAVE_SYS_SOCKET_H
890 #include <sys/socket.h>
892 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
893 [#ifdef HAVE_SYS_TYPES_H
894 #include <sys/types.h>
896 #ifdef HAVE_SYS_SOCKET_H
897 #include <sys/socket.h>
902 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
903 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
904 [#ifdef HAVE_SYS_TYPES_H
905 #include <sys/types.h>
907 #ifdef HAVE_SYS_SOCKET_H
908 #include <sys/socket.h>
913 #ifdef HAVE_LINUX_TYPES_H
914 #include <linux/types.h>
916 #ifdef HAVE_NETINET_IN6_H
917 #include <netinet/in6.h>
919 #ifdef HAVE_NETINET_IN_H
920 #include <netinet/in.h>
923 if test x$transparent = xtrue ; then
925 if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
928 if test x$linux_netfilter_ipv4 = x1 ; then
931 if test x$transparent_ok = x1 ; then
932 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
934 *-*-openbsd* | *-*-bitrig*)
935 AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
938 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
942 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
943 [#ifdef HAVE_SYS_TYPES_H
944 #include <sys/types.h>
946 #ifdef HAVE_SYS_TIME_H
947 #include <sys/time.h>
950 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
953 AC_CHECK_SIZEOF(int8_t)
954 AC_CHECK_SIZEOF(int16_t)
955 AC_CHECK_SIZEOF(int32_t)
956 AC_CHECK_SIZEOF(int64_t)
957 AC_CHECK_SIZEOF(uint8_t)
958 AC_CHECK_SIZEOF(uint16_t)
959 AC_CHECK_SIZEOF(uint32_t)
960 AC_CHECK_SIZEOF(uint64_t)
961 AC_CHECK_SIZEOF(intptr_t)
962 AC_CHECK_SIZEOF(uintptr_t)
964 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
966 AC_CHECK_SIZEOF(char)
967 AC_CHECK_SIZEOF(short)
969 AC_CHECK_SIZEOF(long)
970 AC_CHECK_SIZEOF(long long)
971 AC_CHECK_SIZEOF(__int64)
972 AC_CHECK_SIZEOF(void *)
973 AC_CHECK_SIZEOF(time_t)
974 AC_CHECK_SIZEOF(size_t)
975 AC_CHECK_SIZEOF(pid_t)
977 AC_CHECK_TYPES([uint, u_char, ssize_t])
979 AC_PC_FROM_UCONTEXT([/bin/true])
981 dnl used to include sockaddr_storage, but everybody has that.
982 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
983 [#ifdef HAVE_SYS_TYPES_H
984 #include <sys/types.h>
986 #ifdef HAVE_NETINET_IN_H
987 #include <netinet/in.h>
989 #ifdef HAVE_NETINET_IN6_H
990 #include <netinet/in6.h>
992 #ifdef HAVE_SYS_SOCKET_H
993 #include <sys/socket.h>
996 #define _WIN32_WINNT 0x0501
997 #define WIN32_LEAN_AND_MEAN
998 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1001 #include <winsock2.h>
1002 #include <ws2tcpip.h>
1006 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1007 [#ifdef HAVE_SYS_TYPES_H
1008 #include <sys/types.h>
1010 #ifdef HAVE_NETINET_IN_H
1011 #include <netinet/in.h>
1013 #ifdef HAVE_NETINET_IN6_H
1014 #include <netinet/in6.h>
1016 #ifdef HAVE_SYS_SOCKET_H
1017 #include <sys/socket.h>
1020 #define _WIN32_WINNT 0x0501
1021 #define WIN32_LEAN_AND_MEAN
1022 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1023 #include <winsock.h>
1025 #include <winsock2.h>
1026 #include <ws2tcpip.h>
1031 AC_CHECK_TYPES([rlim_t], , ,
1032 [#ifdef HAVE_SYS_TYPES_H
1033 #include <sys/types.h>
1035 #ifdef HAVE_SYS_TIME_H
1036 #include <sys/time.h>
1038 #ifdef HAVE_SYS_RESOURCE_H
1039 #include <sys/resource.h>
1043 AX_CHECK_SIGN([time_t],
1044 [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1046 #ifdef HAVE_SYS_TYPES_H
1047 #include <sys/types.h>
1049 #ifdef HAVE_SYS_TIME_H
1050 #include <sys/time.h>
1057 if test "$ax_cv_decl_time_t_signed" = no; then
1058 AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1061 AX_CHECK_SIGN([size_t],
1062 [ tor_cv_size_t_signed=yes ],
1063 [ tor_cv_size_t_signed=no ], [
1064 #ifdef HAVE_SYS_TYPES_H
1065 #include <sys/types.h>
1069 if test "$ax_cv_decl_size_t_signed" = yes; then
1070 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1073 AX_CHECK_SIGN([enum always],
1074 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1076 enum always { AAA, BBB, CCC };
1079 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1080 #ifdef HAVE_SYS_SOCKET_H
1081 #include <sys/socket.h>
1085 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1087 AC_CHECK_SIZEOF(cell_t)
1089 # Now make sure that NULL can be represented as zero bytes.
1090 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1091 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1092 [[#include <stdlib.h>
1095 #ifdef HAVE_STDDEF_H
1098 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1099 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1100 [tor_cv_null_is_zero=yes],
1101 [tor_cv_null_is_zero=no],
1102 [tor_cv_null_is_zero=cross])])
1104 if test "$tor_cv_null_is_zero" = cross ; then
1105 # Cross-compiling; let's hope that the target isn't raving mad.
1106 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1109 if test "$tor_cv_null_is_zero" != no; then
1110 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1111 [Define to 1 iff memset(0) sets pointers to NULL])
1114 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1115 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1116 [[#include <stdlib.h>
1119 #ifdef HAVE_STDDEF_H
1122 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1123 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1124 [tor_cv_dbl0_is_zero=yes],
1125 [tor_cv_dbl0_is_zero=no],
1126 [tor_cv_dbl0_is_zero=cross])])
1128 if test "$tor_cv_dbl0_is_zero" = cross ; then
1129 # Cross-compiling; let's hope that the target isn't raving mad.
1130 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1133 if test "$tor_cv_dbl0_is_zero" != no; then
1134 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1135 [Define to 1 iff memset(0) sets doubles to 0.0])
1138 # And what happens when we malloc zero?
1139 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1140 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1141 [[#include <stdlib.h>
1144 #ifdef HAVE_STDDEF_H
1147 int main () { return malloc(0)?0:1; }]])],
1148 [tor_cv_malloc_zero_works=yes],
1149 [tor_cv_malloc_zero_works=no],
1150 [tor_cv_malloc_zero_works=cross])])
1152 if test "$tor_cv_malloc_zero_works" = cross; then
1153 # Cross-compiling; let's hope that the target isn't raving mad.
1154 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1157 if test "$tor_cv_malloc_zero_works" = yes; then
1158 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1159 [Define to 1 iff malloc(0) returns a pointer])
1162 # whether we seem to be in a 2s-complement world.
1163 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1164 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1165 [[int main () { int problem = ((-99) != (~99)+1);
1166 return problem ? 1 : 0; }]])],
1167 [tor_cv_twos_complement=yes],
1168 [tor_cv_twos_complement=no],
1169 [tor_cv_twos_complement=cross])])
1171 if test "$tor_cv_twos_complement" = cross ; then
1172 # Cross-compiling; let's hope that the target isn't raving mad.
1173 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1176 if test "$tor_cv_twos_complement" != no ; then
1177 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1178 [Define to 1 iff we represent negative integers with two's complement])
1181 # What does shifting a negative value do?
1182 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1183 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1184 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1185 [tor_cv_sign_extend=yes],
1186 [tor_cv_sign_extend=no],
1187 [tor_cv_sign_extend=cross])])
1189 if test "$tor_cv_sign_extend" = cross ; then
1190 # Cross-compiling; let's hope that the target isn't raving mad.
1191 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1194 if test "$tor_cv_sign_extend" != no ; then
1195 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1196 [Define to 1 iff right-shifting a negative value performs sign-extension])
1199 # Whether we should use the dmalloc memory allocation debugging library.
1200 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1201 AC_ARG_WITH(dmalloc,
1202 [ --with-dmalloc Use debug memory allocation library. ],
1203 [if [[ "$withval" = "yes" ]]; then
1209 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1212 if [[ $dmalloc -eq 1 ]]; then
1213 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1214 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1215 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1216 AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1217 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1220 AC_ARG_WITH(tcmalloc,
1221 [ --with-tcmalloc Use tcmalloc memory allocation library. ],
1222 [ tcmalloc=yes ], [ tcmalloc=no ])
1224 if test x$tcmalloc = xyes ; then
1225 LDFLAGS="-ltcmalloc $LDFLAGS"
1228 using_custom_malloc=no
1229 if test x$enable_openbsd_malloc = xyes ; then
1230 using_custom_malloc=yes
1232 if test x$tcmalloc = xyes ; then
1233 using_custom_malloc=yes
1235 if test $using_custom_malloc = no ; then
1236 AC_CHECK_FUNCS(mallinfo)
1239 # By default, we're going to assume we don't have mlockall()
1240 # bionic and other platforms have various broken mlockall subsystems.
1241 # Some systems don't have a working mlockall, some aren't linkable,
1242 # and some have it but don't declare it.
1243 AC_CHECK_FUNCS(mlockall)
1244 AC_CHECK_DECLS([mlockall], , , [
1245 #ifdef HAVE_SYS_MMAN_H
1246 #include <sys/mman.h>
1249 # Allow user to specify an alternate syslog facility
1250 AC_ARG_WITH(syslog-facility,
1251 [ --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1252 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1253 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1254 AC_SUBST(LOGFACILITY)
1256 # Check if we have getresuid and getresgid
1257 AC_CHECK_FUNCS(getresuid getresgid)
1259 # Check for gethostbyname_r in all its glorious incompatible versions.
1260 # (This logic is based on that in Python's configure.in)
1261 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1262 [Define this if you have any gethostbyname_r()])
1264 AC_CHECK_FUNC(gethostbyname_r, [
1265 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1267 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1268 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1272 struct hostent *h1, *h2;
1274 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1276 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1277 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1278 [Define this if gethostbyname_r takes 6 arguments])
1287 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1289 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1290 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1291 [Define this if gethostbyname_r takes 5 arguments])
1299 struct hostent_data hd;
1300 (void) gethostbyname_r(cp1,h1,&hd);
1302 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1303 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1304 [Define this if gethostbyname_r takes 3 arguments])
1314 AC_CACHE_CHECK([whether the C compiler supports __func__],
1315 tor_cv_have_func_macro,
1316 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1318 int main(int c, char **v) { puts(__func__); }])],
1319 tor_cv_have_func_macro=yes,
1320 tor_cv_have_func_macro=no))
1322 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1323 tor_cv_have_FUNC_macro,
1324 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1326 int main(int c, char **v) { puts(__FUNC__); }])],
1327 tor_cv_have_FUNC_macro=yes,
1328 tor_cv_have_FUNC_macro=no))
1330 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1331 tor_cv_have_FUNCTION_macro,
1332 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1334 int main(int c, char **v) { puts(__FUNCTION__); }])],
1335 tor_cv_have_FUNCTION_macro=yes,
1336 tor_cv_have_FUNCTION_macro=no))
1338 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1339 tor_cv_have_environ_declared,
1340 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1341 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1342 * Without it environ doesn't get declared. */
1344 #ifdef HAVE_UNISTD_H
1348 int main(int c, char **v) { char **t = environ; }])],
1349 tor_cv_have_environ_declared=yes,
1350 tor_cv_have_environ_declared=no))
1352 if test "$tor_cv_have_func_macro" = 'yes'; then
1353 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1356 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1357 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1360 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1361 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1362 [Defined if the compiler supports __FUNCTION__])
1365 if test "$tor_cv_have_environ_declared" = 'yes'; then
1366 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1367 [Defined if we have extern char **environ already declared])
1370 # $prefix stores the value of the --prefix command line option, or
1371 # NONE if the option wasn't set. In the case that it wasn't set, make
1372 # it be the default, so that we can use it to expand directories now.
1373 if test "x$prefix" = "xNONE"; then
1374 prefix=$ac_default_prefix
1377 # and similarly for $exec_prefix
1378 if test "x$exec_prefix" = "xNONE"; then
1382 if test "x$BUILDDIR" = "x"; then
1386 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1387 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1389 if test "x$CONFDIR" = "x"; then
1390 CONFDIR=`eval echo $sysconfdir/tor`
1393 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1394 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1396 BINDIR=`eval echo $bindir`
1398 LOCALSTATEDIR=`eval echo $localstatedir`
1399 AC_SUBST(LOCALSTATEDIR)
1401 if test "$bwin32" = true; then
1402 # Test if the linker supports the --nxcompat and --dynamicbase options
1404 save_LDFLAGS="$LDFLAGS"
1405 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1406 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1407 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1408 [AC_MSG_RESULT([yes])]
1409 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1410 [AC_MSG_RESULT([no])]
1412 LDFLAGS="$save_LDFLAGS"
1415 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1416 # than autoconf's macros like.
1417 if test "$GCC" = yes; then
1418 # Disable GCC's strict aliasing checks. They are an hours-to-debug
1419 # accident waiting to happen.
1420 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1422 # Autoconf sets -g -O2 by default. Override optimization level
1423 # for non-gcc compilers
1425 enable_gcc_warnings=no
1426 enable_gcc_warnings_advisory=no
1429 # OS X Lion started deprecating the system openssl. Let's just disable
1430 # all deprecation warnings on OS X. Also, to potentially make the binary
1431 # a little smaller, let's enable dead_strip.
1435 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1436 LDFLAGS="$LDFLAGS -dead_strip" ;;
1439 # Add some more warnings which we use in development but not in the
1440 # released versions. (Some relevant gcc versions can't handle these.)
1441 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1443 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1444 #if !defined(__GNUC__) || (__GNUC__ < 4)
1446 #endif])], have_gcc4=yes, have_gcc4=no)
1448 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1449 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1451 #endif])], have_gcc42=yes, have_gcc42=no)
1453 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1454 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1456 #endif])], have_gcc43=yes, have_gcc43=no)
1458 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1459 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1461 #endif])], have_gcc46=yes, have_gcc46=no)
1464 save_CFLAGS="$CFLAGS"
1465 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1466 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1467 have_shorten64_flag=no)
1468 CFLAGS="$save_CFLAGS"
1471 *-*-openbsd* | *-*-bitrig*)
1472 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1473 # That's fine, except that the headers don't pass -Wredundant-decls.
1474 # Therefore, let's disable -Wsystem-headers when we're building
1475 # with maximal warnings on OpenBSD.
1476 CFLAGS="$CFLAGS -Wno-system-headers" ;;
1479 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1480 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1481 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1482 CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1483 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1485 if test x$enable_gcc_warnings = xyes; then
1486 CFLAGS="$CFLAGS -Werror"
1489 # Disabled, so we can use mallinfo(): -Waggregate-return
1491 if test x$have_gcc4 = xyes ; then
1492 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1493 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1496 if test x$have_gcc42 = xyes ; then
1497 # These warnings break gcc 4.0.2 and work on gcc 4.2
1498 # XXXX020 See if any of these work with earlier versions.
1499 CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1501 # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1504 if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1505 # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1506 CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1509 if test x$have_gcc43 = xyes ; then
1510 # These warnings break gcc 4.2 and work on gcc 4.3
1511 # XXXX020 See if any of these work with earlier versions.
1512 CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1515 if test x$have_gcc46 = xyes ; then
1516 # This warning was added in gcc 4.3, but it appears to generate
1517 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
1518 CFLAGS="$CFLAGS -Wlogical-op"
1521 if test x$have_shorten64_flag = xyes ; then
1522 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1527 ##This will break the world on some 64-bit architectures
1528 # CFLAGS="$CFLAGS -Winline"
1531 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1534 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.])
1538 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1544 contrib/tor.logrotate
1547 src/config/torrc.sample
1550 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1551 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1552 for file in $regular_mans ; do
1553 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1554 echo "==================================";
1556 echo "You need asciidoc installed to be able to build the manpage.";
1557 echo "To build without manpages, use the --disable-asciidoc argument";
1558 echo "when calling configure.";
1560 echo "==================================";
1568 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1569 ./contrib/updateVersions.pl