clean up, and make progress on, the discovery section.
[tor.git] / configure.in
blobabfd1b86393542496f309da0dbbb15aba3701c22
1 dnl $Id$
2 dnl Copyright (c) 2001-2004, Roger Dingledine
3 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.1.2.3-alpha-dev)
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     fi ;;
55     *-*-solaris* )
56      # Don't try multithreading on solaris -- cpuworkers seem to lock.
57      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
58 cpu workers lock up here, so I will disable threads.])
59      enable_threads="no";;
60     *)
61      enable_threads="yes";;
62    esac
65 if test $enable_threads = "yes"; then
66   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
69 case $host in
70    *-*-solaris* )
71      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
72      ;;
73 esac
75 AC_ARG_ENABLE(gcc-warnings,
76      AC_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
78 AC_PROG_CC
79 AC_PROG_MAKE_SET
80 AC_PROG_RANLIB
82 # The big search for OpenSSL
83 # copied from openssh's configure.ac
84 tryssldir=""
85 AC_ARG_WITH(ssl-dir,
86         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
87         [
88                 if test "x$withval" != "xno" ; then
89                         tryssldir=$withval
90                 fi
91         ]
94 trylibeventdir=""
95 AC_ARG_WITH(libevent-dir,
96        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
97        [
98                 if test "x$withval" != "xno" ; then
99                         trylibeventdir=$withval
100                 fi
101        ]
104 TORUSER=_tor
105 AC_ARG_WITH(tor-user,
106         [  --with-tor-user=NAME    Specify username for tor daemon ],
107         [
108            TORUSER=$withval
109         ]
111 AC_SUBST(TORUSER)
113 TORGROUP=_tor
114 AC_ARG_WITH(tor-group,
115         [  --with-tor-group=NAME   Specify group name for tor daemon ],
116         [
117            TORGROUP=$withval
118         ]
120 AC_SUBST(TORGROUP)
123 dnl If WIN32 is defined and non-zero, we are building for win32
124 AC_MSG_CHECKING([for win32])
125 AC_RUN_IFELSE([
126 int main(int c, char **v) {
127 #ifdef WIN32
128 #if WIN32
129   return 0;
130 #else
131   return 1;
132 #endif
133 #else
134   return 2;
135 #endif
137 bwin32=true; AC_MSG_RESULT([yes]),
138 bwin32=false; AC_MSG_RESULT([no]),
139 bwin32=cross; AC_MSG_RESULT([cross])
142 if test $bwin32 = cross; then
143 AC_MSG_CHECKING([for win32 (cross)])
144 AC_COMPILE_IFELSE([
145 #ifdef WIN32
146 int main(int c, char **v) {return 0;}
147 #else
148 #error
149 int main(int c, char **v) {return x(y);}
150 #endif
152 bwin32=true; AC_MSG_RESULT([yes]),
153 bwin32=false; AC_MSG_RESULT([no]))
156 if test $bwin32 = true; then
157 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
160 AC_SEARCH_LIBS(socket, [socket])
161 AC_SEARCH_LIBS(gethostbyname, [nsl])
162 AC_SEARCH_LIBS(dlopen, [dl])
163 AC_SEARCH_LIBS(inet_aton, [resolv])
165 if test $enable_threads = "yes"; then
166   AC_SEARCH_LIBS(pthread_create, [pthread])
167   AC_SEARCH_LIBS(pthread_detach, [pthread])
170 dnl -------------------------------------------------------------------
171 dnl Check for functions before libevent, since libevent-1.2 apparently
172 dnl exports strlcpy without defining it in a header.
174 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r)
176 if test $enable_threads = "yes"; then
177   AC_CHECK_HEADERS(pthread.h)
178   AC_CHECK_FUNCS(pthread_create)
181 dnl ------------------------------------------------------
182 dnl Where do you live, libevent?  And how do we call you?
184 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
185   saved_LIBS="$LIBS"
186   saved_LDFLAGS="$LDFLAGS"
187   saved_CPPFLAGS="$CPPFLAGS"
188   le_found=no
189   for ledir in $trylibeventdir "" $prefix /usr/local ; do
190     LDFLAGS="$saved_LDFLAGS"
192     if test $bwin32 = true; then
193         LIBS="$saved_LIBS -levent -lws2_32"
194     else
195         LIBS="$saved_LIBS -levent"
196     fi
198     # Skip the directory if it isn't there.
199     if test ! -z "$ledir" -a ! -d "$ledir" ; then
200        continue;
201     fi
202     if test ! -z "$ledir" ; then
203       if test -d "$ledir/lib" ; then
204         LDFLAGS="-L$ledir/lib $LDFLAGS"
205       else
206         LDFLAGS="-L$ledir $LDFLAGS"
207       fi
208       if test -d "$ledir/include" ; then
209         CPPFLAGS="-I$ledir/include $CPPFLAGS"
210       else
211         CPPFLAGS="-I$ledir $CPPFLAGS"
212       fi
213     fi
214     # Can I compile and link it?
215     AC_TRY_LINK([#include <sys/time.h>
216 #include <sys/types.h>
217 #include <event.h>], [ event_init(); ],
218        [ libevent_linked=yes ], [ libevent_linked=no ])
219     if test $libevent_linked = yes; then
220        if test ! -z "$ledir" ; then
221          ac_cv_libevent_dir=$ledir
222        else
223          ac_cv_libevent_dir="(system)"
224        fi
225        le_found=yes
226        break
227     fi
228   done
229   LIBS="$saved_LIBS"
230   LDFLAGS="$saved_LDFLAGS"
231   CPPFLAGS="$saved_CPPFLAGS"
232   if test $le_found = no ; then
233     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
234   fi
237 if test $bwin32 = true; then
238 LIBS="$LIBS -levent -lws2_32"
239 else
240 LIBS="$LIBS -levent"
242 if test $ac_cv_libevent_dir != "(system)"; then
243   if test -d "$ac_cv_libevent_dir/lib" ; then
244     LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
245     le_libdir="$ac_cv_libevent_dir/lib"
246   else
247     LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
248     le_libdir="$ac_cv_libevent_dir"
249   fi
250   if test -d "$ac_cv_libevent_dir/include" ; then
251     CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
252   else
253     CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
254   fi
257 if test -z "$CROSS_COMPILE"; then
258 AC_CACHE_CHECK([whether we need extra options to link libevent],
259                ac_cv_libevent_linker_option, [
260     saved_LDFLAGS="$LDFLAGS"
261     le_runs=no
262     linked_with=nothing
263     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" ; do
264       LDFLAGS="$le_extra $saved_LDFLAGS"
265       AC_TRY_RUN([void *event_init(void);
266                 int main(int c, char **v) {
267                    event_init(); return 0;
268                 }],
269                 libevent_runs=yes, libevent_runs=no)
270       if test $libevent_runs = yes ; then
271         if test -z "$le_extra" ; then
272           ac_cv_libevent_linker_option='(none)'
273         else
274           ac_cv_libevent_linker_option=$le_extra
275         fi
276         le_runs=yes
277         break
278       fi
279     done
280     if test $le_runs = no ; then
281       AC_MSG_ERROR([Found linkable libevent in $ac_cv_libevent_dir, but it doesn't run, even with -R.  Maybe specify another using --with-libevent-dir?])
282     fi
283     LDFLAGS="$saved_LDFLAGS"
286 if test $ac_cv_libevent_linker_option != '(none)' ; then
287    LDFLAGS="$ac_cv_libevent_linker_option $LDFLAGS"
291 dnl Now check for particular libevent functions.
292 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
294 dnl ------------------------------------------------------
295 dnl Where do you live, openssl?  And how do we call you?
297 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [
298   saved_LIBS="$LIBS"
299   saved_LDFLAGS="$LDFLAGS"
300   saved_CPPFLAGS="$CPPFLAGS"
301   ssl_found=no
302   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
303     LDFLAGS="$saved_LDFLAGS"
305     if test $bwin32 = true; then
306       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
307     else
308       LIBS="$saved_LIBS -lssl -lcrypto"
309     fi
311     # Skip the directory if it isn't there.
312     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
313        continue;
314     fi
315     if test ! -z "$ssldir" ; then
316       if test -d "$ssldir/lib" ; then
317         LDFLAGS="-L$ssldir/lib $LDFLAGS"
318       else
319         LDFLAGS="-L$ssldir $LDFLAGS"
320       fi
321       if test -d "$ssldir/include" ; then
322         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
323       else
324         CPPFLAGS="-I$ssldir $CPPFLAGS"
325       fi
326     fi
327     # Can I link it?
328     AC_TRY_LINK([#include <openssl/rand.h>],
329        [ RAND_add((void*)0,0,0); ],
330        [ openssl_linked=yes ], [ openssl_linked=no ])
331     if test $openssl_linked = yes; then
332        if test ! -z "$ssldir" ; then
333          ac_cv_openssl_dir=$ssldir
334        else
335          ac_cv_openssl_dir="(system)"
336        fi
337        ssl_found=yes
338        break
339     fi
340   done
341   LIBS="$saved_LIBS"
342   LDFLAGS="$saved_LDFLAGS"
343   CPPFLAGS="$saved_CPPFLAGS"
344   if test $ssl_found = no ; then
345     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
346   fi
349 if test $bwin32 = true; then
350 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
351 else
352 LIBS="$LIBS -lssl -lcrypto"
355 if test "$ac_cv_openssl_dir" != "(system)"; then
356   if test -d "$ac_cv_openssl_dir/lib" ; then
357     LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS"
358     ssl_libdir="$ac_cv_openssl_dir/lib"
359   else
360     LDFLAGS="-L$ac_cv_openssl_dir $LDFLAGS"
361     ssl_libdir="$ac_cv_openssl_dir"
362   fi
363   if test -d "$ac_cv_openssl_dir/include" ; then
364     CPPFLAGS="-I$ac_cv_openssl_dir/include $CPPFLAGS"
365   else
366     CPPFLAGS="-I$ac_cv_openssl_dir $CPPFLAGS"
367   fi
370 if test -z "$CROSS_COMPILE"
371 then
372 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
373                ac_cv_openssl_linker_option, [
374     saved_LDFLAGS="$LDFLAGS"
375     ssl_runs=no
376     linked_with=nothing
377     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
378       LDFLAGS="$ssl_extra $saved_LDFLAGS"
379       AC_TRY_RUN([
380 #include <string.h>
381 #include <openssl/rand.h>
382 int main(void)
384         char a[2048];
385         memset(a, 0, sizeof(a));
386         RAND_add(a, sizeof(a), sizeof(a));
387         return(RAND_status() <= 0);
389                         ],
390                 openssl_runs=yes, openssl_runs=no)
391       if test $openssl_runs = yes ; then
392         if test "$linked_with" = nothing; then
393            linked_with="$ssl_extra"
394         fi
395         AC_TRY_RUN([
396 #include <openssl/opensslv.h>
397 #include <openssl/crypto.h>
398 int main(void) {
399 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
401         right_version=yes, right_version=no)
402         if test "$right_version" = yes; then
403           if test -z "$ssl_extra" ; then
404             ac_cv_openssl_linker_option='(none)'
405           else
406             ac_cv_openssl_linker_option=$ssl_extra
407           fi
408           ssl_runs=yes
409           break
410         fi
411      fi
412     done
413     if test $ssl_runs = no ; then
414       if test "$linked_with" = 'nothing' ; then
415         AC_MSG_ERROR([Found linkable OpenSSL in $ac_cv_openssl_dir, but it doesn't run, even with -R.  Maybe specify another using --with-ssl-dir?])
416       else
417         if test -z "$linked_with" ; then
418             ac_cv_openssl_linker_option='(none)'
419         else
420             ac_cv_openssl_linker_option=$linked_with
421         fi
422         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.])
423       fi
424     fi
425     LDFLAGS="$saved_LDFLAGS"
428 if test "$ac_cv_openssl_linker_option" != '(none)' ; then
429    LDFLAGS="$ac_cv_openssl_linker_option $LDFLAGS"
433 dnl Make sure to enable support for large off_t if avalable.
435 AC_SYS_LARGEFILE
437 dnl The warning message here is no longer strictly accurate.
439 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))
441 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h)
443 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
444 [#ifdef HAVE_SYS_TYPES_H
445 #include <sys/types.h>
446 #endif
447 #ifdef HAVE_SYS_TIME_H
448 #include <sys/time.h>
449 #else
450   struct timeval {
451     long tv_sec;
452     long tv_usec;
453  };
454 #endif])
456 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.))
458 dnl These headers are not essential
460 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)
462 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
463 [#ifdef HAVE_SYS_TYPES_H
464 #include <sys/types.h>
465 #endif
466 #ifdef HAVE_SYS_SOCKET_H
467 #include <sys/socket.h>
468 #endif])
469 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
470 [#ifdef HAVE_SYS_TYPES_H
471 #include <sys/types.h>
472 #endif
473 #ifdef HAVE_SYS_SOCKET_H
474 #include <sys/socket.h>
475 #endif
476 #ifdef HAVE_NET_IF_H
477 #include <net/if.h>
478 #endif])
479 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
480         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
481 [#ifdef HAVE_SYS_SOCKET_H
482 #include <sys/socket.h>
483 #endif])
485 if test x$transparent = xtrue ; then
486    transparent_ok=0
487    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
488      transparent_ok=1
489    fi
490    if test x$linux_netfilter_ipv4 = x1 ; then
491      transparent_ok=1
492    fi
493    if test x$transparent_ok = x1 ; then
494      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
495      case $host in
496        *-*-openbsd*)
497          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
498      esac
499    else
500      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
501    fi
504 AC_FUNC_FSEEKO
506 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
507 [#ifdef HAVE_SYS_TYPES_H
508 #include <sys/types.h>
509 #endif
510 #ifdef HAVE_SYS_TIME_H
511 #include <sys/time.h>
512 #endif])
514 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
515 dnl Watch out.
517 AC_CHECK_SIZEOF(int8_t)
518 AC_CHECK_SIZEOF(int16_t)
519 AC_CHECK_SIZEOF(int32_t)
520 AC_CHECK_SIZEOF(int64_t)
521 AC_CHECK_SIZEOF(uint8_t)
522 AC_CHECK_SIZEOF(uint16_t)
523 AC_CHECK_SIZEOF(uint32_t)
524 AC_CHECK_SIZEOF(uint64_t)
525 AC_CHECK_SIZEOF(intptr_t)
526 AC_CHECK_SIZEOF(uintptr_t)
528 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
530 AC_CHECK_SIZEOF(char)
531 AC_CHECK_SIZEOF(short)
532 AC_CHECK_SIZEOF(int)
533 AC_CHECK_SIZEOF(long)
534 AC_CHECK_SIZEOF(long long)
535 AC_CHECK_SIZEOF(__int64)
536 AC_CHECK_SIZEOF(void *)
537 AC_CHECK_SIZEOF(time_t)
538 AC_CHECK_SIZEOF(size_t)
540 AC_CHECK_TYPES([uint, u_char])
542 if test -z "$CROSS_COMPILE"; then
543 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
544 AC_TRY_RUN([
545 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
546   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
548 else
549   # Cross-compiling; let's hope the target platform isn't loony.
550   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
551   tor_cv_time_t_signed=yes
554 if test $tor_cv_time_t_signed = yes; then
555   AC_DEFINE([TIME_T_IS_SIGNED], 1,
556             [Define to 1 iff time_t is signed])
559 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
560 #ifdef HAVE_SYS_SOCKET_H
561 #include <sys/socket.h>
562 #endif
565 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
567 AC_CHECK_SIZEOF(cell_t)
569 # Now make sure that NULL can be represented as zero bytes.
570 if test -z "$CROSS_COMPILE"; then
571 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
572 [AC_RUN_IFELSE([AC_LANG_SOURCE(
573 [[#include <stdlib.h>
574 #include <string.h>
575 #include <stdio.h>
576 #ifdef HAVE_STDDEF_H
577 #include <stddef.h>
578 #endif
579 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
580 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
581        [tor_cv_null_is_zero=yes],
582        [tor_cv_null_is_zero=no],
583        [tor_cv_null_is_zero=cross])])
585 else
586   # Cross-compiling; let's hope that the target isn't raving mad.
587   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
588   tor_cv_null_is_zero=yes
591 if test $tor_cv_null_is_zero = yes; then
592   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
593             [Define to 1 iff memset(0) sets pointers to NULL])
596 # And what happens when we malloc zero?
598 if test -z "$CROSS_COMPILE"; then
599 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
600 [AC_RUN_IFELSE([AC_LANG_SOURCE(
601 [[#include <stdlib.h>
602 #include <string.h>
603 #include <stdio.h>
604 #ifdef HAVE_STDDEF_H
605 #include <stddef.h>
606 #endif
607 int main () { return malloc(0)?0:1; }]])],
608        [tor_cv_malloc_zero_works=yes],
609        [tor_cv_malloc_zero_works=no],
610        [tor_cv_malloc_zero_works=cross])])
612 else
613   # Cross-compiling; let's hope that the target isn't raving mad.
614   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
615   tor_cv_malloc_zero_works=no
618 if test $tor_cv_malloc_zero_works = yes; then
619   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
620             [Define to 1 iff malloc(0) returns a pointer])
623 # whether we seem to be in a 2s-complement world.
624 if test -z "$CROSS_COMPILE"; then
625 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
626 [AC_RUN_IFELSE([AC_LANG_SOURCE(
627 [[int main () { int problem = ((-99) != (~99)+1);
628 return problem ? 1 : 0; }]])],
629        [tor_cv_twos_complement=yes],
630        [tor_cv_twos_complement=no],
631        [tor_cv_twos_complement=cross])])
633 else
634   # Cross-compiling; let's hope that the target isn't raving mad.
635   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
636   tor_cv_twos_complement=yes
639 if test $tor_cv_twos_complement = yes; then
640   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
641             [Define to 1 iff we represent negative integers with two's complement])
644 # Whether we should use the dmalloc memory allocation debugging library.
645 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
646 AC_ARG_WITH(dmalloc,
647 [  --with-dmalloc          Use debug memory allocation library. ],
648 [if [[ "$withval" = "yes" ]]; then
649   dmalloc=1
650   AC_MSG_RESULT(yes)
651 else
652   dmalloc=1
653   AC_MSG_RESULT(no)
654 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
657 if [[ $dmalloc -eq 1 ]]; then
658   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
659   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
660   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
661   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
664 # Allow user to specify an alternate syslog facility
665 AC_ARG_WITH(syslog-facility,
666 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
667 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
668 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
669 AC_SUBST(LOGFACILITY)
671 # Check for gethostbyname_r in all its glorious incompatible versions.
672 #   (This logic is based on that in Python's configure.in)
673 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
674   [Define this if you have any gethostbyname_r()])
676 AC_CHECK_FUNC(gethostbyname_r, [
677   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
678   OLD_CFLAGS=$CFLAGS
679   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
680   AC_TRY_COMPILE([
681 #include <netdb.h>
682   ], [
683     char *cp1, *cp2;
684     struct hostent *h1, *h2;
685     int i1, i2;
686     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
687   ], [
688     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
689     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
690      [Define this if gethostbyname_r takes 6 arguments])
691     AC_MSG_RESULT(6)
692   ], [
693     AC_TRY_COMPILE([
694 #include <netdb.h>
695     ], [
696       char *cp1, *cp2;
697       struct hostent *h1;
698       int i1, i2;
699       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
700     ], [
701       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
702       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
703         [Define this if gethostbyname_r takes 5 arguments])
704       AC_MSG_RESULT(5)
705    ], [
706       AC_TRY_COMPILE([
707 #include <netdb.h>
708      ], [
709        char *cp1;
710        struct hostent *h1;
711        struct hostent_data hd;
712        (void) gethostbyname_r(cp1,h1,&hd);
713      ], [
714        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
715        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
716          [Define this if gethostbyname_r takes 3 arguments])
717        AC_MSG_RESULT(3)
718      ], [
719        AC_MSG_RESULT(0)
720      ])
721   ])
722  ])
723  CFLAGS=$OLD_CFLAGS
726 AC_CACHE_CHECK([whether the C compiler supports __func__],
727   ac_cv_have_func_macro,
728   AC_COMPILE_IFELSE([
729 #include <stdio.h>
730 int main(int c, char **v) { puts(__func__); }],
731   ac_cv_have_func_macro=yes,
732   ac_cv_have_func_macro=no))
734 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
735   ac_cv_have_FUNC_macro,
736   AC_COMPILE_IFELSE([
737 #include <stdio.h>
738 int main(int c, char **v) { puts(__FUNC__); }],
739   ac_cv_have_FUNC_macro=yes,
740   ac_cv_have_FUNC_macro=no))
742 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
743   ac_cv_have_FUNCTION_macro,
744   AC_COMPILE_IFELSE([
745 #include <stdio.h>
746 int main(int c, char **v) { puts(__FUNCTION__); }],
747   ac_cv_have_FUNCTION_macro=yes,
748   ac_cv_have_FUNCTION_macro=no))
750 if test $ac_cv_have_func_macro = 'yes'; then
751   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
754 if test $ac_cv_have_FUNC_macro = 'yes'; then
755   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
758 if test $ac_cv_have_FUNCTION_macro = 'yes'; then
759   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
760            [Defined if the compiler supports __FUNCTION__])
763 # $prefix stores the value of the --prefix command line option, or
764 # NONE if the option wasn't set.  In the case that it wasn't set, make
765 # it be the default, so that we can use it to expand directories now.
766 if test "x$prefix" = "xNONE"; then
767   prefix=$ac_default_prefix
770 # and similarly for $exec_prefix
771 if test "x$exec_prefix" = "xNONE"; then
772   exec_prefix=$prefix
775 if test "x$CONFDIR" = "x"; then
776   CONFDIR=`eval echo $sysconfdir/tor`
778 AC_SUBST(CONFDIR)
779 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
780 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
782 BINDIR=`eval echo $bindir`
783 AC_SUBST(BINDIR)
785 LOCALSTATEDIR=`eval echo $localstatedir`
786 AC_SUBST(LOCALSTATEDIR)
787 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
788 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
790 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
791 # than autoconf's macros like.
792 if test $ac_cv_c_compiler_gnu = yes; then
793   CFLAGS="$CFLAGS -Wall -g -O2"
794 else
795   CFLAGS="$CFLAGS -g -O"
796   enable_gcc_warnings=no
799 # Add some more warnings which we use in the cvs version but not in the
800 # released versions.  (Some relevant gcc versions can't handle these.)
801 if test x$enable_gcc_warnings = xyes; then
803   AC_TRY_COMPILE([], [
804 #if !defined(__GNUC__) || (__GNUC__ < 4)
805 #error
806 #endif], have_gcc4=yes, have_gcc4=no)
808   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"
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 ##This will break the world on some 64-bit architectures
816 # CFLAGS="$CFLAGS -Winline"
820 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 src/config/Makefile src/common/Makefile src/or/Makefile src/win32/Makefile src/tools/Makefile contrib/suse/Makefile contrib/suse/tor.sh)
822 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
823   ./contrib/updateVersions.pl