avoid calling smartlist_get(..., -1) if we have a consensus but no
[tor.git] / configure.in
blob4cc334de01df182f78066fedbd101d72c78051ec
1 dnl $Id$
2 dnl Copyright (c) 2001-2004, Roger Dingledine
3 dnl Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.2.0.17-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../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(cell-pool,
39      AS_HELP_STRING(--disable-cell-pool, disable pool allocator for cells))
40 AC_ARG_ENABLE(buf-freelists,
41    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
43 if test x$enable_cell_pool != xno; then
44   AC_DEFINE(ENABLE_CELL_POOL, 1,
45             [Defined if we try to use the pool allocator for queued cells])
47 if test x$enable_buf_freelists != xno; then
48   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
49             [Defined if we try to use freelists for buffer RAM chunks])
52 AC_ARG_ENABLE(transparent,
53      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
54      [case "${enableval}" in
55         yes) transparent=true ;;
56         no)  transparent=false ;;
57         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
58       esac], [transparent=true])
60 AC_ARG_ENABLE(threads,
61      AS_HELP_STRING(--disable-threads, disable multi-threading support))
63 if test x$enable_threads = x; then
64    case $host in
65     *-*-solaris* )
66      # Don't try multithreading on solaris -- cpuworkers seem to lock.
67      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
68 cpu workers lock up here, so I will disable threads.])
69      enable_threads="no";;
70     *)
71      enable_threads="yes";;
72    esac
75 if test "$enable_threads" = "yes"; then
76   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
79 case $host in
80    *-*-solaris* )
81      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
82      ;;
83 esac
85 AC_ARG_ENABLE(gcc-warnings,
86      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
88 AC_PROG_CC
89 AC_PROG_CPP
90 AC_PROG_MAKE_SET
91 AC_PROG_RANLIB
93 TORUSER=_tor
94 AC_ARG_WITH(tor-user,
95         [  --with-tor-user=NAME    Specify username for tor daemon ],
96         [
97            TORUSER=$withval
98         ]
100 AC_SUBST(TORUSER)
102 TORGROUP=_tor
103 AC_ARG_WITH(tor-group,
104         [  --with-tor-group=NAME   Specify group name for tor daemon ],
105         [
106            TORGROUP=$withval
107         ]
109 AC_SUBST(TORGROUP)
112 dnl If WIN32 is defined and non-zero, we are building for win32
113 AC_MSG_CHECKING([for win32])
114 AC_RUN_IFELSE([
115 int main(int c, char **v) {
116 #ifdef WIN32
117 #if WIN32
118   return 0;
119 #else
120   return 1;
121 #endif
122 #else
123   return 2;
124 #endif
126 bwin32=true; AC_MSG_RESULT([yes]),
127 bwin32=false; AC_MSG_RESULT([no]),
128 bwin32=cross; AC_MSG_RESULT([cross])
131 if test "$bwin32" = cross; then
132 AC_MSG_CHECKING([for win32 (cross)])
133 AC_COMPILE_IFELSE([
134 #ifdef WIN32
135 int main(int c, char **v) {return 0;}
136 #else
137 #error
138 int main(int c, char **v) {return x(y);}
139 #endif
141 bwin32=true; AC_MSG_RESULT([yes]),
142 bwin32=false; AC_MSG_RESULT([no]))
145 if test "$bwin32" = true; then
146 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
148 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
150 dnl Enable C99 when compiling with MIPSpro
151 AC_MSG_CHECKING([for MIPSpro compiler])
152 AC_COMPILE_IFELSE(AC_LANG_PROGRAM(, [
153 #if (defined(__sgi) && defined(_COMPILER_VERSION))
154 #error
155   return x(y);
156 #endif
158 bmipspro=false; AC_MSG_RESULT(no),
159 bmipspro=true; AC_MSG_RESULT(yes))
161 if test "$bmipspro" = true; then
162   CFLAGS="$CFLAGS -c99"
165 AC_C_BIGENDIAN
167 AC_SEARCH_LIBS(socket, [socket])
168 AC_SEARCH_LIBS(gethostbyname, [nsl])
169 AC_SEARCH_LIBS(dlopen, [dl])
170 AC_SEARCH_LIBS(inet_aton, [resolv])
172 if test "$enable_threads" = "yes"; then
173   AC_SEARCH_LIBS(pthread_create, [pthread])
174   AC_SEARCH_LIBS(pthread_detach, [pthread])
177 dnl -------------------------------------------------------------------
178 dnl Check for functions before libevent, since libevent-1.2 apparently
179 dnl exports strlcpy without defining it in a header.
181 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo malloc_good_size malloc_usable_size)
183 if test "$enable_threads" = "yes"; then
184   AC_CHECK_HEADERS(pthread.h)
185   AC_CHECK_FUNCS(pthread_create)
188 dnl ------------------------------------------------------
189 dnl Where do you live, libevent?  And how do we call you?
191 if test "$bwin32" = true; then
192   TOR_LIB_WS32=-lws2_32
193   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
194   # think it's actually necessary.
195   TOR_LIB_GDI=-lgdi32
196 else
197   TOR_LIB_WS32=
198   TOR_LIB_GDI=
200 AC_SUBST(TOR_LIB_WS32)
201 AC_SUBST(TOR_LIB_GDI)
203 dnl We need to do this before we try our disgusting hack below.
204 AC_CHECK_HEADERS([sys/types.h])
206 dnl This is a disgusting hack so we safely include older libevent headers.
207 AC_CHECK_TYPE(u_int64_t, unsigned long long)
208 AC_CHECK_TYPE(u_int32_t, unsigned long)
209 AC_CHECK_TYPE(u_int16_t, unsigned short)
210 AC_CHECK_TYPE(u_int8_t, unsigned char)
212 tor_libevent_pkg_redhat="libevent"
213 tor_libevent_pkg_debian="libevent-dev"
214 tor_libevent_devpkg_redhat="libevent-devel"
215 tor_libevent_devpkg_debian="libevent-dev"
217 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $TOR_LIB_WS32], [
218 #include <stdlib.h>
219 #include <sys/time.h>
220 #include <sys/types.h>
221 #include <event.h>], [void exit(int); void *event_init(void);],
222     [event_init(); exit(0);], [--with-libevent-dir], [/opt/libevent])
224 dnl Now check for particular libevent functions.
225 save_LIBS="$LIBS"
226 save_LDFLAGS="$LDFLAGS"
227 save_CPPFLAGS="$CPPFLAGS"
228 LIBS="-levent $TOR_LIB_WS32 $LIBS"
229 LDFLAGS="$TOR_LDFLAGS_libevent $LIBS"
230 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
231 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
232 LIBS="$save_LIBS"
233 LDFLAGS="$save_LDFLAGS"
234 CPPFLAGS="$save_CPPFLAGS"
236 dnl ------------------------------------------------------
237 dnl Where do you live, openssl?  And how do we call you?
239 tor_openssl_pkg_redhat="openssl"
240 tor_openssl_pkg_debian="libssl"
241 tor_openssl_devpkg_redhat="openssl-devel"
242 tor_openssl_devpkg_debian="libssl-dev"
244 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
245     [#include <openssl/rand.h>],
246     [void RAND_add(const void *buf, int num, double entropy);],
247     [RAND_add((void*)0,0,0); exit(0);], [--with-ssl-dir],
248     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
250 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
252 dnl ------------------------------------------------------
253 dnl Where do you live, zlib?  And how do we call you?
255 tor_openssl_pkg_redhat="zlib"
256 tor_openssl_pkg_debian="zlib1g"
257 tor_openssl_devpkg_redhat="zlib-devel"
258 tor_openssl_devpkg_debian="zlib1g-dev"
260 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
261     [#include <zlib.h>],
262     [const char * zlibVersion(void);],
263     [zlibVersion(); exit(0);], [--with-zlib-dir],
264     [/opt/zlib])
266 dnl Make sure to enable support for large off_t if available.
268 AC_SYS_LARGEFILE
270 AC_CHECK_HEADERS(unistd.h string.h signal.h ctype.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.))
272 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h sys/un.h)
274 dnl These headers are not essential
276 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 netintet/in.h netinet/in6.h malloc.h sys/syslimits.h malloc/malloc.h)
278 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
279 [#ifdef HAVE_SYS_TYPES_H
280 #include <sys/types.h>
281 #endif
282 #ifdef HAVE_SYS_SOCKET_H
283 #include <sys/socket.h>
284 #endif])
285 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
286 [#ifdef HAVE_SYS_TYPES_H
287 #include <sys/types.h>
288 #endif
289 #ifdef HAVE_SYS_SOCKET_H
290 #include <sys/socket.h>
291 #endif
292 #ifdef HAVE_NET_IF_H
293 #include <net/if.h>
294 #endif])
295 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
296         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
297 [#ifdef HAVE_SYS_TYPES_H
298 #include <sys/types.h>
299 #endif
300 #ifdef HAVE_SYS_SOCKET_H
301 #include <sys/socket.h>
302 #endif])
304 if test x$transparent = xtrue ; then
305    transparent_ok=0
306    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
307      transparent_ok=1
308    fi
309    if test x$linux_netfilter_ipv4 = x1 ; then
310      transparent_ok=1
311    fi
312    if test x$transparent_ok = x1 ; then
313      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
314      case $host in
315        *-*-openbsd*)
316          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
317      esac
318    else
319      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
320    fi
323 AC_FUNC_FSEEKO
325 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
326 [#ifdef HAVE_SYS_TYPES_H
327 #include <sys/types.h>
328 #endif
329 #ifdef HAVE_SYS_TIME_H
330 #include <sys/time.h>
331 #endif])
333 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
334 dnl Watch out.
336 AC_CHECK_SIZEOF(int8_t)
337 AC_CHECK_SIZEOF(int16_t)
338 AC_CHECK_SIZEOF(int32_t)
339 AC_CHECK_SIZEOF(int64_t)
340 AC_CHECK_SIZEOF(uint8_t)
341 AC_CHECK_SIZEOF(uint16_t)
342 AC_CHECK_SIZEOF(uint32_t)
343 AC_CHECK_SIZEOF(uint64_t)
344 AC_CHECK_SIZEOF(intptr_t)
345 AC_CHECK_SIZEOF(uintptr_t)
347 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
349 AC_CHECK_SIZEOF(char)
350 AC_CHECK_SIZEOF(short)
351 AC_CHECK_SIZEOF(int)
352 AC_CHECK_SIZEOF(long)
353 AC_CHECK_SIZEOF(long long)
354 AC_CHECK_SIZEOF(__int64)
355 AC_CHECK_SIZEOF(void *)
356 AC_CHECK_SIZEOF(time_t)
357 AC_CHECK_SIZEOF(size_t)
359 AC_CHECK_TYPES([uint, u_char])
361 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, struct sockaddr_storage, sa_family_t], , ,
362 [#ifdef HAVE_SYS_TYPES_H
363 #include <sys/types.h>
364 #endif
365 #ifdef HAVE_NETINET_IN_H
366 #include <netinet/in.h>
367 #endif
368 #ifdef HAVE_NETINET_IN6_H
369 #include <netinet/in6.h>
370 #endif
371 #ifdef HAVE_SYS_SOCKET_H
372 #include <sys/socket.h>
373 #endif
374 #ifdef MS_WINDOWS
375 #define WIN32_WINNT 0x400
376 #define _WIN32_WINNT 0x400
377 #define WIN32_LEAN_AND_MEAN
378 #if defined(_MSC_VER) && (_MSC_VER < 1300)
379 #include <winsock.h>
380 #else
381 #include <winsock2.h>
382 #include <ws2tcpip.h>
383 #endif
384 #endif
386 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16], , ,
387 [#ifdef HAVE_SYS_TYPES_H
388 #include <sys/types.h>
389 #endif
390 #ifdef HAVE_NETINET_IN_H
391 #include <netinet/in.h>
392 #endif
393 #ifdef HAVE_NETINET_IN6_H
394 #include <netinet/in6.h>
395 #endif
396 #ifdef HAVE_SYS_SOCKET_H
397 #include <sys/socket.h>
398 #endif
399 #ifdef MS_WINDOWS
400 #define WIN32_WINNT 0x400
401 #define _WIN32_WINNT 0x400
402 #define WIN32_LEAN_AND_MEAN
403 #if defined(_MSC_VER) && (_MSC_VER < 1300)
404 #include <winsock.h>
405 #else
406 #include <winsock2.h>
407 #include <ws2tcpip.h>
408 #endif
409 #endif
412 AC_CHECK_TYPES([rlim_t], , ,
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
419 #ifdef HAVE_SYS_RESOURCE_H
420 #include <sys/resource.h>
421 #endif
424 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
425 AC_RUN_IFELSE(AC_LANG_SOURCE([
426 #ifdef HAVE_SYS_TYPES_H
427 #include <sys/types.h>
428 #endif
429 #ifdef HAVE_SYS_TIME_H
430 #include <sys/time.h>
431 #endif
432 #ifdef HAVE_TIME_H
433 #include <time.h>
434 #endif
435 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }]),
436   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
439 if test "$tor_cv_time_t_signed" = cross; then
440   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
443 if test "$tor_cv_time_t_signed" != no; then
444   AC_DEFINE([TIME_T_IS_SIGNED], 1,
445             [Define to 1 iff time_t is signed])
448 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
449 #ifdef HAVE_SYS_SOCKET_H
450 #include <sys/socket.h>
451 #endif
454 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
456 AC_CHECK_SIZEOF(cell_t)
458 # Now make sure that NULL can be represented as zero bytes.
459 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
460 [AC_RUN_IFELSE([AC_LANG_SOURCE(
461 [[#include <stdlib.h>
462 #include <string.h>
463 #include <stdio.h>
464 #ifdef HAVE_STDDEF_H
465 #include <stddef.h>
466 #endif
467 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
468 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
469        [tor_cv_null_is_zero=yes],
470        [tor_cv_null_is_zero=no],
471        [tor_cv_null_is_zero=cross])])
473 if test "$tor_cv_null_is_zero" = cross ; then
474   # Cross-compiling; let's hope that the target isn't raving mad.
475   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
478 if test "$tor_cv_null_is_zero" != no; then
479   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
480             [Define to 1 iff memset(0) sets pointers to NULL])
483 # And what happens when we malloc zero?
484 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
485 [AC_RUN_IFELSE([AC_LANG_SOURCE(
486 [[#include <stdlib.h>
487 #include <string.h>
488 #include <stdio.h>
489 #ifdef HAVE_STDDEF_H
490 #include <stddef.h>
491 #endif
492 int main () { return malloc(0)?0:1; }]])],
493        [tor_cv_malloc_zero_works=yes],
494        [tor_cv_malloc_zero_works=no],
495        [tor_cv_malloc_zero_works=cross])])
497 if test "$tor_cv_malloc_zero_works" = cross; then
498   # Cross-compiling; let's hope that the target isn't raving mad.
499   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
502 if test "$tor_cv_malloc_zero_works" = yes; then
503   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
504             [Define to 1 iff malloc(0) returns a pointer])
507 # whether we seem to be in a 2s-complement world.
508 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
509 [AC_RUN_IFELSE([AC_LANG_SOURCE(
510 [[int main () { int problem = ((-99) != (~99)+1);
511 return problem ? 1 : 0; }]])],
512        [tor_cv_twos_complement=yes],
513        [tor_cv_twos_complement=no],
514        [tor_cv_twos_complement=cross])])
516 if test "$tor_cv_twos_complement" = cross ; then
517   # Cross-compiling; let's hope that the target isn't raving mad.
518   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
521 if test "$tor_cv_twos_complement" != no ; then
522   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
523             [Define to 1 iff we represent negative integers with two's complement])
526 # Whether we should use the dmalloc memory allocation debugging library.
527 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
528 AC_ARG_WITH(dmalloc,
529 [  --with-dmalloc          Use debug memory allocation library. ],
530 [if [[ "$withval" = "yes" ]]; then
531   dmalloc=1
532   AC_MSG_RESULT(yes)
533 else
534   dmalloc=1
535   AC_MSG_RESULT(no)
536 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
539 if [[ $dmalloc -eq 1 ]]; then
540   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
541   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
542   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
543   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
544   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
547 # Allow user to specify an alternate syslog facility
548 AC_ARG_WITH(syslog-facility,
549 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
550 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
551 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
552 AC_SUBST(LOGFACILITY)
554 # Check for gethostbyname_r in all its glorious incompatible versions.
555 #   (This logic is based on that in Python's configure.in)
556 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
557   [Define this if you have any gethostbyname_r()])
559 AC_CHECK_FUNC(gethostbyname_r, [
560   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
561   OLD_CFLAGS=$CFLAGS
562   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
563   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
564 #include <netdb.h>
565   ], [[
566     char *cp1, *cp2;
567     struct hostent *h1, *h2;
568     int i1, i2;
569     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
570   ]]),[
571     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
572     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
573      [Define this if gethostbyname_r takes 6 arguments])
574     AC_MSG_RESULT(6)
575   ], [
576     AC_TRY_COMPILE([
577 #include <netdb.h>
578     ], [
579       char *cp1, *cp2;
580       struct hostent *h1;
581       int i1, i2;
582       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
583     ], [
584       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
585       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
586         [Define this if gethostbyname_r takes 5 arguments])
587       AC_MSG_RESULT(5)
588    ], [
589       AC_TRY_COMPILE([
590 #include <netdb.h>
591      ], [
592        char *cp1;
593        struct hostent *h1;
594        struct hostent_data hd;
595        (void) gethostbyname_r(cp1,h1,&hd);
596      ], [
597        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
598        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
599          [Define this if gethostbyname_r takes 3 arguments])
600        AC_MSG_RESULT(3)
601      ], [
602        AC_MSG_RESULT(0)
603      ])
604   ])
605  ])
606  CFLAGS=$OLD_CFLAGS
609 AC_CACHE_CHECK([whether the C compiler supports __func__],
610   tor_cv_have_func_macro,
611   AC_COMPILE_IFELSE([
612 #include <stdio.h>
613 int main(int c, char **v) { puts(__func__); }],
614   tor_cv_have_func_macro=yes,
615   tor_cv_have_func_macro=no))
617 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
618   tor_cv_have_FUNC_macro,
619   AC_COMPILE_IFELSE([
620 #include <stdio.h>
621 int main(int c, char **v) { puts(__FUNC__); }],
622   tor_cv_have_FUNC_macro=yes,
623   tor_cv_have_FUNC_macro=no))
625 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
626   tor_cv_have_FUNCTION_macro,
627   AC_COMPILE_IFELSE([
628 #include <stdio.h>
629 int main(int c, char **v) { puts(__FUNCTION__); }],
630   tor_cv_have_FUNCTION_macro=yes,
631   tor_cv_have_FUNCTION_macro=no))
633 if test "$tor_cv_have_func_macro" = 'yes'; then
634   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
637 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
638   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
641 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
642   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
643            [Defined if the compiler supports __FUNCTION__])
646 # $prefix stores the value of the --prefix command line option, or
647 # NONE if the option wasn't set.  In the case that it wasn't set, make
648 # it be the default, so that we can use it to expand directories now.
649 if test "x$prefix" = "xNONE"; then
650   prefix=$ac_default_prefix
653 # and similarly for $exec_prefix
654 if test "x$exec_prefix" = "xNONE"; then
655   exec_prefix=$prefix
658 if test "x$CONFDIR" = "x"; then
659   CONFDIR=`eval echo $sysconfdir/tor`
661 AC_SUBST(CONFDIR)
662 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
663 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
665 BINDIR=`eval echo $bindir`
666 AC_SUBST(BINDIR)
667 LOCALSTATEDIR=`eval echo $localstatedir`
668 AC_SUBST(LOCALSTATEDIR)
670 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
671 # than autoconf's macros like.
672 if test "$ac_cv_c_compiler_gnu" = yes; then
673   CFLAGS="$CFLAGS -Wall -g -O2"
674 else
675   CFLAGS="$CFLAGS -g -O"
676   enable_gcc_warnings=no
679 # Add some more warnings which we use in development but not in the
680 # released versions.  (Some relevant gcc versions can't handle these.)
681 if test x$enable_gcc_warnings = xyes; then
683   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
684 #if !defined(__GNUC__) || (__GNUC__ < 4)
685 #error
686 #endif]), have_gcc4=yes, have_gcc4=no)
688   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
689 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
690 #error
691 #endif]), have_gcc42=yes, have_gcc42=no)
693   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"
694   # Disabled, so we can use mallinfo(): -Waggregate-return
696   if test x$have_gcc4 = xyes ; then 
697     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
698     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
699   fi
701   if test x$have_gcc42 = xyes ; then 
702     # These warnings break gcc 4.0.2 and work on gcc 4.2
703     # XXXX020 Use -fstack-protector.
704     # XXXX020 See if any of these work with earlier versions.
705     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=5"
706   fi
708 ##This will break the world on some 64-bit architectures
709 # CFLAGS="$CFLAGS -Winline"
713 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
715 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])
716 AC_OUTPUT
718 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
719   ./contrib/updateVersions.pl