bump stable to 0.1.2.19
[tor.git] / configure.in
blobb7bbd1bf67826d40972b793ef47f9a955c904570
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.1.2.19)
8 AM_CONFIG_HEADER(orconfig.h)
10 AC_CANONICAL_HOST
12 if test -f /etc/redhat-release; then
13     CFLAGS="$CFLAGS -I/usr/kerberos/include"
16 AC_ARG_ENABLE(debug,
17  AC_HELP_STRING(--enable-debug, compile with debugging info),
18 [if test x$enableval = xyes; then
19     CFLAGS="$CFLAGS -g"
20 fi])
22 AC_ARG_ENABLE(eventdns,
23      AC_HELP_STRING(--enable-eventdns, enable asynchronous dns module),
24      [case "${enableval}" in
25         yes) eventdns=true ;;
26         no)  eventdns=false ;;
27         *) AC_MSG_ERROR(bad value for --enable-eventdns) ;;
28       esac], [eventdns=true])
29 AM_CONDITIONAL(EVENTDNS, test x$eventdns = xtrue)
30 if test x$eventdns = xtrue; then
31    AC_DEFINE([USE_EVENTDNS], 1, "Define to 1 if we'll be using eventdns.c")
34 AC_ARG_ENABLE(transparent,
35      AC_HELP_STRING(--disable-transparent, disable transparent proxy support),
36      [case "${enableval}" in
37         yes) transparent=true ;;
38         no)  transparent=false ;;
39         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
40       esac], [transparent=true])
42 AC_ARG_ENABLE(threads,
43      AC_HELP_STRING(--disable-threads, disable multi-threading support))
45 if test x$enable_threads = x; then
46    case $host in
47     *-*-netbsd* | *-*-openbsd* )
48      # Don't try multithreading on netbsd -- there is no threadsafe DNS
49      # lookup function there.
50      if test x$eventdns != xtrue; then
51         AC_MSG_NOTICE([You are running OpenBSD or NetBSD; I am assuming that
52 getaddrinfo is not threadsafe here, so I will disable threads.])
53         enable_threads="no"
54      else
55         # This was an inadvertant default up through 0.1.2.14; in 0.2.0.x,
56         # it's getting some testing, but for now, best leave threads off
57         # unless the user urns them on.
58         AC_MSG_NOTICE([You are running OpenBSD or NetBSD; Tor 0.1.2.x hasn't
59 been tested with threads on these platforms, so I'm turning them off.  You
60 can enable threads by passing --enable-threads to the configure script.])
61         enable_threads="no"
62      fi ;;
63     *-*-solaris* )
64      # Don't try multithreading on solaris -- cpuworkers seem to lock.
65      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
66 cpu workers lock up here, so I will disable threads.])
67      enable_threads="no";;
68     *)
69      enable_threads="yes";;
70    esac
73 if test $enable_threads = "yes"; then
74   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
77 case $host in
78    *-*-solaris* )
79      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
80      ;;
81 esac
83 AC_ARG_ENABLE(gcc-warnings,
84      AC_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
86 AC_PROG_CC
87 AC_PROG_CPP
88 AC_PROG_MAKE_SET
89 AC_PROG_RANLIB
91 # The big search for OpenSSL
92 # copied from openssh's configure.ac
93 tryssldir=""
94 AC_ARG_WITH(ssl-dir,
95         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
96         [
97                 if test "x$withval" != "xno" ; then
98                         tryssldir=$withval
99                 fi
100         ]
103 trylibeventdir=""
104 AC_ARG_WITH(libevent-dir,
105        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
106        [
107                 if test "x$withval" != "xno" ; then
108                         trylibeventdir=$withval
109                 fi
110        ]
113 TORUSER=_tor
114 AC_ARG_WITH(tor-user,
115         [  --with-tor-user=NAME    Specify username for tor daemon ],
116         [
117            TORUSER=$withval
118         ]
120 AC_SUBST(TORUSER)
122 TORGROUP=_tor
123 AC_ARG_WITH(tor-group,
124         [  --with-tor-group=NAME   Specify group name for tor daemon ],
125         [
126            TORGROUP=$withval
127         ]
129 AC_SUBST(TORGROUP)
132 dnl If WIN32 is defined and non-zero, we are building for win32
133 AC_MSG_CHECKING([for win32])
134 AC_RUN_IFELSE([
135 int main(int c, char **v) {
136 #ifdef WIN32
137 #if WIN32
138   return 0;
139 #else
140   return 1;
141 #endif
142 #else
143   return 2;
144 #endif
146 bwin32=true; AC_MSG_RESULT([yes]),
147 bwin32=false; AC_MSG_RESULT([no]),
148 bwin32=cross; AC_MSG_RESULT([cross])
151 if test $bwin32 = cross; then
152 AC_MSG_CHECKING([for win32 (cross)])
153 AC_COMPILE_IFELSE([
154 #ifdef WIN32
155 int main(int c, char **v) {return 0;}
156 #else
157 #error
158 int main(int c, char **v) {return x(y);}
159 #endif
161 bwin32=true; AC_MSG_RESULT([yes]),
162 bwin32=false; AC_MSG_RESULT([no]))
165 if test $bwin32 = true; then
166 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
169 dnl Enable C99 when compiling with MIPSpro
170 AC_MSG_CHECKING([for MIPSpro compiler])
171 AC_TRY_COMPILE([], [
172 #if (defined(__sgi) && defined(_COMPILER_VERSION))
173 #error
174   return x(y);
175 #endif
177 bmipspro=false; AC_MSG_RESULT([no]),
178 bmipspro=true; AC_MSG_RESULT([yes]))
180 if test $bmipspro = true; then
181   CFLAGS="$CFLAGS -c99"
184 AC_SEARCH_LIBS(socket, [socket])
185 AC_SEARCH_LIBS(gethostbyname, [nsl])
186 AC_SEARCH_LIBS(dlopen, [dl])
187 AC_SEARCH_LIBS(inet_aton, [resolv])
189 if test $enable_threads = "yes"; then
190   AC_SEARCH_LIBS(pthread_create, [pthread])
191   AC_SEARCH_LIBS(pthread_detach, [pthread])
194 dnl -------------------------------------------------------------------
195 dnl Check for functions before libevent, since libevent-1.2 apparently
196 dnl exports strlcpy without defining it in a header.
198 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r)
200 if test $enable_threads = "yes"; then
201   AC_CHECK_HEADERS(pthread.h)
202   AC_CHECK_FUNCS(pthread_create)
205 dnl ------------------------------------------------------
206 dnl Where do you live, libevent?  And how do we call you?
208 dnl This needs to happen before the below disgusting hack.
209 AC_CHECK_HEADERS(sys/types.h)
211 dnl This is a disgusting hack so we safely include older libevent headers.
212 AC_CHECK_TYPE(u_int64_t, unsigned long long)
213 AC_CHECK_TYPE(u_int32_t, unsigned long)
214 AC_CHECK_TYPE(u_int16_t, unsigned short)
215 AC_CHECK_TYPE(u_int8_t, unsigned char)
217 AC_CACHE_CHECK([for libevent directory], tor_cv_libevent_dir, [
218   saved_LIBS="$LIBS"
219   saved_LDFLAGS="$LDFLAGS"
220   saved_CPPFLAGS="$CPPFLAGS"
221   le_found=no
222   for ledir in $trylibeventdir "" $prefix /usr/local /usr/pkg ; do
223     LDFLAGS="$saved_LDFLAGS"
225     if test $bwin32 = true; then
226         LIBS="$saved_LIBS -levent -lws2_32"
227     else
228         LIBS="$saved_LIBS -levent"
229     fi
231     # Skip the directory if it isn't there.
232     if test ! -z "$ledir" -a ! -d "$ledir" ; then
233        continue;
234     fi
235     if test ! -z "$ledir" ; then
236       if test -d "$ledir/lib" ; then
237         LDFLAGS="-L$ledir/lib $LDFLAGS"
238       else
239         LDFLAGS="-L$ledir $LDFLAGS"
240       fi
241       if test -d "$ledir/include" ; then
242         CPPFLAGS="-I$ledir/include $CPPFLAGS"
243       else
244         CPPFLAGS="-I$ledir $CPPFLAGS"
245       fi
246     fi
247     # Can I compile and link it?
248     AC_TRY_LINK([#include <sys/time.h>
249 #include <sys/types.h>
250 #include <event.h>], [ event_init(); ],
251        [ libevent_linked=yes ], [ libevent_linked=no ])
252     if test $libevent_linked = yes; then
253        if test ! -z "$ledir" ; then
254          tor_cv_libevent_dir=$ledir
255        else
256          tor_cv_libevent_dir="(system)"
257        fi
258        le_found=yes
259        break
260     fi
261   done
262   LIBS="$saved_LIBS"
263   LDFLAGS="$saved_LDFLAGS"
264   CPPFLAGS="$saved_CPPFLAGS"
265   if test $le_found = no ; then
266     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
267   fi
270 if test $bwin32 = true; then
271 LIBS="$LIBS -levent -lws2_32"
272 else
273 LIBS="$LIBS -levent"
275 if test "$tor_cv_libevent_dir" != "(system)"; then
276   if test -d "$tor_cv_libevent_dir/lib" ; then
277     LDFLAGS="-L$tor_cv_libevent_dir/lib $LDFLAGS"
278     le_libdir="$tor_cv_libevent_dir/lib"
279   else
280     LDFLAGS="-L$tor_cv_libevent_dir $LDFLAGS"
281     le_libdir="$tor_cv_libevent_dir"
282   fi
283   if test -d "$tor_cv_libevent_dir/include" ; then
284     CPPFLAGS="-I$tor_cv_libevent_dir/include $CPPFLAGS"
285   else
286     CPPFLAGS="-I$tor_cv_libevent_dir $CPPFLAGS"
287   fi
290 if test -z "$CROSS_COMPILE"; then
291 AC_CACHE_CHECK([whether we need extra options to link libevent],
292                tor_cv_libevent_linker_option, [
293     saved_LDFLAGS="$LDFLAGS"
294     le_runs=no
295     linked_with=nothing
296     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" "-Wl,-rpath,$le_libdir" ; do
297       LDFLAGS="$le_extra $saved_LDFLAGS"
298       AC_TRY_RUN([void *event_init(void);
299                 int main(int c, char **v) {
300                    event_init(); return 0;
301                 }],
302                 libevent_runs=yes, libevent_runs=no, libevent_runs=cross)
303       if test $libevent_runs != no ; then
304         if test -z "$le_extra" ; then
305           tor_cv_libevent_linker_option='(none)'
306         else
307           tor_cv_libevent_linker_option=$le_extra
308         fi
309         le_runs=yes
310         break
311       fi
312     done
313     if test $le_runs = no ; then
314       AC_MSG_ERROR([Found linkable libevent in $tor_cv_libevent_dir, but it doesn't run, even with -R.  Maybe specify another using --with-libevent-dir?])
315     fi
316     LDFLAGS="$saved_LDFLAGS"
319 if test $tor_cv_libevent_linker_option != '(none)' ; then
320    LDFLAGS="$tor_cv_libevent_linker_option $LDFLAGS"
324 dnl Now check for particular libevent functions.
325 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
327 dnl ------------------------------------------------------
328 dnl Where do you live, openssl?  And how do we call you?
330 AC_CACHE_CHECK([for OpenSSL directory], tor_cv_openssl_dir, [
331   saved_LIBS="$LIBS"
332   saved_LDFLAGS="$LDFLAGS"
333   saved_CPPFLAGS="$CPPFLAGS"
334   ssl_found=no
335   for ssldir in $tryssldir "" $prefix /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do
336     LDFLAGS="$saved_LDFLAGS"
338     if test $bwin32 = true; then
339       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
340     else
341       LIBS="$saved_LIBS -lssl -lcrypto"
342     fi
344     # Skip the directory if it isn't there.
345     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
346        continue;
347     fi
348     if test ! -z "$ssldir" ; then
349       if test -d "$ssldir/lib" ; then
350         LDFLAGS="-L$ssldir/lib $LDFLAGS"
351       else
352         LDFLAGS="-L$ssldir $LDFLAGS"
353       fi
354       if test -d "$ssldir/include" ; then
355         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
356       else
357         CPPFLAGS="-I$ssldir $CPPFLAGS"
358       fi
359     fi
360     # Can I link it?
361     AC_TRY_LINK([#include <openssl/rand.h>],
362        [ RAND_add((void*)0,0,0); ],
363        [ openssl_linked=yes ], [ openssl_linked=no ])
364     if test $openssl_linked = yes; then
365        if test ! -z "$ssldir" ; then
366          tor_cv_openssl_dir=$ssldir
367        else
368          tor_cv_openssl_dir="(system)"
369        fi
370        ssl_found=yes
371        break
372     fi
373   done
374   LIBS="$saved_LIBS"
375   LDFLAGS="$saved_LDFLAGS"
376   CPPFLAGS="$saved_CPPFLAGS"
377   if test $ssl_found = no ; then
378     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
379   fi
382 if test $bwin32 = true; then
383 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
384 else
385 LIBS="$LIBS -lssl -lcrypto"
388 if test "$tor_cv_openssl_dir" != "(system)"; then
389   if test -d "$tor_cv_openssl_dir/lib" ; then
390     LDFLAGS="-L$tor_cv_openssl_dir/lib $LDFLAGS"
391     ssl_libdir="$tor_cv_openssl_dir/lib"
392   else
393     LDFLAGS="-L$tor_cv_openssl_dir $LDFLAGS"
394     ssl_libdir="$tor_cv_openssl_dir"
395   fi
396   if test -d "$tor_cv_openssl_dir/include" ; then
397     CPPFLAGS="-I$tor_cv_openssl_dir/include $CPPFLAGS"
398   else
399     CPPFLAGS="-I$tor_cv_openssl_dir $CPPFLAGS"
400   fi
403 if test -z "$CROSS_COMPILE"
404 then
405 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
406                tor_cv_openssl_linker_option, [
407     saved_LDFLAGS="$LDFLAGS"
408     ssl_runs=no
409     linked_with=nothing
410     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
411       LDFLAGS="$ssl_extra $saved_LDFLAGS"
412       AC_TRY_RUN([
413 #include <string.h>
414 #include <openssl/rand.h>
415 int main(void)
417         char a[2048];
418         memset(a, 0, sizeof(a));
419         RAND_add(a, sizeof(a), sizeof(a));
420         return(RAND_status() <= 0);
422                         ],
423                 openssl_runs=yes, openssl_runs=no, openssl_runs=cross)
424       if test $openssl_runs != no ; then
425         if test "$linked_with" = nothing; then
426            linked_with="$ssl_extra"
427         fi
428         AC_TRY_RUN([
429 #include <openssl/opensslv.h>
430 #include <openssl/crypto.h>
431 int main(void) {
432 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
434         right_version=yes, right_version=no)
435         if test "$right_version" = yes; then
436           if test -z "$ssl_extra" ; then
437             tor_cv_openssl_linker_option='(none)'
438           else
439             tor_cv_openssl_linker_option=$ssl_extra
440           fi
441           ssl_runs=yes
442           break
443         fi
444      fi
445     done
446     if test $ssl_runs = no ; then
447       if test "$linked_with" = 'nothing' ; then
448         AC_MSG_ERROR([Found linkable OpenSSL in $tor_cv_openssl_dir, but it doesn't run, even with -R.  Maybe specify another using --with-ssl-dir?])
449       else
450         if test -z "$linked_with" ; then
451             tor_cv_openssl_linker_option='(none)'
452         else
453             tor_cv_openssl_linker_option=$linked_with
454         fi
455         AC_MSG_WARN([I managed to make OpenSSL link and run, but I couldn't make it link against the same version I found header files for.])
456       fi
457     fi
458     LDFLAGS="$saved_LDFLAGS"
461 if test "$tor_cv_openssl_linker_option" != '(none)' ; then
462    LDFLAGS="$tor_cv_openssl_linker_option $LDFLAGS"
466 dnl Make sure to enable support for large off_t if avalable.
468 AC_SYS_LARGEFILE
470 dnl The warning message here is no longer strictly accurate.
472 AC_CHECK_HEADERS(unistd.h string.h signal.h ctype.h sys/stat.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))
474 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h)
476 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
477 [#ifdef HAVE_SYS_TYPES_H
478 #include <sys/types.h>
479 #endif
480 #ifdef HAVE_SYS_TIME_H
481 #include <sys/time.h>
482 #else
483   struct timeval {
484     long tv_sec;
485     long tv_usec;
486  };
487 #endif])
489 AC_CHECK_HEADERS(zlib.h, , AC_MSG_ERROR(Zlib header (zlib.h) not found. Tor requires zlib to build. You may need to install a zlib development package.))
491 dnl These headers are not essential
493 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 sys/syslimits.h)
495 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
496 [#ifdef HAVE_SYS_TYPES_H
497 #include <sys/types.h>
498 #endif
499 #ifdef HAVE_SYS_SOCKET_H
500 #include <sys/socket.h>
501 #endif])
502 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
503 [#ifdef HAVE_SYS_TYPES_H
504 #include <sys/types.h>
505 #endif
506 #ifdef HAVE_SYS_SOCKET_H
507 #include <sys/socket.h>
508 #endif
509 #ifdef HAVE_NET_IF_H
510 #include <net/if.h>
511 #endif])
512 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
513         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
514 [#ifdef HAVE_SYS_TYPES_H
515 #include <sys/types.h>
516 #endif
517 #ifdef HAVE_SYS_SOCKET_H
518 #include <sys/socket.h>
519 #endif])
521 if test x$transparent = xtrue ; then
522    transparent_ok=0
523    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
524      transparent_ok=1
525    fi
526    if test x$linux_netfilter_ipv4 = x1 ; then
527      transparent_ok=1
528    fi
529    if test x$transparent_ok = x1 ; then
530      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
531      case $host in
532        *-*-openbsd*)
533          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
534      esac
535    else
536      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
537    fi
540 AC_FUNC_FSEEKO
542 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
543 [#ifdef HAVE_SYS_TYPES_H
544 #include <sys/types.h>
545 #endif
546 #ifdef HAVE_SYS_TIME_H
547 #include <sys/time.h>
548 #endif])
550 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
551 dnl Watch out.
553 AC_CHECK_SIZEOF(int8_t)
554 AC_CHECK_SIZEOF(int16_t)
555 AC_CHECK_SIZEOF(int32_t)
556 AC_CHECK_SIZEOF(int64_t)
557 AC_CHECK_SIZEOF(uint8_t)
558 AC_CHECK_SIZEOF(uint16_t)
559 AC_CHECK_SIZEOF(uint32_t)
560 AC_CHECK_SIZEOF(uint64_t)
561 AC_CHECK_SIZEOF(intptr_t)
562 AC_CHECK_SIZEOF(uintptr_t)
564 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
566 AC_CHECK_SIZEOF(char)
567 AC_CHECK_SIZEOF(short)
568 AC_CHECK_SIZEOF(int)
569 AC_CHECK_SIZEOF(long)
570 AC_CHECK_SIZEOF(long long)
571 AC_CHECK_SIZEOF(__int64)
572 AC_CHECK_SIZEOF(void *)
573 AC_CHECK_SIZEOF(time_t)
574 AC_CHECK_SIZEOF(size_t)
576 AC_CHECK_TYPES([uint, u_char])
578 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_storage], , ,
579 [#ifdef HAVE_SYS_TYPES_H
580 #include <sys/types.h>
581 #endif
582 #ifdef HAVE_NETINET_IN_H
583 #include <netinet/in.h>
584 #endif
585 #ifdef HAVE_NETINET_IN6_H
586 #include <netinet/in6.h>
587 #endif
588 #ifdef HAVE_SYS_SOCKET_H
589 #include <sys/socket.h>
590 #endif])
592 AC_CHECK_TYPES([rlim_t], , ,
593 [#ifdef HAVE_SYS_TYPES_H
594 #include <sys/types.h>
595 #endif
596 #ifdef HAVE_SYS_TIME_H
597 #include <sys/time.h>
598 #endif
599 #ifdef HAVE_SYS_RESOURCE_H
600 #include <sys/resource.h>
601 #endif
604 if test -z "$CROSS_COMPILE"; then
605 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
606 AC_TRY_RUN([
607 #ifdef HAVE_SYS_TYPES_H
608 #include <sys/types.h>
609 #endif
610 #ifdef HAVE_SYS_TIME_H
611 #include <sys/time.h>
612 #endif
613 #ifdef HAVE_TIME_H
614 #include <time.h>
615 #endif
616 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
617   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
619 else
620   # Cross-compiling; let's hope the target platform isn't loony.
621   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
622   tor_cv_time_t_signed=yes
625 if test $tor_cv_time_t_signed = yes; then
626   AC_DEFINE([TIME_T_IS_SIGNED], 1,
627             [Define to 1 iff time_t is signed])
630 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
631 #ifdef HAVE_SYS_SOCKET_H
632 #include <sys/socket.h>
633 #endif
636 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
638 AC_CHECK_SIZEOF(cell_t)
640 # Now make sure that NULL can be represented as zero bytes.
641 if test -z "$CROSS_COMPILE"; then
642 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
643 [AC_RUN_IFELSE([AC_LANG_SOURCE(
644 [[#include <stdlib.h>
645 #include <string.h>
646 #include <stdio.h>
647 #ifdef HAVE_STDDEF_H
648 #include <stddef.h>
649 #endif
650 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
651 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
652        [tor_cv_null_is_zero=yes],
653        [tor_cv_null_is_zero=no],
654        [tor_cv_null_is_zero=cross])])
656 else
657   # Cross-compiling; let's hope that the target isn't raving mad.
658   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
659   tor_cv_null_is_zero=yes
662 if test $tor_cv_null_is_zero = yes; then
663   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
664             [Define to 1 iff memset(0) sets pointers to NULL])
667 # And what happens when we malloc zero?
669 if test -z "$CROSS_COMPILE"; then
670 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
671 [AC_RUN_IFELSE([AC_LANG_SOURCE(
672 [[#include <stdlib.h>
673 #include <string.h>
674 #include <stdio.h>
675 #ifdef HAVE_STDDEF_H
676 #include <stddef.h>
677 #endif
678 int main () { return malloc(0)?0:1; }]])],
679        [tor_cv_malloc_zero_works=yes],
680        [tor_cv_malloc_zero_works=no],
681        [tor_cv_malloc_zero_works=cross])])
683 else
684   # Cross-compiling; let's hope that the target isn't raving mad.
685   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
686   tor_cv_malloc_zero_works=no
689 if test $tor_cv_malloc_zero_works = yes; then
690   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
691             [Define to 1 iff malloc(0) returns a pointer])
694 # whether we seem to be in a 2s-complement world.
695 if test -z "$CROSS_COMPILE"; then
696 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
697 [AC_RUN_IFELSE([AC_LANG_SOURCE(
698 [[int main () { int problem = ((-99) != (~99)+1);
699 return problem ? 1 : 0; }]])],
700        [tor_cv_twos_complement=yes],
701        [tor_cv_twos_complement=no],
702        [tor_cv_twos_complement=cross])])
704 else
705   # Cross-compiling; let's hope that the target isn't raving mad.
706   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
707   tor_cv_twos_complement=yes
710 if test $tor_cv_twos_complement = yes; then
711   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
712             [Define to 1 iff we represent negative integers with two's complement])
715 # Whether we should use the dmalloc memory allocation debugging library.
716 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
717 AC_ARG_WITH(dmalloc,
718 [  --with-dmalloc          Use debug memory allocation library. ],
719 [if [[ "$withval" = "yes" ]]; then
720   dmalloc=1
721   AC_MSG_RESULT(yes)
722 else
723   dmalloc=1
724   AC_MSG_RESULT(no)
725 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
728 if [[ $dmalloc -eq 1 ]]; then
729   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
730   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
731   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
732   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
735 # Allow user to specify an alternate syslog facility
736 AC_ARG_WITH(syslog-facility,
737 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
738 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
739 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
740 AC_SUBST(LOGFACILITY)
742 # Check for gethostbyname_r in all its glorious incompatible versions.
743 #   (This logic is based on that in Python's configure.in)
744 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
745   [Define this if you have any gethostbyname_r()])
747 AC_CHECK_FUNC(gethostbyname_r, [
748   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
749   OLD_CFLAGS=$CFLAGS
750   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
751   AC_TRY_COMPILE([
752 #include <netdb.h>
753   ], [
754     char *cp1, *cp2;
755     struct hostent *h1, *h2;
756     int i1, i2;
757     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
758   ], [
759     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
760     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
761      [Define this if gethostbyname_r takes 6 arguments])
762     AC_MSG_RESULT(6)
763   ], [
764     AC_TRY_COMPILE([
765 #include <netdb.h>
766     ], [
767       char *cp1, *cp2;
768       struct hostent *h1;
769       int i1, i2;
770       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
771     ], [
772       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
773       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
774         [Define this if gethostbyname_r takes 5 arguments])
775       AC_MSG_RESULT(5)
776    ], [
777       AC_TRY_COMPILE([
778 #include <netdb.h>
779      ], [
780        char *cp1;
781        struct hostent *h1;
782        struct hostent_data hd;
783        (void) gethostbyname_r(cp1,h1,&hd);
784      ], [
785        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
786        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
787          [Define this if gethostbyname_r takes 3 arguments])
788        AC_MSG_RESULT(3)
789      ], [
790        AC_MSG_RESULT(0)
791      ])
792   ])
793  ])
794  CFLAGS=$OLD_CFLAGS
797 AC_CACHE_CHECK([whether the C compiler supports __func__],
798   tor_cv_have_func_macro,
799   AC_COMPILE_IFELSE([
800 #include <stdio.h>
801 int main(int c, char **v) { puts(__func__); }],
802   tor_cv_have_func_macro=yes,
803   tor_cv_have_func_macro=no))
805 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
806   tor_cv_have_FUNC_macro,
807   AC_COMPILE_IFELSE([
808 #include <stdio.h>
809 int main(int c, char **v) { puts(__FUNC__); }],
810   tor_cv_have_FUNC_macro=yes,
811   tor_cv_have_FUNC_macro=no))
813 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
814   tor_cv_have_FUNCTION_macro,
815   AC_COMPILE_IFELSE([
816 #include <stdio.h>
817 int main(int c, char **v) { puts(__FUNCTION__); }],
818   tor_cv_have_FUNCTION_macro=yes,
819   tor_cv_have_FUNCTION_macro=no))
821 if test $tor_cv_have_func_macro = 'yes'; then
822   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
825 if test $tor_cv_have_FUNC_macro = 'yes'; then
826   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
829 if test $tor_cv_have_FUNCTION_macro = 'yes'; then
830   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
831            [Defined if the compiler supports __FUNCTION__])
834 # $prefix stores the value of the --prefix command line option, or
835 # NONE if the option wasn't set.  In the case that it wasn't set, make
836 # it be the default, so that we can use it to expand directories now.
837 if test "x$prefix" = "xNONE"; then
838   prefix=$ac_default_prefix
841 # and similarly for $exec_prefix
842 if test "x$exec_prefix" = "xNONE"; then
843   exec_prefix=$prefix
846 if test "x$CONFDIR" = "x"; then
847   CONFDIR=`eval echo $sysconfdir/tor`
849 AC_SUBST(CONFDIR)
850 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
851 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
853 BINDIR=`eval echo $bindir`
854 AC_SUBST(BINDIR)
856 LOCALSTATEDIR=`eval echo $localstatedir`
857 AC_SUBST(LOCALSTATEDIR)
858 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
859 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
861 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
862 # than autoconf's macros like.
863 if test $ac_cv_c_compiler_gnu = yes; then
864   CFLAGS="$CFLAGS -Wall -g -O2"
865 else
866   CFLAGS="$CFLAGS -g -O"
867   enable_gcc_warnings=no
870 # Add some more warnings which we use in the cvs version but not in the
871 # released versions.  (Some relevant gcc versions can't handle these.)
872 if test x$enable_gcc_warnings = xyes; then
874   AC_TRY_COMPILE([], [
875 #if !defined(__GNUC__) || (__GNUC__ < 4)
876 #error
877 #endif], have_gcc4=yes, have_gcc4=no)
879   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Waggregate-return -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror"
881   if test x$have_gcc4 = xyes ; then 
882     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
883     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
884   fi
886 ##This will break the world on some 64-bit architectures
887 # CFLAGS="$CFLAGS -Winline"
891 AC_OUTPUT(Makefile tor.spec 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)
893 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
894   ./contrib/updateVersions.pl