r12840@catbus: nickm | 2007-05-21 21:39:23 -0400
[tor.git] / configure.in
bloba552b55f8da839a620dd69853d33714aa4312ff7
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.13)
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 dnl Enable C99 when compiling with MIPSpro
161 AC_MSG_CHECKING([for MIPSpro compiler])
162 AC_TRY_COMPILE([], [
163 #if (defined(__sgi) && defined(_COMPILER_VERSION))
164 #error
165   return x(y);
166 #endif
168 bmipspro=false; AC_MSG_RESULT([no]),
169 bmipspro=true; AC_MSG_RESULT([yes]))
171 if test $bmipspro = true; then
172   CFLAGS="$CFLAGS -c99"
175 AC_SEARCH_LIBS(socket, [socket])
176 AC_SEARCH_LIBS(gethostbyname, [nsl])
177 AC_SEARCH_LIBS(dlopen, [dl])
178 AC_SEARCH_LIBS(inet_aton, [resolv])
180 if test $enable_threads = "yes"; then
181   AC_SEARCH_LIBS(pthread_create, [pthread])
182   AC_SEARCH_LIBS(pthread_detach, [pthread])
185 dnl -------------------------------------------------------------------
186 dnl Check for functions before libevent, since libevent-1.2 apparently
187 dnl exports strlcpy without defining it in a header.
189 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r)
191 if test $enable_threads = "yes"; then
192   AC_CHECK_HEADERS(pthread.h)
193   AC_CHECK_FUNCS(pthread_create)
196 dnl ------------------------------------------------------
197 dnl Where do you live, libevent?  And how do we call you?
199 dnl This is a disgusting hack so we safely include recent libevent headers.
200 AC_CHECK_TYPE(u_int64_t, unsigned long long)
201 AC_CHECK_TYPE(u_int32_t, unsigned long)
202 AC_CHECK_TYPE(u_int16_t, unsigned short)
203 AC_CHECK_TYPE(u_int8_t, unsigned char)
205 AC_CACHE_CHECK([for libevent directory], tor_cv_libevent_dir, [
206   saved_LIBS="$LIBS"
207   saved_LDFLAGS="$LDFLAGS"
208   saved_CPPFLAGS="$CPPFLAGS"
209   le_found=no
210   for ledir in $trylibeventdir "" $prefix /usr/local /usr/pkg ; do
211     LDFLAGS="$saved_LDFLAGS"
213     if test $bwin32 = true; then
214         LIBS="$saved_LIBS -levent -lws2_32"
215     else
216         LIBS="$saved_LIBS -levent"
217     fi
219     # Skip the directory if it isn't there.
220     if test ! -z "$ledir" -a ! -d "$ledir" ; then
221        continue;
222     fi
223     if test ! -z "$ledir" ; then
224       if test -d "$ledir/lib" ; then
225         LDFLAGS="-L$ledir/lib $LDFLAGS"
226       else
227         LDFLAGS="-L$ledir $LDFLAGS"
228       fi
229       if test -d "$ledir/include" ; then
230         CPPFLAGS="-I$ledir/include $CPPFLAGS"
231       else
232         CPPFLAGS="-I$ledir $CPPFLAGS"
233       fi
234     fi
235     # Can I compile and link it?
236     AC_TRY_LINK([#include <sys/time.h>
237 #include <sys/types.h>
238 #include <event.h>], [ event_init(); ],
239        [ libevent_linked=yes ], [ libevent_linked=no ])
240     if test $libevent_linked = yes; then
241        if test ! -z "$ledir" ; then
242          tor_cv_libevent_dir=$ledir
243        else
244          tor_cv_libevent_dir="(system)"
245        fi
246        le_found=yes
247        break
248     fi
249   done
250   LIBS="$saved_LIBS"
251   LDFLAGS="$saved_LDFLAGS"
252   CPPFLAGS="$saved_CPPFLAGS"
253   if test $le_found = no ; then
254     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
255   fi
258 if test $bwin32 = true; then
259 LIBS="$LIBS -levent -lws2_32"
260 else
261 LIBS="$LIBS -levent"
263 if test $tor_cv_libevent_dir != "(system)"; then
264   if test -d "$tor_cv_libevent_dir/lib" ; then
265     LDFLAGS="-L$tor_cv_libevent_dir/lib $LDFLAGS"
266     le_libdir="$tor_cv_libevent_dir/lib"
267   else
268     LDFLAGS="-L$tor_cv_libevent_dir $LDFLAGS"
269     le_libdir="$tor_cv_libevent_dir"
270   fi
271   if test -d "$tor_cv_libevent_dir/include" ; then
272     CPPFLAGS="-I$tor_cv_libevent_dir/include $CPPFLAGS"
273   else
274     CPPFLAGS="-I$tor_cv_libevent_dir $CPPFLAGS"
275   fi
278 if test -z "$CROSS_COMPILE"; then
279 AC_CACHE_CHECK([whether we need extra options to link libevent],
280                tor_cv_libevent_linker_option, [
281     saved_LDFLAGS="$LDFLAGS"
282     le_runs=no
283     linked_with=nothing
284     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" "-Wl,-rpath,$le_libdir" ; do
285       LDFLAGS="$le_extra $saved_LDFLAGS"
286       AC_TRY_RUN([void *event_init(void);
287                 int main(int c, char **v) {
288                    event_init(); return 0;
289                 }],
290                 libevent_runs=yes, libevent_runs=no, libevent_runs=cross)
291       if test $libevent_runs != no ; then
292         if test -z "$le_extra" ; then
293           tor_cv_libevent_linker_option='(none)'
294         else
295           tor_cv_libevent_linker_option=$le_extra
296         fi
297         le_runs=yes
298         break
299       fi
300     done
301     if test $le_runs = no ; then
302       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?])
303     fi
304     LDFLAGS="$saved_LDFLAGS"
307 if test $tor_cv_libevent_linker_option != '(none)' ; then
308    LDFLAGS="$tor_cv_libevent_linker_option $LDFLAGS"
312 dnl Now check for particular libevent functions.
313 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
315 dnl ------------------------------------------------------
316 dnl Where do you live, openssl?  And how do we call you?
318 AC_CACHE_CHECK([for OpenSSL directory], tor_cv_openssl_dir, [
319   saved_LIBS="$LIBS"
320   saved_LDFLAGS="$LDFLAGS"
321   saved_CPPFLAGS="$CPPFLAGS"
322   ssl_found=no
323   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
324     LDFLAGS="$saved_LDFLAGS"
326     if test $bwin32 = true; then
327       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
328     else
329       LIBS="$saved_LIBS -lssl -lcrypto"
330     fi
332     # Skip the directory if it isn't there.
333     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
334        continue;
335     fi
336     if test ! -z "$ssldir" ; then
337       if test -d "$ssldir/lib" ; then
338         LDFLAGS="-L$ssldir/lib $LDFLAGS"
339       else
340         LDFLAGS="-L$ssldir $LDFLAGS"
341       fi
342       if test -d "$ssldir/include" ; then
343         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
344       else
345         CPPFLAGS="-I$ssldir $CPPFLAGS"
346       fi
347     fi
348     # Can I link it?
349     AC_TRY_LINK([#include <openssl/rand.h>],
350        [ RAND_add((void*)0,0,0); ],
351        [ openssl_linked=yes ], [ openssl_linked=no ])
352     if test $openssl_linked = yes; then
353        if test ! -z "$ssldir" ; then
354          tor_cv_openssl_dir=$ssldir
355        else
356          tor_cv_openssl_dir="(system)"
357        fi
358        ssl_found=yes
359        break
360     fi
361   done
362   LIBS="$saved_LIBS"
363   LDFLAGS="$saved_LDFLAGS"
364   CPPFLAGS="$saved_CPPFLAGS"
365   if test $ssl_found = no ; then
366     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
367   fi
370 if test $bwin32 = true; then
371 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
372 else
373 LIBS="$LIBS -lssl -lcrypto"
376 if test "$tor_cv_openssl_dir" != "(system)"; then
377   if test -d "$tor_cv_openssl_dir/lib" ; then
378     LDFLAGS="-L$tor_cv_openssl_dir/lib $LDFLAGS"
379     ssl_libdir="$tor_cv_openssl_dir/lib"
380   else
381     LDFLAGS="-L$tor_cv_openssl_dir $LDFLAGS"
382     ssl_libdir="$tor_cv_openssl_dir"
383   fi
384   if test -d "$tor_cv_openssl_dir/include" ; then
385     CPPFLAGS="-I$tor_cv_openssl_dir/include $CPPFLAGS"
386   else
387     CPPFLAGS="-I$tor_cv_openssl_dir $CPPFLAGS"
388   fi
391 if test -z "$CROSS_COMPILE"
392 then
393 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
394                tor_cv_openssl_linker_option, [
395     saved_LDFLAGS="$LDFLAGS"
396     ssl_runs=no
397     linked_with=nothing
398     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
399       LDFLAGS="$ssl_extra $saved_LDFLAGS"
400       AC_TRY_RUN([
401 #include <string.h>
402 #include <openssl/rand.h>
403 int main(void)
405         char a[2048];
406         memset(a, 0, sizeof(a));
407         RAND_add(a, sizeof(a), sizeof(a));
408         return(RAND_status() <= 0);
410                         ],
411                 openssl_runs=yes, openssl_runs=no, openssl_runs=cross)
412       if test $openssl_runs != no ; then
413         if test "$linked_with" = nothing; then
414            linked_with="$ssl_extra"
415         fi
416         AC_TRY_RUN([
417 #include <openssl/opensslv.h>
418 #include <openssl/crypto.h>
419 int main(void) {
420 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
422         right_version=yes, right_version=no)
423         if test "$right_version" = yes; then
424           if test -z "$ssl_extra" ; then
425             tor_cv_openssl_linker_option='(none)'
426           else
427             tor_cv_openssl_linker_option=$ssl_extra
428           fi
429           ssl_runs=yes
430           break
431         fi
432      fi
433     done
434     if test $ssl_runs = no ; then
435       if test "$linked_with" = 'nothing' ; then
436         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?])
437       else
438         if test -z "$linked_with" ; then
439             tor_cv_openssl_linker_option='(none)'
440         else
441             tor_cv_openssl_linker_option=$linked_with
442         fi
443         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.])
444       fi
445     fi
446     LDFLAGS="$saved_LDFLAGS"
449 if test "$tor_cv_openssl_linker_option" != '(none)' ; then
450    LDFLAGS="$tor_cv_openssl_linker_option $LDFLAGS"
454 dnl Make sure to enable support for large off_t if avalable.
456 AC_SYS_LARGEFILE
458 dnl The warning message here is no longer strictly accurate.
460 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))
462 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h)
464 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
465 [#ifdef HAVE_SYS_TYPES_H
466 #include <sys/types.h>
467 #endif
468 #ifdef HAVE_SYS_TIME_H
469 #include <sys/time.h>
470 #else
471   struct timeval {
472     long tv_sec;
473     long tv_usec;
474  };
475 #endif])
477 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.))
479 dnl These headers are not essential
481 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)
483 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
484 [#ifdef HAVE_SYS_TYPES_H
485 #include <sys/types.h>
486 #endif
487 #ifdef HAVE_SYS_SOCKET_H
488 #include <sys/socket.h>
489 #endif])
490 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
491 [#ifdef HAVE_SYS_TYPES_H
492 #include <sys/types.h>
493 #endif
494 #ifdef HAVE_SYS_SOCKET_H
495 #include <sys/socket.h>
496 #endif
497 #ifdef HAVE_NET_IF_H
498 #include <net/if.h>
499 #endif])
500 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
501         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
502 [#ifdef HAVE_SYS_TYPES_H
503 #include <sys/types.h>
504 #endif
505 #ifdef HAVE_SYS_SOCKET_H
506 #include <sys/socket.h>
507 #endif])
509 if test x$transparent = xtrue ; then
510    transparent_ok=0
511    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
512      transparent_ok=1
513    fi
514    if test x$linux_netfilter_ipv4 = x1 ; then
515      transparent_ok=1
516    fi
517    if test x$transparent_ok = x1 ; then
518      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
519      case $host in
520        *-*-openbsd*)
521          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
522      esac
523    else
524      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
525    fi
528 AC_FUNC_FSEEKO
530 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
531 [#ifdef HAVE_SYS_TYPES_H
532 #include <sys/types.h>
533 #endif
534 #ifdef HAVE_SYS_TIME_H
535 #include <sys/time.h>
536 #endif])
538 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
539 dnl Watch out.
541 AC_CHECK_SIZEOF(int8_t)
542 AC_CHECK_SIZEOF(int16_t)
543 AC_CHECK_SIZEOF(int32_t)
544 AC_CHECK_SIZEOF(int64_t)
545 AC_CHECK_SIZEOF(uint8_t)
546 AC_CHECK_SIZEOF(uint16_t)
547 AC_CHECK_SIZEOF(uint32_t)
548 AC_CHECK_SIZEOF(uint64_t)
549 AC_CHECK_SIZEOF(intptr_t)
550 AC_CHECK_SIZEOF(uintptr_t)
552 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
554 AC_CHECK_SIZEOF(char)
555 AC_CHECK_SIZEOF(short)
556 AC_CHECK_SIZEOF(int)
557 AC_CHECK_SIZEOF(long)
558 AC_CHECK_SIZEOF(long long)
559 AC_CHECK_SIZEOF(__int64)
560 AC_CHECK_SIZEOF(void *)
561 AC_CHECK_SIZEOF(time_t)
562 AC_CHECK_SIZEOF(size_t)
564 AC_CHECK_TYPES([uint, u_char])
566 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_storage], , ,
567 [#ifdef HAVE_SYS_TYPES_H
568 #include <sys/types.h>
569 #endif
570 #ifdef HAVE_NETINET_IN_H
571 #include <netinet/in.h>
572 #endif
573 #ifdef HAVE_NETINET_IN6_H
574 #include <netinet/in6.h>
575 #endif
576 #ifdef HAVE_SYS_SOCKET_H
577 #include <sys/socket.h>
578 #endif])
580 if test -z "$CROSS_COMPILE"; then
581 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
582 AC_TRY_RUN([
583 #ifdef HAVE_SYS_TYPES_H
584 #include <sys/types.h>
585 #endif
586 #ifdef HAVE_SYS_TIME_H
587 #include <sys/time.h>
588 #endif
589 #ifdef HAVE_TIME_H
590 #include <time.h>
591 #endif
592 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
593   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
595 else
596   # Cross-compiling; let's hope the target platform isn't loony.
597   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
598   tor_cv_time_t_signed=yes
601 if test $tor_cv_time_t_signed = yes; then
602   AC_DEFINE([TIME_T_IS_SIGNED], 1,
603             [Define to 1 iff time_t is signed])
606 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
607 #ifdef HAVE_SYS_SOCKET_H
608 #include <sys/socket.h>
609 #endif
612 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
614 AC_CHECK_SIZEOF(cell_t)
616 # Now make sure that NULL can be represented as zero bytes.
617 if test -z "$CROSS_COMPILE"; then
618 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
619 [AC_RUN_IFELSE([AC_LANG_SOURCE(
620 [[#include <stdlib.h>
621 #include <string.h>
622 #include <stdio.h>
623 #ifdef HAVE_STDDEF_H
624 #include <stddef.h>
625 #endif
626 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
627 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
628        [tor_cv_null_is_zero=yes],
629        [tor_cv_null_is_zero=no],
630        [tor_cv_null_is_zero=cross])])
632 else
633   # Cross-compiling; let's hope that the target isn't raving mad.
634   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
635   tor_cv_null_is_zero=yes
638 if test $tor_cv_null_is_zero = yes; then
639   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
640             [Define to 1 iff memset(0) sets pointers to NULL])
643 # And what happens when we malloc zero?
645 if test -z "$CROSS_COMPILE"; then
646 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
647 [AC_RUN_IFELSE([AC_LANG_SOURCE(
648 [[#include <stdlib.h>
649 #include <string.h>
650 #include <stdio.h>
651 #ifdef HAVE_STDDEF_H
652 #include <stddef.h>
653 #endif
654 int main () { return malloc(0)?0:1; }]])],
655        [tor_cv_malloc_zero_works=yes],
656        [tor_cv_malloc_zero_works=no],
657        [tor_cv_malloc_zero_works=cross])])
659 else
660   # Cross-compiling; let's hope that the target isn't raving mad.
661   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
662   tor_cv_malloc_zero_works=no
665 if test $tor_cv_malloc_zero_works = yes; then
666   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
667             [Define to 1 iff malloc(0) returns a pointer])
670 # whether we seem to be in a 2s-complement world.
671 if test -z "$CROSS_COMPILE"; then
672 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
673 [AC_RUN_IFELSE([AC_LANG_SOURCE(
674 [[int main () { int problem = ((-99) != (~99)+1);
675 return problem ? 1 : 0; }]])],
676        [tor_cv_twos_complement=yes],
677        [tor_cv_twos_complement=no],
678        [tor_cv_twos_complement=cross])])
680 else
681   # Cross-compiling; let's hope that the target isn't raving mad.
682   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
683   tor_cv_twos_complement=yes
686 if test $tor_cv_twos_complement = yes; then
687   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
688             [Define to 1 iff we represent negative integers with two's complement])
691 # Whether we should use the dmalloc memory allocation debugging library.
692 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
693 AC_ARG_WITH(dmalloc,
694 [  --with-dmalloc          Use debug memory allocation library. ],
695 [if [[ "$withval" = "yes" ]]; then
696   dmalloc=1
697   AC_MSG_RESULT(yes)
698 else
699   dmalloc=1
700   AC_MSG_RESULT(no)
701 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
704 if [[ $dmalloc -eq 1 ]]; then
705   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
706   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
707   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
708   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
711 # Allow user to specify an alternate syslog facility
712 AC_ARG_WITH(syslog-facility,
713 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
714 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
715 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
716 AC_SUBST(LOGFACILITY)
718 # Check for gethostbyname_r in all its glorious incompatible versions.
719 #   (This logic is based on that in Python's configure.in)
720 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
721   [Define this if you have any gethostbyname_r()])
723 AC_CHECK_FUNC(gethostbyname_r, [
724   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
725   OLD_CFLAGS=$CFLAGS
726   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
727   AC_TRY_COMPILE([
728 #include <netdb.h>
729   ], [
730     char *cp1, *cp2;
731     struct hostent *h1, *h2;
732     int i1, i2;
733     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
734   ], [
735     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
736     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
737      [Define this if gethostbyname_r takes 6 arguments])
738     AC_MSG_RESULT(6)
739   ], [
740     AC_TRY_COMPILE([
741 #include <netdb.h>
742     ], [
743       char *cp1, *cp2;
744       struct hostent *h1;
745       int i1, i2;
746       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
747     ], [
748       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
749       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
750         [Define this if gethostbyname_r takes 5 arguments])
751       AC_MSG_RESULT(5)
752    ], [
753       AC_TRY_COMPILE([
754 #include <netdb.h>
755      ], [
756        char *cp1;
757        struct hostent *h1;
758        struct hostent_data hd;
759        (void) gethostbyname_r(cp1,h1,&hd);
760      ], [
761        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
762        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
763          [Define this if gethostbyname_r takes 3 arguments])
764        AC_MSG_RESULT(3)
765      ], [
766        AC_MSG_RESULT(0)
767      ])
768   ])
769  ])
770  CFLAGS=$OLD_CFLAGS
773 AC_CACHE_CHECK([whether the C compiler supports __func__],
774   tor_cv_have_func_macro,
775   AC_COMPILE_IFELSE([
776 #include <stdio.h>
777 int main(int c, char **v) { puts(__func__); }],
778   tor_cv_have_func_macro=yes,
779   tor_cv_have_func_macro=no))
781 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
782   tor_cv_have_FUNC_macro,
783   AC_COMPILE_IFELSE([
784 #include <stdio.h>
785 int main(int c, char **v) { puts(__FUNC__); }],
786   tor_cv_have_FUNC_macro=yes,
787   tor_cv_have_FUNC_macro=no))
789 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
790   tor_cv_have_FUNCTION_macro,
791   AC_COMPILE_IFELSE([
792 #include <stdio.h>
793 int main(int c, char **v) { puts(__FUNCTION__); }],
794   tor_cv_have_FUNCTION_macro=yes,
795   tor_cv_have_FUNCTION_macro=no))
797 if test $tor_cv_have_func_macro = 'yes'; then
798   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
801 if test $tor_cv_have_FUNC_macro = 'yes'; then
802   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
805 if test $tor_cv_have_FUNCTION_macro = 'yes'; then
806   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
807            [Defined if the compiler supports __FUNCTION__])
810 # $prefix stores the value of the --prefix command line option, or
811 # NONE if the option wasn't set.  In the case that it wasn't set, make
812 # it be the default, so that we can use it to expand directories now.
813 if test "x$prefix" = "xNONE"; then
814   prefix=$ac_default_prefix
817 # and similarly for $exec_prefix
818 if test "x$exec_prefix" = "xNONE"; then
819   exec_prefix=$prefix
822 if test "x$CONFDIR" = "x"; then
823   CONFDIR=`eval echo $sysconfdir/tor`
825 AC_SUBST(CONFDIR)
826 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
827 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
829 BINDIR=`eval echo $bindir`
830 AC_SUBST(BINDIR)
832 LOCALSTATEDIR=`eval echo $localstatedir`
833 AC_SUBST(LOCALSTATEDIR)
834 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
835 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
837 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
838 # than autoconf's macros like.
839 if test $ac_cv_c_compiler_gnu = yes; then
840   CFLAGS="$CFLAGS -Wall -g -O2"
841 else
842   CFLAGS="$CFLAGS -g -O"
843   enable_gcc_warnings=no
846 # Add some more warnings which we use in the cvs version but not in the
847 # released versions.  (Some relevant gcc versions can't handle these.)
848 if test x$enable_gcc_warnings = xyes; then
850   AC_TRY_COMPILE([], [
851 #if !defined(__GNUC__) || (__GNUC__ < 4)
852 #error
853 #endif], have_gcc4=yes, have_gcc4=no)
855   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"
857   if test x$have_gcc4 = xyes ; then 
858     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
859     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
860   fi
862 ##This will break the world on some 64-bit architectures
863 # CFLAGS="$CFLAGS -Winline"
867 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)
869 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
870   ./contrib/updateVersions.pl