Add new sections to the HACKING file
[tor.git] / configure.in
blob91010ab725f9bf32cf98436c42433eda986f1599
1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2008, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.2.2.10-alpha-dev)
8 AM_CONFIG_HEADER(orconfig.h)
10 AC_CANONICAL_HOST
12 if test -f /etc/redhat-release ; then
13   if test -f /usr/kerberos/include ; then
14     CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
15   fi
18 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
19 # the += operator on it in src/or/Makefile.am
20 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
22 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
23 AC_ARG_ENABLE(buf-freelists,
24    AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
25 AC_ARG_ENABLE(openbsd-malloc,
26    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
27 AC_ARG_ENABLE(instrument-downloads,
28    AS_HELP_STRING(--enable-instrument-downloads, Instrument downloads of directory resources etc.))
29 AC_ARG_ENABLE(static-openssl,
30    AS_HELP_STRING(--enable-static-openssl, Link against a static openssl library. Requires --with-openssl-dir))
31 AC_ARG_ENABLE(static-libevent,
32    AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir))
33 AC_ARG_ENABLE(static-zlib,
34    AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir))
36 if test x$enable_buf_freelists != xno; then
37   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
38             [Defined if we try to use freelists for buffer RAM chunks])
40 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
41 if test x$enable_instrument_downloads = xyes; then
42   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
43             [Defined if we want to keep track of how much of each kind of resource we download.])
46 AC_ARG_ENABLE(transparent,
47      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
48      [case "${enableval}" in
49         yes) transparent=true ;;
50         no)  transparent=false ;;
51         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
52       esac], [transparent=true])
54 AC_ARG_ENABLE(asciidoc,
55      AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
56      [case "${enableval}" in
57         yes) asciidoc=true ;;
58         no)  asciidoc=false ;;
59         *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
60       esac], [asciidoc=true])
63 AC_ARG_ENABLE(threads,
64      AS_HELP_STRING(--disable-threads, disable multi-threading support))
66 if test x$enable_threads = x; then
67    case $host in
68     *-*-solaris* )
69      # Don't try multithreading on solaris -- cpuworkers seem to lock.
70      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
71 cpu workers lock up here, so I will disable threads.])
72      enable_threads="no";;
73     *)
74      enable_threads="yes";;
75    esac
78 if test "$enable_threads" = "yes"; then
79   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
82 case $host in
83    *-*-solaris* )
84      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
85      ;;
86 esac
88 AC_ARG_ENABLE(gcc-warnings,
89      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
90 AC_ARG_ENABLE(gcc-warnings-advisory,
91      AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
93 AC_ARG_ENABLE(local-appdata,
94    AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
95 if test "$enable_local_appdata" = "yes"; then
96   AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
97             [Defined if we default to host local appdata paths on Windows])
100 AC_PROG_CC
101 AC_PROG_CPP
102 AC_PROG_MAKE_SET
103 AC_PROG_RANLIB
105 dnl autoconf 2.59 appears not to support AC_PROG_SED
106 AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
108 dnl check for asciidoc and a2x
109 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
110 AC_PATH_PROG([A2X], [a2x], none)
112 AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
114 AC_PATH_PROG([SHA1SUM], [sha1sum], none)
115 AC_PATH_PROG([OPENSSL], [openssl], none)
117 TORUSER=_tor
118 AC_ARG_WITH(tor-user,
119         [  --with-tor-user=NAME    Specify username for tor daemon ],
120         [
121            TORUSER=$withval
122         ]
124 AC_SUBST(TORUSER)
126 TORGROUP=_tor
127 AC_ARG_WITH(tor-group,
128         [  --with-tor-group=NAME   Specify group name for tor daemon ],
129         [
130            TORGROUP=$withval
131         ]
133 AC_SUBST(TORGROUP)
136 dnl If WIN32 is defined and non-zero, we are building for win32
137 AC_MSG_CHECKING([for win32])
138 AC_RUN_IFELSE([
139 int main(int c, char **v) {
140 #ifdef WIN32
141 #if WIN32
142   return 0;
143 #else
144   return 1;
145 #endif
146 #else
147   return 2;
148 #endif
150 bwin32=true; AC_MSG_RESULT([yes]),
151 bwin32=false; AC_MSG_RESULT([no]),
152 bwin32=cross; AC_MSG_RESULT([cross])
155 if test "$bwin32" = cross; then
156 AC_MSG_CHECKING([for win32 (cross)])
157 AC_COMPILE_IFELSE([
158 #ifdef WIN32
159 int main(int c, char **v) {return 0;}
160 #else
161 #error
162 int main(int c, char **v) {return x(y);}
163 #endif
165 bwin32=true; AC_MSG_RESULT([yes]),
166 bwin32=false; AC_MSG_RESULT([no]))
169 if test "$bwin32" = true; then
170 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
172 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
174 dnl Enable C99 when compiling with MIPSpro
175 AC_MSG_CHECKING([for MIPSpro compiler])
176 AC_COMPILE_IFELSE(AC_LANG_PROGRAM(, [
177 #if (defined(__sgi) && defined(_COMPILER_VERSION))
178 #error
179   return x(y);
180 #endif
182 bmipspro=false; AC_MSG_RESULT(no),
183 bmipspro=true; AC_MSG_RESULT(yes))
185 if test "$bmipspro" = true; then
186   CFLAGS="$CFLAGS -c99"
189 AC_C_BIGENDIAN
191 AC_SEARCH_LIBS(socket, [socket])
192 AC_SEARCH_LIBS(gethostbyname, [nsl])
193 AC_SEARCH_LIBS(dlopen, [dl])
194 AC_SEARCH_LIBS(inet_aton, [resolv])
196 if test "$enable_threads" = "yes"; then
197   AC_SEARCH_LIBS(pthread_create, [pthread])
198   AC_SEARCH_LIBS(pthread_detach, [pthread])
201 dnl -------------------------------------------------------------------
202 dnl Check for functions before libevent, since libevent-1.2 apparently
203 dnl exports strlcpy without defining it in a header.
205 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull getaddrinfo localtime_r gmtime_r memmem strtok_r writev readv flock prctl vasprintf)
207 using_custom_malloc=no
208 if test x$enable_openbsd_malloc = xyes ; then
209    AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function])
210    using_custom_malloc=yes
212 if test x$tcmalloc = xyes ; then
213    using_custom_malloc=yes
215 if test $using_custom_malloc = no ; then
216    AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size)
219 if test "$enable_threads" = "yes"; then
220   AC_CHECK_HEADERS(pthread.h)
221   AC_CHECK_FUNCS(pthread_create)
224 dnl ------------------------------------------------------
225 dnl Where do you live, libevent?  And how do we call you?
227 if test "$bwin32" = true; then
228   TOR_LIB_WS32=-lws2_32
229   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
230   # think it's actually necessary.
231   TOR_LIB_GDI=-lgdi32
232 else
233   TOR_LIB_WS32=
234   TOR_LIB_GDI=
236 AC_SUBST(TOR_LIB_WS32)
237 AC_SUBST(TOR_LIB_GDI)
239 dnl We need to do this before we try our disgusting hack below.
240 AC_CHECK_HEADERS([sys/types.h])
242 dnl This is a disgusting hack so we safely include older libevent headers.
243 AC_CHECK_TYPE(u_int64_t, unsigned long long)
244 AC_CHECK_TYPE(u_int32_t, unsigned long)
245 AC_CHECK_TYPE(u_int16_t, unsigned short)
246 AC_CHECK_TYPE(u_int8_t, unsigned char)
248 tor_libevent_pkg_redhat="libevent"
249 tor_libevent_pkg_debian="libevent-dev"
250 tor_libevent_devpkg_redhat="libevent-devel"
251 tor_libevent_devpkg_debian="libevent-dev"
253 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $TOR_LIB_WS32], [
254 #ifdef WIN32
255 #include <winsock2.h>
256 #endif
257 #include <stdlib.h>
258 #include <sys/time.h>
259 #include <sys/types.h>
260 #include <event.h>], [
261 #ifdef WIN32
262 #include <winsock2.h>
263 #endif
264 void exit(int); void *event_init(void);],
265     [
266 #ifdef WIN32
267 {WSADATA d; WSAStartup(0x101,&d); }
268 #endif
269 event_init(); exit(0);
270 ], [--with-libevent-dir], [/opt/libevent])
272 dnl Now check for particular libevent functions.
273 save_LIBS="$LIBS"
274 save_LDFLAGS="$LDFLAGS"
275 save_CPPFLAGS="$CPPFLAGS"
276 LIBS="-levent $TOR_LIB_WS32 $LIBS"
277 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
278 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
279 AC_CHECK_FUNCS(event_get_version event_get_version_number event_get_method event_set_log_callback evdns_set_outgoing_bind_address event_base_loopexit)
280 AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
281 [#include <event.h>
284 AC_CHECK_HEADERS(event2/event.h event2/dns.h)
286 LIBS="$save_LIBS"
287 LDFLAGS="$save_LDFLAGS"
288 CPPFLAGS="$save_CPPFLAGS"
291 AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
293 if test "$enable_static_libevent" = "yes"; then
294    if test "$tor_cv_library_libevent_dir" = "(system)"; then
295      AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
296    else
297      TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a"
298    fi
299 else
300      TOR_LIBEVENT_LIBS="-levent"
302 AC_SUBST(TOR_LIBEVENT_LIBS)
305 dnl ------------------------------------------------------
306 dnl Where do you live, openssl?  And how do we call you?
308 tor_openssl_pkg_redhat="openssl"
309 tor_openssl_pkg_debian="libssl"
310 tor_openssl_devpkg_redhat="openssl-devel"
311 tor_openssl_devpkg_debian="libssl-dev"
313 ALT_openssl_WITHVAL=""
314 AC_ARG_WITH(ssl-dir,
315   [  --with-ssl-dir=PATH    Obsolete alias for --with-openssl-dir ],
316   [
317       if test "x$withval" != xno && test "x$withval" != "x" ; then
318          ALT_openssl_WITHVAL="$withval"
319       fi
320   ])
322 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
323     [#include <openssl/rand.h>],
324     [void RAND_add(const void *buf, int num, double entropy);],
325     [RAND_add((void*)0,0,0); exit(0);], [],
326     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
328 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
330 echo "tor_cv_library_openssl_dir is $tor_cv_library_openssl_dir"
331 if test "$enable_static_openssl" = "yes"; then
332    if test "$tor_cv_library_openssl_dir" = "(system)"; then
333      AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
334    else
335      TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
336    fi
337 else
338      TOR_OPENSSL_LIBS="-lssl -lcrypto"
340 AC_SUBST(TOR_OPENSSL_LIBS)
342 dnl ------------------------------------------------------
343 dnl Where do you live, zlib?  And how do we call you?
345 tor_openssl_pkg_redhat="zlib"
346 tor_openssl_pkg_debian="zlib1g"
347 tor_openssl_devpkg_redhat="zlib-devel"
348 tor_openssl_devpkg_debian="zlib1g-dev"
350 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
351     [#include <zlib.h>],
352     [const char * zlibVersion(void);],
353     [zlibVersion(); exit(0);], [--with-zlib-dir],
354     [/opt/zlib])
356 if test "$enable_static_zlib" = "yes"; then
357    if test "$tor_cv_library_zlib_dir" = "(system)"; then
358      AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
359  using --enable-static-zlib")
360    else
361      TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
362      echo "$TOR_LIBDIR_zlib/libz.a"
363    fi
364 else
365      TOR_ZLIB_LIBS="-lz"
367 AC_SUBST(TOR_ZLIB_LIBS)
369 dnl Make sure to enable support for large off_t if available.
371 AC_SYS_LARGEFILE
373 AC_CHECK_HEADERS(unistd.h string.h signal.h sys/stat.h sys/types.h fcntl.h sys/fcntl.h sys/time.h errno.h assert.h time.h, , AC_MSG_WARN(Some headers were not found, compilation may fail.  If compilation succeeds, please send your orconfig.h to the developers so we can fix this warning.))
375 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h sys/un.h sys/uio.h)
377 dnl These headers are not essential
379 AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netinet/in6.h malloc.h sys/syslimits.h malloc/malloc.h linux/types.h sys/file.h malloc_np.h sys/prctl.h)
381 TOR_CHECK_PROTOTYPE(malloc_good_size, HAVE_MALLOC_GOOD_SIZE_PROTOTYPE,
382 [#ifdef HAVE_MALLOC_H
383 #include <malloc.h>
384 #endif
385 #ifdef HAVE_MALLOC_MALLOC_H
386 #include <malloc/malloc.h>
387 #endif])
389 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
390 [#ifdef HAVE_SYS_TYPES_H
391 #include <sys/types.h>
392 #endif
393 #ifdef HAVE_SYS_SOCKET_H
394 #include <sys/socket.h>
395 #endif])
396 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
397 [#ifdef HAVE_SYS_TYPES_H
398 #include <sys/types.h>
399 #endif
400 #ifdef HAVE_SYS_SOCKET_H
401 #include <sys/socket.h>
402 #endif
403 #ifdef HAVE_NET_IF_H
404 #include <net/if.h>
405 #endif])
406 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
407         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
408 [#ifdef HAVE_SYS_TYPES_H
409 #include <sys/types.h>
410 #endif
411 #ifdef HAVE_SYS_SOCKET_H
412 #include <sys/socket.h>
413 #endif
414 #ifdef HAVE_LIMITS_H
415 #include <limits.h>
416 #endif
417 #ifdef HAVE_LINUX_TYPES_H
418 #include <linux/types.h>
419 #endif
420 #ifdef HAVE_NETINET_IN6_H
421 #include <netinet/in6.h>
422 #endif
423 #ifdef HAVE_NETINET_IN_H
424 #include <netinet/in.h>
425 #endif])
427 if test x$transparent = xtrue ; then
428    transparent_ok=0
429    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
430      transparent_ok=1
431    fi
432    if test x$linux_netfilter_ipv4 = x1 ; then
433      transparent_ok=1
434    fi
435    if test x$transparent_ok = x1 ; then
436      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
437      case $host in
438        *-*-openbsd*)
439          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
440      esac
441    else
442      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
443    fi
446 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
447 [#ifdef HAVE_SYS_TYPES_H
448 #include <sys/types.h>
449 #endif
450 #ifdef HAVE_SYS_TIME_H
451 #include <sys/time.h>
452 #endif])
454 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
455 dnl Watch out.
457 AC_CHECK_SIZEOF(int8_t)
458 AC_CHECK_SIZEOF(int16_t)
459 AC_CHECK_SIZEOF(int32_t)
460 AC_CHECK_SIZEOF(int64_t)
461 AC_CHECK_SIZEOF(uint8_t)
462 AC_CHECK_SIZEOF(uint16_t)
463 AC_CHECK_SIZEOF(uint32_t)
464 AC_CHECK_SIZEOF(uint64_t)
465 AC_CHECK_SIZEOF(intptr_t)
466 AC_CHECK_SIZEOF(uintptr_t)
468 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
470 AC_CHECK_SIZEOF(char)
471 AC_CHECK_SIZEOF(short)
472 AC_CHECK_SIZEOF(int)
473 AC_CHECK_SIZEOF(long)
474 AC_CHECK_SIZEOF(long long)
475 AC_CHECK_SIZEOF(__int64)
476 AC_CHECK_SIZEOF(void *)
477 AC_CHECK_SIZEOF(time_t)
478 AC_CHECK_SIZEOF(size_t)
480 AC_CHECK_TYPES([uint, u_char, ssize_t])
482 dnl used to include sockaddr_storage, but everybody has that.
483 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
484 [#ifdef HAVE_SYS_TYPES_H
485 #include <sys/types.h>
486 #endif
487 #ifdef HAVE_NETINET_IN_H
488 #include <netinet/in.h>
489 #endif
490 #ifdef HAVE_NETINET_IN6_H
491 #include <netinet/in6.h>
492 #endif
493 #ifdef HAVE_SYS_SOCKET_H
494 #include <sys/socket.h>
495 #endif
496 #ifdef MS_WINDOWS
497 #define WIN32_WINNT 0x400
498 #define _WIN32_WINNT 0x400
499 #define WIN32_LEAN_AND_MEAN
500 #if defined(_MSC_VER) && (_MSC_VER < 1300)
501 #include <winsock.h>
502 #else
503 #include <winsock2.h>
504 #include <ws2tcpip.h>
505 #endif
506 #endif
508 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
509 [#ifdef HAVE_SYS_TYPES_H
510 #include <sys/types.h>
511 #endif
512 #ifdef HAVE_NETINET_IN_H
513 #include <netinet/in.h>
514 #endif
515 #ifdef HAVE_NETINET_IN6_H
516 #include <netinet/in6.h>
517 #endif
518 #ifdef HAVE_SYS_SOCKET_H
519 #include <sys/socket.h>
520 #endif
521 #ifdef MS_WINDOWS
522 #define WIN32_WINNT 0x400
523 #define _WIN32_WINNT 0x400
524 #define WIN32_LEAN_AND_MEAN
525 #if defined(_MSC_VER) && (_MSC_VER < 1300)
526 #include <winsock.h>
527 #else
528 #include <winsock2.h>
529 #include <ws2tcpip.h>
530 #endif
531 #endif
534 AC_CHECK_TYPES([rlim_t], , ,
535 [#ifdef HAVE_SYS_TYPES_H
536 #include <sys/types.h>
537 #endif
538 #ifdef HAVE_SYS_TIME_H
539 #include <sys/time.h>
540 #endif
541 #ifdef HAVE_SYS_RESOURCE_H
542 #include <sys/resource.h>
543 #endif
546 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
547 AC_RUN_IFELSE(AC_LANG_SOURCE([
548 #ifdef HAVE_SYS_TYPES_H
549 #include <sys/types.h>
550 #endif
551 #ifdef HAVE_SYS_TIME_H
552 #include <sys/time.h>
553 #endif
554 #ifdef HAVE_TIME_H
555 #include <time.h>
556 #endif
557 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }]),
558   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
561 if test "$tor_cv_time_t_signed" = cross; then
562   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
565 if test "$tor_cv_time_t_signed" != no; then
566   AC_DEFINE([TIME_T_IS_SIGNED], 1,
567             [Define to 1 iff time_t is signed])
570 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
571 #ifdef HAVE_SYS_SOCKET_H
572 #include <sys/socket.h>
573 #endif
576 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
578 AC_CHECK_SIZEOF(cell_t)
580 # Now make sure that NULL can be represented as zero bytes.
581 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
582 [AC_RUN_IFELSE([AC_LANG_SOURCE(
583 [[#include <stdlib.h>
584 #include <string.h>
585 #include <stdio.h>
586 #ifdef HAVE_STDDEF_H
587 #include <stddef.h>
588 #endif
589 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
590 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
591        [tor_cv_null_is_zero=yes],
592        [tor_cv_null_is_zero=no],
593        [tor_cv_null_is_zero=cross])])
595 if test "$tor_cv_null_is_zero" = cross ; then
596   # Cross-compiling; let's hope that the target isn't raving mad.
597   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
600 if test "$tor_cv_null_is_zero" != no; then
601   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
602             [Define to 1 iff memset(0) sets pointers to NULL])
605 # And what happens when we malloc zero?
606 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
607 [AC_RUN_IFELSE([AC_LANG_SOURCE(
608 [[#include <stdlib.h>
609 #include <string.h>
610 #include <stdio.h>
611 #ifdef HAVE_STDDEF_H
612 #include <stddef.h>
613 #endif
614 int main () { return malloc(0)?0:1; }]])],
615        [tor_cv_malloc_zero_works=yes],
616        [tor_cv_malloc_zero_works=no],
617        [tor_cv_malloc_zero_works=cross])])
619 if test "$tor_cv_malloc_zero_works" = cross; then
620   # Cross-compiling; let's hope that the target isn't raving mad.
621   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
624 if test "$tor_cv_malloc_zero_works" = yes; then
625   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
626             [Define to 1 iff malloc(0) returns a pointer])
629 # whether we seem to be in a 2s-complement world.
630 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
631 [AC_RUN_IFELSE([AC_LANG_SOURCE(
632 [[int main () { int problem = ((-99) != (~99)+1);
633 return problem ? 1 : 0; }]])],
634        [tor_cv_twos_complement=yes],
635        [tor_cv_twos_complement=no],
636        [tor_cv_twos_complement=cross])])
638 if test "$tor_cv_twos_complement" = cross ; then
639   # Cross-compiling; let's hope that the target isn't raving mad.
640   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
643 if test "$tor_cv_twos_complement" != no ; then
644   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
645             [Define to 1 iff we represent negative integers with two's complement])
648 # Whether we should use the dmalloc memory allocation debugging library.
649 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
650 AC_ARG_WITH(dmalloc,
651 [  --with-dmalloc          Use debug memory allocation library. ],
652 [if [[ "$withval" = "yes" ]]; then
653   dmalloc=1
654   AC_MSG_RESULT(yes)
655 else
656   dmalloc=1
657   AC_MSG_RESULT(no)
658 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
661 if [[ $dmalloc -eq 1 ]]; then
662   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
663   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
664   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
665   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
666   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
669 AC_ARG_WITH(tcmalloc,
670 [  --with-tcmalloc         Use tcmalloc memory allocation library. ],
671 [ tcmalloc=yes ], [ tcmalloc=no ])
673 if test x$tcmalloc = xyes ; then
674    LDFLAGS="-ltcmalloc $LDFLAGS"
677 # By default, we're going to assume we don't have mlockall()
678 # bionic and other platforms have various broken mlockall subsystems.
679 # Some systems don't have a working mlockall, some aren't linkable,
680 # and some have it but don't declare it.
681 AC_CHECK_FUNCS(mlockall)
682 AC_CHECK_DECLS([mlockall], , , [
683 #ifdef HAVE_SYS_MMAN_H
684 #include <sys/mman.h>
685 #endif])
687 # Allow user to specify an alternate syslog facility
688 AC_ARG_WITH(syslog-facility,
689 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
690 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
691 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
692 AC_SUBST(LOGFACILITY)
694 # Check if we have getresuid and getresgid
695 AC_CHECK_FUNCS(getresuid getresgid)
697 # Check for gethostbyname_r in all its glorious incompatible versions.
698 #   (This logic is based on that in Python's configure.in)
699 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
700   [Define this if you have any gethostbyname_r()])
702 AC_CHECK_FUNC(gethostbyname_r, [
703   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
704   OLD_CFLAGS=$CFLAGS
705   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
706   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
707 #include <netdb.h>
708   ], [[
709     char *cp1, *cp2;
710     struct hostent *h1, *h2;
711     int i1, i2;
712     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
713   ]]),[
714     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
715     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
716      [Define this if gethostbyname_r takes 6 arguments])
717     AC_MSG_RESULT(6)
718   ], [
719     AC_TRY_COMPILE([
720 #include <netdb.h>
721     ], [
722       char *cp1, *cp2;
723       struct hostent *h1;
724       int i1, i2;
725       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
726     ], [
727       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
728       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
729         [Define this if gethostbyname_r takes 5 arguments])
730       AC_MSG_RESULT(5)
731    ], [
732       AC_TRY_COMPILE([
733 #include <netdb.h>
734      ], [
735        char *cp1;
736        struct hostent *h1;
737        struct hostent_data hd;
738        (void) gethostbyname_r(cp1,h1,&hd);
739      ], [
740        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
741        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
742          [Define this if gethostbyname_r takes 3 arguments])
743        AC_MSG_RESULT(3)
744      ], [
745        AC_MSG_RESULT(0)
746      ])
747   ])
748  ])
749  CFLAGS=$OLD_CFLAGS
752 AC_CACHE_CHECK([whether the C compiler supports __func__],
753   tor_cv_have_func_macro,
754   AC_COMPILE_IFELSE([
755 #include <stdio.h>
756 int main(int c, char **v) { puts(__func__); }],
757   tor_cv_have_func_macro=yes,
758   tor_cv_have_func_macro=no))
760 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
761   tor_cv_have_FUNC_macro,
762   AC_COMPILE_IFELSE([
763 #include <stdio.h>
764 int main(int c, char **v) { puts(__FUNC__); }],
765   tor_cv_have_FUNC_macro=yes,
766   tor_cv_have_FUNC_macro=no))
768 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
769   tor_cv_have_FUNCTION_macro,
770   AC_COMPILE_IFELSE([
771 #include <stdio.h>
772 int main(int c, char **v) { puts(__FUNCTION__); }],
773   tor_cv_have_FUNCTION_macro=yes,
774   tor_cv_have_FUNCTION_macro=no))
776 if test "$tor_cv_have_func_macro" = 'yes'; then
777   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
780 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
781   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
784 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
785   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
786            [Defined if the compiler supports __FUNCTION__])
789 # $prefix stores the value of the --prefix command line option, or
790 # NONE if the option wasn't set.  In the case that it wasn't set, make
791 # it be the default, so that we can use it to expand directories now.
792 if test "x$prefix" = "xNONE"; then
793   prefix=$ac_default_prefix
796 # and similarly for $exec_prefix
797 if test "x$exec_prefix" = "xNONE"; then
798   exec_prefix=$prefix
801 if test "x$CONFDIR" = "x"; then
802   CONFDIR=`eval echo $sysconfdir/tor`
804 AC_SUBST(CONFDIR)
805 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
806 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
808 BINDIR=`eval echo $bindir`
809 AC_SUBST(BINDIR)
810 LOCALSTATEDIR=`eval echo $localstatedir`
811 AC_SUBST(LOCALSTATEDIR)
813 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
814 # than autoconf's macros like.
815 if test "$GCC" = yes; then
816   CFLAGS="$CFLAGS -Wall -g -O2"
817   # Disable GCC's strict aliasing checks.  They are an hours-to-debug
818   # accident waiting to happen.
819   CFLAGS="$CFLAGS -fno-strict-aliasing"
820 else
821   CFLAGS="$CFLAGS -g -O"
822   enable_gcc_warnings=no
823   enable_gcc_warnings_advisory=no
826 # Add some more warnings which we use in development but not in the
827 # released versions.  (Some relevant gcc versions can't handle these.)
828 if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
830   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
831 #if !defined(__GNUC__) || (__GNUC__ < 4)
832 #error
833 #endif]), have_gcc4=yes, have_gcc4=no)
835   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
836 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
837 #error
838 #endif]), have_gcc42=yes, have_gcc42=no)
840   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
841 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
842 #error
843 #endif]), have_gcc43=yes, have_gcc43=no)
845   save_CFLAGS="$CFLAGS"
846   CFLAGS="$CFLAGS -Wshorten-64-to-32"
847   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], []), have_shorten64_flag=yes,
848                     have_shorten64_flag=no)
849   CFLAGS="$save_CFLAGS"
851   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum"
852   if test x$enable_gcc_warnings = xyes; then
853     CFLAGS="$CFLAGS -Werror"
854   fi
856   # Disabled, so we can use mallinfo(): -Waggregate-return
858   if test x$have_gcc4 = xyes ; then 
859     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
860     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
861   fi
863   if test x$have_gcc42 = xyes ; then 
864     # These warnings break gcc 4.0.2 and work on gcc 4.2
865     # XXXX020 Use -fstack-protector.
866     # XXXX020 See if any of these work with earlier versions.
867     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=1"
868     # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
869   fi
871   if test x$have_gcc43 = xyes ; then 
872     # These warnings break gcc 4.2 and work on gcc 4.3
873     # XXXX020 See if any of these work with earlier versions.
874     CFLAGS="$CFLAGS -Wextra -Warray-bounds"
875   fi
877   if test x$have_shorten64_flag = xyes ; then
878     CFLAGS="$CFLAGS -Wshorten-64-to-32"
879   fi
881 ##This will break the world on some 64-bit architectures
882 # CFLAGS="$CFLAGS -Winline"
887 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
889 AC_CONFIG_FILES([Makefile tor.spec Doxyfile 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 src/Makefile doc/Makefile doc/spec/Makefile src/config/Makefile src/common/Makefile src/or/Makefile src/test/Makefile src/win32/Makefile src/tools/Makefile contrib/suse/Makefile contrib/suse/tor.sh])
890 AC_OUTPUT
892 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
893   ./contrib/updateVersions.pl