Merge branch 'maint-0.2.4' into release-0.2.4
[tor.git] / configure.ac
blob0d0cdf84015c8ccde9dce57efedf5480b4bcf0b4
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.11-alpha])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AC_CONFIG_MACRO_DIR([m4])
9 AM_INIT_AUTOMAKE
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AC_CONFIG_HEADERS([orconfig.h])
13 AC_CANONICAL_HOST
15 if test -f /etc/redhat-release ; then
16   if test -f /usr/kerberos/include ; then
17     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
18   fi
21 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
22 # the += operator on it in src/or/Makefile.am
23 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
25 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
26 AC_ARG_ENABLE(buf-freelists,
27    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
28 AC_ARG_ENABLE(openbsd-malloc,
29    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
30 AC_ARG_ENABLE(instrument-downloads,
31    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
32 AC_ARG_ENABLE(static-openssl,
33    AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
34 AC_ARG_ENABLE(static-libevent,
35    AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
36 AC_ARG_ENABLE(static-zlib,
37    AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
38 AC_ARG_ENABLE(static-tor,
39    AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir))
40 AC_ARG_ENABLE(curve25519,
41    AS_HELP_STRING(--disable-curve25519, Build Tor with no curve25519 elliptic-curve crypto support))
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         ], [dnl
667           uint64_t a = ((uint64_t)2000000000) * 1000000000;
668           uint64_t b = ((uint64_t)1234567890) << 24;
669           uint128_t c = ((uint128_t)a) * b;
670           return ((uint64_t)(c>>96)) == 522859 &&
671                  ((uint64_t)(c>>64))&0xffffffffL == 3604448702L &&
672                  ((uint64_t)(c>>32))&0xffffffffL == 2351960064L &&
673                  ((uint64_t)(c))&0xffffffffL == 0;
674         ])],
675         [tor_cv_can_use_curve25519_donna_c64=yes],
676         [tor_cv_can_use_curve25519_donna_c64=no],
677         [AC_COMPILE_IFELSE(
678           [AC_LANG_PROGRAM([dnl
679             #include <stdint.h>
680             typedef unsigned uint128_t __attribute__((mode(TI)));
681             ], [dnl
682               uint64_t a = ((uint64_t)2000000000) * 1000000000;
683               uint64_t b = ((uint64_t)1234567890) << 24;
684               uint128_t c = ((uint128_t)a) * b;
685               return ((uint64_t)(c>>96)) == 522859 &&
686                      ((uint64_t)(c>>64))&0xffffffffL == 3604448702L &&
687                      ((uint64_t)(c>>32))&0xffffffffL == 2351960064L &&
688                      ((uint64_t)(c))&0xffffffffL == 0;
689             ])],
690             [tor_cv_can_use_curve25519_donna_c64=cross],
691             [tor_cv_can_use_curve25519_donna_c64=no])])])
693   AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
694                     nacl/crypto_scalarmult_curve25519.h])
696   AC_CACHE_CHECK([whether we can use curve25519 from nacl],
697     tor_cv_can_use_curve25519_nacl,
698     [tor_saved_LIBS="$LIBS"
699      LIBS="$LIBS -lnacl"
700      AC_LINK_IFELSE(
701        [AC_LANG_PROGRAM([dnl
702          #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
703          #include <crypto_scalarmult_curve25519.h>
704          #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
705          #include <nacl/crypto_scalarmult_curve25519.h>
706          #endif
707          #ifdef crypto_scalarmult_curve25519_ref_BYTES
708          #error Hey, this is the reference implementation!
709          #endif
710        ], [
711          unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
712        ])], [tor_cv_can_use_curve25519_nacl=yes],
713        [tor_cv_can_use_curve25519_nacl=no])
714      LIBS="$tor_saved_LIBS" ])
716    dnl Okay, now we need to figure out which one to actually use. Fall back
717    dnl to curve25519-donna.c
719    if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
720      build_curve25519_donna_c64=yes
721      use_curve25519_donna=yes
722    elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
723      use_curve25519_nacl=yes
724      CURVE25519_LIBS=-lnacl
725    else
726      build_curve25519_donna=yes
727      use_curve25519_donna=yes
728    fi
729    have_a_curve25519=yes
732 if test x$have_a_curve25519 = xyes; then
733   AC_DEFINE(CURVE25519_ENABLED, 1,
734             [Defined if we have a curve25519 implementation])
736 if test x$use_curve25519_donna = xyes; then
737   AC_DEFINE(USE_CURVE25519_DONNA, 1,
738             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
740 if test x$use_curve25519_nacl = xyes; then
741   AC_DEFINE(USE_CURVE25519_NACL, 1,
742             [Defined if we should use a curve25519 from nacl])
744 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
745 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
746 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
747 AC_SUBST(CURVE25519_LIBS)
749 dnl Make sure to enable support for large off_t if available.
750 AC_SYS_LARGEFILE
752 AC_CHECK_HEADERS(
753         assert.h \
754         errno.h \
755         fcntl.h \
756         signal.h \
757         string.h \
758         sys/fcntl.h \
759         sys/stat.h \
760         sys/time.h \
761         sys/types.h \
762         time.h \
763         unistd.h
764  , , 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.))
766 dnl These headers are not essential
768 AC_CHECK_HEADERS(
769         arpa/inet.h \
770         crt_externs.h \
771         grp.h \
772         ifaddrs.h \
773         inttypes.h \
774         limits.h \
775         linux/types.h \
776         machine/limits.h \
777         malloc.h \
778         malloc/malloc.h \
779         malloc_np.h \
780         netdb.h \
781         netinet/in.h \
782         netinet/in6.h \
783         pwd.h \
784         stdint.h \
785         sys/file.h \
786         sys/ioctl.h \
787         sys/limits.h \
788         sys/mman.h \
789         sys/param.h \
790         sys/prctl.h \
791         sys/resource.h \
792         sys/socket.h \
793         sys/syslimits.h \
794         sys/time.h \
795         sys/types.h \
796         sys/un.h \
797         sys/utime.h \
798         sys/wait.h \
799         syslog.h \
800         utime.h
803 AC_CHECK_HEADERS(sys/param.h)
805 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
806 [#ifdef HAVE_SYS_TYPES_H
807 #include <sys/types.h>
808 #endif
809 #ifdef HAVE_SYS_SOCKET_H
810 #include <sys/socket.h>
811 #endif])
812 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
813 [#ifdef HAVE_SYS_TYPES_H
814 #include <sys/types.h>
815 #endif
816 #ifdef HAVE_SYS_SOCKET_H
817 #include <sys/socket.h>
818 #endif
819 #ifdef HAVE_NET_IF_H
820 #include <net/if.h>
821 #endif])
822 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
823         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
824 [#ifdef HAVE_SYS_TYPES_H
825 #include <sys/types.h>
826 #endif
827 #ifdef HAVE_SYS_SOCKET_H
828 #include <sys/socket.h>
829 #endif
830 #ifdef HAVE_LIMITS_H
831 #include <limits.h>
832 #endif
833 #ifdef HAVE_LINUX_TYPES_H
834 #include <linux/types.h>
835 #endif
836 #ifdef HAVE_NETINET_IN6_H
837 #include <netinet/in6.h>
838 #endif
839 #ifdef HAVE_NETINET_IN_H
840 #include <netinet/in.h>
841 #endif])
843 if test x$transparent = xtrue ; then
844    transparent_ok=0
845    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
846      transparent_ok=1
847    fi
848    if test x$linux_netfilter_ipv4 = x1 ; then
849      transparent_ok=1
850    fi
851    if test x$transparent_ok = x1 ; then
852      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
853      case $host in
854        *-*-openbsd* | *-*-bitrig*)
855          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
856      esac
857    else
858      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
859    fi
862 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
863 [#ifdef HAVE_SYS_TYPES_H
864 #include <sys/types.h>
865 #endif
866 #ifdef HAVE_SYS_TIME_H
867 #include <sys/time.h>
868 #endif])
870 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
871 dnl Watch out.
873 AC_CHECK_SIZEOF(int8_t)
874 AC_CHECK_SIZEOF(int16_t)
875 AC_CHECK_SIZEOF(int32_t)
876 AC_CHECK_SIZEOF(int64_t)
877 AC_CHECK_SIZEOF(uint8_t)
878 AC_CHECK_SIZEOF(uint16_t)
879 AC_CHECK_SIZEOF(uint32_t)
880 AC_CHECK_SIZEOF(uint64_t)
881 AC_CHECK_SIZEOF(intptr_t)
882 AC_CHECK_SIZEOF(uintptr_t)
884 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
886 AC_CHECK_SIZEOF(char)
887 AC_CHECK_SIZEOF(short)
888 AC_CHECK_SIZEOF(int)
889 AC_CHECK_SIZEOF(long)
890 AC_CHECK_SIZEOF(long long)
891 AC_CHECK_SIZEOF(__int64)
892 AC_CHECK_SIZEOF(void *)
893 AC_CHECK_SIZEOF(time_t)
894 AC_CHECK_SIZEOF(size_t)
895 AC_CHECK_SIZEOF(pid_t)
897 AC_CHECK_TYPES([uint, u_char, ssize_t])
899 dnl used to include sockaddr_storage, but everybody has that.
900 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
901 [#ifdef HAVE_SYS_TYPES_H
902 #include <sys/types.h>
903 #endif
904 #ifdef HAVE_NETINET_IN_H
905 #include <netinet/in.h>
906 #endif
907 #ifdef HAVE_NETINET_IN6_H
908 #include <netinet/in6.h>
909 #endif
910 #ifdef HAVE_SYS_SOCKET_H
911 #include <sys/socket.h>
912 #endif
913 #ifdef _WIN32
914 #define _WIN32_WINNT 0x0501
915 #define WIN32_LEAN_AND_MEAN
916 #if defined(_MSC_VER) && (_MSC_VER < 1300)
917 #include <winsock.h>
918 #else
919 #include <winsock2.h>
920 #include <ws2tcpip.h>
921 #endif
922 #endif
924 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
925 [#ifdef HAVE_SYS_TYPES_H
926 #include <sys/types.h>
927 #endif
928 #ifdef HAVE_NETINET_IN_H
929 #include <netinet/in.h>
930 #endif
931 #ifdef HAVE_NETINET_IN6_H
932 #include <netinet/in6.h>
933 #endif
934 #ifdef HAVE_SYS_SOCKET_H
935 #include <sys/socket.h>
936 #endif
937 #ifdef _WIN32
938 #define _WIN32_WINNT 0x0501
939 #define WIN32_LEAN_AND_MEAN
940 #if defined(_MSC_VER) && (_MSC_VER < 1300)
941 #include <winsock.h>
942 #else
943 #include <winsock2.h>
944 #include <ws2tcpip.h>
945 #endif
946 #endif
949 AC_CHECK_TYPES([rlim_t], , ,
950 [#ifdef HAVE_SYS_TYPES_H
951 #include <sys/types.h>
952 #endif
953 #ifdef HAVE_SYS_TIME_H
954 #include <sys/time.h>
955 #endif
956 #ifdef HAVE_SYS_RESOURCE_H
957 #include <sys/resource.h>
958 #endif
961 AX_CHECK_SIGN([time_t],
962        [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
963        [ : ], [
964 #ifdef HAVE_SYS_TYPES_H
965 #include <sys/types.h>
966 #endif
967 #ifdef HAVE_SYS_TIME_H
968 #include <sys/time.h>
969 #endif
970 #ifdef HAVE_TIME_H
971 #include <time.h>
972 #endif
975 AX_CHECK_SIGN([size_t],
976        [ tor_cv_size_t_signed=yes ],
977        [ tor_cv_size_t_signed=no ], [
978 #ifdef HAVE_SYS_TYPES_H
979 #include <sys/types.h>
980 #endif
983 if test "$tor_cv_size_t_signed" = yes; then
984   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
987 AX_CHECK_SIGN([enum always],
988        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
989        [ : ], [
990  enum always { AAA, BBB, CCC };
993 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
994 #ifdef HAVE_SYS_SOCKET_H
995 #include <sys/socket.h>
996 #endif
999 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1001 AC_CHECK_SIZEOF(cell_t)
1003 # Now make sure that NULL can be represented as zero bytes.
1004 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1005 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1006 [[#include <stdlib.h>
1007 #include <string.h>
1008 #include <stdio.h>
1009 #ifdef HAVE_STDDEF_H
1010 #include <stddef.h>
1011 #endif
1012 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1013 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1014        [tor_cv_null_is_zero=yes],
1015        [tor_cv_null_is_zero=no],
1016        [tor_cv_null_is_zero=cross])])
1018 if test "$tor_cv_null_is_zero" = cross ; then
1019   # Cross-compiling; let's hope that the target isn't raving mad.
1020   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1023 if test "$tor_cv_null_is_zero" != no; then
1024   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1025             [Define to 1 iff memset(0) sets pointers to NULL])
1028 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1029 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1030 [[#include <stdlib.h>
1031 #include <string.h>
1032 #include <stdio.h>
1033 #ifdef HAVE_STDDEF_H
1034 #include <stddef.h>
1035 #endif
1036 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1037 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1038        [tor_cv_dbl0_is_zero=yes],
1039        [tor_cv_dbl0_is_zero=no],
1040        [tor_cv_dbl0_is_zero=cross])])
1042 if test "$tor_cv_dbl0_is_zero" = cross ; then
1043   # Cross-compiling; let's hope that the target isn't raving mad.
1044   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1047 if test "$tor_cv_dbl0_is_zero" != no; then
1048   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1049             [Define to 1 iff memset(0) sets doubles to 0.0])
1052 # And what happens when we malloc zero?
1053 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1054 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1055 [[#include <stdlib.h>
1056 #include <string.h>
1057 #include <stdio.h>
1058 #ifdef HAVE_STDDEF_H
1059 #include <stddef.h>
1060 #endif
1061 int main () { return malloc(0)?0:1; }]])],
1062        [tor_cv_malloc_zero_works=yes],
1063        [tor_cv_malloc_zero_works=no],
1064        [tor_cv_malloc_zero_works=cross])])
1066 if test "$tor_cv_malloc_zero_works" = cross; then
1067   # Cross-compiling; let's hope that the target isn't raving mad.
1068   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1071 if test "$tor_cv_malloc_zero_works" = yes; then
1072   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1073             [Define to 1 iff malloc(0) returns a pointer])
1076 # whether we seem to be in a 2s-complement world.
1077 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1078 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1079 [[int main () { int problem = ((-99) != (~99)+1);
1080 return problem ? 1 : 0; }]])],
1081        [tor_cv_twos_complement=yes],
1082        [tor_cv_twos_complement=no],
1083        [tor_cv_twos_complement=cross])])
1085 if test "$tor_cv_twos_complement" = cross ; then
1086   # Cross-compiling; let's hope that the target isn't raving mad.
1087   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1090 if test "$tor_cv_twos_complement" != no ; then
1091   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1092             [Define to 1 iff we represent negative integers with two's complement])
1095 # What does shifting a negative value do?
1096 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1097 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1098 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1099        [tor_cv_sign_extend=yes],
1100        [tor_cv_sign_extend=no],
1101        [tor_cv_sign_extend=cross])])
1103 if test "$tor_cv_sign_extend" = cross ; then
1104   # Cross-compiling; let's hope that the target isn't raving mad.
1105   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1108 if test "$tor_cv_sign_extend" != no ; then
1109   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1110             [Define to 1 iff right-shifting a negative value performs sign-extension])
1113 # Whether we should use the dmalloc memory allocation debugging library.
1114 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1115 AC_ARG_WITH(dmalloc,
1116 [  --with-dmalloc          Use debug memory allocation library. ],
1117 [if [[ "$withval" = "yes" ]]; then
1118   dmalloc=1
1119   AC_MSG_RESULT(yes)
1120 else
1121   dmalloc=1
1122   AC_MSG_RESULT(no)
1123 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1126 if [[ $dmalloc -eq 1 ]]; then
1127   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1128   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1129   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1130   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1131   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1134 AC_ARG_WITH(tcmalloc,
1135 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1136 [ tcmalloc=yes ], [ tcmalloc=no ])
1138 if test x$tcmalloc = xyes ; then
1139    LDFLAGS="-ltcmalloc $LDFLAGS"
1142 using_custom_malloc=no
1143 if test x$enable_openbsd_malloc = xyes ; then
1144    using_custom_malloc=yes
1146 if test x$tcmalloc = xyes ; then
1147    using_custom_malloc=yes
1149 if test $using_custom_malloc = no ; then
1150    AC_CHECK_FUNCS(mallinfo)
1153 # By default, we're going to assume we don't have mlockall()
1154 # bionic and other platforms have various broken mlockall subsystems.
1155 # Some systems don't have a working mlockall, some aren't linkable,
1156 # and some have it but don't declare it.
1157 AC_CHECK_FUNCS(mlockall)
1158 AC_CHECK_DECLS([mlockall], , , [
1159 #ifdef HAVE_SYS_MMAN_H
1160 #include <sys/mman.h>
1161 #endif])
1163 # Allow user to specify an alternate syslog facility
1164 AC_ARG_WITH(syslog-facility,
1165 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1166 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1167 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1168 AC_SUBST(LOGFACILITY)
1170 # Check if we have getresuid and getresgid
1171 AC_CHECK_FUNCS(getresuid getresgid)
1173 # Check for gethostbyname_r in all its glorious incompatible versions.
1174 #   (This logic is based on that in Python's configure.in)
1175 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1176   [Define this if you have any gethostbyname_r()])
1178 AC_CHECK_FUNC(gethostbyname_r, [
1179   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1180   OLD_CFLAGS=$CFLAGS
1181   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1182   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1183 #include <netdb.h>
1184   ], [[
1185     char *cp1, *cp2;
1186     struct hostent *h1, *h2;
1187     int i1, i2;
1188     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1189   ]])],[
1190     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1191     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1192      [Define this if gethostbyname_r takes 6 arguments])
1193     AC_MSG_RESULT(6)
1194   ], [
1195     AC_TRY_COMPILE([
1196 #include <netdb.h>
1197     ], [
1198       char *cp1, *cp2;
1199       struct hostent *h1;
1200       int i1, i2;
1201       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1202     ], [
1203       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1204       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1205         [Define this if gethostbyname_r takes 5 arguments])
1206       AC_MSG_RESULT(5)
1207    ], [
1208       AC_TRY_COMPILE([
1209 #include <netdb.h>
1210      ], [
1211        char *cp1;
1212        struct hostent *h1;
1213        struct hostent_data hd;
1214        (void) gethostbyname_r(cp1,h1,&hd);
1215      ], [
1216        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1217        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1218          [Define this if gethostbyname_r takes 3 arguments])
1219        AC_MSG_RESULT(3)
1220      ], [
1221        AC_MSG_RESULT(0)
1222      ])
1223   ])
1224  ])
1225  CFLAGS=$OLD_CFLAGS
1228 AC_CACHE_CHECK([whether the C compiler supports __func__],
1229   tor_cv_have_func_macro,
1230   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1231 #include <stdio.h>
1232 int main(int c, char **v) { puts(__func__); }])],
1233   tor_cv_have_func_macro=yes,
1234   tor_cv_have_func_macro=no))
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 __FUNCTION__],
1245   tor_cv_have_FUNCTION_macro,
1246   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1247 #include <stdio.h>
1248 int main(int c, char **v) { puts(__FUNCTION__); }])],
1249   tor_cv_have_FUNCTION_macro=yes,
1250   tor_cv_have_FUNCTION_macro=no))
1252 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1253   tor_cv_have_environ_declared,
1254   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1255 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1256  * Without it environ doesn't get declared. */
1257 #define _GNU_SOURCE
1258 #ifdef HAVE_UNISTD_H
1259 #include <unistd.h>
1260 #endif
1261 #include <stdlib.h>
1262 int main(int c, char **v) { char **t = environ; }])],
1263   tor_cv_have_environ_declared=yes,
1264   tor_cv_have_environ_declared=no))
1266 if test "$tor_cv_have_func_macro" = 'yes'; then
1267   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1270 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1271   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1274 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1275   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1276            [Defined if the compiler supports __FUNCTION__])
1279 if test "$tor_cv_have_environ_declared" = 'yes'; then
1280   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1281            [Defined if we have extern char **environ already declared])
1284 # $prefix stores the value of the --prefix command line option, or
1285 # NONE if the option wasn't set.  In the case that it wasn't set, make
1286 # it be the default, so that we can use it to expand directories now.
1287 if test "x$prefix" = "xNONE"; then
1288   prefix=$ac_default_prefix
1291 # and similarly for $exec_prefix
1292 if test "x$exec_prefix" = "xNONE"; then
1293   exec_prefix=$prefix
1296 if test "x$BUILDDIR" = "x"; then
1297   BUILDDIR=`pwd`
1299 AC_SUBST(BUILDDIR)
1300 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1301 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1303 if test "x$CONFDIR" = "x"; then
1304   CONFDIR=`eval echo $sysconfdir/tor`
1306 AC_SUBST(CONFDIR)
1307 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1308 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1310 BINDIR=`eval echo $bindir`
1311 AC_SUBST(BINDIR)
1312 LOCALSTATEDIR=`eval echo $localstatedir`
1313 AC_SUBST(LOCALSTATEDIR)
1315 if test "$bwin32" = true; then
1316   # Test if the linker supports the --nxcompat and --dynamicbase options
1317   # for Windows
1318   save_LDFLAGS="$LDFLAGS"
1319   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1320   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1321   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1322     [AC_MSG_RESULT([yes])]
1323     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1324     [AC_MSG_RESULT([no])]
1325   )
1326   LDFLAGS="$save_LDFLAGS"
1329 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1330 # than autoconf's macros like.
1331 if test "$GCC" = yes; then
1332   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1333   # accident waiting to happen.
1334   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1335 else
1336   # Autoconf sets -g -O2 by default. Override optimization level
1337   # for non-gcc compilers
1338   CFLAGS="$CFLAGS -O"
1339   enable_gcc_warnings=no
1340   enable_gcc_warnings_advisory=no
1343 # OS X Lion started deprecating the system openssl. Let's just disable
1344 # all deprecation warnings on OS X. Also, to potentially make the binary
1345 # a little smaller, let's enable dead_strip.
1346 case "$host_os" in
1348  darwin*)
1349     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1350     LDFLAGS="$LDFLAGS -dead_strip" ;;
1351 esac
1353 # Add some more warnings which we use in development but not in the
1354 # released versions.  (Some relevant gcc versions can't handle these.)
1355 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1357   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1358 #if !defined(__GNUC__) || (__GNUC__ < 4)
1359 #error
1360 #endif])], have_gcc4=yes, have_gcc4=no)
1362   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1363 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1364 #error
1365 #endif])], have_gcc42=yes, have_gcc42=no)
1367   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1368 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1369 #error
1370 #endif])], have_gcc43=yes, have_gcc43=no)
1372   save_CFLAGS="$CFLAGS"
1373   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1374   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1375                     have_shorten64_flag=no)
1376   CFLAGS="$save_CFLAGS"
1378   case $host in
1379     *-*-openbsd* | *-*-bitrig*)
1380       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1381       # That's fine, except that the headers don't pass -Wredundant-decls.
1382       # Therefore, let's disable -Wsystem-headers when we're building
1383       # with maximal warnings on OpenBSD.
1384       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1385   esac
1387   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1388   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1389   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1390   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1391   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1393   if test x$enable_gcc_warnings = xyes; then
1394     CFLAGS="$CFLAGS -Werror"
1395   fi
1397   # Disabled, so we can use mallinfo(): -Waggregate-return
1399   if test x$have_gcc4 = xyes ; then
1400     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1401     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1402   fi
1404   if test x$have_gcc42 = xyes ; then
1405     # These warnings break gcc 4.0.2 and work on gcc 4.2
1406     # XXXX020 See if any of these work with earlier versions.
1407     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1409     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1410   fi
1412   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1413     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1414     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1415   fi
1417   if test x$have_gcc43 = xyes ; then
1418     # These warnings break gcc 4.2 and work on gcc 4.3
1419     # XXXX020 See if any of these work with earlier versions.
1420     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1421   fi
1423   if test x$have_shorten64_flag = xyes ; then
1424     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1425   fi
1427 ##This will break the world on some 64-bit architectures
1428 # CFLAGS="$CFLAGS -Winline"
1433 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1435 AC_CONFIG_FILES([
1436         Doxyfile
1437         Makefile
1438         contrib/suse/tor.sh
1439         contrib/tor.logrotate
1440         contrib/tor.sh
1441         contrib/torctl
1442         contrib/torify
1443         src/config/torrc.sample
1446 AC_OUTPUT
1448 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1449   ./contrib/updateVersions.pl