forward-port the 0.2.2.38 changelog
[tor.git] / configure.in
blobc85930948f2aed4cfeadeb6284cd422878a321f8
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.20-rc)
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         localtime_r \
304         lround \
305         memmem \
306         prctl \
307         rint \
308         socketpair \
309         strlcat \
310         strlcpy \
311         strptime \
312         strtok_r \
313         strtoull \
314         sysconf \
315         uname \
316         vasprintf \
319 using_custom_malloc=no
320 if test x$enable_openbsd_malloc = xyes ; then
321    AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function])
322    using_custom_malloc=yes
324 if test x$tcmalloc = xyes ; then
325    using_custom_malloc=yes
327 if test $using_custom_malloc = no ; then
328    AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size)
331 if test "$enable_threads" = "yes"; then
332   AC_CHECK_HEADERS(pthread.h)
333   AC_CHECK_FUNCS(pthread_create)
336 dnl ------------------------------------------------------
337 dnl Where do you live, libevent?  And how do we call you?
339 if test "$bwin32" = true; then
340   TOR_LIB_WS32=-lws2_32
341   TOR_LIB_IPHLPAPI=-liphlpapi
342   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
343   # think it's actually necessary.
344   TOR_LIB_GDI=-lgdi32
345 else
346   TOR_LIB_WS32=
347   TOR_LIB_GDI=
349 AC_SUBST(TOR_LIB_WS32)
350 AC_SUBST(TOR_LIB_GDI)
351 AC_SUBST(TOR_LIB_IPHLPAPI)
353 dnl We need to do this before we try our disgusting hack below.
354 AC_CHECK_HEADERS([sys/types.h])
356 dnl This is a disgusting hack so we safely include older libevent headers.
357 AC_CHECK_TYPE(u_int64_t, unsigned long long)
358 AC_CHECK_TYPE(u_int32_t, unsigned long)
359 AC_CHECK_TYPE(u_int16_t, unsigned short)
360 AC_CHECK_TYPE(u_int8_t, unsigned char)
362 tor_libevent_pkg_redhat="libevent"
363 tor_libevent_pkg_debian="libevent-dev"
364 tor_libevent_devpkg_redhat="libevent-devel"
365 tor_libevent_devpkg_debian="libevent-dev"
367 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
368 dnl linking for static builds.
369 STATIC_LIBEVENT_FLAGS=""
370 if test "$enable_static_libevent" = "yes"; then
371     if test "$have_rt" = yes; then
372       STATIC_LIBEVENT_FLAGS=" -lrt "
373     fi
376 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
377 #ifdef _WIN32
378 #include <winsock2.h>
379 #endif
380 #include <stdlib.h>
381 #include <sys/time.h>
382 #include <sys/types.h>
383 #include <event.h>], [
384 #ifdef _WIN32
385 #include <winsock2.h>
386 #endif
387 void exit(int); void *event_init(void);],
388     [
389 #ifdef _WIN32
390 {WSADATA d; WSAStartup(0x101,&d); }
391 #endif
392 event_init(); exit(0);
393 ], [--with-libevent-dir], [/opt/libevent])
395 dnl Now check for particular libevent functions.
396 save_LIBS="$LIBS"
397 save_LDFLAGS="$LDFLAGS"
398 save_CPPFLAGS="$CPPFLAGS"
399 LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
400 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
401 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
402 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)
403 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
404 [#include <event.h>
407 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
409 LIBS="$save_LIBS"
410 LDFLAGS="$save_LDFLAGS"
411 CPPFLAGS="$save_CPPFLAGS"
414 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
416 if test "$enable_static_libevent" = "yes"; then
417    if test "$tor_cv_library_libevent_dir" = "(system)"; then
418      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
419    else
420      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
421    fi
422 else
423      TOR_LIBEVENT_LIBS="-levent"
426 dnl This isn't the best test for Libevent 2.0.3-alpha.  Once it's released,
427 dnl we can do much better.
428 if test "$enable_bufferevents" = "yes" ; then
429   if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
430     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.])
431   else
433     CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
435     # Check for the right version.  First see if version detection works.
436     AC_MSG_CHECKING([whether we can detect the Libevent version])
437     AC_COMPILE_IFELSE([AC_LANG_SOURCE([
438 #include <event2/event.h>
439 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
440 #error
441 int x = y(zz);
442 #else
443 int x = 1;
444 #endif
445   ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
446      [event_version_number_works=no;  AC_MSG_RESULT([no])])
447     if test "$event_version_number_works" != 'yes'; then
448       AC_MSG_WARN([Version detection on Libevent seems broken.  Your Libevent installation is probably screwed up or very old.])
449     else
450       AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
451       AC_COMPILE_IFELSE([AC_LANG_SOURCE([
452 #include <event2/event.h>
453 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
454 #error
455 int x = y(zz);
456 #else
457 int x = 1;
458 #endif
459    ])], [ AC_MSG_RESULT([yes]) ],
460       [ AC_MSG_RESULT([no])
461         AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents.  We require 2.0.13-stable or later]) ] )
462     fi
463   fi
466 LIBS="$save_LIBS"
467 LDFLAGS="$save_LDFLAGS"
468 CPPFLAGS="$save_CPPFLAGS"
470 AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
471 if test "$enable_bufferevents" = "yes"; then
472   AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
473   if test "$enable_static_libevent" = "yes"; then
474     TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
475   else
476     TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
477   fi
479 AC_SUBST(TOR_LIBEVENT_LIBS)
481 dnl ------------------------------------------------------
482 dnl Where do you live, libm?
484 dnl On some platforms (Haiku/BeOS) the math library is
485 dnl part of libroot. In which case don't link against lm
486 TOR_LIB_MATH=""
487 save_LIBS="$LIBS"
488 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
489 if test "$ac_cv_search_pow" != "none required"; then
490     TOR_LIB_MATH="$ac_cv_search_pow"
492 LIBS="$save_LIBS"
493 AC_SUBST(TOR_LIB_MATH)
495 dnl ------------------------------------------------------
496 dnl Where do you live, openssl?  And how do we call you?
498 tor_openssl_pkg_redhat="openssl"
499 tor_openssl_pkg_debian="libssl"
500 tor_openssl_devpkg_redhat="openssl-devel"
501 tor_openssl_devpkg_debian="libssl-dev"
503 ALT_openssl_WITHVAL=""
504 AC_ARG_WITH(ssl-dir,
505   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
506   [
507       if test "x$withval" != xno && test "x$withval" != "x" ; then
508          ALT_openssl_WITHVAL="$withval"
509       fi
510   ])
512 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
513     [#include <openssl/rand.h>],
514     [void RAND_add(const void *buf, int num, double entropy);],
515     [RAND_add((void*)0,0,0); exit(0);], [],
516     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
518 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
520 if test "$enable_static_openssl" = "yes"; then
521    if test "$tor_cv_library_openssl_dir" = "(system)"; then
522      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
523    else
524      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
525    fi
526 else
527      TOR_OPENSSL_LIBS="-lssl -lcrypto"
529 AC_SUBST(TOR_OPENSSL_LIBS)
531 dnl ------------------------------------------------------
532 dnl Where do you live, zlib?  And how do we call you?
534 tor_zlib_pkg_redhat="zlib"
535 tor_zlib_pkg_debian="zlib1g"
536 tor_zlib_devpkg_redhat="zlib-devel"
537 tor_zlib_devpkg_debian="zlib1g-dev"
539 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
540     [#include <zlib.h>],
541     [const char * zlibVersion(void);],
542     [zlibVersion(); exit(0);], [--with-zlib-dir],
543     [/opt/zlib])
545 if test "$enable_static_zlib" = "yes"; then
546    if test "$tor_cv_library_zlib_dir" = "(system)"; then
547      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
548  using --enable-static-zlib")
549    else
550      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
551    fi
552 else
553      TOR_ZLIB_LIBS="-lz"
555 AC_SUBST(TOR_ZLIB_LIBS)
557 dnl ---------------------------------------------------------------------
558 dnl Now that we know about our major libraries, we can check for compiler
559 dnl and linker hardening options.  We need to do this with the libraries known,
560 dnl since sometimes the linker will like an option but not be willing to
561 dnl use it with a build of a library.
563 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
564 all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
566 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
567 #if !defined(__clang__)
568 #error
569 #endif])], have_clang=yes, have_clang=no)
571 if test x$enable_gcc_hardening != xno; then
572     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
573     if test x$have_clang = xyes; then
574         TOR_CHECK_CFLAGS(-Qunused-arguments)
575     fi
576     TOR_CHECK_CFLAGS(-fstack-protector-all)
577     TOR_CHECK_CFLAGS(-Wstack-protector)
578     TOR_CHECK_CFLAGS(-fwrapv)
579     TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
580     if test "$bwin32" = "false"; then
581        TOR_CHECK_CFLAGS(-fPIE)
582        TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
583     fi
586 if test x$enable_linker_hardening != xno; then
587     TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
590 dnl ------------------------------------------------------
591 dnl Where do you live, libnatpmp?  And how do we call you?
592 dnl There are no packages for Debian or Redhat as of this patch
594 if test "$natpmp" = "true"; then
595     AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
596     TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
597         [#include <natpmp.h>],
598         [#ifdef _WIN32
599          #define STATICLIB
600          #endif
601          #include <natpmp.h>],
602         [   int r;
603             natpmp_t natpmp;
604             natpmpresp_t response;
605             r = initnatpmp(&natpmp, 0, 0);],
606             [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
607             exit(0);],
608         [--with-libnatpmp-dir],
609         [/usr/lib/])
613 dnl ------------------------------------------------------
614 dnl Where do you live, libminiupnpc?  And how do we call you?
615 dnl There are no packages for Debian or Redhat as of this patch
617 if test "$upnp" = "true"; then
618     AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
620     dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
621     dnl to see if we have miniupnpc-1.5 or -1.6
622     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
623         [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
625     if test "$miniupnpc15" = "true" ; then
626         AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
627         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
628             [#include <miniupnpc/miniwget.h>
629              #include <miniupnpc/miniupnpc.h>
630              #include <miniupnpc/upnpcommands.h>],
631             [void upnpDiscover(int delay, const char * multicastif,
632              const char * minissdpdsock, int sameport);],
633             [upnpDiscover(1, 0, 0, 0); exit(0);],
634             [--with-libminiupnpc-dir],
635             [/usr/lib/])
636     else
637         TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
638             [#include <miniupnpc/miniwget.h>
639              #include <miniupnpc/miniupnpc.h>
640              #include <miniupnpc/upnpcommands.h>],
641             [void upnpDiscover(int delay, const char * multicastif,
642              const char * minissdpdsock, int sameport, int ipv6, int * error);],
643             [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
644             [--with-libminiupnpc-dir],
645             [/usr/lib/])
646     fi
649 dnl Make sure to enable support for large off_t if available.
650 AC_SYS_LARGEFILE
652 AC_CHECK_HEADERS(
653         assert.h \
654         errno.h \
655         fcntl.h \
656         signal.h \
657         string.h \
658         sys/fcntl.h \
659         sys/stat.h \
660         sys/time.h \
661         sys/types.h \
662         time.h \
663         unistd.h
664  , , 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.))
666 dnl These headers are not essential
668 AC_CHECK_HEADERS(
669         arpa/inet.h \
670         crt_externs.h \
671         grp.h \
672         ifaddrs.h \
673         inttypes.h \
674         limits.h \
675         linux/types.h \
676         machine/limits.h \
677         malloc.h \
678         malloc/malloc.h \
679         malloc_np.h \
680         netdb.h \
681         netinet/in.h \
682         netinet/in6.h \
683         pwd.h \
684         stdint.h \
685         sys/file.h \
686         sys/ioctl.h \
687         sys/limits.h \
688         sys/mman.h \
689         sys/param.h \
690         sys/prctl.h \
691         sys/resource.h \
692         sys/socket.h \
693         sys/syslimits.h \
694         sys/time.h \
695         sys/types.h \
696         sys/un.h \
697         sys/utime.h \
698         sys/wait.h \
699         syslog.h \
700         utime.h
703 AC_CHECK_HEADERS(sys/param.h)
705 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
706 [#ifdef HAVE_MALLOC_H
707 #include <malloc.h>
708 #endif
709 #ifdef HAVE_MALLOC_MALLOC_H
710 #include <malloc/malloc.h>
711 #endif])
713 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
714 [#ifdef HAVE_SYS_TYPES_H
715 #include <sys/types.h>
716 #endif
717 #ifdef HAVE_SYS_SOCKET_H
718 #include <sys/socket.h>
719 #endif])
720 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
721 [#ifdef HAVE_SYS_TYPES_H
722 #include <sys/types.h>
723 #endif
724 #ifdef HAVE_SYS_SOCKET_H
725 #include <sys/socket.h>
726 #endif
727 #ifdef HAVE_NET_IF_H
728 #include <net/if.h>
729 #endif])
730 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
731         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
732 [#ifdef HAVE_SYS_TYPES_H
733 #include <sys/types.h>
734 #endif
735 #ifdef HAVE_SYS_SOCKET_H
736 #include <sys/socket.h>
737 #endif
738 #ifdef HAVE_LIMITS_H
739 #include <limits.h>
740 #endif
741 #ifdef HAVE_LINUX_TYPES_H
742 #include <linux/types.h>
743 #endif
744 #ifdef HAVE_NETINET_IN6_H
745 #include <netinet/in6.h>
746 #endif
747 #ifdef HAVE_NETINET_IN_H
748 #include <netinet/in.h>
749 #endif])
751 if test x$transparent = xtrue ; then
752    transparent_ok=0
753    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
754      transparent_ok=1
755    fi
756    if test x$linux_netfilter_ipv4 = x1 ; then
757      transparent_ok=1
758    fi
759    if test x$transparent_ok = x1 ; then
760      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
761      case $host in
762        *-*-openbsd*)
763          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
764      esac
765    else
766      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
767    fi
770 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
771 [#ifdef HAVE_SYS_TYPES_H
772 #include <sys/types.h>
773 #endif
774 #ifdef HAVE_SYS_TIME_H
775 #include <sys/time.h>
776 #endif])
778 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
779 dnl Watch out.
781 AC_CHECK_SIZEOF(int8_t)
782 AC_CHECK_SIZEOF(int16_t)
783 AC_CHECK_SIZEOF(int32_t)
784 AC_CHECK_SIZEOF(int64_t)
785 AC_CHECK_SIZEOF(uint8_t)
786 AC_CHECK_SIZEOF(uint16_t)
787 AC_CHECK_SIZEOF(uint32_t)
788 AC_CHECK_SIZEOF(uint64_t)
789 AC_CHECK_SIZEOF(intptr_t)
790 AC_CHECK_SIZEOF(uintptr_t)
792 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
794 AC_CHECK_SIZEOF(char)
795 AC_CHECK_SIZEOF(short)
796 AC_CHECK_SIZEOF(int)
797 AC_CHECK_SIZEOF(long)
798 AC_CHECK_SIZEOF(long long)
799 AC_CHECK_SIZEOF(__int64)
800 AC_CHECK_SIZEOF(void *)
801 AC_CHECK_SIZEOF(time_t)
802 AC_CHECK_SIZEOF(size_t)
804 AC_CHECK_TYPES([uint, u_char, ssize_t])
806 dnl used to include sockaddr_storage, but everybody has that.
807 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
808 [#ifdef HAVE_SYS_TYPES_H
809 #include <sys/types.h>
810 #endif
811 #ifdef HAVE_NETINET_IN_H
812 #include <netinet/in.h>
813 #endif
814 #ifdef HAVE_NETINET_IN6_H
815 #include <netinet/in6.h>
816 #endif
817 #ifdef HAVE_SYS_SOCKET_H
818 #include <sys/socket.h>
819 #endif
820 #ifdef _WIN32
821 #define _WIN32_WINNT 0x0501
822 #define WIN32_LEAN_AND_MEAN
823 #if defined(_MSC_VER) && (_MSC_VER < 1300)
824 #include <winsock.h>
825 #else
826 #include <winsock2.h>
827 #include <ws2tcpip.h>
828 #endif
829 #endif
831 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
832 [#ifdef HAVE_SYS_TYPES_H
833 #include <sys/types.h>
834 #endif
835 #ifdef HAVE_NETINET_IN_H
836 #include <netinet/in.h>
837 #endif
838 #ifdef HAVE_NETINET_IN6_H
839 #include <netinet/in6.h>
840 #endif
841 #ifdef HAVE_SYS_SOCKET_H
842 #include <sys/socket.h>
843 #endif
844 #ifdef _WIN32
845 #define _WIN32_WINNT 0x0501
846 #define WIN32_LEAN_AND_MEAN
847 #if defined(_MSC_VER) && (_MSC_VER < 1300)
848 #include <winsock.h>
849 #else
850 #include <winsock2.h>
851 #include <ws2tcpip.h>
852 #endif
853 #endif
856 AC_CHECK_TYPES([rlim_t], , ,
857 [#ifdef HAVE_SYS_TYPES_H
858 #include <sys/types.h>
859 #endif
860 #ifdef HAVE_SYS_TIME_H
861 #include <sys/time.h>
862 #endif
863 #ifdef HAVE_SYS_RESOURCE_H
864 #include <sys/resource.h>
865 #endif
868 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
869 AC_RUN_IFELSE([AC_LANG_SOURCE([
870 #ifdef HAVE_SYS_TYPES_H
871 #include <sys/types.h>
872 #endif
873 #ifdef HAVE_SYS_TIME_H
874 #include <sys/time.h>
875 #endif
876 #ifdef HAVE_TIME_H
877 #include <time.h>
878 #endif
879 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }])],
880   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
883 if test "$tor_cv_time_t_signed" = cross; then
884   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
887 if test "$tor_cv_time_t_signed" != no; then
888   AC_DEFINE([TIME_T_IS_SIGNED], 1,
889             [Define to 1 iff time_t is signed])
892 AC_CACHE_CHECK([whether size_t is signed], tor_cv_size_t_signed, [
893 AC_RUN_IFELSE([AC_LANG_SOURCE([
894 #ifdef HAVE_SYS_TYPES_H
895 #include <sys/types.h>
896 #endif
897 int main(int c, char**v) { if (((size_t)-1)<0) return 1; else return 0; }])],
898   tor_cv_size_t_signed=no, tor_cv_size_t_signed=yes, tor_cv_size_t_signed=cross)
901 if test "$tor_cv_size_t_signed" = cross; then
902   AC_MSG_NOTICE([Cross compiling: assuming that size_t is not signed.])
905 if test "$tor_cv_size_t_signed" = yes; then
906   AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
909 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
910 #ifdef HAVE_SYS_SOCKET_H
911 #include <sys/socket.h>
912 #endif
915 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
917 AC_CHECK_SIZEOF(cell_t)
919 # Now make sure that NULL can be represented as zero bytes.
920 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
921 [AC_RUN_IFELSE([AC_LANG_SOURCE(
922 [[#include <stdlib.h>
923 #include <string.h>
924 #include <stdio.h>
925 #ifdef HAVE_STDDEF_H
926 #include <stddef.h>
927 #endif
928 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
929 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
930        [tor_cv_null_is_zero=yes],
931        [tor_cv_null_is_zero=no],
932        [tor_cv_null_is_zero=cross])])
934 if test "$tor_cv_null_is_zero" = cross ; then
935   # Cross-compiling; let's hope that the target isn't raving mad.
936   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
939 if test "$tor_cv_null_is_zero" != no; then
940   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
941             [Define to 1 iff memset(0) sets pointers to NULL])
944 # And what happens when we malloc zero?
945 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
946 [AC_RUN_IFELSE([AC_LANG_SOURCE(
947 [[#include <stdlib.h>
948 #include <string.h>
949 #include <stdio.h>
950 #ifdef HAVE_STDDEF_H
951 #include <stddef.h>
952 #endif
953 int main () { return malloc(0)?0:1; }]])],
954        [tor_cv_malloc_zero_works=yes],
955        [tor_cv_malloc_zero_works=no],
956        [tor_cv_malloc_zero_works=cross])])
958 if test "$tor_cv_malloc_zero_works" = cross; then
959   # Cross-compiling; let's hope that the target isn't raving mad.
960   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
963 if test "$tor_cv_malloc_zero_works" = yes; then
964   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
965             [Define to 1 iff malloc(0) returns a pointer])
968 # whether we seem to be in a 2s-complement world.
969 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
970 [AC_RUN_IFELSE([AC_LANG_SOURCE(
971 [[int main () { int problem = ((-99) != (~99)+1);
972 return problem ? 1 : 0; }]])],
973        [tor_cv_twos_complement=yes],
974        [tor_cv_twos_complement=no],
975        [tor_cv_twos_complement=cross])])
977 if test "$tor_cv_twos_complement" = cross ; then
978   # Cross-compiling; let's hope that the target isn't raving mad.
979   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
982 if test "$tor_cv_twos_complement" != no ; then
983   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
984             [Define to 1 iff we represent negative integers with two's complement])
987 # What does shifting a negative value do?
988 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
989 [AC_RUN_IFELSE([AC_LANG_SOURCE(
990 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
991        [tor_cv_sign_extend=yes],
992        [tor_cv_sign_extend=no],
993        [tor_cv_sign_extend=cross])])
995 if test "$tor_cv_sign_extend" = cross ; then
996   # Cross-compiling; let's hope that the target isn't raving mad.
997   AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1000 if test "$tor_cv_sign_extend" != no ; then
1001   AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1002             [Define to 1 iff right-shifting a negative value performs sign-extension])
1005 # Whether we should use the dmalloc memory allocation debugging library.
1006 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1007 AC_ARG_WITH(dmalloc,
1008 [  --with-dmalloc          Use debug memory allocation library. ],
1009 [if [[ "$withval" = "yes" ]]; then
1010   dmalloc=1
1011   AC_MSG_RESULT(yes)
1012 else
1013   dmalloc=1
1014   AC_MSG_RESULT(no)
1015 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1018 if [[ $dmalloc -eq 1 ]]; then
1019   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1020   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1021   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1022   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
1023   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1026 AC_ARG_WITH(tcmalloc,
1027 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
1028 [ tcmalloc=yes ], [ tcmalloc=no ])
1030 if test x$tcmalloc = xyes ; then
1031    LDFLAGS="-ltcmalloc $LDFLAGS"
1034 # By default, we're going to assume we don't have mlockall()
1035 # bionic and other platforms have various broken mlockall subsystems.
1036 # Some systems don't have a working mlockall, some aren't linkable,
1037 # and some have it but don't declare it.
1038 AC_CHECK_FUNCS(mlockall)
1039 AC_CHECK_DECLS([mlockall], , , [
1040 #ifdef HAVE_SYS_MMAN_H
1041 #include <sys/mman.h>
1042 #endif])
1044 # Allow user to specify an alternate syslog facility
1045 AC_ARG_WITH(syslog-facility,
1046 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
1047 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1048 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1049 AC_SUBST(LOGFACILITY)
1051 # Check if we have getresuid and getresgid
1052 AC_CHECK_FUNCS(getresuid getresgid)
1054 # Check for gethostbyname_r in all its glorious incompatible versions.
1055 #   (This logic is based on that in Python's configure.in)
1056 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1057   [Define this if you have any gethostbyname_r()])
1059 AC_CHECK_FUNC(gethostbyname_r, [
1060   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1061   OLD_CFLAGS=$CFLAGS
1062   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1063   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1064 #include <netdb.h>
1065   ], [[
1066     char *cp1, *cp2;
1067     struct hostent *h1, *h2;
1068     int i1, i2;
1069     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1070   ]])],[
1071     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1072     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1073      [Define this if gethostbyname_r takes 6 arguments])
1074     AC_MSG_RESULT(6)
1075   ], [
1076     AC_TRY_COMPILE([
1077 #include <netdb.h>
1078     ], [
1079       char *cp1, *cp2;
1080       struct hostent *h1;
1081       int i1, i2;
1082       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1083     ], [
1084       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1085       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1086         [Define this if gethostbyname_r takes 5 arguments])
1087       AC_MSG_RESULT(5)
1088    ], [
1089       AC_TRY_COMPILE([
1090 #include <netdb.h>
1091      ], [
1092        char *cp1;
1093        struct hostent *h1;
1094        struct hostent_data hd;
1095        (void) gethostbyname_r(cp1,h1,&hd);
1096      ], [
1097        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1098        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1099          [Define this if gethostbyname_r takes 3 arguments])
1100        AC_MSG_RESULT(3)
1101      ], [
1102        AC_MSG_RESULT(0)
1103      ])
1104   ])
1105  ])
1106  CFLAGS=$OLD_CFLAGS
1109 AC_CACHE_CHECK([whether the C compiler supports __func__],
1110   tor_cv_have_func_macro,
1111   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1112 #include <stdio.h>
1113 int main(int c, char **v) { puts(__func__); }])],
1114   tor_cv_have_func_macro=yes,
1115   tor_cv_have_func_macro=no))
1117 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1118   tor_cv_have_FUNC_macro,
1119   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1120 #include <stdio.h>
1121 int main(int c, char **v) { puts(__FUNC__); }])],
1122   tor_cv_have_FUNC_macro=yes,
1123   tor_cv_have_FUNC_macro=no))
1125 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1126   tor_cv_have_FUNCTION_macro,
1127   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1128 #include <stdio.h>
1129 int main(int c, char **v) { puts(__FUNCTION__); }])],
1130   tor_cv_have_FUNCTION_macro=yes,
1131   tor_cv_have_FUNCTION_macro=no))
1133 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1134   tor_cv_have_environ_declared,
1135   AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1136 /* We define _GNU_SOURCE here because it is also defined in compat.c.
1137  * Without it environ doesn't get declared. */
1138 #define _GNU_SOURCE
1139 #ifdef HAVE_UNISTD_H
1140 #include <unistd.h>
1141 #endif
1142 #include <stdlib.h>
1143 int main(int c, char **v) { char **t = environ; }])],
1144   tor_cv_have_environ_declared=yes,
1145   tor_cv_have_environ_declared=no))
1147 if test "$tor_cv_have_func_macro" = 'yes'; then
1148   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1151 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
1152   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1155 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
1156   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
1157            [Defined if the compiler supports __FUNCTION__])
1160 if test "$tor_cv_have_environ_declared" = 'yes'; then
1161   AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
1162            [Defined if we have extern char **environ already declared])
1165 # $prefix stores the value of the --prefix command line option, or
1166 # NONE if the option wasn't set.  In the case that it wasn't set, make
1167 # it be the default, so that we can use it to expand directories now.
1168 if test "x$prefix" = "xNONE"; then
1169   prefix=$ac_default_prefix
1172 # and similarly for $exec_prefix
1173 if test "x$exec_prefix" = "xNONE"; then
1174   exec_prefix=$prefix
1177 if test "x$BUILDDIR" = "x"; then
1178   BUILDDIR=`pwd`
1180 AC_SUBST(BUILDDIR)
1181 AH_TEMPLATE([BUILDDIR],[tor's build directory])
1182 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
1184 if test "x$CONFDIR" = "x"; then
1185   CONFDIR=`eval echo $sysconfdir/tor`
1187 AC_SUBST(CONFDIR)
1188 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
1189 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
1191 BINDIR=`eval echo $bindir`
1192 AC_SUBST(BINDIR)
1193 LOCALSTATEDIR=`eval echo $localstatedir`
1194 AC_SUBST(LOCALSTATEDIR)
1196 if test "$bwin32" = true; then
1197   # Test if the linker supports the --nxcompat and --dynamicbase options
1198   # for Windows
1199   save_LDFLAGS="$LDFLAGS"
1200   LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
1201   AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
1202   AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
1203     [AC_MSG_RESULT([yes])]
1204     [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
1205     [AC_MSG_RESULT([no])]
1206   )
1207   LDFLAGS="$save_LDFLAGS"
1210 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
1211 # than autoconf's macros like.
1212 if test "$GCC" = yes; then
1213   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
1214   # accident waiting to happen.
1215   CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
1216 else
1217   # Autoconf sets -g -O2 by default. Override optimization level
1218   # for non-gcc compilers
1219   CFLAGS="$CFLAGS -O"
1220   enable_gcc_warnings=no
1221   enable_gcc_warnings_advisory=no
1224 # OS X Lion started deprecating the system openssl. Let's just disable
1225 # all deprecation warnings on OS X. Also, to potentially make the binary
1226 # a little smaller, let's enable dead_strip.
1227 case "$host_os" in
1229  darwin*)
1230     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
1231     LDFLAGS="$LDFLAGS -dead_strip" ;;
1232 esac
1234 # Add some more warnings which we use in development but not in the
1235 # released versions.  (Some relevant gcc versions can't handle these.)
1236 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
1238   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1239 #if !defined(__GNUC__) || (__GNUC__ < 4)
1240 #error
1241 #endif])], have_gcc4=yes, have_gcc4=no)
1243   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1244 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
1245 #error
1246 #endif])], have_gcc42=yes, have_gcc42=no)
1248   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1249 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
1250 #error
1251 #endif])], have_gcc43=yes, have_gcc43=no)
1253   save_CFLAGS="$CFLAGS"
1254   CFLAGS="$CFLAGS -Wshorten-64-to-32"
1255   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
1256                     have_shorten64_flag=no)
1257   CFLAGS="$save_CFLAGS"
1259   case $host in
1260     *-*-openbsd*)
1261       # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
1262       # That's fine, except that the headers don't pass -Wredundant-decls.
1263       # Therefore, let's disable -Wsystem-headers when we're building
1264       # with maximal warnings on OpenBSD.
1265       CFLAGS="$CFLAGS -Wno-system-headers" ;;
1266   esac
1268   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
1269   CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
1270   CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
1271   CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
1272   CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
1274   if test x$enable_gcc_warnings = xyes; then
1275     CFLAGS="$CFLAGS -Werror"
1276   fi
1278   # Disabled, so we can use mallinfo(): -Waggregate-return
1280   if test x$have_gcc4 = xyes ; then
1281     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
1282     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
1283   fi
1285   if test x$have_gcc42 = xyes ; then
1286     # These warnings break gcc 4.0.2 and work on gcc 4.2
1287     # XXXX020 See if any of these work with earlier versions.
1288     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
1290     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
1291   fi
1293   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
1294     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
1295     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
1296   fi
1298   if test x$have_gcc43 = xyes ; then
1299     # These warnings break gcc 4.2 and work on gcc 4.3
1300     # XXXX020 See if any of these work with earlier versions.
1301     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
1302   fi
1304   if test x$have_shorten64_flag = xyes ; then
1305     CFLAGS="$CFLAGS -Wshorten-64-to-32"
1306   fi
1308 ##This will break the world on some 64-bit architectures
1309 # CFLAGS="$CFLAGS -Winline"
1314 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
1316 AC_CONFIG_FILES([
1317         Doxyfile
1318         Makefile
1319         contrib/Makefile
1320         contrib/suse/Makefile
1321         contrib/suse/tor.sh
1322         contrib/tor.logrotate
1323         contrib/tor.sh
1324         contrib/torctl
1325         contrib/torify
1326         doc/Makefile
1327         src/Makefile
1328         src/common/Makefile
1329         src/config/Makefile
1330         src/config/torrc.sample
1331         src/or/Makefile
1332         src/test/Makefile
1333         src/tools/Makefile
1334         src/tools/tor-fw-helper/Makefile
1335         src/win32/Makefile
1336         tor.spec
1339 AC_OUTPUT
1341 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
1342   ./contrib/updateVersions.pl