whitespace fix
[tor.git] / configure.ac
blob5a5b6e444ff78e05c0e9927d1d0be43bedd72086
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2013, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT([tor],[0.2.5.3-alpha])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AC_CONFIG_MACRO_DIR([m4])
9 AM_INIT_AUTOMAKE
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AC_CONFIG_HEADERS([orconfig.h])
13 AC_CANONICAL_HOST
15 if test -f /etc/redhat-release ; then
16   if test -f /usr/kerberos/include ; then
17     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
18   fi
21 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
22 # the += operator on it in src/or/Makefile.am
23 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
25 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
26 AC_ARG_ENABLE(buf-freelists,
27    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
28 AC_ARG_ENABLE(openbsd-malloc,
29    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
30 AC_ARG_ENABLE(instrument-downloads,
31    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
32 AC_ARG_ENABLE(static-openssl,
33    AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
34 AC_ARG_ENABLE(static-libevent,
35    AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
36 AC_ARG_ENABLE(static-zlib,
37    AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
38 AC_ARG_ENABLE(static-tor,
39    AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir))
40 AC_ARG_ENABLE(curve25519,
41    AS_HELP_STRING(--disable-curve25519, Build Tor with no curve25519 elliptic-curve crypto support))
42 AC_ARG_ENABLE(unittests,
43    AS_HELP_STRING(--disable-unittests, [Don't build unit tests for Tor. Risky!]))
44 AC_ARG_ENABLE(coverage,
45    AS_HELP_STRING(--enable-coverage, [Enable coverage support in the unit-test build]))
47 AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
48 AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
50 if test "$enable_static_tor" = "yes"; then
51   enable_static_libevent="yes";
52   enable_static_openssl="yes";
53   enable_static_zlib="yes";
54   CFLAGS="$CFLAGS -static"
57 if test x$enable_buf_freelists != xno; then
58   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
59             [Defined if we try to use freelists for buffer RAM chunks])
61 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
62 if test x$enable_instrument_downloads = xyes; then
63   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
64             [Defined if we want to keep track of how much of each kind of resource we download.])
67 AC_ARG_ENABLE(transparent,
68      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
69      [case "${enableval}" in
70         yes) transparent=true ;;
71         no)  transparent=false ;;
72         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
73       esac], [transparent=true])
75 AC_ARG_ENABLE(asciidoc,
76      AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
77      [case "${enableval}" in
78         yes) asciidoc=true ;;
79         no)  asciidoc=false ;;
80         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
81       esac], [asciidoc=true])
83 # By default, we're not ready to ship a NAT-PMP aware Tor
84 AC_ARG_ENABLE(nat-pmp,
85      AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
86      [case "${enableval}" in
87         yes) natpmp=true ;;
88         no)  natpmp=false ;;
89         * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
90       esac], [natpmp=false])
92 # By default, we're not ready to ship a UPnP aware Tor
93 AC_ARG_ENABLE(upnp,
94      AS_HELP_STRING(--enable-upnp, enable UPnP support),
95      [case "${enableval}" in
96         yes) upnp=true ;;
97         no)  upnp=false ;;
98         * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
99       esac], [upnp=false])
102 AC_ARG_ENABLE(threads,
103      AS_HELP_STRING(--disable-threads, disable multi-threading support))
105 if test x$enable_threads = x; then
106    case $host in
107     *-*-solaris* )
108      # Don't try multithreading on solaris -- cpuworkers seem to lock.
109      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
110 cpu workers lock up here, so I will disable threads.])
111      enable_threads="no";;
112     *)
113      enable_threads="yes";;
114    esac
117 if test "$enable_threads" = "yes"; then
118   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
121 case $host in
122    *-*-solaris* )
123      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
124      ;;
125 esac
127 AC_ARG_ENABLE(gcc-warnings,
128      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
129 AC_ARG_ENABLE(gcc-warnings-advisory,
130      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
132 dnl Adam shostack suggests the following for Windows:
133 dnl -D_FORTIFY_SOURCE=2 -fstack-protector-all
134 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
135 dnl This requires that we use gcc and that we add -O2 to the CFLAGS.
136 AC_ARG_ENABLE(gcc-hardening,
137     AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
139 dnl Linker hardening options
140 dnl Currently these options are ELF specific - you can't use this with MacOSX
141 AC_ARG_ENABLE(linker-hardening,
142     AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
144 AC_ARG_ENABLE(local-appdata,
145    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
146 if test "$enable_local_appdata" = "yes"; then
147   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
148             [Defined if we default to host local appdata paths on Windows])
151 # Tor2web mode flag
152 AC_ARG_ENABLE(tor2web-mode,
153      AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
154 [if test x$enableval = xyes; then
155     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
156 fi])
158 AC_ARG_ENABLE(bufferevents,
159      AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
161 AC_ARG_ENABLE(tool-name-check,
162      AS_HELP_STRING(--disable-tool-name-check, check for sanely named toolchain when cross-compiling))
164 dnl check for the correct "ar" when cross-compiling
165 AN_MAKEVAR([AR], [AC_PROG_AR])
166 AN_PROGRAM([ar], [AC_PROG_AR])
167 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
168 AC_PROG_AR
170 dnl Check whether the above macro has settled for a simply named tool even
171 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
172 dnl because that will find any cc on the system, not only the cross-compiler,
173 dnl and then verify that a binary built with this compiler runs on the
174 dnl build system. It will then come to the false conclusion that we're not
175 dnl cross-compiling.
176 if test x$enable_tool_name_check != xno; then
177     if test x$ac_tool_warned = xyes; then
178         AC_MSG_ERROR([We are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
179         elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
180                 AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
181         fi
184 AC_PROG_CC
185 AC_PROG_CPP
186 AC_PROG_MAKE_SET
187 AC_PROG_RANLIB
189 dnl autoconf 2.59 appears not to support AC_PROG_SED
190 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
192 dnl check for asciidoc and a2x
193 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
194 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
196 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
198 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
199 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
200 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
201 AM_PROG_CC_C_O
203 AC_ARG_VAR(PYTHON)
204 AC_CHECK_PROGS(PYTHON, [python python2 python3])
205 if test "x$PYTHON" = "x"; then
206   AC_MSG_WARN([Python unavailable; some tests will not be run.])
208 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
210 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
211 AC_C_FLEXIBLE_ARRAY_MEMBER
212 ], [
213  dnl Maybe we've got an old autoconf...
214  AC_CACHE_CHECK([for flexible array members],
215      tor_cv_c_flexarray,
216      [AC_COMPILE_IFELSE(
217        AC_LANG_PROGRAM([
218  struct abc { int a; char b[]; };
219 ], [
220  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
221  def->b[0] = 33;
223   [tor_cv_c_flexarray=yes],
224   [tor_cv_c_flexarray=no])])
225  if test $tor_cv_flexarray = yes ; then
226    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
227  else
228    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
229  fi
232 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
233 AC_PATH_PROG([OPENSSL], [openssl], none)
235 TORUSER=_tor
236 AC_ARG_WITH(tor-user,
237         [  --with-tor-user=NAME    Specify username for tor daemon ],
238         [
239            TORUSER=$withval
240         ]
242 AC_SUBST(TORUSER)
244 TORGROUP=_tor
245 AC_ARG_WITH(tor-group,
246         [  --with-tor-group=NAME   Specify group name for tor daemon ],
247         [
248            TORGROUP=$withval
249         ]
251 AC_SUBST(TORGROUP)
254 dnl If _WIN32 is defined and non-zero, we are building for win32
255 AC_MSG_CHECKING([for win32])
256 AC_RUN_IFELSE([AC_LANG_SOURCE([
257 int main(int c, char **v) {
258 #ifdef _WIN32
259 #if _WIN32
260   return 0;
261 #else
262   return 1;
263 #endif
264 #else
265   return 2;
266 #endif
267 }])],
268 bwin32=true; AC_MSG_RESULT([yes]),
269 bwin32=false; AC_MSG_RESULT([no]),
270 bwin32=cross; AC_MSG_RESULT([cross])
273 if test "$bwin32" = cross; then
274 AC_MSG_CHECKING([for win32 (cross)])
275 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
276 #ifdef _WIN32
277 int main(int c, char **v) {return 0;}
278 #else
279 #error
280 int main(int c, char **v) {return x(y);}
281 #endif
282 ])],
283 bwin32=true; AC_MSG_RESULT([yes]),
284 bwin32=false; AC_MSG_RESULT([no]))
287 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
289 dnl Enable C99 when compiling with MIPSpro
290 AC_MSG_CHECKING([for MIPSpro compiler])
291 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
292 #if (defined(__sgi) && defined(_COMPILER_VERSION))
293 #error
294   return x(y);
295 #endif
296 ])],
297 bmipspro=false; AC_MSG_RESULT(no),
298 bmipspro=true; AC_MSG_RESULT(yes))
300 if test "$bmipspro" = true; then
301   CFLAGS="$CFLAGS -c99"
304 AC_C_BIGENDIAN
306 AC_SEARCH_LIBS(socket, [socket network])
307 AC_SEARCH_LIBS(gethostbyname, [nsl])
308 AC_SEARCH_LIBS(dlopen, [dl])
309 AC_SEARCH_LIBS(inet_aton, [resolv])
310 saved_LIBS="$LIBS"
311 AC_SEARCH_LIBS([clock_gettime], [rt])
312 if test "$LIBS" != "$saved_LIBS"; then
313    # Looks like we need -lrt for clock_gettime().
314    have_rt=yes
317 if test "$enable_threads" = "yes"; then
318   AC_SEARCH_LIBS(pthread_create, [pthread])
319   AC_SEARCH_LIBS(pthread_detach, [pthread])
322 dnl -------------------------------------------------------------------
323 dnl Check for functions before libevent, since libevent-1.2 apparently
324 dnl exports strlcpy without defining it in a header.
326 AC_CHECK_FUNCS(
327         _NSGetEnviron \
328         accept4 \
329         backtrace \
330         backtrace_symbols_fd \
331         clock_gettime \
332         flock \
333         ftime \
334         getaddrinfo \
335         getifaddrs \
336         getrlimit \
337         gettimeofday \
338         gmtime_r \
339         inet_aton \
340         ioctl \
341         issetugid \
342         llround \
343         localtime_r \
344         lround \
345         memmem \
346         prctl \
347         rint \
348         sigaction \
349         socketpair \
350         strlcat \
351         strlcpy \
352         strptime \
353         strtok_r \
354         strtoull \
355         sysconf \
356         uname \
357         vasprintf \
358         _vscprintf
361 if test "$enable_threads" = "yes"; then
362   AC_CHECK_HEADERS(pthread.h)
363   AC_CHECK_FUNCS(pthread_create)
366 dnl ------------------------------------------------------
367 dnl Where do you live, libevent?  And how do we call you?
369 if test "$bwin32" = true; then
370   TOR_LIB_WS32=-lws2_32
371   TOR_LIB_IPHLPAPI=-liphlpapi
372   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
373   # think it's actually necessary.
374   TOR_LIB_GDI=-lgdi32
375 else
376   TOR_LIB_WS32=
377   TOR_LIB_GDI=
379 AC_SUBST(TOR_LIB_WS32)
380 AC_SUBST(TOR_LIB_GDI)
381 AC_SUBST(TOR_LIB_IPHLPAPI)
383 dnl We need to do this before we try our disgusting hack below.
384 AC_CHECK_HEADERS([sys/types.h])
386 dnl This is a disgusting hack so we safely include older libevent headers.
387 AC_CHECK_TYPE(u_int64_t, unsigned long long)
388 AC_CHECK_TYPE(u_int32_t, unsigned long)
389 AC_CHECK_TYPE(u_int16_t, unsigned short)
390 AC_CHECK_TYPE(u_int8_t, unsigned char)
392 tor_libevent_pkg_redhat="libevent"
393 tor_libevent_pkg_debian="libevent-dev"
394 tor_libevent_devpkg_redhat="libevent-devel"
395 tor_libevent_devpkg_debian="libevent-dev"
397 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
398 dnl linking for static builds.
399 STATIC_LIBEVENT_FLAGS=""
400 if test "$enable_static_libevent" = "yes"; then
401     if test "$have_rt" = yes; then
402       STATIC_LIBEVENT_FLAGS=" -lrt "
403     fi
406 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
407 #ifdef _WIN32
408 #include <winsock2.h>
409 #endif
410 #include <stdlib.h>
411 #include <sys/time.h>
412 #include <sys/types.h>
413 #include <event.h>], [
414 #ifdef _WIN32
415 #include <winsock2.h>
416 #endif
417 void exit(int); void *event_init(void);],
418     [
419 #ifdef _WIN32
420 {WSADATA d; WSAStartup(0x101,&d); }
421 #endif
422 event_init(); exit(0);
423 ], [--with-libevent-dir], [/opt/libevent])
425 dnl Now check for particular libevent functions.
426 save_LIBS="$LIBS"
427 save_LDFLAGS="$LDFLAGS"
428 save_CPPFLAGS="$CPPFLAGS"
429 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
430 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
431 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
432 AC_CHECK_FUNCS([event_get_version \
433                 event_get_version_number \
434                 event_get_method \
435                 event_set_log_callback \
436                 evdns_set_outgoing_bind_address \
437                 evutil_secure_rng_set_urandom_device_file \
438                 event_base_loopexit])
439 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
440 [#include <event.h>
443 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
445 LIBS="$save_LIBS"
446 LDFLAGS="$save_LDFLAGS"
447 CPPFLAGS="$save_CPPFLAGS"
450 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
452 if test "$enable_static_libevent" = "yes"; then
453    if test "$tor_cv_library_libevent_dir" = "(system)"; then
454      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
455    else
456      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
457    fi
458 else
459      TOR_LIBEVENT_LIBS="-levent"
462 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
463 dnl we can do much better.
464 if test "$enable_bufferevents" = "yes" ; then
465   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
466     AC_MSG_ERROR([You've asked for bufferevent support, but you're using a version of Libevent without SSL support.  This won't work.  We need Libevent 2.0.8-rc or later, and you don't seem to even have Libevent 2.0.3-alpha.])
467   else
469     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
471     # Check for the right version.  First see if version detection works.
472     AC_MSG_CHECKING([whether we can detect the Libevent version])
473     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
474 #include <event2/event.h>
475 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
476 #error
477 int x = y(zz);
478 #else
479 int x = 1;
480 #endif
481   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
482      [event_version_number_works=no;  AC_MSG_RESULT([no])])
483     if test "$event_version_number_works" != 'yes'; then
484       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
485     else
486       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
487       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
488 #include <event2/event.h>
489 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
490 #error
491 int x = y(zz);
492 #else
493 int x = 1;
494 #endif
495    ])], [ AC_MSG_RESULT([yes]) ],
496       [ AC_MSG_RESULT([no])
497         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
498     fi
499   fi
502 LIBS="$save_LIBS"
503 LDFLAGS="$save_LDFLAGS"
504 CPPFLAGS="$save_CPPFLAGS"
506 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
507 if test "$enable_bufferevents" = "yes"; then
508   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
509   if test "$enable_static_libevent" = "yes"; then
510     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
511   else
512     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
513   fi
515 AC_SUBST(TOR_LIBEVENT_LIBS)
517 dnl ------------------------------------------------------
518 dnl Where do you live, libm?
520 dnl On some platforms (Haiku/BeOS) the math library is
521 dnl part of libroot. In which case don't link against lm
522 TOR_LIB_MATH=""
523 save_LIBS="$LIBS"
524 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
525 if test "$ac_cv_search_pow" != "none required"; then
526     TOR_LIB_MATH="$ac_cv_search_pow"
528 LIBS="$save_LIBS"
529 AC_SUBST(TOR_LIB_MATH)
531 dnl ------------------------------------------------------
532 dnl Where do you live, openssl?  And how do we call you?
534 tor_openssl_pkg_redhat="openssl"
535 tor_openssl_pkg_debian="libssl-dev"
536 tor_openssl_devpkg_redhat="openssl-devel"
537 tor_openssl_devpkg_debian="libssl-dev"
539 ALT_openssl_WITHVAL=""
540 AC_ARG_WITH(ssl-dir,
541   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
542   [
543       if test "x$withval" != xno && test "x$withval" != "x" ; then
544          ALT_openssl_WITHVAL="$withval"
545       fi
546   ])
548 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
549     [#include <openssl/rand.h>],
550     [void RAND_add(const void *buf, int num, double entropy);],
551     [RAND_add((void*)0,0,0); exit(0);], [],
552     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
554 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
556 if test "$enable_static_openssl" = "yes"; then
557    if test "$tor_cv_library_openssl_dir" = "(system)"; then
558      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
559    else
560      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
561    fi
562 else
563      TOR_OPENSSL_LIBS="-lssl -lcrypto"
565 AC_SUBST(TOR_OPENSSL_LIBS)
567 dnl ------------------------------------------------------
568 dnl Where do you live, zlib?  And how do we call you?
570 tor_zlib_pkg_redhat="zlib"
571 tor_zlib_pkg_debian="zlib1g"
572 tor_zlib_devpkg_redhat="zlib-devel"
573 tor_zlib_devpkg_debian="zlib1g-dev"
575 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
576     [#include <zlib.h>],
577     [const char * zlibVersion(void);],
578     [zlibVersion(); exit(0);], [--with-zlib-dir],
579     [/opt/zlib])
581 if test "$enable_static_zlib" = "yes"; then
582    if test "$tor_cv_library_zlib_dir" = "(system)"; then
583      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
584  using --enable-static-zlib")
585    else
586      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
587    fi
588 else
589      TOR_ZLIB_LIBS="-lz"
591 AC_SUBST(TOR_ZLIB_LIBS)
593 dnl ---------------------------------------------------------------------
594 dnl Now that we know about our major libraries, we can check for compiler
595 dnl and linker hardening options.  We need to do this with the libraries known,
596 dnl since sometimes the linker will like an option but not be willing to
597 dnl use it with a build of a library.
599 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
600 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
602 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
603 #if !defined(__clang__)
604 #error
605 #endif])], have_clang=yes, have_clang=no)
607 if test x$enable_gcc_hardening != xno; then
608     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
609     if test x$have_clang = xyes; then
610         TOR_CHECK_CFLAGS(-Qunused-arguments)
611     fi
612     TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
613     AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
614     AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
615     AS_VAR_IF(can_compile, [yes],
616         AS_VAR_IF(can_link, [yes],
617                   [],
618                   AC_MSG_ERROR([We tried to build with stack protection; it looks like your compiler supports it but your libc does not provide it. Are you missing libssp? (You can --disable-gcc-hardening to ignore this error.)]))
619         )
620     AS_VAR_POPDEF([can_link])
621     AS_VAR_POPDEF([can_compile])
622     TOR_CHECK_CFLAGS(-Wstack-protector)
623     TOR_CHECK_CFLAGS(-fwrapv)
624     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
625     if test "$bwin32" = "false"; then
626        TOR_CHECK_CFLAGS(-fPIE)
627        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
628     fi
631 if test x$enable_linker_hardening != xno; then
632     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
635 # For backtrace support
636 TOR_CHECK_LDFLAGS(-rdynamic)
638 dnl ------------------------------------------------------
639 dnl Now see if we have a -fomit-frame-pointer compiler option.
641 saved_CFLAGS="$CFLAGS"
642 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
643 if test "$saved_CFLAGS" != "$CFLAGS"; then
644   F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
645 else
646   F_OMIT_FRAME_POINTER=''
648 CFLAGS="$saved_CFLAGS"
649 AC_SUBST(F_OMIT_FRAME_POINTER)
651 dnl ------------------------------------------------------
652 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
653 dnl for us, as GCC 4.6 and later do at many optimization levels), then
654 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
655 dnl code will work.
656 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
658 dnl ------------------------------------------------------
659 dnl Where do you live, libnatpmp?  And how do we call you?
660 dnl There are no packages for Debian or Redhat as of this patch
662 if test "$natpmp" = "true"; then
663     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
664     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
665         [#include <natpmp.h>],
666         [#ifdef _WIN32
667          #define STATICLIB
668          #endif
669          #include <natpmp.h>],
670         [   int r;
671             natpmp_t natpmp;
672             natpmpresp_t response;
673             r = initnatpmp(&natpmp, 0, 0);],
674             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
675             exit(0);],
676         [--with-libnatpmp-dir],
677         [/usr/lib/])
681 dnl ------------------------------------------------------
682 dnl Where do you live, libminiupnpc?  And how do we call you?
683 dnl There are no packages for Debian or Redhat as of this patch
685 if test "$upnp" = "true"; then
686     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
688     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
689     dnl to see if we have miniupnpc-1.5 or -1.6
690     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
691         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
693     if test "$miniupnpc15" = "true" ; then
694         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
695         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
696             [#include <miniupnpc/miniwget.h>
697              #include <miniupnpc/miniupnpc.h>
698              #include <miniupnpc/upnpcommands.h>],
699             [void upnpDiscover(int delay, const char * multicastif,
700              const char * minissdpdsock, int sameport);],
701             [upnpDiscover(1, 0, 0, 0); exit(0);],
702             [--with-libminiupnpc-dir],
703             [/usr/lib/])
704     else
705         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
706             [#include <miniupnpc/miniwget.h>
707              #include <miniupnpc/miniupnpc.h>
708              #include <miniupnpc/upnpcommands.h>],
709             [void upnpDiscover(int delay, const char * multicastif,
710              const char * minissdpdsock, int sameport, int ipv6, int * error);],
711             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
712             [--with-libminiupnpc-dir],
713             [/usr/lib/])
714     fi
717 dnl ============================================================
718 dnl Check for libseccomp
720 AC_CHECK_HEADERS([seccomp.h])
721 AC_SEARCH_LIBS(seccomp_init, [seccomp])
723 dnl ============================================================
724 dnl We need an implementation of curve25519.
726 dnl set these defaults.
727 have_a_curve25519=no
728 build_curve25519_donna=no
729 build_curve25519_donna_c64=no
730 use_curve25519_donna=no
731 use_curve25519_nacl=no
732 CURVE25519_LIBS=
734 if test x$enable_curve25519 != xno; then
736   dnl The best choice is using curve25519-donna-c64, but that requires
737   dnl that we
738   AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
739     tor_cv_can_use_curve25519_donna_c64,
740     [AC_RUN_IFELSE(
741       [AC_LANG_PROGRAM([dnl
742         #include <stdint.h>
743         typedef unsigned uint128_t __attribute__((mode(TI)));
744         int func(uint64_t a, uint64_t b) {
745              uint128_t c = ((uint128_t)a) * b;
746              int ok = ((uint64_t)(c>>96)) == 522859 &&
747                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
748                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
749                    (((uint64_t)(c))&0xffffffffL) == 0;
750              return ok;
751         }
752         ], [dnl
753           int ok = func( ((uint64_t)2000000000) * 1000000000,
754                          ((uint64_t)1234567890) << 24);
755           return !ok;
756         ])],
757         [tor_cv_can_use_curve25519_donna_c64=yes],
758         [tor_cv_can_use_curve25519_donna_c64=no],
759         [AC_COMPILE_IFELSE(
760           [AC_LANG_PROGRAM([dnl
761         #include <stdint.h>
762         typedef unsigned uint128_t __attribute__((mode(TI)));
763         int func(uint64_t a, uint64_t b) {
764              uint128_t c = ((uint128_t)a) * b;
765              int ok = ((uint64_t)(c>>96)) == 522859 &&
766                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
767                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
768                    (((uint64_t)(c))&0xffffffffL) == 0;
769              return ok;
770         }
771         ], [dnl
772           int ok = func( ((uint64_t)2000000000) * 1000000000,
773                          ((uint64_t)1234567890) << 24);
774           return !ok;
775         ])],
776             [tor_cv_can_use_curve25519_donna_c64=cross],
777             [tor_cv_can_use_curve25519_donna_c64=no])])])
779   AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
780                     nacl/crypto_scalarmult_curve25519.h])
782   AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
783     tor_cv_can_use_curve25519_nacl,
784     [tor_saved_LIBS="$LIBS"
785      LIBS="$LIBS -lnacl"
786      AC_LINK_IFELSE(
787        [AC_LANG_PROGRAM([dnl
788          #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
789          #include <crypto_scalarmult_curve25519.h>
790          #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
791          #include <nacl/crypto_scalarmult_curve25519.h>
792          #endif
793          #ifdef crypto_scalarmult_curve25519_ref_BYTES
794          #error Hey, this is the reference implementation! That's not fast.
795          #endif
796        ], [
797          unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
798        ])], [tor_cv_can_use_curve25519_nacl=yes],
799        [tor_cv_can_use_curve25519_nacl=no])
800      LIBS="$tor_saved_LIBS" ])
802    dnl Okay, now we need to figure out which one to actually use. Fall back
803    dnl to curve25519-donna.c
805    if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
806      build_curve25519_donna_c64=yes
807      use_curve25519_donna=yes
808    elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
809      use_curve25519_nacl=yes
810      CURVE25519_LIBS=-lnacl
811    else
812      build_curve25519_donna=yes
813      use_curve25519_donna=yes
814    fi
815    have_a_curve25519=yes
818 if test x$have_a_curve25519 = xyes; then
819   AC_DEFINE(CURVE25519_ENABLED, 1,
820             [Defined if we have a curve25519 implementation])
822 if test x$use_curve25519_donna = xyes; then
823   AC_DEFINE(USE_CURVE25519_DONNA, 1,
824             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
826 if test x$use_curve25519_nacl = xyes; then
827   AC_DEFINE(USE_CURVE25519_NACL, 1,
828             [Defined if we should use a curve25519 from nacl])
830 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
831 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
832 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
833 AC_SUBST(CURVE25519_LIBS)
835 dnl Make sure to enable support for large off_t if available.
836 AC_SYS_LARGEFILE
838 AC_CHECK_HEADERS(
839         assert.h \
840         errno.h \
841         fcntl.h \
842         signal.h \
843         string.h \
844         sys/fcntl.h \
845         sys/stat.h \
846         sys/time.h \
847         sys/types.h \
848         time.h \
849         unistd.h
850  , , 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.))
852 dnl These headers are not essential
854 AC_CHECK_HEADERS(
855         arpa/inet.h \
856         crt_externs.h \
857         execinfo.h \
858         grp.h \
859         ifaddrs.h \
860         inttypes.h \
861         limits.h \
862         linux/types.h \
863         machine/limits.h \
864         malloc.h \
865         malloc/malloc.h \
866         malloc_np.h \
867         netdb.h \
868         netinet/in.h \
869         netinet/in6.h \
870         pwd.h \
871         stdint.h \
872         sys/file.h \
873         sys/ioctl.h \
874         sys/limits.h \
875         sys/mman.h \
876         sys/param.h \
877         sys/prctl.h \
878         sys/resource.h \
879         sys/socket.h \
880         sys/syslimits.h \
881         sys/time.h \
882         sys/types.h \
883         sys/un.h \
884         sys/utime.h \
885         sys/wait.h \
886         syslog.h \
887         utime.h
890 AC_CHECK_HEADERS(sys/param.h)
892 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
893 [#ifdef HAVE_SYS_TYPES_H
894 #include <sys/types.h>
895 #endif
896 #ifdef HAVE_SYS_SOCKET_H
897 #include <sys/socket.h>
898 #endif])
899 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
900 [#ifdef HAVE_SYS_TYPES_H
901 #include <sys/types.h>
902 #endif
903 #ifdef HAVE_SYS_SOCKET_H
904 #include <sys/socket.h>
905 #endif
906 #ifdef HAVE_NET_IF_H
907 #include <net/if.h>
908 #endif])
909 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
910         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
911 [#ifdef HAVE_SYS_TYPES_H
912 #include <sys/types.h>
913 #endif
914 #ifdef HAVE_SYS_SOCKET_H
915 #include <sys/socket.h>
916 #endif
917 #ifdef HAVE_LIMITS_H
918 #include <limits.h>
919 #endif
920 #ifdef HAVE_LINUX_TYPES_H
921 #include <linux/types.h>
922 #endif
923 #ifdef HAVE_NETINET_IN6_H
924 #include <netinet/in6.h>
925 #endif
926 #ifdef HAVE_NETINET_IN_H
927 #include <netinet/in.h>
928 #endif])
930 if test x$transparent = xtrue ; then
931    transparent_ok=0
932    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
933      transparent_ok=1
934    fi
935    if test x$linux_netfilter_ipv4 = x1 ; then
936      transparent_ok=1
937    fi
938    if test x$transparent_ok = x1 ; then
939      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
940      case $host in
941        *-*-openbsd* | *-*-bitrig*)
942          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
943      esac
944    else
945      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
946    fi
949 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
950 [#ifdef HAVE_SYS_TYPES_H
951 #include <sys/types.h>
952 #endif
953 #ifdef HAVE_SYS_TIME_H
954 #include <sys/time.h>
955 #endif])
957 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
958 dnl Watch out.
960 AC_CHECK_SIZEOF(int8_t)
961 AC_CHECK_SIZEOF(int16_t)
962 AC_CHECK_SIZEOF(int32_t)
963 AC_CHECK_SIZEOF(int64_t)
964 AC_CHECK_SIZEOF(uint8_t)
965 AC_CHECK_SIZEOF(uint16_t)
966 AC_CHECK_SIZEOF(uint32_t)
967 AC_CHECK_SIZEOF(uint64_t)
968 AC_CHECK_SIZEOF(intptr_t)
969 AC_CHECK_SIZEOF(uintptr_t)
971 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
973 AC_CHECK_SIZEOF(char)
974 AC_CHECK_SIZEOF(short)
975 AC_CHECK_SIZEOF(int)
976 AC_CHECK_SIZEOF(long)
977 AC_CHECK_SIZEOF(long long)
978 AC_CHECK_SIZEOF(__int64)
979 AC_CHECK_SIZEOF(void *)
980 AC_CHECK_SIZEOF(time_t)
981 AC_CHECK_SIZEOF(size_t)
982 AC_CHECK_SIZEOF(pid_t)
984 AC_CHECK_TYPES([uint, u_char, ssize_t])
986 AC_PC_FROM_UCONTEXT([/bin/true])
988 dnl used to include sockaddr_storage, but everybody has that.
989 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
990 [#ifdef HAVE_SYS_TYPES_H
991 #include <sys/types.h>
992 #endif
993 #ifdef HAVE_NETINET_IN_H
994 #include <netinet/in.h>
995 #endif
996 #ifdef HAVE_NETINET_IN6_H
997 #include <netinet/in6.h>
998 #endif
999 #ifdef HAVE_SYS_SOCKET_H
1000 #include <sys/socket.h>
1001 #endif
1002 #ifdef _WIN32
1003 #define _WIN32_WINNT 0x0501
1004 #define WIN32_LEAN_AND_MEAN
1005 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1006 #include <winsock.h>
1007 #else
1008 #include <winsock2.h>
1009 #include <ws2tcpip.h>
1010 #endif
1011 #endif
1013 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1014 [#ifdef HAVE_SYS_TYPES_H
1015 #include <sys/types.h>
1016 #endif
1017 #ifdef HAVE_NETINET_IN_H
1018 #include <netinet/in.h>
1019 #endif
1020 #ifdef HAVE_NETINET_IN6_H
1021 #include <netinet/in6.h>
1022 #endif
1023 #ifdef HAVE_SYS_SOCKET_H
1024 #include <sys/socket.h>
1025 #endif
1026 #ifdef _WIN32
1027 #define _WIN32_WINNT 0x0501
1028 #define WIN32_LEAN_AND_MEAN
1029 #if defined(_MSC_VER) && (_MSC_VER < 1300)
1030 #include <winsock.h>
1031 #else
1032 #include <winsock2.h>
1033 #include <ws2tcpip.h>
1034 #endif
1035 #endif
1038 AC_CHECK_TYPES([rlim_t], , ,
1039 [#ifdef HAVE_SYS_TYPES_H
1040 #include <sys/types.h>
1041 #endif
1042 #ifdef HAVE_SYS_TIME_H
1043 #include <sys/time.h>
1044 #endif
1045 #ifdef HAVE_SYS_RESOURCE_H
1046 #include <sys/resource.h>
1047 #endif
1050 AX_CHECK_SIGN([time_t],
1051        [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
1052        [ : ], [
1053 #ifdef HAVE_SYS_TYPES_H
1054 #include <sys/types.h>
1055 #endif
1056 #ifdef HAVE_SYS_TIME_H
1057 #include <sys/time.h>
1058 #endif
1059 #ifdef HAVE_TIME_H
1060 #include <time.h>
1061 #endif
1064 if test "$ax_cv_decl_time_t_signed" = no; then
1065   AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1068 AX_CHECK_SIGN([size_t],
1069        [ tor_cv_size_t_signed=yes ],
1070        [ tor_cv_size_t_signed=no ], [
1071 #ifdef HAVE_SYS_TYPES_H
1072 #include <sys/types.h>
1073 #endif
1076 if test "$ax_cv_decl_size_t_signed" = yes; then
1077   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1080 AX_CHECK_SIGN([enum always],
1081        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1082        [ : ], [
1083  enum always { AAA, BBB, CCC };
1086 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1087 #ifdef HAVE_SYS_SOCKET_H
1088 #include <sys/socket.h>
1089 #endif
1092 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1094 AC_CHECK_SIZEOF(cell_t)
1096 # Now make sure that NULL can be represented as zero bytes.
1097 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1098 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1099 [[#include <stdlib.h>
1100 #include <string.h>
1101 #include <stdio.h>
1102 #ifdef HAVE_STDDEF_H
1103 #include <stddef.h>
1104 #endif
1105 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1106 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1107        [tor_cv_null_is_zero=yes],
1108        [tor_cv_null_is_zero=no],
1109        [tor_cv_null_is_zero=cross])])
1111 if test "$tor_cv_null_is_zero" = cross ; then
1112   # Cross-compiling; let's hope that the target isn't raving mad.
1113   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1116 if test "$tor_cv_null_is_zero" != no; then
1117   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1118             [Define to 1 iff memset(0) sets pointers to NULL])
1121 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1122 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1123 [[#include <stdlib.h>
1124 #include <string.h>
1125 #include <stdio.h>
1126 #ifdef HAVE_STDDEF_H
1127 #include <stddef.h>
1128 #endif
1129 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1130 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1131        [tor_cv_dbl0_is_zero=yes],
1132        [tor_cv_dbl0_is_zero=no],
1133        [tor_cv_dbl0_is_zero=cross])])
1135 if test "$tor_cv_dbl0_is_zero" = cross ; then
1136   # Cross-compiling; let's hope that the target isn't raving mad.
1137   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1140 if test "$tor_cv_dbl0_is_zero" != no; then
1141   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1142             [Define to 1 iff memset(0) sets doubles to 0.0])
1145 # And what happens when we malloc zero?
1146 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1147 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1148 [[#include <stdlib.h>
1149 #include <string.h>
1150 #include <stdio.h>
1151 #ifdef HAVE_STDDEF_H
1152 #include <stddef.h>
1153 #endif
1154 int main () { return malloc(0)?0:1; }]])],
1155        [tor_cv_malloc_zero_works=yes],
1156        [tor_cv_malloc_zero_works=no],
1157        [tor_cv_malloc_zero_works=cross])])
1159 if test "$tor_cv_malloc_zero_works" = cross; then
1160   # Cross-compiling; let's hope that the target isn't raving mad.
1161   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1164 if test "$tor_cv_malloc_zero_works" = yes; then
1165   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1166             [Define to 1 iff malloc(0) returns a pointer])
1169 # whether we seem to be in a 2s-complement world.
1170 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1171 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1172 [[int main () { int problem = ((-99) != (~99)+1);
1173 return problem ? 1 : 0; }]])],
1174        [tor_cv_twos_complement=yes],
1175        [tor_cv_twos_complement=no],
1176        [tor_cv_twos_complement=cross])])
1178 if test "$tor_cv_twos_complement" = cross ; then
1179   # Cross-compiling; let's hope that the target isn't raving mad.
1180   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1183 if test "$tor_cv_twos_complement" != no ; then
1184   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1185             [Define to 1 iff we represent negative integers with two's complement])
1188 # What does shifting a negative value do?
1189 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1190 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1191 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1192        [tor_cv_sign_extend=yes],
1193        [tor_cv_sign_extend=no],
1194        [tor_cv_sign_extend=cross])])
1196 if test "$tor_cv_sign_extend" = cross ; then
1197   # Cross-compiling; let's hope that the target isn't raving mad.
1198   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1201 if test "$tor_cv_sign_extend" != no ; then
1202   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1203             [Define to 1 iff right-shifting a negative value performs sign-extension])
1206 # Whether we should use the dmalloc memory allocation debugging library.
1207 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1208 AC_ARG_WITH(dmalloc,
1209 [  --with-dmalloc          Use debug memory allocation library. ],
1210 [if [[ "$withval" = "yes" ]]; then
1211   dmalloc=1
1212   AC_MSG_RESULT(yes)
1213 else
1214   dmalloc=1
1215   AC_MSG_RESULT(no)
1216 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1219 if [[ $dmalloc -eq 1 ]]; then
1220   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1221   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1222   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1223   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1224   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1227 AC_ARG_WITH(tcmalloc,
1228 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1229 [ tcmalloc=yes ], [ tcmalloc=no ])
1231 if test x$tcmalloc = xyes ; then
1232    LDFLAGS="-ltcmalloc $LDFLAGS"
1235 using_custom_malloc=no
1236 if test x$enable_openbsd_malloc = xyes ; then
1237    using_custom_malloc=yes
1239 if test x$tcmalloc = xyes ; then
1240    using_custom_malloc=yes
1242 if test $using_custom_malloc = no ; then
1243    AC_CHECK_FUNCS(mallinfo)
1246 # By default, we're going to assume we don't have mlockall()
1247 # bionic and other platforms have various broken mlockall subsystems.
1248 # Some systems don't have a working mlockall, some aren't linkable,
1249 # and some have it but don't declare it.
1250 AC_CHECK_FUNCS(mlockall)
1251 AC_CHECK_DECLS([mlockall], , , [
1252 #ifdef HAVE_SYS_MMAN_H
1253 #include <sys/mman.h>
1254 #endif])
1256 # Allow user to specify an alternate syslog facility
1257 AC_ARG_WITH(syslog-facility,
1258 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1259 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1260 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1261 AC_SUBST(LOGFACILITY)
1263 # Check if we have getresuid and getresgid
1264 AC_CHECK_FUNCS(getresuid getresgid)
1266 # Check for gethostbyname_r in all its glorious incompatible versions.
1267 #   (This logic is based on that in Python's configure.in)
1268 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1269   [Define this if you have any gethostbyname_r()])
1271 AC_CHECK_FUNC(gethostbyname_r, [
1272   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1273   OLD_CFLAGS=$CFLAGS
1274   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1275   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1276 #include <netdb.h>
1277   ], [[
1278     char *cp1, *cp2;
1279     struct hostent *h1, *h2;
1280     int i1, i2;
1281     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1282   ]])],[
1283     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1284     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1285      [Define this if gethostbyname_r takes 6 arguments])
1286     AC_MSG_RESULT(6)
1287   ], [
1288     AC_TRY_COMPILE([
1289 #include <netdb.h>
1290     ], [
1291       char *cp1, *cp2;
1292       struct hostent *h1;
1293       int i1, i2;
1294       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1295     ], [
1296       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1297       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1298         [Define this if gethostbyname_r takes 5 arguments])
1299       AC_MSG_RESULT(5)
1300    ], [
1301       AC_TRY_COMPILE([
1302 #include <netdb.h>
1303      ], [
1304        char *cp1;
1305        struct hostent *h1;
1306        struct hostent_data hd;
1307        (void) gethostbyname_r(cp1,h1,&hd);
1308      ], [
1309        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1310        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1311          [Define this if gethostbyname_r takes 3 arguments])
1312        AC_MSG_RESULT(3)
1313      ], [
1314        AC_MSG_RESULT(0)
1315      ])
1316   ])
1317  ])
1318  CFLAGS=$OLD_CFLAGS
1321 AC_CACHE_CHECK([whether the C compiler supports __func__],
1322   tor_cv_have_func_macro,
1323   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1324 #include <stdio.h>
1325 int main(int c, char **v) { puts(__func__); }])],
1326   tor_cv_have_func_macro=yes,
1327   tor_cv_have_func_macro=no))
1329 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1330   tor_cv_have_FUNC_macro,
1331   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1332 #include <stdio.h>
1333 int main(int c, char **v) { puts(__FUNC__); }])],
1334   tor_cv_have_FUNC_macro=yes,
1335   tor_cv_have_FUNC_macro=no))
1337 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1338   tor_cv_have_FUNCTION_macro,
1339   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1340 #include <stdio.h>
1341 int main(int c, char **v) { puts(__FUNCTION__); }])],
1342   tor_cv_have_FUNCTION_macro=yes,
1343   tor_cv_have_FUNCTION_macro=no))
1345 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1346   tor_cv_have_environ_declared,
1347   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1348 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1349  * Without it environ doesn't get declared. */
1350 #define _GNU_SOURCE
1351 #ifdef HAVE_UNISTD_H
1352 #include <unistd.h>
1353 #endif
1354 #include <stdlib.h>
1355 int main(int c, char **v) { char **t = environ; }])],
1356   tor_cv_have_environ_declared=yes,
1357   tor_cv_have_environ_declared=no))
1359 if test "$tor_cv_have_func_macro" = 'yes'; then
1360   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1363 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1364   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1367 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1368   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1369            [Defined if the compiler supports __FUNCTION__])
1372 if test "$tor_cv_have_environ_declared" = 'yes'; then
1373   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1374            [Defined if we have extern char **environ already declared])
1377 # $prefix stores the value of the --prefix command line option, or
1378 # NONE if the option wasn't set.  In the case that it wasn't set, make
1379 # it be the default, so that we can use it to expand directories now.
1380 if test "x$prefix" = "xNONE"; then
1381   prefix=$ac_default_prefix
1384 # and similarly for $exec_prefix
1385 if test "x$exec_prefix" = "xNONE"; then
1386   exec_prefix=$prefix
1389 if test "x$BUILDDIR" = "x"; then
1390   BUILDDIR=`pwd`
1392 AC_SUBST(BUILDDIR)
1393 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1394 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1396 if test "x$CONFDIR" = "x"; then
1397   CONFDIR=`eval echo $sysconfdir/tor`
1399 AC_SUBST(CONFDIR)
1400 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1401 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1403 BINDIR=`eval echo $bindir`
1404 AC_SUBST(BINDIR)
1405 LOCALSTATEDIR=`eval echo $localstatedir`
1406 AC_SUBST(LOCALSTATEDIR)
1408 if test "$bwin32" = true; then
1409   # Test if the linker supports the --nxcompat and --dynamicbase options
1410   # for Windows
1411   save_LDFLAGS="$LDFLAGS"
1412   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1413   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1414   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1415     [AC_MSG_RESULT([yes])]
1416     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1417     [AC_MSG_RESULT([no])]
1418   )
1419   LDFLAGS="$save_LDFLAGS"
1422 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1423 # than autoconf's macros like.
1424 if test "$GCC" = yes; then
1425   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1426   # accident waiting to happen.
1427   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1428 else
1429   # Autoconf sets -g -O2 by default. Override optimization level
1430   # for non-gcc compilers
1431   CFLAGS="$CFLAGS -O"
1432   enable_gcc_warnings=no
1433   enable_gcc_warnings_advisory=no
1436 # OS X Lion started deprecating the system openssl. Let's just disable
1437 # all deprecation warnings on OS X. Also, to potentially make the binary
1438 # a little smaller, let's enable dead_strip.
1439 case "$host_os" in
1441  darwin*)
1442     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1443     LDFLAGS="$LDFLAGS -dead_strip" ;;
1444 esac
1446 # Add some more warnings which we use in development but not in the
1447 # released versions.  (Some relevant gcc versions can't handle these.)
1448 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1450   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1451 #if !defined(__GNUC__) || (__GNUC__ < 4)
1452 #error
1453 #endif])], have_gcc4=yes, have_gcc4=no)
1455   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1456 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1457 #error
1458 #endif])], have_gcc42=yes, have_gcc42=no)
1460   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1461 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1462 #error
1463 #endif])], have_gcc43=yes, have_gcc43=no)
1465   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1466 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
1467 #error
1468 #endif])], have_gcc46=yes, have_gcc46=no)
1471   save_CFLAGS="$CFLAGS"
1472   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1473   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1474                     have_shorten64_flag=no)
1475   CFLAGS="$save_CFLAGS"
1477   case $host in
1478     *-*-openbsd* | *-*-bitrig*)
1479       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1480       # That's fine, except that the headers don't pass -Wredundant-decls.
1481       # Therefore, let's disable -Wsystem-headers when we're building
1482       # with maximal warnings on OpenBSD.
1483       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1484   esac
1486   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1487   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1488   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1489   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1490   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1492   if test x$enable_gcc_warnings = xyes; then
1493     CFLAGS="$CFLAGS -Werror"
1494   fi
1496   # Disabled, so we can use mallinfo(): -Waggregate-return
1498   if test x$have_gcc4 = xyes ; then
1499     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1500     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1501   fi
1503   if test x$have_gcc42 = xyes ; then
1504     # These warnings break gcc 4.0.2 and work on gcc 4.2
1505     # XXXX020 See if any of these work with earlier versions.
1506     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1508     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1509   fi
1511   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1512     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1513     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1514   fi
1516   if test x$have_gcc43 = xyes ; then
1517     # These warnings break gcc 4.2 and work on gcc 4.3
1518     # XXXX020 See if any of these work with earlier versions.
1519     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1520   fi
1522   if test x$have_gcc46 = xyes ; then
1523     # This warning was added in gcc 4.3, but it appears to generate
1524     # spurious warnings in gcc 4.4.  I don't know if it works in 4.5.
1525     CFLAGS="$CFLAGS -Wlogical-op"
1526   fi
1528   if test x$have_shorten64_flag = xyes ; then
1529     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1530   fi
1534 ##This will break the world on some 64-bit architectures
1535 # CFLAGS="$CFLAGS -Winline"
1538 if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
1539    case "$host_os" in
1540     darwin*)
1541       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.])
1542    esac
1545 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1547 AC_CONFIG_FILES([
1548         Doxyfile
1549         Makefile
1550         contrib/suse/tor.sh
1551         contrib/tor.logrotate
1552         contrib/tor.sh
1553         contrib/torctl
1554         src/config/torrc.sample
1557 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1558   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1559   for file in $regular_mans ; do
1560     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1561       echo "==================================";
1562       echo;
1563       echo "You need asciidoc installed to be able to build the manpage.";
1564       echo "To build without manpages, use the --disable-asciidoc argument";
1565       echo "when calling configure.";
1566       echo;
1567       echo "==================================";
1568       exit 1;
1569     fi
1570   done
1573 AC_OUTPUT
1575 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1576   ./contrib/updateVersions.pl