tweaks
[tor.git] / configure.in
blobf177ad7386d46e34d04d530a37ed946d3620a35a
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(threads,
23      AC_HELP_STRING(--disable-threads, disable multi-threading support))
25 if test x$enable_threads = x; then
26    case $host in
27     *-*-netbsd* | *-*-openbsd* )
28      # Don't try multithreading on netbsd -- there is no threadsafe DNS
29      # lookup function there.
30      AC_MSG_NOTICE([You are running OpenBSD or NetBSD; I am assuming that
31 getaddrinfo is not threadsafe here, so I will disable threads.])
32      enable_threads="no";;
33     *-*-solaris* )
34      # Don't try multithreading on solaris -- cpuworkers seem to lock.
35      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
36 cpu workers lock up here, so I will disable threads.])
37      enable_threads="no";;
38     *)
39      enable_threads="yes";;
40    esac
43 if test $enable_threads = "yes"; then
44   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
47 AC_ARG_ENABLE(eventdns,
48      AC_HELP_STRING(--enable-eventdns, enable asynchronous dns module),
49      [case "${enableval}" in
50         yes) eventdns=true ;;
51         no)  eventdns=false ;;
52         *) AC_MSG_ERROR(bad value for --enable-eventdns) ;;
53       esac], [eventdns=true])
54 AM_CONDITIONAL(EVENTDNS, test x$eventdns = xtrue)
55 if test x$eventdns = xtrue; then
56    AC_DEFINE([USE_EVENTDNS], 1, "Define to 1 if we'll be using eventdns.c")
59 AC_ARG_ENABLE(transparent,
60      AC_HELP_STRING(--disable-transparent, disable transparent proxy support),
61      [case "${enableval}" in
62         yes) transparent=true ;;
63         no)  transparent=false ;;
64         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
65       esac], [transparent=true])
67 case $host in
68    *-*-solaris* )
69      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
70      ;;
71 esac
73 AC_PROG_CC
74 AC_PROG_MAKE_SET
75 AC_PROG_RANLIB
77 # If WIN32 is defined and non-zero, we are building for win32
78 AC_MSG_CHECKING([for win32])
79 AC_TRY_COMPILE(,
81 #ifdef WIN32
82 #if WIN32
83 //all is well
84 #else
85 #error
86 #endif
87 #else
88 #error
89 #endif
91 bwin32=true; AC_MSG_RESULT([yes]),
92 bwin32=false; AC_MSG_RESULT([no])
95 if test $bwin32 = true; then
97 AC_DEFINE(MS_WINDOWS,1, [Define to 1 if we are building for a Windows platform.])
102 # The big search for OpenSSL
103 # copied from openssh's configure.ac
104 tryssldir=""
105 AC_ARG_WITH(ssl-dir,
106         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
107         [
108                 if test "x$withval" != "xno" ; then
109                         tryssldir=$withval
110                 fi
111         ]
114 trylibeventdir=""
115 AC_ARG_WITH(libevent-dir,
116        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
117        [
118                 if test "x$withval" != "xno" ; then
119                         trylibeventdir=$withval
120                 fi
121        ]
124 TORUSER=_tor
125 AC_ARG_WITH(tor-user,
126         [  --with-tor-user=NAME    Specify username for tor daemon ],
127         [
128            TORUSER=$withval
129         ]
131 AC_SUBST(TORUSER)
133 TORGROUP=_tor
134 AC_ARG_WITH(tor-group,
135         [  --with-tor-group=NAME   Specify group name for tor daemon ],
136         [
137            TORGROUP=$withval
138         ]
140 AC_SUBST(TORGROUP)
142 AC_SEARCH_LIBS(socket, [socket])
143 AC_SEARCH_LIBS(gethostbyname, [nsl])
144 AC_SEARCH_LIBS(dlopen, [dl])
146 if test $enable_threads = "yes"; then
147   AC_SEARCH_LIBS(pthread_create, [pthread])
148   AC_SEARCH_LIBS(pthread_detach, [pthread])
151 dnl ------------------------------------------------------
152 dnl Where do you live, libevent?  And how do we call you?
154 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
155   saved_LIBS="$LIBS"
156   saved_LDFLAGS="$LDFLAGS"
157   saved_CPPFLAGS="$CPPFLAGS"
158   le_found=no
159   for ledir in $trylibeventdir "" $prefix /usr/local ; do
160     LDFLAGS="$saved_LDFLAGS"
162     if test $bwin32 = true; then
163         LIBS="$saved_LIBS -levent -lws2_32"
164     else
165         LIBS="$saved_LIBS -levent"
166     fi
168     # Skip the directory if it isn't there.
169     if test ! -z "$ledir" -a ! -d "$ledir" ; then
170        continue;
171     fi
172     if test ! -z "$ledir" ; then
173       if test -d "$ledir/lib" ; then
174         LDFLAGS="-L$ledir/lib $LDFLAGS"
175       else
176         LDFLAGS="-L$ledir $LDFLAGS"
177       fi
178       if test -d "$ledir/include" ; then
179         CPPFLAGS="-I$ledir/include $CPPFLAGS"
180       else
181         CPPFLAGS="-I$ledir $CPPFLAGS"
182       fi
183     fi
184     # Can I compile and link it?
185     AC_TRY_LINK([#include <sys/time.h>
186 #include <sys/types.h>
187 #include <event.h>], [ event_init(); ],
188        [ libevent_linked=yes ], [ libevent_linked=no ])
189     if test $libevent_linked = yes; then
190        if test ! -z "$ledir" ; then
191          ac_cv_libevent_dir=$ledir
192        else
193          ac_cv_libevent_dir="(system)"
194        fi
195        le_found=yes
196        break
197     fi
198   done
199   LIBS="$saved_LIBS"
200   LDFLAGS="$saved_LDFLAGS"
201   CPPFLAGS="$saved_CPPFLAGS"
202   if test $le_found = no ; then
203     AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
204   fi
207 if test $bwin32 = true; then
208 LIBS="$LIBS -levent -lws2_32"
209 else
210 LIBS="$LIBS -levent"
212 if test $ac_cv_libevent_dir != "(system)"; then
213   if test -d "$ac_cv_libevent_dir/lib" ; then
214     LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
215     le_libdir="$ac_cv_libevent_dir/lib"
216   else
217     LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
218     le_libdir="$ac_cv_libevent_dir"
219   fi
220   if test -d "$ac_cv_libevent_dir/include" ; then
221     CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
222   else
223     CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
224   fi
227 if test -z "$CROSS_COMPILE"; then
228 AC_CACHE_CHECK([whether we need extra options to link libevent],
229                ac_cv_libevent_linker_option, [
230     saved_LDFLAGS="$LDFLAGS"
231     le_runs=no
232     linked_with=nothing
233     for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" ; do
234       LDFLAGS="$le_extra $saved_LDFLAGS"
235       AC_TRY_RUN([void *event_init(void);
236                 int main(int c, char **v) {
237                    event_init(); return 0;
238                 }],
239                 libevent_runs=yes, libevent_runs=no)
240       if test $libevent_runs = yes ; then
241         if test -z "$le_extra" ; then
242           ac_cv_libevent_linker_option='(none)'
243         else
244           ac_cv_libevent_linker_option=$le_extra
245         fi
246         le_runs=yes
247         break
248       fi
249     done
250     if test $le_runs = no ; then
251       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?])
252     fi
253     LDFLAGS="$saved_LDFLAGS"
256 if test $ac_cv_libevent_linker_option != '(none)' ; then
257    LDFLAGS="$ac_cv_libevent_linker_option $LDFLAGS"
261 dnl ------------------------------------------------------
262 dnl Where do you live, openssl?  And how do we call you?
264 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [
265   saved_LIBS="$LIBS"
266   saved_LDFLAGS="$LDFLAGS"
267   saved_CPPFLAGS="$CPPFLAGS"
268   ssl_found=no
269   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
270     LDFLAGS="$saved_LDFLAGS"
272     if test $bwin32 = true; then
273       LIBS="$saved_LIBS -lssl -lcrypto -lws2_32 -lgdi32"
274     else
275       LIBS="$saved_LIBS -lssl -lcrypto"
276     fi
278     # Skip the directory if it isn't there.
279     if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
280        continue;
281     fi
282     if test ! -z "$ssldir" ; then
283       if test -d "$ssldir/lib" ; then
284         LDFLAGS="-L$ssldir/lib $LDFLAGS"
285       else
286         LDFLAGS="-L$ssldir $LDFLAGS"
287       fi
288       if test -d "$ssldir/include" ; then
289         CPPFLAGS="-I$ssldir/include $CPPFLAGS"
290       else
291         CPPFLAGS="-I$ssldir $CPPFLAGS"
292       fi
293     fi
294     # Can I link it?
295     AC_TRY_LINK([#include <openssl/rand.h>],
296        [ RAND_add((void*)0,0,0); ],
297        [ openssl_linked=yes ], [ openssl_linked=no ])
298     if test $openssl_linked = yes; then
299        if test ! -z "$ssldir" ; then
300          ac_cv_openssl_dir=$ssldir
301        else
302          ac_cv_openssl_dir="(system)"
303        fi
304        ssl_found=yes
305        break
306     fi
307   done
308   LIBS="$saved_LIBS"
309   LDFLAGS="$saved_LDFLAGS"
310   CPPFLAGS="$saved_CPPFLAGS"
311   if test $ssl_found = no ; then
312     AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
313   fi
316 if test $bwin32 = true; then
317 LIBS="$LIBS -lssl -lcrypto -lws2_32 -lgdi32"
318 else
319 LIBS="$LIBS -lssl -lcrypto"
322 if test "$ac_cv_openssl_dir" != "(system)"; then
323   if test -d "$ac_cv_openssl_dir/lib" ; then
324     LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS"
325     ssl_libdir="$ac_cv_openssl_dir/lib"
326   else
327     LDFLAGS="-L$ac_cv_openssl_dir $LDFLAGS"
328     ssl_libdir="$ac_cv_openssl_dir"
329   fi
330   if test -d "$ac_cv_openssl_dir/include" ; then
331     CPPFLAGS="-I$ac_cv_openssl_dir/include $CPPFLAGS"
332   else
333     CPPFLAGS="-I$ac_cv_openssl_dir $CPPFLAGS"
334   fi
337 if test -z $CROSS_COMPILE
338 then
339 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
340                ac_cv_openssl_linker_option, [
341     saved_LDFLAGS="$LDFLAGS"
342     ssl_runs=no
343     linked_with=nothing
344     for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
345       LDFLAGS="$ssl_extra $saved_LDFLAGS"
346       AC_TRY_RUN([
347 #include <string.h>
348 #include <openssl/rand.h>
349 int main(void)
351         char a[2048];
352         memset(a, 0, sizeof(a));
353         RAND_add(a, sizeof(a), sizeof(a));
354         return(RAND_status() <= 0);
356                         ],
357                 openssl_runs=yes, openssl_runs=no)
358       if test $openssl_runs = yes ; then
359         if test "$linked_with" = nothing; then
360            linked_with="$ssl_extra"
361         fi
362         AC_TRY_RUN([
363 #include <openssl/opensslv.h>
364 #include <openssl/crypto.h>
365 int main(void) {
366 return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
368         right_version=yes, right_version=no)
369         if test "$right_version" = yes; then
370           if test -z "$ssl_extra" ; then
371             ac_cv_openssl_linker_option='(none)'
372           else
373             ac_cv_openssl_linker_option=$ssl_extra
374           fi
375           ssl_runs=yes
376           break
377         fi
378      fi
379     done
380     if test $ssl_runs = no ; then
381       if test "$linked_with" = 'nothing' ; then
382         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?])
383       else
384         if test -z "$linked_with" ; then
385             ac_cv_openssl_linker_option='(none)'
386         else
387             ac_cv_openssl_linker_option=$linked_with
388         fi
389         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.])
390       fi
391     fi
392     LDFLAGS="$saved_LDFLAGS"
395 if test "$ac_cv_openssl_linker_option" != '(none)' ; then
396    LDFLAGS="$ac_cv_openssl_linker_option $LDFLAGS"
400 dnl Make sure to enable support for large off_t if avalable.
402 AC_SYS_LARGEFILE
404 dnl The warning message here is no longer strictly accurate.
406 AC_CHECK_HEADERS(unistd.h string.h signal.h netdb.h ctype.h sys/stat.h sys/types.h fcntl.h sys/fcntl.h sys/ioctl.h sys/socket.h sys/time.h netinet/in.h arpa/inet.h errno.h assert.h time.h pwd.h grp.h, , AC_MSG_WARN(some headers were not found, compilation may fail))
408 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.),
409 [#ifdef HAVE_SYS_TYPES_H
410 #include <sys/types.h>
411 #endif
412 #ifdef HAVE_SYS_TIME_H
413 #include <sys/time.h>
414 #else
415   struct timeval {
416     long tv_sec;
417     long tv_usec;
418  };
419 #endif])
421 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.))
423 dnl These headers are not essential
425 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)
427 AC_CHECK_HEADERS(net/if.h, [net_if_found=1], [net_if_found=0],
428 [#ifdef HAVE_SYS_TYPES_H
429 #include <sys/types.h>
430 #endif
431 #ifdef HAVE_SYS_SOCKET_H
432 #include <sys/socket.h>
433 #endif])
434 AC_CHECK_HEADERS(net/pfvar.h, [net_pfvar_found=1], [net_pfvar_found=0],
435 [#ifdef HAVE_SYS_TYPES_H
436 #include <sys/types.h>
437 #endif
438 #ifdef HAVE_SYS_SOCKET_H
439 #include <sys/socket.h>
440 #endif
441 #ifdef HAVE_NET_IF_H
442 #include <net/if.h>
443 #endif])
444 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
445         [linux_netfilter_ipv4=1], [linux_netfilter_ipv4=0],
446 [#ifdef HAVE_SYS_SOCKET_H
447 #include <sys/socket.h>
448 #endif])
450 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)
452 if test $enable_threads = "yes"; then
453   AC_CHECK_HEADERS(pthread.h)
454   AC_CHECK_FUNCS(pthread_create)
457 if test x$transparent = xtrue ; then
458    transparent_ok=0
459    if test x$net_if_found = x1 -a x$net_pfvar_found = x1 ; then
460      transparent_ok=1
461    fi
462    if test x$linux_netfilter_ipv4 = x1 ; then
463      transparent_ok=1
464    fi
465    if test x$transparent_ok = x1 ; then
466      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
467      case $host in
468        *-*-openbsd*)
469          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
470      esac
471    else
472      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
473    fi
476 AC_FUNC_FSEEKO
478 AC_CHECK_MEMBERS([struct timeval.tv_sec])
480 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
481 dnl Watch out.
483 AC_CHECK_SIZEOF(int8_t)
484 AC_CHECK_SIZEOF(int16_t)
485 AC_CHECK_SIZEOF(int32_t)
486 AC_CHECK_SIZEOF(int64_t)
487 AC_CHECK_SIZEOF(uint8_t)
488 AC_CHECK_SIZEOF(uint16_t)
489 AC_CHECK_SIZEOF(uint32_t)
490 AC_CHECK_SIZEOF(uint64_t)
491 AC_CHECK_SIZEOF(intptr_t)
492 AC_CHECK_SIZEOF(uintptr_t)
494 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
496 AC_CHECK_SIZEOF(char)
497 AC_CHECK_SIZEOF(short)
498 AC_CHECK_SIZEOF(int)
499 AC_CHECK_SIZEOF(long)
500 AC_CHECK_SIZEOF(long long)
501 AC_CHECK_SIZEOF(__int64)
502 AC_CHECK_SIZEOF(void *)
503 AC_CHECK_SIZEOF(time_t)
505 AC_CHECK_TYPES([uint, u_char])
507 if test -z "$CROSS_COMPILE"; then
508 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
509 AC_TRY_RUN([
510 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
511   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
513 else
514   # Cross-compiling; let's hope the target platform isn't loony.
515   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
516   tor_cv_time_t_signed=yes
519 if test $tor_cv_time_t_signed = yes; then
520   AC_DEFINE([TIME_T_IS_SIGNED], 1,
521             [Define to 1 iff time_t is signed])
524 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
525 #ifdef HAVE_SYS_SOCKET_H
526 #include <sys/socket.h>
527 #endif
530 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
532 AC_CHECK_SIZEOF(cell_t)
534 # Now make sure that NULL can be represented as zero bytes.
535 if test -z "$CROSS_COMPILE"; then
536 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
537 [AC_RUN_IFELSE([AC_LANG_SOURCE(
538 [[#include <stdlib.h>
539 #include <string.h>
540 #include <stdio.h>
541 #ifdef HAVE_STDDEF_H
542 #include <stddef.h>
543 #endif
544 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
545 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
546        [tor_cv_null_is_zero=yes],
547        [tor_cv_null_is_zero=no],
548        [tor_cv_null_is_zero=cross])])
550 else
551   # Cross-compiling; let's hope that the target isn't raving mad.
552   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
553   tor_cv_null_is_zero=yes
556 if test $tor_cv_null_is_zero = yes; then
557   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
558             [Define to 1 iff memset(0) sets pointers to NULL])
561 # And what happens when we malloc zero?
563 if test -z "$CROSS_COMPILE"; then
564 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
565 [AC_RUN_IFELSE([AC_LANG_SOURCE(
566 [[#include <stdlib.h>
567 #include <string.h>
568 #include <stdio.h>
569 #ifdef HAVE_STDDEF_H
570 #include <stddef.h>
571 #endif
572 int main () { return malloc(0)?0:1; }]])],
573        [tor_cv_malloc_zero_works=yes],
574        [tor_cv_malloc_zero_works=no],
575        [tor_cv_malloc_zero_works=cross])])
577 else
578   # Cross-compiling; let's hope that the target isn't raving mad.
579   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
580   tor_cv_malloc_zero_works=no
583 if test $tor_cv_malloc_zero_works = yes; then
584   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
585             [Define to 1 iff malloc(0) returns a pointer])
588 # Whether we should use the dmalloc memory allocation debugging library.
589 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
590 AC_ARG_WITH(dmalloc,
591 [  --with-dmalloc          Use debug memory allocation library. ],
592 [if [[ "$withval" = "yes" ]]; then
593   dmalloc=1
594   AC_MSG_RESULT(yes)
595 else
596   dmalloc=1
597   AC_MSG_RESULT(no)
598 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
601 if [[ $dmalloc -eq 1 ]]; then
602   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
603   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
604   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
605   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
608 # Allow user to specify an alternate syslog facility
609 AC_ARG_WITH(syslog-facility,
610 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
611 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
612 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
613 AC_SUBST(LOGFACILITY)
615 # Check for gethostbyname_r in all its glorious incompatible versions.
616 #   (This logic is based on that in Python's configure.in)
617 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
618   [Define this if you have any gethostbyname_r()])
620 AC_CHECK_FUNC(gethostbyname_r, [
621   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
622   OLD_CFLAGS=$CFLAGS
623   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
624   AC_TRY_COMPILE([
625 #include <netdb.h>
626   ], [
627     char *cp1, *cp2;
628     struct hostent *h1, *h2;
629     int i1, i2;
630     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
631   ], [
632     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
633     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
634      [Define this if gethostbyname_r takes 6 arguments])
635     AC_MSG_RESULT(6)
636   ], [
637     AC_TRY_COMPILE([
638 #include <netdb.h>
639     ], [
640       char *cp1, *cp2;
641       struct hostent *h1;
642       int i1, i2;
643       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
644     ], [
645       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
646       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
647         [Define this if gethostbyname_r takes 5 arguments])
648       AC_MSG_RESULT(5)
649    ], [
650       AC_TRY_COMPILE([
651 #include <netdb.h>
652      ], [
653        char *cp1;
654        struct hostent *h1;
655        struct hostent_data hd;
656        (void) gethostbyname_r(cp1,h1,&hd);
657      ], [
658        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
659        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
660          [Define this if gethostbyname_r takes 3 arguments])
661        AC_MSG_RESULT(3)
662      ], [
663        AC_MSG_RESULT(0)
664      ])
665   ])
666  ])
667  CFLAGS=$OLD_CFLAGS
670 AC_CACHE_CHECK([whether the C compiler supports __func__],
671   ac_cv_have_func_macro,
672   AC_COMPILE_IFELSE([
673 #include <stdio.h>
674 int main(int c, char **v) { puts(__func__); }],
675   ac_cv_have_func_macro=yes,
676   ac_cv_have_func_macro=no))
678 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
679   ac_cv_have_FUNC_macro,
680   AC_COMPILE_IFELSE([
681 #include <stdio.h>
682 int main(int c, char **v) { puts(__FUNC__); }],
683   ac_cv_have_FUNC_macro=yes,
684   ac_cv_have_FUNC_macro=no))
686 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
687   ac_cv_have_FUNCTION_macro,
688   AC_COMPILE_IFELSE([
689 #include <stdio.h>
690 int main(int c, char **v) { puts(__FUNCTION__); }],
691   ac_cv_have_FUNCTION_macro=yes,
692   ac_cv_have_FUNCTION_macro=no))
694 if test $ac_cv_have_func_macro = 'yes'; then
695   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
698 if test $ac_cv_have_FUNC_macro = 'yes'; then
699   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
702 if test $ac_cv_have_FUNCTION_macro = 'yes'; then
703   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
704            [Defined if the compiler supports __FUNCTION__])
707 # $prefix stores the value of the --prefix command line option, or
708 # NONE if the option wasn't set.  In the case that it wasn't set, make
709 # it be the default, so that we can use it to expand directories now.
710 if test "x$prefix" = "xNONE"; then
711   prefix=$ac_default_prefix
714 # and similarly for $exec_prefix
715 if test "x$exec_prefix" = "xNONE"; then
716   exec_prefix=$prefix
719 if test "x$CONFDIR" = "x"; then
720   CONFDIR=`eval echo $sysconfdir/tor`
722 AC_SUBST(CONFDIR)
723 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
724 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
726 BINDIR=`eval echo $bindir`
727 AC_SUBST(BINDIR)
729 LOCALSTATEDIR=`eval echo $localstatedir`
730 AC_SUBST(LOCALSTATEDIR)
731 AH_TEMPLATE([LOCALSTATEDIR], [Default location to store state files.])
732 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
734 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
735 # than autoconf's macros like.
736 if test $ac_cv_c_compiler_gnu = yes; then
737   CFLAGS="$CFLAGS -Wall -g -O2"
738 else
739   CFLAGS="$CFLAGS -g -O"
741 # Add some more warnings which we use in the cvs version but not in the
742 # released versions.  (Some relevant gcc versions can't handle these.)
743 #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"
744 # Add these in when you feel like fun.
745 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement -Wold-style-definition"
747 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)
749 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
750   ./contrib/updateVersions.pl