correct the explanation for KeepalivePeriod
[tor.git] / configure.in
blob5e9e9bbf81c316c1083152f5b376f969b115a0b9
1 dnl $Id$
2 dnl Copyright 2001-2004 Roger Dingledine
3 dnl Copyright 2004-2005 Roger Dingledine, Nick Mathewson
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.1.0.8-rc)
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     *)
34      enable_threads="yes";;
35    esac
38 if test $enable_threads = "yes"; then
39   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
42 AC_PROG_CC
43 AC_PROG_MAKE_SET
44 AC_PROG_RANLIB
46 # The big search for OpenSSL
47 # copied from openssh's configure.ac
48 AC_ARG_WITH(ssl-dir,
49         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
50         [
51                 if test "x$withval" != "xno" ; then
52                         tryssldir=$withval
53                 fi
54         ]
57 AC_SEARCH_LIBS(socket, [socket])
58 AC_SEARCH_LIBS(gethostbyname, [nsl])
59 AC_SEARCH_LIBS(pthread_create, [pthread])
60 AC_SEARCH_LIBS(pthread_detach, [pthread])
62 dnl ------------------------------------------------------
63 dnl Where do you live, libevent?  And how do we call you?
66 # Step 1. Try to link and run a program using libevent.  If it works,
67 #         great!  Just add -levent.
68 AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
69    saved_LIBS="$LIBS"
70    LIBS="$LIBS -levent"
71    AC_TRY_RUN([
72 void *event_init(void);
73 int main(void)
75         event_init();
76         return 0;
77 }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
78    LIBS="$saved_LIBS"
81 if test "$ac_cv_libevent_normal" = yes; then
82   LIBS="$LIBS -levent"
83 else
84   AC_CACHE_CHECK([for libevent in /usr/local/lib], ac_cv_libevent_local, [
85      saved_LIBS="$LIBS"
86      saved_LDFLAGS="$LDFLAGS"  
87      LIBS="$LIBS -levent"
88      LDFLAGS="$LDFLAGS -L/usr/local/lib"
89      # Step 2.  Otherwise, check whether adding -L/usr/local/lib allows
90      #          us to link.  If not, assume we have no libevent at all.
91      AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
92         [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
93      if test $libevent_is_in_local = no ; then
94        ac_cv_libevent_local=no   
95      else
96        # Step 3.  Does adding -L/usr/local/lib allow us to run, too?
97        #          If so, all we have to do as adjust LDFLAGS and CFLAGS.
98        AC_TRY_RUN([
99 void *event_init(void);
100 int main(void)
102         event_init();
103         return 0;
104 }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
105     fi
106     if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
107        # Step 4.  Okay, so we can link but not run.  This probably means
108        #          that the dynamic linker doesn't have /usr/local/lib in
109        #          its search path.  If we're lucky enough to be running
110        #          GCC on an ELF system, we might have a workaround for that.
111        #          See whether -Wl,-R/usr/local/lib makes things better.
112        LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
113        AC_TRY_RUN([
114 void *event_init(void);
115 int main(void)
117         event_init();
118         return 0;
119 }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
120     fi 
122     LIBS="$saved_LIBS"
123     LDFLAGS="$saved_LDFLAGS" ])
125   # Now we're done.  ac_vc_libevent_local could be:
126   #    yes -- Add -L/usr/local/lib and we can link fine.
127   #    unlinked_gcc_elf -- We can link, but we need to use the GCC-ELF
128   #        workaround.  Complain a little.
129   #    unlinked -- We can link, but we can't run.  Complain a lot.
130   #    no -- we can't link at all.  Give an error and die.
132   if test $ac_cv_libevent_local != no; then
133       LIBS="$LIBS -levent"
134       LDFLAGS="$LDFLAGS -L/usr/local/lib"
135       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
136   fi
137   if test $ac_cv_libevent_local = unlinked_gcc_elf; then
138       LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
139       if test -f /etc/ld.so.conf ; then
140         AC_MSG_NOTICE([
141 Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
142 Tor is smart enought to deal this now, but other applications aren't.
143 You might want to add it in.])
144       fi
145   fi
147   if test $ac_cv_libevent_local = unlinked ; then
148     if test -f /etc/ld.so.conf ; then
149       AC_MSG_NOTICE([
150 =================================================
151 Your libevent library is installed in /usr/local/lib,
152 but your dynamic linker isn't configured to look for
153 it there.
155 Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
156 and then run ldconfig -v ?
157 =================================================])
158     else
159       AC_MSG_NOTICE([
160 =================================================
161 Your libevent library is installed in /usr/local/lib,
162 but your dynamic linker isn't configured to look for
163 it there.
164 =================================================])
165     fi 
166   fi
168   if test $ac_cv_libevent_local = no ; then
169       AC_MSG_ERROR([
170 Tor requires libevent to build.  You can download the latest
171 version of libevent from http://monkey.org/~provos/libevent/])
172   fi
176 dnl ------------------------------------------------------
177 dnl Where do you live, OpenSSL?
179 saved_LIBS="$LIBS"
180 saved_LDFLAGS="$LDFLAGS"
181 saved_CPPFLAGS="$CPPFLAGS"
182 if test "x$prefix" != "xNONE" ; then
183         tryssldir="$tryssldir $prefix"
185 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
186         for ssldir in $tryssldir "" /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do
187                 CPPFLAGS="$saved_CPPFLAGS"
188                 LDFLAGS="$saved_LDFLAGS"
189                 LIBS="$saved_LIBS -lssl -lcrypto"
191                 # Skip directories if they don't exist
192                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
193                         continue;
194                 fi
195                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
196                         # Try to use $ssldir/lib if it exists, otherwise
197                         # $ssldir
198                         if test -d "$ssldir/lib" ; then
199                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
200                                 if test ! -z "$need_dash_r" ; then
201                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
202                                 fi
203                         else
204                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
205                                 if test ! -z "$need_dash_r" ; then
206                                         LDFLAGS="-R$ssldir $LDFLAGS"
207                                 fi
208                         fi
209                         # Try to use $ssldir/include if it exists, otherwise
210                         # $ssldir
211                         if test -d "$ssldir/include" ; then
212                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
213                         else
214                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
215                         fi
216                 fi
218                 # Basic test to check for compatible version and correct linking
219                 # *does not* test for RSA - that comes later.
220                 AC_TRY_RUN(
221                         [
222 #include <string.h>
223 #include <openssl/rand.h>
224 int main(void)
226         char a[2048];
227         memset(a, 0, sizeof(a));
228         RAND_add(a, sizeof(a), sizeof(a));
229         return(RAND_status() <= 0);
231                         ],
232                         [
233                                 found_crypto=1
234                                 break;
235                         ], []
236                 )
238                 if test ! -z "$found_crypto" ; then
239                         break;
240                 fi
241         done
243         if test -z "$found_crypto" ; then
244                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
245         fi
246         if test -z "$ssldir" ; then
247                 ssldir="(system)"
248         fi
250         ac_cv_openssldir=$ssldir
252 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
253  then
254         dnl Need to recover ssldir - test above runs in subshell
255         ssldir=$ac_cv_openssldir
256         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
257                 # Try to use $ssldir/lib if it exists, otherwise
258                 # $ssldir
259                 if test -d "$ssldir/lib" ; then
260                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
261                         if test ! -z "$need_dash_r" ; then
262                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
263                         fi
264                 else
265                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
266                         if test ! -z "$need_dash_r" ; then
267                                 LDFLAGS="-R$ssldir $LDFLAGS"
268                         fi
269                 fi
270                 # Try to use $ssldir/include if it exists, otherwise
271                 # $ssldir
272                 if test -d "$ssldir/include" ; then
273                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
274                 else
275                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
276                 fi
277         fi
279 LIBS="$saved_LIBS"
281 AC_SYS_LARGEFILE
283 dnl The warning message here is no longer strictly accurate.
285 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))
287 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
289 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.))
291 dnl These headers are not essential
293 AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h pthread.h stddef.h inttypes.h)
295 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam ftello pthread_create getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback)
296 AC_FUNC_FSEEKO
298 AC_CHECK_MEMBERS([struct timeval.tv_sec])
301 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
302 dnl Watch out.
304 AC_CHECK_SIZEOF(int8_t)
305 AC_CHECK_SIZEOF(int16_t)
306 AC_CHECK_SIZEOF(int32_t)
307 AC_CHECK_SIZEOF(int64_t)
308 AC_CHECK_SIZEOF(uint8_t)
309 AC_CHECK_SIZEOF(uint16_t)
310 AC_CHECK_SIZEOF(uint32_t)
311 AC_CHECK_SIZEOF(uint64_t)
312 AC_CHECK_SIZEOF(intptr_t)
313 AC_CHECK_SIZEOF(uintptr_t)
315 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
317 AC_CHECK_SIZEOF(char)
318 AC_CHECK_SIZEOF(short)
319 AC_CHECK_SIZEOF(int)
320 AC_CHECK_SIZEOF(long)
321 AC_CHECK_SIZEOF(long long)
322 AC_CHECK_SIZEOF(__int64)
323 AC_CHECK_SIZEOF(void *)
324 AC_CHECK_SIZEOF(time_t)
325 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
326 #ifdef HAVE_SYS_SOCKET_H
327 #include <sys/socket.h>
328 #endif
331 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
333 AC_CHECK_SIZEOF(cell_t)
335 # Now, let's see about alignment requirements.  On some platforms, we override
336 # the default.
337 case $host in
338  ia64-*-* | arm-*-* )
339     tor_cv_unaligned_ok=no
340     ;;
341  *)
342 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
343 [AC_RUN_IFELSE([AC_LANG_SOURCE(
344 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
345 return *(int*)(&s[1]); }]])],
346        [tor_cv_unaligned_ok=yes],
347        [tor_cv_unaligned_ok=no],
348        [tor_cv_unaligned_ok=cross])])
349 esac
351 if test $tor_cv_unaligned_ok = yes; then
352   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
353             [Define to 1 iff unaligned int access is allowed])
356 # Now make sure that NULL can be represented as zero bytes.
357 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
358 [AC_RUN_IFELSE([AC_LANG_SOURCE(
359 [[#include <stdlib.h>
360 #include <string.h>
361 #include <stdio.h>
362 #ifdef HAVE_STDDEF_H
363 #include <stddef.h>
364 #endif
365 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
366 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
367        [tor_cv_null_is_zero=yes],
368        [tor_cv_null_is_zero=no],
369        [tor_cv_null_is_zero=cross])])
371 if test $tor_cv_null_is_zero = yes; then
372   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
373             [Define to 1 iff memset(0) sets pointers to NULL])
376 # Whether we should use the dmalloc memory allocation debugging library.
377 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
378 AC_ARG_WITH(dmalloc,
379 [  --with-dmalloc          Use debug memory allocation library. ],
380 [if [[ "$withval" = "yes" ]]; then
381   dmalloc=1
382   AC_MSG_RESULT(yes)
383 else
384   dmalloc=1
385   AC_MSG_RESULT(no)
386 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
389 if [[ $dmalloc -eq 1 ]]; then
390   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
391   AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
392   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
393   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
396 # Check for gethostbyname_r in all its glorious incompatible versions.
397 #   (This logic is based on that in Python's configure.in)
398 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
399   [Define this if you have any gethostbyname_r()])
401 AC_CHECK_FUNC(gethostbyname_r, [
402   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
403   OLD_CFLAGS=$CFLAGS
404   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
405   AC_TRY_COMPILE([
406 #include <netdb.h>
407   ], [
408     char *cp1, *cp2;
409     struct hostent *h1, *h2;
410     int i1, i2;
411     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
412   ], [
413     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
414     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
415      [Define this if gethostbyname_r takes 6 arguments])
416     AC_MSG_RESULT(6)
417   ], [
418     AC_TRY_COMPILE([
419 #include <netdb.h>
420     ], [
421       char *cp1, *cp2;
422       struct hostent *h1;
423       int i1, i2;
424       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
425     ], [
426       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
427       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
428         [Define this if gethostbyname_r takes 5 arguments])
429       AC_MSG_RESULT(5)
430    ], [
431       AC_TRY_COMPILE([
432 #include <netdb.h>
433      ], [
434        char *cp1;
435        struct hostent *h1;
436        struct hostent_data hd;
437        (void) gethostbyname_r(cp1,h1,&hd);
438      ], [
439        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
440        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
441          [Define this if gethostbyname_r takes 3 arguments])
442        AC_MSG_RESULT(3)
443      ], [
444        AC_MSG_RESULT(0)
445      ])
446   ])
447  ])
448  CFLAGS=$OLD_CFLAGS
451 # $prefix stores the value of the --prefix command line option, or
452 # NONE if the option wasn't set.  In the case that it wasn't set, make
453 # it be the default, so that we can use it to expand directories now.
454 if test "x$prefix" = "xNONE"; then
455   prefix=$ac_default_prefix
458 # and similarly for $exec_prefix
459 if test "x$exec_prefix" = "xNONE"; then
460   exec_prefix=$prefix
463 CONFDIR=`eval echo $sysconfdir/tor`
464 AC_SUBST(CONFDIR)
465 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
466 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
468 BINDIR=`eval echo $bindir`
469 AC_SUBST(BINDIR)
471 LOCALSTATEDIR=`eval echo $localstatedir`
472 AC_SUBST(LOCALSTATEDIR)
473 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
474 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
476 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
477 # than autoconf's macros like.
478 CFLAGS="$CFLAGS -Wall -g -O2"
479 # Add some more warnings which we use in the cvs version but not in the
480 # released versions.  (Some relevant gcc versions can't handle these.)
481 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
482 # Add these in when you feel like fun.
483 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
485 echo "confdir: $CONFDIR"
487 AC_OUTPUT(Makefile tor.spec contrib/tor.sh contrib/torctl contrib/torify contrib/Makefile contrib/osx/Makefile contrib/osx/TorBundleDesc.plist contrib/osx/TorBundleInfo.plist contrib/osx/TorDesc.plist contrib/osx/TorInfo.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)
489 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
490   ./contrib/updateVersions.pl