Remove a bogus semicolon spotted by Gisle Vanem
[tor.git] / configure.ac
blob235f19b4383908bf2ef51cf55435c0a0f372f453
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2013, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT([tor],[0.2.5.0-alpha-dev])
7 AC_CONFIG_SRCDIR([src/or/main.c])
8 AC_CONFIG_MACRO_DIR([m4])
9 AM_INIT_AUTOMAKE
10 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
11 AC_CONFIG_HEADERS([orconfig.h])
13 AC_CANONICAL_HOST
15 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 Now see if we have a -fomit-frame-pointer compiler option.
589 saved_CFLAGS="$CFLAGS"
590 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
591 if test "$saved_CFLAGS" != "$CFLAGS"; then
592   F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
593 else
594   F_OMIT_FRAME_POINTER=''
596 CFLAGS="$saved_CFLAGS"
597 AC_SUBST(F_OMIT_FRAME_POINTER)
599 dnl ------------------------------------------------------
600 dnl Where do you live, libnatpmp?  And how do we call you?
601 dnl There are no packages for Debian or Redhat as of this patch
603 if test "$natpmp" = "true"; then
604     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
605     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
606         [#include <natpmp.h>],
607         [#ifdef _WIN32
608          #define STATICLIB
609          #endif
610          #include <natpmp.h>],
611         [   int r;
612             natpmp_t natpmp;
613             natpmpresp_t response;
614             r = initnatpmp(&natpmp, 0, 0);],
615             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
616             exit(0);],
617         [--with-libnatpmp-dir],
618         [/usr/lib/])
622 dnl ------------------------------------------------------
623 dnl Where do you live, libminiupnpc?  And how do we call you?
624 dnl There are no packages for Debian or Redhat as of this patch
626 if test "$upnp" = "true"; then
627     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
629     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
630     dnl to see if we have miniupnpc-1.5 or -1.6
631     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
632         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
634     if test "$miniupnpc15" = "true" ; then
635         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
636         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
637             [#include <miniupnpc/miniwget.h>
638              #include <miniupnpc/miniupnpc.h>
639              #include <miniupnpc/upnpcommands.h>],
640             [void upnpDiscover(int delay, const char * multicastif,
641              const char * minissdpdsock, int sameport);],
642             [upnpDiscover(1, 0, 0, 0); exit(0);],
643             [--with-libminiupnpc-dir],
644             [/usr/lib/])
645     else
646         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
647             [#include <miniupnpc/miniwget.h>
648              #include <miniupnpc/miniupnpc.h>
649              #include <miniupnpc/upnpcommands.h>],
650             [void upnpDiscover(int delay, const char * multicastif,
651              const char * minissdpdsock, int sameport, int ipv6, int * error);],
652             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
653             [--with-libminiupnpc-dir],
654             [/usr/lib/])
655     fi
658 dnl ============================================================
659 dnl We need an implementation of curve25519.
661 dnl set these defaults.
662 have_a_curve25519=no
663 build_curve25519_donna=no
664 build_curve25519_donna_c64=no
665 use_curve25519_donna=no
666 use_curve25519_nacl=no
667 CURVE25519_LIBS=
669 if test x$enable_curve25519 != xno; then
671   dnl The best choice is using curve25519-donna-c64, but that requires
672   dnl that we
673   AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
674     tor_cv_can_use_curve25519_donna_c64,
675     [AC_RUN_IFELSE(
676       [AC_LANG_PROGRAM([dnl
677         #include <stdint.h>
678         typedef unsigned uint128_t __attribute__((mode(TI)));
679         int func(uint64_t a, uint64_t b) {
680              uint128_t c = ((uint128_t)a) * b;
681              int ok = ((uint64_t)(c>>96)) == 522859 &&
682                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
683                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
684                    (((uint64_t)(c))&0xffffffffL) == 0;
685              return ok;
686         }
687         ], [dnl
688           int ok = func( ((uint64_t)2000000000) * 1000000000,
689                          ((uint64_t)1234567890) << 24);
690           return !ok;
691         ])],
692         [tor_cv_can_use_curve25519_donna_c64=yes],
693         [tor_cv_can_use_curve25519_donna_c64=no],
694         [AC_COMPILE_IFELSE(
695           [AC_LANG_PROGRAM([dnl
696         #include <stdint.h>
697         typedef unsigned uint128_t __attribute__((mode(TI)));
698         int func(uint64_t a, uint64_t b) {
699              uint128_t c = ((uint128_t)a) * b;
700              int ok = ((uint64_t)(c>>96)) == 522859 &&
701                    (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
702                    (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
703                    (((uint64_t)(c))&0xffffffffL) == 0;
704              return ok;
705         }
706         ], [dnl
707           int ok = func( ((uint64_t)2000000000) * 1000000000,
708                          ((uint64_t)1234567890) << 24);
709           return !ok;
710         ])],
711             [tor_cv_can_use_curve25519_donna_c64=cross],
712             [tor_cv_can_use_curve25519_donna_c64=no])])])
714   AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
715                     nacl/crypto_scalarmult_curve25519.h])
717   AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
718     tor_cv_can_use_curve25519_nacl,
719     [tor_saved_LIBS="$LIBS"
720      LIBS="$LIBS -lnacl"
721      AC_LINK_IFELSE(
722        [AC_LANG_PROGRAM([dnl
723          #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
724          #include <crypto_scalarmult_curve25519.h>
725          #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
726          #include <nacl/crypto_scalarmult_curve25519.h>
727          #endif
728          #ifdef crypto_scalarmult_curve25519_ref_BYTES
729          #error Hey, this is the reference implementation! That's not fast.
730          #endif
731        ], [
732          unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
733        ])], [tor_cv_can_use_curve25519_nacl=yes],
734        [tor_cv_can_use_curve25519_nacl=no])
735      LIBS="$tor_saved_LIBS" ])
737    dnl Okay, now we need to figure out which one to actually use. Fall back
738    dnl to curve25519-donna.c
740    if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
741      build_curve25519_donna_c64=yes
742      use_curve25519_donna=yes
743    elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
744      use_curve25519_nacl=yes
745      CURVE25519_LIBS=-lnacl
746    else
747      build_curve25519_donna=yes
748      use_curve25519_donna=yes
749    fi
750    have_a_curve25519=yes
753 if test x$have_a_curve25519 = xyes; then
754   AC_DEFINE(CURVE25519_ENABLED, 1,
755             [Defined if we have a curve25519 implementation])
757 if test x$use_curve25519_donna = xyes; then
758   AC_DEFINE(USE_CURVE25519_DONNA, 1,
759             [Defined if we should use an internal curve25519_donna{,_c64} implementation])
761 if test x$use_curve25519_nacl = xyes; then
762   AC_DEFINE(USE_CURVE25519_NACL, 1,
763             [Defined if we should use a curve25519 from nacl])
765 AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
766 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
767 AM_CONDITIONAL(CURVE25519_ENABLED, test x$have_a_curve25519 = xyes)
768 AC_SUBST(CURVE25519_LIBS)
770 dnl Make sure to enable support for large off_t if available.
771 AC_SYS_LARGEFILE
773 AC_CHECK_HEADERS(
774         assert.h \
775         errno.h \
776         fcntl.h \
777         signal.h \
778         string.h \
779         sys/fcntl.h \
780         sys/stat.h \
781         sys/time.h \
782         sys/types.h \
783         time.h \
784         unistd.h
785  , , 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.))
787 dnl These headers are not essential
789 AC_CHECK_HEADERS(
790         arpa/inet.h \
791         crt_externs.h \
792         grp.h \
793         ifaddrs.h \
794         inttypes.h \
795         limits.h \
796         linux/types.h \
797         machine/limits.h \
798         malloc.h \
799         malloc/malloc.h \
800         malloc_np.h \
801         netdb.h \
802         netinet/in.h \
803         netinet/in6.h \
804         pwd.h \
805         stdint.h \
806         sys/file.h \
807         sys/ioctl.h \
808         sys/limits.h \
809         sys/mman.h \
810         sys/param.h \
811         sys/prctl.h \
812         sys/resource.h \
813         sys/socket.h \
814         sys/syslimits.h \
815         sys/time.h \
816         sys/types.h \
817         sys/un.h \
818         sys/utime.h \
819         sys/wait.h \
820         syslog.h \
821         utime.h
824 AC_CHECK_HEADERS(sys/param.h)
826 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
827 [#ifdef HAVE_SYS_TYPES_H
828 #include <sys/types.h>
829 #endif
830 #ifdef HAVE_SYS_SOCKET_H
831 #include <sys/socket.h>
832 #endif])
833 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
834 [#ifdef HAVE_SYS_TYPES_H
835 #include <sys/types.h>
836 #endif
837 #ifdef HAVE_SYS_SOCKET_H
838 #include <sys/socket.h>
839 #endif
840 #ifdef HAVE_NET_IF_H
841 #include <net/if.h>
842 #endif])
843 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
844         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
845 [#ifdef HAVE_SYS_TYPES_H
846 #include <sys/types.h>
847 #endif
848 #ifdef HAVE_SYS_SOCKET_H
849 #include <sys/socket.h>
850 #endif
851 #ifdef HAVE_LIMITS_H
852 #include <limits.h>
853 #endif
854 #ifdef HAVE_LINUX_TYPES_H
855 #include <linux/types.h>
856 #endif
857 #ifdef HAVE_NETINET_IN6_H
858 #include <netinet/in6.h>
859 #endif
860 #ifdef HAVE_NETINET_IN_H
861 #include <netinet/in.h>
862 #endif])
864 if test x$transparent = xtrue ; then
865    transparent_ok=0
866    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
867      transparent_ok=1
868    fi
869    if test x$linux_netfilter_ipv4 = x1 ; then
870      transparent_ok=1
871    fi
872    if test x$transparent_ok = x1 ; then
873      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
874      case $host in
875        *-*-openbsd* | *-*-bitrig*)
876          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
877      esac
878    else
879      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
880    fi
883 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
884 [#ifdef HAVE_SYS_TYPES_H
885 #include <sys/types.h>
886 #endif
887 #ifdef HAVE_SYS_TIME_H
888 #include <sys/time.h>
889 #endif])
891 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
892 dnl Watch out.
894 AC_CHECK_SIZEOF(int8_t)
895 AC_CHECK_SIZEOF(int16_t)
896 AC_CHECK_SIZEOF(int32_t)
897 AC_CHECK_SIZEOF(int64_t)
898 AC_CHECK_SIZEOF(uint8_t)
899 AC_CHECK_SIZEOF(uint16_t)
900 AC_CHECK_SIZEOF(uint32_t)
901 AC_CHECK_SIZEOF(uint64_t)
902 AC_CHECK_SIZEOF(intptr_t)
903 AC_CHECK_SIZEOF(uintptr_t)
905 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
907 AC_CHECK_SIZEOF(char)
908 AC_CHECK_SIZEOF(short)
909 AC_CHECK_SIZEOF(int)
910 AC_CHECK_SIZEOF(long)
911 AC_CHECK_SIZEOF(long long)
912 AC_CHECK_SIZEOF(__int64)
913 AC_CHECK_SIZEOF(void *)
914 AC_CHECK_SIZEOF(time_t)
915 AC_CHECK_SIZEOF(size_t)
916 AC_CHECK_SIZEOF(pid_t)
918 AC_CHECK_TYPES([uint, u_char, ssize_t])
920 dnl used to include sockaddr_storage, but everybody has that.
921 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
922 [#ifdef HAVE_SYS_TYPES_H
923 #include <sys/types.h>
924 #endif
925 #ifdef HAVE_NETINET_IN_H
926 #include <netinet/in.h>
927 #endif
928 #ifdef HAVE_NETINET_IN6_H
929 #include <netinet/in6.h>
930 #endif
931 #ifdef HAVE_SYS_SOCKET_H
932 #include <sys/socket.h>
933 #endif
934 #ifdef _WIN32
935 #define _WIN32_WINNT 0x0501
936 #define WIN32_LEAN_AND_MEAN
937 #if defined(_MSC_VER) && (_MSC_VER < 1300)
938 #include <winsock.h>
939 #else
940 #include <winsock2.h>
941 #include <ws2tcpip.h>
942 #endif
943 #endif
945 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
946 [#ifdef HAVE_SYS_TYPES_H
947 #include <sys/types.h>
948 #endif
949 #ifdef HAVE_NETINET_IN_H
950 #include <netinet/in.h>
951 #endif
952 #ifdef HAVE_NETINET_IN6_H
953 #include <netinet/in6.h>
954 #endif
955 #ifdef HAVE_SYS_SOCKET_H
956 #include <sys/socket.h>
957 #endif
958 #ifdef _WIN32
959 #define _WIN32_WINNT 0x0501
960 #define WIN32_LEAN_AND_MEAN
961 #if defined(_MSC_VER) && (_MSC_VER < 1300)
962 #include <winsock.h>
963 #else
964 #include <winsock2.h>
965 #include <ws2tcpip.h>
966 #endif
967 #endif
970 AC_CHECK_TYPES([rlim_t], , ,
971 [#ifdef HAVE_SYS_TYPES_H
972 #include <sys/types.h>
973 #endif
974 #ifdef HAVE_SYS_TIME_H
975 #include <sys/time.h>
976 #endif
977 #ifdef HAVE_SYS_RESOURCE_H
978 #include <sys/resource.h>
979 #endif
982 AX_CHECK_SIGN([time_t],
983        [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
984        [ : ], [
985 #ifdef HAVE_SYS_TYPES_H
986 #include <sys/types.h>
987 #endif
988 #ifdef HAVE_SYS_TIME_H
989 #include <sys/time.h>
990 #endif
991 #ifdef HAVE_TIME_H
992 #include <time.h>
993 #endif
996 if test "$ax_cv_decl_time_t_signed" = no; then
997   AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
1000 AX_CHECK_SIGN([size_t],
1001        [ tor_cv_size_t_signed=yes ],
1002        [ tor_cv_size_t_signed=no ], [
1003 #ifdef HAVE_SYS_TYPES_H
1004 #include <sys/types.h>
1005 #endif
1008 if test "$ax_cv_decl_size_t_signed" = yes; then
1009   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1012 AX_CHECK_SIGN([enum always],
1013        [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1014        [ : ], [
1015  enum always { AAA, BBB, CCC };
1018 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1019 #ifdef HAVE_SYS_SOCKET_H
1020 #include <sys/socket.h>
1021 #endif
1024 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1026 AC_CHECK_SIZEOF(cell_t)
1028 # Now make sure that NULL can be represented as zero bytes.
1029 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1030 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1031 [[#include <stdlib.h>
1032 #include <string.h>
1033 #include <stdio.h>
1034 #ifdef HAVE_STDDEF_H
1035 #include <stddef.h>
1036 #endif
1037 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1038 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1039        [tor_cv_null_is_zero=yes],
1040        [tor_cv_null_is_zero=no],
1041        [tor_cv_null_is_zero=cross])])
1043 if test "$tor_cv_null_is_zero" = cross ; then
1044   # Cross-compiling; let's hope that the target isn't raving mad.
1045   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1048 if test "$tor_cv_null_is_zero" != no; then
1049   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1050             [Define to 1 iff memset(0) sets pointers to NULL])
1053 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
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 () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1062 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1063        [tor_cv_dbl0_is_zero=yes],
1064        [tor_cv_dbl0_is_zero=no],
1065        [tor_cv_dbl0_is_zero=cross])])
1067 if test "$tor_cv_dbl0_is_zero" = cross ; then
1068   # Cross-compiling; let's hope that the target isn't raving mad.
1069   AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1072 if test "$tor_cv_dbl0_is_zero" != no; then
1073   AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1074             [Define to 1 iff memset(0) sets doubles to 0.0])
1077 # And what happens when we malloc zero?
1078 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1079 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1080 [[#include <stdlib.h>
1081 #include <string.h>
1082 #include <stdio.h>
1083 #ifdef HAVE_STDDEF_H
1084 #include <stddef.h>
1085 #endif
1086 int main () { return malloc(0)?0:1; }]])],
1087        [tor_cv_malloc_zero_works=yes],
1088        [tor_cv_malloc_zero_works=no],
1089        [tor_cv_malloc_zero_works=cross])])
1091 if test "$tor_cv_malloc_zero_works" = cross; then
1092   # Cross-compiling; let's hope that the target isn't raving mad.
1093   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1096 if test "$tor_cv_malloc_zero_works" = yes; then
1097   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1098             [Define to 1 iff malloc(0) returns a pointer])
1101 # whether we seem to be in a 2s-complement world.
1102 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1103 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1104 [[int main () { int problem = ((-99) != (~99)+1);
1105 return problem ? 1 : 0; }]])],
1106        [tor_cv_twos_complement=yes],
1107        [tor_cv_twos_complement=no],
1108        [tor_cv_twos_complement=cross])])
1110 if test "$tor_cv_twos_complement" = cross ; then
1111   # Cross-compiling; let's hope that the target isn't raving mad.
1112   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1115 if test "$tor_cv_twos_complement" != no ; then
1116   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1117             [Define to 1 iff we represent negative integers with two's complement])
1120 # What does shifting a negative value do?
1121 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1122 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1123 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1124        [tor_cv_sign_extend=yes],
1125        [tor_cv_sign_extend=no],
1126        [tor_cv_sign_extend=cross])])
1128 if test "$tor_cv_sign_extend" = cross ; then
1129   # Cross-compiling; let's hope that the target isn't raving mad.
1130   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1133 if test "$tor_cv_sign_extend" != no ; then
1134   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1135             [Define to 1 iff right-shifting a negative value performs sign-extension])
1138 # Whether we should use the dmalloc memory allocation debugging library.
1139 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1140 AC_ARG_WITH(dmalloc,
1141 [  --with-dmalloc          Use debug memory allocation library. ],
1142 [if [[ "$withval" = "yes" ]]; then
1143   dmalloc=1
1144   AC_MSG_RESULT(yes)
1145 else
1146   dmalloc=1
1147   AC_MSG_RESULT(no)
1148 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1151 if [[ $dmalloc -eq 1 ]]; then
1152   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1153   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1154   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1155   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1156   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1159 AC_ARG_WITH(tcmalloc,
1160 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1161 [ tcmalloc=yes ], [ tcmalloc=no ])
1163 if test x$tcmalloc = xyes ; then
1164    LDFLAGS="-ltcmalloc $LDFLAGS"
1167 using_custom_malloc=no
1168 if test x$enable_openbsd_malloc = xyes ; then
1169    using_custom_malloc=yes
1171 if test x$tcmalloc = xyes ; then
1172    using_custom_malloc=yes
1174 if test $using_custom_malloc = no ; then
1175    AC_CHECK_FUNCS(mallinfo)
1178 # By default, we're going to assume we don't have mlockall()
1179 # bionic and other platforms have various broken mlockall subsystems.
1180 # Some systems don't have a working mlockall, some aren't linkable,
1181 # and some have it but don't declare it.
1182 AC_CHECK_FUNCS(mlockall)
1183 AC_CHECK_DECLS([mlockall], , , [
1184 #ifdef HAVE_SYS_MMAN_H
1185 #include <sys/mman.h>
1186 #endif])
1188 # Allow user to specify an alternate syslog facility
1189 AC_ARG_WITH(syslog-facility,
1190 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1191 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1192 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1193 AC_SUBST(LOGFACILITY)
1195 # Check if we have getresuid and getresgid
1196 AC_CHECK_FUNCS(getresuid getresgid)
1198 # Check for gethostbyname_r in all its glorious incompatible versions.
1199 #   (This logic is based on that in Python's configure.in)
1200 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1201   [Define this if you have any gethostbyname_r()])
1203 AC_CHECK_FUNC(gethostbyname_r, [
1204   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1205   OLD_CFLAGS=$CFLAGS
1206   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1207   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1208 #include <netdb.h>
1209   ], [[
1210     char *cp1, *cp2;
1211     struct hostent *h1, *h2;
1212     int i1, i2;
1213     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1214   ]])],[
1215     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1216     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1217      [Define this if gethostbyname_r takes 6 arguments])
1218     AC_MSG_RESULT(6)
1219   ], [
1220     AC_TRY_COMPILE([
1221 #include <netdb.h>
1222     ], [
1223       char *cp1, *cp2;
1224       struct hostent *h1;
1225       int i1, i2;
1226       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1227     ], [
1228       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1229       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1230         [Define this if gethostbyname_r takes 5 arguments])
1231       AC_MSG_RESULT(5)
1232    ], [
1233       AC_TRY_COMPILE([
1234 #include <netdb.h>
1235      ], [
1236        char *cp1;
1237        struct hostent *h1;
1238        struct hostent_data hd;
1239        (void) gethostbyname_r(cp1,h1,&hd);
1240      ], [
1241        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1242        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1243          [Define this if gethostbyname_r takes 3 arguments])
1244        AC_MSG_RESULT(3)
1245      ], [
1246        AC_MSG_RESULT(0)
1247      ])
1248   ])
1249  ])
1250  CFLAGS=$OLD_CFLAGS
1253 AC_CACHE_CHECK([whether the C compiler supports __func__],
1254   tor_cv_have_func_macro,
1255   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1256 #include <stdio.h>
1257 int main(int c, char **v) { puts(__func__); }])],
1258   tor_cv_have_func_macro=yes,
1259   tor_cv_have_func_macro=no))
1261 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1262   tor_cv_have_FUNC_macro,
1263   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1264 #include <stdio.h>
1265 int main(int c, char **v) { puts(__FUNC__); }])],
1266   tor_cv_have_FUNC_macro=yes,
1267   tor_cv_have_FUNC_macro=no))
1269 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1270   tor_cv_have_FUNCTION_macro,
1271   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1272 #include <stdio.h>
1273 int main(int c, char **v) { puts(__FUNCTION__); }])],
1274   tor_cv_have_FUNCTION_macro=yes,
1275   tor_cv_have_FUNCTION_macro=no))
1277 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1278   tor_cv_have_environ_declared,
1279   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1280 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1281  * Without it environ doesn't get declared. */
1282 #define _GNU_SOURCE
1283 #ifdef HAVE_UNISTD_H
1284 #include <unistd.h>
1285 #endif
1286 #include <stdlib.h>
1287 int main(int c, char **v) { char **t = environ; }])],
1288   tor_cv_have_environ_declared=yes,
1289   tor_cv_have_environ_declared=no))
1291 if test "$tor_cv_have_func_macro" = 'yes'; then
1292   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1295 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1296   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1299 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1300   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1301            [Defined if the compiler supports __FUNCTION__])
1304 if test "$tor_cv_have_environ_declared" = 'yes'; then
1305   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1306            [Defined if we have extern char **environ already declared])
1309 # $prefix stores the value of the --prefix command line option, or
1310 # NONE if the option wasn't set.  In the case that it wasn't set, make
1311 # it be the default, so that we can use it to expand directories now.
1312 if test "x$prefix" = "xNONE"; then
1313   prefix=$ac_default_prefix
1316 # and similarly for $exec_prefix
1317 if test "x$exec_prefix" = "xNONE"; then
1318   exec_prefix=$prefix
1321 if test "x$BUILDDIR" = "x"; then
1322   BUILDDIR=`pwd`
1324 AC_SUBST(BUILDDIR)
1325 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1326 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1328 if test "x$CONFDIR" = "x"; then
1329   CONFDIR=`eval echo $sysconfdir/tor`
1331 AC_SUBST(CONFDIR)
1332 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1333 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1335 BINDIR=`eval echo $bindir`
1336 AC_SUBST(BINDIR)
1337 LOCALSTATEDIR=`eval echo $localstatedir`
1338 AC_SUBST(LOCALSTATEDIR)
1340 if test "$bwin32" = true; then
1341   # Test if the linker supports the --nxcompat and --dynamicbase options
1342   # for Windows
1343   save_LDFLAGS="$LDFLAGS"
1344   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1345   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1346   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1347     [AC_MSG_RESULT([yes])]
1348     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1349     [AC_MSG_RESULT([no])]
1350   )
1351   LDFLAGS="$save_LDFLAGS"
1354 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1355 # than autoconf's macros like.
1356 if test "$GCC" = yes; then
1357   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1358   # accident waiting to happen.
1359   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1360 else
1361   # Autoconf sets -g -O2 by default. Override optimization level
1362   # for non-gcc compilers
1363   CFLAGS="$CFLAGS -O"
1364   enable_gcc_warnings=no
1365   enable_gcc_warnings_advisory=no
1368 # OS X Lion started deprecating the system openssl. Let's just disable
1369 # all deprecation warnings on OS X. Also, to potentially make the binary
1370 # a little smaller, let's enable dead_strip.
1371 case "$host_os" in
1373  darwin*)
1374     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1375     LDFLAGS="$LDFLAGS -dead_strip" ;;
1376 esac
1378 # Add some more warnings which we use in development but not in the
1379 # released versions.  (Some relevant gcc versions can't handle these.)
1380 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1382   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1383 #if !defined(__GNUC__) || (__GNUC__ < 4)
1384 #error
1385 #endif])], have_gcc4=yes, have_gcc4=no)
1387   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1388 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1389 #error
1390 #endif])], have_gcc42=yes, have_gcc42=no)
1392   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1393 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1394 #error
1395 #endif])], have_gcc43=yes, have_gcc43=no)
1397   save_CFLAGS="$CFLAGS"
1398   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1399   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1400                     have_shorten64_flag=no)
1401   CFLAGS="$save_CFLAGS"
1403   case $host in
1404     *-*-openbsd* | *-*-bitrig*)
1405       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1406       # That's fine, except that the headers don't pass -Wredundant-decls.
1407       # Therefore, let's disable -Wsystem-headers when we're building
1408       # with maximal warnings on OpenBSD.
1409       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1410   esac
1412   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1413   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1414   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1415   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1416   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1418   if test x$enable_gcc_warnings = xyes; then
1419     CFLAGS="$CFLAGS -Werror"
1420   fi
1422   # Disabled, so we can use mallinfo(): -Waggregate-return
1424   if test x$have_gcc4 = xyes ; then
1425     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1426     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1427   fi
1429   if test x$have_gcc42 = xyes ; then
1430     # These warnings break gcc 4.0.2 and work on gcc 4.2
1431     # XXXX020 See if any of these work with earlier versions.
1432     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1434     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1435   fi
1437   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1438     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1439     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1440   fi
1442   if test x$have_gcc43 = xyes ; then
1443     # These warnings break gcc 4.2 and work on gcc 4.3
1444     # XXXX020 See if any of these work with earlier versions.
1445     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1446   fi
1448   if test x$have_shorten64_flag = xyes ; then
1449     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1450   fi
1452 ##This will break the world on some 64-bit architectures
1453 # CFLAGS="$CFLAGS -Winline"
1458 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1460 AC_CONFIG_FILES([
1461         Doxyfile
1462         Makefile
1463         contrib/suse/tor.sh
1464         contrib/tor.logrotate
1465         contrib/tor.sh
1466         contrib/torctl
1467         contrib/torify
1468         src/config/torrc.sample
1471 if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
1472   regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
1473   for file in $regular_mans ; do
1474     if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
1475       echo "==================================";
1476       echo;
1477       echo "You need asciidoc installed to be able to build the manpage.";
1478       echo "To build without manpages, use the --disable-asciidoc argument";
1479       echo "when calling configure.";
1480       echo;
1481       echo "==================================";
1482       exit 1;
1483     fi
1484   done
1487 AC_OUTPUT
1489 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1490   ./contrib/updateVersions.pl