Note that our #13426 fix is also a #13471 fix.
[tor.git] / configure.in
blob8aa90f6414f2dbdc1387599e0d3b89b7ce61933e
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2012, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.2.3.18-rc-dev)
8 AM_CONFIG_HEADER(orconfig.h)
10 AC_CANONICAL_HOST
12 if test -f /etc/redhat-release ; then
13   if test -f /usr/kerberos/include ; then
14     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
15   fi
18 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
19 # the += operator on it in src/or/Makefile.am
20 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
22 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
23 AC_ARG_ENABLE(buf-freelists,
24    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
25 AC_ARG_ENABLE(openbsd-malloc,
26    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
27 AC_ARG_ENABLE(instrument-downloads,
28    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
29 AC_ARG_ENABLE(static-openssl,
30    AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
31 AC_ARG_ENABLE(static-libevent,
32    AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
33 AC_ARG_ENABLE(static-zlib,
34    AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
35 AC_ARG_ENABLE(static-tor,
36    AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir))
38 if test "$enable_static_tor" = "yes"; then
39   enable_static_libevent="yes";
40   enable_static_openssl="yes";
41   enable_static_zlib="yes";
42   CFLAGS="$CFLAGS -static"
45 if test x$enable_buf_freelists != xno; then
46   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
47             [Defined if we try to use freelists for buffer RAM chunks])
49 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
50 if test x$enable_instrument_downloads = xyes; then
51   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
52             [Defined if we want to keep track of how much of each kind of resource we download.])
55 AC_ARG_ENABLE(transparent,
56      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
57      [case "${enableval}" in
58         yes) transparent=true ;;
59         no)  transparent=false ;;
60         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
61       esac], [transparent=true])
63 AC_ARG_ENABLE(asciidoc,
64      AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
65      [case "${enableval}" in
66         yes) asciidoc=true ;;
67         no)  asciidoc=false ;;
68         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
69       esac], [asciidoc=true])
71 # By default, we're not ready to ship a NAT-PMP aware Tor
72 AC_ARG_ENABLE(nat-pmp,
73      AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
74      [case "${enableval}" in
75         yes) natpmp=true ;;
76         no)  natpmp=false ;;
77         * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
78       esac], [natpmp=false])
80 # By default, we're not ready to ship a UPnP aware Tor
81 AC_ARG_ENABLE(upnp,
82      AS_HELP_STRING(--enable-upnp, enable UPnP support),
83      [case "${enableval}" in
84         yes) upnp=true ;;
85         no)  upnp=false ;;
86         * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
87       esac], [upnp=false])
90 AC_ARG_ENABLE(threads,
91      AS_HELP_STRING(--disable-threads, disable multi-threading support))
93 if test x$enable_threads = x; then
94    case $host in
95     *-*-solaris* )
96      # Don't try multithreading on solaris -- cpuworkers seem to lock.
97      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
98 cpu workers lock up here, so I will disable threads.])
99      enable_threads="no";;
100     *)
101      enable_threads="yes";;
102    esac
105 if test "$enable_threads" = "yes"; then
106   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
109 case $host in
110    *-*-solaris* )
111      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
112      ;;
113 esac
115 AC_ARG_ENABLE(gcc-warnings,
116      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
117 AC_ARG_ENABLE(gcc-warnings-advisory,
118      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
120 dnl Adam shostack suggests the following for Windows:
121 dnl -D_FORTIFY_SOURCE=2 -fstack-protector-all
122 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
123 dnl This requires that we use gcc and that we add -O2 to the CFLAGS.
124 AC_ARG_ENABLE(gcc-hardening,
125     AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
127 dnl Linker hardening options
128 dnl Currently these options are ELF specific - you can't use this with MacOSX
129 AC_ARG_ENABLE(linker-hardening,
130     AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
132 AC_ARG_ENABLE(local-appdata,
133    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
134 if test "$enable_local_appdata" = "yes"; then
135   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
136             [Defined if we default to host local appdata paths on Windows])
139 # Tor2web mode flag
140 AC_ARG_ENABLE(tor2web-mode,
141      AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
142 [if test x$enableval = xyes; then
143     CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
144 fi])
146 AC_ARG_ENABLE(bufferevents,
147      AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
149 dnl check for the correct "ar" when cross-compiling
150 AN_MAKEVAR([AR], [AC_PROG_AR])
151 AN_PROGRAM([ar], [AC_PROG_AR])
152 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
153 AC_PROG_AR
155 AC_PROG_CC
156 AC_PROG_CPP
157 AC_PROG_MAKE_SET
158 AC_PROG_RANLIB
160 dnl autoconf 2.59 appears not to support AC_PROG_SED
161 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
163 dnl check for asciidoc and a2x
164 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
165 AC_PATH_PROG([A2X], [a2x], none)
167 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
169 AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
170 AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
171 AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
172 AM_PROG_CC_C_O
174 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
175 AC_C_FLEXIBLE_ARRAY_MEMBER
176 ], [
177  dnl Maybe we've got an old autoconf...
178  AC_CACHE_CHECK([for flexible array members],
179      tor_cv_c_flexarray,
180      [AC_COMPILE_IFELSE(
181        AC_LANG_PROGRAM([
182  struct abc { int a; char b[]; };
183 ], [
184  struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
185  def->b[0] = 33;
187   [tor_cv_c_flexarray=yes],
188   [tor_cv_c_flexarray=no])])
189  if test $tor_cv_flexarray = yes ; then
190    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
191  else
192    AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
193  fi
196 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
197 AC_PATH_PROG([OPENSSL], [openssl], none)
199 TORUSER=_tor
200 AC_ARG_WITH(tor-user,
201         [  --with-tor-user=NAME    Specify username for tor daemon ],
202         [
203            TORUSER=$withval
204         ]
206 AC_SUBST(TORUSER)
208 TORGROUP=_tor
209 AC_ARG_WITH(tor-group,
210         [  --with-tor-group=NAME   Specify group name for tor daemon ],
211         [
212            TORGROUP=$withval
213         ]
215 AC_SUBST(TORGROUP)
218 dnl If _WIN32 is defined and non-zero, we are building for win32
219 AC_MSG_CHECKING([for win32])
220 AC_RUN_IFELSE([AC_LANG_SOURCE([
221 int main(int c, char **v) {
222 #ifdef _WIN32
223 #if _WIN32
224   return 0;
225 #else
226   return 1;
227 #endif
228 #else
229   return 2;
230 #endif
231 }])],
232 bwin32=true; AC_MSG_RESULT([yes]),
233 bwin32=false; AC_MSG_RESULT([no]),
234 bwin32=cross; AC_MSG_RESULT([cross])
237 if test "$bwin32" = cross; then
238 AC_MSG_CHECKING([for win32 (cross)])
239 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
240 #ifdef _WIN32
241 int main(int c, char **v) {return 0;}
242 #else
243 #error
244 int main(int c, char **v) {return x(y);}
245 #endif
246 ])],
247 bwin32=true; AC_MSG_RESULT([yes]),
248 bwin32=false; AC_MSG_RESULT([no]))
251 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
253 dnl Enable C99 when compiling with MIPSpro
254 AC_MSG_CHECKING([for MIPSpro compiler])
255 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
256 #if (defined(__sgi) && defined(_COMPILER_VERSION))
257 #error
258   return x(y);
259 #endif
260 ])],
261 bmipspro=false; AC_MSG_RESULT(no),
262 bmipspro=true; AC_MSG_RESULT(yes))
264 if test "$bmipspro" = true; then
265   CFLAGS="$CFLAGS -c99"
268 AC_C_BIGENDIAN
270 AC_SEARCH_LIBS(socket, [socket network])
271 AC_SEARCH_LIBS(gethostbyname, [nsl])
272 AC_SEARCH_LIBS(dlopen, [dl])
273 AC_SEARCH_LIBS(inet_aton, [resolv])
274 saved_LIBS="$LIBS"
275 AC_SEARCH_LIBS([clock_gettime], [rt])
276 if test "$LIBS" != "$saved_LIBS"; then
277    # Looks like we need -lrt for clock_gettime().
278    have_rt=yes
281 if test "$enable_threads" = "yes"; then
282   AC_SEARCH_LIBS(pthread_create, [pthread])
283   AC_SEARCH_LIBS(pthread_detach, [pthread])
286 dnl -------------------------------------------------------------------
287 dnl Check for functions before libevent, since libevent-1.2 apparently
288 dnl exports strlcpy without defining it in a header.
290 AC_CHECK_FUNCS(
291         _NSGetEnviron \
292         accept4 \
293         clock_gettime \
294         flock \
295         ftime \
296         getaddrinfo \
297         getifaddrs \
298         getrlimit \
299         gettimeofday \
300         gmtime_r \
301         inet_aton \
302         ioctl \
303         issetugid \
304         localtime_r \
305         lround \
306         memmem \
307         prctl \
308         rint \
309         socketpair \
310         strlcat \
311         strlcpy \
312         strptime \
313         strtok_r \
314         strtoull \
315         sysconf \
316         uname \
317         vasprintf \
320 using_custom_malloc=no
321 if test x$enable_openbsd_malloc = xyes ; then
322    AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function])
323    using_custom_malloc=yes
325 if test x$tcmalloc = xyes ; then
326    using_custom_malloc=yes
328 if test $using_custom_malloc = no ; then
329    AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size)
332 if test "$enable_threads" = "yes"; then
333   AC_CHECK_HEADERS(pthread.h)
334   AC_CHECK_FUNCS(pthread_create)
337 dnl ------------------------------------------------------
338 dnl Where do you live, libevent?  And how do we call you?
340 if test "$bwin32" = true; then
341   TOR_LIB_WS32=-lws2_32
342   TOR_LIB_IPHLPAPI=-liphlpapi
343   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
344   # think it's actually necessary.
345   TOR_LIB_GDI=-lgdi32
346 else
347   TOR_LIB_WS32=
348   TOR_LIB_GDI=
350 AC_SUBST(TOR_LIB_WS32)
351 AC_SUBST(TOR_LIB_GDI)
352 AC_SUBST(TOR_LIB_IPHLPAPI)
354 dnl We need to do this before we try our disgusting hack below.
355 AC_CHECK_HEADERS([sys/types.h])
357 dnl This is a disgusting hack so we safely include older libevent headers.
358 AC_CHECK_TYPE(u_int64_t, unsigned long long)
359 AC_CHECK_TYPE(u_int32_t, unsigned long)
360 AC_CHECK_TYPE(u_int16_t, unsigned short)
361 AC_CHECK_TYPE(u_int8_t, unsigned char)
363 tor_libevent_pkg_redhat="libevent"
364 tor_libevent_pkg_debian="libevent-dev"
365 tor_libevent_devpkg_redhat="libevent-devel"
366 tor_libevent_devpkg_debian="libevent-dev"
368 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
369 dnl linking for static builds.
370 STATIC_LIBEVENT_FLAGS=""
371 if test "$enable_static_libevent" = "yes"; then
372     if test "$have_rt" = yes; then
373       STATIC_LIBEVENT_FLAGS=" -lrt "
374     fi
377 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
378 #ifdef _WIN32
379 #include <winsock2.h>
380 #endif
381 #include <stdlib.h>
382 #include <sys/time.h>
383 #include <sys/types.h>
384 #include <event.h>], [
385 #ifdef _WIN32
386 #include <winsock2.h>
387 #endif
388 void exit(int); void *event_init(void);],
389     [
390 #ifdef _WIN32
391 {WSADATA d; WSAStartup(0x101,&d); }
392 #endif
393 event_init(); exit(0);
394 ], [--with-libevent-dir], [/opt/libevent])
396 dnl Now check for particular libevent functions.
397 save_LIBS="$LIBS"
398 save_LDFLAGS="$LDFLAGS"
399 save_CPPFLAGS="$CPPFLAGS"
400 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
401 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
402 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
403 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)
404 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
405 [#include <event.h>
408 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
410 LIBS="$save_LIBS"
411 LDFLAGS="$save_LDFLAGS"
412 CPPFLAGS="$save_CPPFLAGS"
415 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
417 if test "$enable_static_libevent" = "yes"; then
418    if test "$tor_cv_library_libevent_dir" = "(system)"; then
419      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
420    else
421      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
422    fi
423 else
424      TOR_LIBEVENT_LIBS="-levent"
427 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
428 dnl we can do much better.
429 if test "$enable_bufferevents" = "yes" ; then
430   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
431     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.])
432   else
434     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
436     # Check for the right version.  First see if version detection works.
437     AC_MSG_CHECKING([whether we can detect the Libevent version])
438     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
439 #include <event2/event.h>
440 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
441 #error
442 int x = y(zz);
443 #else
444 int x = 1;
445 #endif
446   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
447      [event_version_number_works=no;  AC_MSG_RESULT([no])])
448     if test "$event_version_number_works" != 'yes'; then
449       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
450     else
451       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
452       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
453 #include <event2/event.h>
454 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
455 #error
456 int x = y(zz);
457 #else
458 int x = 1;
459 #endif
460    ])], [ AC_MSG_RESULT([yes]) ],
461       [ AC_MSG_RESULT([no])
462         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
463     fi
464   fi
467 LIBS="$save_LIBS"
468 LDFLAGS="$save_LDFLAGS"
469 CPPFLAGS="$save_CPPFLAGS"
471 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
472 if test "$enable_bufferevents" = "yes"; then
473   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
474   if test "$enable_static_libevent" = "yes"; then
475     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
476   else
477     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
478   fi
480 AC_SUBST(TOR_LIBEVENT_LIBS)
482 dnl ------------------------------------------------------
483 dnl Where do you live, libm?
485 dnl On some platforms (Haiku/BeOS) the math library is
486 dnl part of libroot. In which case don't link against lm
487 TOR_LIB_MATH=""
488 save_LIBS="$LIBS"
489 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
490 if test "$ac_cv_search_pow" != "none required"; then
491     TOR_LIB_MATH="$ac_cv_search_pow"
493 LIBS="$save_LIBS"
494 AC_SUBST(TOR_LIB_MATH)
496 dnl ------------------------------------------------------
497 dnl Where do you live, openssl?  And how do we call you?
499 tor_openssl_pkg_redhat="openssl"
500 tor_openssl_pkg_debian="libssl"
501 tor_openssl_devpkg_redhat="openssl-devel"
502 tor_openssl_devpkg_debian="libssl-dev"
504 ALT_openssl_WITHVAL=""
505 AC_ARG_WITH(ssl-dir,
506   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
507   [
508       if test "x$withval" != xno && test "x$withval" != "x" ; then
509          ALT_openssl_WITHVAL="$withval"
510       fi
511   ])
513 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
514     [#include <openssl/rand.h>],
515     [void RAND_add(const void *buf, int num, double entropy);],
516     [RAND_add((void*)0,0,0); exit(0);], [],
517     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
519 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
521 if test "$enable_static_openssl" = "yes"; then
522    if test "$tor_cv_library_openssl_dir" = "(system)"; then
523      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
524    else
525      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
526    fi
527 else
528      TOR_OPENSSL_LIBS="-lssl -lcrypto"
530 AC_SUBST(TOR_OPENSSL_LIBS)
532 dnl ------------------------------------------------------
533 dnl Where do you live, zlib?  And how do we call you?
535 tor_zlib_pkg_redhat="zlib"
536 tor_zlib_pkg_debian="zlib1g"
537 tor_zlib_devpkg_redhat="zlib-devel"
538 tor_zlib_devpkg_debian="zlib1g-dev"
540 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
541     [#include <zlib.h>],
542     [const char * zlibVersion(void);],
543     [zlibVersion(); exit(0);], [--with-zlib-dir],
544     [/opt/zlib])
546 if test "$enable_static_zlib" = "yes"; then
547    if test "$tor_cv_library_zlib_dir" = "(system)"; then
548      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
549  using --enable-static-zlib")
550    else
551      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
552    fi
553 else
554      TOR_ZLIB_LIBS="-lz"
556 AC_SUBST(TOR_ZLIB_LIBS)
558 dnl ---------------------------------------------------------------------
559 dnl Now that we know about our major libraries, we can check for compiler
560 dnl and linker hardening options.  We need to do this with the libraries known,
561 dnl since sometimes the linker will like an option but not be willing to
562 dnl use it with a build of a library.
564 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
565 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
567 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
568 #if !defined(__clang__)
569 #error
570 #endif])], have_clang=yes, have_clang=no)
572 if test x$enable_gcc_hardening != xno; then
573     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
574     if test x$have_clang = xyes; then
575         TOR_CHECK_CFLAGS(-Qunused-arguments)
576     fi
577     TOR_CHECK_CFLAGS(-fstack-protector-all)
578     TOR_CHECK_CFLAGS(-Wstack-protector)
579     TOR_CHECK_CFLAGS(-fwrapv)
580     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
581     if test "$bwin32" = "false"; then
582        TOR_CHECK_CFLAGS(-fPIE)
583        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
584     fi
587 if test x$enable_linker_hardening != xno; then
588     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
591 dnl ------------------------------------------------------
592 dnl Where do you live, libnatpmp?  And how do we call you?
593 dnl There are no packages for Debian or Redhat as of this patch
595 if test "$natpmp" = "true"; then
596     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
597     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
598         [#include <natpmp.h>],
599         [#ifdef _WIN32
600          #define STATICLIB
601          #endif
602          #include <natpmp.h>],
603         [   int r;
604             natpmp_t natpmp;
605             natpmpresp_t response;
606             r = initnatpmp(&natpmp, 0, 0);],
607             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
608             exit(0);],
609         [--with-libnatpmp-dir],
610         [/usr/lib/])
614 dnl ------------------------------------------------------
615 dnl Where do you live, libminiupnpc?  And how do we call you?
616 dnl There are no packages for Debian or Redhat as of this patch
618 if test "$upnp" = "true"; then
619     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
621     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
622     dnl to see if we have miniupnpc-1.5 or -1.6
623     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
624         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
626     if test "$miniupnpc15" = "true" ; then
627         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
628         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
629             [#include <miniupnpc/miniwget.h>
630              #include <miniupnpc/miniupnpc.h>
631              #include <miniupnpc/upnpcommands.h>],
632             [void upnpDiscover(int delay, const char * multicastif,
633              const char * minissdpdsock, int sameport);],
634             [upnpDiscover(1, 0, 0, 0); exit(0);],
635             [--with-libminiupnpc-dir],
636             [/usr/lib/])
637     else
638         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
639             [#include <miniupnpc/miniwget.h>
640              #include <miniupnpc/miniupnpc.h>
641              #include <miniupnpc/upnpcommands.h>],
642             [void upnpDiscover(int delay, const char * multicastif,
643              const char * minissdpdsock, int sameport, int ipv6, int * error);],
644             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
645             [--with-libminiupnpc-dir],
646             [/usr/lib/])
647     fi
650 dnl Make sure to enable support for large off_t if available.
651 AC_SYS_LARGEFILE
653 AC_CHECK_HEADERS(
654         assert.h \
655         errno.h \
656         fcntl.h \
657         signal.h \
658         string.h \
659         sys/fcntl.h \
660         sys/stat.h \
661         sys/time.h \
662         sys/types.h \
663         time.h \
664         unistd.h
665  , , 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.))
667 dnl These headers are not essential
669 AC_CHECK_HEADERS(
670         arpa/inet.h \
671         crt_externs.h \
672         grp.h \
673         ifaddrs.h \
674         inttypes.h \
675         limits.h \
676         linux/types.h \
677         machine/limits.h \
678         malloc.h \
679         malloc/malloc.h \
680         malloc_np.h \
681         netdb.h \
682         netinet/in.h \
683         netinet/in6.h \
684         pwd.h \
685         stdint.h \
686         sys/file.h \
687         sys/ioctl.h \
688         sys/limits.h \
689         sys/mman.h \
690         sys/param.h \
691         sys/prctl.h \
692         sys/resource.h \
693         sys/socket.h \
694         sys/syslimits.h \
695         sys/time.h \
696         sys/types.h \
697         sys/un.h \
698         sys/utime.h \
699         sys/wait.h \
700         syslog.h \
701         utime.h
704 AC_CHECK_HEADERS(sys/param.h)
706 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
707 [#ifdef HAVE_MALLOC_H
708 #include <malloc.h>
709 #endif
710 #ifdef HAVE_MALLOC_MALLOC_H
711 #include <malloc/malloc.h>
712 #endif])
714 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
715 [#ifdef HAVE_SYS_TYPES_H
716 #include <sys/types.h>
717 #endif
718 #ifdef HAVE_SYS_SOCKET_H
719 #include <sys/socket.h>
720 #endif])
721 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
722 [#ifdef HAVE_SYS_TYPES_H
723 #include <sys/types.h>
724 #endif
725 #ifdef HAVE_SYS_SOCKET_H
726 #include <sys/socket.h>
727 #endif
728 #ifdef HAVE_NET_IF_H
729 #include <net/if.h>
730 #endif])
731 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
732         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
733 [#ifdef HAVE_SYS_TYPES_H
734 #include <sys/types.h>
735 #endif
736 #ifdef HAVE_SYS_SOCKET_H
737 #include <sys/socket.h>
738 #endif
739 #ifdef HAVE_LIMITS_H
740 #include <limits.h>
741 #endif
742 #ifdef HAVE_LINUX_TYPES_H
743 #include <linux/types.h>
744 #endif
745 #ifdef HAVE_NETINET_IN6_H
746 #include <netinet/in6.h>
747 #endif
748 #ifdef HAVE_NETINET_IN_H
749 #include <netinet/in.h>
750 #endif])
752 if test x$transparent = xtrue ; then
753    transparent_ok=0
754    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
755      transparent_ok=1
756    fi
757    if test x$linux_netfilter_ipv4 = x1 ; then
758      transparent_ok=1
759    fi
760    if test x$transparent_ok = x1 ; then
761      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
762      case $host in
763        *-*-openbsd*)
764          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
765      esac
766    else
767      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
768    fi
771 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
772 [#ifdef HAVE_SYS_TYPES_H
773 #include <sys/types.h>
774 #endif
775 #ifdef HAVE_SYS_TIME_H
776 #include <sys/time.h>
777 #endif])
779 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
780 dnl Watch out.
782 AC_CHECK_SIZEOF(int8_t)
783 AC_CHECK_SIZEOF(int16_t)
784 AC_CHECK_SIZEOF(int32_t)
785 AC_CHECK_SIZEOF(int64_t)
786 AC_CHECK_SIZEOF(uint8_t)
787 AC_CHECK_SIZEOF(uint16_t)
788 AC_CHECK_SIZEOF(uint32_t)
789 AC_CHECK_SIZEOF(uint64_t)
790 AC_CHECK_SIZEOF(intptr_t)
791 AC_CHECK_SIZEOF(uintptr_t)
793 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
795 AC_CHECK_SIZEOF(char)
796 AC_CHECK_SIZEOF(short)
797 AC_CHECK_SIZEOF(int)
798 AC_CHECK_SIZEOF(long)
799 AC_CHECK_SIZEOF(long long)
800 AC_CHECK_SIZEOF(__int64)
801 AC_CHECK_SIZEOF(void *)
802 AC_CHECK_SIZEOF(time_t)
803 AC_CHECK_SIZEOF(size_t)
805 AC_CHECK_TYPES([uint, u_char, ssize_t])
807 dnl used to include sockaddr_storage, but everybody has that.
808 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
809 [#ifdef HAVE_SYS_TYPES_H
810 #include <sys/types.h>
811 #endif
812 #ifdef HAVE_NETINET_IN_H
813 #include <netinet/in.h>
814 #endif
815 #ifdef HAVE_NETINET_IN6_H
816 #include <netinet/in6.h>
817 #endif
818 #ifdef HAVE_SYS_SOCKET_H
819 #include <sys/socket.h>
820 #endif
821 #ifdef _WIN32
822 #define _WIN32_WINNT 0x0501
823 #define WIN32_LEAN_AND_MEAN
824 #if defined(_MSC_VER) && (_MSC_VER < 1300)
825 #include <winsock.h>
826 #else
827 #include <winsock2.h>
828 #include <ws2tcpip.h>
829 #endif
830 #endif
832 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
833 [#ifdef HAVE_SYS_TYPES_H
834 #include <sys/types.h>
835 #endif
836 #ifdef HAVE_NETINET_IN_H
837 #include <netinet/in.h>
838 #endif
839 #ifdef HAVE_NETINET_IN6_H
840 #include <netinet/in6.h>
841 #endif
842 #ifdef HAVE_SYS_SOCKET_H
843 #include <sys/socket.h>
844 #endif
845 #ifdef _WIN32
846 #define _WIN32_WINNT 0x0501
847 #define WIN32_LEAN_AND_MEAN
848 #if defined(_MSC_VER) && (_MSC_VER < 1300)
849 #include <winsock.h>
850 #else
851 #include <winsock2.h>
852 #include <ws2tcpip.h>
853 #endif
854 #endif
857 AC_CHECK_TYPES([rlim_t], , ,
858 [#ifdef HAVE_SYS_TYPES_H
859 #include <sys/types.h>
860 #endif
861 #ifdef HAVE_SYS_TIME_H
862 #include <sys/time.h>
863 #endif
864 #ifdef HAVE_SYS_RESOURCE_H
865 #include <sys/resource.h>
866 #endif
869 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
870 AC_RUN_IFELSE([AC_LANG_SOURCE([
871 #ifdef HAVE_SYS_TYPES_H
872 #include <sys/types.h>
873 #endif
874 #ifdef HAVE_SYS_TIME_H
875 #include <sys/time.h>
876 #endif
877 #ifdef HAVE_TIME_H
878 #include <time.h>
879 #endif
880 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }])],
881   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
884 if test "$tor_cv_time_t_signed" = cross; then
885   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
888 if test "$tor_cv_time_t_signed" != no; then
889   AC_DEFINE([TIME_T_IS_SIGNED], 1,
890             [Define to 1 iff time_t is signed])
893 AC_CACHE_CHECK([whether size_t is signed], tor_cv_size_t_signed, [
894 AC_RUN_IFELSE([AC_LANG_SOURCE([
895 #ifdef HAVE_SYS_TYPES_H
896 #include <sys/types.h>
897 #endif
898 int main(int c, char**v) { if (((size_t)-1)<0) return 1; else return 0; }])],
899   tor_cv_size_t_signed=no, tor_cv_size_t_signed=yes, tor_cv_size_t_signed=cross)
902 if test "$tor_cv_size_t_signed" = cross; then
903   AC_MSG_NOTICE([Cross compiling: assuming that size_t is not signed.])
906 if test "$tor_cv_size_t_signed" = yes; then
907   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
910 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
911 #ifdef HAVE_SYS_SOCKET_H
912 #include <sys/socket.h>
913 #endif
916 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
918 AC_CHECK_SIZEOF(cell_t)
920 # Now make sure that NULL can be represented as zero bytes.
921 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
922 [AC_RUN_IFELSE([AC_LANG_SOURCE(
923 [[#include <stdlib.h>
924 #include <string.h>
925 #include <stdio.h>
926 #ifdef HAVE_STDDEF_H
927 #include <stddef.h>
928 #endif
929 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
930 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
931        [tor_cv_null_is_zero=yes],
932        [tor_cv_null_is_zero=no],
933        [tor_cv_null_is_zero=cross])])
935 if test "$tor_cv_null_is_zero" = cross ; then
936   # Cross-compiling; let's hope that the target isn't raving mad.
937   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
940 if test "$tor_cv_null_is_zero" != no; then
941   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
942             [Define to 1 iff memset(0) sets pointers to NULL])
945 # And what happens when we malloc zero?
946 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
947 [AC_RUN_IFELSE([AC_LANG_SOURCE(
948 [[#include <stdlib.h>
949 #include <string.h>
950 #include <stdio.h>
951 #ifdef HAVE_STDDEF_H
952 #include <stddef.h>
953 #endif
954 int main () { return malloc(0)?0:1; }]])],
955        [tor_cv_malloc_zero_works=yes],
956        [tor_cv_malloc_zero_works=no],
957        [tor_cv_malloc_zero_works=cross])])
959 if test "$tor_cv_malloc_zero_works" = cross; then
960   # Cross-compiling; let's hope that the target isn't raving mad.
961   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
964 if test "$tor_cv_malloc_zero_works" = yes; then
965   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
966             [Define to 1 iff malloc(0) returns a pointer])
969 # whether we seem to be in a 2s-complement world.
970 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
971 [AC_RUN_IFELSE([AC_LANG_SOURCE(
972 [[int main () { int problem = ((-99) != (~99)+1);
973 return problem ? 1 : 0; }]])],
974        [tor_cv_twos_complement=yes],
975        [tor_cv_twos_complement=no],
976        [tor_cv_twos_complement=cross])])
978 if test "$tor_cv_twos_complement" = cross ; then
979   # Cross-compiling; let's hope that the target isn't raving mad.
980   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
983 if test "$tor_cv_twos_complement" != no ; then
984   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
985             [Define to 1 iff we represent negative integers with two's complement])
988 # What does shifting a negative value do?
989 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
990 [AC_RUN_IFELSE([AC_LANG_SOURCE(
991 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
992        [tor_cv_sign_extend=yes],
993        [tor_cv_sign_extend=no],
994        [tor_cv_sign_extend=cross])])
996 if test "$tor_cv_sign_extend" = cross ; then
997   # Cross-compiling; let's hope that the target isn't raving mad.
998   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1001 if test "$tor_cv_sign_extend" != no ; then
1002   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1003             [Define to 1 iff right-shifting a negative value performs sign-extension])
1006 # Whether we should use the dmalloc memory allocation debugging library.
1007 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1008 AC_ARG_WITH(dmalloc,
1009 [  --with-dmalloc          Use debug memory allocation library. ],
1010 [if [[ "$withval" = "yes" ]]; then
1011   dmalloc=1
1012   AC_MSG_RESULT(yes)
1013 else
1014   dmalloc=1
1015   AC_MSG_RESULT(no)
1016 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1019 if [[ $dmalloc -eq 1 ]]; then
1020   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1021   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1022   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1023   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1024   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1027 AC_ARG_WITH(tcmalloc,
1028 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1029 [ tcmalloc=yes ], [ tcmalloc=no ])
1031 if test x$tcmalloc = xyes ; then
1032    LDFLAGS="-ltcmalloc $LDFLAGS"
1035 # By default, we're going to assume we don't have mlockall()
1036 # bionic and other platforms have various broken mlockall subsystems.
1037 # Some systems don't have a working mlockall, some aren't linkable,
1038 # and some have it but don't declare it.
1039 AC_CHECK_FUNCS(mlockall)
1040 AC_CHECK_DECLS([mlockall], , , [
1041 #ifdef HAVE_SYS_MMAN_H
1042 #include <sys/mman.h>
1043 #endif])
1045 # Allow user to specify an alternate syslog facility
1046 AC_ARG_WITH(syslog-facility,
1047 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1048 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1049 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1050 AC_SUBST(LOGFACILITY)
1052 # Check if we have getresuid and getresgid
1053 AC_CHECK_FUNCS(getresuid getresgid)
1055 # Check for gethostbyname_r in all its glorious incompatible versions.
1056 #   (This logic is based on that in Python's configure.in)
1057 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1058   [Define this if you have any gethostbyname_r()])
1060 AC_CHECK_FUNC(gethostbyname_r, [
1061   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1062   OLD_CFLAGS=$CFLAGS
1063   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1064   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1065 #include <netdb.h>
1066   ], [[
1067     char *cp1, *cp2;
1068     struct hostent *h1, *h2;
1069     int i1, i2;
1070     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1071   ]])],[
1072     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1073     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1074      [Define this if gethostbyname_r takes 6 arguments])
1075     AC_MSG_RESULT(6)
1076   ], [
1077     AC_TRY_COMPILE([
1078 #include <netdb.h>
1079     ], [
1080       char *cp1, *cp2;
1081       struct hostent *h1;
1082       int i1, i2;
1083       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1084     ], [
1085       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1086       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1087         [Define this if gethostbyname_r takes 5 arguments])
1088       AC_MSG_RESULT(5)
1089    ], [
1090       AC_TRY_COMPILE([
1091 #include <netdb.h>
1092      ], [
1093        char *cp1;
1094        struct hostent *h1;
1095        struct hostent_data hd;
1096        (void) gethostbyname_r(cp1,h1,&hd);
1097      ], [
1098        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1099        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1100          [Define this if gethostbyname_r takes 3 arguments])
1101        AC_MSG_RESULT(3)
1102      ], [
1103        AC_MSG_RESULT(0)
1104      ])
1105   ])
1106  ])
1107  CFLAGS=$OLD_CFLAGS
1110 AC_CACHE_CHECK([whether the C compiler supports __func__],
1111   tor_cv_have_func_macro,
1112   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1113 #include <stdio.h>
1114 int main(int c, char **v) { puts(__func__); }])],
1115   tor_cv_have_func_macro=yes,
1116   tor_cv_have_func_macro=no))
1118 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1119   tor_cv_have_FUNC_macro,
1120   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1121 #include <stdio.h>
1122 int main(int c, char **v) { puts(__FUNC__); }])],
1123   tor_cv_have_FUNC_macro=yes,
1124   tor_cv_have_FUNC_macro=no))
1126 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1127   tor_cv_have_FUNCTION_macro,
1128   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1129 #include <stdio.h>
1130 int main(int c, char **v) { puts(__FUNCTION__); }])],
1131   tor_cv_have_FUNCTION_macro=yes,
1132   tor_cv_have_FUNCTION_macro=no))
1134 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1135   tor_cv_have_environ_declared,
1136   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1137 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1138  * Without it environ doesn't get declared. */
1139 #define _GNU_SOURCE
1140 #ifdef HAVE_UNISTD_H
1141 #include <unistd.h>
1142 #endif
1143 #include <stdlib.h>
1144 int main(int c, char **v) { char **t = environ; }])],
1145   tor_cv_have_environ_declared=yes,
1146   tor_cv_have_environ_declared=no))
1148 if test "$tor_cv_have_func_macro" = 'yes'; then
1149   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1152 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1153   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1156 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1157   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1158            [Defined if the compiler supports __FUNCTION__])
1161 if test "$tor_cv_have_environ_declared" = 'yes'; then
1162   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1163            [Defined if we have extern char **environ already declared])
1166 # $prefix stores the value of the --prefix command line option, or
1167 # NONE if the option wasn't set.  In the case that it wasn't set, make
1168 # it be the default, so that we can use it to expand directories now.
1169 if test "x$prefix" = "xNONE"; then
1170   prefix=$ac_default_prefix
1173 # and similarly for $exec_prefix
1174 if test "x$exec_prefix" = "xNONE"; then
1175   exec_prefix=$prefix
1178 if test "x$BUILDDIR" = "x"; then
1179   BUILDDIR=`pwd`
1181 AC_SUBST(BUILDDIR)
1182 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1183 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1185 if test "x$CONFDIR" = "x"; then
1186   CONFDIR=`eval echo $sysconfdir/tor`
1188 AC_SUBST(CONFDIR)
1189 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1190 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1192 BINDIR=`eval echo $bindir`
1193 AC_SUBST(BINDIR)
1194 LOCALSTATEDIR=`eval echo $localstatedir`
1195 AC_SUBST(LOCALSTATEDIR)
1197 if test "$bwin32" = true; then
1198   # Test if the linker supports the --nxcompat and --dynamicbase options
1199   # for Windows
1200   save_LDFLAGS="$LDFLAGS"
1201   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1202   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1203   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1204     [AC_MSG_RESULT([yes])]
1205     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1206     [AC_MSG_RESULT([no])]
1207   )
1208   LDFLAGS="$save_LDFLAGS"
1211 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1212 # than autoconf's macros like.
1213 if test "$GCC" = yes; then
1214   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1215   # accident waiting to happen.
1216   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1217 else
1218   # Autoconf sets -g -O2 by default. Override optimization level
1219   # for non-gcc compilers
1220   CFLAGS="$CFLAGS -O"
1221   enable_gcc_warnings=no
1222   enable_gcc_warnings_advisory=no
1225 # OS X Lion started deprecating the system openssl. Let's just disable
1226 # all deprecation warnings on OS X. Also, to potentially make the binary
1227 # a little smaller, let's enable dead_strip.
1228 case "$host_os" in
1230  darwin*)
1231     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1232     LDFLAGS="$LDFLAGS -dead_strip" ;;
1233 esac
1235 # Add some more warnings which we use in development but not in the
1236 # released versions.  (Some relevant gcc versions can't handle these.)
1237 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1239   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1240 #if !defined(__GNUC__) || (__GNUC__ < 4)
1241 #error
1242 #endif])], have_gcc4=yes, have_gcc4=no)
1244   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1245 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1246 #error
1247 #endif])], have_gcc42=yes, have_gcc42=no)
1249   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1250 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1251 #error
1252 #endif])], have_gcc43=yes, have_gcc43=no)
1254   save_CFLAGS="$CFLAGS"
1255   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1256   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1257                     have_shorten64_flag=no)
1258   CFLAGS="$save_CFLAGS"
1260   case $host in
1261     *-*-openbsd*)
1262       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1263       # That's fine, except that the headers don't pass -Wredundant-decls.
1264       # Therefore, let's disable -Wsystem-headers when we're building
1265       # with maximal warnings on OpenBSD.
1266       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1267   esac
1269   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1270   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1271   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1272   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1273   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1275   if test x$enable_gcc_warnings = xyes; then
1276     CFLAGS="$CFLAGS -Werror"
1277   fi
1279   # Disabled, so we can use mallinfo(): -Waggregate-return
1281   if test x$have_gcc4 = xyes ; then
1282     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1283     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1284   fi
1286   if test x$have_gcc42 = xyes ; then
1287     # These warnings break gcc 4.0.2 and work on gcc 4.2
1288     # XXXX020 See if any of these work with earlier versions.
1289     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1291     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1292   fi
1294   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1295     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1296     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1297   fi
1299   if test x$have_gcc43 = xyes ; then
1300     # These warnings break gcc 4.2 and work on gcc 4.3
1301     # XXXX020 See if any of these work with earlier versions.
1302     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1303   fi
1305   if test x$have_shorten64_flag = xyes ; then
1306     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1307   fi
1309 ##This will break the world on some 64-bit architectures
1310 # CFLAGS="$CFLAGS -Winline"
1315 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1317 AC_CONFIG_FILES([
1318         Doxyfile
1319         Makefile
1320         contrib/Makefile
1321         contrib/suse/Makefile
1322         contrib/suse/tor.sh
1323         contrib/tor.logrotate
1324         contrib/tor.sh
1325         contrib/torctl
1326         contrib/torify
1327         doc/Makefile
1328         src/Makefile
1329         src/common/Makefile
1330         src/config/Makefile
1331         src/config/torrc.sample
1332         src/or/Makefile
1333         src/test/Makefile
1334         src/tools/Makefile
1335         src/tools/tor-fw-helper/Makefile
1336         src/win32/Makefile
1337         tor.spec
1340 AC_OUTPUT
1342 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1343   ./contrib/updateVersions.pl