If we receive a general-purpose descriptor and then receive an
[tor.git] / configure.in
blobf6bdcdaffcd667d51edddf4ed792def468bcdc5b
1 dnl $Id$
2 dnl Copyright (c) 2001-2004, Roger Dingledine
3 dnl Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
4 dnl See LICENSE for licensing information
6 AC_INIT
7 AM_INIT_AUTOMAKE(tor, 0.2.0.13-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../common"
22 AC_ARG_ENABLE(debug,
23  AS_HELP_STRING(--enable-debug, compile with debugging info),
24 [if test x$enableval = xyes; then
25     CFLAGS="$CFLAGS -g"
26 fi])
28 AC_ARG_ENABLE(cell-pool,
29      AS_HELP_STRING(--disable-cell-pool, disable pool allocator for cells))
31 if test x$enable_cell_pool != xno; then
32   AC_DEFINE(ENABLE_CELL_POOL, 1,
33             [Defined if we try to use the pool allocator for queued cells])
36 AC_ARG_ENABLE(transparent,
37      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
38      [case "${enableval}" in
39         yes) transparent=true ;;
40         no)  transparent=false ;;
41         *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
42       esac], [transparent=true])
44 AC_ARG_ENABLE(threads,
45      AS_HELP_STRING(--disable-threads, disable multi-threading support))
47 if test x$enable_threads = x; then
48    case $host in
49     *-*-solaris* )
50      # Don't try multithreading on solaris -- cpuworkers seem to lock.
51      AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
52 cpu workers lock up here, so I will disable threads.])
53      enable_threads="no";;
54     *)
55      enable_threads="yes";;
56    esac
59 if test "$enable_threads" = "yes"; then
60   AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
63 case $host in
64    *-*-solaris* )
65      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
66      ;;
67 esac
69 AC_ARG_ENABLE(gcc-warnings,
70      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
72 AC_PROG_CC
73 AC_PROG_CPP
74 AC_PROG_MAKE_SET
75 AC_PROG_RANLIB
77 TORUSER=_tor
78 AC_ARG_WITH(tor-user,
79         [  --with-tor-user=NAME    Specify username for tor daemon ],
80         [
81            TORUSER=$withval
82         ]
84 AC_SUBST(TORUSER)
86 TORGROUP=_tor
87 AC_ARG_WITH(tor-group,
88         [  --with-tor-group=NAME   Specify group name for tor daemon ],
89         [
90            TORGROUP=$withval
91         ]
93 AC_SUBST(TORGROUP)
96 dnl If WIN32 is defined and non-zero, we are building for win32
97 AC_MSG_CHECKING([for win32])
98 AC_RUN_IFELSE([
99 int main(int c, char **v) {
100 #ifdef WIN32
101 #if WIN32
102   return 0;
103 #else
104   return 1;
105 #endif
106 #else
107   return 2;
108 #endif
110 bwin32=true; AC_MSG_RESULT([yes]),
111 bwin32=false; AC_MSG_RESULT([no]),
112 bwin32=cross; AC_MSG_RESULT([cross])
115 if test "$bwin32" = cross; then
116 AC_MSG_CHECKING([for win32 (cross)])
117 AC_COMPILE_IFELSE([
118 #ifdef WIN32
119 int main(int c, char **v) {return 0;}
120 #else
121 #error
122 int main(int c, char **v) {return x(y);}
123 #endif
125 bwin32=true; AC_MSG_RESULT([yes]),
126 bwin32=false; AC_MSG_RESULT([no]))
129 if test "$bwin32" = true; then
130 AC_DEFINE(MS_WINDOWS, 1, [Define to 1 if we are building for Windows.])
132 AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
134 dnl Enable C99 when compiling with MIPSpro
135 AC_MSG_CHECKING([for MIPSpro compiler])
136 AC_COMPILE_IFELSE(AC_LANG_PROGRAM(, [
137 #if (defined(__sgi) && defined(_COMPILER_VERSION))
138 #error
139   return x(y);
140 #endif
142 bmipspro=false; AC_MSG_RESULT(no),
143 bmipspro=true; AC_MSG_RESULT(yes))
145 if test "$bmipspro" = true; then
146   CFLAGS="$CFLAGS -c99"
149 AC_C_BIGENDIAN
151 AC_SEARCH_LIBS(socket, [socket])
152 AC_SEARCH_LIBS(gethostbyname, [nsl])
153 AC_SEARCH_LIBS(dlopen, [dl])
154 AC_SEARCH_LIBS(inet_aton, [resolv])
156 if test "$enable_threads" = "yes"; then
157   AC_SEARCH_LIBS(pthread_create, [pthread])
158   AC_SEARCH_LIBS(pthread_detach, [pthread])
161 dnl -------------------------------------------------------------------
162 dnl Check for functions before libevent, since libevent-1.2 apparently
163 dnl exports strlcpy without defining it in a header.
165 AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo)
167 if test "$enable_threads" = "yes"; then
168   AC_CHECK_HEADERS(pthread.h)
169   AC_CHECK_FUNCS(pthread_create)
172 dnl ------------------------------------------------------
173 dnl Where do you live, libevent?  And how do we call you?
175 if test "$bwin32" = true; then
176   TOR_LIB_WS32=-lws2_32
177   # Some of the cargo-cults recommend -lwsock32 as well, but I don't
178   # think it's actually necessary.
179   TOR_LIB_GDI=-lgdi32
180 else
181   TOR_LIB_WS32=
182   TOR_LIB_GDI=
184 AC_SUBST(TOR_LIB_WS32)
185 AC_SUBST(TOR_LIB_GDI)
187 dnl We need to do this before we try our disgusting hack below.
188 AC_CHECK_HEADERS([sys/types.h])
190 dnl This is a disgusting hack so we safely include older libevent headers.
191 AC_CHECK_TYPE(u_int64_t, unsigned long long)
192 AC_CHECK_TYPE(u_int32_t, unsigned long)
193 AC_CHECK_TYPE(u_int16_t, unsigned short)
194 AC_CHECK_TYPE(u_int8_t, unsigned char)
196 tor_libevent_pkg_redhat="libevent"
197 tor_libevent_pkg_debian="libevent-dev"
198 tor_libevent_devpkg_redhat="libevent-devel"
199 tor_libevent_devpkg_debian="libevent-dev"
201 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $TOR_LIB_WS32], [
202 #include <stdlib.h>
203 #include <sys/time.h>
204 #include <sys/types.h>
205 #include <event.h>], [void exit(int); void *event_init(void);],
206     [event_init(); exit(0);], [--with-libevent-dir], [/opt/libevent])
208 dnl Now check for particular libevent functions.
209 save_LIBS="$LIBS"
210 save_LDFLAGS="$LDFLAGS"
211 save_CPPFLAGS="$CPPFLAGS"
212 LIBS="-levent $TOR_LIB_WS32 $LIBS"
213 LDFLAGS="$TOR_LDFLAGS_libevent $LIBS"
214 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
215 AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)
216 LIBS="$save_LIBS"
217 LDFLAGS="$save_LDFLAGS"
218 CPPFLAGS="$save_CPPFLAGS"
220 dnl ------------------------------------------------------
221 dnl Where do you live, openssl?  And how do we call you?
223 tor_openssl_pkg_redhat="openssl"
224 tor_openssl_pkg_debian="libssl"
225 tor_openssl_devpkg_redhat="openssl-devel"
226 tor_openssl_devpkg_debian="libssl-dev"
228 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
229     [#include <openssl/rand.h>],
230     [void RAND_add(const void *buf, int num, double entropy);],
231     [RAND_add((void*)0,0,0); exit(0);], [--with-ssl-dir],
232     [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
234 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
236 dnl ------------------------------------------------------
237 dnl Where do you live, zlib?  And how do we call you?
239 tor_openssl_pkg_redhat="zlib"
240 tor_openssl_pkg_debian="zlib1g"
241 tor_openssl_devpkg_redhat="zlib-devel"
242 tor_openssl_devpkg_debian="zlib1g-dev"
244 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
245     [#include <zlib.h>],
246     [const char * zlibVersion(void);],
247     [zlibVersion(); exit(0);], [--with-zlib-dir],
248     [/opt/zlib])
250 dnl Make sure to enable support for large off_t if available.
252 AC_SYS_LARGEFILE
254 AC_CHECK_HEADERS(unistd.h string.h signal.h ctype.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.))
256 AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h grp.h sys/un.h)
258 dnl These headers are not essential
260 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 netintet/in.h netinet/in6.h malloc.h sys/syslimits.h)
262 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
263 [#ifdef HAVE_SYS_TYPES_H
264 #include <sys/types.h>
265 #endif
266 #ifdef HAVE_SYS_SOCKET_H
267 #include <sys/socket.h>
268 #endif])
269 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
270 [#ifdef HAVE_SYS_TYPES_H
271 #include <sys/types.h>
272 #endif
273 #ifdef HAVE_SYS_SOCKET_H
274 #include <sys/socket.h>
275 #endif
276 #ifdef HAVE_NET_IF_H
277 #include <net/if.h>
278 #endif])
279 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
280         linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
281 [#ifdef HAVE_SYS_TYPES_H
282 #include <sys/types.h>
283 #endif
284 #ifdef HAVE_SYS_SOCKET_H
285 #include <sys/socket.h>
286 #endif])
288 if test x$transparent = xtrue ; then
289    transparent_ok=0
290    if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
291      transparent_ok=1
292    fi
293    if test x$linux_netfilter_ipv4 = x1 ; then
294      transparent_ok=1
295    fi
296    if test x$transparent_ok = x1 ; then
297      AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
298      case $host in
299        *-*-openbsd*)
300          AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
301      esac
302    else
303      AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
304    fi
307 AC_FUNC_FSEEKO
309 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
310 [#ifdef HAVE_SYS_TYPES_H
311 #include <sys/types.h>
312 #endif
313 #ifdef HAVE_SYS_TIME_H
314 #include <sys/time.h>
315 #endif])
317 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
318 dnl Watch out.
320 AC_CHECK_SIZEOF(int8_t)
321 AC_CHECK_SIZEOF(int16_t)
322 AC_CHECK_SIZEOF(int32_t)
323 AC_CHECK_SIZEOF(int64_t)
324 AC_CHECK_SIZEOF(uint8_t)
325 AC_CHECK_SIZEOF(uint16_t)
326 AC_CHECK_SIZEOF(uint32_t)
327 AC_CHECK_SIZEOF(uint64_t)
328 AC_CHECK_SIZEOF(intptr_t)
329 AC_CHECK_SIZEOF(uintptr_t)
331 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
333 AC_CHECK_SIZEOF(char)
334 AC_CHECK_SIZEOF(short)
335 AC_CHECK_SIZEOF(int)
336 AC_CHECK_SIZEOF(long)
337 AC_CHECK_SIZEOF(long long)
338 AC_CHECK_SIZEOF(__int64)
339 AC_CHECK_SIZEOF(void *)
340 AC_CHECK_SIZEOF(time_t)
341 AC_CHECK_SIZEOF(size_t)
343 AC_CHECK_TYPES([uint, u_char])
345 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, struct sockaddr_storage, sa_family_t], , ,
346 [#ifdef HAVE_SYS_TYPES_H
347 #include <sys/types.h>
348 #endif
349 #ifdef HAVE_NETINET_IN_H
350 #include <netinet/in.h>
351 #endif
352 #ifdef HAVE_NETINET_IN6_H
353 #include <netinet/in6.h>
354 #endif
355 #ifdef HAVE_SYS_SOCKET_H
356 #include <sys/socket.h>
357 #endif
358 #ifdef MS_WINDOWS
359 #define WIN32_WINNT 0x400
360 #define _WIN32_WINNT 0x400
361 #define WIN32_LEAN_AND_MEAN
362 #if defined(_MSC_VER) && (_MSC_VER < 1300)
363 #include <winsock.h>
364 #else
365 #include <winsock2.h>
366 #include <ws2tcpip.h>
367 #endif
368 #endif
370 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16], , ,
371 [#ifdef HAVE_SYS_TYPES_H
372 #include <sys/types.h>
373 #endif
374 #ifdef HAVE_NETINET_IN_H
375 #include <netinet/in.h>
376 #endif
377 #ifdef HAVE_NETINET_IN6_H
378 #include <netinet/in6.h>
379 #endif
380 #ifdef HAVE_SYS_SOCKET_H
381 #include <sys/socket.h>
382 #endif
383 #ifdef MS_WINDOWS
384 #define WIN32_WINNT 0x400
385 #define _WIN32_WINNT 0x400
386 #define WIN32_LEAN_AND_MEAN
387 #if defined(_MSC_VER) && (_MSC_VER < 1300)
388 #include <winsock.h>
389 #else
390 #include <winsock2.h>
391 #include <ws2tcpip.h>
392 #endif
393 #endif
396 AC_CHECK_TYPES([rlim_t], , ,
397 [#ifdef HAVE_SYS_TYPES_H
398 #include <sys/types.h>
399 #endif
400 #ifdef HAVE_SYS_TIME_H
401 #include <sys/time.h>
402 #endif
403 #ifdef HAVE_SYS_RESOURCE_H
404 #include <sys/resource.h>
405 #endif
408 if test -z "$CROSS_COMPILE"; then
409 AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
410 AC_RUN_IFELSE(AC_LANG_SOURCE([
411 #ifdef HAVE_SYS_TYPES_H
412 #include <sys/types.h>
413 #endif
414 #ifdef HAVE_SYS_TIME_H
415 #include <sys/time.h>
416 #endif
417 #ifdef HAVE_TIME_H
418 #include <time.h>
419 #endif
420 int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }]),
421   tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes)
423 else
424   # Cross-compiling; let's hope the target platform isn't loony.
425   AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
426   tor_cv_time_t_signed=yes
429 if test "$tor_cv_time_t_signed" = yes; then
430   AC_DEFINE([TIME_T_IS_SIGNED], 1,
431             [Define to 1 iff time_t is signed])
434 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
435 #ifdef HAVE_SYS_SOCKET_H
436 #include <sys/socket.h>
437 #endif
440 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
442 AC_CHECK_SIZEOF(cell_t)
444 # Now make sure that NULL can be represented as zero bytes.
445 if test -z "$CROSS_COMPILE"; then
446 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
447 [AC_RUN_IFELSE([AC_LANG_SOURCE(
448 [[#include <stdlib.h>
449 #include <string.h>
450 #include <stdio.h>
451 #ifdef HAVE_STDDEF_H
452 #include <stddef.h>
453 #endif
454 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
455 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
456        [tor_cv_null_is_zero=yes],
457        [tor_cv_null_is_zero=no],
458        [tor_cv_null_is_zero=cross])])
460 else
461   # Cross-compiling; let's hope that the target isn't raving mad.
462   AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
463   tor_cv_null_is_zero=yes
466 if test "$tor_cv_null_is_zero" = yes; then
467   AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
468             [Define to 1 iff memset(0) sets pointers to NULL])
471 # And what happens when we malloc zero?
473 if test -z "$CROSS_COMPILE"; then
474 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
475 [AC_RUN_IFELSE([AC_LANG_SOURCE(
476 [[#include <stdlib.h>
477 #include <string.h>
478 #include <stdio.h>
479 #ifdef HAVE_STDDEF_H
480 #include <stddef.h>
481 #endif
482 int main () { return malloc(0)?0:1; }]])],
483        [tor_cv_malloc_zero_works=yes],
484        [tor_cv_malloc_zero_works=no],
485        [tor_cv_malloc_zero_works=cross])])
487 else
488   # Cross-compiling; let's hope that the target isn't raving mad.
489   AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
490   tor_cv_malloc_zero_works=no
493 if test "$tor_cv_malloc_zero_works" = yes; then
494   AC_DEFINE([MALLOC_ZERO_WORKS], 1,
495             [Define to 1 iff malloc(0) returns a pointer])
498 # whether we seem to be in a 2s-complement world.
499 if test -z "$CROSS_COMPILE"; then
500 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
501 [AC_RUN_IFELSE([AC_LANG_SOURCE(
502 [[int main () { int problem = ((-99) != (~99)+1);
503 return problem ? 1 : 0; }]])],
504        [tor_cv_twos_complement=yes],
505        [tor_cv_twos_complement=no],
506        [tor_cv_twos_complement=cross])])
508 else
509   # Cross-compiling; let's hope that the target isn't raving mad.
510   AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
511   tor_cv_twos_complement=yes
514 if test "$tor_cv_twos_complement" = yes; then
515   AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
516             [Define to 1 iff we represent negative integers with two's complement])
519 # Whether we should use the dmalloc memory allocation debugging library.
520 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
521 AC_ARG_WITH(dmalloc,
522 [  --with-dmalloc          Use debug memory allocation library. ],
523 [if [[ "$withval" = "yes" ]]; then
524   dmalloc=1
525   AC_MSG_RESULT(yes)
526 else
527   dmalloc=1
528   AC_MSG_RESULT(no)
529 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
532 if [[ $dmalloc -eq 1 ]]; then
533   AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
534   AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
535   AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
536   AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
537   AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
540 # Allow user to specify an alternate syslog facility
541 AC_ARG_WITH(syslog-facility,
542 [  --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
543 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
544 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
545 AC_SUBST(LOGFACILITY)
547 # Check for gethostbyname_r in all its glorious incompatible versions.
548 #   (This logic is based on that in Python's configure.in)
549 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
550   [Define this if you have any gethostbyname_r()])
552 AC_CHECK_FUNC(gethostbyname_r, [
553   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
554   OLD_CFLAGS=$CFLAGS
555   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
556   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
557 #include <netdb.h>
558   ], [[
559     char *cp1, *cp2;
560     struct hostent *h1, *h2;
561     int i1, i2;
562     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
563   ]]),[
564     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
565     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
566      [Define this if gethostbyname_r takes 6 arguments])
567     AC_MSG_RESULT(6)
568   ], [
569     AC_TRY_COMPILE([
570 #include <netdb.h>
571     ], [
572       char *cp1, *cp2;
573       struct hostent *h1;
574       int i1, i2;
575       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
576     ], [
577       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
578       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
579         [Define this if gethostbyname_r takes 5 arguments])
580       AC_MSG_RESULT(5)
581    ], [
582       AC_TRY_COMPILE([
583 #include <netdb.h>
584      ], [
585        char *cp1;
586        struct hostent *h1;
587        struct hostent_data hd;
588        (void) gethostbyname_r(cp1,h1,&hd);
589      ], [
590        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
591        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
592          [Define this if gethostbyname_r takes 3 arguments])
593        AC_MSG_RESULT(3)
594      ], [
595        AC_MSG_RESULT(0)
596      ])
597   ])
598  ])
599  CFLAGS=$OLD_CFLAGS
602 AC_CACHE_CHECK([whether the C compiler supports __func__],
603   tor_cv_have_func_macro,
604   AC_COMPILE_IFELSE([
605 #include <stdio.h>
606 int main(int c, char **v) { puts(__func__); }],
607   tor_cv_have_func_macro=yes,
608   tor_cv_have_func_macro=no))
610 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
611   tor_cv_have_FUNC_macro,
612   AC_COMPILE_IFELSE([
613 #include <stdio.h>
614 int main(int c, char **v) { puts(__FUNC__); }],
615   tor_cv_have_FUNC_macro=yes,
616   tor_cv_have_FUNC_macro=no))
618 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
619   tor_cv_have_FUNCTION_macro,
620   AC_COMPILE_IFELSE([
621 #include <stdio.h>
622 int main(int c, char **v) { puts(__FUNCTION__); }],
623   tor_cv_have_FUNCTION_macro=yes,
624   tor_cv_have_FUNCTION_macro=no))
626 if test "$tor_cv_have_func_macro" = 'yes'; then
627   AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
630 if test "$tor_cv_have_FUNC_macro" = 'yes'; then
631   AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
634 if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
635   AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
636            [Defined if the compiler supports __FUNCTION__])
639 # $prefix stores the value of the --prefix command line option, or
640 # NONE if the option wasn't set.  In the case that it wasn't set, make
641 # it be the default, so that we can use it to expand directories now.
642 if test "x$prefix" = "xNONE"; then
643   prefix=$ac_default_prefix
646 # and similarly for $exec_prefix
647 if test "x$exec_prefix" = "xNONE"; then
648   exec_prefix=$prefix
651 if test "x$CONFDIR" = "x"; then
652   CONFDIR=`eval echo $sysconfdir/tor`
654 AC_SUBST(CONFDIR)
655 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
656 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
658 BINDIR=`eval echo $bindir`
659 AC_SUBST(BINDIR)
660 LOCALSTATEDIR=`eval echo $localstatedir`
661 AC_SUBST(LOCALSTATEDIR)
663 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
664 # than autoconf's macros like.
665 if test "$ac_cv_c_compiler_gnu" = yes; then
666   CFLAGS="$CFLAGS -Wall -g -O2"
667 else
668   CFLAGS="$CFLAGS -g -O"
669   enable_gcc_warnings=no
672 # Add some more warnings which we use in development but not in the
673 # released versions.  (Some relevant gcc versions can't handle these.)
674 if test x$enable_gcc_warnings = xyes; then
676   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
677 #if !defined(__GNUC__) || (__GNUC__ < 4)
678 #error
679 #endif]), have_gcc4=yes, have_gcc4=no)
681   AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
682 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
683 #error
684 #endif]), have_gcc42=yes, have_gcc42=no)
686   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 -Werror"
687   # Disabled, so we can use mallinfo(): -Waggregate-return
689   if test x$have_gcc4 = xyes ; then 
690     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
691     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
692   fi
694   if test x$have_gcc42 = xyes ; then 
695     # These warnings break gcc 4.0.2 and work on gcc 4.2
696     # XXXX020 Use -fstack-protector.
697     # XXXX020 See if any of these work with earlier versions.
698     CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wnormalized=id -Woverride-init -Wstrict-overflow=5"
699   fi
701 ##This will break the world on some 64-bit architectures
702 # CFLAGS="$CFLAGS -Winline"
706 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
708 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 doc/tor.1 src/Makefile doc/Makefile doc/design-paper/Makefile doc/spec/Makefile src/config/Makefile src/common/Makefile src/or/Makefile src/win32/Makefile src/tools/Makefile contrib/suse/Makefile contrib/suse/tor.sh])
709 AC_OUTPUT
711 if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
712   ./contrib/updateVersions.pl