Merge branch 'analyze_cg_more'
[tor.git] / configure.ac
blob3bb70ed88fc3d8daec8e00486225498e3eb0ba24
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2015, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT([tor],[0.2.7.2-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 PKG_PROG_PKG_CONFIG
17 if test -f /etc/redhat-release ; then
18   if test -f /usr/kerberos/include ; then
19     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
20   fi
23 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
24 # the += operator on it in src/or/Makefile.am
25 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
27 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
28 AC_ARG_ENABLE(openbsd-malloc,
29    AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD.  Linux only]))
30 AC_ARG_ENABLE(instrument-downloads,
31    AS_HELP_STRING(--enable-instrument-downloads, [instrument downloads of directory resources etc.]))
32 AC_ARG_ENABLE(static-openssl,
33    AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
34 AC_ARG_ENABLE(static-libevent,
35    AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
36 AC_ARG_ENABLE(static-zlib,
37    AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
38 AC_ARG_ENABLE(static-tor,
39    AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
40 AC_ARG_ENABLE(unittests,
41    AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
42 AC_ARG_ENABLE(coverage,
43    AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
44 AC_ARG_ENABLE(system-torrc,
45    AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
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 "$enable_system_torrc" = "no"; then
58   AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
59             [Defined if we're not going to look for a torrc in SYSCONF])
62 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
63 if test x$enable_instrument_downloads = xyes; then
64   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
65             [Defined if we want to keep track of how much of each kind of resource we download.])
68 AC_ARG_ENABLE(transparent,
69      AS_HELP_STRING(--disable-transparent, [disable transparent proxy support]),
70      [case "${enableval}" in
71         yes) transparent=true ;;
72         no)  transparent=false ;;
73         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
74       esac], [transparent=true])
76 AC_ARG_ENABLE(asciidoc,
77      AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
78      [case "${enableval}" in
79         yes) asciidoc=true ;;
80         no)  asciidoc=false ;;
81         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
82       esac], [asciidoc=true])
84 # systemd notify support
85 AC_ARG_ENABLE(systemd,
86       AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
87       [case "${enableval}" in
88         yes) systemd=true ;;
89         no)  systemd=false ;;
90         * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
91       esac], [systemd=auto])
95 # systemd support
96 if test x$enable_systemd = xno ; then
97     have_systemd=no;
98 else
99     PKG_CHECK_MODULES(SYSTEMD,
100         [libsystemd-daemon],
101         have_systemd=yes,
102         have_systemd=no)
103     if test x$have_systemd=xno; then
104         AC_MSG_NOTICE([Okay, checking for systemd a different way...])
105         PKG_CHECK_MODULES(SYSTEMD,
106             [libsystemd],
107             have_systemd=yes,
108             have_systemd=no)
109     fi
112 if test x$have_systemd = xyes; then
113     AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
114     TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
115     TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
116     PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
117          [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
119 AC_SUBST(TOR_SYSTEMD_CFLAGS)
120 AC_SUBST(TOR_SYSTEMD_LIBS)
122 if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
123     AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
126 case $host in
127    *-*-solaris* )
128      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
129      ;;
130 esac
132 AC_ARG_ENABLE(gcc-warnings,
133      AS_HELP_STRING(--enable-gcc-warnings, [enable verbose warnings]))
134 AC_ARG_ENABLE(gcc-warnings-advisory,
135      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
137 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
138 AC_ARG_ENABLE(gcc-hardening,
139     AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
141 AC_ARG_ENABLE(expensive-hardening,
142     AS_HELP_STRING(--enable-expensive-hardening, [enable more expensive compiler hardening; makes Tor slower]))
144 dnl Linker hardening options
145 dnl Currently these options are ELF specific - you can't use this with MacOSX
146 AC_ARG_ENABLE(linker-hardening,
147     AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
149 AC_ARG_ENABLE(local-appdata,
150    AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
151 if test "$enable_local_appdata" = "yes"; then
152   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
153             [Defined if we default to host local appdata paths on Windows])
156 # Tor2web mode flag
157 AC_ARG_ENABLE(tor2web-mode,
158      AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
159 [if test x$enableval = xyes; then
160     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
161 fi])
163 AC_ARG_ENABLE(bufferevents,
164      AS_HELP_STRING(--enable-bufferevents, [use Libevent's buffered IO]))
166 AC_ARG_ENABLE(tool-name-check,
167      AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
169 AC_ARG_ENABLE(seccomp,
170      AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
172 AC_ARG_ENABLE(libscrypt,
173      AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
175 dnl check for the correct "ar" when cross-compiling
176 AN_MAKEVAR([AR], [AC_PROG_AR])
177 AN_PROGRAM([ar], [AC_PROG_AR])
178 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
179 AC_PROG_AR
181 dnl Check whether the above macro has settled for a simply named tool even
182 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
183 dnl because that will find any cc on the system, not only the cross-compiler,
184 dnl and then verify that a binary built with this compiler runs on the
185 dnl build system. It will then come to the false conclusion that we're not
186 dnl cross-compiling.
187 if test x$enable_tool_name_check != xno; then
188     if test x$ac_tool_warned = xyes; then
189         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.)])
190         elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
191                 AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
192         fi
195 AC_PROG_CC
196 AC_PROG_CPP
197 AC_PROG_MAKE_SET
198 AC_PROG_RANLIB
200 AC_PATH_PROG([PERL], [perl])
202 dnl autoconf 2.59 appears not to support AC_PROG_SED
203 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
205 dnl check for asciidoc and a2x
206 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
207 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
209 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
211 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
212 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
213 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
214 AM_PROG_CC_C_O
215 AC_PROG_CC_C99
217 AC_ARG_VAR([PYTHON], [path to Python binary])
218 AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
219 if test "x$PYTHON" = "x"; then
220   AC_MSG_WARN([Python unavailable; some tests will not be run.])
222 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
224 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
225 AC_C_FLEXIBLE_ARRAY_MEMBER
226 ], [
227  dnl Maybe we've got an old autoconf...
228  AC_CACHE_CHECK([for flexible array members],
229      tor_cv_c_flexarray,
230      [AC_COMPILE_IFELSE(
231        AC_LANG_PROGRAM([
232  struct abc { int a; char b[]; };
233 ], [
234  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
235  def->b[0] = 33;
237   [tor_cv_c_flexarray=yes],
238   [tor_cv_c_flexarray=no])])
239  if test $tor_cv_flexarray = yes ; then
240    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
241  else
242    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
243  fi
246 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
247       tor_cv_c_c99_decl,
248       [AC_COMPILE_IFELSE(
249          [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
250          [tor_cv_c_c99_decl=yes],
251          [tor_cv_c_c99_decl=no] )])
252 if test "$tor_cv_c_c99_decl" != "yes"; then
253   AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
256 AC_CACHE_CHECK([for working C99 designated initializers],
257       tor_cv_c_c99_designated_init,
258       [AC_COMPILE_IFELSE(
259          [AC_LANG_PROGRAM([struct s { int a; int b; };],
260                [[ struct s ss = { .b = 5, .a = 6 }; ]])],
261          [tor_cv_c_c99_designated_init=yes],
262          [tor_cv_c_c99_designated_init=no] )])
264 if test "$tor_cv_c_c99_designated_init" != "yes"; then
265   AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
268 TORUSER=_tor
269 AC_ARG_WITH(tor-user,
270         AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
271         [
272            TORUSER=$withval
273         ]
275 AC_SUBST(TORUSER)
277 TORGROUP=_tor
278 AC_ARG_WITH(tor-group,
279         AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
280         [
281            TORGROUP=$withval
282         ]
284 AC_SUBST(TORGROUP)
287 dnl If _WIN32 is defined and non-zero, we are building for win32
288 AC_MSG_CHECKING([for win32])
289 AC_RUN_IFELSE([AC_LANG_SOURCE([
290 int main(int c, char **v) {
291 #ifdef _WIN32
292 #if _WIN32
293   return 0;
294 #else
295   return 1;
296 #endif
297 #else
298   return 2;
299 #endif
300 }])],
301 bwin32=true; AC_MSG_RESULT([yes]),
302 bwin32=false; AC_MSG_RESULT([no]),
303 bwin32=cross; AC_MSG_RESULT([cross])
306 if test "$bwin32" = cross; then
307 AC_MSG_CHECKING([for win32 (cross)])
308 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
309 #ifdef _WIN32
310 int main(int c, char **v) {return 0;}
311 #else
312 #error
313 int main(int c, char **v) {return x(y);}
314 #endif
315 ])],
316 bwin32=true; AC_MSG_RESULT([yes]),
317 bwin32=false; AC_MSG_RESULT([no]))
320 AH_BOTTOM([
321 #ifdef _WIN32
322 /* Defined to access windows functions and definitions for >=WinXP */
323 # ifndef WINVER
324 #  define WINVER 0x0501
325 # endif
327 /* Defined to access _other_ windows functions and definitions for >=WinXP */
328 # ifndef _WIN32_WINNT
329 #  define _WIN32_WINNT 0x0501
330 # endif
332 /* Defined to avoid including some windows headers as part of Windows.h */
333 # ifndef WIN32_LEAN_AND_MEAN
334 #  define WIN32_LEAN_AND_MEAN 1
335 # endif
336 #endif
340 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
342 dnl Enable C99 when compiling with MIPSpro
343 AC_MSG_CHECKING([for MIPSpro compiler])
344 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
345 #if (defined(__sgi) && defined(_COMPILER_VERSION))
346 #error
347   return x(y);
348 #endif
349 ])],
350 bmipspro=false; AC_MSG_RESULT(no),
351 bmipspro=true; AC_MSG_RESULT(yes))
353 if test "$bmipspro" = true; then
354   CFLAGS="$CFLAGS -c99"
357 AC_C_BIGENDIAN
359 AC_SEARCH_LIBS(socket, [socket network])
360 AC_SEARCH_LIBS(gethostbyname, [nsl])
361 AC_SEARCH_LIBS(dlopen, [dl])
362 AC_SEARCH_LIBS(inet_aton, [resolv])
363 saved_LIBS="$LIBS"
364 AC_SEARCH_LIBS([clock_gettime], [rt])
365 if test "$LIBS" != "$saved_LIBS"; then
366    # Looks like we need -lrt for clock_gettime().
367    have_rt=yes
370 AC_SEARCH_LIBS(pthread_create, [pthread])
371 AC_SEARCH_LIBS(pthread_detach, [pthread])
373 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
374 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
376 dnl -------------------------------------------------------------------
377 dnl Check for functions before libevent, since libevent-1.2 apparently
378 dnl exports strlcpy without defining it in a header.
380 AC_CHECK_FUNCS(
381         _NSGetEnviron \
382         accept4 \
383         backtrace \
384         backtrace_symbols_fd \
385         clock_gettime \
386         eventfd \
387         flock \
388         ftime \
389         getaddrinfo \
390         getifaddrs \
391         getpass \
392         getrlimit \
393         gettimeofday \
394         gmtime_r \
395         inet_aton \
396         ioctl \
397         issetugid \
398         llround \
399         localtime_r \
400         lround \
401         memmem \
402         pipe \
403         pipe2 \
404         prctl \
405         readpassphrase \
406         rint \
407         sigaction \
408         socketpair \
409         statvfs \
410         strlcat \
411         strlcpy \
412         strnlen \
413         strptime \
414         strtok_r \
415         strtoull \
416         sysconf \
417         sysctl \
418         uname \
419         usleep \
420         vasprintf \
421         _vscprintf
424 if test "$bwin32" != true; then
425   AC_CHECK_HEADERS(pthread.h)
426   AC_CHECK_FUNCS(pthread_create)
429 if test "$bwin32" = true; then
430   AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
431 #include <windows.h>
432 #include <conio.h>
433 #include <wchar.h>
434                  ])
437 AM_CONDITIONAL(BUILD_READPASSPHRASE_C, test x$ac_cv_func_readpassphrase = xno && test $bwin32 = false)
439 dnl ------------------------------------------------------
440 dnl Where do you live, libevent?  And how do we call you?
442 if test "$bwin32" = true; then
443   TOR_LIB_WS32=-lws2_32
444   TOR_LIB_IPHLPAPI=-liphlpapi
445   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
446   # think it's actually necessary.
447   TOR_LIB_GDI=-lgdi32
448 else
449   TOR_LIB_WS32=
450   TOR_LIB_GDI=
452 AC_SUBST(TOR_LIB_WS32)
453 AC_SUBST(TOR_LIB_GDI)
454 AC_SUBST(TOR_LIB_IPHLPAPI)
456 tor_libevent_pkg_redhat="libevent"
457 tor_libevent_pkg_debian="libevent-dev"
458 tor_libevent_devpkg_redhat="libevent-devel"
459 tor_libevent_devpkg_debian="libevent-dev"
461 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
462 dnl linking for static builds.
463 STATIC_LIBEVENT_FLAGS=""
464 if test "$enable_static_libevent" = "yes"; then
465     if test "$have_rt" = yes; then
466       STATIC_LIBEVENT_FLAGS=" -lrt "
467     fi
470 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
471 #ifdef _WIN32
472 #include <winsock2.h>
473 #endif
474 #include <stdlib.h>
475 #include <sys/time.h>
476 #include <sys/types.h>
477 #include <event.h>], [
478 #ifdef _WIN32
479 #include <winsock2.h>
480 #endif
481 void exit(int); void *event_init(void);],
482     [
483 #ifdef _WIN32
484 {WSADATA d; WSAStartup(0x101,&d); }
485 #endif
486 event_init(); exit(0);
487 ], [--with-libevent-dir], [/opt/libevent])
489 dnl Now check for particular libevent functions.
490 save_LIBS="$LIBS"
491 save_LDFLAGS="$LDFLAGS"
492 save_CPPFLAGS="$CPPFLAGS"
493 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
494 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
495 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
496 AC_CHECK_FUNCS([event_get_version_number \
497                 evutil_secure_rng_set_urandom_device_file \
498                 evutil_secure_rng_init \
499                ])
500 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
501 [#include <event.h>
504 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
506 LIBS="$save_LIBS"
507 LDFLAGS="$save_LDFLAGS"
508 CPPFLAGS="$save_CPPFLAGS"
511 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
513 if test "$enable_static_libevent" = "yes"; then
514    if test "$tor_cv_library_libevent_dir" = "(system)"; then
515      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
516    else
517      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
518    fi
519 else
520      TOR_LIBEVENT_LIBS="-levent"
523 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
524 dnl we can do much better.
525 if test "$enable_bufferevents" = "yes" ; then
526   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
527     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.])
528   else
530     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
532     # Check for the right version.  First see if version detection works.
533     AC_MSG_CHECKING([whether we can detect the Libevent version])
534     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
535 #include <event2/event.h>
536 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
537 #error
538 int x = y(zz);
539 #else
540 int x = 1;
541 #endif
542   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
543      [event_version_number_works=no;  AC_MSG_RESULT([no])])
544     if test "$event_version_number_works" != 'yes'; then
545       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
546     else
547       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
548       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
549 #include <event2/event.h>
550 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
551 #error
552 int x = y(zz);
553 #else
554 int x = 1;
555 #endif
556    ])], [ AC_MSG_RESULT([yes]) ],
557       [ AC_MSG_RESULT([no])
558         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
559     fi
560   fi
563 LIBS="$save_LIBS"
564 LDFLAGS="$save_LDFLAGS"
565 CPPFLAGS="$save_CPPFLAGS"
567 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
568 if test "$enable_bufferevents" = "yes"; then
569   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
570   if test "$enable_static_libevent" = "yes"; then
571     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
572   else
573     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
574   fi
576 AC_SUBST(TOR_LIBEVENT_LIBS)
578 dnl ------------------------------------------------------
579 dnl Where do you live, libm?
581 dnl On some platforms (Haiku/BeOS) the math library is
582 dnl part of libroot. In which case don't link against lm
583 TOR_LIB_MATH=""
584 save_LIBS="$LIBS"
585 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
586 if test "$ac_cv_search_pow" != "none required"; then
587     TOR_LIB_MATH="$ac_cv_search_pow"
589 LIBS="$save_LIBS"
590 AC_SUBST(TOR_LIB_MATH)
592 dnl ------------------------------------------------------
593 dnl Where do you live, openssl?  And how do we call you?
595 tor_openssl_pkg_redhat="openssl"
596 tor_openssl_pkg_debian="libssl-dev"
597 tor_openssl_devpkg_redhat="openssl-devel"
598 tor_openssl_devpkg_debian="libssl-dev"
600 ALT_openssl_WITHVAL=""
601 AC_ARG_WITH(ssl-dir,
602   AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
603   [
604       if test "x$withval" != xno && test "x$withval" != "x" ; then
605          ALT_openssl_WITHVAL="$withval"
606       fi
607   ])
609 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
610     [#include <openssl/rand.h>],
611     [void RAND_add(const void *buf, int num, double entropy);],
612     [RAND_add((void*)0,0,0); exit(0);], [],
613     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
615 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
617 if test "$enable_static_openssl" = "yes"; then
618    if test "$tor_cv_library_openssl_dir" = "(system)"; then
619      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
620    else
621      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
622    fi
623 else
624      TOR_OPENSSL_LIBS="-lssl -lcrypto"
626 AC_SUBST(TOR_OPENSSL_LIBS)
628 dnl Now check for particular openssl functions.
629 save_LIBS="$LIBS"
630 save_LDFLAGS="$LDFLAGS"
631 save_CPPFLAGS="$CPPFLAGS"
632 LIBS="$TOR_OPENSSL_LIBS $LIBS"
633 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
634 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
635 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
636 [#include <openssl/ssl.h>
639 AC_CHECK_FUNCS([ \
640                 SSL_SESSION_get_master_key \
641                 SSL_get_server_random \
642                 SSL_get_client_ciphers \
643                 SSL_get_client_random \
644                 SSL_CIPHER_find \
645                 TLS_method
646                ])
648 dnl Check if OpenSSL has scrypt implementation.
649 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
651 LIBS="$save_LIBS"
652 LDFLAGS="$save_LDFLAGS"
653 CPPFLAGS="$save_CPPFLAGS"
655 dnl ------------------------------------------------------
656 dnl Where do you live, zlib?  And how do we call you?
658 tor_zlib_pkg_redhat="zlib"
659 tor_zlib_pkg_debian="zlib1g"
660 tor_zlib_devpkg_redhat="zlib-devel"
661 tor_zlib_devpkg_debian="zlib1g-dev"
663 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
664     [#include <zlib.h>],
665     [const char * zlibVersion(void);],
666     [zlibVersion(); exit(0);], [--with-zlib-dir],
667     [/opt/zlib])
669 if test "$enable_static_zlib" = "yes"; then
670    if test "$tor_cv_library_zlib_dir" = "(system)"; then
671      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
672  using --enable-static-zlib")
673    else
674      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
675    fi
676 else
677      TOR_ZLIB_LIBS="-lz"
679 AC_SUBST(TOR_ZLIB_LIBS)
681 dnl ---------------------------------------------------------------------
682 dnl Now that we know about our major libraries, we can check for compiler
683 dnl and linker hardening options.  We need to do this with the libraries known,
684 dnl since sometimes the linker will like an option but not be willing to
685 dnl use it with a build of a library.
687 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
688 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
690 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
691 #if !defined(__clang__)
692 #error
693 #endif])], have_clang=yes, have_clang=no)
695 if test x$enable_gcc_hardening != xno; then
696     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
697     if test x$have_clang = xyes; then
698         TOR_CHECK_CFLAGS(-Qunused-arguments)
699     fi
700     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
701     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
702     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
703 m4_ifdef([AS_VAR_IF],[
704     AS_VAR_IF(can_compile, [yes],
705         AS_VAR_IF(can_link, [yes],
706                   [],
707                   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.)]))
708         )])
709     AS_VAR_POPDEF([can_link])
710     AS_VAR_POPDEF([can_compile])
711     TOR_CHECK_CFLAGS(-Wstack-protector)
712     TOR_CHECK_CFLAGS(-fwrapv)
713     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
714     if test "$bwin32" = "false"; then
715        TOR_CHECK_CFLAGS(-fPIE)
716        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
717     fi
720 if test x$enable_expensive_hardening = xyes ; then
721    TOR_CHECK_CFLAGS([-fsanitize=address])
722    TOR_CHECK_CFLAGS([-fsanitize=undefined])
723    TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
726 if test x$enable_linker_hardening != xno; then
727     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
730 # For backtrace support
731 TOR_CHECK_LDFLAGS(-rdynamic)
733 dnl ------------------------------------------------------
734 dnl Now see if we have a -fomit-frame-pointer compiler option.
736 saved_CFLAGS="$CFLAGS"
737 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
738 F_OMIT_FRAME_POINTER=''
739 if test "$saved_CFLAGS" != "$CFLAGS"; then
740   if test x$enable_expensive_hardening != xyes ; then
741     F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
742   fi
744 CFLAGS="$saved_CFLAGS"
745 AC_SUBST(F_OMIT_FRAME_POINTER)
747 dnl ------------------------------------------------------
748 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
749 dnl for us, as GCC 4.6 and later do at many optimization levels), then
750 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
751 dnl code will work.
752 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
754 dnl ============================================================
755 dnl Check for libseccomp
757 if test "x$enable_seccomp" != "xno"; then
758   AC_CHECK_HEADERS([seccomp.h])
759   AC_SEARCH_LIBS(seccomp_init, [seccomp])
762 dnl ============================================================
763 dnl Check for libscrypt
765 if test "x$enable_libscrypt" != "xno"; then
766   AC_CHECK_HEADERS([libscrypt.h])
767   AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
770 dnl ============================================================
771 dnl We need an implementation of curve25519.
773 dnl set these defaults.
774 build_curve25519_donna=no
775 build_curve25519_donna_c64=no
776 use_curve25519_donna=no
777 use_curve25519_nacl=no
778 CURVE25519_LIBS=
780 dnl The best choice is using curve25519-donna-c64, but that requires
781 dnl that we
782 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
783   tor_cv_can_use_curve25519_donna_c64,
784   [AC_RUN_IFELSE(
785     [AC_LANG_PROGRAM([dnl
786       #include <stdint.h>
787       typedef unsigned uint128_t __attribute__((mode(TI)));
788   int func(uint64_t a, uint64_t b) {
789            uint128_t c = ((uint128_t)a) * b;
790            int ok = ((uint64_t)(c>>96)) == 522859 &&
791              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
792                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
793                  (((uint64_t)(c))&0xffffffffL) == 0;
794            return ok;
795       }
796   ], [dnl
797     int ok = func( ((uint64_t)2000000000) * 1000000000,
798                    ((uint64_t)1234567890) << 24);
799         return !ok;
800       ])],
801   [tor_cv_can_use_curve25519_donna_c64=yes],
802       [tor_cv_can_use_curve25519_donna_c64=no],
803   [AC_LINK_IFELSE(
804         [AC_LANG_PROGRAM([dnl
805       #include <stdint.h>
806       typedef unsigned uint128_t __attribute__((mode(TI)));
807   int func(uint64_t a, uint64_t b) {
808            uint128_t c = ((uint128_t)a) * b;
809            int ok = ((uint64_t)(c>>96)) == 522859 &&
810              (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
811                  (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
812                  (((uint64_t)(c))&0xffffffffL) == 0;
813            return ok;
814       }
815   ], [dnl
816     int ok = func( ((uint64_t)2000000000) * 1000000000,
817                  ((uint64_t)1234567890) << 24);
818         return !ok;
819       ])],
820           [tor_cv_can_use_curve25519_donna_c64=cross],
821       [tor_cv_can_use_curve25519_donna_c64=no])])])
823 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
824                   nacl/crypto_scalarmult_curve25519.h])
826 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
827   tor_cv_can_use_curve25519_nacl,
828   [tor_saved_LIBS="$LIBS"
829    LIBS="$LIBS -lnacl"
830    AC_LINK_IFELSE(
831      [AC_LANG_PROGRAM([dnl
832        #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
833        #include <crypto_scalarmult_curve25519.h>
834    #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
835    #include <nacl/crypto_scalarmult_curve25519.h>
836    #endif
837        #ifdef crypto_scalarmult_curve25519_ref_BYTES
838    #error Hey, this is the reference implementation! That's not fast.
839    #endif
840      ], [
841    unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
842      ])], [tor_cv_can_use_curve25519_nacl=yes],
843      [tor_cv_can_use_curve25519_nacl=no])
844    LIBS="$tor_saved_LIBS" ])
846  dnl Okay, now we need to figure out which one to actually use. Fall back
847  dnl to curve25519-donna.c
849  if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
850    build_curve25519_donna_c64=yes
851    use_curve25519_donna=yes
852  elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
853    use_curve25519_nacl=yes
854    CURVE25519_LIBS=-lnacl
855  else
856    build_curve25519_donna=yes
857    use_curve25519_donna=yes
858  fi
860 if test x$use_curve25519_donna = xyes; then
861   AC_DEFINE(USE_CURVE25519_DONNA, 1,
862             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
864 if test x$use_curve25519_nacl = xyes; then
865   AC_DEFINE(USE_CURVE25519_NACL, 1,
866             [Defined if we should use a curve25519 from nacl])
868 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
869 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
870 AC_SUBST(CURVE25519_LIBS)
872 dnl Make sure to enable support for large off_t if available.
873 AC_SYS_LARGEFILE
875 AC_CHECK_HEADERS(
876         assert.h \
877         errno.h \
878         fcntl.h \
879         signal.h \
880         string.h \
881         sys/fcntl.h \
882         sys/stat.h \
883         sys/time.h \
884         sys/types.h \
885         time.h \
886         unistd.h
887  , , 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.))
889 dnl These headers are not essential
891 AC_CHECK_HEADERS(
892         arpa/inet.h \
893         crt_externs.h \
894         execinfo.h \
895         grp.h \
896         ifaddrs.h \
897         inttypes.h \
898         limits.h \
899         linux/types.h \
900         machine/limits.h \
901         malloc.h \
902         malloc/malloc.h \
903         malloc_np.h \
904         netdb.h \
905         netinet/in.h \
906         netinet/in6.h \
907         pwd.h \
908         readpassphrase.h \
909         stdint.h \
910         sys/eventfd.h \
911         sys/file.h \
912         sys/ioctl.h \
913         sys/limits.h \
914         sys/mman.h \
915         sys/param.h \
916         sys/prctl.h \
917         sys/resource.h \
918         sys/select.h \
919         sys/socket.h \
920         sys/statvfs.h \
921         sys/sysctl.h \
922         sys/syslimits.h \
923         sys/time.h \
924         sys/types.h \
925         sys/un.h \
926         sys/utime.h \
927         sys/wait.h \
928         syslog.h \
929         utime.h
932 AC_CHECK_HEADERS(sys/param.h)
934 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
935 [#ifdef HAVE_SYS_TYPES_H
936 #include <sys/types.h>
937 #endif
938 #ifdef HAVE_SYS_SOCKET_H
939 #include <sys/socket.h>
940 #endif])
941 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
942 [#ifdef HAVE_SYS_TYPES_H
943 #include <sys/types.h>
944 #endif
945 #ifdef HAVE_SYS_SOCKET_H
946 #include <sys/socket.h>
947 #endif
948 #ifdef HAVE_NET_IF_H
949 #include <net/if.h>
950 #endif])
952 AC_CHECK_HEADERS(linux/if.h,[],[],
954 #ifdef HAVE_SYS_SOCKET_H
955 #include <sys/socket.h>
956 #endif
959 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
960         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
961 [#ifdef HAVE_SYS_TYPES_H
962 #include <sys/types.h>
963 #endif
964 #ifdef HAVE_SYS_SOCKET_H
965 #include <sys/socket.h>
966 #endif
967 #ifdef HAVE_LIMITS_H
968 #include <limits.h>
969 #endif
970 #ifdef HAVE_LINUX_TYPES_H
971 #include <linux/types.h>
972 #endif
973 #ifdef HAVE_NETINET_IN6_H
974 #include <netinet/in6.h>
975 #endif
976 #ifdef HAVE_NETINET_IN_H
977 #include <netinet/in.h>
978 #endif])
980 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
981         linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
982 [#ifdef HAVE_SYS_TYPES_H
983 #include <sys/types.h>
984 #endif
985 #ifdef HAVE_SYS_SOCKET_H
986 #include <sys/socket.h>
987 #endif
988 #ifdef HAVE_LIMITS_H
989 #include <limits.h>
990 #endif
991 #ifdef HAVE_LINUX_TYPES_H
992 #include <linux/types.h>
993 #endif
994 #ifdef HAVE_NETINET_IN6_H
995 #include <netinet/in6.h>
996 #endif
997 #ifdef HAVE_NETINET_IN_H
998 #include <netinet/in.h>
999 #endif
1000 #ifdef HAVE_LINUX_IF_H
1001 #include <linux/if.h>
1002 #endif])
1004 if test x$transparent = xtrue ; then
1005    transparent_ok=0
1006    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
1007      transparent_ok=1
1008    fi
1009    if test x$linux_netfilter_ipv4 = x1 ; then
1010      transparent_ok=1
1011    fi
1012    if test x$linux_netfilter_ipv6_ip6_tables = x1 ; then
1013      transparent_ok=1
1014    fi
1015    if test x$transparent_ok = x1 ; then
1016      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1017      case $host in
1018        *-*-openbsd* | *-*-bitrig*)
1019          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
1020      esac
1021    else
1022      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1023    fi
1026 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1027 [#ifdef HAVE_SYS_TYPES_H
1028 #include <sys/types.h>
1029 #endif
1030 #ifdef HAVE_SYS_TIME_H
1031 #include <sys/time.h>
1032 #endif])
1034 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1035 dnl Watch out.
1037 AC_CHECK_SIZEOF(int8_t)
1038 AC_CHECK_SIZEOF(int16_t)
1039 AC_CHECK_SIZEOF(int32_t)
1040 AC_CHECK_SIZEOF(int64_t)
1041 AC_CHECK_SIZEOF(uint8_t)
1042 AC_CHECK_SIZEOF(uint16_t)
1043 AC_CHECK_SIZEOF(uint32_t)
1044 AC_CHECK_SIZEOF(uint64_t)
1045 AC_CHECK_SIZEOF(intptr_t)
1046 AC_CHECK_SIZEOF(uintptr_t)
1048 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1050 AC_CHECK_SIZEOF(char)
1051 AC_CHECK_SIZEOF(short)
1052 AC_CHECK_SIZEOF(int)
1053 AC_CHECK_SIZEOF(long)
1054 AC_CHECK_SIZEOF(long long)
1055 AC_CHECK_SIZEOF(__int64)
1056 AC_CHECK_SIZEOF(void *)
1057 AC_CHECK_SIZEOF(time_t)
1058 AC_CHECK_SIZEOF(size_t)
1059 AC_CHECK_SIZEOF(pid_t)
1061 AC_CHECK_TYPES([uint, u_char, ssize_t])
1063 AC_PC_FROM_UCONTEXT([/bin/true])
1065 dnl used to include sockaddr_storage, but everybody has that.
1066 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1067 [#ifdef HAVE_SYS_TYPES_H
1068 #include <sys/types.h>
1069 #endif
1070 #ifdef HAVE_NETINET_IN_H
1071 #include <netinet/in.h>
1072 #endif
1073 #ifdef HAVE_NETINET_IN6_H
1074 #include <netinet/in6.h>
1075 #endif
1076 #ifdef HAVE_SYS_SOCKET_H
1077 #include <sys/socket.h>
1078 #endif
1079 #ifdef _WIN32
1080 #define _WIN32_WINNT 0x0501
1081 #define WIN32_LEAN_AND_MEAN
1082 #include <winsock2.h>
1083 #include <ws2tcpip.h>
1084 #endif
1086 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1087 [#ifdef HAVE_SYS_TYPES_H
1088 #include <sys/types.h>
1089 #endif
1090 #ifdef HAVE_NETINET_IN_H
1091 #include <netinet/in.h>
1092 #endif
1093 #ifdef HAVE_NETINET_IN6_H
1094 #include <netinet/in6.h>
1095 #endif
1096 #ifdef HAVE_SYS_SOCKET_H
1097 #include <sys/socket.h>
1098 #endif
1099 #ifdef _WIN32
1100 #define _WIN32_WINNT 0x0501
1101 #define WIN32_LEAN_AND_MEAN
1102 #include <winsock2.h>
1103 #include <ws2tcpip.h>
1104 #endif
1105 #endif
1108 AC_CHECK_TYPES([rlim_t], , ,
1109 [#ifdef HAVE_SYS_TYPES_H
1110 #include <sys/types.h>
1111 #endif
1112 #ifdef HAVE_SYS_TIME_H
1113 #include <sys/time.h>
1114 #endif
1115 #ifdef HAVE_SYS_RESOURCE_H
1116 #include <sys/resource.h>
1117 #endif
1120 AX_CHECK_SIGN([time_t],
1121        [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1122        [ : ], [
1123 #ifdef HAVE_SYS_TYPES_H
1124 #include <sys/types.h>
1125 #endif
1126 #ifdef HAVE_SYS_TIME_H
1127 #include <sys/time.h>
1128 #endif
1129 #ifdef HAVE_TIME_H
1130 #include <time.h>
1131 #endif
1134 if test "$ax_cv_decl_time_t_signed" = no; then
1135   AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1138 AX_CHECK_SIGN([size_t],
1139        [ tor_cv_size_t_signed=yes ],
1140        [ tor_cv_size_t_signed=no ], [
1141 #ifdef HAVE_SYS_TYPES_H
1142 #include <sys/types.h>
1143 #endif
1146 if test "$ax_cv_decl_size_t_signed" = yes; then
1147   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1150 AX_CHECK_SIGN([enum always],
1151        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1152        [ : ], [
1153  enum always { AAA, BBB, CCC };
1156 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1157 #ifdef HAVE_SYS_SOCKET_H
1158 #include <sys/socket.h>
1159 #endif
1162 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1164 AC_CHECK_SIZEOF(cell_t)
1166 # Now make sure that NULL can be represented as zero bytes.
1167 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1168 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1169 [[#include <stdlib.h>
1170 #include <string.h>
1171 #include <stdio.h>
1172 #ifdef HAVE_STDDEF_H
1173 #include <stddef.h>
1174 #endif
1175 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1176 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1177        [tor_cv_null_is_zero=yes],
1178        [tor_cv_null_is_zero=no],
1179        [tor_cv_null_is_zero=cross])])
1181 if test "$tor_cv_null_is_zero" = cross ; then
1182   # Cross-compiling; let's hope that the target isn't raving mad.
1183   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1186 if test "$tor_cv_null_is_zero" != no; then
1187   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1188             [Define to 1 iff memset(0) sets pointers to NULL])
1191 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1192 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1193 [[#include <stdlib.h>
1194 #include <string.h>
1195 #include <stdio.h>
1196 #ifdef HAVE_STDDEF_H
1197 #include <stddef.h>
1198 #endif
1199 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1200 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1201        [tor_cv_dbl0_is_zero=yes],
1202        [tor_cv_dbl0_is_zero=no],
1203        [tor_cv_dbl0_is_zero=cross])])
1205 if test "$tor_cv_dbl0_is_zero" = cross ; then
1206   # Cross-compiling; let's hope that the target isn't raving mad.
1207   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1210 if test "$tor_cv_dbl0_is_zero" != no; then
1211   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1212             [Define to 1 iff memset(0) sets doubles to 0.0])
1215 # And what happens when we malloc zero?
1216 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1217 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1218 [[#include <stdlib.h>
1219 #include <string.h>
1220 #include <stdio.h>
1221 #ifdef HAVE_STDDEF_H
1222 #include <stddef.h>
1223 #endif
1224 int main () { return malloc(0)?0:1; }]])],
1225        [tor_cv_malloc_zero_works=yes],
1226        [tor_cv_malloc_zero_works=no],
1227        [tor_cv_malloc_zero_works=cross])])
1229 if test "$tor_cv_malloc_zero_works" = cross; then
1230   # Cross-compiling; let's hope that the target isn't raving mad.
1231   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1234 if test "$tor_cv_malloc_zero_works" = yes; then
1235   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1236             [Define to 1 iff malloc(0) returns a pointer])
1239 # whether we seem to be in a 2s-complement world.
1240 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1241 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1242 [[int main () { int problem = ((-99) != (~99)+1);
1243 return problem ? 1 : 0; }]])],
1244        [tor_cv_twos_complement=yes],
1245        [tor_cv_twos_complement=no],
1246        [tor_cv_twos_complement=cross])])
1248 if test "$tor_cv_twos_complement" = cross ; then
1249   # Cross-compiling; let's hope that the target isn't raving mad.
1250   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1253 if test "$tor_cv_twos_complement" != no ; then
1254   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1255             [Define to 1 iff we represent negative integers with two's complement])
1258 # What does shifting a negative value do?
1259 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1260 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1261 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1262        [tor_cv_sign_extend=yes],
1263        [tor_cv_sign_extend=no],
1264        [tor_cv_sign_extend=cross])])
1266 if test "$tor_cv_sign_extend" = cross ; then
1267   # Cross-compiling; let's hope that the target isn't raving mad.
1268   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1271 if test "$tor_cv_sign_extend" != no ; then
1272   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1273             [Define to 1 iff right-shifting a negative value performs sign-extension])
1276 # Whether we should use the dmalloc memory allocation debugging library.
1277 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1278 AC_ARG_WITH(dmalloc,
1279 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1280 [if [[ "$withval" = "yes" ]]; then
1281   dmalloc=1
1282   AC_MSG_RESULT(yes)
1283 else
1284   dmalloc=1
1285   AC_MSG_RESULT(no)
1286 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1289 if [[ $dmalloc -eq 1 ]]; then
1290   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1291   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1292   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1293   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1296 AC_ARG_WITH(tcmalloc,
1297 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1298 [ tcmalloc=yes ], [ tcmalloc=no ])
1300 if test x$tcmalloc = xyes ; then
1301    LDFLAGS="-ltcmalloc $LDFLAGS"
1304 using_custom_malloc=no
1305 if test x$enable_openbsd_malloc = xyes ; then
1306    using_custom_malloc=yes
1308 if test x$tcmalloc = xyes ; then
1309    using_custom_malloc=yes
1311 if test $using_custom_malloc = no ; then
1312    AC_CHECK_FUNCS(mallinfo)
1315 # By default, we're going to assume we don't have mlockall()
1316 # bionic and other platforms have various broken mlockall subsystems.
1317 # Some systems don't have a working mlockall, some aren't linkable,
1318 # and some have it but don't declare it.
1319 AC_CHECK_FUNCS(mlockall)
1320 AC_CHECK_DECLS([mlockall], , , [
1321 #ifdef HAVE_SYS_MMAN_H
1322 #include <sys/mman.h>
1323 #endif])
1325 # Allow user to specify an alternate syslog facility
1326 AC_ARG_WITH(syslog-facility,
1327 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1328 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1329 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1330 AC_SUBST(LOGFACILITY)
1332 # Check if we have getresuid and getresgid
1333 AC_CHECK_FUNCS(getresuid getresgid)
1335 # Check for gethostbyname_r in all its glorious incompatible versions.
1336 #   (This logic is based on that in Python's configure.in)
1337 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1338   [Define this if you have any gethostbyname_r()])
1340 AC_CHECK_FUNC(gethostbyname_r, [
1341   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1342   OLD_CFLAGS=$CFLAGS
1343   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1344   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1345 #include <netdb.h>
1346   ], [[
1347     char *cp1, *cp2;
1348     struct hostent *h1, *h2;
1349     int i1, i2;
1350     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1351   ]])],[
1352     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1353     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1354      [Define this if gethostbyname_r takes 6 arguments])
1355     AC_MSG_RESULT(6)
1356   ], [
1357     AC_TRY_COMPILE([
1358 #include <netdb.h>
1359     ], [
1360       char *cp1, *cp2;
1361       struct hostent *h1;
1362       int i1, i2;
1363       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1364     ], [
1365       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1366       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1367         [Define this if gethostbyname_r takes 5 arguments])
1368       AC_MSG_RESULT(5)
1369    ], [
1370       AC_TRY_COMPILE([
1371 #include <netdb.h>
1372      ], [
1373        char *cp1;
1374        struct hostent *h1;
1375        struct hostent_data hd;
1376        (void) gethostbyname_r(cp1,h1,&hd);
1377      ], [
1378        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1379        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1380          [Define this if gethostbyname_r takes 3 arguments])
1381        AC_MSG_RESULT(3)
1382      ], [
1383        AC_MSG_RESULT(0)
1384      ])
1385   ])
1386  ])
1387  CFLAGS=$OLD_CFLAGS
1390 AC_CACHE_CHECK([whether the C compiler supports __func__],
1391   tor_cv_have_func_macro,
1392   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1393 #include <stdio.h>
1394 int main(int c, char **v) { puts(__func__); }])],
1395   tor_cv_have_func_macro=yes,
1396   tor_cv_have_func_macro=no))
1398 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1399   tor_cv_have_FUNC_macro,
1400   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1401 #include <stdio.h>
1402 int main(int c, char **v) { puts(__FUNC__); }])],
1403   tor_cv_have_FUNC_macro=yes,
1404   tor_cv_have_FUNC_macro=no))
1406 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1407   tor_cv_have_FUNCTION_macro,
1408   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1409 #include <stdio.h>
1410 int main(int c, char **v) { puts(__FUNCTION__); }])],
1411   tor_cv_have_FUNCTION_macro=yes,
1412   tor_cv_have_FUNCTION_macro=no))
1414 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1415   tor_cv_have_environ_declared,
1416   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1417 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1418  * Without it environ doesn't get declared. */
1419 #define _GNU_SOURCE
1420 #ifdef HAVE_UNISTD_H
1421 #include <unistd.h>
1422 #endif
1423 #include <stdlib.h>
1424 int main(int c, char **v) { char **t = environ; }])],
1425   tor_cv_have_environ_declared=yes,
1426   tor_cv_have_environ_declared=no))
1428 if test "$tor_cv_have_func_macro" = 'yes'; then
1429   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1432 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1433   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1436 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1437   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1438            [Defined if the compiler supports __FUNCTION__])
1441 if test "$tor_cv_have_environ_declared" = 'yes'; then
1442   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1443            [Defined if we have extern char **environ already declared])
1446 # $prefix stores the value of the --prefix command line option, or
1447 # NONE if the option wasn't set.  In the case that it wasn't set, make
1448 # it be the default, so that we can use it to expand directories now.
1449 if test "x$prefix" = "xNONE"; then
1450   prefix=$ac_default_prefix
1453 # and similarly for $exec_prefix
1454 if test "x$exec_prefix" = "xNONE"; then
1455   exec_prefix=$prefix
1458 if test "x$BUILDDIR" = "x"; then
1459   BUILDDIR=`pwd`
1461 AC_SUBST(BUILDDIR)
1462 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1463 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1465 if test "x$CONFDIR" = "x"; then
1466   CONFDIR=`eval echo $sysconfdir/tor`
1468 AC_SUBST(CONFDIR)
1469 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1470 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1472 BINDIR=`eval echo $bindir`
1473 AC_SUBST(BINDIR)
1474 LOCALSTATEDIR=`eval echo $localstatedir`
1475 AC_SUBST(LOCALSTATEDIR)
1477 if test "$bwin32" = true; then
1478   # Test if the linker supports the --nxcompat and --dynamicbase options
1479   # for Windows
1480   save_LDFLAGS="$LDFLAGS"
1481   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1482   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1483   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1484     [AC_MSG_RESULT([yes])]
1485     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1486     [AC_MSG_RESULT([no])]
1487   )
1488   LDFLAGS="$save_LDFLAGS"
1491 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1492 # than autoconf's macros like.
1493 if test "$GCC" = yes; then
1494   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1495   # accident waiting to happen.
1496   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1497 else
1498   # Override optimization level for non-gcc compilers
1499   CFLAGS="$CFLAGS -O"
1500   enable_gcc_warnings=no
1501   enable_gcc_warnings_advisory=no
1504 # OS X Lion started deprecating the system openssl. Let's just disable
1505 # all deprecation warnings on OS X. Also, to potentially make the binary
1506 # a little smaller, let's enable dead_strip.
1507 case "$host_os" in
1509  darwin*)
1510     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1511     LDFLAGS="$LDFLAGS -dead_strip" ;;
1512 esac
1514 # Add some more warnings which we use in development but not in the
1515 # released versions.  (Some relevant gcc versions can't handle these.)
1516 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1518   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1519 #if !defined(__GNUC__) || (__GNUC__ < 4)
1520 #error
1521 #endif])], have_gcc4=yes, have_gcc4=no)
1523   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1524 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1525 #error
1526 #endif])], have_gcc42=yes, have_gcc42=no)
1528   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1529 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1530 #error
1531 #endif])], have_gcc43=yes, have_gcc43=no)
1533   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1534 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1535 #error
1536 #endif])], have_gcc46=yes, have_gcc46=no)
1539   save_CFLAGS="$CFLAGS"
1540   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1541   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1542                     have_shorten64_flag=no)
1543   CFLAGS="$save_CFLAGS"
1545   case $host in
1546     *-*-openbsd* | *-*-bitrig*)
1547       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1548       # That's fine, except that the headers don't pass -Wredundant-decls.
1549       # Therefore, let's disable -Wsystem-headers when we're building
1550       # with maximal warnings on OpenBSD.
1551       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1552   esac
1554   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1555   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1556   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1557   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1558   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1560   if test x$enable_gcc_warnings = xyes; then
1561     CFLAGS="$CFLAGS -Werror"
1562   fi
1564   # Disabled, so we can use mallinfo(): -Waggregate-return
1566   if test x$have_gcc4 = xyes ; then
1567     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1568     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
1569   fi
1571   if test x$have_gcc42 = xyes ; then
1572     # These warnings break gcc 4.0.2 and work on gcc 4.2
1573     # XXXX020 See if any of these work with earlier versions.
1574     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1576     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1577   fi
1579   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1580     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1581     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1582   fi
1584   if test x$have_gcc43 = xyes ; then
1585     # These warnings break gcc 4.2 and work on gcc 4.3
1586     # XXXX020 See if any of these work with earlier versions.
1587     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1588   fi
1590   if test x$have_gcc46 = xyes ; then
1591     # This warning was added in gcc 4.3, but it appears to generate
1592     # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
1593     CFLAGS="$CFLAGS -Wlogical-op"
1594   fi
1596   if test x$have_shorten64_flag = xyes ; then
1597     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1598   fi
1602 ##This will break the world on some 64-bit architectures
1603 # CFLAGS="$CFLAGS -Winline"
1606 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1607    case "$host_os" in
1608     darwin*)
1609       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.])
1610    esac
1613 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1615 AC_CONFIG_FILES([
1616         Doxyfile
1617         Makefile
1618         contrib/dist/suse/tor.sh
1619         contrib/operator-tools/tor.logrotate
1620         contrib/dist/tor.sh
1621         contrib/dist/torctl
1622         contrib/dist/tor.service
1623         src/config/torrc.sample
1624         src/config/torrc.minimal
1625         scripts/maint/checkOptionDocs.pl
1626         scripts/maint/updateVersions.pl
1627         src/test/test_zero_length_keys.sh
1628         src/test/test_ntor.sh
1629         src/test/test_bt.sh
1632 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1633   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1634   for file in $regular_mans ; do
1635     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1636       echo "==================================";
1637       echo;
1638       echo "Building Tor has failed since manpages cannot be built.";
1639       echo;
1640       echo "You need asciidoc installed to be able to build the manpages.";
1641       echo "To build without manpages, use the --disable-asciidoc argument";
1642       echo "when calling configure.";
1643       echo;
1644       echo "==================================";
1645       exit 1;
1646     fi
1647   done
1650 AC_OUTPUT