Another snapshot so we get a newer announced version number
[tor.git] / configure.in
blobe138c6711a3f744b8387a418b0e49d989785f983
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.3-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 [  --enable-debug          compiles with debugging info],
18 [if test x$enableval = xyes; then
19     CFLAGS="$CFLAGS -g"
20 fi])
22 AC_PROG_CC
23 AC_PROG_MAKE_SET
24 AC_PROG_RANLIB
26 # The big search for OpenSSL
27 # copied from openssh's configure.ac
28 AC_ARG_WITH(ssl-dir,
29         [  --with-ssl-dir=PATH     Specify path to OpenSSL installation ],
30         [
31                 if test "x$withval" != "xno" ; then
32                         tryssldir=$withval
33                 fi
34         ]
37 AC_SEARCH_LIBS(socket, [socket])
38 AC_SEARCH_LIBS(gethostbyname, [nsl])
39 AC_SEARCH_LIBS(pthread_create, [pthread])
40 AC_SEARCH_LIBS(pthread_detach, [pthread])
41 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/ ))
43 saved_LIBS="$LIBS"
44 saved_LDFLAGS="$LDFLAGS"
45 saved_CPPFLAGS="$CPPFLAGS"
46 if test "x$prefix" != "xNONE" ; then
47         tryssldir="$tryssldir $prefix"
49 AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
50         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
51                 CPPFLAGS="$saved_CPPFLAGS"
52                 LDFLAGS="$saved_LDFLAGS"
53                 LIBS="$saved_LIBS -lssl -lcrypto"
55                 # Skip directories if they don't exist
56                 if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
57                         continue;
58                 fi
59                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
60                         # Try to use $ssldir/lib if it exists, otherwise
61                         # $ssldir
62                         if test -d "$ssldir/lib" ; then
63                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
64                                 if test ! -z "$need_dash_r" ; then
65                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
66                                 fi
67                         else
68                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
69                                 if test ! -z "$need_dash_r" ; then
70                                         LDFLAGS="-R$ssldir $LDFLAGS"
71                                 fi
72                         fi
73                         # Try to use $ssldir/include if it exists, otherwise
74                         # $ssldir
75                         if test -d "$ssldir/include" ; then
76                                 CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
77                         else
78                                 CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
79                         fi
80                 fi
82                 # Basic test to check for compatible version and correct linking
83                 # *does not* test for RSA - that comes later.
84                 AC_TRY_RUN(
85                         [
86 #include <string.h>
87 #include <openssl/rand.h>
88 int main(void)
90         char a[2048];
91         memset(a, 0, sizeof(a));
92         RAND_add(a, sizeof(a), sizeof(a));
93         return(RAND_status() <= 0);
95                         ],
96                         [
97                                 found_crypto=1
98                                 break;
99                         ], []
100                 )
102                 if test ! -z "$found_crypto" ; then
103                         break;
104                 fi
105         done
107         if test -z "$found_crypto" ; then
108                 AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
109         fi
110         if test -z "$ssldir" ; then
111                 ssldir="(system)"
112         fi
114         ac_cv_openssldir=$ssldir
116 if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
117  then
118         dnl Need to recover ssldir - test above runs in subshell
119         ssldir=$ac_cv_openssldir
120         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
121                 # Try to use $ssldir/lib if it exists, otherwise
122                 # $ssldir
123                 if test -d "$ssldir/lib" ; then
124                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
125                         if test ! -z "$need_dash_r" ; then
126                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
127                         fi
128                 else
129                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
130                         if test ! -z "$need_dash_r" ; then
131                                 LDFLAGS="-R$ssldir $LDFLAGS"
132                         fi
133                 fi
134                 # Try to use $ssldir/include if it exists, otherwise
135                 # $ssldir
136                 if test -d "$ssldir/include" ; then
137                         CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
138                 else
139                         CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
140                 fi
141         fi
143 LIBS="$saved_LIBS"
145 AC_SYS_LARGEFILE
147 dnl The warning message here is no longer strictly accurate.
149 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))
151 AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
153 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.))
155 dnl These headers are not essential
157 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)
159 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)
160 AC_FUNC_FSEEKO
162 AC_CHECK_MEMBERS([struct timeval.tv_sec])
165 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
166 dnl Watch out.
168 AC_CHECK_SIZEOF(int8_t)
169 AC_CHECK_SIZEOF(int16_t)
170 AC_CHECK_SIZEOF(int32_t)
171 AC_CHECK_SIZEOF(int64_t)
172 AC_CHECK_SIZEOF(uint8_t)
173 AC_CHECK_SIZEOF(uint16_t)
174 AC_CHECK_SIZEOF(uint32_t)
175 AC_CHECK_SIZEOF(uint64_t)
176 AC_CHECK_SIZEOF(intptr_t)
177 AC_CHECK_SIZEOF(uintptr_t)
179 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
181 AC_CHECK_SIZEOF(char)
182 AC_CHECK_SIZEOF(short)
183 AC_CHECK_SIZEOF(int)
184 AC_CHECK_SIZEOF(long)
185 AC_CHECK_SIZEOF(long long)
186 AC_CHECK_SIZEOF(__int64)
187 AC_CHECK_SIZEOF(void *)
188 AC_CHECK_SIZEOF(time_t)
190 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
192 AC_CHECK_SIZEOF(cell_t)
194 # Now, let's see about alignment requirements.  On some platforms, we override
195 # the default.
196 case $host in
197  ia64-*-* | arm-*-* )
198     tor_cv_unaligned_ok=no
199     ;;
200  *)
201 AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
202 [AC_RUN_IFELSE([AC_LANG_SOURCE(
203 [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
204 return *(int*)(&s[1]); }]])],
205        [tor_cv_unaligned_ok=yes],
206        [tor_cv_unaligned_ok=no],
207        [tor_cv_unaligned_ok=cross])])
208 esac
210 if test $tor_cv_unaligned_ok = yes; then
211   AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
212             [Define to 1 iff unaligned int access is allowed])
215 # Now make sure that NULL can be represented as zero bytes.
216 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
217 [AC_RUN_IFELSE([AC_LANG_SOURCE(
218 [[#include <stdlib.h>
219 #include <string.h>
220 #include <stdio.h>
221 #ifdef HAVE_STDDEF_H
222 #include <stddef.h>
223 #endif
224 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
225 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
226        [tor_cv_null_is_zero=yes],
227        [tor_cv_null_is_zero=no],
228        [tor_cv_null_is_zero=cross])])
230 if test $tor_cv_null_is_zero = yes; then
231   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
232             [Define to 1 iff memset(0) sets pointers to NULL])
235 # Whether we should use the dmalloc memory allocation debugging library.
236 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
237 AC_ARG_WITH(dmalloc,
238 [  --with-dmalloc          Use debug memory allocation library. ],
239 [if [[ "$withval" = "yes" ]]; then
240   dmalloc=1
241   AC_MSG_RESULT(yes)
242 else
243   dmalloc=1
244   AC_MSG_RESULT(no)
245 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
248 if [[ $dmalloc -eq 1 ]]; then
249   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
250   AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
251   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
252   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
255 # Check for gethostbyname_r in all its glorious incompatible versions.
256 #   (This logic is based on that in Python's configure.in)
257 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
258   [Define this if you have any gethostbyname_r()])
260 AC_CHECK_FUNC(gethostbyname_r, [
261   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
262   OLD_CFLAGS=$CFLAGS
263   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
264   AC_TRY_COMPILE([
265 #include <netdb.h>
266   ], [
267     char *cp1, *cp2;
268     struct hostent *h1, *h2;
269     int i1, i2;
270     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
271   ], [
272     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
273     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
274      [Define this if gethostbyname_r takes 6 arguments])
275     AC_MSG_RESULT(6)
276   ], [
277     AC_TRY_COMPILE([
278 #include <netdb.h>
279     ], [
280       char *cp1, *cp2;
281       struct hostent *h1;
282       int i1, i2;
283       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
284     ], [
285       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
286       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
287         [Define this if gethostbyname_r takes 5 arguments])
288       AC_MSG_RESULT(5)
289    ], [
290       AC_TRY_COMPILE([
291 #include <netdb.h>
292      ], [
293        char *cp1;
294        struct hostent *h1;
295        struct hostent_data hd;
296        (void) gethostbyname_r(cp1,h1,&hd);
297      ], [
298        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
299        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
300          [Define this if gethostbyname_r takes 3 arguments])
301        AC_MSG_RESULT(3)
302      ], [
303        AC_MSG_RESULT(0)
304      ])
305   ])
306  ])
307  CFLAGS=$OLD_CFLAGS
310 # $prefix stores the value of the --prefix command line option, or
311 # NONE if the option wasn't set.  In the case that it wasn't set, make
312 # it be the default, so that we can use it to expand directories now.
313 if test "x$prefix" = "xNONE"; then
314   prefix=$ac_default_prefix
317 # and similarly for $exec_prefix
318 if test "x$exec_prefix" = "xNONE"; then
319   exec_prefix=$prefix
322 CONFDIR=`eval echo $sysconfdir/tor`
323 AC_SUBST(CONFDIR)
324 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
325 AC_DEFINE([CONFDIR], [], [tor's configuration directory])
327 BINDIR=`eval echo $bindir`
328 AC_SUBST(BINDIR)
330 LOCALSTATEDIR=`eval echo $localstatedir`
331 AC_SUBST(LOCALSTATEDIR)
333 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
334 # than autoconf's macros like.
335 CFLAGS="$CFLAGS -Wall -g -O2"
336 # Add some more warnings which we use in the cvs version but not in the
337 # released versions.  (Some relevant gcc versions can't handle these.)
338 #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
339 # Add these in when you feel like fun.
340 #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
342 echo "confdir: $CONFDIR"
344 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)
346 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
347   ./contrib/updateVersions.pl