add HttpProxyAuthenticator config option too
[tor.git] / configure.in
blob345bcd70c5dd065522e9ffa7f30f81b0ea2d1e5f
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.7-rc-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     *)
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?
66 AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
67    saved_LIBS="$LIBS"
68    LIBS="$LIBS -levent"
69    AC_TRY_RUN([
70 void *event_init(void);
71 int main(void)
73         if (!event_init())
74                 return -1;
75         return 0;
76 }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
77    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      AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
90         [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
91     if test $libevent_is_in_local = yes; then
92        AC_TRY_RUN([
93 void *event_init(void);
94 int main(void)
96         if (!event_init())
97                 return -1;
98         return 0;
99 }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
100     else
101        ac_cv_libevent_local=no   
102     fi
103     if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
104        LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
105        AC_TRY_RUN([
106 void *event_init(void);
107 int main(void)
109         if (!event_init())
110                 return -1;
111         return 0;
112 }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
113     fi 
115     LIBS="$saved_LIBS"
116     CFLAGS="$saved_CFLAGS"
117     LDFLAGS="$saved_LDFLAGS" ])
119   if test $ac_cv_libevent_local != no; then
120       LIBS="$LIBS -levent"
121       LDFLAGS="$LDFLAGS -L/usr/local/lib"
122       CPPFLAGS="$CPPFLAGS -I/usr/local/include"
123   fi
124   if test $ac_cv_libevent_local = unlinked_gcc_elf; then
125       LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
126       if test -f /etc/ld.so.conf ; then
127         AC_MSG_NOTICE([
128 Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
129 Tor is smart enought to deal this now, but other applications aren't.
130 You might want to add it in.])
131       fi
132   fi
134   if test $ac_cv_libevent_local = unlinked ; then
135     if test -f /etc/ld.so.conf ; then
136       AC_MSG_NOTICE([
137 =================================================
138 Your libevent library is installed in /usr/local/lib,
139 but your dynamic linker isn't configured to look for
140 it there.
142 Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
143 and then run ldconfig -v ?
144 =================================================])
145     else
146       AC_MSG_NOTICE([
147 =================================================
148 Your libevent library is installed in /usr/local/lib,
149 but your dynamic linker isn't configured to look for
150 it there.
151 =================================================])
152     fi 
153   fi
155   if test $ac_cv_libevent_local = no ; then
156       AC_MSG_ERROR([
157 Tor requires libevent to build.  You can download the latest
158 version of libevent from http://monkey.org/~provos/libevent/])
159   fi
163 dnl ------------------------------------------------------
164 dnl Where do you live, OpenSSL?
166 saved_LIBS="$LIBS"
167 saved_LDFLAGS="$LDFLAGS"
168 saved_CPPFLAGS="$CPPFLAGS"
169 if test "x$prefix" != "xNONE" ; then
170         tryssldir="$tryssldir $prefix"
172 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
173         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
174                 CPPFLAGS="$saved_CPPFLAGS"
175                 LDFLAGS="$saved_LDFLAGS"
176                 LIBS="$saved_LIBS -lssl -lcrypto"
178                 # Skip directories if they don't exist
179                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
180                         continue;
181                 fi
182                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
183                         # Try to use $ssldir/lib if it exists, otherwise
184                         # $ssldir
185                         if test -d "$ssldir/lib" ; then
186                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
187                                 if test ! -z "$need_dash_r" ; then
188                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
189                                 fi
190                         else
191                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
192                                 if test ! -z "$need_dash_r" ; then
193                                         LDFLAGS="-R$ssldir $LDFLAGS"
194                                 fi
195                         fi
196                         # Try to use $ssldir/include if it exists, otherwise
197                         # $ssldir
198                         if test -d "$ssldir/include" ; then
199                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
200                         else
201                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
202                         fi
203                 fi
205                 # Basic test to check for compatible version and correct linking
206                 # *does not* test for RSA - that comes later.
207                 AC_TRY_RUN(
208                         [
209 #include <string.h>
210 #include <openssl/rand.h>
211 int main(void)
213         char a[2048];
214         memset(a, 0, sizeof(a));
215         RAND_add(a, sizeof(a), sizeof(a));
216         return(RAND_status() <= 0);
218                         ],
219                         [
220                                 found_crypto=1
221                                 break;
222                         ], []
223                 )
225                 if test ! -z "$found_crypto" ; then
226                         break;
227                 fi
228         done
230         if test -z "$found_crypto" ; then
231                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
232         fi
233         if test -z "$ssldir" ; then
234                 ssldir="(system)"
235         fi
237         ac_cv_openssldir=$ssldir
239 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
240  then
241         dnl Need to recover ssldir - test above runs in subshell
242         ssldir=$ac_cv_openssldir
243         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
244                 # Try to use $ssldir/lib if it exists, otherwise
245                 # $ssldir
246                 if test -d "$ssldir/lib" ; then
247                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
248                         if test ! -z "$need_dash_r" ; then
249                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
250                         fi
251                 else
252                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
253                         if test ! -z "$need_dash_r" ; then
254                                 LDFLAGS="-R$ssldir $LDFLAGS"
255                         fi
256                 fi
257                 # Try to use $ssldir/include if it exists, otherwise
258                 # $ssldir
259                 if test -d "$ssldir/include" ; then
260                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
261                 else
262                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
263                 fi
264         fi
266 LIBS="$saved_LIBS"
268 AC_SYS_LARGEFILE
270 dnl The warning message here is no longer strictly accurate.
272 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))
274 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
276 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.))
278 dnl These headers are not essential
280 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)
282 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)
283 AC_FUNC_FSEEKO
285 AC_CHECK_MEMBERS([struct timeval.tv_sec])
288 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
289 dnl Watch out.
291 AC_CHECK_SIZEOF(int8_t)
292 AC_CHECK_SIZEOF(int16_t)
293 AC_CHECK_SIZEOF(int32_t)
294 AC_CHECK_SIZEOF(int64_t)
295 AC_CHECK_SIZEOF(uint8_t)
296 AC_CHECK_SIZEOF(uint16_t)
297 AC_CHECK_SIZEOF(uint32_t)
298 AC_CHECK_SIZEOF(uint64_t)
299 AC_CHECK_SIZEOF(intptr_t)
300 AC_CHECK_SIZEOF(uintptr_t)
302 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
304 AC_CHECK_SIZEOF(char)
305 AC_CHECK_SIZEOF(short)
306 AC_CHECK_SIZEOF(int)
307 AC_CHECK_SIZEOF(long)
308 AC_CHECK_SIZEOF(long long)
309 AC_CHECK_SIZEOF(__int64)
310 AC_CHECK_SIZEOF(void *)
311 AC_CHECK_SIZEOF(time_t)
312 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
313 #ifdef HAVE_SYS_SOCKET_H
314 #include <sys/socket.h>
315 #endif
318 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
320 AC_CHECK_SIZEOF(cell_t)
322 # Now, let's see about alignment requirements.  On some platforms, we override
323 # the default.
324 case $host in
325  ia64-*-* | arm-*-* )
326     tor_cv_unaligned_ok=no
327     ;;
328  *)
329 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
330 [AC_RUN_IFELSE([AC_LANG_SOURCE(
331 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
332 return *(int*)(&s[1]); }]])],
333        [tor_cv_unaligned_ok=yes],
334        [tor_cv_unaligned_ok=no],
335        [tor_cv_unaligned_ok=cross])])
336 esac
338 if test $tor_cv_unaligned_ok = yes; then
339   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
340             [Define to 1 iff unaligned int access is allowed])
343 # Now make sure that NULL can be represented as zero bytes.
344 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
345 [AC_RUN_IFELSE([AC_LANG_SOURCE(
346 [[#include <stdlib.h>
347 #include <string.h>
348 #include <stdio.h>
349 #ifdef HAVE_STDDEF_H
350 #include <stddef.h>
351 #endif
352 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
353 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
354        [tor_cv_null_is_zero=yes],
355        [tor_cv_null_is_zero=no],
356        [tor_cv_null_is_zero=cross])])
358 if test $tor_cv_null_is_zero = yes; then
359   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
360             [Define to 1 iff memset(0) sets pointers to NULL])
363 # Whether we should use the dmalloc memory allocation debugging library.
364 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
365 AC_ARG_WITH(dmalloc,
366 [  --with-dmalloc          Use debug memory allocation library. ],
367 [if [[ "$withval" = "yes" ]]; then
368   dmalloc=1
369   AC_MSG_RESULT(yes)
370 else
371   dmalloc=1
372   AC_MSG_RESULT(no)
373 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
376 if [[ $dmalloc -eq 1 ]]; then
377   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
378   AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
379   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
380   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
383 # Check for gethostbyname_r in all its glorious incompatible versions.
384 #   (This logic is based on that in Python's configure.in)
385 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
386   [Define this if you have any gethostbyname_r()])
388 AC_CHECK_FUNC(gethostbyname_r, [
389   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
390   OLD_CFLAGS=$CFLAGS
391   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
392   AC_TRY_COMPILE([
393 #include <netdb.h>
394   ], [
395     char *cp1, *cp2;
396     struct hostent *h1, *h2;
397     int i1, i2;
398     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
399   ], [
400     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
401     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
402      [Define this if gethostbyname_r takes 6 arguments])
403     AC_MSG_RESULT(6)
404   ], [
405     AC_TRY_COMPILE([
406 #include <netdb.h>
407     ], [
408       char *cp1, *cp2;
409       struct hostent *h1;
410       int i1, i2;
411       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
412     ], [
413       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
414       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
415         [Define this if gethostbyname_r takes 5 arguments])
416       AC_MSG_RESULT(5)
417    ], [
418       AC_TRY_COMPILE([
419 #include <netdb.h>
420      ], [
421        char *cp1;
422        struct hostent *h1;
423        struct hostent_data hd;
424        (void) gethostbyname_r(cp1,h1,&hd);
425      ], [
426        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
427        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
428          [Define this if gethostbyname_r takes 3 arguments])
429        AC_MSG_RESULT(3)
430      ], [
431        AC_MSG_RESULT(0)
432      ])
433   ])
434  ])
435  CFLAGS=$OLD_CFLAGS
438 # $prefix stores the value of the --prefix command line option, or
439 # NONE if the option wasn't set.  In the case that it wasn't set, make
440 # it be the default, so that we can use it to expand directories now.
441 if test "x$prefix" = "xNONE"; then
442   prefix=$ac_default_prefix
445 # and similarly for $exec_prefix
446 if test "x$exec_prefix" = "xNONE"; then
447   exec_prefix=$prefix
450 CONFDIR=`eval echo $sysconfdir/tor`
451 AC_SUBST(CONFDIR)
452 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
453 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
455 BINDIR=`eval echo $bindir`
456 AC_SUBST(BINDIR)
458 LOCALSTATEDIR=`eval echo $localstatedir`
459 AC_SUBST(LOCALSTATEDIR)
460 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
461 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
463 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
464 # than autoconf's macros like.
465 CFLAGS="$CFLAGS -Wall -g -O2"
466 # Add some more warnings which we use in the cvs version but not in the
467 # released versions.  (Some relevant gcc versions can't handle these.)
468 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
469 # Add these in when you feel like fun.
470 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
472 echo "confdir: $CONFDIR"
474 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)
476 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
477   ./contrib/updateVersions.pl