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