If configured, write cell statistics to disk periodically.
[tor/rransom.git] / configure.in
blob10b05aeffb9ecc2ef4c47357e309cddeb5f0cc2a
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(buffer-stats,
103      AS_HELP_STRING(--enable-buffer-stats, enable code for relays to collect buffer statistics))
105 if test "$enable_buffer_stats" = "yes"; then
106   AC_DEFINE(ENABLE_BUFFER_STATS, 1, [Defined if we try to collect buffer statistics])
109 AC_ARG_ENABLE(gcc-warnings,
110      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
112 AC_ARG_ENABLE(local-appdata,
113    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
114 if test "$enable_local_appdata" = "yes"; then
115   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
116             [Defined if we default to host local appdata paths on Windows])
119 AC_PROG_CC
120 AC_PROG_CPP
121 AC_PROG_MAKE_SET
122 AC_PROG_RANLIB
123 AC_PROG_SED
125 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
126 AC_PATH_PROG([OPENSSL], [openssl], none)
128 TORUSER=_tor
129 AC_ARG_WITH(tor-user,
130         [  --with-tor-user=NAME    Specify username for tor daemon ],
131         [
132            TORUSER=$withval
133         ]
135 AC_SUBST(TORUSER)
137 TORGROUP=_tor
138 AC_ARG_WITH(tor-group,
139         [  --with-tor-group=NAME   Specify group name for tor daemon ],
140         [
141            TORGROUP=$withval
142         ]
144 AC_SUBST(TORGROUP)
147 dnl If WIN32 is defined and non-zero, we are building for win32
148 AC_MSG_CHECKING([for win32])
149 AC_RUN_IFELSE([
150 int main(int c, char **v) {
151 #ifdef WIN32
152 #if WIN32
153   return 0;
154 #else
155   return 1;
156 #endif
157 #else
158   return 2;
159 #endif
161 bwin32=true; AC_MSG_RESULT([yes]),
162 bwin32=false; AC_MSG_RESULT([no]),
163 bwin32=cross; AC_MSG_RESULT([cross])
166 if test "$bwin32" = cross; then
167 AC_MSG_CHECKING([for win32 (cross)])
168 AC_COMPILE_IFELSE([
169 #ifdef WIN32
170 int main(int c, char **v) {return 0;}
171 #else
172 #error
173 int main(int c, char **v) {return x(y);}
174 #endif
176 bwin32=true; AC_MSG_RESULT([yes]),
177 bwin32=false; AC_MSG_RESULT([no]))
180 if test "$bwin32" = true; then
181 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
183 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
185 dnl Enable C99 when compiling with MIPSpro
186 AC_MSG_CHECKING([for MIPSpro compiler])
187 AC_COMPILE_IFELSE(AC_LANG_PROGRAM(, [
188 #if (defined(__sgi) && defined(_COMPILER_VERSION))
189 #error
190   return x(y);
191 #endif
193 bmipspro=false; AC_MSG_RESULT(no),
194 bmipspro=true; AC_MSG_RESULT(yes))
196 if test "$bmipspro" = true; then
197   CFLAGS="$CFLAGS -c99"
200 AC_C_BIGENDIAN
202 AC_SEARCH_LIBS(socket, [socket])
203 AC_SEARCH_LIBS(gethostbyname, [nsl])
204 AC_SEARCH_LIBS(dlopen, [dl])
205 AC_SEARCH_LIBS(inet_aton, [resolv])
207 if test "$enable_threads" = "yes"; then
208   AC_SEARCH_LIBS(pthread_create, [pthread])
209   AC_SEARCH_LIBS(pthread_detach, [pthread])
212 dnl -------------------------------------------------------------------
213 dnl Check for functions before libevent, since libevent-1.2 apparently
214 dnl exports strlcpy without defining it in a header.
216 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)
218 using_custom_malloc=no
219 if test x$enable_openbsd_malloc = xyes ; then
220    AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function])
221    using_custom_malloc=yes
223 if test x$tcmalloc = xyes ; then
224    using_custom_malloc=yes
226 if test $using_custom_malloc = no ; then
227    AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size)
230 if test "$enable_threads" = "yes"; then
231   AC_CHECK_HEADERS(pthread.h)
232   AC_CHECK_FUNCS(pthread_create)
235 dnl ------------------------------------------------------
236 dnl Where do you live, libevent?  And how do we call you?
238 if test "$bwin32" = true; then
239   TOR_LIB_WS32=-lws2_32
240   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
241   # think it's actually necessary.
242   TOR_LIB_GDI=-lgdi32
243 else
244   TOR_LIB_WS32=
245   TOR_LIB_GDI=
247 AC_SUBST(TOR_LIB_WS32)
248 AC_SUBST(TOR_LIB_GDI)
250 dnl We need to do this before we try our disgusting hack below.
251 AC_CHECK_HEADERS([sys/types.h])
253 dnl This is a disgusting hack so we safely include older libevent headers.
254 AC_CHECK_TYPE(u_int64_t, unsigned long long)
255 AC_CHECK_TYPE(u_int32_t, unsigned long)
256 AC_CHECK_TYPE(u_int16_t, unsigned short)
257 AC_CHECK_TYPE(u_int8_t, unsigned char)
259 tor_libevent_pkg_redhat="libevent"
260 tor_libevent_pkg_debian="libevent-dev"
261 tor_libevent_devpkg_redhat="libevent-devel"
262 tor_libevent_devpkg_debian="libevent-dev"
264 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $TOR_LIB_WS32], [
265 #ifdef WIN32
266 #include <winsock2.h>
267 #endif
268 #include <stdlib.h>
269 #include <sys/time.h>
270 #include <sys/types.h>
271 #include <event.h>], [
272 #ifdef WIN32
273 #include <winsock2.h>
274 #endif
275 void exit(int); void *event_init(void);],
276     [
277 #ifdef WIN32
278 {WSADATA d; WSAStartup(0x101,&d); }
279 #endif
280 event_init(); exit(0);
281 ], [--with-libevent-dir], [/opt/libevent])
283 dnl Now check for particular libevent functions.
284 save_LIBS="$LIBS"
285 save_LDFLAGS="$LDFLAGS"
286 save_CPPFLAGS="$CPPFLAGS"
287 LIBS="-levent $TOR_LIB_WS32 $LIBS"
288 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
289 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
290 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)
291 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
292 [#include <event.h>
295 AC_CHECK_HEADERS(event2/event.h event2/dns.h)
297 LIBS="$save_LIBS"
298 LDFLAGS="$save_LDFLAGS"
299 CPPFLAGS="$save_CPPFLAGS"
301 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
303 dnl ------------------------------------------------------
304 dnl Where do you live, openssl?  And how do we call you?
306 tor_openssl_pkg_redhat="openssl"
307 tor_openssl_pkg_debian="libssl"
308 tor_openssl_devpkg_redhat="openssl-devel"
309 tor_openssl_devpkg_debian="libssl-dev"
311 ALT_openssl_WITHVAL=""
312 AC_ARG_WITH(ssl-dir,
313   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
314   [
315       if test "x$withval" != xno && test "x$withval" != "x" ; then
316          ALT_openssl_WITHVAL="$withval"
317       fi
318   ])
320 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
321     [#include <openssl/rand.h>],
322     [void RAND_add(const void *buf, int num, double entropy);],
323     [RAND_add((void*)0,0,0); exit(0);], [],
324     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
326 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
328 dnl ------------------------------------------------------
329 dnl Where do you live, zlib?  And how do we call you?
331 tor_openssl_pkg_redhat="zlib"
332 tor_openssl_pkg_debian="zlib1g"
333 tor_openssl_devpkg_redhat="zlib-devel"
334 tor_openssl_devpkg_debian="zlib1g-dev"
336 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
337     [#include <zlib.h>],
338     [const char * zlibVersion(void);],
339     [zlibVersion(); exit(0);], [--with-zlib-dir],
340     [/opt/zlib])
342 dnl Make sure to enable support for large off_t if available.
344 AC_SYS_LARGEFILE
346 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.))
348 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)
350 dnl These headers are not essential
352 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)
354 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
355 [#ifdef HAVE_MALLOC_H
356 #include <malloc.h>
357 #endif
358 #ifdef HAVE_MALLOC_MALLOC_H
359 #include <malloc/malloc.h>
360 #endif])
362 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_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 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
370 [#ifdef HAVE_SYS_TYPES_H
371 #include <sys/types.h>
372 #endif
373 #ifdef HAVE_SYS_SOCKET_H
374 #include <sys/socket.h>
375 #endif
376 #ifdef HAVE_NET_IF_H
377 #include <net/if.h>
378 #endif])
379 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
380         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
381 [#ifdef HAVE_SYS_TYPES_H
382 #include <sys/types.h>
383 #endif
384 #ifdef HAVE_SYS_SOCKET_H
385 #include <sys/socket.h>
386 #endif
387 #ifdef HAVE_LIMITS_H
388 #include <limits.h>
389 #endif
390 #ifdef HAVE_LINUX_TYPES_H
391 #include <linux/types.h>
392 #endif
393 #ifdef HAVE_NETINET_IN6_H
394 #include <netinet/in6.h>
395 #endif
396 #ifdef HAVE_NETINET_IN_H
397 #include <netinet/in.h>
398 #endif])
400 if test x$transparent = xtrue ; then
401    transparent_ok=0
402    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
403      transparent_ok=1
404    fi
405    if test x$linux_netfilter_ipv4 = x1 ; then
406      transparent_ok=1
407    fi
408    if test x$transparent_ok = x1 ; then
409      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
410      case $host in
411        *-*-openbsd*)
412          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
413      esac
414    else
415      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
416    fi
419 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
420 [#ifdef HAVE_SYS_TYPES_H
421 #include <sys/types.h>
422 #endif
423 #ifdef HAVE_SYS_TIME_H
424 #include <sys/time.h>
425 #endif])
427 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
428 dnl Watch out.
430 AC_CHECK_SIZEOF(int8_t)
431 AC_CHECK_SIZEOF(int16_t)
432 AC_CHECK_SIZEOF(int32_t)
433 AC_CHECK_SIZEOF(int64_t)
434 AC_CHECK_SIZEOF(uint8_t)
435 AC_CHECK_SIZEOF(uint16_t)
436 AC_CHECK_SIZEOF(uint32_t)
437 AC_CHECK_SIZEOF(uint64_t)
438 AC_CHECK_SIZEOF(intptr_t)
439 AC_CHECK_SIZEOF(uintptr_t)
441 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
443 AC_CHECK_SIZEOF(char)
444 AC_CHECK_SIZEOF(short)
445 AC_CHECK_SIZEOF(int)
446 AC_CHECK_SIZEOF(long)
447 AC_CHECK_SIZEOF(long long)
448 AC_CHECK_SIZEOF(__int64)
449 AC_CHECK_SIZEOF(void *)
450 AC_CHECK_SIZEOF(time_t)
451 AC_CHECK_SIZEOF(size_t)
453 AC_CHECK_TYPES([uint, u_char, ssize_t])
455 dnl used to include sockaddr_storage, but everybody has that.
456 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
457 [#ifdef HAVE_SYS_TYPES_H
458 #include <sys/types.h>
459 #endif
460 #ifdef HAVE_NETINET_IN_H
461 #include <netinet/in.h>
462 #endif
463 #ifdef HAVE_NETINET_IN6_H
464 #include <netinet/in6.h>
465 #endif
466 #ifdef HAVE_SYS_SOCKET_H
467 #include <sys/socket.h>
468 #endif
469 #ifdef MS_WINDOWS
470 #define WIN32_WINNT 0x400
471 #define _WIN32_WINNT 0x400
472 #define WIN32_LEAN_AND_MEAN
473 #if defined(_MSC_VER) && (_MSC_VER < 1300)
474 #include <winsock.h>
475 #else
476 #include <winsock2.h>
477 #include <ws2tcpip.h>
478 #endif
479 #endif
481 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
482 [#ifdef HAVE_SYS_TYPES_H
483 #include <sys/types.h>
484 #endif
485 #ifdef HAVE_NETINET_IN_H
486 #include <netinet/in.h>
487 #endif
488 #ifdef HAVE_NETINET_IN6_H
489 #include <netinet/in6.h>
490 #endif
491 #ifdef HAVE_SYS_SOCKET_H
492 #include <sys/socket.h>
493 #endif
494 #ifdef MS_WINDOWS
495 #define WIN32_WINNT 0x400
496 #define _WIN32_WINNT 0x400
497 #define WIN32_LEAN_AND_MEAN
498 #if defined(_MSC_VER) && (_MSC_VER < 1300)
499 #include <winsock.h>
500 #else
501 #include <winsock2.h>
502 #include <ws2tcpip.h>
503 #endif
504 #endif
507 AC_CHECK_TYPES([rlim_t], , ,
508 [#ifdef HAVE_SYS_TYPES_H
509 #include <sys/types.h>
510 #endif
511 #ifdef HAVE_SYS_TIME_H
512 #include <sys/time.h>
513 #endif
514 #ifdef HAVE_SYS_RESOURCE_H
515 #include <sys/resource.h>
516 #endif
519 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
520 AC_RUN_IFELSE(AC_LANG_SOURCE([
521 #ifdef HAVE_SYS_TYPES_H
522 #include <sys/types.h>
523 #endif
524 #ifdef HAVE_SYS_TIME_H
525 #include <sys/time.h>
526 #endif
527 #ifdef HAVE_TIME_H
528 #include <time.h>
529 #endif
530 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }]),
531   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
534 if test "$tor_cv_time_t_signed" = cross; then
535   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
538 if test "$tor_cv_time_t_signed" != no; then
539   AC_DEFINE([TIME_T_IS_SIGNED], 1,
540             [Define to 1 iff time_t is signed])
543 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
544 #ifdef HAVE_SYS_SOCKET_H
545 #include <sys/socket.h>
546 #endif
549 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
551 AC_CHECK_SIZEOF(cell_t)
553 # Now make sure that NULL can be represented as zero bytes.
554 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
555 [AC_RUN_IFELSE([AC_LANG_SOURCE(
556 [[#include <stdlib.h>
557 #include <string.h>
558 #include <stdio.h>
559 #ifdef HAVE_STDDEF_H
560 #include <stddef.h>
561 #endif
562 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
563 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
564        [tor_cv_null_is_zero=yes],
565        [tor_cv_null_is_zero=no],
566        [tor_cv_null_is_zero=cross])])
568 if test "$tor_cv_null_is_zero" = cross ; then
569   # Cross-compiling; let's hope that the target isn't raving mad.
570   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
573 if test "$tor_cv_null_is_zero" != no; then
574   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
575             [Define to 1 iff memset(0) sets pointers to NULL])
578 # And what happens when we malloc zero?
579 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
580 [AC_RUN_IFELSE([AC_LANG_SOURCE(
581 [[#include <stdlib.h>
582 #include <string.h>
583 #include <stdio.h>
584 #ifdef HAVE_STDDEF_H
585 #include <stddef.h>
586 #endif
587 int main () { return malloc(0)?0:1; }]])],
588        [tor_cv_malloc_zero_works=yes],
589        [tor_cv_malloc_zero_works=no],
590        [tor_cv_malloc_zero_works=cross])])
592 if test "$tor_cv_malloc_zero_works" = cross; then
593   # Cross-compiling; let's hope that the target isn't raving mad.
594   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
597 if test "$tor_cv_malloc_zero_works" = yes; then
598   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
599             [Define to 1 iff malloc(0) returns a pointer])
602 # whether we seem to be in a 2s-complement world.
603 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
604 [AC_RUN_IFELSE([AC_LANG_SOURCE(
605 [[int main () { int problem = ((-99) != (~99)+1);
606 return problem ? 1 : 0; }]])],
607        [tor_cv_twos_complement=yes],
608        [tor_cv_twos_complement=no],
609        [tor_cv_twos_complement=cross])])
611 if test "$tor_cv_twos_complement" = cross ; then
612   # Cross-compiling; let's hope that the target isn't raving mad.
613   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
616 if test "$tor_cv_twos_complement" != no ; then
617   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
618             [Define to 1 iff we represent negative integers with two's complement])
621 # Whether we should use the dmalloc memory allocation debugging library.
622 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
623 AC_ARG_WITH(dmalloc,
624 [  --with-dmalloc          Use debug memory allocation library. ],
625 [if [[ "$withval" = "yes" ]]; then
626   dmalloc=1
627   AC_MSG_RESULT(yes)
628 else
629   dmalloc=1
630   AC_MSG_RESULT(no)
631 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
634 if [[ $dmalloc -eq 1 ]]; then
635   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
636   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
637   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
638   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
639   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
642 AC_ARG_WITH(tcmalloc,
643 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
644 [ tcmalloc=yes ], [ tcmalloc=no ])
646 if test x$tcmalloc = xyes ; then
647    LDFLAGS="-ltcmalloc $LDFLAGS"
650 # Allow user to specify an alternate syslog facility
651 AC_ARG_WITH(syslog-facility,
652 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
653 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
654 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
655 AC_SUBST(LOGFACILITY)
657 # Check if we have getresuid and getresgid
658 AC_CHECK_FUNCS(getresuid getresgid)
660 # Check for gethostbyname_r in all its glorious incompatible versions.
661 #   (This logic is based on that in Python's configure.in)
662 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
663   [Define this if you have any gethostbyname_r()])
665 AC_CHECK_FUNC(gethostbyname_r, [
666   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
667   OLD_CFLAGS=$CFLAGS
668   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
669   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
670 #include <netdb.h>
671   ], [[
672     char *cp1, *cp2;
673     struct hostent *h1, *h2;
674     int i1, i2;
675     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
676   ]]),[
677     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
678     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
679      [Define this if gethostbyname_r takes 6 arguments])
680     AC_MSG_RESULT(6)
681   ], [
682     AC_TRY_COMPILE([
683 #include <netdb.h>
684     ], [
685       char *cp1, *cp2;
686       struct hostent *h1;
687       int i1, i2;
688       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
689     ], [
690       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
691       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
692         [Define this if gethostbyname_r takes 5 arguments])
693       AC_MSG_RESULT(5)
694    ], [
695       AC_TRY_COMPILE([
696 #include <netdb.h>
697      ], [
698        char *cp1;
699        struct hostent *h1;
700        struct hostent_data hd;
701        (void) gethostbyname_r(cp1,h1,&hd);
702      ], [
703        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
704        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
705          [Define this if gethostbyname_r takes 3 arguments])
706        AC_MSG_RESULT(3)
707      ], [
708        AC_MSG_RESULT(0)
709      ])
710   ])
711  ])
712  CFLAGS=$OLD_CFLAGS
715 AC_CACHE_CHECK([whether the C compiler supports __func__],
716   tor_cv_have_func_macro,
717   AC_COMPILE_IFELSE([
718 #include <stdio.h>
719 int main(int c, char **v) { puts(__func__); }],
720   tor_cv_have_func_macro=yes,
721   tor_cv_have_func_macro=no))
723 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
724   tor_cv_have_FUNC_macro,
725   AC_COMPILE_IFELSE([
726 #include <stdio.h>
727 int main(int c, char **v) { puts(__FUNC__); }],
728   tor_cv_have_FUNC_macro=yes,
729   tor_cv_have_FUNC_macro=no))
731 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
732   tor_cv_have_FUNCTION_macro,
733   AC_COMPILE_IFELSE([
734 #include <stdio.h>
735 int main(int c, char **v) { puts(__FUNCTION__); }],
736   tor_cv_have_FUNCTION_macro=yes,
737   tor_cv_have_FUNCTION_macro=no))
739 if test "$tor_cv_have_func_macro" = 'yes'; then
740   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
743 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
744   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
747 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
748   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
749            [Defined if the compiler supports __FUNCTION__])
752 # $prefix stores the value of the --prefix command line option, or
753 # NONE if the option wasn't set.  In the case that it wasn't set, make
754 # it be the default, so that we can use it to expand directories now.
755 if test "x$prefix" = "xNONE"; then
756   prefix=$ac_default_prefix
759 # and similarly for $exec_prefix
760 if test "x$exec_prefix" = "xNONE"; then
761   exec_prefix=$prefix
764 if test "x$CONFDIR" = "x"; then
765   CONFDIR=`eval echo $sysconfdir/tor`
767 AC_SUBST(CONFDIR)
768 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
769 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
771 BINDIR=`eval echo $bindir`
772 AC_SUBST(BINDIR)
773 LOCALSTATEDIR=`eval echo $localstatedir`
774 AC_SUBST(LOCALSTATEDIR)
776 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
777 # than autoconf's macros like.
778 if test "$GCC" = yes; then
779   CFLAGS="$CFLAGS -Wall -g -O2"
780   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
781   # accident waiting to happen.
782   CFLAGS="$CFLAGS -fno-strict-aliasing"
783 else
784   CFLAGS="$CFLAGS -g -O"
785   enable_gcc_warnings=no
788 # Add some more warnings which we use in development but not in the
789 # released versions.  (Some relevant gcc versions can't handle these.)
790 if test x$enable_gcc_warnings = xyes; then
792   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
793 #if !defined(__GNUC__) || (__GNUC__ < 4)
794 #error
795 #endif]), have_gcc4=yes, have_gcc4=no)
797   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
798 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
799 #error
800 #endif]), have_gcc42=yes, have_gcc42=no)
802   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
803 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
804 #error
805 #endif]), have_gcc43=yes, have_gcc43=no)
807   save_CFLAGS="$CFLAGS"
808   CFLAGS="$CFLAGS -Wshorten-64-to-32"
809   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], []), have_shorten64_flag=yes,
810                     have_shorten64_flag=no)
811   CFLAGS="$save_CFLAGS"
813   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"
815   # Disabled, so we can use mallinfo(): -Waggregate-return
817   if test x$have_gcc4 = xyes ; then 
818     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
819     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
820   fi
822   if test x$have_gcc42 = xyes ; then 
823     # These warnings break gcc 4.0.2 and work on gcc 4.2
824     # XXXX020 Use -fstack-protector.
825     # XXXX020 See if any of these work with earlier versions.
826     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=1"
827     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
828   fi
830   if test x$have_gcc43 = xyes ; then 
831     # These warnings break gcc 4.2 and work on gcc 4.3
832     # XXXX020 See if any of these work with earlier versions.
833     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
834   fi
836   if test x$have_shorten64_flag = xyes ; then
837     CFLAGS="$CFLAGS -Wshorten-64-to-32"
838   fi
840 ##This will break the world on some 64-bit architectures
841 # CFLAGS="$CFLAGS -Winline"
846 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
848 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])
849 AC_OUTPUT
851 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
852   ./contrib/updateVersions.pl