Whoops: evdns_log, not tor_log, in src/ext/eventdns.c
[tor.git] / configure.ac
blob6c4a0792fee1c7837524324b19750fc73887f33e
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.4.9-alpha-dev])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AM_INIT_AUTOMAKE
9 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
10 AC_CONFIG_HEADERS([orconfig.h])
12 AC_CANONICAL_HOST
14 if test -f /etc/redhat-release ; then
15   if test -f /usr/kerberos/include ; then
16     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
17   fi
20 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
21 # the += operator on it in src/or/Makefile.am
22 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
24 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
25 AC_ARG_ENABLE(buf-freelists,
26    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
27 AC_ARG_ENABLE(openbsd-malloc,
28    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
29 AC_ARG_ENABLE(instrument-downloads,
30    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
31 AC_ARG_ENABLE(static-openssl,
32    AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
33 AC_ARG_ENABLE(static-libevent,
34    AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
35 AC_ARG_ENABLE(static-zlib,
36    AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
37 AC_ARG_ENABLE(static-tor,
38    AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir))
39 AC_ARG_ENABLE(curve25519,
40    AS_HELP_STRING(--disable-curve25519, Build Tor with no curve25519 elliptic-curve crypto support))
42 if test "$enable_static_tor" = "yes"; then
43   enable_static_libevent="yes";
44   enable_static_openssl="yes";
45   enable_static_zlib="yes";
46   CFLAGS="$CFLAGS -static"
49 if test x$enable_buf_freelists != xno; then
50   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
51             [Defined if we try to use freelists for buffer RAM chunks])
53 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
54 if test x$enable_instrument_downloads = xyes; then
55   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
56             [Defined if we want to keep track of how much of each kind of resource we download.])
59 AC_ARG_ENABLE(transparent,
60      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
61      [case "${enableval}" in
62         yes) transparent=true ;;
63         no)  transparent=false ;;
64         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
65       esac], [transparent=true])
67 AC_ARG_ENABLE(asciidoc,
68      AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
69      [case "${enableval}" in
70         yes) asciidoc=true ;;
71         no)  asciidoc=false ;;
72         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
73       esac], [asciidoc=true])
75 # By default, we're not ready to ship a NAT-PMP aware Tor
76 AC_ARG_ENABLE(nat-pmp,
77      AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
78      [case "${enableval}" in
79         yes) natpmp=true ;;
80         no)  natpmp=false ;;
81         * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
82       esac], [natpmp=false])
84 # By default, we're not ready to ship a UPnP aware Tor
85 AC_ARG_ENABLE(upnp,
86      AS_HELP_STRING(--enable-upnp, enable UPnP support),
87      [case "${enableval}" in
88         yes) upnp=true ;;
89         no)  upnp=false ;;
90         * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
91       esac], [upnp=false])
94 AC_ARG_ENABLE(threads,
95      AS_HELP_STRING(--disable-threads, disable multi-threading support))
97 if test x$enable_threads = x; then
98    case $host in
99     *-*-solaris* )
100      # Don't try multithreading on solaris -- cpuworkers seem to lock.
101      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
102 cpu workers lock up here, so I will disable threads.])
103      enable_threads="no";;
104     *)
105      enable_threads="yes";;
106    esac
109 if test "$enable_threads" = "yes"; then
110   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
113 case $host in
114    *-*-solaris* )
115      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
116      ;;
117 esac
119 AC_ARG_ENABLE(gcc-warnings,
120      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
121 AC_ARG_ENABLE(gcc-warnings-advisory,
122      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
124 dnl Adam shostack suggests the following for Windows:
125 dnl -D_FORTIFY_SOURCE=2 -fstack-protector-all
126 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
127 dnl This requires that we use gcc and that we add -O2 to the CFLAGS.
128 AC_ARG_ENABLE(gcc-hardening,
129     AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
131 dnl Linker hardening options
132 dnl Currently these options are ELF specific - you can't use this with MacOSX
133 AC_ARG_ENABLE(linker-hardening,
134     AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
136 AC_ARG_ENABLE(local-appdata,
137    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
138 if test "$enable_local_appdata" = "yes"; then
139   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
140             [Defined if we default to host local appdata paths on Windows])
143 # Tor2web mode flag
144 AC_ARG_ENABLE(tor2web-mode,
145      AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
146 [if test x$enableval = xyes; then
147     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
148 fi])
150 AC_ARG_ENABLE(bufferevents,
151      AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
153 dnl check for the correct "ar" when cross-compiling
154 AN_MAKEVAR([AR], [AC_PROG_AR])
155 AN_PROGRAM([ar], [AC_PROG_AR])
156 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
157 AC_PROG_AR
159 AC_PROG_CC
160 AC_PROG_CPP
161 AC_PROG_MAKE_SET
162 AC_PROG_RANLIB
164 dnl autoconf 2.59 appears not to support AC_PROG_SED
165 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
167 dnl check for asciidoc and a2x
168 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
169 AC_PATH_PROG([A2X], [a2x], none)
171 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
173 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
174 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
175 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
176 AM_PROG_CC_C_O
178 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
179 AC_C_FLEXIBLE_ARRAY_MEMBER
180 ], [
181  dnl Maybe we've got an old autoconf...
182  AC_CACHE_CHECK([for flexible array members],
183      tor_cv_c_flexarray,
184      [AC_COMPILE_IFELSE(
185        AC_LANG_PROGRAM([
186  struct abc { int a; char b[]; };
187 ], [
188  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
189  def->b[0] = 33;
191   [tor_cv_c_flexarray=yes],
192   [tor_cv_c_flexarray=no])])
193  if test $tor_cv_flexarray = yes ; then
194    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
195  else
196    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
197  fi
200 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
201 AC_PATH_PROG([OPENSSL], [openssl], none)
203 TORUSER=_tor
204 AC_ARG_WITH(tor-user,
205         [  --with-tor-user=NAME    Specify username for tor daemon ],
206         [
207            TORUSER=$withval
208         ]
210 AC_SUBST(TORUSER)
212 TORGROUP=_tor
213 AC_ARG_WITH(tor-group,
214         [  --with-tor-group=NAME   Specify group name for tor daemon ],
215         [
216            TORGROUP=$withval
217         ]
219 AC_SUBST(TORGROUP)
222 dnl If _WIN32 is defined and non-zero, we are building for win32
223 AC_MSG_CHECKING([for win32])
224 AC_RUN_IFELSE([AC_LANG_SOURCE([
225 int main(int c, char **v) {
226 #ifdef _WIN32
227 #if _WIN32
228   return 0;
229 #else
230   return 1;
231 #endif
232 #else
233   return 2;
234 #endif
235 }])],
236 bwin32=true; AC_MSG_RESULT([yes]),
237 bwin32=false; AC_MSG_RESULT([no]),
238 bwin32=cross; AC_MSG_RESULT([cross])
241 if test "$bwin32" = cross; then
242 AC_MSG_CHECKING([for win32 (cross)])
243 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
244 #ifdef _WIN32
245 int main(int c, char **v) {return 0;}
246 #else
247 #error
248 int main(int c, char **v) {return x(y);}
249 #endif
250 ])],
251 bwin32=true; AC_MSG_RESULT([yes]),
252 bwin32=false; AC_MSG_RESULT([no]))
255 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
257 dnl Enable C99 when compiling with MIPSpro
258 AC_MSG_CHECKING([for MIPSpro compiler])
259 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
260 #if (defined(__sgi) && defined(_COMPILER_VERSION))
261 #error
262   return x(y);
263 #endif
264 ])],
265 bmipspro=false; AC_MSG_RESULT(no),
266 bmipspro=true; AC_MSG_RESULT(yes))
268 if test "$bmipspro" = true; then
269   CFLAGS="$CFLAGS -c99"
272 AC_C_BIGENDIAN
274 AC_SEARCH_LIBS(socket, [socket network])
275 AC_SEARCH_LIBS(gethostbyname, [nsl])
276 AC_SEARCH_LIBS(dlopen, [dl])
277 AC_SEARCH_LIBS(inet_aton, [resolv])
278 saved_LIBS="$LIBS"
279 AC_SEARCH_LIBS([clock_gettime], [rt])
280 if test "$LIBS" != "$saved_LIBS"; then
281    # Looks like we need -lrt for clock_gettime().
282    have_rt=yes
285 if test "$enable_threads" = "yes"; then
286   AC_SEARCH_LIBS(pthread_create, [pthread])
287   AC_SEARCH_LIBS(pthread_detach, [pthread])
290 dnl -------------------------------------------------------------------
291 dnl Check for functions before libevent, since libevent-1.2 apparently
292 dnl exports strlcpy without defining it in a header.
294 AC_CHECK_FUNCS(
295         _NSGetEnviron \
296         accept4 \
297         clock_gettime \
298         flock \
299         ftime \
300         getaddrinfo \
301         getifaddrs \
302         getrlimit \
303         gettimeofday \
304         gmtime_r \
305         inet_aton \
306         ioctl \
307         issetugid \
308         llround \
309         localtime_r \
310         lround \
311         memmem \
312         prctl \
313         rint \
314         socketpair \
315         strlcat \
316         strlcpy \
317         strptime \
318         strtok_r \
319         strtoull \
320         sysconf \
321         uname \
322         vasprintf \
323         _vscprintf
326 if test "$enable_threads" = "yes"; then
327   AC_CHECK_HEADERS(pthread.h)
328   AC_CHECK_FUNCS(pthread_create)
331 dnl ------------------------------------------------------
332 dnl Where do you live, libevent?  And how do we call you?
334 if test "$bwin32" = true; then
335   TOR_LIB_WS32=-lws2_32
336   TOR_LIB_IPHLPAPI=-liphlpapi
337   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
338   # think it's actually necessary.
339   TOR_LIB_GDI=-lgdi32
340 else
341   TOR_LIB_WS32=
342   TOR_LIB_GDI=
344 AC_SUBST(TOR_LIB_WS32)
345 AC_SUBST(TOR_LIB_GDI)
346 AC_SUBST(TOR_LIB_IPHLPAPI)
348 dnl We need to do this before we try our disgusting hack below.
349 AC_CHECK_HEADERS([sys/types.h])
351 dnl This is a disgusting hack so we safely include older libevent headers.
352 AC_CHECK_TYPE(u_int64_t, unsigned long long)
353 AC_CHECK_TYPE(u_int32_t, unsigned long)
354 AC_CHECK_TYPE(u_int16_t, unsigned short)
355 AC_CHECK_TYPE(u_int8_t, unsigned char)
357 tor_libevent_pkg_redhat="libevent"
358 tor_libevent_pkg_debian="libevent-dev"
359 tor_libevent_devpkg_redhat="libevent-devel"
360 tor_libevent_devpkg_debian="libevent-dev"
362 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
363 dnl linking for static builds.
364 STATIC_LIBEVENT_FLAGS=""
365 if test "$enable_static_libevent" = "yes"; then
366     if test "$have_rt" = yes; then
367       STATIC_LIBEVENT_FLAGS=" -lrt "
368     fi
371 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
372 #ifdef _WIN32
373 #include <winsock2.h>
374 #endif
375 #include <stdlib.h>
376 #include <sys/time.h>
377 #include <sys/types.h>
378 #include <event.h>], [
379 #ifdef _WIN32
380 #include <winsock2.h>
381 #endif
382 void exit(int); void *event_init(void);],
383     [
384 #ifdef _WIN32
385 {WSADATA d; WSAStartup(0x101,&d); }
386 #endif
387 event_init(); exit(0);
388 ], [--with-libevent-dir], [/opt/libevent])
390 dnl Now check for particular libevent functions.
391 save_LIBS="$LIBS"
392 save_LDFLAGS="$LDFLAGS"
393 save_CPPFLAGS="$CPPFLAGS"
394 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
395 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
396 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
397 AC_CHECK_FUNCS(event_get_version event_get_version_number event_get_method event_set_log_callback evdns_set_outgoing_bind_address event_base_loopexit)
398 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
399 [#include <event.h>
402 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
404 LIBS="$save_LIBS"
405 LDFLAGS="$save_LDFLAGS"
406 CPPFLAGS="$save_CPPFLAGS"
409 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
411 if test "$enable_static_libevent" = "yes"; then
412    if test "$tor_cv_library_libevent_dir" = "(system)"; then
413      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
414    else
415      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
416    fi
417 else
418      TOR_LIBEVENT_LIBS="-levent"
421 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
422 dnl we can do much better.
423 if test "$enable_bufferevents" = "yes" ; then
424   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
425     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.])
426   else
428     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
430     # Check for the right version.  First see if version detection works.
431     AC_MSG_CHECKING([whether we can detect the Libevent version])
432     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
433 #include <event2/event.h>
434 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
435 #error
436 int x = y(zz);
437 #else
438 int x = 1;
439 #endif
440   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
441      [event_version_number_works=no;  AC_MSG_RESULT([no])])
442     if test "$event_version_number_works" != 'yes'; then
443       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
444     else
445       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
446       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
447 #include <event2/event.h>
448 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
449 #error
450 int x = y(zz);
451 #else
452 int x = 1;
453 #endif
454    ])], [ AC_MSG_RESULT([yes]) ],
455       [ AC_MSG_RESULT([no])
456         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
457     fi
458   fi
461 LIBS="$save_LIBS"
462 LDFLAGS="$save_LDFLAGS"
463 CPPFLAGS="$save_CPPFLAGS"
465 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
466 if test "$enable_bufferevents" = "yes"; then
467   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
468   if test "$enable_static_libevent" = "yes"; then
469     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
470   else
471     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
472   fi
474 AC_SUBST(TOR_LIBEVENT_LIBS)
476 dnl ------------------------------------------------------
477 dnl Where do you live, libm?
479 dnl On some platforms (Haiku/BeOS) the math library is
480 dnl part of libroot. In which case don't link against lm
481 TOR_LIB_MATH=""
482 save_LIBS="$LIBS"
483 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
484 if test "$ac_cv_search_pow" != "none required"; then
485     TOR_LIB_MATH="$ac_cv_search_pow"
487 LIBS="$save_LIBS"
488 AC_SUBST(TOR_LIB_MATH)
490 dnl ------------------------------------------------------
491 dnl Where do you live, openssl?  And how do we call you?
493 tor_openssl_pkg_redhat="openssl"
494 tor_openssl_pkg_debian="libssl"
495 tor_openssl_devpkg_redhat="openssl-devel"
496 tor_openssl_devpkg_debian="libssl-dev"
498 ALT_openssl_WITHVAL=""
499 AC_ARG_WITH(ssl-dir,
500   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
501   [
502       if test "x$withval" != xno && test "x$withval" != "x" ; then
503          ALT_openssl_WITHVAL="$withval"
504       fi
505   ])
507 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
508     [#include <openssl/rand.h>],
509     [void RAND_add(const void *buf, int num, double entropy);],
510     [RAND_add((void*)0,0,0); exit(0);], [],
511     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
513 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
515 if test "$enable_static_openssl" = "yes"; then
516    if test "$tor_cv_library_openssl_dir" = "(system)"; then
517      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
518    else
519      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
520    fi
521 else
522      TOR_OPENSSL_LIBS="-lssl -lcrypto"
524 AC_SUBST(TOR_OPENSSL_LIBS)
526 dnl ------------------------------------------------------
527 dnl Where do you live, zlib?  And how do we call you?
529 tor_zlib_pkg_redhat="zlib"
530 tor_zlib_pkg_debian="zlib1g"
531 tor_zlib_devpkg_redhat="zlib-devel"
532 tor_zlib_devpkg_debian="zlib1g-dev"
534 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
535     [#include <zlib.h>],
536     [const char * zlibVersion(void);],
537     [zlibVersion(); exit(0);], [--with-zlib-dir],
538     [/opt/zlib])
540 if test "$enable_static_zlib" = "yes"; then
541    if test "$tor_cv_library_zlib_dir" = "(system)"; then
542      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
543  using --enable-static-zlib")
544    else
545      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
546    fi
547 else
548      TOR_ZLIB_LIBS="-lz"
550 AC_SUBST(TOR_ZLIB_LIBS)
552 dnl ---------------------------------------------------------------------
553 dnl Now that we know about our major libraries, we can check for compiler
554 dnl and linker hardening options.  We need to do this with the libraries known,
555 dnl since sometimes the linker will like an option but not be willing to
556 dnl use it with a build of a library.
558 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
559 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
561 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
562 #if !defined(__clang__)
563 #error
564 #endif])], have_clang=yes, have_clang=no)
566 if test x$enable_gcc_hardening != xno; then
567     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
568     if test x$have_clang = xyes; then
569         TOR_CHECK_CFLAGS(-Qunused-arguments)
570     fi
571     TOR_CHECK_CFLAGS(-fstack-protector-all)
572     TOR_CHECK_CFLAGS(-Wstack-protector)
573     TOR_CHECK_CFLAGS(-fwrapv)
574     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
575     if test "$bwin32" = "false"; then
576        TOR_CHECK_CFLAGS(-fPIE)
577        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
578     fi
581 if test x$enable_linker_hardening != xno; then
582     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
585 dnl ------------------------------------------------------
586 dnl Where do you live, libnatpmp?  And how do we call you?
587 dnl There are no packages for Debian or Redhat as of this patch
589 if test "$natpmp" = "true"; then
590     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
591     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
592         [#include <natpmp.h>],
593         [#ifdef _WIN32
594          #define STATICLIB
595          #endif
596          #include <natpmp.h>],
597         [   int r;
598             natpmp_t natpmp;
599             natpmpresp_t response;
600             r = initnatpmp(&natpmp, 0, 0);],
601             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
602             exit(0);],
603         [--with-libnatpmp-dir],
604         [/usr/lib/])
608 dnl ------------------------------------------------------
609 dnl Where do you live, libminiupnpc?  And how do we call you?
610 dnl There are no packages for Debian or Redhat as of this patch
612 if test "$upnp" = "true"; then
613     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
615     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
616     dnl to see if we have miniupnpc-1.5 or -1.6
617     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
618         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
620     if test "$miniupnpc15" = "true" ; then
621         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
622         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
623             [#include <miniupnpc/miniwget.h>
624              #include <miniupnpc/miniupnpc.h>
625              #include <miniupnpc/upnpcommands.h>],
626             [void upnpDiscover(int delay, const char * multicastif,
627              const char * minissdpdsock, int sameport);],
628             [upnpDiscover(1, 0, 0, 0); exit(0);],
629             [--with-libminiupnpc-dir],
630             [/usr/lib/])
631     else
632         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
633             [#include <miniupnpc/miniwget.h>
634              #include <miniupnpc/miniupnpc.h>
635              #include <miniupnpc/upnpcommands.h>],
636             [void upnpDiscover(int delay, const char * multicastif,
637              const char * minissdpdsock, int sameport, int ipv6, int * error);],
638             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
639             [--with-libminiupnpc-dir],
640             [/usr/lib/])
641     fi
644 dnl ============================================================
645 dnl We need an implementation of curve25519.
647 dnl set these defaults.
648 have_a_curve25519=no
649 build_curve25519_donna=no
650 build_curve25519_donna_c64=no
651 use_curve25519_donna=no
652 use_curve25519_nacl=no
653 CURVE25519_LIBS=
655 if test x$enable_curve25519 != xno; then
657   dnl The best choice is using curve25519-donna-c64, but that requires
658   dnl that we
659   AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
660     tor_cv_can_use_curve25519_donna_c64,
661     [AC_RUN_IFELSE(
662       [AC_LANG_PROGRAM([dnl
663         #include <stdint.h>
664         typedef unsigned uint128_t __attribute__((mode(TI)));
665         ], [dnl
666           uint64_t a = ((uint64_t)2000000000) * 1000000000;
667           uint64_t b = ((uint64_t)1234567890) << 24;
668           uint128_t c = ((uint128_t)a) * b;
669           return ((uint64_t)(c>>96)) == 522859 &&
670                  ((uint64_t)(c>>64))&0xffffffffL == 3604448702L &&
671                  ((uint64_t)(c>>32))&0xffffffffL == 2351960064L &&
672                  ((uint64_t)(c))&0xffffffffL == 0;
673         ])],
674         [tor_cv_can_use_curve25519_donna_c64=yes],
675         [tor_cv_can_use_curve25519_donna_c64=no],
676         [AC_COMPILE_IFELSE(
677           [AC_LANG_PROGRAM([dnl
678             #include <stdint.h>
679             typedef unsigned uint128_t __attribute__((mode(TI)));
680             ], [dnl
681               uint64_t a = ((uint64_t)2000000000) * 1000000000;
682               uint64_t b = ((uint64_t)1234567890) << 24;
683               uint128_t c = ((uint128_t)a) * b;
684               return ((uint64_t)(c>>96)) == 522859 &&
685                      ((uint64_t)(c>>64))&0xffffffffL == 3604448702L &&
686                      ((uint64_t)(c>>32))&0xffffffffL == 2351960064L &&
687                      ((uint64_t)(c))&0xffffffffL == 0;
688             ])],
689             [tor_cv_can_use_curve25519_donna_c64=cross],
690             [tor_cv_can_use_curve25519_donna_c64=no])])])
692   AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
693                     nacl/crypto_scalarmult_curve25519.h])
695   AC_CACHE_CHECK([whether we can use curve25519 from nacl],
696     tor_cv_can_use_curve25519_nacl,
697     [tor_saved_LIBS="$LIBS"
698      LIBS="$LIBS -lnacl"
699      AC_LINK_IFELSE(
700        [AC_LANG_PROGRAM([dnl
701          #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
702          #include <crypto_scalarmult_curve25519.h>
703          #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
704          #include <nacl/crypto_scalarmult_curve25519.h>
705          #endif
706          #ifdef crypto_scalarmult_curve25519_ref_BYTES
707          #error Hey, this is the reference implementation!
708          #endif
709        ], [
710          unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
711        ])], [tor_cv_can_use_curve25519_nacl=yes],
712        [tor_cv_can_use_curve25519_nacl=no])
713      LIBS="$tor_saved_LIBS" ])
715    dnl Okay, now we need to figure out which one to actually use. Fall back
716    dnl to curve25519-donna.c
718    if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
719      build_curve25519_donna_c64=yes
720      use_curve25519_donna=yes
721    elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
722      use_curve25519_nacl=yes
723      CURVE25519_LIBS=-lnacl
724    else
725      build_curve25519_donna=yes
726      use_curve25519_donna=yes
727    fi
728    have_a_curve25519=yes
731 if test x$have_a_curve25519 = xyes; then
732   AC_DEFINE(CURVE25519_ENABLED, 1,
733             [Defined if we have a curve25519 implementation])
735 if test x$use_curve25519_donna = xyes; then
736   AC_DEFINE(USE_CURVE25519_DONNA, 1,
737             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
739 if test x$use_curve25519_nacl = xyes; then
740   AC_DEFINE(USE_CURVE25519_NACL, 1,
741             [Defined if we should use a curve25519 from nacl])
743 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
744 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
745 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
746 AC_SUBST(CURVE25519_LIBS)
748 dnl Make sure to enable support for large off_t if available.
749 AC_SYS_LARGEFILE
751 AC_CHECK_HEADERS(
752         assert.h \
753         errno.h \
754         fcntl.h \
755         signal.h \
756         string.h \
757         sys/fcntl.h \
758         sys/stat.h \
759         sys/time.h \
760         sys/types.h \
761         time.h \
762         unistd.h
763  , , 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.))
765 dnl These headers are not essential
767 AC_CHECK_HEADERS(
768         arpa/inet.h \
769         crt_externs.h \
770         grp.h \
771         ifaddrs.h \
772         inttypes.h \
773         limits.h \
774         linux/types.h \
775         machine/limits.h \
776         malloc.h \
777         malloc/malloc.h \
778         malloc_np.h \
779         netdb.h \
780         netinet/in.h \
781         netinet/in6.h \
782         pwd.h \
783         stdint.h \
784         sys/file.h \
785         sys/ioctl.h \
786         sys/limits.h \
787         sys/mman.h \
788         sys/param.h \
789         sys/prctl.h \
790         sys/resource.h \
791         sys/socket.h \
792         sys/syslimits.h \
793         sys/time.h \
794         sys/types.h \
795         sys/un.h \
796         sys/utime.h \
797         sys/wait.h \
798         syslog.h \
799         utime.h
802 AC_CHECK_HEADERS(sys/param.h)
804 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
805 [#ifdef HAVE_SYS_TYPES_H
806 #include <sys/types.h>
807 #endif
808 #ifdef HAVE_SYS_SOCKET_H
809 #include <sys/socket.h>
810 #endif])
811 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
812 [#ifdef HAVE_SYS_TYPES_H
813 #include <sys/types.h>
814 #endif
815 #ifdef HAVE_SYS_SOCKET_H
816 #include <sys/socket.h>
817 #endif
818 #ifdef HAVE_NET_IF_H
819 #include <net/if.h>
820 #endif])
821 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
822         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
823 [#ifdef HAVE_SYS_TYPES_H
824 #include <sys/types.h>
825 #endif
826 #ifdef HAVE_SYS_SOCKET_H
827 #include <sys/socket.h>
828 #endif
829 #ifdef HAVE_LIMITS_H
830 #include <limits.h>
831 #endif
832 #ifdef HAVE_LINUX_TYPES_H
833 #include <linux/types.h>
834 #endif
835 #ifdef HAVE_NETINET_IN6_H
836 #include <netinet/in6.h>
837 #endif
838 #ifdef HAVE_NETINET_IN_H
839 #include <netinet/in.h>
840 #endif])
842 if test x$transparent = xtrue ; then
843    transparent_ok=0
844    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
845      transparent_ok=1
846    fi
847    if test x$linux_netfilter_ipv4 = x1 ; then
848      transparent_ok=1
849    fi
850    if test x$transparent_ok = x1 ; then
851      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
852      case $host in
853        *-*-openbsd* | *-*-bitrig*)
854          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
855      esac
856    else
857      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
858    fi
861 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
862 [#ifdef HAVE_SYS_TYPES_H
863 #include <sys/types.h>
864 #endif
865 #ifdef HAVE_SYS_TIME_H
866 #include <sys/time.h>
867 #endif])
869 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
870 dnl Watch out.
872 AC_CHECK_SIZEOF(int8_t)
873 AC_CHECK_SIZEOF(int16_t)
874 AC_CHECK_SIZEOF(int32_t)
875 AC_CHECK_SIZEOF(int64_t)
876 AC_CHECK_SIZEOF(uint8_t)
877 AC_CHECK_SIZEOF(uint16_t)
878 AC_CHECK_SIZEOF(uint32_t)
879 AC_CHECK_SIZEOF(uint64_t)
880 AC_CHECK_SIZEOF(intptr_t)
881 AC_CHECK_SIZEOF(uintptr_t)
883 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
885 AC_CHECK_SIZEOF(char)
886 AC_CHECK_SIZEOF(short)
887 AC_CHECK_SIZEOF(int)
888 AC_CHECK_SIZEOF(long)
889 AC_CHECK_SIZEOF(long long)
890 AC_CHECK_SIZEOF(__int64)
891 AC_CHECK_SIZEOF(void *)
892 AC_CHECK_SIZEOF(time_t)
893 AC_CHECK_SIZEOF(size_t)
894 AC_CHECK_SIZEOF(pid_t)
896 AC_CHECK_TYPES([uint, u_char, ssize_t])
898 dnl used to include sockaddr_storage, but everybody has that.
899 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
900 [#ifdef HAVE_SYS_TYPES_H
901 #include <sys/types.h>
902 #endif
903 #ifdef HAVE_NETINET_IN_H
904 #include <netinet/in.h>
905 #endif
906 #ifdef HAVE_NETINET_IN6_H
907 #include <netinet/in6.h>
908 #endif
909 #ifdef HAVE_SYS_SOCKET_H
910 #include <sys/socket.h>
911 #endif
912 #ifdef _WIN32
913 #define _WIN32_WINNT 0x0501
914 #define WIN32_LEAN_AND_MEAN
915 #if defined(_MSC_VER) && (_MSC_VER < 1300)
916 #include <winsock.h>
917 #else
918 #include <winsock2.h>
919 #include <ws2tcpip.h>
920 #endif
921 #endif
923 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
924 [#ifdef HAVE_SYS_TYPES_H
925 #include <sys/types.h>
926 #endif
927 #ifdef HAVE_NETINET_IN_H
928 #include <netinet/in.h>
929 #endif
930 #ifdef HAVE_NETINET_IN6_H
931 #include <netinet/in6.h>
932 #endif
933 #ifdef HAVE_SYS_SOCKET_H
934 #include <sys/socket.h>
935 #endif
936 #ifdef _WIN32
937 #define _WIN32_WINNT 0x0501
938 #define WIN32_LEAN_AND_MEAN
939 #if defined(_MSC_VER) && (_MSC_VER < 1300)
940 #include <winsock.h>
941 #else
942 #include <winsock2.h>
943 #include <ws2tcpip.h>
944 #endif
945 #endif
948 AC_CHECK_TYPES([rlim_t], , ,
949 [#ifdef HAVE_SYS_TYPES_H
950 #include <sys/types.h>
951 #endif
952 #ifdef HAVE_SYS_TIME_H
953 #include <sys/time.h>
954 #endif
955 #ifdef HAVE_SYS_RESOURCE_H
956 #include <sys/resource.h>
957 #endif
960 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
961 AC_RUN_IFELSE([AC_LANG_SOURCE([
962 #ifdef HAVE_SYS_TYPES_H
963 #include <sys/types.h>
964 #endif
965 #ifdef HAVE_SYS_TIME_H
966 #include <sys/time.h>
967 #endif
968 #ifdef HAVE_TIME_H
969 #include <time.h>
970 #endif
971 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }])],
972   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
975 if test "$tor_cv_time_t_signed" = cross; then
976   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
979 if test "$tor_cv_time_t_signed" != no; then
980   AC_DEFINE([TIME_T_IS_SIGNED], 1,
981             [Define to 1 iff time_t is signed])
984 AC_CACHE_CHECK([whether size_t is signed], tor_cv_size_t_signed, [
985 AC_RUN_IFELSE([AC_LANG_SOURCE([
986 #ifdef HAVE_SYS_TYPES_H
987 #include <sys/types.h>
988 #endif
989 int main(int c, char**v) { if (((size_t)-1)<0) return 1; else return 0; }])],
990   tor_cv_size_t_signed=no, tor_cv_size_t_signed=yes, tor_cv_size_t_signed=cross)
993 if test "$tor_cv_size_t_signed" = cross; then
994   AC_MSG_NOTICE([Cross compiling: assuming that size_t is not signed.])
997 if test "$tor_cv_size_t_signed" = yes; then
998   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1001 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1002 #ifdef HAVE_SYS_SOCKET_H
1003 #include <sys/socket.h>
1004 #endif
1007 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1009 AC_CHECK_SIZEOF(cell_t)
1011 # Now make sure that NULL can be represented as zero bytes.
1012 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1013 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1014 [[#include <stdlib.h>
1015 #include <string.h>
1016 #include <stdio.h>
1017 #ifdef HAVE_STDDEF_H
1018 #include <stddef.h>
1019 #endif
1020 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1021 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1022        [tor_cv_null_is_zero=yes],
1023        [tor_cv_null_is_zero=no],
1024        [tor_cv_null_is_zero=cross])])
1026 if test "$tor_cv_null_is_zero" = cross ; then
1027   # Cross-compiling; let's hope that the target isn't raving mad.
1028   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1031 if test "$tor_cv_null_is_zero" != no; then
1032   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1033             [Define to 1 iff memset(0) sets pointers to NULL])
1036 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1037 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1038 [[#include <stdlib.h>
1039 #include <string.h>
1040 #include <stdio.h>
1041 #ifdef HAVE_STDDEF_H
1042 #include <stddef.h>
1043 #endif
1044 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1045 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1046        [tor_cv_dbl0_is_zero=yes],
1047        [tor_cv_dbl0_is_zero=no],
1048        [tor_cv_dbl0_is_zero=cross])])
1050 if test "$tor_cv_dbl0_is_zero" = cross ; then
1051   # Cross-compiling; let's hope that the target isn't raving mad.
1052   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1055 if test "$tor_cv_dbl0_is_zero" != no; then
1056   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1057             [Define to 1 iff memset(0) sets doubles to 0.0])
1060 # And what happens when we malloc zero?
1061 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1062 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1063 [[#include <stdlib.h>
1064 #include <string.h>
1065 #include <stdio.h>
1066 #ifdef HAVE_STDDEF_H
1067 #include <stddef.h>
1068 #endif
1069 int main () { return malloc(0)?0:1; }]])],
1070        [tor_cv_malloc_zero_works=yes],
1071        [tor_cv_malloc_zero_works=no],
1072        [tor_cv_malloc_zero_works=cross])])
1074 if test "$tor_cv_malloc_zero_works" = cross; then
1075   # Cross-compiling; let's hope that the target isn't raving mad.
1076   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1079 if test "$tor_cv_malloc_zero_works" = yes; then
1080   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1081             [Define to 1 iff malloc(0) returns a pointer])
1084 # whether we seem to be in a 2s-complement world.
1085 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1086 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1087 [[int main () { int problem = ((-99) != (~99)+1);
1088 return problem ? 1 : 0; }]])],
1089        [tor_cv_twos_complement=yes],
1090        [tor_cv_twos_complement=no],
1091        [tor_cv_twos_complement=cross])])
1093 if test "$tor_cv_twos_complement" = cross ; then
1094   # Cross-compiling; let's hope that the target isn't raving mad.
1095   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1098 if test "$tor_cv_twos_complement" != no ; then
1099   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1100             [Define to 1 iff we represent negative integers with two's complement])
1103 # What does shifting a negative value do?
1104 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1105 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1106 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1107        [tor_cv_sign_extend=yes],
1108        [tor_cv_sign_extend=no],
1109        [tor_cv_sign_extend=cross])])
1111 if test "$tor_cv_sign_extend" = 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 right-shifting negative integers causes sign-extension])
1116 if test "$tor_cv_sign_extend" != no ; then
1117   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1118             [Define to 1 iff right-shifting a negative value performs sign-extension])
1121 # Whether we should use the dmalloc memory allocation debugging library.
1122 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1123 AC_ARG_WITH(dmalloc,
1124 [  --with-dmalloc          Use debug memory allocation library. ],
1125 [if [[ "$withval" = "yes" ]]; then
1126   dmalloc=1
1127   AC_MSG_RESULT(yes)
1128 else
1129   dmalloc=1
1130   AC_MSG_RESULT(no)
1131 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1134 if [[ $dmalloc -eq 1 ]]; then
1135   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1136   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1137   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1138   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1139   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1142 AC_ARG_WITH(tcmalloc,
1143 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1144 [ tcmalloc=yes ], [ tcmalloc=no ])
1146 if test x$tcmalloc = xyes ; then
1147    LDFLAGS="-ltcmalloc $LDFLAGS"
1150 using_custom_malloc=no
1151 if test x$enable_openbsd_malloc = xyes ; then
1152    using_custom_malloc=yes
1154 if test x$tcmalloc = xyes ; then
1155    using_custom_malloc=yes
1157 if test $using_custom_malloc = no ; then
1158    AC_CHECK_FUNCS(mallinfo)
1161 # By default, we're going to assume we don't have mlockall()
1162 # bionic and other platforms have various broken mlockall subsystems.
1163 # Some systems don't have a working mlockall, some aren't linkable,
1164 # and some have it but don't declare it.
1165 AC_CHECK_FUNCS(mlockall)
1166 AC_CHECK_DECLS([mlockall], , , [
1167 #ifdef HAVE_SYS_MMAN_H
1168 #include <sys/mman.h>
1169 #endif])
1171 # Allow user to specify an alternate syslog facility
1172 AC_ARG_WITH(syslog-facility,
1173 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1174 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1175 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1176 AC_SUBST(LOGFACILITY)
1178 # Check if we have getresuid and getresgid
1179 AC_CHECK_FUNCS(getresuid getresgid)
1181 # Check for gethostbyname_r in all its glorious incompatible versions.
1182 #   (This logic is based on that in Python's configure.in)
1183 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1184   [Define this if you have any gethostbyname_r()])
1186 AC_CHECK_FUNC(gethostbyname_r, [
1187   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1188   OLD_CFLAGS=$CFLAGS
1189   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1190   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1191 #include <netdb.h>
1192   ], [[
1193     char *cp1, *cp2;
1194     struct hostent *h1, *h2;
1195     int i1, i2;
1196     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1197   ]])],[
1198     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1199     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1200      [Define this if gethostbyname_r takes 6 arguments])
1201     AC_MSG_RESULT(6)
1202   ], [
1203     AC_TRY_COMPILE([
1204 #include <netdb.h>
1205     ], [
1206       char *cp1, *cp2;
1207       struct hostent *h1;
1208       int i1, i2;
1209       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1210     ], [
1211       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1212       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1213         [Define this if gethostbyname_r takes 5 arguments])
1214       AC_MSG_RESULT(5)
1215    ], [
1216       AC_TRY_COMPILE([
1217 #include <netdb.h>
1218      ], [
1219        char *cp1;
1220        struct hostent *h1;
1221        struct hostent_data hd;
1222        (void) gethostbyname_r(cp1,h1,&hd);
1223      ], [
1224        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1225        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1226          [Define this if gethostbyname_r takes 3 arguments])
1227        AC_MSG_RESULT(3)
1228      ], [
1229        AC_MSG_RESULT(0)
1230      ])
1231   ])
1232  ])
1233  CFLAGS=$OLD_CFLAGS
1236 AC_CACHE_CHECK([whether the C compiler supports __func__],
1237   tor_cv_have_func_macro,
1238   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1239 #include <stdio.h>
1240 int main(int c, char **v) { puts(__func__); }])],
1241   tor_cv_have_func_macro=yes,
1242   tor_cv_have_func_macro=no))
1244 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1245   tor_cv_have_FUNC_macro,
1246   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1247 #include <stdio.h>
1248 int main(int c, char **v) { puts(__FUNC__); }])],
1249   tor_cv_have_FUNC_macro=yes,
1250   tor_cv_have_FUNC_macro=no))
1252 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1253   tor_cv_have_FUNCTION_macro,
1254   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1255 #include <stdio.h>
1256 int main(int c, char **v) { puts(__FUNCTION__); }])],
1257   tor_cv_have_FUNCTION_macro=yes,
1258   tor_cv_have_FUNCTION_macro=no))
1260 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1261   tor_cv_have_environ_declared,
1262   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1263 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1264  * Without it environ doesn't get declared. */
1265 #define _GNU_SOURCE
1266 #ifdef HAVE_UNISTD_H
1267 #include <unistd.h>
1268 #endif
1269 #include <stdlib.h>
1270 int main(int c, char **v) { char **t = environ; }])],
1271   tor_cv_have_environ_declared=yes,
1272   tor_cv_have_environ_declared=no))
1274 if test "$tor_cv_have_func_macro" = 'yes'; then
1275   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1278 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1279   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1282 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1283   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1284            [Defined if the compiler supports __FUNCTION__])
1287 if test "$tor_cv_have_environ_declared" = 'yes'; then
1288   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1289            [Defined if we have extern char **environ already declared])
1292 # $prefix stores the value of the --prefix command line option, or
1293 # NONE if the option wasn't set.  In the case that it wasn't set, make
1294 # it be the default, so that we can use it to expand directories now.
1295 if test "x$prefix" = "xNONE"; then
1296   prefix=$ac_default_prefix
1299 # and similarly for $exec_prefix
1300 if test "x$exec_prefix" = "xNONE"; then
1301   exec_prefix=$prefix
1304 if test "x$BUILDDIR" = "x"; then
1305   BUILDDIR=`pwd`
1307 AC_SUBST(BUILDDIR)
1308 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1309 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1311 if test "x$CONFDIR" = "x"; then
1312   CONFDIR=`eval echo $sysconfdir/tor`
1314 AC_SUBST(CONFDIR)
1315 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1316 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1318 BINDIR=`eval echo $bindir`
1319 AC_SUBST(BINDIR)
1320 LOCALSTATEDIR=`eval echo $localstatedir`
1321 AC_SUBST(LOCALSTATEDIR)
1323 if test "$bwin32" = true; then
1324   # Test if the linker supports the --nxcompat and --dynamicbase options
1325   # for Windows
1326   save_LDFLAGS="$LDFLAGS"
1327   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1328   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1329   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1330     [AC_MSG_RESULT([yes])]
1331     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1332     [AC_MSG_RESULT([no])]
1333   )
1334   LDFLAGS="$save_LDFLAGS"
1337 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1338 # than autoconf's macros like.
1339 if test "$GCC" = yes; then
1340   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1341   # accident waiting to happen.
1342   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1343 else
1344   # Autoconf sets -g -O2 by default. Override optimization level
1345   # for non-gcc compilers
1346   CFLAGS="$CFLAGS -O"
1347   enable_gcc_warnings=no
1348   enable_gcc_warnings_advisory=no
1351 # OS X Lion started deprecating the system openssl. Let's just disable
1352 # all deprecation warnings on OS X. Also, to potentially make the binary
1353 # a little smaller, let's enable dead_strip.
1354 case "$host_os" in
1356  darwin*)
1357     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1358     LDFLAGS="$LDFLAGS -dead_strip" ;;
1359 esac
1361 # Add some more warnings which we use in development but not in the
1362 # released versions.  (Some relevant gcc versions can't handle these.)
1363 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1365   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1366 #if !defined(__GNUC__) || (__GNUC__ < 4)
1367 #error
1368 #endif])], have_gcc4=yes, have_gcc4=no)
1370   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1371 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1372 #error
1373 #endif])], have_gcc42=yes, have_gcc42=no)
1375   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1376 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1377 #error
1378 #endif])], have_gcc43=yes, have_gcc43=no)
1380   save_CFLAGS="$CFLAGS"
1381   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1382   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1383                     have_shorten64_flag=no)
1384   CFLAGS="$save_CFLAGS"
1386   case $host in
1387     *-*-openbsd* | *-*-bitrig*)
1388       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1389       # That's fine, except that the headers don't pass -Wredundant-decls.
1390       # Therefore, let's disable -Wsystem-headers when we're building
1391       # with maximal warnings on OpenBSD.
1392       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1393   esac
1395   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1396   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1397   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1398   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1399   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1401   if test x$enable_gcc_warnings = xyes; then
1402     CFLAGS="$CFLAGS -Werror"
1403   fi
1405   # Disabled, so we can use mallinfo(): -Waggregate-return
1407   if test x$have_gcc4 = xyes ; then
1408     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1409     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1410   fi
1412   if test x$have_gcc42 = xyes ; then
1413     # These warnings break gcc 4.0.2 and work on gcc 4.2
1414     # XXXX020 See if any of these work with earlier versions.
1415     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1417     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1418   fi
1420   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1421     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1422     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1423   fi
1425   if test x$have_gcc43 = xyes ; then
1426     # These warnings break gcc 4.2 and work on gcc 4.3
1427     # XXXX020 See if any of these work with earlier versions.
1428     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1429   fi
1431   if test x$have_shorten64_flag = xyes ; then
1432     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1433   fi
1435 ##This will break the world on some 64-bit architectures
1436 # CFLAGS="$CFLAGS -Winline"
1441 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1443 AC_CONFIG_FILES([
1444         Doxyfile
1445         Makefile
1446         contrib/suse/tor.sh
1447         contrib/tor.logrotate
1448         contrib/tor.sh
1449         contrib/torctl
1450         contrib/torify
1451         src/config/torrc.sample
1454 AC_OUTPUT
1456 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1457   ./contrib/updateVersions.pl