Implement --with-libevent-dir. Improve libevent search techniques. May be buggy...
[tor.git] / configure.in
blob65ce6b74c92d37f8e5bee6ba6e98de11fea7f24a
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.12-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 tryssldir=""
60 AC_ARG_WITH(ssl-dir,
61         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
62         [
63                 if test "x$withval" != "xno" ; then
64                         tryssldir=$withval
65                 fi
66         ]
69 trylibeventdir=""
70 AC_ARG_WITH(libevent-dir,
71        [  --with-libevent-dir=PATH     Specify path to Libevent installation ],
72        [
73                 if test "x$withval" != "xno" ; then
74                         trylibeventdir=$withval
75                 fi
76        ]
79 TORUSER=_tor
80 AC_ARG_WITH(tor-user,
81         [  --with-tor-user=NAME    Specify username for tor daemon ],
82         [
83            TORUSER=$withval
84         ]
86 AC_SUBST(TORUSER)
88 TORGROUP=_tor
89 AC_ARG_WITH(tor-group,
90         [  --with-tor-group=NAME   Specify group name for tor daemon ],
91         [
92            TORGROUP=$withval
93         ]
95 AC_SUBST(TORGROUP)
97 AC_SEARCH_LIBS(socket, [socket])
98 AC_SEARCH_LIBS(gethostbyname, [nsl])
99 AC_SEARCH_LIBS(dlopen, [dl])
101 if test $enable_threads = "yes"; then
102   AC_SEARCH_LIBS(pthread_create, [pthread])
103   AC_SEARCH_LIBS(pthread_detach, [pthread])
106 dnl ------------------------------------------------------
107 dnl Where do you live, libevent?  And how do we call you?
109 saved_LIBS="$LIBS"
110 saved_LDFLAGS="$LDFLAGS"
111 if test "x$prefix" != "xNONE" ; then
112         trylibeventdir="$trylibeventdir $prefix"
115 AC_CACHE_CHECK([for libevent location], ac_cv_libevent_dir, [
116   for ledir in $trylibeventdir "" /usr/local ; do
117     LDFLAGS="$saved_LDFLAGS"
118     LIBS="$saved_LIBS -levent"
119     
120     # Skip the directory if it isn't there.
121     if test ! -z "$ledir" -a ! -d "$ledir" ; then
122        continue;  
123     fi
124     if test ! -z "$ledir" ; then
125       if test -d "$ledir/lib" ; then
126         LDFLAGS="-L$ledir/lib $LDFLAGS"
127       else
128         LDFLAGS="-L$ledir $LDFLAGS"
129       fi
130     fi
131     # Can I link it?
132     AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
133        [ libevent_linked=yes ], [ libevent_linked=no ])
134     if test $libevent_linked = yes; then
135        if test ! -z "$ledir" ; then
136          ac_cv_libevent_dir=$ledir
137        else
138          ac_cv_libevent_dir="(system)"
139        fi
140        break
141     fi
142   done
144 LIBS="$LIBS -levent"
145 if test $ac_cv_libevent_dir != "(system)"; then
146   if test -d "$ac_cv_libevent_dir/lib" ; then
147     LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
148     le_libdir="$ac_cv_libevent_dir/lib"
149   else
150     LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
151     le_libdir="$ac_cv_libevent_dir"
152   fi
153   if test -d "$ac_cv_libevent_dir/include" ; then
154     CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
155   else
156     CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
157   fi
160 AC_CACHE_CHECK([whether libevent is in LDPATH], ac_cv_libevent_in_ldpath, [
161     saved_LDFLAGS="$LDFLAGS"
162     AC_TRY_RUN([void *event_init(void);
163                 int main(int c, char **v) {
164                    event_init(); return 0;
165                 }], 
166                 libevent_runs=yes, libevent_runs=no)
167     if test $libevent_runs = yes; then
168        ac_cv_libevent_in_ldpath=yes
169     else
170        LDFLAGS="$LDFLAGS -Wl,-R$le_libdir"
171        AC_TRY_RUN([void *event_init(void);
172                 int main(int c, char **v) {
173                    event_init(); return 0;
174                 }], 
175                 libevent_runs_with_r=yes, libevent_runs_with_r=no)
176        if test $libevent_runs_with_r = yes; then
177          ac_cv_libevent_in_ldpath=no
178        else
179          AC_MSG_ERROR([Found linkable libevent in $ac_cv_libevent_dir, but it doesn't run, even with -R.  Maybe specify another using --with-libevent-dir?])
180        fi
181     fi
182     LDFLAGS="$saved_LDFLAGS"
185 if test $ac_cv_libevent_in_ldpath = no ; then
186    LDFLAGS="$LDFLAGS -Wl,-R$le_libdir"
189 dnl ------------------------------------------------------
190 dnl Where do you live, OpenSSL?
192 saved_LIBS="$LIBS"
193 saved_LDFLAGS="$LDFLAGS"
194 saved_CPPFLAGS="$CPPFLAGS"
195 if test "x$prefix" != "xNONE" ; then
196         tryssldir="$tryssldir $prefix"
198 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
199         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
200                 CPPFLAGS="$saved_CPPFLAGS"
201                 LDFLAGS="$saved_LDFLAGS"
202                 LIBS="$saved_LIBS -lssl -lcrypto"
204                 # Skip directories if they don't exist
205                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
206                         continue;
207                 fi
208                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
209                         # Try to use $ssldir/lib if it exists, otherwise
210                         # $ssldir
211                         if test -d "$ssldir/lib" ; then
212                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
213                                 if test ! -z "$need_dash_r" ; then
214                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
215                                 fi
216                         else
217                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
218                                 if test ! -z "$need_dash_r" ; then
219                                         LDFLAGS="-R$ssldir $LDFLAGS"
220                                 fi
221                         fi
222                         # Try to use $ssldir/include if it exists, otherwise
223                         # $ssldir
224                         if test -d "$ssldir/include" ; then
225                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
226                         else
227                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
228                         fi
229                 fi
231                 # Basic test to check for compatible version and correct linking
232                 # *does not* test for RSA - that comes later.
233                 AC_TRY_RUN(
234                         [
235 #include <string.h>
236 #include <openssl/rand.h>
237 int main(void)
239         char a[2048];
240         memset(a, 0, sizeof(a));
241         RAND_add(a, sizeof(a), sizeof(a));
242         return(RAND_status() <= 0);
244                         ],
245                         [
246                                 found_crypto=1
247                                 break;
248                         ], []
249                 )
251                 if test ! -z "$found_crypto" ; then
252                         break;
253                 fi
254         done
256         if test -z "$found_crypto" ; then
257                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
258         fi
259         if test -z "$ssldir" ; then
260                 ssldir="(system)"
261         fi
263         ac_cv_openssldir=$ssldir
265 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
266  then
267         dnl Need to recover ssldir - test above runs in subshell
268         ssldir=$ac_cv_openssldir
269         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
270                 # Try to use $ssldir/lib if it exists, otherwise
271                 # $ssldir
272                 if test -d "$ssldir/lib" ; then
273                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
274                         if test ! -z "$need_dash_r" ; then
275                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
276                         fi
277                 else
278                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
279                         if test ! -z "$need_dash_r" ; then
280                                 LDFLAGS="-R$ssldir $LDFLAGS"
281                         fi
282                 fi
283                 # Try to use $ssldir/include if it exists, otherwise
284                 # $ssldir
285                 if test -d "$ssldir/include" ; then
286                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
287                 else
288                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
289                 fi
290         fi
292 LIBS="$saved_LIBS"
294 AC_SYS_LARGEFILE
296 dnl The warning message here is no longer strictly accurate.
298 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))
300 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
302 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.))
304 dnl These headers are not essential
306 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)
308 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)
310 if test $enable_threads = "yes"; then
311   AC_CHECK_HEADERS(pthread.h)
312   AC_CHECK_FUNCS(pthread_create)
315 AC_FUNC_FSEEKO
317 AC_CHECK_MEMBERS([struct timeval.tv_sec])
319 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
320 dnl Watch out.
322 AC_CHECK_SIZEOF(int8_t)
323 AC_CHECK_SIZEOF(int16_t)
324 AC_CHECK_SIZEOF(int32_t)
325 AC_CHECK_SIZEOF(int64_t)
326 AC_CHECK_SIZEOF(uint8_t)
327 AC_CHECK_SIZEOF(uint16_t)
328 AC_CHECK_SIZEOF(uint32_t)
329 AC_CHECK_SIZEOF(uint64_t)
330 AC_CHECK_SIZEOF(intptr_t)
331 AC_CHECK_SIZEOF(uintptr_t)
333 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
335 AC_CHECK_SIZEOF(char)
336 AC_CHECK_SIZEOF(short)
337 AC_CHECK_SIZEOF(int)
338 AC_CHECK_SIZEOF(long)
339 AC_CHECK_SIZEOF(long long)
340 AC_CHECK_SIZEOF(__int64)
341 AC_CHECK_SIZEOF(void *)
342 AC_CHECK_SIZEOF(time_t)
343 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
344 AC_TRY_RUN([
345 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
346   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
349 if test $tor_cv_time_t_signed = yes; then
350   AC_DEFINE([TIME_T_IS_SIGNED], 1,
351             [Define to 1 iff time_t is signed])
354 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
355 #ifdef HAVE_SYS_SOCKET_H
356 #include <sys/socket.h>
357 #endif
360 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
362 AC_CHECK_SIZEOF(cell_t)
364 # Now, let's see about alignment requirements.  On some platforms, we override
365 # the default.
366 case $host in
367  ia64-*-* | arm-*-* | sparc-*-* | sparc64-*-* )
368     tor_cv_unaligned_ok=no
369     ;;
370  # On the following architectures unaligned access works, but is not done in
371  # hardware.  This means that when you try to do unaligned access the kernel
372  # gets to sort out an exception and then work around to somehow make your
373  # reqest work, which is quite expensive.  Therefore it's probably better to
374  # not even do it.
375  alpha-*-* | mips-*-* | mipsel-*-* )
376     tor_cv_unaligned_ok=no
377     ;;
378  *)
379 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
380 [AC_RUN_IFELSE([AC_LANG_SOURCE(
381 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
382 return *(int*)(&s[1]); }]])],
383        [tor_cv_unaligned_ok=yes],
384        [tor_cv_unaligned_ok=no],
385        [tor_cv_unaligned_ok=cross])])
386 esac
388 if test $tor_cv_unaligned_ok = yes; then
389   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
390             [Define to 1 iff unaligned int access is allowed])
393 # Now make sure that NULL can be represented as zero bytes.
394 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
395 [AC_RUN_IFELSE([AC_LANG_SOURCE(
396 [[#include <stdlib.h>
397 #include <string.h>
398 #include <stdio.h>
399 #ifdef HAVE_STDDEF_H
400 #include <stddef.h>
401 #endif
402 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
403 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
404        [tor_cv_null_is_zero=yes],
405        [tor_cv_null_is_zero=no],
406        [tor_cv_null_is_zero=cross])])
408 if test $tor_cv_null_is_zero = yes; then
409   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
410             [Define to 1 iff memset(0) sets pointers to NULL])
413 # Whether we should use the dmalloc memory allocation debugging library.
414 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
415 AC_ARG_WITH(dmalloc,
416 [  --with-dmalloc          Use debug memory allocation library. ],
417 [if [[ "$withval" = "yes" ]]; then
418   dmalloc=1
419   AC_MSG_RESULT(yes)
420 else
421   dmalloc=1
422   AC_MSG_RESULT(no)
423 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
426 if [[ $dmalloc -eq 1 ]]; then
427   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
428   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
429   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
430   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
433 # Check for gethostbyname_r in all its glorious incompatible versions.
434 #   (This logic is based on that in Python's configure.in)
435 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
436   [Define this if you have any gethostbyname_r()])
438 AC_CHECK_FUNC(gethostbyname_r, [
439   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
440   OLD_CFLAGS=$CFLAGS
441   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
442   AC_TRY_COMPILE([
443 #include <netdb.h>
444   ], [
445     char *cp1, *cp2;
446     struct hostent *h1, *h2;
447     int i1, i2;
448     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
449   ], [
450     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
451     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
452      [Define this if gethostbyname_r takes 6 arguments])
453     AC_MSG_RESULT(6)
454   ], [
455     AC_TRY_COMPILE([
456 #include <netdb.h>
457     ], [
458       char *cp1, *cp2;
459       struct hostent *h1;
460       int i1, i2;
461       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
462     ], [
463       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
464       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
465         [Define this if gethostbyname_r takes 5 arguments])
466       AC_MSG_RESULT(5)
467    ], [
468       AC_TRY_COMPILE([
469 #include <netdb.h>
470      ], [
471        char *cp1;
472        struct hostent *h1;
473        struct hostent_data hd;
474        (void) gethostbyname_r(cp1,h1,&hd);
475      ], [
476        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
477        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
478          [Define this if gethostbyname_r takes 3 arguments])
479        AC_MSG_RESULT(3)
480      ], [
481        AC_MSG_RESULT(0)
482      ])
483   ])
484  ])
485  CFLAGS=$OLD_CFLAGS
488 # $prefix stores the value of the --prefix command line option, or
489 # NONE if the option wasn't set.  In the case that it wasn't set, make
490 # it be the default, so that we can use it to expand directories now.
491 if test "x$prefix" = "xNONE"; then
492   prefix=$ac_default_prefix
495 # and similarly for $exec_prefix
496 if test "x$exec_prefix" = "xNONE"; then
497   exec_prefix=$prefix
500 CONFDIR=`eval echo $sysconfdir/tor`
501 AC_SUBST(CONFDIR)
502 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
503 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
505 BINDIR=`eval echo $bindir`
506 AC_SUBST(BINDIR)
508 LOCALSTATEDIR=`eval echo $localstatedir`
509 AC_SUBST(LOCALSTATEDIR)
510 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
511 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
513 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
514 # than autoconf's macros like.
515 CFLAGS="$CFLAGS -Wall -g -O2"
516 # Add some more warnings which we use in the cvs version but not in the
517 # released versions.  (Some relevant gcc versions can't handle these.)
518 #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"
519 # Add these in when you feel like fun.
520 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement -Wold-style-definition"
522 echo "confdir: $CONFDIR"
524 AC_OUTPUT(Makefile tor.spec contrib/tor.sh contrib/torctl contrib/torify contrib/tor.logrotate 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)
526 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
527   ./contrib/updateVersions.pl