bugfix and cleanups re: entry guards.
[tor.git] / configure.in
blob2c3447a32ff900b6ededc19dedbb0c7d6f50d40a
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.1-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_PROG_CC
76 AC_PROG_MAKE_SET
77 AC_PROG_RANLIB
79 # If WIN32 is defined and non-zero, we are building for win32
80 AC_MSG_CHECKING([for win32])
81 AC_TRY_COMPILE(,
83 #ifdef WIN32
84 #if WIN32
85 //all is well
86 #else
87 #error
88 #endif
89 #else
90 #error
91 #endif
93 bwin32=true; AC_MSG_RESULT([yes]),
94 bwin32=false; AC_MSG_RESULT([no])
97 if test $bwin32 = true; then
99 AC_DEFINE(MS_WINDOWS,1, [Define to 1 if we are building for a Windows platform.])
104 # The big search for OpenSSL
105 # copied from openssh's configure.ac
106 tryssldir=""
107 AC_ARG_WITH(ssl-dir,
108         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
109         [
110                 if test "x$withval" != "xno" ; then
111                         tryssldir=$withval
112                 fi
113         ]
116 trylibeventdir=""
117 AC_ARG_WITH(libevent-dir,
118        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
119        [
120                 if test "x$withval" != "xno" ; then
121                         trylibeventdir=$withval
122                 fi
123        ]
126 TORUSER=_tor
127 AC_ARG_WITH(tor-user,
128         [  --with-tor-user=NAME    Specify username for tor daemon ],
129         [
130            TORUSER=$withval
131         ]
133 AC_SUBST(TORUSER)
135 TORGROUP=_tor
136 AC_ARG_WITH(tor-group,
137         [  --with-tor-group=NAME   Specify group name for tor daemon ],
138         [
139            TORGROUP=$withval
140         ]
142 AC_SUBST(TORGROUP)
144 AC_SEARCH_LIBS(socket, [socket])
145 AC_SEARCH_LIBS(gethostbyname, [nsl])
146 AC_SEARCH_LIBS(dlopen, [dl])
147 AC_SEARCH_LIBS(inet_aton, [resolv])
149 if test $enable_threads = "yes"; then
150   AC_SEARCH_LIBS(pthread_create, [pthread])
151   AC_SEARCH_LIBS(pthread_detach, [pthread])
154 dnl ------------------------------------------------------
155 dnl Where do you live, libevent?  And how do we call you?
157 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
158   saved_LIBS="$LIBS"
159   saved_LDFLAGS="$LDFLAGS"
160   saved_CPPFLAGS="$CPPFLAGS"
161   le_found=no
162   for ledir in $trylibeventdir "" $prefix /usr/local ; do
163     LDFLAGS="$saved_LDFLAGS"
165     if test $bwin32 = true; then
166         LIBS="$saved_LIBS -levent -lws2_32"
167     else
168         LIBS="$saved_LIBS -levent"
169     fi
171     # Skip the directory if it isn't there.
172     if test ! -z "$ledir" -a ! -d "$ledir" ; then
173        continue;
174     fi
175     if test ! -z "$ledir" ; then
176       if test -d "$ledir/lib" ; then
177         LDFLAGS="-L$ledir/lib $LDFLAGS"
178       else
179         LDFLAGS="-L$ledir $LDFLAGS"
180       fi
181       if test -d "$ledir/include" ; then
182         CPPFLAGS="-I$ledir/include $CPPFLAGS"
183       else
184         CPPFLAGS="-I$ledir $CPPFLAGS"
185       fi
186     fi
187     # Can I compile and link it?
188     AC_TRY_LINK([#include <sys/time.h>
189 #include <sys/types.h>
190 #include <event.h>], [ event_init(); ],
191        [ libevent_linked=yes ], [ libevent_linked=no ])
192     if test $libevent_linked = yes; then
193        if test ! -z "$ledir" ; then
194          ac_cv_libevent_dir=$ledir
195        else
196          ac_cv_libevent_dir="(system)"
197        fi
198        le_found=yes
199        break
200     fi
201   done
202   LIBS="$saved_LIBS"
203   LDFLAGS="$saved_LDFLAGS"
204   CPPFLAGS="$saved_CPPFLAGS"
205   if test $le_found = no ; then
206     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
207   fi
210 if test $bwin32 = true; then
211 LIBS="$LIBS -levent -lws2_32"
212 else
213 LIBS="$LIBS -levent"
215 if test $ac_cv_libevent_dir != "(system)"; then
216   if test -d "$ac_cv_libevent_dir/lib" ; then
217     LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
218     le_libdir="$ac_cv_libevent_dir/lib"
219   else
220     LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
221     le_libdir="$ac_cv_libevent_dir"
222   fi
223   if test -d "$ac_cv_libevent_dir/include" ; then
224     CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
225   else
226     CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
227   fi
230 if test -z "$CROSS_COMPILE"; then
231 AC_CACHE_CHECK([whether we need extra options to link libevent],
232                ac_cv_libevent_linker_option, [
233     saved_LDFLAGS="$LDFLAGS"
234     le_runs=no
235     linked_with=nothing
236     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" ; do
237       LDFLAGS="$le_extra $saved_LDFLAGS"
238       AC_TRY_RUN([void *event_init(void);
239                 int main(int c, char **v) {
240                    event_init(); return 0;
241                 }],
242                 libevent_runs=yes, libevent_runs=no)
243       if test $libevent_runs = yes ; then
244         if test -z "$le_extra" ; then
245           ac_cv_libevent_linker_option='(none)'
246         else
247           ac_cv_libevent_linker_option=$le_extra
248         fi
249         le_runs=yes
250         break
251       fi
252     done
253     if test $le_runs = no ; then
254       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?])
255     fi
256     LDFLAGS="$saved_LDFLAGS"
259 if test $ac_cv_libevent_linker_option != '(none)' ; then
260    LDFLAGS="$ac_cv_libevent_linker_option $LDFLAGS"
264 dnl ------------------------------------------------------
265 dnl Where do you live, openssl?  And how do we call you?
267 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [
268   saved_LIBS="$LIBS"
269   saved_LDFLAGS="$LDFLAGS"
270   saved_CPPFLAGS="$CPPFLAGS"
271   ssl_found=no
272   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
273     LDFLAGS="$saved_LDFLAGS"
275     if test $bwin32 = true; then
276       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
277     else
278       LIBS="$saved_LIBS -lssl -lcrypto"
279     fi
281     # Skip the directory if it isn't there.
282     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
283        continue;
284     fi
285     if test ! -z "$ssldir" ; then
286       if test -d "$ssldir/lib" ; then
287         LDFLAGS="-L$ssldir/lib $LDFLAGS"
288       else
289         LDFLAGS="-L$ssldir $LDFLAGS"
290       fi
291       if test -d "$ssldir/include" ; then
292         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
293       else
294         CPPFLAGS="-I$ssldir $CPPFLAGS"
295       fi
296     fi
297     # Can I link it?
298     AC_TRY_LINK([#include <openssl/rand.h>],
299        [ RAND_add((void*)0,0,0); ],
300        [ openssl_linked=yes ], [ openssl_linked=no ])
301     if test $openssl_linked = yes; then
302        if test ! -z "$ssldir" ; then
303          ac_cv_openssl_dir=$ssldir
304        else
305          ac_cv_openssl_dir="(system)"
306        fi
307        ssl_found=yes
308        break
309     fi
310   done
311   LIBS="$saved_LIBS"
312   LDFLAGS="$saved_LDFLAGS"
313   CPPFLAGS="$saved_CPPFLAGS"
314   if test $ssl_found = no ; then
315     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
316   fi
319 if test $bwin32 = true; then
320 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
321 else
322 LIBS="$LIBS -lssl -lcrypto"
325 if test "$ac_cv_openssl_dir" != "(system)"; then
326   if test -d "$ac_cv_openssl_dir/lib" ; then
327     LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS"
328     ssl_libdir="$ac_cv_openssl_dir/lib"
329   else
330     LDFLAGS="-L$ac_cv_openssl_dir $LDFLAGS"
331     ssl_libdir="$ac_cv_openssl_dir"
332   fi
333   if test -d "$ac_cv_openssl_dir/include" ; then
334     CPPFLAGS="-I$ac_cv_openssl_dir/include $CPPFLAGS"
335   else
336     CPPFLAGS="-I$ac_cv_openssl_dir $CPPFLAGS"
337   fi
340 if test -z $CROSS_COMPILE
341 then
342 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
343                ac_cv_openssl_linker_option, [
344     saved_LDFLAGS="$LDFLAGS"
345     ssl_runs=no
346     linked_with=nothing
347     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
348       LDFLAGS="$ssl_extra $saved_LDFLAGS"
349       AC_TRY_RUN([
350 #include <string.h>
351 #include <openssl/rand.h>
352 int main(void)
354         char a[2048];
355         memset(a, 0, sizeof(a));
356         RAND_add(a, sizeof(a), sizeof(a));
357         return(RAND_status() <= 0);
359                         ],
360                 openssl_runs=yes, openssl_runs=no)
361       if test $openssl_runs = yes ; then
362         if test "$linked_with" = nothing; then
363            linked_with="$ssl_extra"
364         fi
365         AC_TRY_RUN([
366 #include <openssl/opensslv.h>
367 #include <openssl/crypto.h>
368 int main(void) {
369 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
371         right_version=yes, right_version=no)
372         if test "$right_version" = yes; then
373           if test -z "$ssl_extra" ; then
374             ac_cv_openssl_linker_option='(none)'
375           else
376             ac_cv_openssl_linker_option=$ssl_extra
377           fi
378           ssl_runs=yes
379           break
380         fi
381      fi
382     done
383     if test $ssl_runs = no ; then
384       if test "$linked_with" = 'nothing' ; then
385         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?])
386       else
387         if test -z "$linked_with" ; then
388             ac_cv_openssl_linker_option='(none)'
389         else
390             ac_cv_openssl_linker_option=$linked_with
391         fi
392         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.])
393       fi
394     fi
395     LDFLAGS="$saved_LDFLAGS"
398 if test "$ac_cv_openssl_linker_option" != '(none)' ; then
399    LDFLAGS="$ac_cv_openssl_linker_option $LDFLAGS"
403 dnl Make sure to enable support for large off_t if avalable.
405 AC_SYS_LARGEFILE
407 dnl The warning message here is no longer strictly accurate.
409 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))
411 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h)
413 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
414 [#ifdef HAVE_SYS_TYPES_H
415 #include <sys/types.h>
416 #endif
417 #ifdef HAVE_SYS_TIME_H
418 #include <sys/time.h>
419 #else
420   struct timeval {
421     long tv_sec;
422     long tv_usec;
423  };
424 #endif])
426 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.))
428 dnl These headers are not essential
430 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)
432 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
433 [#ifdef HAVE_SYS_TYPES_H
434 #include <sys/types.h>
435 #endif
436 #ifdef HAVE_SYS_SOCKET_H
437 #include <sys/socket.h>
438 #endif])
439 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
440 [#ifdef HAVE_SYS_TYPES_H
441 #include <sys/types.h>
442 #endif
443 #ifdef HAVE_SYS_SOCKET_H
444 #include <sys/socket.h>
445 #endif
446 #ifdef HAVE_NET_IF_H
447 #include <net/if.h>
448 #endif])
449 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
450         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
451 [#ifdef HAVE_SYS_SOCKET_H
452 #include <sys/socket.h>
453 #endif])
455 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback memmem strtok_r)
457 if test $enable_threads = "yes"; then
458   AC_CHECK_HEADERS(pthread.h)
459   AC_CHECK_FUNCS(pthread_create)
462 if test x$transparent = xtrue ; then
463    transparent_ok=0
464    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
465      transparent_ok=1
466    fi
467    if test x$linux_netfilter_ipv4 = x1 ; then
468      transparent_ok=1
469    fi
470    if test x$transparent_ok = x1 ; then
471      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
472      case $host in
473        *-*-openbsd*)
474          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
475      esac
476    else
477      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
478    fi
481 AC_FUNC_FSEEKO
483 AC_CHECK_MEMBERS([struct timeval.tv_sec])
485 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
486 dnl Watch out.
488 AC_CHECK_SIZEOF(int8_t)
489 AC_CHECK_SIZEOF(int16_t)
490 AC_CHECK_SIZEOF(int32_t)
491 AC_CHECK_SIZEOF(int64_t)
492 AC_CHECK_SIZEOF(uint8_t)
493 AC_CHECK_SIZEOF(uint16_t)
494 AC_CHECK_SIZEOF(uint32_t)
495 AC_CHECK_SIZEOF(uint64_t)
496 AC_CHECK_SIZEOF(intptr_t)
497 AC_CHECK_SIZEOF(uintptr_t)
499 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
501 AC_CHECK_SIZEOF(char)
502 AC_CHECK_SIZEOF(short)
503 AC_CHECK_SIZEOF(int)
504 AC_CHECK_SIZEOF(long)
505 AC_CHECK_SIZEOF(long long)
506 AC_CHECK_SIZEOF(__int64)
507 AC_CHECK_SIZEOF(void *)
508 AC_CHECK_SIZEOF(time_t)
509 AC_CHECK_SIZEOF(size_t)
511 AC_CHECK_TYPES([uint, u_char])
513 if test -z "$CROSS_COMPILE"; then
514 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
515 AC_TRY_RUN([
516 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
517   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
519 else
520   # Cross-compiling; let's hope the target platform isn't loony.
521   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
522   tor_cv_time_t_signed=yes
525 if test $tor_cv_time_t_signed = yes; then
526   AC_DEFINE([TIME_T_IS_SIGNED], 1,
527             [Define to 1 iff time_t is signed])
530 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
531 #ifdef HAVE_SYS_SOCKET_H
532 #include <sys/socket.h>
533 #endif
536 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
538 AC_CHECK_SIZEOF(cell_t)
540 # Now make sure that NULL can be represented as zero bytes.
541 if test -z "$CROSS_COMPILE"; then
542 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
543 [AC_RUN_IFELSE([AC_LANG_SOURCE(
544 [[#include <stdlib.h>
545 #include <string.h>
546 #include <stdio.h>
547 #ifdef HAVE_STDDEF_H
548 #include <stddef.h>
549 #endif
550 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
551 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
552        [tor_cv_null_is_zero=yes],
553        [tor_cv_null_is_zero=no],
554        [tor_cv_null_is_zero=cross])])
556 else
557   # Cross-compiling; let's hope that the target isn't raving mad.
558   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
559   tor_cv_null_is_zero=yes
562 if test $tor_cv_null_is_zero = yes; then
563   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
564             [Define to 1 iff memset(0) sets pointers to NULL])
567 # And what happens when we malloc zero?
569 if test -z "$CROSS_COMPILE"; then
570 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
571 [AC_RUN_IFELSE([AC_LANG_SOURCE(
572 [[#include <stdlib.h>
573 #include <string.h>
574 #include <stdio.h>
575 #ifdef HAVE_STDDEF_H
576 #include <stddef.h>
577 #endif
578 int main () { return malloc(0)?0:1; }]])],
579        [tor_cv_malloc_zero_works=yes],
580        [tor_cv_malloc_zero_works=no],
581        [tor_cv_malloc_zero_works=cross])])
583 else
584   # Cross-compiling; let's hope that the target isn't raving mad.
585   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
586   tor_cv_malloc_zero_works=no
589 if test $tor_cv_malloc_zero_works = yes; then
590   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
591             [Define to 1 iff malloc(0) returns a pointer])
594 # whether we seem to be in a 2s-complement world.
595 if test -z "$CROSS_COMPILE"; then
596 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
597 [AC_RUN_IFELSE([AC_LANG_SOURCE(
598 [[int main () { int problem = ((-99) != (~99)+1);
599 return problem ? 1 : 0; }]])],
600        [tor_cv_twos_complement=yes],
601        [tor_cv_twos_complement=no],
602        [tor_cv_twos_complement=cross])])
604 else
605   # Cross-compiling; let's hope that the target isn't raving mad.
606   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
607   tor_cv_twos_complement=yes
610 if test $tor_cv_twos_complement = yes; then
611   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
612             [Define to 1 iff we represent negative integers with two's complement])
615 # Whether we should use the dmalloc memory allocation debugging library.
616 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
617 AC_ARG_WITH(dmalloc,
618 [  --with-dmalloc          Use debug memory allocation library. ],
619 [if [[ "$withval" = "yes" ]]; then
620   dmalloc=1
621   AC_MSG_RESULT(yes)
622 else
623   dmalloc=1
624   AC_MSG_RESULT(no)
625 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
628 if [[ $dmalloc -eq 1 ]]; then
629   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
630   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
631   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
632   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
635 # Allow user to specify an alternate syslog facility
636 AC_ARG_WITH(syslog-facility,
637 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
638 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
639 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
640 AC_SUBST(LOGFACILITY)
642 # Check for gethostbyname_r in all its glorious incompatible versions.
643 #   (This logic is based on that in Python's configure.in)
644 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
645   [Define this if you have any gethostbyname_r()])
647 AC_CHECK_FUNC(gethostbyname_r, [
648   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
649   OLD_CFLAGS=$CFLAGS
650   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
651   AC_TRY_COMPILE([
652 #include <netdb.h>
653   ], [
654     char *cp1, *cp2;
655     struct hostent *h1, *h2;
656     int i1, i2;
657     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
658   ], [
659     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
660     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
661      [Define this if gethostbyname_r takes 6 arguments])
662     AC_MSG_RESULT(6)
663   ], [
664     AC_TRY_COMPILE([
665 #include <netdb.h>
666     ], [
667       char *cp1, *cp2;
668       struct hostent *h1;
669       int i1, i2;
670       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
671     ], [
672       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
673       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
674         [Define this if gethostbyname_r takes 5 arguments])
675       AC_MSG_RESULT(5)
676    ], [
677       AC_TRY_COMPILE([
678 #include <netdb.h>
679      ], [
680        char *cp1;
681        struct hostent *h1;
682        struct hostent_data hd;
683        (void) gethostbyname_r(cp1,h1,&hd);
684      ], [
685        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
686        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
687          [Define this if gethostbyname_r takes 3 arguments])
688        AC_MSG_RESULT(3)
689      ], [
690        AC_MSG_RESULT(0)
691      ])
692   ])
693  ])
694  CFLAGS=$OLD_CFLAGS
697 AC_CACHE_CHECK([whether the C compiler supports __func__],
698   ac_cv_have_func_macro,
699   AC_COMPILE_IFELSE([
700 #include <stdio.h>
701 int main(int c, char **v) { puts(__func__); }],
702   ac_cv_have_func_macro=yes,
703   ac_cv_have_func_macro=no))
705 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
706   ac_cv_have_FUNC_macro,
707   AC_COMPILE_IFELSE([
708 #include <stdio.h>
709 int main(int c, char **v) { puts(__FUNC__); }],
710   ac_cv_have_FUNC_macro=yes,
711   ac_cv_have_FUNC_macro=no))
713 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
714   ac_cv_have_FUNCTION_macro,
715   AC_COMPILE_IFELSE([
716 #include <stdio.h>
717 int main(int c, char **v) { puts(__FUNCTION__); }],
718   ac_cv_have_FUNCTION_macro=yes,
719   ac_cv_have_FUNCTION_macro=no))
721 if test $ac_cv_have_func_macro = 'yes'; then
722   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
725 if test $ac_cv_have_FUNC_macro = 'yes'; then
726   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
729 if test $ac_cv_have_FUNCTION_macro = 'yes'; then
730   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
731            [Defined if the compiler supports __FUNCTION__])
734 # $prefix stores the value of the --prefix command line option, or
735 # NONE if the option wasn't set.  In the case that it wasn't set, make
736 # it be the default, so that we can use it to expand directories now.
737 if test "x$prefix" = "xNONE"; then
738   prefix=$ac_default_prefix
741 # and similarly for $exec_prefix
742 if test "x$exec_prefix" = "xNONE"; then
743   exec_prefix=$prefix
746 if test "x$CONFDIR" = "x"; then
747   CONFDIR=`eval echo $sysconfdir/tor`
749 AC_SUBST(CONFDIR)
750 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
751 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
753 BINDIR=`eval echo $bindir`
754 AC_SUBST(BINDIR)
756 LOCALSTATEDIR=`eval echo $localstatedir`
757 AC_SUBST(LOCALSTATEDIR)
758 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
759 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
761 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
762 # than autoconf's macros like.
763 if test $ac_cv_c_compiler_gnu = yes; then
764   CFLAGS="$CFLAGS -Wall -g -O2"
765 else
766   CFLAGS="$CFLAGS -g -O"
768 # Add some more warnings which we use in the cvs version but not in the
769 # released versions.  (Some relevant gcc versions can't handle these.)
770 #CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Winit-self -Wwrite-strings -Waggregate-return -Wmissing-declarations -Wmissing-field-initializers -Wredundant-decls -Winline -Wnested-externs -Wswitch-enums"
771 # Add these in when you feel like fun.
772 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement -Wold-style-definition"
774 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)
776 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
777   ./contrib/updateVersions.pl