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