Make hashtables use a little less space on 64-bit architectures.
[tor.git] / configure.in
blob84ac5f95d27325fe955968d43e688778162d6473
1 dnl $Id$
2 dnl Copyright (c) 2001-2005 Roger Dingledine
3 dnl Copyright (c) 2004-2005 Nick Mathewson
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.1.1.10-alpha-cvs)
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 case $host in
48    *-*-solaris* )
49      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
50      ;;
51 esac
53 AC_PROG_CC
54 AC_PROG_MAKE_SET
55 AC_PROG_RANLIB
57 # The big search for OpenSSL
58 # copied from openssh's configure.ac
59 AC_ARG_WITH(ssl-dir,
60         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
61         [
62                 if test "x$withval" != "xno" ; then
63                         tryssldir=$withval
64                 fi
65         ]
68 AC_SEARCH_LIBS(socket, [socket])
69 AC_SEARCH_LIBS(gethostbyname, [nsl])
70 AC_SEARCH_LIBS(dlopen, [dl])
72 if test $enable_threads = "yes"; then
73   AC_SEARCH_LIBS(pthread_create, [pthread])
74   AC_SEARCH_LIBS(pthread_detach, [pthread])
77 dnl ------------------------------------------------------
78 dnl Where do you live, libevent?  And how do we call you?
81 # Step 1. Try to link and run a program using libevent.  If it works,
82 #         great!  Just add -levent.
83 AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
84    saved_LIBS="$LIBS"
85    LIBS="$LIBS -levent"
86    AC_TRY_RUN([
87 void *event_init(void);
88 int main(void)
90         event_init();
91         return 0;
92 }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
93    LIBS="$saved_LIBS"
96 if test "$ac_cv_libevent_normal" = yes; then
97   LIBS="$LIBS -levent"
98 else
99   AC_CACHE_CHECK([for libevent in /usr/local/lib], ac_cv_libevent_local, [
100      saved_LIBS="$LIBS"
101      saved_LDFLAGS="$LDFLAGS"
102      LIBS="$LIBS -levent"
103      LDFLAGS="$LDFLAGS -L/usr/local/lib"
104      # Step 2.  Otherwise, check whether adding -L/usr/local/lib allows
105      #          us to link.  If not, assume we have no libevent at all.
106      AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
107         [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
108      if test $libevent_is_in_local = no ; then
109        ac_cv_libevent_local=no   
110      else
111        # Step 3.  Does adding -L/usr/local/lib allow us to run, too?
112        #          If so, all we have to do as adjust LDFLAGS and CFLAGS.
113        AC_TRY_RUN([
114 void *event_init(void);
115 int main(void)
117         event_init();
118         return 0;
119 }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
120     fi
121     if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
122        # Step 4.  Okay, so we can link but not run.  This probably means
123        #          that the dynamic linker doesn't have /usr/local/lib in
124        #          its search path.  If we're lucky enough to be running
125        #          GCC on an ELF system, we might have a workaround for that.
126        #          See whether -Wl,-R/usr/local/lib makes things better.
127        LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
128        AC_TRY_RUN([
129 void *event_init(void);
130 int main(void)
132         event_init();
133         return 0;
134 }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
135     fi
137     LIBS="$saved_LIBS"
138     LDFLAGS="$saved_LDFLAGS" ])
140   # Now we're done.  ac_vc_libevent_local could be:
141   #    yes -- Add -L/usr/local/lib and we can link fine.
142   #    unlinked_gcc_elf -- We can link, but we need to use the GCC-ELF
143   #        workaround.  Complain a little.
144   #    unlinked -- We can link, but we can't run.  Complain a lot.
145   #    no -- we can't link at all.  Give an error and die.
147   if test $ac_cv_libevent_local != no; then
148       LIBS="$LIBS -levent"
149       LDFLAGS="$LDFLAGS -L/usr/local/lib"
150       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
151   fi
152   if test $ac_cv_libevent_local = unlinked_gcc_elf; then
153       LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
154       if test -f /etc/ld.so.conf ; then
155         AC_MSG_NOTICE([
156 Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
157 Tor is smart enought to deal this now, but other applications aren't.
158 You might want to add it in.])
159       fi
160   fi
162   if test $ac_cv_libevent_local = unlinked ; then
163     if test -f /etc/ld.so.conf ; then
164       AC_MSG_NOTICE([
165 =================================================
166 Your libevent library is installed in /usr/local/lib,
167 but your dynamic linker isn't configured to look for
168 it there.
170 Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
171 and then run ldconfig -v ?
172 =================================================])
173     else
174       AC_MSG_NOTICE([
175 =================================================
176 Your libevent library is installed in /usr/local/lib,
177 but your dynamic linker isn't configured to look for
178 it there.
179 =================================================])
180     fi 
181   fi
183   if test $ac_cv_libevent_local = no ; then
184       AC_MSG_ERROR([
185 Tor requires libevent to build.  You can download the latest
186 version of libevent from http://monkey.org/~provos/libevent/])
187   fi
191 dnl ------------------------------------------------------
192 dnl Where do you live, OpenSSL?
194 saved_LIBS="$LIBS"
195 saved_LDFLAGS="$LDFLAGS"
196 saved_CPPFLAGS="$CPPFLAGS"
197 if test "x$prefix" != "xNONE" ; then
198         tryssldir="$tryssldir $prefix"
200 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
201         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
202                 CPPFLAGS="$saved_CPPFLAGS"
203                 LDFLAGS="$saved_LDFLAGS"
204                 LIBS="$saved_LIBS -lssl -lcrypto"
206                 # Skip directories if they don't exist
207                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
208                         continue;
209                 fi
210                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
211                         # Try to use $ssldir/lib if it exists, otherwise
212                         # $ssldir
213                         if test -d "$ssldir/lib" ; then
214                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
215                                 if test ! -z "$need_dash_r" ; then
216                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
217                                 fi
218                         else
219                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
220                                 if test ! -z "$need_dash_r" ; then
221                                         LDFLAGS="-R$ssldir $LDFLAGS"
222                                 fi
223                         fi
224                         # Try to use $ssldir/include if it exists, otherwise
225                         # $ssldir
226                         if test -d "$ssldir/include" ; then
227                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
228                         else
229                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
230                         fi
231                 fi
233                 # Basic test to check for compatible version and correct linking
234                 # *does not* test for RSA - that comes later.
235                 AC_TRY_RUN(
236                         [
237 #include <string.h>
238 #include <openssl/rand.h>
239 int main(void)
241         char a[2048];
242         memset(a, 0, sizeof(a));
243         RAND_add(a, sizeof(a), sizeof(a));
244         return(RAND_status() <= 0);
246                         ],
247                         [
248                                 found_crypto=1
249                                 break;
250                         ], []
251                 )
253                 if test ! -z "$found_crypto" ; then
254                         break;
255                 fi
256         done
258         if test -z "$found_crypto" ; then
259                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
260         fi
261         if test -z "$ssldir" ; then
262                 ssldir="(system)"
263         fi
265         ac_cv_openssldir=$ssldir
267 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
268  then
269         dnl Need to recover ssldir - test above runs in subshell
270         ssldir=$ac_cv_openssldir
271         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
272                 # Try to use $ssldir/lib if it exists, otherwise
273                 # $ssldir
274                 if test -d "$ssldir/lib" ; then
275                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
276                         if test ! -z "$need_dash_r" ; then
277                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
278                         fi
279                 else
280                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
281                         if test ! -z "$need_dash_r" ; then
282                                 LDFLAGS="-R$ssldir $LDFLAGS"
283                         fi
284                 fi
285                 # Try to use $ssldir/include if it exists, otherwise
286                 # $ssldir
287                 if test -d "$ssldir/include" ; then
288                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
289                 else
290                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
291                 fi
292         fi
294 LIBS="$saved_LIBS"
296 AC_SYS_LARGEFILE
298 dnl The warning message here is no longer strictly accurate.
300 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))
302 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
304 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.))
306 dnl These headers are not essential
308 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 stddef.h inttypes.h utime.h sys/utime.h)
310 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam getpwuid ftello getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback memmem)
312 if test $enable_threads = "yes"; then
313   AC_CHECK_HEADERS(pthread.h)
314   AC_CHECK_FUNCS(pthread_create)
317 AC_FUNC_FSEEKO
319 AC_CHECK_MEMBERS([struct timeval.tv_sec])
321 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
322 dnl Watch out.
324 AC_CHECK_SIZEOF(int8_t)
325 AC_CHECK_SIZEOF(int16_t)
326 AC_CHECK_SIZEOF(int32_t)
327 AC_CHECK_SIZEOF(int64_t)
328 AC_CHECK_SIZEOF(uint8_t)
329 AC_CHECK_SIZEOF(uint16_t)
330 AC_CHECK_SIZEOF(uint32_t)
331 AC_CHECK_SIZEOF(uint64_t)
332 AC_CHECK_SIZEOF(intptr_t)
333 AC_CHECK_SIZEOF(uintptr_t)
335 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
337 AC_CHECK_SIZEOF(char)
338 AC_CHECK_SIZEOF(short)
339 AC_CHECK_SIZEOF(int)
340 AC_CHECK_SIZEOF(long)
341 AC_CHECK_SIZEOF(long long)
342 AC_CHECK_SIZEOF(__int64)
343 AC_CHECK_SIZEOF(void *)
344 AC_CHECK_SIZEOF(time_t)
345 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
346 AC_TRY_RUN([
347 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
348   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
351 if test $tor_cv_time_t_signed = yes; then
352   AC_DEFINE([TIME_T_IS_SIGNED], 1,
353             [Define to 1 iff time_t is signed])
356 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
357 #ifdef HAVE_SYS_SOCKET_H
358 #include <sys/socket.h>
359 #endif
362 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
364 AC_CHECK_SIZEOF(cell_t)
366 # Now, let's see about alignment requirements.  On some platforms, we override
367 # the default.
368 case $host in
369  ia64-*-* | arm-*-* | sparc-*-* | sparc64-*-* )
370     tor_cv_unaligned_ok=no
371     ;;
372  # On the following architectures unaligned access works, but is not done in
373  # hardware.  This means that when you try to do unaligned access the kernel
374  # gets to sort out an exception and then work around to somehow make your
375  # reqest work, which is quite expensive.  Therefore it's probably better to
376  # not even do it.
377  alpha-*-* | mips-*-* | mipsel-*-* )
378     tor_cv_unaligned_ok=no
379     ;;
380  *)
381 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
382 [AC_RUN_IFELSE([AC_LANG_SOURCE(
383 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
384 return *(int*)(&s[1]); }]])],
385        [tor_cv_unaligned_ok=yes],
386        [tor_cv_unaligned_ok=no],
387        [tor_cv_unaligned_ok=cross])])
388 esac
390 if test $tor_cv_unaligned_ok = yes; then
391   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
392             [Define to 1 iff unaligned int access is allowed])
395 # Now make sure that NULL can be represented as zero bytes.
396 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
397 [AC_RUN_IFELSE([AC_LANG_SOURCE(
398 [[#include <stdlib.h>
399 #include <string.h>
400 #include <stdio.h>
401 #ifdef HAVE_STDDEF_H
402 #include <stddef.h>
403 #endif
404 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
405 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
406        [tor_cv_null_is_zero=yes],
407        [tor_cv_null_is_zero=no],
408        [tor_cv_null_is_zero=cross])])
410 if test $tor_cv_null_is_zero = yes; then
411   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
412             [Define to 1 iff memset(0) sets pointers to NULL])
415 # Whether we should use the dmalloc memory allocation debugging library.
416 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
417 AC_ARG_WITH(dmalloc,
418 [  --with-dmalloc          Use debug memory allocation library. ],
419 [if [[ "$withval" = "yes" ]]; then
420   dmalloc=1
421   AC_MSG_RESULT(yes)
422 else
423   dmalloc=1
424   AC_MSG_RESULT(no)
425 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
428 if [[ $dmalloc -eq 1 ]]; then
429   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
430   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
431   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
432   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
435 # Check for gethostbyname_r in all its glorious incompatible versions.
436 #   (This logic is based on that in Python's configure.in)
437 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
438   [Define this if you have any gethostbyname_r()])
440 AC_CHECK_FUNC(gethostbyname_r, [
441   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
442   OLD_CFLAGS=$CFLAGS
443   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
444   AC_TRY_COMPILE([
445 #include <netdb.h>
446   ], [
447     char *cp1, *cp2;
448     struct hostent *h1, *h2;
449     int i1, i2;
450     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
451   ], [
452     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
453     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
454      [Define this if gethostbyname_r takes 6 arguments])
455     AC_MSG_RESULT(6)
456   ], [
457     AC_TRY_COMPILE([
458 #include <netdb.h>
459     ], [
460       char *cp1, *cp2;
461       struct hostent *h1;
462       int i1, i2;
463       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
464     ], [
465       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
466       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
467         [Define this if gethostbyname_r takes 5 arguments])
468       AC_MSG_RESULT(5)
469    ], [
470       AC_TRY_COMPILE([
471 #include <netdb.h>
472      ], [
473        char *cp1;
474        struct hostent *h1;
475        struct hostent_data hd;
476        (void) gethostbyname_r(cp1,h1,&hd);
477      ], [
478        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
479        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
480          [Define this if gethostbyname_r takes 3 arguments])
481        AC_MSG_RESULT(3)
482      ], [
483        AC_MSG_RESULT(0)
484      ])
485   ])
486  ])
487  CFLAGS=$OLD_CFLAGS
490 # $prefix stores the value of the --prefix command line option, or
491 # NONE if the option wasn't set.  In the case that it wasn't set, make
492 # it be the default, so that we can use it to expand directories now.
493 if test "x$prefix" = "xNONE"; then
494   prefix=$ac_default_prefix
497 # and similarly for $exec_prefix
498 if test "x$exec_prefix" = "xNONE"; then
499   exec_prefix=$prefix
502 CONFDIR=`eval echo $sysconfdir/tor`
503 AC_SUBST(CONFDIR)
504 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
505 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
507 BINDIR=`eval echo $bindir`
508 AC_SUBST(BINDIR)
510 LOCALSTATEDIR=`eval echo $localstatedir`
511 AC_SUBST(LOCALSTATEDIR)
512 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
513 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
515 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
516 # than autoconf's macros like.
517 CFLAGS="$CFLAGS -Wall -g -O2"
518 # Add some more warnings which we use in the cvs version but not in the
519 # released versions.  (Some relevant gcc versions can't handle these.)
520 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -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"
521 # Add these in when you feel like fun.
522 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement -Wold-style-definition"
524 echo "confdir: $CONFDIR"
526 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 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)
528 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
529   ./contrib/updateVersions.pl