In routerlist_assert_ok(), check r2 before taking &(r2->cache_info)
[tor.git] / configure.ac
blobc37f15422252ff25b20c693bdaaedc39bbf13f1f
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.6-alpha])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AC_CONFIG_MACRO_DIR([m4])
9 AM_INIT_AUTOMAKE
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AC_CONFIG_HEADERS([orconfig.h])
13 AC_CANONICAL_HOST
15 if test -f /etc/redhat-release ; then
16   if test -f /usr/kerberos/include ; then
17     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
18   fi
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
87         yes) asciidoc=true ;;
88         no)  asciidoc=false ;;
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
96         yes) natpmp=true ;;
97         no)  natpmp=false ;;
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
102 AC_ARG_ENABLE(upnp,
103      AS_HELP_STRING(--enable-upnp, enable UPnP support),
104      [case "${enableval}" in
105         yes) upnp=true ;;
106         no)  upnp=false ;;
107         * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
108       esac], [upnp=false])
111 AC_ARG_ENABLE(threads,
112      AS_HELP_STRING(--disable-threads, disable multi-threading support))
114 if test x$enable_threads = x; then
115    case $host in
116     *-*-solaris* )
117      # Don't try multithreading on solaris -- cpuworkers seem to lock.
118      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
119 cpu workers lock up here, so I will disable threads.])
120      enable_threads="no";;
121     *)
122      enable_threads="yes";;
123    esac
126 if test "$enable_threads" = "yes"; then
127   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
130 case $host in
131    *-*-solaris* )
132      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
133      ;;
134 esac
136 AC_ARG_ENABLE(gcc-warnings,
137      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
138 AC_ARG_ENABLE(gcc-warnings-advisory,
139      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
141 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
142 AC_ARG_ENABLE(gcc-hardening,
143     AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
145 AC_ARG_ENABLE(expensive-hardening,
146     AS_HELP_STRING(--enable-expensive-hardening, enable more expensive compiler hardening; makes Tor slower))
148 dnl Linker hardening options
149 dnl Currently these options are ELF specific - you can't use this with MacOSX
150 AC_ARG_ENABLE(linker-hardening,
151     AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
153 AC_ARG_ENABLE(local-appdata,
154    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
155 if test "$enable_local_appdata" = "yes"; then
156   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
157             [Defined if we default to host local appdata paths on Windows])
160 # Tor2web mode flag
161 AC_ARG_ENABLE(tor2web-mode,
162      AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
163 [if test x$enableval = xyes; then
164     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
165 fi])
167 AC_ARG_ENABLE(bufferevents,
168      AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
170 AC_ARG_ENABLE(tool-name-check,
171      AS_HELP_STRING(--disable-tool-name-check, check for sanely named toolchain when cross-compiling))
173 AC_ARG_ENABLE(seccomp,
174      AS_HELP_STRING(--disable-seccomp, do not attempt to use libseccomp))
176 dnl check for the correct "ar" when cross-compiling
177 AN_MAKEVAR([AR], [AC_PROG_AR])
178 AN_PROGRAM([ar], [AC_PROG_AR])
179 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
180 AC_PROG_AR
182 dnl Check whether the above macro has settled for a simply named tool even
183 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
184 dnl because that will find any cc on the system, not only the cross-compiler,
185 dnl and then verify that a binary built with this compiler runs on the
186 dnl build system. It will then come to the false conclusion that we're not
187 dnl cross-compiling.
188 if test x$enable_tool_name_check != xno; then
189     if test x$ac_tool_warned = xyes; then
190         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.)])
191         elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
192                 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.)])
193         fi
196 AC_PROG_CC
197 AC_PROG_CPP
198 AC_PROG_MAKE_SET
199 AC_PROG_RANLIB
201 dnl autoconf 2.59 appears not to support AC_PROG_SED
202 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
204 dnl check for asciidoc and a2x
205 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
206 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
208 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
210 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
211 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
212 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
213 AM_PROG_CC_C_O
215 AC_ARG_VAR(PYTHON)
216 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
217 if test "x$PYTHON" = "x"; then
218   AC_MSG_WARN([Python unavailable; some tests will not be run.])
220 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
222 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
223 AC_C_FLEXIBLE_ARRAY_MEMBER
224 ], [
225  dnl Maybe we've got an old autoconf...
226  AC_CACHE_CHECK([for flexible array members],
227      tor_cv_c_flexarray,
228      [AC_COMPILE_IFELSE(
229        AC_LANG_PROGRAM([
230  struct abc { int a; char b[]; };
231 ], [
232  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
233  def->b[0] = 33;
235   [tor_cv_c_flexarray=yes],
236   [tor_cv_c_flexarray=no])])
237  if test $tor_cv_flexarray = yes ; then
238    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
239  else
240    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
241  fi
244 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
245 AC_PATH_PROG([OPENSSL], [openssl], none)
247 TORUSER=_tor
248 AC_ARG_WITH(tor-user,
249         [  --with-tor-user=NAME    Specify username for tor daemon ],
250         [
251            TORUSER=$withval
252         ]
254 AC_SUBST(TORUSER)
256 TORGROUP=_tor
257 AC_ARG_WITH(tor-group,
258         [  --with-tor-group=NAME   Specify group name for tor daemon ],
259         [
260            TORGROUP=$withval
261         ]
263 AC_SUBST(TORGROUP)
266 dnl If _WIN32 is defined and non-zero, we are building for win32
267 AC_MSG_CHECKING([for win32])
268 AC_RUN_IFELSE([AC_LANG_SOURCE([
269 int main(int c, char **v) {
270 #ifdef _WIN32
271 #if _WIN32
272   return 0;
273 #else
274   return 1;
275 #endif
276 #else
277   return 2;
278 #endif
279 }])],
280 bwin32=true; AC_MSG_RESULT([yes]),
281 bwin32=false; AC_MSG_RESULT([no]),
282 bwin32=cross; AC_MSG_RESULT([cross])
285 if test "$bwin32" = cross; then
286 AC_MSG_CHECKING([for win32 (cross)])
287 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
288 #ifdef _WIN32
289 int main(int c, char **v) {return 0;}
290 #else
291 #error
292 int main(int c, char **v) {return x(y);}
293 #endif
294 ])],
295 bwin32=true; AC_MSG_RESULT([yes]),
296 bwin32=false; AC_MSG_RESULT([no]))
299 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
301 dnl Enable C99 when compiling with MIPSpro
302 AC_MSG_CHECKING([for MIPSpro compiler])
303 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
304 #if (defined(__sgi) && defined(_COMPILER_VERSION))
305 #error
306   return x(y);
307 #endif
308 ])],
309 bmipspro=false; AC_MSG_RESULT(no),
310 bmipspro=true; AC_MSG_RESULT(yes))
312 if test "$bmipspro" = true; then
313   CFLAGS="$CFLAGS -c99"
316 AC_C_BIGENDIAN
318 AC_SEARCH_LIBS(socket, [socket network])
319 AC_SEARCH_LIBS(gethostbyname, [nsl])
320 AC_SEARCH_LIBS(dlopen, [dl])
321 AC_SEARCH_LIBS(inet_aton, [resolv])
322 saved_LIBS="$LIBS"
323 AC_SEARCH_LIBS([clock_gettime], [rt])
324 if test "$LIBS" != "$saved_LIBS"; then
325    # Looks like we need -lrt for clock_gettime().
326    have_rt=yes
329 if test "$enable_threads" = "yes"; then
330   AC_SEARCH_LIBS(pthread_create, [pthread])
331   AC_SEARCH_LIBS(pthread_detach, [pthread])
334 dnl -------------------------------------------------------------------
335 dnl Check for functions before libevent, since libevent-1.2 apparently
336 dnl exports strlcpy without defining it in a header.
338 AC_CHECK_FUNCS(
339         _NSGetEnviron \
340         accept4 \
341         backtrace \
342         backtrace_symbols_fd \
343         clock_gettime \
344         flock \
345         ftime \
346         getaddrinfo \
347         getifaddrs \
348         getrlimit \
349         gettimeofday \
350         gmtime_r \
351         inet_aton \
352         ioctl \
353         issetugid \
354         llround \
355         localtime_r \
356         lround \
357         memmem \
358         prctl \
359         rint \
360         sigaction \
361         socketpair \
362         strlcat \
363         strlcpy \
364         strptime \
365         strtok_r \
366         strtoull \
367         sysconf \
368         sysctl \
369         uname \
370         usleep \
371         vasprintf \
372         _vscprintf
375 if test "$enable_threads" = "yes"; then
376   AC_CHECK_HEADERS(pthread.h)
377   AC_CHECK_FUNCS(pthread_create)
380 dnl ------------------------------------------------------
381 dnl Where do you live, libevent?  And how do we call you?
383 if test "$bwin32" = true; then
384   TOR_LIB_WS32=-lws2_32
385   TOR_LIB_IPHLPAPI=-liphlpapi
386   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
387   # think it's actually necessary.
388   TOR_LIB_GDI=-lgdi32
389 else
390   TOR_LIB_WS32=
391   TOR_LIB_GDI=
393 AC_SUBST(TOR_LIB_WS32)
394 AC_SUBST(TOR_LIB_GDI)
395 AC_SUBST(TOR_LIB_IPHLPAPI)
397 dnl We need to do this before we try our disgusting hack below.
398 AC_CHECK_HEADERS([sys/types.h])
400 dnl This is a disgusting hack so we safely include older libevent headers.
401 AC_CHECK_TYPE(u_int64_t, unsigned long long)
402 AC_CHECK_TYPE(u_int32_t, unsigned long)
403 AC_CHECK_TYPE(u_int16_t, unsigned short)
404 AC_CHECK_TYPE(u_int8_t, unsigned char)
406 tor_libevent_pkg_redhat="libevent"
407 tor_libevent_pkg_debian="libevent-dev"
408 tor_libevent_devpkg_redhat="libevent-devel"
409 tor_libevent_devpkg_debian="libevent-dev"
411 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
412 dnl linking for static builds.
413 STATIC_LIBEVENT_FLAGS=""
414 if test "$enable_static_libevent" = "yes"; then
415     if test "$have_rt" = yes; then
416       STATIC_LIBEVENT_FLAGS=" -lrt "
417     fi
420 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
421 #ifdef _WIN32
422 #include <winsock2.h>
423 #endif
424 #include <stdlib.h>
425 #include <sys/time.h>
426 #include <sys/types.h>
427 #include <event.h>], [
428 #ifdef _WIN32
429 #include <winsock2.h>
430 #endif
431 void exit(int); void *event_init(void);],
432     [
433 #ifdef _WIN32
434 {WSADATA d; WSAStartup(0x101,&d); }
435 #endif
436 event_init(); exit(0);
437 ], [--with-libevent-dir], [/opt/libevent])
439 dnl Now check for particular libevent functions.
440 save_LIBS="$LIBS"
441 save_LDFLAGS="$LDFLAGS"
442 save_CPPFLAGS="$CPPFLAGS"
443 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
444 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
445 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
446 AC_CHECK_FUNCS([event_get_version \
447                 event_get_version_number \
448                 event_get_method \
449                 event_set_log_callback \
450                 evutil_secure_rng_set_urandom_device_file \
451                 evutil_secure_rng_init \
452                 event_base_loopexit])
453 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
454 [#include <event.h>
457 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
459 LIBS="$save_LIBS"
460 LDFLAGS="$save_LDFLAGS"
461 CPPFLAGS="$save_CPPFLAGS"
464 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
466 if test "$enable_static_libevent" = "yes"; then
467    if test "$tor_cv_library_libevent_dir" = "(system)"; then
468      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
469    else
470      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
471    fi
472 else
473      TOR_LIBEVENT_LIBS="-levent"
476 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
477 dnl we can do much better.
478 if test "$enable_bufferevents" = "yes" ; then
479   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
480     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.])
481   else
483     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
485     # Check for the right version.  First see if version detection works.
486     AC_MSG_CHECKING([whether we can detect the Libevent version])
487     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
488 #include <event2/event.h>
489 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
490 #error
491 int x = y(zz);
492 #else
493 int x = 1;
494 #endif
495   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
496      [event_version_number_works=no;  AC_MSG_RESULT([no])])
497     if test "$event_version_number_works" != 'yes'; then
498       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
499     else
500       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
501       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
502 #include <event2/event.h>
503 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
504 #error
505 int x = y(zz);
506 #else
507 int x = 1;
508 #endif
509    ])], [ AC_MSG_RESULT([yes]) ],
510       [ AC_MSG_RESULT([no])
511         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
512     fi
513   fi
516 LIBS="$save_LIBS"
517 LDFLAGS="$save_LDFLAGS"
518 CPPFLAGS="$save_CPPFLAGS"
520 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
521 if test "$enable_bufferevents" = "yes"; then
522   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
523   if test "$enable_static_libevent" = "yes"; then
524     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
525   else
526     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
527   fi
529 AC_SUBST(TOR_LIBEVENT_LIBS)
531 dnl ------------------------------------------------------
532 dnl Where do you live, libm?
534 dnl On some platforms (Haiku/BeOS) the math library is
535 dnl part of libroot. In which case don't link against lm
536 TOR_LIB_MATH=""
537 save_LIBS="$LIBS"
538 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
539 if test "$ac_cv_search_pow" != "none required"; then
540     TOR_LIB_MATH="$ac_cv_search_pow"
542 LIBS="$save_LIBS"
543 AC_SUBST(TOR_LIB_MATH)
545 dnl ------------------------------------------------------
546 dnl Where do you live, openssl?  And how do we call you?
548 tor_openssl_pkg_redhat="openssl"
549 tor_openssl_pkg_debian="libssl-dev"
550 tor_openssl_devpkg_redhat="openssl-devel"
551 tor_openssl_devpkg_debian="libssl-dev"
553 ALT_openssl_WITHVAL=""
554 AC_ARG_WITH(ssl-dir,
555   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
556   [
557       if test "x$withval" != xno && test "x$withval" != "x" ; then
558          ALT_openssl_WITHVAL="$withval"
559       fi
560   ])
562 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
563     [#include <openssl/rand.h>],
564     [void RAND_add(const void *buf, int num, double entropy);],
565     [RAND_add((void*)0,0,0); exit(0);], [],
566     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
568 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
570 if test "$enable_static_openssl" = "yes"; then
571    if test "$tor_cv_library_openssl_dir" = "(system)"; then
572      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
573    else
574      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
575    fi
576 else
577      TOR_OPENSSL_LIBS="-lssl -lcrypto"
579 AC_SUBST(TOR_OPENSSL_LIBS)
581 dnl ------------------------------------------------------
582 dnl Where do you live, zlib?  And how do we call you?
584 tor_zlib_pkg_redhat="zlib"
585 tor_zlib_pkg_debian="zlib1g"
586 tor_zlib_devpkg_redhat="zlib-devel"
587 tor_zlib_devpkg_debian="zlib1g-dev"
589 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
590     [#include <zlib.h>],
591     [const char * zlibVersion(void);],
592     [zlibVersion(); exit(0);], [--with-zlib-dir],
593     [/opt/zlib])
595 if test "$enable_static_zlib" = "yes"; then
596    if test "$tor_cv_library_zlib_dir" = "(system)"; then
597      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
598  using --enable-static-zlib")
599    else
600      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
601    fi
602 else
603      TOR_ZLIB_LIBS="-lz"
605 AC_SUBST(TOR_ZLIB_LIBS)
607 dnl ---------------------------------------------------------------------
608 dnl Now that we know about our major libraries, we can check for compiler
609 dnl and linker hardening options.  We need to do this with the libraries known,
610 dnl since sometimes the linker will like an option but not be willing to
611 dnl use it with a build of a library.
613 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
614 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
616 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
617 #if !defined(__clang__)
618 #error
619 #endif])], have_clang=yes, have_clang=no)
621 if test x$enable_gcc_hardening != xno; then
622     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
623     if test x$have_clang = xyes; then
624         TOR_CHECK_CFLAGS(-Qunused-arguments)
625     fi
626     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
627     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
628     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
629     AS_VAR_IF(can_compile, [yes],
630         AS_VAR_IF(can_link, [yes],
631                   [],
632                   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.)]))
633         )
634     AS_VAR_POPDEF([can_link])
635     AS_VAR_POPDEF([can_compile])
636     TOR_CHECK_CFLAGS(-Wstack-protector)
637     TOR_CHECK_CFLAGS(-fwrapv)
638     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
639     if test "$bwin32" = "false"; then
640        TOR_CHECK_CFLAGS(-fPIE)
641        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
642     fi
645 if test x$enable_expensive_hardening = xyes ; then
646    TOR_CHECK_CFLAGS([-fsanitize=address])
647    TOR_CHECK_CFLAGS([-fsanitize=undefined])
648    TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
651 if test x$enable_linker_hardening != xno; then
652     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
655 # For backtrace support
656 TOR_CHECK_LDFLAGS(-rdynamic)
658 dnl ------------------------------------------------------
659 dnl Now see if we have a -fomit-frame-pointer compiler option.
661 saved_CFLAGS="$CFLAGS"
662 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
663 F_OMIT_FRAME_POINTER=''
664 if test "$saved_CFLAGS" != "$CFLAGS"; then
665   if test x$enable_expensive_hardening != xyes ; then
666     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
667   fi
669 CFLAGS="$saved_CFLAGS"
670 AC_SUBST(F_OMIT_FRAME_POINTER)
672 dnl ------------------------------------------------------
673 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
674 dnl for us, as GCC 4.6 and later do at many optimization levels), then
675 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
676 dnl code will work.
677 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
679 dnl ------------------------------------------------------
680 dnl Where do you live, libnatpmp?  And how do we call you?
681 dnl There are no packages for Debian or Redhat as of this patch
683 if test "$natpmp" = "true"; then
684     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
685     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
686         [#include <natpmp.h>],
687         [#ifdef _WIN32
688          #define STATICLIB
689          #endif
690          #include <natpmp.h>],
691         [   int r;
692             natpmp_t natpmp;
693             natpmpresp_t response;
694             r = initnatpmp(&natpmp, 0, 0);],
695             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
696             exit(0);],
697         [--with-libnatpmp-dir],
698         [/usr/lib/])
702 dnl ------------------------------------------------------
703 dnl Where do you live, libminiupnpc?  And how do we call you?
704 dnl There are no packages for Debian or Redhat as of this patch
706 if test "$upnp" = "true"; then
707     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
709     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
710     dnl to see if we have miniupnpc-1.5 or -1.6
711     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
712         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
714     if test "$miniupnpc15" = "true" ; then
715         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
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);],
722             [upnpDiscover(1, 0, 0, 0); exit(0);],
723             [--with-libminiupnpc-dir],
724             [/usr/lib/])
725     else
726         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
727             [#include <miniupnpc/miniwget.h>
728              #include <miniupnpc/miniupnpc.h>
729              #include <miniupnpc/upnpcommands.h>],
730             [void upnpDiscover(int delay, const char * multicastif,
731              const char * minissdpdsock, int sameport, int ipv6, int * error);],
732             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
733             [--with-libminiupnpc-dir],
734             [/usr/lib/])
735     fi
738 dnl ============================================================
739 dnl Check for libseccomp
741 if test "x$enable_seccomp" != "xno"; then
742   AC_CHECK_HEADERS([seccomp.h])
743   AC_SEARCH_LIBS(seccomp_init, [seccomp])
746 dnl ============================================================
747 dnl We need an implementation of curve25519.
749 dnl set these defaults.
750 have_a_curve25519=no
751 build_curve25519_donna=no
752 build_curve25519_donna_c64=no
753 use_curve25519_donna=no
754 use_curve25519_nacl=no
755 CURVE25519_LIBS=
757 if test x$enable_curve25519 != xno; then
759   dnl The best choice is using curve25519-donna-c64, but that requires
760   dnl that we
761   AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
762     tor_cv_can_use_curve25519_donna_c64,
763     [AC_RUN_IFELSE(
764       [AC_LANG_PROGRAM([dnl
765         #include <stdint.h>
766         typedef unsigned uint128_t __attribute__((mode(TI)));
767         int func(uint64_t a, uint64_t b) {
768              uint128_t c = ((uint128_t)a) * b;
769              int ok = ((uint64_t)(c>>96)) == 522859 &&
770                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
771                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
772                    (((uint64_t)(c))&0xffffffffL) == 0;
773              return ok;
774         }
775         ], [dnl
776           int ok = func( ((uint64_t)2000000000) * 1000000000,
777                          ((uint64_t)1234567890) << 24);
778           return !ok;
779         ])],
780         [tor_cv_can_use_curve25519_donna_c64=yes],
781         [tor_cv_can_use_curve25519_donna_c64=no],
782         [AC_LINK_IFELSE(
783           [AC_LANG_PROGRAM([dnl
784         #include <stdint.h>
785         typedef unsigned uint128_t __attribute__((mode(TI)));
786         int func(uint64_t a, uint64_t b) {
787              uint128_t c = ((uint128_t)a) * b;
788              int ok = ((uint64_t)(c>>96)) == 522859 &&
789                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
790                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
791                    (((uint64_t)(c))&0xffffffffL) == 0;
792              return ok;
793         }
794         ], [dnl
795           int ok = func( ((uint64_t)2000000000) * 1000000000,
796                          ((uint64_t)1234567890) << 24);
797           return !ok;
798         ])],
799             [tor_cv_can_use_curve25519_donna_c64=cross],
800             [tor_cv_can_use_curve25519_donna_c64=no])])])
802   AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
803                     nacl/crypto_scalarmult_curve25519.h])
805   AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
806     tor_cv_can_use_curve25519_nacl,
807     [tor_saved_LIBS="$LIBS"
808      LIBS="$LIBS -lnacl"
809      AC_LINK_IFELSE(
810        [AC_LANG_PROGRAM([dnl
811          #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
812          #include <crypto_scalarmult_curve25519.h>
813          #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
814          #include <nacl/crypto_scalarmult_curve25519.h>
815          #endif
816          #ifdef crypto_scalarmult_curve25519_ref_BYTES
817          #error Hey, this is the reference implementation! That's not fast.
818          #endif
819        ], [
820          unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
821        ])], [tor_cv_can_use_curve25519_nacl=yes],
822        [tor_cv_can_use_curve25519_nacl=no])
823      LIBS="$tor_saved_LIBS" ])
825    dnl Okay, now we need to figure out which one to actually use. Fall back
826    dnl to curve25519-donna.c
828    if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
829      build_curve25519_donna_c64=yes
830      use_curve25519_donna=yes
831    elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
832      use_curve25519_nacl=yes
833      CURVE25519_LIBS=-lnacl
834    else
835      build_curve25519_donna=yes
836      use_curve25519_donna=yes
837    fi
838    have_a_curve25519=yes
841 if test x$have_a_curve25519 = xyes; then
842   AC_DEFINE(CURVE25519_ENABLED, 1,
843             [Defined if we have a curve25519 implementation])
845 if test x$use_curve25519_donna = xyes; then
846   AC_DEFINE(USE_CURVE25519_DONNA, 1,
847             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
849 if test x$use_curve25519_nacl = xyes; then
850   AC_DEFINE(USE_CURVE25519_NACL, 1,
851             [Defined if we should use a curve25519 from nacl])
853 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
854 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
855 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
856 AC_SUBST(CURVE25519_LIBS)
858 dnl Make sure to enable support for large off_t if available.
859 AC_SYS_LARGEFILE
861 AC_CHECK_HEADERS(
862         assert.h \
863         errno.h \
864         fcntl.h \
865         signal.h \
866         string.h \
867         sys/fcntl.h \
868         sys/stat.h \
869         sys/time.h \
870         sys/types.h \
871         time.h \
872         unistd.h
873  , , 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.))
875 dnl These headers are not essential
877 AC_CHECK_HEADERS(
878         arpa/inet.h \
879         crt_externs.h \
880         execinfo.h \
881         grp.h \
882         ifaddrs.h \
883         inttypes.h \
884         limits.h \
885         linux/types.h \
886         machine/limits.h \
887         malloc.h \
888         malloc/malloc.h \
889         malloc_np.h \
890         netdb.h \
891         netinet/in.h \
892         netinet/in6.h \
893         pwd.h \
894         stdint.h \
895         sys/file.h \
896         sys/ioctl.h \
897         sys/limits.h \
898         sys/mman.h \
899         sys/param.h \
900         sys/prctl.h \
901         sys/resource.h \
902         sys/select.h \
903         sys/socket.h \
904         sys/sysctl.h \
905         sys/syslimits.h \
906         sys/time.h \
907         sys/types.h \
908         sys/un.h \
909         sys/utime.h \
910         sys/wait.h \
911         syslog.h \
912         utime.h
915 AC_CHECK_HEADERS(sys/param.h)
917 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
918 [#ifdef HAVE_SYS_TYPES_H
919 #include <sys/types.h>
920 #endif
921 #ifdef HAVE_SYS_SOCKET_H
922 #include <sys/socket.h>
923 #endif])
924 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
925 [#ifdef HAVE_SYS_TYPES_H
926 #include <sys/types.h>
927 #endif
928 #ifdef HAVE_SYS_SOCKET_H
929 #include <sys/socket.h>
930 #endif
931 #ifdef HAVE_NET_IF_H
932 #include <net/if.h>
933 #endif])
934 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
935         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
936 [#ifdef HAVE_SYS_TYPES_H
937 #include <sys/types.h>
938 #endif
939 #ifdef HAVE_SYS_SOCKET_H
940 #include <sys/socket.h>
941 #endif
942 #ifdef HAVE_LIMITS_H
943 #include <limits.h>
944 #endif
945 #ifdef HAVE_LINUX_TYPES_H
946 #include <linux/types.h>
947 #endif
948 #ifdef HAVE_NETINET_IN6_H
949 #include <netinet/in6.h>
950 #endif
951 #ifdef HAVE_NETINET_IN_H
952 #include <netinet/in.h>
953 #endif])
955 if test x$transparent = xtrue ; then
956    transparent_ok=0
957    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
958      transparent_ok=1
959    fi
960    if test x$linux_netfilter_ipv4 = x1 ; then
961      transparent_ok=1
962    fi
963    if test x$transparent_ok = x1 ; then
964      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
965      case $host in
966        *-*-openbsd* | *-*-bitrig*)
967          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
968      esac
969    else
970      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
971    fi
974 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
975 [#ifdef HAVE_SYS_TYPES_H
976 #include <sys/types.h>
977 #endif
978 #ifdef HAVE_SYS_TIME_H
979 #include <sys/time.h>
980 #endif])
982 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
983 dnl Watch out.
985 AC_CHECK_SIZEOF(int8_t)
986 AC_CHECK_SIZEOF(int16_t)
987 AC_CHECK_SIZEOF(int32_t)
988 AC_CHECK_SIZEOF(int64_t)
989 AC_CHECK_SIZEOF(uint8_t)
990 AC_CHECK_SIZEOF(uint16_t)
991 AC_CHECK_SIZEOF(uint32_t)
992 AC_CHECK_SIZEOF(uint64_t)
993 AC_CHECK_SIZEOF(intptr_t)
994 AC_CHECK_SIZEOF(uintptr_t)
996 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
998 AC_CHECK_SIZEOF(char)
999 AC_CHECK_SIZEOF(short)
1000 AC_CHECK_SIZEOF(int)
1001 AC_CHECK_SIZEOF(long)
1002 AC_CHECK_SIZEOF(long long)
1003 AC_CHECK_SIZEOF(__int64)
1004 AC_CHECK_SIZEOF(void *)
1005 AC_CHECK_SIZEOF(time_t)
1006 AC_CHECK_SIZEOF(size_t)
1007 AC_CHECK_SIZEOF(pid_t)
1009 AC_CHECK_TYPES([uint, u_char, ssize_t])
1011 AC_PC_FROM_UCONTEXT([/bin/true])
1013 dnl used to include sockaddr_storage, but everybody has that.
1014 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1015 [#ifdef HAVE_SYS_TYPES_H
1016 #include <sys/types.h>
1017 #endif
1018 #ifdef HAVE_NETINET_IN_H
1019 #include <netinet/in.h>
1020 #endif
1021 #ifdef HAVE_NETINET_IN6_H
1022 #include <netinet/in6.h>
1023 #endif
1024 #ifdef HAVE_SYS_SOCKET_H
1025 #include <sys/socket.h>
1026 #endif
1027 #ifdef _WIN32
1028 #define _WIN32_WINNT 0x0501
1029 #define WIN32_LEAN_AND_MEAN
1030 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1031 #include <winsock.h>
1032 #else
1033 #include <winsock2.h>
1034 #include <ws2tcpip.h>
1035 #endif
1036 #endif
1038 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1039 [#ifdef HAVE_SYS_TYPES_H
1040 #include <sys/types.h>
1041 #endif
1042 #ifdef HAVE_NETINET_IN_H
1043 #include <netinet/in.h>
1044 #endif
1045 #ifdef HAVE_NETINET_IN6_H
1046 #include <netinet/in6.h>
1047 #endif
1048 #ifdef HAVE_SYS_SOCKET_H
1049 #include <sys/socket.h>
1050 #endif
1051 #ifdef _WIN32
1052 #define _WIN32_WINNT 0x0501
1053 #define WIN32_LEAN_AND_MEAN
1054 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1055 #include <winsock.h>
1056 #else
1057 #include <winsock2.h>
1058 #include <ws2tcpip.h>
1059 #endif
1060 #endif
1063 AC_CHECK_TYPES([rlim_t], , ,
1064 [#ifdef HAVE_SYS_TYPES_H
1065 #include <sys/types.h>
1066 #endif
1067 #ifdef HAVE_SYS_TIME_H
1068 #include <sys/time.h>
1069 #endif
1070 #ifdef HAVE_SYS_RESOURCE_H
1071 #include <sys/resource.h>
1072 #endif
1075 AX_CHECK_SIGN([time_t],
1076        [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1077        [ : ], [
1078 #ifdef HAVE_SYS_TYPES_H
1079 #include <sys/types.h>
1080 #endif
1081 #ifdef HAVE_SYS_TIME_H
1082 #include <sys/time.h>
1083 #endif
1084 #ifdef HAVE_TIME_H
1085 #include <time.h>
1086 #endif
1089 if test "$ax_cv_decl_time_t_signed" = no; then
1090   AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1093 AX_CHECK_SIGN([size_t],
1094        [ tor_cv_size_t_signed=yes ],
1095        [ tor_cv_size_t_signed=no ], [
1096 #ifdef HAVE_SYS_TYPES_H
1097 #include <sys/types.h>
1098 #endif
1101 if test "$ax_cv_decl_size_t_signed" = yes; then
1102   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1105 AX_CHECK_SIGN([enum always],
1106        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1107        [ : ], [
1108  enum always { AAA, BBB, CCC };
1111 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1112 #ifdef HAVE_SYS_SOCKET_H
1113 #include <sys/socket.h>
1114 #endif
1117 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1119 AC_CHECK_SIZEOF(cell_t)
1121 # Now make sure that NULL can be represented as zero bytes.
1122 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1123 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1124 [[#include <stdlib.h>
1125 #include <string.h>
1126 #include <stdio.h>
1127 #ifdef HAVE_STDDEF_H
1128 #include <stddef.h>
1129 #endif
1130 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1131 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1132        [tor_cv_null_is_zero=yes],
1133        [tor_cv_null_is_zero=no],
1134        [tor_cv_null_is_zero=cross])])
1136 if test "$tor_cv_null_is_zero" = cross ; then
1137   # Cross-compiling; let's hope that the target isn't raving mad.
1138   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1141 if test "$tor_cv_null_is_zero" != no; then
1142   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1143             [Define to 1 iff memset(0) sets pointers to NULL])
1146 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1147 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1148 [[#include <stdlib.h>
1149 #include <string.h>
1150 #include <stdio.h>
1151 #ifdef HAVE_STDDEF_H
1152 #include <stddef.h>
1153 #endif
1154 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1155 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1156        [tor_cv_dbl0_is_zero=yes],
1157        [tor_cv_dbl0_is_zero=no],
1158        [tor_cv_dbl0_is_zero=cross])])
1160 if test "$tor_cv_dbl0_is_zero" = cross ; then
1161   # Cross-compiling; let's hope that the target isn't raving mad.
1162   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1165 if test "$tor_cv_dbl0_is_zero" != no; then
1166   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1167             [Define to 1 iff memset(0) sets doubles to 0.0])
1170 # And what happens when we malloc zero?
1171 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1172 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1173 [[#include <stdlib.h>
1174 #include <string.h>
1175 #include <stdio.h>
1176 #ifdef HAVE_STDDEF_H
1177 #include <stddef.h>
1178 #endif
1179 int main () { return malloc(0)?0:1; }]])],
1180        [tor_cv_malloc_zero_works=yes],
1181        [tor_cv_malloc_zero_works=no],
1182        [tor_cv_malloc_zero_works=cross])])
1184 if test "$tor_cv_malloc_zero_works" = cross; then
1185   # Cross-compiling; let's hope that the target isn't raving mad.
1186   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1189 if test "$tor_cv_malloc_zero_works" = yes; then
1190   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1191             [Define to 1 iff malloc(0) returns a pointer])
1194 # whether we seem to be in a 2s-complement world.
1195 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1196 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1197 [[int main () { int problem = ((-99) != (~99)+1);
1198 return problem ? 1 : 0; }]])],
1199        [tor_cv_twos_complement=yes],
1200        [tor_cv_twos_complement=no],
1201        [tor_cv_twos_complement=cross])])
1203 if test "$tor_cv_twos_complement" = cross ; then
1204   # Cross-compiling; let's hope that the target isn't raving mad.
1205   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1208 if test "$tor_cv_twos_complement" != no ; then
1209   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1210             [Define to 1 iff we represent negative integers with two's complement])
1213 # What does shifting a negative value do?
1214 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1215 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1216 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1217        [tor_cv_sign_extend=yes],
1218        [tor_cv_sign_extend=no],
1219        [tor_cv_sign_extend=cross])])
1221 if test "$tor_cv_sign_extend" = cross ; then
1222   # Cross-compiling; let's hope that the target isn't raving mad.
1223   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1226 if test "$tor_cv_sign_extend" != no ; then
1227   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1228             [Define to 1 iff right-shifting a negative value performs sign-extension])
1231 # Whether we should use the dmalloc memory allocation debugging library.
1232 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1233 AC_ARG_WITH(dmalloc,
1234 [  --with-dmalloc          Use debug memory allocation library. ],
1235 [if [[ "$withval" = "yes" ]]; then
1236   dmalloc=1
1237   AC_MSG_RESULT(yes)
1238 else
1239   dmalloc=1
1240   AC_MSG_RESULT(no)
1241 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1244 if [[ $dmalloc -eq 1 ]]; then
1245   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1246   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1247   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1248   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1251 AC_ARG_WITH(tcmalloc,
1252 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1253 [ tcmalloc=yes ], [ tcmalloc=no ])
1255 if test x$tcmalloc = xyes ; then
1256    LDFLAGS="-ltcmalloc $LDFLAGS"
1259 using_custom_malloc=no
1260 if test x$enable_openbsd_malloc = xyes ; then
1261    using_custom_malloc=yes
1263 if test x$tcmalloc = xyes ; then
1264    using_custom_malloc=yes
1266 if test $using_custom_malloc = no ; then
1267    AC_CHECK_FUNCS(mallinfo)
1270 # By default, we're going to assume we don't have mlockall()
1271 # bionic and other platforms have various broken mlockall subsystems.
1272 # Some systems don't have a working mlockall, some aren't linkable,
1273 # and some have it but don't declare it.
1274 AC_CHECK_FUNCS(mlockall)
1275 AC_CHECK_DECLS([mlockall], , , [
1276 #ifdef HAVE_SYS_MMAN_H
1277 #include <sys/mman.h>
1278 #endif])
1280 # Allow user to specify an alternate syslog facility
1281 AC_ARG_WITH(syslog-facility,
1282 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1283 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1284 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1285 AC_SUBST(LOGFACILITY)
1287 # Check if we have getresuid and getresgid
1288 AC_CHECK_FUNCS(getresuid getresgid)
1290 # Check for gethostbyname_r in all its glorious incompatible versions.
1291 #   (This logic is based on that in Python's configure.in)
1292 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1293   [Define this if you have any gethostbyname_r()])
1295 AC_CHECK_FUNC(gethostbyname_r, [
1296   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1297   OLD_CFLAGS=$CFLAGS
1298   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1299   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1300 #include <netdb.h>
1301   ], [[
1302     char *cp1, *cp2;
1303     struct hostent *h1, *h2;
1304     int i1, i2;
1305     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1306   ]])],[
1307     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1308     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1309      [Define this if gethostbyname_r takes 6 arguments])
1310     AC_MSG_RESULT(6)
1311   ], [
1312     AC_TRY_COMPILE([
1313 #include <netdb.h>
1314     ], [
1315       char *cp1, *cp2;
1316       struct hostent *h1;
1317       int i1, i2;
1318       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1319     ], [
1320       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1321       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1322         [Define this if gethostbyname_r takes 5 arguments])
1323       AC_MSG_RESULT(5)
1324    ], [
1325       AC_TRY_COMPILE([
1326 #include <netdb.h>
1327      ], [
1328        char *cp1;
1329        struct hostent *h1;
1330        struct hostent_data hd;
1331        (void) gethostbyname_r(cp1,h1,&hd);
1332      ], [
1333        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1334        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1335          [Define this if gethostbyname_r takes 3 arguments])
1336        AC_MSG_RESULT(3)
1337      ], [
1338        AC_MSG_RESULT(0)
1339      ])
1340   ])
1341  ])
1342  CFLAGS=$OLD_CFLAGS
1345 AC_CACHE_CHECK([whether the C compiler supports __func__],
1346   tor_cv_have_func_macro,
1347   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1348 #include <stdio.h>
1349 int main(int c, char **v) { puts(__func__); }])],
1350   tor_cv_have_func_macro=yes,
1351   tor_cv_have_func_macro=no))
1353 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1354   tor_cv_have_FUNC_macro,
1355   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1356 #include <stdio.h>
1357 int main(int c, char **v) { puts(__FUNC__); }])],
1358   tor_cv_have_FUNC_macro=yes,
1359   tor_cv_have_FUNC_macro=no))
1361 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1362   tor_cv_have_FUNCTION_macro,
1363   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1364 #include <stdio.h>
1365 int main(int c, char **v) { puts(__FUNCTION__); }])],
1366   tor_cv_have_FUNCTION_macro=yes,
1367   tor_cv_have_FUNCTION_macro=no))
1369 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1370   tor_cv_have_environ_declared,
1371   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1372 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1373  * Without it environ doesn't get declared. */
1374 #define _GNU_SOURCE
1375 #ifdef HAVE_UNISTD_H
1376 #include <unistd.h>
1377 #endif
1378 #include <stdlib.h>
1379 int main(int c, char **v) { char **t = environ; }])],
1380   tor_cv_have_environ_declared=yes,
1381   tor_cv_have_environ_declared=no))
1383 if test "$tor_cv_have_func_macro" = 'yes'; then
1384   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1387 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1388   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1391 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1392   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1393            [Defined if the compiler supports __FUNCTION__])
1396 if test "$tor_cv_have_environ_declared" = 'yes'; then
1397   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1398            [Defined if we have extern char **environ already declared])
1401 # $prefix stores the value of the --prefix command line option, or
1402 # NONE if the option wasn't set.  In the case that it wasn't set, make
1403 # it be the default, so that we can use it to expand directories now.
1404 if test "x$prefix" = "xNONE"; then
1405   prefix=$ac_default_prefix
1408 # and similarly for $exec_prefix
1409 if test "x$exec_prefix" = "xNONE"; then
1410   exec_prefix=$prefix
1413 if test "x$BUILDDIR" = "x"; then
1414   BUILDDIR=`pwd`
1416 AC_SUBST(BUILDDIR)
1417 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1418 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1420 if test "x$CONFDIR" = "x"; then
1421   CONFDIR=`eval echo $sysconfdir/tor`
1423 AC_SUBST(CONFDIR)
1424 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1425 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1427 BINDIR=`eval echo $bindir`
1428 AC_SUBST(BINDIR)
1429 LOCALSTATEDIR=`eval echo $localstatedir`
1430 AC_SUBST(LOCALSTATEDIR)
1432 if test "$bwin32" = true; then
1433   # Test if the linker supports the --nxcompat and --dynamicbase options
1434   # for Windows
1435   save_LDFLAGS="$LDFLAGS"
1436   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1437   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1438   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1439     [AC_MSG_RESULT([yes])]
1440     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1441     [AC_MSG_RESULT([no])]
1442   )
1443   LDFLAGS="$save_LDFLAGS"
1446 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1447 # than autoconf's macros like.
1448 if test "$GCC" = yes; then
1449   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1450   # accident waiting to happen.
1451   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1452 else
1453   # Autoconf sets -g -O2 by default. Override optimization level
1454   # for non-gcc compilers
1455   CFLAGS="$CFLAGS -O"
1456   enable_gcc_warnings=no
1457   enable_gcc_warnings_advisory=no
1460 # OS X Lion started deprecating the system openssl. Let's just disable
1461 # all deprecation warnings on OS X. Also, to potentially make the binary
1462 # a little smaller, let's enable dead_strip.
1463 case "$host_os" in
1465  darwin*)
1466     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1467     LDFLAGS="$LDFLAGS -dead_strip" ;;
1468 esac
1470 # Add some more warnings which we use in development but not in the
1471 # released versions.  (Some relevant gcc versions can't handle these.)
1472 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1474   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1475 #if !defined(__GNUC__) || (__GNUC__ < 4)
1476 #error
1477 #endif])], have_gcc4=yes, have_gcc4=no)
1479   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1480 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1481 #error
1482 #endif])], have_gcc42=yes, have_gcc42=no)
1484   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1485 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1486 #error
1487 #endif])], have_gcc43=yes, have_gcc43=no)
1489   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1490 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1491 #error
1492 #endif])], have_gcc46=yes, have_gcc46=no)
1495   save_CFLAGS="$CFLAGS"
1496   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1497   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1498                     have_shorten64_flag=no)
1499   CFLAGS="$save_CFLAGS"
1501   case $host in
1502     *-*-openbsd* | *-*-bitrig*)
1503       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1504       # That's fine, except that the headers don't pass -Wredundant-decls.
1505       # Therefore, let's disable -Wsystem-headers when we're building
1506       # with maximal warnings on OpenBSD.
1507       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1508   esac
1510   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1511   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1512   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1513   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1514   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1516   if test x$enable_gcc_warnings = xyes; then
1517     CFLAGS="$CFLAGS -Werror"
1518   fi
1520   # Disabled, so we can use mallinfo(): -Waggregate-return
1522   if test x$have_gcc4 = xyes ; then
1523     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1524     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1525   fi
1527   if test x$have_gcc42 = xyes ; then
1528     # These warnings break gcc 4.0.2 and work on gcc 4.2
1529     # XXXX020 See if any of these work with earlier versions.
1530     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1532     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1533   fi
1535   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1536     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1537     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1538   fi
1540   if test x$have_gcc43 = xyes ; then
1541     # These warnings break gcc 4.2 and work on gcc 4.3
1542     # XXXX020 See if any of these work with earlier versions.
1543     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1544   fi
1546   if test x$have_gcc46 = xyes ; then
1547     # This warning was added in gcc 4.3, but it appears to generate
1548     # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
1549     CFLAGS="$CFLAGS -Wlogical-op"
1550   fi
1552   if test x$have_shorten64_flag = xyes ; then
1553     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1554   fi
1558 ##This will break the world on some 64-bit architectures
1559 # CFLAGS="$CFLAGS -Winline"
1562 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1563    case "$host_os" in
1564     darwin*)
1565       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.])
1566    esac
1569 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1571 AC_CONFIG_FILES([
1572         Doxyfile
1573         Makefile
1574         contrib/dist/suse/tor.sh
1575         contrib/operator-tools/tor.logrotate
1576         contrib/dist/tor.sh
1577         contrib/dist/torctl
1578         contrib/dist/tor.service
1579         src/config/torrc.sample
1582 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1583   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1584   for file in $regular_mans ; do
1585     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1586       echo "==================================";
1587       echo;
1588       echo "You need asciidoc installed to be able to build the manpage.";
1589       echo "To build without manpages, use the --disable-asciidoc argument";
1590       echo "when calling configure.";
1591       echo;
1592       echo "==================================";
1593       exit 1;
1594     fi
1595   done
1598 AC_OUTPUT
1600 if test -x /usr/bin/perl && test -x ./scripts/maint/updateVersions.pl ; then
1601   ./scripts/maint/updateVersions.pl