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.4-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 Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
133 AC_ARG_ENABLE(gcc-hardening,
134 AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
136 AC_ARG_ENABLE(expensive-hardening,
137 AS_HELP_STRING(--enable-expensive-hardening, enable more expensive compiler hardening; makes Tor slower))
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 AC_ARG_ENABLE(seccomp,
165 AS_HELP_STRING(--disable-seccomp, do not attempt to use libseccomp))
167 dnl check for the correct "ar" when cross-compiling
168 AN_MAKEVAR([AR], [AC_PROG_AR])
169 AN_PROGRAM([ar], [AC_PROG_AR])
170 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
173 dnl Check whether the above macro has settled for a simply named tool even
174 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
175 dnl because that will find any cc on the system, not only the cross-compiler,
176 dnl and then verify that a binary built with this compiler runs on the
177 dnl build system. It will then come to the false conclusion that we're not
179 if test x$enable_tool_name_check != xno; then
180 if test x$ac_tool_warned = xyes; then
181 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.)])
182 elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
183 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.)])
192 dnl autoconf 2.59 appears not to support AC_PROG_SED
193 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
195 dnl check for asciidoc and a2x
196 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
197 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
199 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
201 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
202 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
203 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
207 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
208 if test "x$PYTHON" = "x"; then
209 AC_MSG_WARN([Python unavailable; some tests will not be run.])
211 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
213 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
214 AC_C_FLEXIBLE_ARRAY_MEMBER
216 dnl Maybe we've got an old autoconf...
217 AC_CACHE_CHECK([for flexible array members],
221 struct abc { int a; char b[]; };
223 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
226 [tor_cv_c_flexarray=yes],
227 [tor_cv_c_flexarray=no])])
228 if test $tor_cv_flexarray = yes ; then
229 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
231 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
235 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
236 AC_PATH_PROG([OPENSSL], [openssl], none)
239 AC_ARG_WITH(tor-user,
240 [ --with-tor-user=NAME Specify username for tor daemon ],
248 AC_ARG_WITH(tor-group,
249 [ --with-tor-group=NAME Specify group name for tor daemon ],
257 dnl If _WIN32 is defined and non-zero, we are building for win32
258 AC_MSG_CHECKING([for win32])
259 AC_RUN_IFELSE([AC_LANG_SOURCE([
260 int main(int c, char **v) {
271 bwin32=true; AC_MSG_RESULT([yes]),
272 bwin32=false; AC_MSG_RESULT([no]),
273 bwin32=cross; AC_MSG_RESULT([cross])
276 if test "$bwin32" = cross; then
277 AC_MSG_CHECKING([for win32 (cross)])
278 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
280 int main(int c, char **v) {return 0;}
283 int main(int c, char **v) {return x(y);}
286 bwin32=true; AC_MSG_RESULT([yes]),
287 bwin32=false; AC_MSG_RESULT([no]))
290 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
292 dnl Enable C99 when compiling with MIPSpro
293 AC_MSG_CHECKING([for MIPSpro compiler])
294 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
295 #if (defined(__sgi) && defined(_COMPILER_VERSION))
300 bmipspro=false; AC_MSG_RESULT(no),
301 bmipspro=true; AC_MSG_RESULT(yes))
303 if test "$bmipspro" = true; then
304 CFLAGS="$CFLAGS -c99"
309 AC_SEARCH_LIBS(socket, [socket network])
310 AC_SEARCH_LIBS(gethostbyname, [nsl])
311 AC_SEARCH_LIBS(dlopen, [dl])
312 AC_SEARCH_LIBS(inet_aton, [resolv])
314 AC_SEARCH_LIBS([clock_gettime], [rt])
315 if test "$LIBS" != "$saved_LIBS"; then
316 # Looks like we need -lrt for clock_gettime().
320 if test "$enable_threads" = "yes"; then
321 AC_SEARCH_LIBS(pthread_create, [pthread])
322 AC_SEARCH_LIBS(pthread_detach, [pthread])
325 dnl -------------------------------------------------------------------
326 dnl Check for functions before libevent, since libevent-1.2 apparently
327 dnl exports strlcpy without defining it in a header.
333 backtrace_symbols_fd \
365 if test "$enable_threads" = "yes"; then
366 AC_CHECK_HEADERS(pthread.h)
367 AC_CHECK_FUNCS(pthread_create)
370 dnl ------------------------------------------------------
371 dnl Where do you live, libevent? And how do we call you?
373 if test "$bwin32" = true; then
374 TOR_LIB_WS32=-lws2_32
375 TOR_LIB_IPHLPAPI=-liphlpapi
376 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
377 # think it's actually necessary.
383 AC_SUBST(TOR_LIB_WS32)
384 AC_SUBST(TOR_LIB_GDI)
385 AC_SUBST(TOR_LIB_IPHLPAPI)
387 dnl We need to do this before we try our disgusting hack below.
388 AC_CHECK_HEADERS([sys/types.h])
390 dnl This is a disgusting hack so we safely include older libevent headers.
391 AC_CHECK_TYPE(u_int64_t, unsigned long long)
392 AC_CHECK_TYPE(u_int32_t, unsigned long)
393 AC_CHECK_TYPE(u_int16_t, unsigned short)
394 AC_CHECK_TYPE(u_int8_t, unsigned char)
396 tor_libevent_pkg_redhat="libevent"
397 tor_libevent_pkg_debian="libevent-dev"
398 tor_libevent_devpkg_redhat="libevent-devel"
399 tor_libevent_devpkg_debian="libevent-dev"
401 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
402 dnl linking for static builds.
403 STATIC_LIBEVENT_FLAGS=""
404 if test "$enable_static_libevent" = "yes"; then
405 if test "$have_rt" = yes; then
406 STATIC_LIBEVENT_FLAGS=" -lrt "
410 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
412 #include <winsock2.h>
415 #include <sys/time.h>
416 #include <sys/types.h>
417 #include <event.h>], [
419 #include <winsock2.h>
421 void exit(int); void *event_init(void);],
424 {WSADATA d; WSAStartup(0x101,&d); }
426 event_init(); exit(0);
427 ], [--with-libevent-dir], [/opt/libevent])
429 dnl Now check for particular libevent functions.
431 save_LDFLAGS="$LDFLAGS"
432 save_CPPFLAGS="$CPPFLAGS"
433 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
434 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
435 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
436 AC_CHECK_FUNCS([event_get_version \
437 event_get_version_number \
439 event_set_log_callback \
440 evutil_secure_rng_set_urandom_device_file \
441 evutil_secure_rng_init \
442 event_base_loopexit])
443 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
447 AC_CHECK_HEADERS(event2/event.h event2/dns.h)
450 LDFLAGS="$save_LDFLAGS"
451 CPPFLAGS="$save_CPPFLAGS"
454 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
456 if test "$enable_static_libevent" = "yes"; then
457 if test "$tor_cv_library_libevent_dir" = "(system)"; then
458 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
460 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
463 TOR_LIBEVENT_LIBS="-levent"
466 dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
467 dnl we can do much better.
468 if test "$enable_bufferevents" = "yes" ; then
469 if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
470 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.])
473 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
475 # Check for the right version. First see if version detection works.
476 AC_MSG_CHECKING([whether we can detect the Libevent version])
477 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
478 #include <event2/event.h>
479 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
485 ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
486 [event_version_number_works=no; AC_MSG_RESULT([no])])
487 if test "$event_version_number_works" != 'yes'; then
488 AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
490 AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
491 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
492 #include <event2/event.h>
493 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
499 ])], [ AC_MSG_RESULT([yes]) ],
500 [ AC_MSG_RESULT([no])
501 AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
507 LDFLAGS="$save_LDFLAGS"
508 CPPFLAGS="$save_CPPFLAGS"
510 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
511 if test "$enable_bufferevents" = "yes"; then
512 AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
513 if test "$enable_static_libevent" = "yes"; then
514 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
516 TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
519 AC_SUBST(TOR_LIBEVENT_LIBS)
521 dnl ------------------------------------------------------
522 dnl Where do you live, libm?
524 dnl On some platforms (Haiku/BeOS) the math library is
525 dnl part of libroot. In which case don't link against lm
528 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
529 if test "$ac_cv_search_pow" != "none required"; then
530 TOR_LIB_MATH="$ac_cv_search_pow"
533 AC_SUBST(TOR_LIB_MATH)
535 dnl ------------------------------------------------------
536 dnl Where do you live, openssl? And how do we call you?
538 tor_openssl_pkg_redhat="openssl"
539 tor_openssl_pkg_debian="libssl-dev"
540 tor_openssl_devpkg_redhat="openssl-devel"
541 tor_openssl_devpkg_debian="libssl-dev"
543 ALT_openssl_WITHVAL=""
545 [ --with-ssl-dir=PATH Obsolete alias for --with-openssl-dir ],
547 if test "x$withval" != xno && test "x$withval" != "x" ; then
548 ALT_openssl_WITHVAL="$withval"
552 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
553 [#include <openssl/rand.h>],
554 [void RAND_add(const void *buf, int num, double entropy);],
555 [RAND_add((void*)0,0,0); exit(0);], [],
556 [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
558 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
560 if test "$enable_static_openssl" = "yes"; then
561 if test "$tor_cv_library_openssl_dir" = "(system)"; then
562 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
564 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
567 TOR_OPENSSL_LIBS="-lssl -lcrypto"
569 AC_SUBST(TOR_OPENSSL_LIBS)
571 dnl ------------------------------------------------------
572 dnl Where do you live, zlib? And how do we call you?
574 tor_zlib_pkg_redhat="zlib"
575 tor_zlib_pkg_debian="zlib1g"
576 tor_zlib_devpkg_redhat="zlib-devel"
577 tor_zlib_devpkg_debian="zlib1g-dev"
579 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
581 [const char * zlibVersion(void);],
582 [zlibVersion(); exit(0);], [--with-zlib-dir],
585 if test "$enable_static_zlib" = "yes"; then
586 if test "$tor_cv_library_zlib_dir" = "(system)"; then
587 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
588 using --enable-static-zlib")
590 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
595 AC_SUBST(TOR_ZLIB_LIBS)
597 dnl ---------------------------------------------------------------------
598 dnl Now that we know about our major libraries, we can check for compiler
599 dnl and linker hardening options. We need to do this with the libraries known,
600 dnl since sometimes the linker will like an option but not be willing to
601 dnl use it with a build of a library.
603 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
604 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
606 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
607 #if !defined(__clang__)
609 #endif])], have_clang=yes, have_clang=no)
611 if test x$enable_gcc_hardening != xno; then
612 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
613 if test x$have_clang = xyes; then
614 TOR_CHECK_CFLAGS(-Qunused-arguments)
616 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
617 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
618 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
619 AS_VAR_IF(can_compile, [yes],
620 AS_VAR_IF(can_link, [yes],
622 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.)]))
624 AS_VAR_POPDEF([can_link])
625 AS_VAR_POPDEF([can_compile])
626 TOR_CHECK_CFLAGS(-Wstack-protector)
627 TOR_CHECK_CFLAGS(-fwrapv)
628 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
629 if test "$bwin32" = "false"; then
630 TOR_CHECK_CFLAGS(-fPIE)
631 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
635 if test x$enable_expensive_hardening = xyes ; then
636 TOR_CHECK_CFLAGS([-fsanitize=address])
637 TOR_CHECK_CFLAGS([-fsanitize=undefined])
638 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
641 if test x$enable_linker_hardening != xno; then
642 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
645 # For backtrace support
646 TOR_CHECK_LDFLAGS(-rdynamic)
648 dnl ------------------------------------------------------
649 dnl Now see if we have a -fomit-frame-pointer compiler option.
651 saved_CFLAGS="$CFLAGS"
652 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
653 F_OMIT_FRAME_POINTER=''
654 if test "$saved_CFLAGS" != "$CFLAGS"; then
655 if test x$enable_expensive_hardening != xyes ; then
656 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
659 CFLAGS="$saved_CFLAGS"
660 AC_SUBST(F_OMIT_FRAME_POINTER)
662 dnl ------------------------------------------------------
663 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
664 dnl for us, as GCC 4.6 and later do at many optimization levels), then
665 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
667 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
669 dnl ------------------------------------------------------
670 dnl Where do you live, libnatpmp? And how do we call you?
671 dnl There are no packages for Debian or Redhat as of this patch
673 if test "$natpmp" = "true"; then
674 AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
675 TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
676 [#include <natpmp.h>],
680 #include <natpmp.h>],
683 natpmpresp_t response;
684 r = initnatpmp(&natpmp, 0, 0);],
685 [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
687 [--with-libnatpmp-dir],
692 dnl ------------------------------------------------------
693 dnl Where do you live, libminiupnpc? And how do we call you?
694 dnl There are no packages for Debian or Redhat as of this patch
696 if test "$upnp" = "true"; then
697 AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
699 dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
700 dnl to see if we have miniupnpc-1.5 or -1.6
701 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
702 [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
704 if test "$miniupnpc15" = "true" ; then
705 AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
706 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
707 [#include <miniupnpc/miniwget.h>
708 #include <miniupnpc/miniupnpc.h>
709 #include <miniupnpc/upnpcommands.h>],
710 [void upnpDiscover(int delay, const char * multicastif,
711 const char * minissdpdsock, int sameport);],
712 [upnpDiscover(1, 0, 0, 0); exit(0);],
713 [--with-libminiupnpc-dir],
716 TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
717 [#include <miniupnpc/miniwget.h>
718 #include <miniupnpc/miniupnpc.h>
719 #include <miniupnpc/upnpcommands.h>],
720 [void upnpDiscover(int delay, const char * multicastif,
721 const char * minissdpdsock, int sameport, int ipv6, int * error);],
722 [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
723 [--with-libminiupnpc-dir],
728 dnl ============================================================
729 dnl Check for libseccomp
731 if test "x$enable_seccomp" != "xno"; then
732 AC_CHECK_HEADERS([seccomp.h])
733 AC_SEARCH_LIBS(seccomp_init, [seccomp])
736 dnl ============================================================
737 dnl We need an implementation of curve25519.
739 dnl set these defaults.
741 build_curve25519_donna=no
742 build_curve25519_donna_c64=no
743 use_curve25519_donna=no
744 use_curve25519_nacl=no
747 if test x$enable_curve25519 != xno; then
749 dnl The best choice is using curve25519-donna-c64, but that requires
751 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
752 tor_cv_can_use_curve25519_donna_c64,
754 [AC_LANG_PROGRAM([dnl
756 typedef unsigned uint128_t __attribute__((mode(TI)));
757 int func(uint64_t a, uint64_t b) {
758 uint128_t c = ((uint128_t)a) * b;
759 int ok = ((uint64_t)(c>>96)) == 522859 &&
760 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
761 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
762 (((uint64_t)(c))&0xffffffffL) == 0;
766 int ok = func( ((uint64_t)2000000000) * 1000000000,
767 ((uint64_t)1234567890) << 24);
770 [tor_cv_can_use_curve25519_donna_c64=yes],
771 [tor_cv_can_use_curve25519_donna_c64=no],
773 [AC_LANG_PROGRAM([dnl
775 typedef unsigned uint128_t __attribute__((mode(TI)));
776 int func(uint64_t a, uint64_t b) {
777 uint128_t c = ((uint128_t)a) * b;
778 int ok = ((uint64_t)(c>>96)) == 522859 &&
779 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
780 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
781 (((uint64_t)(c))&0xffffffffL) == 0;
785 int ok = func( ((uint64_t)2000000000) * 1000000000,
786 ((uint64_t)1234567890) << 24);
789 [tor_cv_can_use_curve25519_donna_c64=cross],
790 [tor_cv_can_use_curve25519_donna_c64=no])])])
792 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
793 nacl/crypto_scalarmult_curve25519.h])
795 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
796 tor_cv_can_use_curve25519_nacl,
797 [tor_saved_LIBS="$LIBS"
800 [AC_LANG_PROGRAM([dnl
801 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
802 #include <crypto_scalarmult_curve25519.h>
803 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
804 #include <nacl/crypto_scalarmult_curve25519.h>
806 #ifdef crypto_scalarmult_curve25519_ref_BYTES
807 #error Hey, this is the reference implementation! That's not fast.
810 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
811 ])], [tor_cv_can_use_curve25519_nacl=yes],
812 [tor_cv_can_use_curve25519_nacl=no])
813 LIBS="$tor_saved_LIBS" ])
815 dnl Okay, now we need to figure out which one to actually use. Fall back
816 dnl to curve25519-donna.c
818 if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
819 build_curve25519_donna_c64=yes
820 use_curve25519_donna=yes
821 elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
822 use_curve25519_nacl=yes
823 CURVE25519_LIBS=-lnacl
825 build_curve25519_donna=yes
826 use_curve25519_donna=yes
828 have_a_curve25519=yes
831 if test x$have_a_curve25519 = xyes; then
832 AC_DEFINE(CURVE25519_ENABLED, 1,
833 [Defined if we have a curve25519 implementation])
835 if test x$use_curve25519_donna = xyes; then
836 AC_DEFINE(USE_CURVE25519_DONNA, 1,
837 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
839 if test x$use_curve25519_nacl = xyes; then
840 AC_DEFINE(USE_CURVE25519_NACL, 1,
841 [Defined if we should use a curve25519 from nacl])
843 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
844 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
845 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
846 AC_SUBST(CURVE25519_LIBS)
848 dnl Make sure to enable support for large off_t if available.
863 , , 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.))
865 dnl These headers are not essential
904 AC_CHECK_HEADERS(sys/param.h)
906 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
907 [#ifdef HAVE_SYS_TYPES_H
908 #include <sys/types.h>
910 #ifdef HAVE_SYS_SOCKET_H
911 #include <sys/socket.h>
913 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
914 [#ifdef HAVE_SYS_TYPES_H
915 #include <sys/types.h>
917 #ifdef HAVE_SYS_SOCKET_H
918 #include <sys/socket.h>
923 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
924 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
925 [#ifdef HAVE_SYS_TYPES_H
926 #include <sys/types.h>
928 #ifdef HAVE_SYS_SOCKET_H
929 #include <sys/socket.h>
934 #ifdef HAVE_LINUX_TYPES_H
935 #include <linux/types.h>
937 #ifdef HAVE_NETINET_IN6_H
938 #include <netinet/in6.h>
940 #ifdef HAVE_NETINET_IN_H
941 #include <netinet/in.h>
944 if test x$transparent = xtrue ; then
946 if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
949 if test x$linux_netfilter_ipv4 = x1 ; then
952 if test x$transparent_ok = x1 ; then
953 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
955 *-*-openbsd* | *-*-bitrig*)
956 AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
959 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
963 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
964 [#ifdef HAVE_SYS_TYPES_H
965 #include <sys/types.h>
967 #ifdef HAVE_SYS_TIME_H
968 #include <sys/time.h>
971 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
974 AC_CHECK_SIZEOF(int8_t)
975 AC_CHECK_SIZEOF(int16_t)
976 AC_CHECK_SIZEOF(int32_t)
977 AC_CHECK_SIZEOF(int64_t)
978 AC_CHECK_SIZEOF(uint8_t)
979 AC_CHECK_SIZEOF(uint16_t)
980 AC_CHECK_SIZEOF(uint32_t)
981 AC_CHECK_SIZEOF(uint64_t)
982 AC_CHECK_SIZEOF(intptr_t)
983 AC_CHECK_SIZEOF(uintptr_t)
985 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
987 AC_CHECK_SIZEOF(char)
988 AC_CHECK_SIZEOF(short)
990 AC_CHECK_SIZEOF(long)
991 AC_CHECK_SIZEOF(long long)
992 AC_CHECK_SIZEOF(__int64)
993 AC_CHECK_SIZEOF(void *)
994 AC_CHECK_SIZEOF(time_t)
995 AC_CHECK_SIZEOF(size_t)
996 AC_CHECK_SIZEOF(pid_t)
998 AC_CHECK_TYPES([uint, u_char, ssize_t])
1000 AC_PC_FROM_UCONTEXT([/bin/true])
1002 dnl used to include sockaddr_storage, but everybody has that.
1003 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1004 [#ifdef HAVE_SYS_TYPES_H
1005 #include <sys/types.h>
1007 #ifdef HAVE_NETINET_IN_H
1008 #include <netinet/in.h>
1010 #ifdef HAVE_NETINET_IN6_H
1011 #include <netinet/in6.h>
1013 #ifdef HAVE_SYS_SOCKET_H
1014 #include <sys/socket.h>
1017 #define _WIN32_WINNT 0x0501
1018 #define WIN32_LEAN_AND_MEAN
1019 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1020 #include <winsock.h>
1022 #include <winsock2.h>
1023 #include <ws2tcpip.h>
1027 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1028 [#ifdef HAVE_SYS_TYPES_H
1029 #include <sys/types.h>
1031 #ifdef HAVE_NETINET_IN_H
1032 #include <netinet/in.h>
1034 #ifdef HAVE_NETINET_IN6_H
1035 #include <netinet/in6.h>
1037 #ifdef HAVE_SYS_SOCKET_H
1038 #include <sys/socket.h>
1041 #define _WIN32_WINNT 0x0501
1042 #define WIN32_LEAN_AND_MEAN
1043 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1044 #include <winsock.h>
1046 #include <winsock2.h>
1047 #include <ws2tcpip.h>
1052 AC_CHECK_TYPES([rlim_t], , ,
1053 [#ifdef HAVE_SYS_TYPES_H
1054 #include <sys/types.h>
1056 #ifdef HAVE_SYS_TIME_H
1057 #include <sys/time.h>
1059 #ifdef HAVE_SYS_RESOURCE_H
1060 #include <sys/resource.h>
1064 AX_CHECK_SIGN([time_t],
1065 [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1067 #ifdef HAVE_SYS_TYPES_H
1068 #include <sys/types.h>
1070 #ifdef HAVE_SYS_TIME_H
1071 #include <sys/time.h>
1078 if test "$ax_cv_decl_time_t_signed" = no; then
1079 AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1082 AX_CHECK_SIGN([size_t],
1083 [ tor_cv_size_t_signed=yes ],
1084 [ tor_cv_size_t_signed=no ], [
1085 #ifdef HAVE_SYS_TYPES_H
1086 #include <sys/types.h>
1090 if test "$ax_cv_decl_size_t_signed" = yes; then
1091 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1094 AX_CHECK_SIGN([enum always],
1095 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1097 enum always { AAA, BBB, CCC };
1100 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1101 #ifdef HAVE_SYS_SOCKET_H
1102 #include <sys/socket.h>
1106 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1108 AC_CHECK_SIZEOF(cell_t)
1110 # Now make sure that NULL can be represented as zero bytes.
1111 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1112 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1113 [[#include <stdlib.h>
1116 #ifdef HAVE_STDDEF_H
1119 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1120 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1121 [tor_cv_null_is_zero=yes],
1122 [tor_cv_null_is_zero=no],
1123 [tor_cv_null_is_zero=cross])])
1125 if test "$tor_cv_null_is_zero" = cross ; then
1126 # Cross-compiling; let's hope that the target isn't raving mad.
1127 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1130 if test "$tor_cv_null_is_zero" != no; then
1131 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1132 [Define to 1 iff memset(0) sets pointers to NULL])
1135 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1136 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1137 [[#include <stdlib.h>
1140 #ifdef HAVE_STDDEF_H
1143 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1144 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1145 [tor_cv_dbl0_is_zero=yes],
1146 [tor_cv_dbl0_is_zero=no],
1147 [tor_cv_dbl0_is_zero=cross])])
1149 if test "$tor_cv_dbl0_is_zero" = cross ; then
1150 # Cross-compiling; let's hope that the target isn't raving mad.
1151 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1154 if test "$tor_cv_dbl0_is_zero" != no; then
1155 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1156 [Define to 1 iff memset(0) sets doubles to 0.0])
1159 # And what happens when we malloc zero?
1160 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1161 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1162 [[#include <stdlib.h>
1165 #ifdef HAVE_STDDEF_H
1168 int main () { return malloc(0)?0:1; }]])],
1169 [tor_cv_malloc_zero_works=yes],
1170 [tor_cv_malloc_zero_works=no],
1171 [tor_cv_malloc_zero_works=cross])])
1173 if test "$tor_cv_malloc_zero_works" = cross; then
1174 # Cross-compiling; let's hope that the target isn't raving mad.
1175 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1178 if test "$tor_cv_malloc_zero_works" = yes; then
1179 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1180 [Define to 1 iff malloc(0) returns a pointer])
1183 # whether we seem to be in a 2s-complement world.
1184 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1185 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1186 [[int main () { int problem = ((-99) != (~99)+1);
1187 return problem ? 1 : 0; }]])],
1188 [tor_cv_twos_complement=yes],
1189 [tor_cv_twos_complement=no],
1190 [tor_cv_twos_complement=cross])])
1192 if test "$tor_cv_twos_complement" = cross ; then
1193 # Cross-compiling; let's hope that the target isn't raving mad.
1194 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1197 if test "$tor_cv_twos_complement" != no ; then
1198 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1199 [Define to 1 iff we represent negative integers with two's complement])
1202 # What does shifting a negative value do?
1203 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1204 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1205 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1206 [tor_cv_sign_extend=yes],
1207 [tor_cv_sign_extend=no],
1208 [tor_cv_sign_extend=cross])])
1210 if test "$tor_cv_sign_extend" = cross ; then
1211 # Cross-compiling; let's hope that the target isn't raving mad.
1212 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1215 if test "$tor_cv_sign_extend" != no ; then
1216 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1217 [Define to 1 iff right-shifting a negative value performs sign-extension])
1220 # Whether we should use the dmalloc memory allocation debugging library.
1221 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1222 AC_ARG_WITH(dmalloc,
1223 [ --with-dmalloc Use debug memory allocation library. ],
1224 [if [[ "$withval" = "yes" ]]; then
1230 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1233 if [[ $dmalloc -eq 1 ]]; then
1234 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1235 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1236 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1237 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1240 AC_ARG_WITH(tcmalloc,
1241 [ --with-tcmalloc Use tcmalloc memory allocation library. ],
1242 [ tcmalloc=yes ], [ tcmalloc=no ])
1244 if test x$tcmalloc = xyes ; then
1245 LDFLAGS="-ltcmalloc $LDFLAGS"
1248 using_custom_malloc=no
1249 if test x$enable_openbsd_malloc = xyes ; then
1250 using_custom_malloc=yes
1252 if test x$tcmalloc = xyes ; then
1253 using_custom_malloc=yes
1255 if test $using_custom_malloc = no ; then
1256 AC_CHECK_FUNCS(mallinfo)
1259 # By default, we're going to assume we don't have mlockall()
1260 # bionic and other platforms have various broken mlockall subsystems.
1261 # Some systems don't have a working mlockall, some aren't linkable,
1262 # and some have it but don't declare it.
1263 AC_CHECK_FUNCS(mlockall)
1264 AC_CHECK_DECLS([mlockall], , , [
1265 #ifdef HAVE_SYS_MMAN_H
1266 #include <sys/mman.h>
1269 # Allow user to specify an alternate syslog facility
1270 AC_ARG_WITH(syslog-facility,
1271 [ --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1272 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1273 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1274 AC_SUBST(LOGFACILITY)
1276 # Check if we have getresuid and getresgid
1277 AC_CHECK_FUNCS(getresuid getresgid)
1279 # Check for gethostbyname_r in all its glorious incompatible versions.
1280 # (This logic is based on that in Python's configure.in)
1281 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1282 [Define this if you have any gethostbyname_r()])
1284 AC_CHECK_FUNC(gethostbyname_r, [
1285 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1287 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1288 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1292 struct hostent *h1, *h2;
1294 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1296 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1297 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1298 [Define this if gethostbyname_r takes 6 arguments])
1307 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1309 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1310 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1311 [Define this if gethostbyname_r takes 5 arguments])
1319 struct hostent_data hd;
1320 (void) gethostbyname_r(cp1,h1,&hd);
1322 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1323 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1324 [Define this if gethostbyname_r takes 3 arguments])
1334 AC_CACHE_CHECK([whether the C compiler supports __func__],
1335 tor_cv_have_func_macro,
1336 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1338 int main(int c, char **v) { puts(__func__); }])],
1339 tor_cv_have_func_macro=yes,
1340 tor_cv_have_func_macro=no))
1342 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1343 tor_cv_have_FUNC_macro,
1344 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1346 int main(int c, char **v) { puts(__FUNC__); }])],
1347 tor_cv_have_FUNC_macro=yes,
1348 tor_cv_have_FUNC_macro=no))
1350 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1351 tor_cv_have_FUNCTION_macro,
1352 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1354 int main(int c, char **v) { puts(__FUNCTION__); }])],
1355 tor_cv_have_FUNCTION_macro=yes,
1356 tor_cv_have_FUNCTION_macro=no))
1358 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1359 tor_cv_have_environ_declared,
1360 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1361 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1362 * Without it environ doesn't get declared. */
1364 #ifdef HAVE_UNISTD_H
1368 int main(int c, char **v) { char **t = environ; }])],
1369 tor_cv_have_environ_declared=yes,
1370 tor_cv_have_environ_declared=no))
1372 if test "$tor_cv_have_func_macro" = 'yes'; then
1373 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1376 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1377 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1380 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1381 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1382 [Defined if the compiler supports __FUNCTION__])
1385 if test "$tor_cv_have_environ_declared" = 'yes'; then
1386 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1387 [Defined if we have extern char **environ already declared])
1390 # $prefix stores the value of the --prefix command line option, or
1391 # NONE if the option wasn't set. In the case that it wasn't set, make
1392 # it be the default, so that we can use it to expand directories now.
1393 if test "x$prefix" = "xNONE"; then
1394 prefix=$ac_default_prefix
1397 # and similarly for $exec_prefix
1398 if test "x$exec_prefix" = "xNONE"; then
1402 if test "x$BUILDDIR" = "x"; then
1406 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1407 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1409 if test "x$CONFDIR" = "x"; then
1410 CONFDIR=`eval echo $sysconfdir/tor`
1413 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1414 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1416 BINDIR=`eval echo $bindir`
1418 LOCALSTATEDIR=`eval echo $localstatedir`
1419 AC_SUBST(LOCALSTATEDIR)
1421 if test "$bwin32" = true; then
1422 # Test if the linker supports the --nxcompat and --dynamicbase options
1424 save_LDFLAGS="$LDFLAGS"
1425 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1426 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1427 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1428 [AC_MSG_RESULT([yes])]
1429 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1430 [AC_MSG_RESULT([no])]
1432 LDFLAGS="$save_LDFLAGS"
1435 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1436 # than autoconf's macros like.
1437 if test "$GCC" = yes; then
1438 # Disable GCC's strict aliasing checks. They are an hours-to-debug
1439 # accident waiting to happen.
1440 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1442 # Autoconf sets -g -O2 by default. Override optimization level
1443 # for non-gcc compilers
1445 enable_gcc_warnings=no
1446 enable_gcc_warnings_advisory=no
1449 # OS X Lion started deprecating the system openssl. Let's just disable
1450 # all deprecation warnings on OS X. Also, to potentially make the binary
1451 # a little smaller, let's enable dead_strip.
1455 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1456 LDFLAGS="$LDFLAGS -dead_strip" ;;
1459 # Add some more warnings which we use in development but not in the
1460 # released versions. (Some relevant gcc versions can't handle these.)
1461 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1463 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1464 #if !defined(__GNUC__) || (__GNUC__ < 4)
1466 #endif])], have_gcc4=yes, have_gcc4=no)
1468 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1469 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1471 #endif])], have_gcc42=yes, have_gcc42=no)
1473 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1474 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1476 #endif])], have_gcc43=yes, have_gcc43=no)
1478 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1479 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1481 #endif])], have_gcc46=yes, have_gcc46=no)
1484 save_CFLAGS="$CFLAGS"
1485 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1486 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1487 have_shorten64_flag=no)
1488 CFLAGS="$save_CFLAGS"
1491 *-*-openbsd* | *-*-bitrig*)
1492 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1493 # That's fine, except that the headers don't pass -Wredundant-decls.
1494 # Therefore, let's disable -Wsystem-headers when we're building
1495 # with maximal warnings on OpenBSD.
1496 CFLAGS="$CFLAGS -Wno-system-headers" ;;
1499 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1500 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1501 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1502 CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1503 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1505 if test x$enable_gcc_warnings = xyes; then
1506 CFLAGS="$CFLAGS -Werror"
1509 # Disabled, so we can use mallinfo(): -Waggregate-return
1511 if test x$have_gcc4 = xyes ; then
1512 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1513 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1516 if test x$have_gcc42 = xyes ; then
1517 # These warnings break gcc 4.0.2 and work on gcc 4.2
1518 # XXXX020 See if any of these work with earlier versions.
1519 CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1521 # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1524 if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1525 # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1526 CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1529 if test x$have_gcc43 = xyes ; then
1530 # These warnings break gcc 4.2 and work on gcc 4.3
1531 # XXXX020 See if any of these work with earlier versions.
1532 CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1535 if test x$have_gcc46 = xyes ; then
1536 # This warning was added in gcc 4.3, but it appears to generate
1537 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
1538 CFLAGS="$CFLAGS -Wlogical-op"
1541 if test x$have_shorten64_flag = xyes ; then
1542 CFLAGS="$CFLAGS -Wshorten-64-to-32"
1547 ##This will break the world on some 64-bit architectures
1548 # CFLAGS="$CFLAGS -Winline"
1551 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1554 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.])
1558 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1563 contrib/dist/suse/tor.sh
1564 contrib/operator-tools/tor.logrotate
1567 contrib/dist/tor.service
1568 src/config/torrc.sample
1571 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1572 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1573 for file in $regular_mans ; do
1574 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1575 echo "==================================";
1577 echo "You need asciidoc installed to be able to build the manpage.";
1578 echo "To build without manpages, use the --disable-asciidoc argument";
1579 echo "when calling configure.";
1581 echo "==================================";
1589 if test -x /usr/bin/perl && test -x ./scripts/maint/updateVersions.pl ; then
1590 ./scripts/maint/updateVersions.pl