grammar fix thanks to chris
[tor.git] / configure.in
blobe95cabbb0dda80bcdc22739b5dcb13a55ca72f09
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.5-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*)
28      # Don't try multithreading on netbsd -- there is no threadsafe DNS
29      # lookup function there.
30      enable_threads="no";;
31     *)
32      enable_threads="yes";;
33    esac
36 if test $enable_threads = "yes"; then
37   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
40 AC_PROG_CC
41 AC_PROG_MAKE_SET
42 AC_PROG_RANLIB
44 # The big search for OpenSSL
45 # copied from openssh's configure.ac
46 AC_ARG_WITH(ssl-dir,
47         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
48         [
49                 if test "x$withval" != "xno" ; then
50                         tryssldir=$withval
51                 fi
52         ]
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])
59 AC_SEARCH_LIBS(event_loop, [event], , AC_MSG_ERROR(Libevent library not found. Tor requires libevent to build.  You can get the latest version of libevent at http://www.monkey.org/~provos/libevent/ ))
61 saved_LIBS="$LIBS"
62 saved_LDFLAGS="$LDFLAGS"
63 saved_CPPFLAGS="$CPPFLAGS"
64 if test "x$prefix" != "xNONE" ; then
65         tryssldir="$tryssldir $prefix"
67 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
68         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
69                 CPPFLAGS="$saved_CPPFLAGS"
70                 LDFLAGS="$saved_LDFLAGS"
71                 LIBS="$saved_LIBS -lssl -lcrypto"
73                 # Skip directories if they don't exist
74                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
75                         continue;
76                 fi
77                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
78                         # Try to use $ssldir/lib if it exists, otherwise
79                         # $ssldir
80                         if test -d "$ssldir/lib" ; then
81                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
82                                 if test ! -z "$need_dash_r" ; then
83                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
84                                 fi
85                         else
86                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
87                                 if test ! -z "$need_dash_r" ; then
88                                         LDFLAGS="-R$ssldir $LDFLAGS"
89                                 fi
90                         fi
91                         # Try to use $ssldir/include if it exists, otherwise
92                         # $ssldir
93                         if test -d "$ssldir/include" ; then
94                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
95                         else
96                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
97                         fi
98                 fi
100                 # Basic test to check for compatible version and correct linking
101                 # *does not* test for RSA - that comes later.
102                 AC_TRY_RUN(
103                         [
104 #include <string.h>
105 #include <openssl/rand.h>
106 int main(void)
108         char a[2048];
109         memset(a, 0, sizeof(a));
110         RAND_add(a, sizeof(a), sizeof(a));
111         return(RAND_status() <= 0);
113                         ],
114                         [
115                                 found_crypto=1
116                                 break;
117                         ], []
118                 )
120                 if test ! -z "$found_crypto" ; then
121                         break;
122                 fi
123         done
125         if test -z "$found_crypto" ; then
126                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
127         fi
128         if test -z "$ssldir" ; then
129                 ssldir="(system)"
130         fi
132         ac_cv_openssldir=$ssldir
134 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
135  then
136         dnl Need to recover ssldir - test above runs in subshell
137         ssldir=$ac_cv_openssldir
138         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
139                 # Try to use $ssldir/lib if it exists, otherwise
140                 # $ssldir
141                 if test -d "$ssldir/lib" ; then
142                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
143                         if test ! -z "$need_dash_r" ; then
144                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
145                         fi
146                 else
147                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
148                         if test ! -z "$need_dash_r" ; then
149                                 LDFLAGS="-R$ssldir $LDFLAGS"
150                         fi
151                 fi
152                 # Try to use $ssldir/include if it exists, otherwise
153                 # $ssldir
154                 if test -d "$ssldir/include" ; then
155                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
156                 else
157                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
158                 fi
159         fi
161 LIBS="$saved_LIBS"
163 AC_SYS_LARGEFILE
165 dnl The warning message here is no longer strictly accurate.
167 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))
169 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
171 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.))
173 dnl These headers are not essential
175 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)
177 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)
178 AC_FUNC_FSEEKO
180 AC_CHECK_MEMBERS([struct timeval.tv_sec])
183 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
184 dnl Watch out.
186 AC_CHECK_SIZEOF(int8_t)
187 AC_CHECK_SIZEOF(int16_t)
188 AC_CHECK_SIZEOF(int32_t)
189 AC_CHECK_SIZEOF(int64_t)
190 AC_CHECK_SIZEOF(uint8_t)
191 AC_CHECK_SIZEOF(uint16_t)
192 AC_CHECK_SIZEOF(uint32_t)
193 AC_CHECK_SIZEOF(uint64_t)
194 AC_CHECK_SIZEOF(intptr_t)
195 AC_CHECK_SIZEOF(uintptr_t)
197 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
199 AC_CHECK_SIZEOF(char)
200 AC_CHECK_SIZEOF(short)
201 AC_CHECK_SIZEOF(int)
202 AC_CHECK_SIZEOF(long)
203 AC_CHECK_SIZEOF(long long)
204 AC_CHECK_SIZEOF(__int64)
205 AC_CHECK_SIZEOF(void *)
206 AC_CHECK_SIZEOF(time_t)
207 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
208 #ifdef HAVE_SYS_SOCKET_H
209 #include <sys/socket.h>
210 #endif
213 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
215 AC_CHECK_SIZEOF(cell_t)
217 # Now, let's see about alignment requirements.  On some platforms, we override
218 # the default.
219 case $host in
220  ia64-*-* | arm-*-* )
221     tor_cv_unaligned_ok=no
222     ;;
223  *)
224 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
225 [AC_RUN_IFELSE([AC_LANG_SOURCE(
226 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
227 return *(int*)(&s[1]); }]])],
228        [tor_cv_unaligned_ok=yes],
229        [tor_cv_unaligned_ok=no],
230        [tor_cv_unaligned_ok=cross])])
231 esac
233 if test $tor_cv_unaligned_ok = yes; then
234   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
235             [Define to 1 iff unaligned int access is allowed])
238 # Now make sure that NULL can be represented as zero bytes.
239 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
240 [AC_RUN_IFELSE([AC_LANG_SOURCE(
241 [[#include <stdlib.h>
242 #include <string.h>
243 #include <stdio.h>
244 #ifdef HAVE_STDDEF_H
245 #include <stddef.h>
246 #endif
247 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
248 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
249        [tor_cv_null_is_zero=yes],
250        [tor_cv_null_is_zero=no],
251        [tor_cv_null_is_zero=cross])])
253 if test $tor_cv_null_is_zero = yes; then
254   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
255             [Define to 1 iff memset(0) sets pointers to NULL])
258 # Whether we should use the dmalloc memory allocation debugging library.
259 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
260 AC_ARG_WITH(dmalloc,
261 [  --with-dmalloc          Use debug memory allocation library. ],
262 [if [[ "$withval" = "yes" ]]; then
263   dmalloc=1
264   AC_MSG_RESULT(yes)
265 else
266   dmalloc=1
267   AC_MSG_RESULT(no)
268 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
271 if [[ $dmalloc -eq 1 ]]; then
272   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
273   AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
274   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
275   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
278 # Check for gethostbyname_r in all its glorious incompatible versions.
279 #   (This logic is based on that in Python's configure.in)
280 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
281   [Define this if you have any gethostbyname_r()])
283 AC_CHECK_FUNC(gethostbyname_r, [
284   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
285   OLD_CFLAGS=$CFLAGS
286   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
287   AC_TRY_COMPILE([
288 #include <netdb.h>
289   ], [
290     char *cp1, *cp2;
291     struct hostent *h1, *h2;
292     int i1, i2;
293     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
294   ], [
295     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
296     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
297      [Define this if gethostbyname_r takes 6 arguments])
298     AC_MSG_RESULT(6)
299   ], [
300     AC_TRY_COMPILE([
301 #include <netdb.h>
302     ], [
303       char *cp1, *cp2;
304       struct hostent *h1;
305       int i1, i2;
306       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
307     ], [
308       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
309       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
310         [Define this if gethostbyname_r takes 5 arguments])
311       AC_MSG_RESULT(5)
312    ], [
313       AC_TRY_COMPILE([
314 #include <netdb.h>
315      ], [
316        char *cp1;
317        struct hostent *h1;
318        struct hostent_data hd;
319        (void) gethostbyname_r(cp1,h1,&hd);
320      ], [
321        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
322        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
323          [Define this if gethostbyname_r takes 3 arguments])
324        AC_MSG_RESULT(3)
325      ], [
326        AC_MSG_RESULT(0)
327      ])
328   ])
329  ])
330  CFLAGS=$OLD_CFLAGS
333 # $prefix stores the value of the --prefix command line option, or
334 # NONE if the option wasn't set.  In the case that it wasn't set, make
335 # it be the default, so that we can use it to expand directories now.
336 if test "x$prefix" = "xNONE"; then
337   prefix=$ac_default_prefix
340 # and similarly for $exec_prefix
341 if test "x$exec_prefix" = "xNONE"; then
342   exec_prefix=$prefix
345 CONFDIR=`eval echo $sysconfdir/tor`
346 AC_SUBST(CONFDIR)
347 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
348 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
350 BINDIR=`eval echo $bindir`
351 AC_SUBST(BINDIR)
353 LOCALSTATEDIR=`eval echo $localstatedir`
354 AC_SUBST(LOCALSTATEDIR)
355 AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
356 AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
358 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
359 # than autoconf's macros like.
360 CFLAGS="$CFLAGS -Wall -g -O2"
361 # Add some more warnings which we use in the cvs version but not in the
362 # released versions.  (Some relevant gcc versions can't handle these.)
363 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
364 # Add these in when you feel like fun.
365 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
367 echo "confdir: $CONFDIR"
369 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)
371 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
372   ./contrib/updateVersions.pl