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