2 dnl Copyright 2001-2004 Roger Dingledine
3 dnl Copyright 2004-2005 Roger Dingledine, Nick Mathewson
4 dnl See LICENSE for licensing information
7 AM_INIT_AUTOMAKE(tor, 0.1.0.7-rc-cvs)
8 AM_CONFIG_HEADER(orconfig.h)
12 if test -f /etc/redhat-release; then
13 CFLAGS="$CFLAGS -I/usr/kerberos/include"
17 AC_HELP_STRING(--enable-debug, compile with debugging info),
18 [if test x$enableval = xyes; then
22 AC_ARG_ENABLE(threads,
23 AC_HELP_STRING(--disable-threads, disable multi-threading support))
25 if test x$enable_threads = x; then
28 # Don't try multithreading on netbsd -- there is no threadsafe DNS
29 # lookup function there.
32 enable_threads="yes";;
36 if test $enable_threads = "yes"; then
37 AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
44 # The big search for OpenSSL
45 # copied from openssh's configure.ac
47 [ --with-ssl-dir=PATH Specify path to OpenSSL installation ],
49 if test "x$withval" != "xno" ; then
55 AC_SEARCH_LIBS(socket, [socket])
56 AC_SEARCH_LIBS(gethostbyname, [nsl])
57 AC_SEARCH_LIBS(pthread_create, [pthread])
58 AC_SEARCH_LIBS(pthread_detach, [pthread])
60 dnl ------------------------------------------------------
61 dnl Where do you live, libevent?
64 AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
68 void *event_init(void);
74 }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
79 if test "$ac_cv_libevent_normal" = yes; then
82 AC_CACHE_CHECK([for libevent in /usr/local/lib], ac_cv_libevent_local, [
84 saved_LDFLAGS="$LDFLAGS"
86 LDFLAGS="$LDFLAGS -L/usr/local/lib"
87 AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
88 [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
89 if test $libevent_is_in_local = yes; then
91 void *event_init(void);
97 }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
99 ac_cv_libevent_local=no
101 if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
102 LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
104 void *event_init(void);
110 }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
114 CFLAGS="$saved_CFLAGS"
115 LDFLAGS="$saved_LDFLAGS" ])
117 if test $ac_cv_libevent_local != no; then
119 LDFLAGS="$LDFLAGS -L/usr/local/lib"
120 CPPFLAGS="$CPPFLAGS -I/usr/local/include"
122 if test $ac_cv_libevent_local = unlinked_gcc_elf; then
123 LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
124 if test -f /etc/ld.so.conf ; then
126 Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
127 Tor is smart enought to deal this now, but other applications aren't.
128 You might want to add it in.])
132 if test $ac_cv_libevent_local = unlinked ; then
133 if test -f /etc/ld.so.conf ; then
135 =================================================
136 Your libevent library is installed in /usr/local/lib,
137 but your dynamic linker isn't configured to look for
140 Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
141 and then run ldconfig -v ?
142 =================================================])
145 =================================================
146 Your libevent library is installed in /usr/local/lib,
147 but your dynamic linker isn't configured to look for
149 =================================================])
153 if test $ac_cv_libevent_local = no ; then
155 Tor requires libevent to build. You can download the latest
156 version of libevent from http://monkey.org/~provos/libevent/])
161 dnl ------------------------------------------------------
162 dnl Where do you live, OpenSSL?
165 saved_LDFLAGS="$LDFLAGS"
166 saved_CPPFLAGS="$CPPFLAGS"
167 if test "x$prefix" != "xNONE" ; then
168 tryssldir="$tryssldir $prefix"
170 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
171 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
172 CPPFLAGS="$saved_CPPFLAGS"
173 LDFLAGS="$saved_LDFLAGS"
174 LIBS="$saved_LIBS -lssl -lcrypto"
176 # Skip directories if they don't exist
177 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
180 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
181 # Try to use $ssldir/lib if it exists, otherwise
183 if test -d "$ssldir/lib" ; then
184 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
185 if test ! -z "$need_dash_r" ; then
186 LDFLAGS="-R$ssldir/lib $LDFLAGS"
189 LDFLAGS="-L$ssldir $saved_LDFLAGS"
190 if test ! -z "$need_dash_r" ; then
191 LDFLAGS="-R$ssldir $LDFLAGS"
194 # Try to use $ssldir/include if it exists, otherwise
196 if test -d "$ssldir/include" ; then
197 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
199 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
203 # Basic test to check for compatible version and correct linking
204 # *does not* test for RSA - that comes later.
208 #include <openssl/rand.h>
212 memset(a, 0, sizeof(a));
213 RAND_add(a, sizeof(a), sizeof(a));
214 return(RAND_status() <= 0);
223 if test ! -z "$found_crypto" ; then
228 if test -z "$found_crypto" ; then
229 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
231 if test -z "$ssldir" ; then
235 ac_cv_openssldir=$ssldir
237 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
239 dnl Need to recover ssldir - test above runs in subshell
240 ssldir=$ac_cv_openssldir
241 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
242 # Try to use $ssldir/lib if it exists, otherwise
244 if test -d "$ssldir/lib" ; then
245 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
246 if test ! -z "$need_dash_r" ; then
247 LDFLAGS="-R$ssldir/lib $LDFLAGS"
250 LDFLAGS="-L$ssldir $saved_LDFLAGS"
251 if test ! -z "$need_dash_r" ; then
252 LDFLAGS="-R$ssldir $LDFLAGS"
255 # Try to use $ssldir/include if it exists, otherwise
257 if test -d "$ssldir/include" ; then
258 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
260 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
268 dnl The warning message here is no longer strictly accurate.
270 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))
272 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
274 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.))
276 dnl These headers are not essential
278 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)
280 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_CHECK_MEMBERS([struct timeval.tv_sec])
286 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
289 AC_CHECK_SIZEOF(int8_t)
290 AC_CHECK_SIZEOF(int16_t)
291 AC_CHECK_SIZEOF(int32_t)
292 AC_CHECK_SIZEOF(int64_t)
293 AC_CHECK_SIZEOF(uint8_t)
294 AC_CHECK_SIZEOF(uint16_t)
295 AC_CHECK_SIZEOF(uint32_t)
296 AC_CHECK_SIZEOF(uint64_t)
297 AC_CHECK_SIZEOF(intptr_t)
298 AC_CHECK_SIZEOF(uintptr_t)
300 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
302 AC_CHECK_SIZEOF(char)
303 AC_CHECK_SIZEOF(short)
305 AC_CHECK_SIZEOF(long)
306 AC_CHECK_SIZEOF(long long)
307 AC_CHECK_SIZEOF(__int64)
308 AC_CHECK_SIZEOF(void *)
309 AC_CHECK_SIZEOF(time_t)
310 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
311 #ifdef HAVE_SYS_SOCKET_H
312 #include <sys/socket.h>
316 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
318 AC_CHECK_SIZEOF(cell_t)
320 # Now, let's see about alignment requirements. On some platforms, we override
324 tor_cv_unaligned_ok=no
327 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
328 [AC_RUN_IFELSE([AC_LANG_SOURCE(
329 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
330 return *(int*)(&s[1]); }]])],
331 [tor_cv_unaligned_ok=yes],
332 [tor_cv_unaligned_ok=no],
333 [tor_cv_unaligned_ok=cross])])
336 if test $tor_cv_unaligned_ok = yes; then
337 AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
338 [Define to 1 iff unaligned int access is allowed])
341 # Now make sure that NULL can be represented as zero bytes.
342 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
343 [AC_RUN_IFELSE([AC_LANG_SOURCE(
344 [[#include <stdlib.h>
350 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
351 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
352 [tor_cv_null_is_zero=yes],
353 [tor_cv_null_is_zero=no],
354 [tor_cv_null_is_zero=cross])])
356 if test $tor_cv_null_is_zero = yes; then
357 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
358 [Define to 1 iff memset(0) sets pointers to NULL])
361 # Whether we should use the dmalloc memory allocation debugging library.
362 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
364 [ --with-dmalloc Use debug memory allocation library. ],
365 [if [[ "$withval" = "yes" ]]; then
371 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
374 if [[ $dmalloc -eq 1 ]]; then
375 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
376 AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
377 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
378 AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
381 # Check for gethostbyname_r in all its glorious incompatible versions.
382 # (This logic is based on that in Python's configure.in)
383 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
384 [Define this if you have any gethostbyname_r()])
386 AC_CHECK_FUNC(gethostbyname_r, [
387 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
389 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
394 struct hostent *h1, *h2;
396 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
398 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
399 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
400 [Define this if gethostbyname_r takes 6 arguments])
409 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
411 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
412 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
413 [Define this if gethostbyname_r takes 5 arguments])
421 struct hostent_data hd;
422 (void) gethostbyname_r(cp1,h1,&hd);
424 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
425 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
426 [Define this if gethostbyname_r takes 3 arguments])
436 # $prefix stores the value of the --prefix command line option, or
437 # NONE if the option wasn't set. In the case that it wasn't set, make
438 # it be the default, so that we can use it to expand directories now.
439 if test "x$prefix" = "xNONE"; then
440 prefix=$ac_default_prefix
443 # and similarly for $exec_prefix
444 if test "x$exec_prefix" = "xNONE"; then
448 CONFDIR=`eval echo $sysconfdir/tor`
450 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
451 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
453 BINDIR=`eval echo $bindir`
456 LOCALSTATEDIR=`eval echo $localstatedir`
457 AC_SUBST(LOCALSTATEDIR)
458 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
459 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
461 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
462 # than autoconf's macros like.
463 CFLAGS="$CFLAGS -Wall -g -O2"
464 # Add some more warnings which we use in the cvs version but not in the
465 # released versions. (Some relevant gcc versions can't handle these.)
466 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
467 # Add these in when you feel like fun.
468 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
470 echo "confdir: $CONFDIR"
472 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)
474 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
475 ./contrib/updateVersions.pl