make doxygen output look prettier
[tor.git] / configure.in
blob31ccecc54d90b2ead2971d50f2711c9747ce2199
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.1.5-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])
71 if test $enable_threads = "yes"; then
72   AC_SEARCH_LIBS(pthread_create, [pthread])
73   AC_SEARCH_LIBS(pthread_detach, [pthread])
76 dnl ------------------------------------------------------
77 dnl Where do you live, libevent?  And how do we call you?
80 # Step 1. Try to link and run a program using libevent.  If it works,
81 #         great!  Just add -levent.
82 AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
83    saved_LIBS="$LIBS"
84    LIBS="$LIBS -levent"
85    AC_TRY_RUN([
86 void *event_init(void);
87 int main(void)
89         event_init();
90         return 0;
91 }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
92    LIBS="$saved_LIBS"
95 if test "$ac_cv_libevent_normal" = yes; then
96   LIBS="$LIBS -levent"
97 else
98   AC_CACHE_CHECK([for libevent in /usr/local/lib], ac_cv_libevent_local, [
99      saved_LIBS="$LIBS"
100      saved_LDFLAGS="$LDFLAGS"  
101      LIBS="$LIBS -levent"
102      LDFLAGS="$LDFLAGS -L/usr/local/lib"
103      # Step 2.  Otherwise, check whether adding -L/usr/local/lib allows
104      #          us to link.  If not, assume we have no libevent at all.
105      AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
106         [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
107      if test $libevent_is_in_local = no ; then
108        ac_cv_libevent_local=no   
109      else
110        # Step 3.  Does adding -L/usr/local/lib allow us to run, too?
111        #          If so, all we have to do as adjust LDFLAGS and CFLAGS.
112        AC_TRY_RUN([
113 void *event_init(void);
114 int main(void)
116         event_init();
117         return 0;
118 }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
119     fi
120     if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
121        # Step 4.  Okay, so we can link but not run.  This probably means
122        #          that the dynamic linker doesn't have /usr/local/lib in
123        #          its search path.  If we're lucky enough to be running
124        #          GCC on an ELF system, we might have a workaround for that.
125        #          See whether -Wl,-R/usr/local/lib makes things better.
126        LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
127        AC_TRY_RUN([
128 void *event_init(void);
129 int main(void)
131         event_init();
132         return 0;
133 }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
134     fi 
136     LIBS="$saved_LIBS"
137     LDFLAGS="$saved_LDFLAGS" ])
139   # Now we're done.  ac_vc_libevent_local could be:
140   #    yes -- Add -L/usr/local/lib and we can link fine.
141   #    unlinked_gcc_elf -- We can link, but we need to use the GCC-ELF
142   #        workaround.  Complain a little.
143   #    unlinked -- We can link, but we can't run.  Complain a lot.
144   #    no -- we can't link at all.  Give an error and die.
146   if test $ac_cv_libevent_local != no; then
147       LIBS="$LIBS -levent"
148       LDFLAGS="$LDFLAGS -L/usr/local/lib"
149       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
150   fi
151   if test $ac_cv_libevent_local = unlinked_gcc_elf; then
152       LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
153       if test -f /etc/ld.so.conf ; then
154         AC_MSG_NOTICE([
155 Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
156 Tor is smart enought to deal this now, but other applications aren't.
157 You might want to add it in.])
158       fi
159   fi
161   if test $ac_cv_libevent_local = unlinked ; then
162     if test -f /etc/ld.so.conf ; then
163       AC_MSG_NOTICE([
164 =================================================
165 Your libevent library is installed in /usr/local/lib,
166 but your dynamic linker isn't configured to look for
167 it there.
169 Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
170 and then run ldconfig -v ?
171 =================================================])
172     else
173       AC_MSG_NOTICE([
174 =================================================
175 Your libevent library is installed in /usr/local/lib,
176 but your dynamic linker isn't configured to look for
177 it there.
178 =================================================])
179     fi 
180   fi
182   if test $ac_cv_libevent_local = no ; then
183       AC_MSG_ERROR([
184 Tor requires libevent to build.  You can download the latest
185 version of libevent from http://monkey.org/~provos/libevent/])
186   fi
190 dnl ------------------------------------------------------
191 dnl Where do you live, OpenSSL?
193 saved_LIBS="$LIBS"
194 saved_LDFLAGS="$LDFLAGS"
195 saved_CPPFLAGS="$CPPFLAGS"
196 if test "x$prefix" != "xNONE" ; then
197         tryssldir="$tryssldir $prefix"
199 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
200         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
201                 CPPFLAGS="$saved_CPPFLAGS"
202                 LDFLAGS="$saved_LDFLAGS"
203                 LIBS="$saved_LIBS -lssl -lcrypto"
205                 # Skip directories if they don't exist
206                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
207                         continue;
208                 fi
209                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
210                         # Try to use $ssldir/lib if it exists, otherwise
211                         # $ssldir
212                         if test -d "$ssldir/lib" ; then
213                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
214                                 if test ! -z "$need_dash_r" ; then
215                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
216                                 fi
217                         else
218                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
219                                 if test ! -z "$need_dash_r" ; then
220                                         LDFLAGS="-R$ssldir $LDFLAGS"
221                                 fi
222                         fi
223                         # Try to use $ssldir/include if it exists, otherwise
224                         # $ssldir
225                         if test -d "$ssldir/include" ; then
226                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
227                         else
228                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
229                         fi
230                 fi
232                 # Basic test to check for compatible version and correct linking
233                 # *does not* test for RSA - that comes later.
234                 AC_TRY_RUN(
235                         [
236 #include <string.h>
237 #include <openssl/rand.h>
238 int main(void)
240         char a[2048];
241         memset(a, 0, sizeof(a));
242         RAND_add(a, sizeof(a), sizeof(a));
243         return(RAND_status() <= 0);
245                         ],
246                         [
247                                 found_crypto=1
248                                 break;
249                         ], []
250                 )
252                 if test ! -z "$found_crypto" ; then
253                         break;
254                 fi
255         done
257         if test -z "$found_crypto" ; then
258                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
259         fi
260         if test -z "$ssldir" ; then
261                 ssldir="(system)"
262         fi
264         ac_cv_openssldir=$ssldir
266 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
267  then
268         dnl Need to recover ssldir - test above runs in subshell
269         ssldir=$ac_cv_openssldir
270         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
271                 # Try to use $ssldir/lib if it exists, otherwise
272                 # $ssldir
273                 if test -d "$ssldir/lib" ; then
274                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
275                         if test ! -z "$need_dash_r" ; then
276                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
277                         fi
278                 else
279                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
280                         if test ! -z "$need_dash_r" ; then
281                                 LDFLAGS="-R$ssldir $LDFLAGS"
282                         fi
283                 fi
284                 # Try to use $ssldir/include if it exists, otherwise
285                 # $ssldir
286                 if test -d "$ssldir/include" ; then
287                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
288                 else
289                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
290                 fi
291         fi
293 LIBS="$saved_LIBS"
295 AC_SYS_LARGEFILE
297 dnl The warning message here is no longer strictly accurate.
299 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))
301 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
303 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.))
305 dnl These headers are not essential
307 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)
309 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam ftello getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback memmem)
311 if test $enable_threads = "yes"; then
312   AC_CHECK_HEADERS(pthread.h)
313   AC_CHECK_FUNCS(pthread_create)
316 AC_FUNC_FSEEKO
318 AC_CHECK_MEMBERS([struct timeval.tv_sec])
320 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
321 dnl Watch out.
323 AC_CHECK_SIZEOF(int8_t)
324 AC_CHECK_SIZEOF(int16_t)
325 AC_CHECK_SIZEOF(int32_t)
326 AC_CHECK_SIZEOF(int64_t)
327 AC_CHECK_SIZEOF(uint8_t)
328 AC_CHECK_SIZEOF(uint16_t)
329 AC_CHECK_SIZEOF(uint32_t)
330 AC_CHECK_SIZEOF(uint64_t)
331 AC_CHECK_SIZEOF(intptr_t)
332 AC_CHECK_SIZEOF(uintptr_t)
334 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
336 AC_CHECK_SIZEOF(char)
337 AC_CHECK_SIZEOF(short)
338 AC_CHECK_SIZEOF(int)
339 AC_CHECK_SIZEOF(long)
340 AC_CHECK_SIZEOF(long long)
341 AC_CHECK_SIZEOF(__int64)
342 AC_CHECK_SIZEOF(void *)
343 AC_CHECK_SIZEOF(time_t)
344 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
345 AC_TRY_RUN([
346 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
347   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
350 if test $tor_cv_time_t_signed = yes; then
351   AC_DEFINE([TIME_T_IS_SIGNED], 1,
352             [Define to 1 iff time_t is signed])
355 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
356 #ifdef HAVE_SYS_SOCKET_H
357 #include <sys/socket.h>
358 #endif
361 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
363 AC_CHECK_SIZEOF(cell_t)
365 # Now, let's see about alignment requirements.  On some platforms, we override
366 # the default.
367 case $host in
368  ia64-*-* | arm-*-* | sparc-*-* )
369     tor_cv_unaligned_ok=no
370     ;;
371  *)
372 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
373 [AC_RUN_IFELSE([AC_LANG_SOURCE(
374 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
375 return *(int*)(&s[1]); }]])],
376        [tor_cv_unaligned_ok=yes],
377        [tor_cv_unaligned_ok=no],
378        [tor_cv_unaligned_ok=cross])])
379 esac
381 if test $tor_cv_unaligned_ok = yes; then
382   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
383             [Define to 1 iff unaligned int access is allowed])
386 # Now make sure that NULL can be represented as zero bytes.
387 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
388 [AC_RUN_IFELSE([AC_LANG_SOURCE(
389 [[#include <stdlib.h>
390 #include <string.h>
391 #include <stdio.h>
392 #ifdef HAVE_STDDEF_H
393 #include <stddef.h>
394 #endif
395 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
396 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
397        [tor_cv_null_is_zero=yes],
398        [tor_cv_null_is_zero=no],
399        [tor_cv_null_is_zero=cross])])
401 if test $tor_cv_null_is_zero = yes; then
402   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
403             [Define to 1 iff memset(0) sets pointers to NULL])
406 # Whether we should use the dmalloc memory allocation debugging library.
407 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
408 AC_ARG_WITH(dmalloc,
409 [  --with-dmalloc          Use debug memory allocation library. ],
410 [if [[ "$withval" = "yes" ]]; then
411   dmalloc=1
412   AC_MSG_RESULT(yes)
413 else
414   dmalloc=1
415   AC_MSG_RESULT(no)
416 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
419 if [[ $dmalloc -eq 1 ]]; then
420   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
421   AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
422   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
423   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
426 # Check for gethostbyname_r in all its glorious incompatible versions.
427 #   (This logic is based on that in Python's configure.in)
428 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
429   [Define this if you have any gethostbyname_r()])
431 AC_CHECK_FUNC(gethostbyname_r, [
432   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
433   OLD_CFLAGS=$CFLAGS
434   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
435   AC_TRY_COMPILE([
436 #include <netdb.h>
437   ], [
438     char *cp1, *cp2;
439     struct hostent *h1, *h2;
440     int i1, i2;
441     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
442   ], [
443     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
444     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
445      [Define this if gethostbyname_r takes 6 arguments])
446     AC_MSG_RESULT(6)
447   ], [
448     AC_TRY_COMPILE([
449 #include <netdb.h>
450     ], [
451       char *cp1, *cp2;
452       struct hostent *h1;
453       int i1, i2;
454       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
455     ], [
456       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
457       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
458         [Define this if gethostbyname_r takes 5 arguments])
459       AC_MSG_RESULT(5)
460    ], [
461       AC_TRY_COMPILE([
462 #include <netdb.h>
463      ], [
464        char *cp1;
465        struct hostent *h1;
466        struct hostent_data hd;
467        (void) gethostbyname_r(cp1,h1,&hd);
468      ], [
469        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
470        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
471          [Define this if gethostbyname_r takes 3 arguments])
472        AC_MSG_RESULT(3)
473      ], [
474        AC_MSG_RESULT(0)
475      ])
476   ])
477  ])
478  CFLAGS=$OLD_CFLAGS
481 # $prefix stores the value of the --prefix command line option, or
482 # NONE if the option wasn't set.  In the case that it wasn't set, make
483 # it be the default, so that we can use it to expand directories now.
484 if test "x$prefix" = "xNONE"; then
485   prefix=$ac_default_prefix
488 # and similarly for $exec_prefix
489 if test "x$exec_prefix" = "xNONE"; then
490   exec_prefix=$prefix
493 CONFDIR=`eval echo $sysconfdir/tor`
494 AC_SUBST(CONFDIR)
495 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
496 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
498 BINDIR=`eval echo $bindir`
499 AC_SUBST(BINDIR)
501 LOCALSTATEDIR=`eval echo $localstatedir`
502 AC_SUBST(LOCALSTATEDIR)
503 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
504 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
506 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
507 # than autoconf's macros like.
508 CFLAGS="$CFLAGS -Wall -g -O2"
509 # Add some more warnings which we use in the cvs version but not in the
510 # released versions.  (Some relevant gcc versions can't handle these.)
511 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
512 # Add these in when you feel like fun.
513 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
515 echo "confdir: $CONFDIR"
517 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)
519 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
520   ./contrib/updateVersions.pl