2 dnl Copyright (c) 2001-2005 Roger Dingledine
3 dnl Copyright (c) 2004-2005 Nick Mathewson
4 dnl See LICENSE for licensing information
7 AM_INIT_AUTOMAKE(tor, 0.1.1.12-alpha-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
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.])
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.])
39 enable_threads="yes";;
43 if test $enable_threads = "yes"; then
44 AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
49 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
57 # The big search for OpenSSL
58 # copied from openssh's configure.ac
61 [ --with-ssl-dir=PATH Specify path to OpenSSL installation ],
63 if test "x$withval" != "xno" ; then
70 AC_ARG_WITH(libevent-dir,
71 [ --with-libevent-dir=PATH Specify path to Libevent installation ],
73 if test "x$withval" != "xno" ; then
74 trylibeventdir=$withval
81 [ --with-tor-user=NAME Specify username for tor daemon ],
89 AC_ARG_WITH(tor-group,
90 [ --with-tor-group=NAME Specify group name for tor daemon ],
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 AC_CACHE_CHECK([for libevent directory], ac_cv_libevent_dir, [
111 saved_LDFLAGS="$LDFLAGS"
113 for ledir in $trylibeventdir "" $prefix /usr/local ; do
114 LDFLAGS="$saved_LDFLAGS"
115 LIBS="$saved_LIBS -levent"
117 # Skip the directory if it isn't there.
118 if test ! -z "$ledir" -a ! -d "$ledir" ; then
121 if test ! -z "$ledir" ; then
122 if test -d "$ledir/lib" ; then
123 LDFLAGS="-L$ledir/lib $LDFLAGS"
125 LDFLAGS="-L$ledir $LDFLAGS"
129 AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
130 [ libevent_linked=yes ], [ libevent_linked=no ])
131 if test $libevent_linked = yes; then
132 if test ! -z "$ledir" ; then
133 ac_cv_libevent_dir=$ledir
135 ac_cv_libevent_dir="(system)"
142 LDFLAGS="$saved_LDFLAGS"
143 if test $le_found = no ; then
144 AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
148 if test $ac_cv_libevent_dir != "(system)"; then
149 if test -d "$ac_cv_libevent_dir/lib" ; then
150 LDFLAGS="-L$ac_cv_libevent_dir/lib $LDFLAGS"
151 le_libdir="$ac_cv_libevent_dir/lib"
153 LDFLAGS="-L$ac_cv_libevent_dir $LDFLAGS"
154 le_libdir="$ac_cv_libevent_dir"
156 if test -d "$ac_cv_libevent_dir/include" ; then
157 CPPFLAGS="-I$ac_cv_libevent_dir/include $CPPFLAGS"
160 CPPFLAGS="-I$ac_cv_libevent_dir $CPPFLAGS"
164 AC_CACHE_CHECK([whether we need extra options to link libevent],
165 ac_cv_libevent_linker_option, [
166 saved_LDFLAGS="$LDFLAGS"
168 for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" ; do
169 LDFLAGS="$le_extra $saved_LDFLAGS"
170 AC_TRY_RUN([void *event_init(void);
171 int main(int c, char **v) {
172 event_init(); return 0;
174 libevent_runs=yes, libevent_runs=no)
175 if test $libevent_runs = yes ; then
176 if test -z "$le_extra" ; then
177 ac_cv_libevent_linker_option='(none)'
179 ac_cv_libevent_linker_option=$le_extra
185 if test le_runs = no ; then
186 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?])
188 LDFLAGS="$saved_LDFLAGS"
191 if test $ac_cv_libevent_linker_option != '(none)' ; then
192 LDFLAGS="$ac_cv_libevent_linker_option $LDFLAGS"
195 dnl ------------------------------------------------------
196 dnl Where do you live, openssl? And how do we call you?
198 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [
200 saved_LDFLAGS="$LDFLAGS"
202 for ssldir in $tryssldir "" $prefix /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do
203 LDFLAGS="$saved_LDFLAGS"
204 LIBS="$saved_LIBS -lssl -lcrypto"
206 # Skip the directory if it isn't there.
207 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
210 if test ! -z "$ssldir" ; then
211 if test -d "$ssldir/lib" ; then
212 LDFLAGS="-L$ssldir/lib $LDFLAGS"
214 LDFLAGS="-L$ssldir $LDFLAGS"
219 [ void RAND_add(const void *, int, double); RAND_add((void*)0,0,0); ],
220 [ openssl_linked=yes ], [ openssl_linked=no ])
221 if test $openssl_linked = yes; then
222 if test ! -z "$ssldir" ; then
223 ac_cv_openssl_dir=$ssldir
225 ac_cv_openssl_dir="(system)"
232 LDFLAGS="$saved_LDFLAGS"
233 if test $ssl_found = no ; then
234 AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
237 LIBS="$LIBS -lssl -lcrypto"
238 if test "$ac_cv_openssl_dir" != "(system)"; then
239 if test -d "$ac_cv_openssl_dir/lib" ; then
240 LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS"
241 ssl_libdir="$ac_cv_openssl_dir/lib"
243 LDFLAGS="-L$ac_cv_openssl_dir $LDFLAGS"
244 ssl_libdir="$ac_cv_openssl_dir"
246 if test -d "$ac_cv_openssl_dir/include" ; then
247 CPPFLAGS="-I$ac_cv_openssl_dir/include $CPPFLAGS"
249 CPPFLAGS="-I$ac_cv_openssl_dir $CPPFLAGS"
253 AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
254 ac_cv_openssl_linker_option, [
255 saved_LDFLAGS="$LDFLAGS"
257 for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
258 LDFLAGS="$ssl_extra $saved_LDFLAGS"
261 #include <openssl/rand.h>
265 memset(a, 0, sizeof(a));
266 RAND_add(a, sizeof(a), sizeof(a));
267 return(RAND_status() <= 0);
270 openssl_runs=yes, openssl_runs=no)
271 if test $openssl_runs = yes ; then
272 if test -z "$ssl_extra" ; then
273 ac_cv_openssl_linker_option='(none)'
275 ac_cv_openssl_linker_option=$ssl_extra
281 if test ssl_runs = no ; then
282 AC_MSG_ERROR([Found linkable OpenSSL in $ac_cv_openssl_dir, but it doesn't run, even with -R. Maybe specify another using --with-ssl-dir?])
284 LDFLAGS="$saved_LDFLAGS"
287 if test $ac_cv_openssl_linker_option != '(none)' ; then
288 LDFLAGS="$ac_cv_openssl_linker_option $LDFLAGS"
291 dnl Make sure to enable support for large off_t if avalable.
295 dnl The warning message here is no longer strictly accurate.
297 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))
299 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
301 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.))
303 dnl These headers are not essential
305 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)
307 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)
309 if test $enable_threads = "yes"; then
310 AC_CHECK_HEADERS(pthread.h)
311 AC_CHECK_FUNCS(pthread_create)
316 AC_CHECK_MEMBERS([struct timeval.tv_sec])
318 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
321 AC_CHECK_SIZEOF(int8_t)
322 AC_CHECK_SIZEOF(int16_t)
323 AC_CHECK_SIZEOF(int32_t)
324 AC_CHECK_SIZEOF(int64_t)
325 AC_CHECK_SIZEOF(uint8_t)
326 AC_CHECK_SIZEOF(uint16_t)
327 AC_CHECK_SIZEOF(uint32_t)
328 AC_CHECK_SIZEOF(uint64_t)
329 AC_CHECK_SIZEOF(intptr_t)
330 AC_CHECK_SIZEOF(uintptr_t)
332 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
334 AC_CHECK_SIZEOF(char)
335 AC_CHECK_SIZEOF(short)
337 AC_CHECK_SIZEOF(long)
338 AC_CHECK_SIZEOF(long long)
339 AC_CHECK_SIZEOF(__int64)
340 AC_CHECK_SIZEOF(void *)
341 AC_CHECK_SIZEOF(time_t)
342 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
344 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }],
345 tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
348 if test $tor_cv_time_t_signed = yes; then
349 AC_DEFINE([TIME_T_IS_SIGNED], 1,
350 [Define to 1 iff time_t is signed])
353 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
354 #ifdef HAVE_SYS_SOCKET_H
355 #include <sys/socket.h>
359 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
361 AC_CHECK_SIZEOF(cell_t)
363 # Now, let's see about alignment requirements. On some platforms, we override
366 ia64-*-* | arm-*-* | sparc-*-* | sparc64-*-* )
367 tor_cv_unaligned_ok=no
369 # On the following architectures unaligned access works, but is not done in
370 # hardware. This means that when you try to do unaligned access the kernel
371 # gets to sort out an exception and then work around to somehow make your
372 # reqest work, which is quite expensive. Therefore it's probably better to
374 alpha-*-* | mips-*-* | mipsel-*-* )
375 tor_cv_unaligned_ok=no
378 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
379 [AC_RUN_IFELSE([AC_LANG_SOURCE(
380 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
381 return *(int*)(&s[1]); }]])],
382 [tor_cv_unaligned_ok=yes],
383 [tor_cv_unaligned_ok=no],
384 [tor_cv_unaligned_ok=cross])])
387 if test $tor_cv_unaligned_ok = yes; then
388 AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
389 [Define to 1 iff unaligned int access is allowed])
392 # Now make sure that NULL can be represented as zero bytes.
393 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
394 [AC_RUN_IFELSE([AC_LANG_SOURCE(
395 [[#include <stdlib.h>
401 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
402 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
403 [tor_cv_null_is_zero=yes],
404 [tor_cv_null_is_zero=no],
405 [tor_cv_null_is_zero=cross])])
407 if test $tor_cv_null_is_zero = yes; then
408 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
409 [Define to 1 iff memset(0) sets pointers to NULL])
412 # Whether we should use the dmalloc memory allocation debugging library.
413 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
415 [ --with-dmalloc Use debug memory allocation library. ],
416 [if [[ "$withval" = "yes" ]]; then
422 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
425 if [[ $dmalloc -eq 1 ]]; then
426 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
427 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
428 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
429 AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
432 # Allow user to specify an alternate syslog facility
433 AC_ARG_WITH(syslog-facility,
434 [ --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
435 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
436 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
437 AC_SUBST(LOGFACILITY)
439 # Check for gethostbyname_r in all its glorious incompatible versions.
440 # (This logic is based on that in Python's configure.in)
441 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
442 [Define this if you have any gethostbyname_r()])
444 AC_CHECK_FUNC(gethostbyname_r, [
445 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
447 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
452 struct hostent *h1, *h2;
454 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
456 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
457 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
458 [Define this if gethostbyname_r takes 6 arguments])
467 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
469 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
470 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
471 [Define this if gethostbyname_r takes 5 arguments])
479 struct hostent_data hd;
480 (void) gethostbyname_r(cp1,h1,&hd);
482 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
483 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
484 [Define this if gethostbyname_r takes 3 arguments])
494 # $prefix stores the value of the --prefix command line option, or
495 # NONE if the option wasn't set. In the case that it wasn't set, make
496 # it be the default, so that we can use it to expand directories now.
497 if test "x$prefix" = "xNONE"; then
498 prefix=$ac_default_prefix
501 # and similarly for $exec_prefix
502 if test "x$exec_prefix" = "xNONE"; then
506 CONFDIR=`eval echo $sysconfdir/tor`
508 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
509 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
511 BINDIR=`eval echo $bindir`
514 LOCALSTATEDIR=`eval echo $localstatedir`
515 AC_SUBST(LOCALSTATEDIR)
516 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
517 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
519 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
520 # than autoconf's macros like.
521 CFLAGS="$CFLAGS -Wall -g -O2"
522 # Add some more warnings which we use in the cvs version but not in the
523 # released versions. (Some relevant gcc versions can't handle these.)
524 #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"
525 # Add these in when you feel like fun.
526 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement -Wold-style-definition"
528 echo "confdir: $CONFDIR"
530 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)
532 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
533 ./contrib/updateVersions.pl