bump to 0.1.2.17
[tor.git] / configure.in
blob092bc0c4f76c18c17653b848b58c097cbf98797c
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.17)
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_MAKE_SET
88 AC_PROG_RANLIB
90 # The big search for OpenSSL
91 # copied from openssh's configure.ac
92 tryssldir=""
93 AC_ARG_WITH(ssl-dir,
94         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
95         [
96                 if test "x$withval" != "xno" ; then
97                         tryssldir=$withval
98                 fi
99         ]
102 trylibeventdir=""
103 AC_ARG_WITH(libevent-dir,
104        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
105        [
106                 if test "x$withval" != "xno" ; then
107                         trylibeventdir=$withval
108                 fi
109        ]
112 TORUSER=_tor
113 AC_ARG_WITH(tor-user,
114         [  --with-tor-user=NAME    Specify username for tor daemon ],
115         [
116            TORUSER=$withval
117         ]
119 AC_SUBST(TORUSER)
121 TORGROUP=_tor
122 AC_ARG_WITH(tor-group,
123         [  --with-tor-group=NAME   Specify group name for tor daemon ],
124         [
125            TORGROUP=$withval
126         ]
128 AC_SUBST(TORGROUP)
131 dnl If WIN32 is defined and non-zero, we are building for win32
132 AC_MSG_CHECKING([for win32])
133 AC_RUN_IFELSE([
134 int main(int c, char **v) {
135 #ifdef WIN32
136 #if WIN32
137   return 0;
138 #else
139   return 1;
140 #endif
141 #else
142   return 2;
143 #endif
145 bwin32=true; AC_MSG_RESULT([yes]),
146 bwin32=false; AC_MSG_RESULT([no]),
147 bwin32=cross; AC_MSG_RESULT([cross])
150 if test $bwin32 = cross; then
151 AC_MSG_CHECKING([for win32 (cross)])
152 AC_COMPILE_IFELSE([
153 #ifdef WIN32
154 int main(int c, char **v) {return 0;}
155 #else
156 #error
157 int main(int c, char **v) {return x(y);}
158 #endif
160 bwin32=true; AC_MSG_RESULT([yes]),
161 bwin32=false; AC_MSG_RESULT([no]))
164 if test $bwin32 = true; then
165 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
168 dnl Enable C99 when compiling with MIPSpro
169 AC_MSG_CHECKING([for MIPSpro compiler])
170 AC_TRY_COMPILE([], [
171 #if (defined(__sgi) && defined(_COMPILER_VERSION))
172 #error
173   return x(y);
174 #endif
176 bmipspro=false; AC_MSG_RESULT([no]),
177 bmipspro=true; AC_MSG_RESULT([yes]))
179 if test $bmipspro = true; then
180   CFLAGS="$CFLAGS -c99"
183 AC_SEARCH_LIBS(socket, [socket])
184 AC_SEARCH_LIBS(gethostbyname, [nsl])
185 AC_SEARCH_LIBS(dlopen, [dl])
186 AC_SEARCH_LIBS(inet_aton, [resolv])
188 if test $enable_threads = "yes"; then
189   AC_SEARCH_LIBS(pthread_create, [pthread])
190   AC_SEARCH_LIBS(pthread_detach, [pthread])
193 dnl -------------------------------------------------------------------
194 dnl Check for functions before libevent, since libevent-1.2 apparently
195 dnl exports strlcpy without defining it in a header.
197 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r)
199 if test $enable_threads = "yes"; then
200   AC_CHECK_HEADERS(pthread.h)
201   AC_CHECK_FUNCS(pthread_create)
204 dnl ------------------------------------------------------
205 dnl Where do you live, libevent?  And how do we call you?
207 dnl This is a disgusting hack so we safely include recent libevent headers.
208 AC_CHECK_TYPE(u_int64_t, unsigned long long)
209 AC_CHECK_TYPE(u_int32_t, unsigned long)
210 AC_CHECK_TYPE(u_int16_t, unsigned short)
211 AC_CHECK_TYPE(u_int8_t, unsigned char)
213 AC_CACHE_CHECK([for libevent directory], tor_cv_libevent_dir, [
214   saved_LIBS="$LIBS"
215   saved_LDFLAGS="$LDFLAGS"
216   saved_CPPFLAGS="$CPPFLAGS"
217   le_found=no
218   for ledir in $trylibeventdir "" $prefix /usr/local /usr/pkg ; do
219     LDFLAGS="$saved_LDFLAGS"
221     if test $bwin32 = true; then
222         LIBS="$saved_LIBS -levent -lws2_32"
223     else
224         LIBS="$saved_LIBS -levent"
225     fi
227     # Skip the directory if it isn't there.
228     if test ! -z "$ledir" -a ! -d "$ledir" ; then
229        continue;
230     fi
231     if test ! -z "$ledir" ; then
232       if test -d "$ledir/lib" ; then
233         LDFLAGS="-L$ledir/lib $LDFLAGS"
234       else
235         LDFLAGS="-L$ledir $LDFLAGS"
236       fi
237       if test -d "$ledir/include" ; then
238         CPPFLAGS="-I$ledir/include $CPPFLAGS"
239       else
240         CPPFLAGS="-I$ledir $CPPFLAGS"
241       fi
242     fi
243     # Can I compile and link it?
244     AC_TRY_LINK([#include <sys/time.h>
245 #include <sys/types.h>
246 #include <event.h>], [ event_init(); ],
247        [ libevent_linked=yes ], [ libevent_linked=no ])
248     if test $libevent_linked = yes; then
249        if test ! -z "$ledir" ; then
250          tor_cv_libevent_dir=$ledir
251        else
252          tor_cv_libevent_dir="(system)"
253        fi
254        le_found=yes
255        break
256     fi
257   done
258   LIBS="$saved_LIBS"
259   LDFLAGS="$saved_LDFLAGS"
260   CPPFLAGS="$saved_CPPFLAGS"
261   if test $le_found = no ; then
262     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
263   fi
266 if test $bwin32 = true; then
267 LIBS="$LIBS -levent -lws2_32"
268 else
269 LIBS="$LIBS -levent"
271 if test $tor_cv_libevent_dir != "(system)"; then
272   if test -d "$tor_cv_libevent_dir/lib" ; then
273     LDFLAGS="-L$tor_cv_libevent_dir/lib $LDFLAGS"
274     le_libdir="$tor_cv_libevent_dir/lib"
275   else
276     LDFLAGS="-L$tor_cv_libevent_dir $LDFLAGS"
277     le_libdir="$tor_cv_libevent_dir"
278   fi
279   if test -d "$tor_cv_libevent_dir/include" ; then
280     CPPFLAGS="-I$tor_cv_libevent_dir/include $CPPFLAGS"
281   else
282     CPPFLAGS="-I$tor_cv_libevent_dir $CPPFLAGS"
283   fi
286 if test -z "$CROSS_COMPILE"; then
287 AC_CACHE_CHECK([whether we need extra options to link libevent],
288                tor_cv_libevent_linker_option, [
289     saved_LDFLAGS="$LDFLAGS"
290     le_runs=no
291     linked_with=nothing
292     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" "-Wl,-rpath,$le_libdir" ; do
293       LDFLAGS="$le_extra $saved_LDFLAGS"
294       AC_TRY_RUN([void *event_init(void);
295                 int main(int c, char **v) {
296                    event_init(); return 0;
297                 }],
298                 libevent_runs=yes, libevent_runs=no, libevent_runs=cross)
299       if test $libevent_runs != no ; then
300         if test -z "$le_extra" ; then
301           tor_cv_libevent_linker_option='(none)'
302         else
303           tor_cv_libevent_linker_option=$le_extra
304         fi
305         le_runs=yes
306         break
307       fi
308     done
309     if test $le_runs = no ; then
310       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?])
311     fi
312     LDFLAGS="$saved_LDFLAGS"
315 if test $tor_cv_libevent_linker_option != '(none)' ; then
316    LDFLAGS="$tor_cv_libevent_linker_option $LDFLAGS"
320 dnl Now check for particular libevent functions.
321 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
323 dnl ------------------------------------------------------
324 dnl Where do you live, openssl?  And how do we call you?
326 AC_CACHE_CHECK([for OpenSSL directory], tor_cv_openssl_dir, [
327   saved_LIBS="$LIBS"
328   saved_LDFLAGS="$LDFLAGS"
329   saved_CPPFLAGS="$CPPFLAGS"
330   ssl_found=no
331   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
332     LDFLAGS="$saved_LDFLAGS"
334     if test $bwin32 = true; then
335       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
336     else
337       LIBS="$saved_LIBS -lssl -lcrypto"
338     fi
340     # Skip the directory if it isn't there.
341     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
342        continue;
343     fi
344     if test ! -z "$ssldir" ; then
345       if test -d "$ssldir/lib" ; then
346         LDFLAGS="-L$ssldir/lib $LDFLAGS"
347       else
348         LDFLAGS="-L$ssldir $LDFLAGS"
349       fi
350       if test -d "$ssldir/include" ; then
351         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
352       else
353         CPPFLAGS="-I$ssldir $CPPFLAGS"
354       fi
355     fi
356     # Can I link it?
357     AC_TRY_LINK([#include <openssl/rand.h>],
358        [ RAND_add((void*)0,0,0); ],
359        [ openssl_linked=yes ], [ openssl_linked=no ])
360     if test $openssl_linked = yes; then
361        if test ! -z "$ssldir" ; then
362          tor_cv_openssl_dir=$ssldir
363        else
364          tor_cv_openssl_dir="(system)"
365        fi
366        ssl_found=yes
367        break
368     fi
369   done
370   LIBS="$saved_LIBS"
371   LDFLAGS="$saved_LDFLAGS"
372   CPPFLAGS="$saved_CPPFLAGS"
373   if test $ssl_found = no ; then
374     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
375   fi
378 if test $bwin32 = true; then
379 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
380 else
381 LIBS="$LIBS -lssl -lcrypto"
384 if test "$tor_cv_openssl_dir" != "(system)"; then
385   if test -d "$tor_cv_openssl_dir/lib" ; then
386     LDFLAGS="-L$tor_cv_openssl_dir/lib $LDFLAGS"
387     ssl_libdir="$tor_cv_openssl_dir/lib"
388   else
389     LDFLAGS="-L$tor_cv_openssl_dir $LDFLAGS"
390     ssl_libdir="$tor_cv_openssl_dir"
391   fi
392   if test -d "$tor_cv_openssl_dir/include" ; then
393     CPPFLAGS="-I$tor_cv_openssl_dir/include $CPPFLAGS"
394   else
395     CPPFLAGS="-I$tor_cv_openssl_dir $CPPFLAGS"
396   fi
399 if test -z "$CROSS_COMPILE"
400 then
401 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
402                tor_cv_openssl_linker_option, [
403     saved_LDFLAGS="$LDFLAGS"
404     ssl_runs=no
405     linked_with=nothing
406     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
407       LDFLAGS="$ssl_extra $saved_LDFLAGS"
408       AC_TRY_RUN([
409 #include <string.h>
410 #include <openssl/rand.h>
411 int main(void)
413         char a[2048];
414         memset(a, 0, sizeof(a));
415         RAND_add(a, sizeof(a), sizeof(a));
416         return(RAND_status() <= 0);
418                         ],
419                 openssl_runs=yes, openssl_runs=no, openssl_runs=cross)
420       if test $openssl_runs != no ; then
421         if test "$linked_with" = nothing; then
422            linked_with="$ssl_extra"
423         fi
424         AC_TRY_RUN([
425 #include <openssl/opensslv.h>
426 #include <openssl/crypto.h>
427 int main(void) {
428 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
430         right_version=yes, right_version=no)
431         if test "$right_version" = yes; then
432           if test -z "$ssl_extra" ; then
433             tor_cv_openssl_linker_option='(none)'
434           else
435             tor_cv_openssl_linker_option=$ssl_extra
436           fi
437           ssl_runs=yes
438           break
439         fi
440      fi
441     done
442     if test $ssl_runs = no ; then
443       if test "$linked_with" = 'nothing' ; then
444         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?])
445       else
446         if test -z "$linked_with" ; then
447             tor_cv_openssl_linker_option='(none)'
448         else
449             tor_cv_openssl_linker_option=$linked_with
450         fi
451         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.])
452       fi
453     fi
454     LDFLAGS="$saved_LDFLAGS"
457 if test "$tor_cv_openssl_linker_option" != '(none)' ; then
458    LDFLAGS="$tor_cv_openssl_linker_option $LDFLAGS"
462 dnl Make sure to enable support for large off_t if avalable.
464 AC_SYS_LARGEFILE
466 dnl The warning message here is no longer strictly accurate.
468 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))
470 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h)
472 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
473 [#ifdef HAVE_SYS_TYPES_H
474 #include <sys/types.h>
475 #endif
476 #ifdef HAVE_SYS_TIME_H
477 #include <sys/time.h>
478 #else
479   struct timeval {
480     long tv_sec;
481     long tv_usec;
482  };
483 #endif])
485 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.))
487 dnl These headers are not essential
489 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)
491 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
492 [#ifdef HAVE_SYS_TYPES_H
493 #include <sys/types.h>
494 #endif
495 #ifdef HAVE_SYS_SOCKET_H
496 #include <sys/socket.h>
497 #endif])
498 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
499 [#ifdef HAVE_SYS_TYPES_H
500 #include <sys/types.h>
501 #endif
502 #ifdef HAVE_SYS_SOCKET_H
503 #include <sys/socket.h>
504 #endif
505 #ifdef HAVE_NET_IF_H
506 #include <net/if.h>
507 #endif])
508 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
509         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
510 [#ifdef HAVE_SYS_TYPES_H
511 #include <sys/types.h>
512 #endif
513 #ifdef HAVE_SYS_SOCKET_H
514 #include <sys/socket.h>
515 #endif])
517 if test x$transparent = xtrue ; then
518    transparent_ok=0
519    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
520      transparent_ok=1
521    fi
522    if test x$linux_netfilter_ipv4 = x1 ; then
523      transparent_ok=1
524    fi
525    if test x$transparent_ok = x1 ; then
526      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
527      case $host in
528        *-*-openbsd*)
529          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
530      esac
531    else
532      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
533    fi
536 AC_FUNC_FSEEKO
538 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
539 [#ifdef HAVE_SYS_TYPES_H
540 #include <sys/types.h>
541 #endif
542 #ifdef HAVE_SYS_TIME_H
543 #include <sys/time.h>
544 #endif])
546 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
547 dnl Watch out.
549 AC_CHECK_SIZEOF(int8_t)
550 AC_CHECK_SIZEOF(int16_t)
551 AC_CHECK_SIZEOF(int32_t)
552 AC_CHECK_SIZEOF(int64_t)
553 AC_CHECK_SIZEOF(uint8_t)
554 AC_CHECK_SIZEOF(uint16_t)
555 AC_CHECK_SIZEOF(uint32_t)
556 AC_CHECK_SIZEOF(uint64_t)
557 AC_CHECK_SIZEOF(intptr_t)
558 AC_CHECK_SIZEOF(uintptr_t)
560 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
562 AC_CHECK_SIZEOF(char)
563 AC_CHECK_SIZEOF(short)
564 AC_CHECK_SIZEOF(int)
565 AC_CHECK_SIZEOF(long)
566 AC_CHECK_SIZEOF(long long)
567 AC_CHECK_SIZEOF(__int64)
568 AC_CHECK_SIZEOF(void *)
569 AC_CHECK_SIZEOF(time_t)
570 AC_CHECK_SIZEOF(size_t)
572 AC_CHECK_TYPES([uint, u_char])
574 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_storage], , ,
575 [#ifdef HAVE_SYS_TYPES_H
576 #include <sys/types.h>
577 #endif
578 #ifdef HAVE_NETINET_IN_H
579 #include <netinet/in.h>
580 #endif
581 #ifdef HAVE_NETINET_IN6_H
582 #include <netinet/in6.h>
583 #endif
584 #ifdef HAVE_SYS_SOCKET_H
585 #include <sys/socket.h>
586 #endif])
588 if test -z "$CROSS_COMPILE"; then
589 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
590 AC_TRY_RUN([
591 #ifdef HAVE_SYS_TYPES_H
592 #include <sys/types.h>
593 #endif
594 #ifdef HAVE_SYS_TIME_H
595 #include <sys/time.h>
596 #endif
597 #ifdef HAVE_TIME_H
598 #include <time.h>
599 #endif
600 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
601   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
603 else
604   # Cross-compiling; let's hope the target platform isn't loony.
605   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
606   tor_cv_time_t_signed=yes
609 if test $tor_cv_time_t_signed = yes; then
610   AC_DEFINE([TIME_T_IS_SIGNED], 1,
611             [Define to 1 iff time_t is signed])
614 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
615 #ifdef HAVE_SYS_SOCKET_H
616 #include <sys/socket.h>
617 #endif
620 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
622 AC_CHECK_SIZEOF(cell_t)
624 # Now make sure that NULL can be represented as zero bytes.
625 if test -z "$CROSS_COMPILE"; then
626 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
627 [AC_RUN_IFELSE([AC_LANG_SOURCE(
628 [[#include <stdlib.h>
629 #include <string.h>
630 #include <stdio.h>
631 #ifdef HAVE_STDDEF_H
632 #include <stddef.h>
633 #endif
634 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
635 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
636        [tor_cv_null_is_zero=yes],
637        [tor_cv_null_is_zero=no],
638        [tor_cv_null_is_zero=cross])])
640 else
641   # Cross-compiling; let's hope that the target isn't raving mad.
642   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
643   tor_cv_null_is_zero=yes
646 if test $tor_cv_null_is_zero = yes; then
647   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
648             [Define to 1 iff memset(0) sets pointers to NULL])
651 # And what happens when we malloc zero?
653 if test -z "$CROSS_COMPILE"; then
654 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
655 [AC_RUN_IFELSE([AC_LANG_SOURCE(
656 [[#include <stdlib.h>
657 #include <string.h>
658 #include <stdio.h>
659 #ifdef HAVE_STDDEF_H
660 #include <stddef.h>
661 #endif
662 int main () { return malloc(0)?0:1; }]])],
663        [tor_cv_malloc_zero_works=yes],
664        [tor_cv_malloc_zero_works=no],
665        [tor_cv_malloc_zero_works=cross])])
667 else
668   # Cross-compiling; let's hope that the target isn't raving mad.
669   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
670   tor_cv_malloc_zero_works=no
673 if test $tor_cv_malloc_zero_works = yes; then
674   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
675             [Define to 1 iff malloc(0) returns a pointer])
678 # whether we seem to be in a 2s-complement world.
679 if test -z "$CROSS_COMPILE"; then
680 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
681 [AC_RUN_IFELSE([AC_LANG_SOURCE(
682 [[int main () { int problem = ((-99) != (~99)+1);
683 return problem ? 1 : 0; }]])],
684        [tor_cv_twos_complement=yes],
685        [tor_cv_twos_complement=no],
686        [tor_cv_twos_complement=cross])])
688 else
689   # Cross-compiling; let's hope that the target isn't raving mad.
690   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
691   tor_cv_twos_complement=yes
694 if test $tor_cv_twos_complement = yes; then
695   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
696             [Define to 1 iff we represent negative integers with two's complement])
699 # Whether we should use the dmalloc memory allocation debugging library.
700 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
701 AC_ARG_WITH(dmalloc,
702 [  --with-dmalloc          Use debug memory allocation library. ],
703 [if [[ "$withval" = "yes" ]]; then
704   dmalloc=1
705   AC_MSG_RESULT(yes)
706 else
707   dmalloc=1
708   AC_MSG_RESULT(no)
709 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
712 if [[ $dmalloc -eq 1 ]]; then
713   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
714   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
715   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
716   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
719 # Allow user to specify an alternate syslog facility
720 AC_ARG_WITH(syslog-facility,
721 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
722 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
723 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
724 AC_SUBST(LOGFACILITY)
726 # Check for gethostbyname_r in all its glorious incompatible versions.
727 #   (This logic is based on that in Python's configure.in)
728 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
729   [Define this if you have any gethostbyname_r()])
731 AC_CHECK_FUNC(gethostbyname_r, [
732   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
733   OLD_CFLAGS=$CFLAGS
734   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
735   AC_TRY_COMPILE([
736 #include <netdb.h>
737   ], [
738     char *cp1, *cp2;
739     struct hostent *h1, *h2;
740     int i1, i2;
741     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
742   ], [
743     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
744     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
745      [Define this if gethostbyname_r takes 6 arguments])
746     AC_MSG_RESULT(6)
747   ], [
748     AC_TRY_COMPILE([
749 #include <netdb.h>
750     ], [
751       char *cp1, *cp2;
752       struct hostent *h1;
753       int i1, i2;
754       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
755     ], [
756       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
757       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
758         [Define this if gethostbyname_r takes 5 arguments])
759       AC_MSG_RESULT(5)
760    ], [
761       AC_TRY_COMPILE([
762 #include <netdb.h>
763      ], [
764        char *cp1;
765        struct hostent *h1;
766        struct hostent_data hd;
767        (void) gethostbyname_r(cp1,h1,&hd);
768      ], [
769        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
770        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
771          [Define this if gethostbyname_r takes 3 arguments])
772        AC_MSG_RESULT(3)
773      ], [
774        AC_MSG_RESULT(0)
775      ])
776   ])
777  ])
778  CFLAGS=$OLD_CFLAGS
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 __FUNC__],
790   tor_cv_have_FUNC_macro,
791   AC_COMPILE_IFELSE([
792 #include <stdio.h>
793 int main(int c, char **v) { puts(__FUNC__); }],
794   tor_cv_have_FUNC_macro=yes,
795   tor_cv_have_FUNC_macro=no))
797 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
798   tor_cv_have_FUNCTION_macro,
799   AC_COMPILE_IFELSE([
800 #include <stdio.h>
801 int main(int c, char **v) { puts(__FUNCTION__); }],
802   tor_cv_have_FUNCTION_macro=yes,
803   tor_cv_have_FUNCTION_macro=no))
805 if test $tor_cv_have_func_macro = 'yes'; then
806   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
809 if test $tor_cv_have_FUNC_macro = 'yes'; then
810   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
813 if test $tor_cv_have_FUNCTION_macro = 'yes'; then
814   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
815            [Defined if the compiler supports __FUNCTION__])
818 # $prefix stores the value of the --prefix command line option, or
819 # NONE if the option wasn't set.  In the case that it wasn't set, make
820 # it be the default, so that we can use it to expand directories now.
821 if test "x$prefix" = "xNONE"; then
822   prefix=$ac_default_prefix
825 # and similarly for $exec_prefix
826 if test "x$exec_prefix" = "xNONE"; then
827   exec_prefix=$prefix
830 if test "x$CONFDIR" = "x"; then
831   CONFDIR=`eval echo $sysconfdir/tor`
833 AC_SUBST(CONFDIR)
834 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
835 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
837 BINDIR=`eval echo $bindir`
838 AC_SUBST(BINDIR)
840 LOCALSTATEDIR=`eval echo $localstatedir`
841 AC_SUBST(LOCALSTATEDIR)
842 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
843 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
845 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
846 # than autoconf's macros like.
847 if test $ac_cv_c_compiler_gnu = yes; then
848   CFLAGS="$CFLAGS -Wall -g -O2"
849 else
850   CFLAGS="$CFLAGS -g -O"
851   enable_gcc_warnings=no
854 # Add some more warnings which we use in the cvs version but not in the
855 # released versions.  (Some relevant gcc versions can't handle these.)
856 if test x$enable_gcc_warnings = xyes; then
858   AC_TRY_COMPILE([], [
859 #if !defined(__GNUC__) || (__GNUC__ < 4)
860 #error
861 #endif], have_gcc4=yes, have_gcc4=no)
863   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"
865   if test x$have_gcc4 = xyes ; then 
866     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
867     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
868   fi
870 ##This will break the world on some 64-bit architectures
871 # CFLAGS="$CFLAGS -Winline"
875 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)
877 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
878   ./contrib/updateVersions.pl