Estimate v2 and v3 shares as mean values over measurement interval.
[tor/rransom.git] / configure.in
blob844211588da431994d6dcacd894a716253dbb6e3
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2008, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.2.2.0-alpha-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 AC_ARG_ENABLE(debug,
23  AS_HELP_STRING(--enable-debug, compile with debugging info),
24 [if test x$enableval = xyes; then
25     CFLAGS="$CFLAGS -g"
26 fi])
28 #XXXX ideally, we should make this into a no-op, and detect whether we're
29 #compiling for the iphone by using $target.
30 AC_ARG_ENABLE(iphone,
31  AS_HELP_STRING(--enable-iphone, compile with iPhone support),
32  [if test x$enableval = xyes ; then
33    tor_cv_iphone=true
34    CFLAGS="$CFLAGS -D__DARWIN_UNIX03 -DIPHONE"
35   fi])
37 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
38 AC_ARG_ENABLE(buf-freelists,
39    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
40 AC_ARG_ENABLE(openbsd-malloc,
41    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
42 AC_ARG_ENABLE(instrument-downloads,
43    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
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(threads,
64      AS_HELP_STRING(--disable-threads, disable multi-threading support))
66 if test x$enable_threads = x; then
67    case $host in
68     *-*-solaris* )
69      # Don't try multithreading on solaris -- cpuworkers seem to lock.
70      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
71 cpu workers lock up here, so I will disable threads.])
72      enable_threads="no";;
73     *)
74      enable_threads="yes";;
75    esac
78 if test "$enable_threads" = "yes"; then
79   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
82 case $host in
83    *-*-solaris* )
84      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
85      ;;
86 esac
88 AC_ARG_ENABLE(exit-stats,
89      AS_HELP_STRING(--enable-exit-stats, enable code for exits to collect per-port statistics))
91 if test "$enable_exit_stats" = "yes"; then
92   AC_DEFINE(ENABLE_EXIT_STATS, 1, [Defined if we try to collect per-port statistics on exits])
95 AC_ARG_ENABLE(geoip-stats,
96      AS_HELP_STRING(--enable-geoip-stats, enable code for directories to collect per-country statistics))
98 if test "$enable_geoip_stats" = "yes"; then
99   AC_DEFINE(ENABLE_GEOIP_STATS, 1, [Defined if we try to collect per-country statistics])
102 AC_ARG_ENABLE(gcc-warnings,
103      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
105 AC_ARG_ENABLE(local-appdata,
106    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
107 if test "$enable_local_appdata" = "yes"; then
108   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
109             [Defined if we default to host local appdata paths on Windows])
112 AC_PROG_CC
113 AC_PROG_CPP
114 AC_PROG_MAKE_SET
115 AC_PROG_RANLIB
116 AC_PROG_SED
118 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
119 AC_PATH_PROG([OPENSSL], [openssl], none)
121 TORUSER=_tor
122 AC_ARG_WITH(tor-user,
123         [  --with-tor-user=NAME    Specify username for tor daemon ],
124         [
125            TORUSER=$withval
126         ]
128 AC_SUBST(TORUSER)
130 TORGROUP=_tor
131 AC_ARG_WITH(tor-group,
132         [  --with-tor-group=NAME   Specify group name for tor daemon ],
133         [
134            TORGROUP=$withval
135         ]
137 AC_SUBST(TORGROUP)
140 dnl If WIN32 is defined and non-zero, we are building for win32
141 AC_MSG_CHECKING([for win32])
142 AC_RUN_IFELSE([
143 int main(int c, char **v) {
144 #ifdef WIN32
145 #if WIN32
146   return 0;
147 #else
148   return 1;
149 #endif
150 #else
151   return 2;
152 #endif
154 bwin32=true; AC_MSG_RESULT([yes]),
155 bwin32=false; AC_MSG_RESULT([no]),
156 bwin32=cross; AC_MSG_RESULT([cross])
159 if test "$bwin32" = cross; then
160 AC_MSG_CHECKING([for win32 (cross)])
161 AC_COMPILE_IFELSE([
162 #ifdef WIN32
163 int main(int c, char **v) {return 0;}
164 #else
165 #error
166 int main(int c, char **v) {return x(y);}
167 #endif
169 bwin32=true; AC_MSG_RESULT([yes]),
170 bwin32=false; AC_MSG_RESULT([no]))
173 if test "$bwin32" = true; then
174 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
176 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
178 dnl Enable C99 when compiling with MIPSpro
179 AC_MSG_CHECKING([for MIPSpro compiler])
180 AC_COMPILE_IFELSE(AC_LANG_PROGRAM(, [
181 #if (defined(__sgi) && defined(_COMPILER_VERSION))
182 #error
183   return x(y);
184 #endif
186 bmipspro=false; AC_MSG_RESULT(no),
187 bmipspro=true; AC_MSG_RESULT(yes))
189 if test "$bmipspro" = true; then
190   CFLAGS="$CFLAGS -c99"
193 AC_C_BIGENDIAN
195 AC_SEARCH_LIBS(socket, [socket])
196 AC_SEARCH_LIBS(gethostbyname, [nsl])
197 AC_SEARCH_LIBS(dlopen, [dl])
198 AC_SEARCH_LIBS(inet_aton, [resolv])
200 if test "$enable_threads" = "yes"; then
201   AC_SEARCH_LIBS(pthread_create, [pthread])
202   AC_SEARCH_LIBS(pthread_detach, [pthread])
205 dnl -------------------------------------------------------------------
206 dnl Check for functions before libevent, since libevent-1.2 apparently
207 dnl exports strlcpy without defining it in a header.
209 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull getaddrinfo localtime_r gmtime_r memmem strtok_r writev readv flock prctl)
211 using_custom_malloc=no
212 if test x$enable_openbsd_malloc = xyes ; then
213    AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function])
214    using_custom_malloc=yes
216 if test x$tcmalloc = xyes ; then
217    using_custom_malloc=yes
219 if test $using_custom_malloc = no ; then
220    AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size)
223 if test "$enable_threads" = "yes"; then
224   AC_CHECK_HEADERS(pthread.h)
225   AC_CHECK_FUNCS(pthread_create)
228 dnl ------------------------------------------------------
229 dnl Where do you live, libevent?  And how do we call you?
231 if test "$bwin32" = true; then
232   TOR_LIB_WS32=-lws2_32
233   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
234   # think it's actually necessary.
235   TOR_LIB_GDI=-lgdi32
236 else
237   TOR_LIB_WS32=
238   TOR_LIB_GDI=
240 AC_SUBST(TOR_LIB_WS32)
241 AC_SUBST(TOR_LIB_GDI)
243 dnl We need to do this before we try our disgusting hack below.
244 AC_CHECK_HEADERS([sys/types.h])
246 dnl This is a disgusting hack so we safely include older libevent headers.
247 AC_CHECK_TYPE(u_int64_t, unsigned long long)
248 AC_CHECK_TYPE(u_int32_t, unsigned long)
249 AC_CHECK_TYPE(u_int16_t, unsigned short)
250 AC_CHECK_TYPE(u_int8_t, unsigned char)
252 tor_libevent_pkg_redhat="libevent"
253 tor_libevent_pkg_debian="libevent-dev"
254 tor_libevent_devpkg_redhat="libevent-devel"
255 tor_libevent_devpkg_debian="libevent-dev"
257 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $TOR_LIB_WS32], [
258 #ifdef WIN32
259 #include <winsock2.h>
260 #endif
261 #include <stdlib.h>
262 #include <sys/time.h>
263 #include <sys/types.h>
264 #include <event.h>], [
265 #ifdef WIN32
266 #include <winsock2.h>
267 #endif
268 void exit(int); void *event_init(void);],
269     [
270 #ifdef WIN32
271 {WSADATA d; WSAStartup(0x101,&d); }
272 #endif
273 event_init(); exit(0);
274 ], [--with-libevent-dir], [/opt/libevent])
276 dnl Now check for particular libevent functions.
277 save_LIBS="$LIBS"
278 save_LDFLAGS="$LDFLAGS"
279 save_CPPFLAGS="$CPPFLAGS"
280 LIBS="-levent $TOR_LIB_WS32 $LIBS"
281 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
282 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
283 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)
284 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
285 [#include <event.h>
288 AC_CHECK_HEADERS(event2/event.h event2/dns.h)
290 LIBS="$save_LIBS"
291 LDFLAGS="$save_LDFLAGS"
292 CPPFLAGS="$save_CPPFLAGS"
294 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
296 dnl ------------------------------------------------------
297 dnl Where do you live, openssl?  And how do we call you?
299 tor_openssl_pkg_redhat="openssl"
300 tor_openssl_pkg_debian="libssl"
301 tor_openssl_devpkg_redhat="openssl-devel"
302 tor_openssl_devpkg_debian="libssl-dev"
304 ALT_openssl_WITHVAL=""
305 AC_ARG_WITH(ssl-dir,
306   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
307   [
308       if test "x$withval" != xno && test "x$withval" != "x" ; then
309          ALT_openssl_WITHVAL="$withval"
310       fi
311   ])
313 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
314     [#include <openssl/rand.h>],
315     [void RAND_add(const void *buf, int num, double entropy);],
316     [RAND_add((void*)0,0,0); exit(0);], [],
317     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
319 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
321 dnl ------------------------------------------------------
322 dnl Where do you live, zlib?  And how do we call you?
324 tor_openssl_pkg_redhat="zlib"
325 tor_openssl_pkg_debian="zlib1g"
326 tor_openssl_devpkg_redhat="zlib-devel"
327 tor_openssl_devpkg_debian="zlib1g-dev"
329 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
330     [#include <zlib.h>],
331     [const char * zlibVersion(void);],
332     [zlibVersion(); exit(0);], [--with-zlib-dir],
333     [/opt/zlib])
335 dnl Make sure to enable support for large off_t if available.
337 AC_SYS_LARGEFILE
339 AC_CHECK_HEADERS(unistd.h string.h signal.h sys/stat.h sys/types.h fcntl.h sys/fcntl.h sys/time.h errno.h assert.h time.h, , 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.))
341 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h sys/un.h sys/uio.h)
343 dnl These headers are not essential
345 AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netinet/in6.h malloc.h sys/syslimits.h malloc/malloc.h linux/types.h sys/file.h malloc_np.h sys/prctl.h)
347 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
348 [#ifdef HAVE_MALLOC_H
349 #include <malloc.h>
350 #endif
351 #ifdef HAVE_MALLOC_MALLOC_H
352 #include <malloc/malloc.h>
353 #endif])
355 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
356 [#ifdef HAVE_SYS_TYPES_H
357 #include <sys/types.h>
358 #endif
359 #ifdef HAVE_SYS_SOCKET_H
360 #include <sys/socket.h>
361 #endif])
362 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
363 [#ifdef HAVE_SYS_TYPES_H
364 #include <sys/types.h>
365 #endif
366 #ifdef HAVE_SYS_SOCKET_H
367 #include <sys/socket.h>
368 #endif
369 #ifdef HAVE_NET_IF_H
370 #include <net/if.h>
371 #endif])
372 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
373         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
374 [#ifdef HAVE_SYS_TYPES_H
375 #include <sys/types.h>
376 #endif
377 #ifdef HAVE_SYS_SOCKET_H
378 #include <sys/socket.h>
379 #endif
380 #ifdef HAVE_LIMITS_H
381 #include <limits.h>
382 #endif
383 #ifdef HAVE_LINUX_TYPES_H
384 #include <linux/types.h>
385 #endif
386 #ifdef HAVE_NETINET_IN6_H
387 #include <netinet/in6.h>
388 #endif
389 #ifdef HAVE_NETINET_IN_H
390 #include <netinet/in.h>
391 #endif])
393 if test x$transparent = xtrue ; then
394    transparent_ok=0
395    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
396      transparent_ok=1
397    fi
398    if test x$linux_netfilter_ipv4 = x1 ; then
399      transparent_ok=1
400    fi
401    if test x$transparent_ok = x1 ; then
402      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
403      case $host in
404        *-*-openbsd*)
405          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
406      esac
407    else
408      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
409    fi
412 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
413 [#ifdef HAVE_SYS_TYPES_H
414 #include <sys/types.h>
415 #endif
416 #ifdef HAVE_SYS_TIME_H
417 #include <sys/time.h>
418 #endif])
420 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
421 dnl Watch out.
423 AC_CHECK_SIZEOF(int8_t)
424 AC_CHECK_SIZEOF(int16_t)
425 AC_CHECK_SIZEOF(int32_t)
426 AC_CHECK_SIZEOF(int64_t)
427 AC_CHECK_SIZEOF(uint8_t)
428 AC_CHECK_SIZEOF(uint16_t)
429 AC_CHECK_SIZEOF(uint32_t)
430 AC_CHECK_SIZEOF(uint64_t)
431 AC_CHECK_SIZEOF(intptr_t)
432 AC_CHECK_SIZEOF(uintptr_t)
434 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
436 AC_CHECK_SIZEOF(char)
437 AC_CHECK_SIZEOF(short)
438 AC_CHECK_SIZEOF(int)
439 AC_CHECK_SIZEOF(long)
440 AC_CHECK_SIZEOF(long long)
441 AC_CHECK_SIZEOF(__int64)
442 AC_CHECK_SIZEOF(void *)
443 AC_CHECK_SIZEOF(time_t)
444 AC_CHECK_SIZEOF(size_t)
446 AC_CHECK_TYPES([uint, u_char, ssize_t])
448 dnl used to include sockaddr_storage, but everybody has that.
449 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
450 [#ifdef HAVE_SYS_TYPES_H
451 #include <sys/types.h>
452 #endif
453 #ifdef HAVE_NETINET_IN_H
454 #include <netinet/in.h>
455 #endif
456 #ifdef HAVE_NETINET_IN6_H
457 #include <netinet/in6.h>
458 #endif
459 #ifdef HAVE_SYS_SOCKET_H
460 #include <sys/socket.h>
461 #endif
462 #ifdef MS_WINDOWS
463 #define WIN32_WINNT 0x400
464 #define _WIN32_WINNT 0x400
465 #define WIN32_LEAN_AND_MEAN
466 #if defined(_MSC_VER) && (_MSC_VER < 1300)
467 #include <winsock.h>
468 #else
469 #include <winsock2.h>
470 #include <ws2tcpip.h>
471 #endif
472 #endif
474 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
475 [#ifdef HAVE_SYS_TYPES_H
476 #include <sys/types.h>
477 #endif
478 #ifdef HAVE_NETINET_IN_H
479 #include <netinet/in.h>
480 #endif
481 #ifdef HAVE_NETINET_IN6_H
482 #include <netinet/in6.h>
483 #endif
484 #ifdef HAVE_SYS_SOCKET_H
485 #include <sys/socket.h>
486 #endif
487 #ifdef MS_WINDOWS
488 #define WIN32_WINNT 0x400
489 #define _WIN32_WINNT 0x400
490 #define WIN32_LEAN_AND_MEAN
491 #if defined(_MSC_VER) && (_MSC_VER < 1300)
492 #include <winsock.h>
493 #else
494 #include <winsock2.h>
495 #include <ws2tcpip.h>
496 #endif
497 #endif
500 AC_CHECK_TYPES([rlim_t], , ,
501 [#ifdef HAVE_SYS_TYPES_H
502 #include <sys/types.h>
503 #endif
504 #ifdef HAVE_SYS_TIME_H
505 #include <sys/time.h>
506 #endif
507 #ifdef HAVE_SYS_RESOURCE_H
508 #include <sys/resource.h>
509 #endif
512 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
513 AC_RUN_IFELSE(AC_LANG_SOURCE([
514 #ifdef HAVE_SYS_TYPES_H
515 #include <sys/types.h>
516 #endif
517 #ifdef HAVE_SYS_TIME_H
518 #include <sys/time.h>
519 #endif
520 #ifdef HAVE_TIME_H
521 #include <time.h>
522 #endif
523 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }]),
524   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
527 if test "$tor_cv_time_t_signed" = cross; then
528   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
531 if test "$tor_cv_time_t_signed" != no; then
532   AC_DEFINE([TIME_T_IS_SIGNED], 1,
533             [Define to 1 iff time_t is signed])
536 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
537 #ifdef HAVE_SYS_SOCKET_H
538 #include <sys/socket.h>
539 #endif
542 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
544 AC_CHECK_SIZEOF(cell_t)
546 # Now make sure that NULL can be represented as zero bytes.
547 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
548 [AC_RUN_IFELSE([AC_LANG_SOURCE(
549 [[#include <stdlib.h>
550 #include <string.h>
551 #include <stdio.h>
552 #ifdef HAVE_STDDEF_H
553 #include <stddef.h>
554 #endif
555 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
556 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
557        [tor_cv_null_is_zero=yes],
558        [tor_cv_null_is_zero=no],
559        [tor_cv_null_is_zero=cross])])
561 if test "$tor_cv_null_is_zero" = cross ; then
562   # Cross-compiling; let's hope that the target isn't raving mad.
563   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
566 if test "$tor_cv_null_is_zero" != no; then
567   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
568             [Define to 1 iff memset(0) sets pointers to NULL])
571 # And what happens when we malloc zero?
572 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
573 [AC_RUN_IFELSE([AC_LANG_SOURCE(
574 [[#include <stdlib.h>
575 #include <string.h>
576 #include <stdio.h>
577 #ifdef HAVE_STDDEF_H
578 #include <stddef.h>
579 #endif
580 int main () { return malloc(0)?0:1; }]])],
581        [tor_cv_malloc_zero_works=yes],
582        [tor_cv_malloc_zero_works=no],
583        [tor_cv_malloc_zero_works=cross])])
585 if test "$tor_cv_malloc_zero_works" = cross; then
586   # Cross-compiling; let's hope that the target isn't raving mad.
587   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
590 if test "$tor_cv_malloc_zero_works" = yes; then
591   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
592             [Define to 1 iff malloc(0) returns a pointer])
595 # whether we seem to be in a 2s-complement world.
596 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
597 [AC_RUN_IFELSE([AC_LANG_SOURCE(
598 [[int main () { int problem = ((-99) != (~99)+1);
599 return problem ? 1 : 0; }]])],
600        [tor_cv_twos_complement=yes],
601        [tor_cv_twos_complement=no],
602        [tor_cv_twos_complement=cross])])
604 if test "$tor_cv_twos_complement" = cross ; then
605   # Cross-compiling; let's hope that the target isn't raving mad.
606   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
609 if test "$tor_cv_twos_complement" != no ; then
610   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
611             [Define to 1 iff we represent negative integers with two's complement])
614 # Whether we should use the dmalloc memory allocation debugging library.
615 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
616 AC_ARG_WITH(dmalloc,
617 [  --with-dmalloc          Use debug memory allocation library. ],
618 [if [[ "$withval" = "yes" ]]; then
619   dmalloc=1
620   AC_MSG_RESULT(yes)
621 else
622   dmalloc=1
623   AC_MSG_RESULT(no)
624 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
627 if [[ $dmalloc -eq 1 ]]; then
628   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
629   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
630   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
631   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
632   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
635 AC_ARG_WITH(tcmalloc,
636 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
637 [ tcmalloc=yes ], [ tcmalloc=no ])
639 if test x$tcmalloc = xyes ; then
640    LDFLAGS="-ltcmalloc $LDFLAGS"
643 # Allow user to specify an alternate syslog facility
644 AC_ARG_WITH(syslog-facility,
645 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
646 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
647 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
648 AC_SUBST(LOGFACILITY)
650 # Check if we have getresuid and getresgid
651 AC_CHECK_FUNCS(getresuid getresgid)
653 # Check for gethostbyname_r in all its glorious incompatible versions.
654 #   (This logic is based on that in Python's configure.in)
655 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
656   [Define this if you have any gethostbyname_r()])
658 AC_CHECK_FUNC(gethostbyname_r, [
659   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
660   OLD_CFLAGS=$CFLAGS
661   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
662   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
663 #include <netdb.h>
664   ], [[
665     char *cp1, *cp2;
666     struct hostent *h1, *h2;
667     int i1, i2;
668     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
669   ]]),[
670     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
671     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
672      [Define this if gethostbyname_r takes 6 arguments])
673     AC_MSG_RESULT(6)
674   ], [
675     AC_TRY_COMPILE([
676 #include <netdb.h>
677     ], [
678       char *cp1, *cp2;
679       struct hostent *h1;
680       int i1, i2;
681       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
682     ], [
683       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
684       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
685         [Define this if gethostbyname_r takes 5 arguments])
686       AC_MSG_RESULT(5)
687    ], [
688       AC_TRY_COMPILE([
689 #include <netdb.h>
690      ], [
691        char *cp1;
692        struct hostent *h1;
693        struct hostent_data hd;
694        (void) gethostbyname_r(cp1,h1,&hd);
695      ], [
696        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
697        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
698          [Define this if gethostbyname_r takes 3 arguments])
699        AC_MSG_RESULT(3)
700      ], [
701        AC_MSG_RESULT(0)
702      ])
703   ])
704  ])
705  CFLAGS=$OLD_CFLAGS
708 AC_CACHE_CHECK([whether the C compiler supports __func__],
709   tor_cv_have_func_macro,
710   AC_COMPILE_IFELSE([
711 #include <stdio.h>
712 int main(int c, char **v) { puts(__func__); }],
713   tor_cv_have_func_macro=yes,
714   tor_cv_have_func_macro=no))
716 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
717   tor_cv_have_FUNC_macro,
718   AC_COMPILE_IFELSE([
719 #include <stdio.h>
720 int main(int c, char **v) { puts(__FUNC__); }],
721   tor_cv_have_FUNC_macro=yes,
722   tor_cv_have_FUNC_macro=no))
724 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
725   tor_cv_have_FUNCTION_macro,
726   AC_COMPILE_IFELSE([
727 #include <stdio.h>
728 int main(int c, char **v) { puts(__FUNCTION__); }],
729   tor_cv_have_FUNCTION_macro=yes,
730   tor_cv_have_FUNCTION_macro=no))
732 if test "$tor_cv_have_func_macro" = 'yes'; then
733   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
736 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
737   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
740 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
741   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
742            [Defined if the compiler supports __FUNCTION__])
745 # $prefix stores the value of the --prefix command line option, or
746 # NONE if the option wasn't set.  In the case that it wasn't set, make
747 # it be the default, so that we can use it to expand directories now.
748 if test "x$prefix" = "xNONE"; then
749   prefix=$ac_default_prefix
752 # and similarly for $exec_prefix
753 if test "x$exec_prefix" = "xNONE"; then
754   exec_prefix=$prefix
757 if test "x$CONFDIR" = "x"; then
758   CONFDIR=`eval echo $sysconfdir/tor`
760 AC_SUBST(CONFDIR)
761 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
762 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
764 BINDIR=`eval echo $bindir`
765 AC_SUBST(BINDIR)
766 LOCALSTATEDIR=`eval echo $localstatedir`
767 AC_SUBST(LOCALSTATEDIR)
769 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
770 # than autoconf's macros like.
771 if test "$GCC" = yes; then
772   CFLAGS="$CFLAGS -Wall -g -O2"
773   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
774   # accident waiting to happen.
775   CFLAGS="$CFLAGS -fno-strict-aliasing"
776 else
777   CFLAGS="$CFLAGS -g -O"
778   enable_gcc_warnings=no
781 # Add some more warnings which we use in development but not in the
782 # released versions.  (Some relevant gcc versions can't handle these.)
783 if test x$enable_gcc_warnings = xyes; then
785   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
786 #if !defined(__GNUC__) || (__GNUC__ < 4)
787 #error
788 #endif]), have_gcc4=yes, have_gcc4=no)
790   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
791 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
792 #error
793 #endif]), have_gcc42=yes, have_gcc42=no)
795   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
796 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
797 #error
798 #endif]), have_gcc43=yes, have_gcc43=no)
800   save_CFLAGS="$CFLAGS"
801   CFLAGS="$CFLAGS -Wshorten-64-to-32"
802   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], []), have_shorten64_flag=yes,
803                     have_shorten64_flag=no)
804   CFLAGS="$save_CFLAGS"
806   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror"
808   # Disabled, so we can use mallinfo(): -Waggregate-return
810   if test x$have_gcc4 = xyes ; then 
811     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
812     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
813   fi
815   if test x$have_gcc42 = xyes ; then 
816     # These warnings break gcc 4.0.2 and work on gcc 4.2
817     # XXXX020 Use -fstack-protector.
818     # XXXX020 See if any of these work with earlier versions.
819     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=1"
820     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
821   fi
823   if test x$have_gcc43 = xyes ; then 
824     # These warnings break gcc 4.2 and work on gcc 4.3
825     # XXXX020 See if any of these work with earlier versions.
826     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
827   fi
829   if test x$have_shorten64_flag = xyes ; then
830     CFLAGS="$CFLAGS -Wshorten-64-to-32"
831   fi
833 ##This will break the world on some 64-bit architectures
834 # CFLAGS="$CFLAGS -Winline"
839 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
841 AC_CONFIG_FILES([Makefile tor.spec Doxyfile contrib/tor.sh contrib/torctl contrib/torify contrib/tor.logrotate contrib/Makefile contrib/osx/Makefile contrib/osx/TorBundleDesc.plist contrib/osx/TorBundleInfo.plist contrib/osx/TorDesc.plist contrib/osx/TorInfo.plist contrib/osx/TorStartupDesc.plist src/config/torrc.sample doc/tor.1 src/Makefile doc/Makefile doc/design-paper/Makefile doc/spec/Makefile src/config/Makefile src/common/Makefile src/or/Makefile src/win32/Makefile src/tools/Makefile contrib/suse/Makefile contrib/suse/tor.sh])
842 AC_OUTPUT
844 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
845   ./contrib/updateVersions.pl