dnscrypto-proxy: Update to release 1.3.0
[tomato.git] / release / src / router / dnscrypt / src / libevent-modified / configure.ac
bloba9405548aa88852c452ebbc3f7fc6f873628a847
1 dnl configure.in for libevent
2 dnl Copyright 2000-2007 Niels Provos
3 dnl Copyright 2007-2012 Niels Provos and Nick Mathewson
4 dnl
5 dnl See LICENSE for copying information.
6 dnl
7 dnl Original version Dug Song <dugsong@monkey.org>
9 AC_PREREQ(2.59c)
11 AC_CONFIG_MACRO_DIR([m4])
13 AC_INIT([libevent],[2.0.21-stable-dev])
14 AC_CONFIG_SRCDIR([evdns.c])
15 AM_INIT_AUTOMAKE
16 AC_CONFIG_HEADERS(config.h)
17 AC_DEFINE(NUMERIC_VERSION, 0x02001501, [Numeric representation of the version])
19 dnl Initialize prefix.
20 if test "$prefix" = "NONE"; then
21    prefix="/usr/local"
24 AC_CANONICAL_BUILD
25 AC_CANONICAL_HOST
26 dnl the 'build' machine is where we run configure and compile
27 dnl the 'host' machine is where the resulting stuff runs.
29 case "$host_os" in
31  osf5*)
32     CFLAGS="$CFLAGS -D_OSF_SOURCE"
33     ;;
34 esac
36 dnl Checks for programs.
37 AC_PROG_CC
38 AM_PROG_CC_C_O
39 AC_PROG_SED
40 AC_PROG_INSTALL
41 AC_PROG_LN_S
42 AC_PROG_MKDIR_P
44 AC_PROG_GCC_TRADITIONAL
46 # We need to test for at least gcc 2.95 here, because older versions don't
47 # have -fno-strict-aliasing
48 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
49 #if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
50 #error
51 #endif])], have_gcc295=yes, have_gcc295=no)
53 if test "$GCC" = "yes" ; then
54         # Enable many gcc warnings by default...
55         CFLAGS="$CFLAGS -Wall"
56         # And disable the strict-aliasing optimization, since it breaks
57         # our sockaddr-handling code in strange ways.
58         if test x$have_gcc295 = xyes; then
59                 CFLAGS="$CFLAGS -fno-strict-aliasing"
60         fi
63 # OS X Lion started deprecating the system openssl. Let's just disable
64 # all deprecation warnings on OS X.
65 case "$host_os" in
67  darwin*)
68     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
69     ;;
70 esac
72 AC_ARG_ENABLE(gcc-warnings,
73      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
74 AC_ARG_ENABLE(thread-support,
75      AS_HELP_STRING(--disable-thread-support, disable support for threading),
76         [], [enable_thread_support=yes])
77 AC_ARG_ENABLE(malloc-replacement,
78      AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
79         [], [enable_malloc_replacement=yes])
80 AC_ARG_ENABLE(openssl,
81      AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
82         [], [enable_openssl=yes])
83 AC_ARG_ENABLE(debug-mode,
84      AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
85         [], [enable_debug_mode=yes])
86 AC_ARG_ENABLE([libevent-install],
87      AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
88         [], [enable_libevent_install=yes])
89 AC_ARG_ENABLE([libevent-regress],
90      AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
91         [], [enable_libevent_regress=yes])
92 AC_ARG_ENABLE([function-sections],
93      AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
94         [], [enable_function_sections=no])
97 AC_PROG_LIBTOOL
99 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
100 dnl   built by default.  You can also turn shared libs on and off from
101 dnl   the command line with --enable-shared and --disable-shared.
102 dnl AC_DISABLE_SHARED
103 AC_SUBST(LIBTOOL_DEPS)
105 AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
107 dnl Checks for libraries.
108 AC_SEARCH_LIBS([inet_ntoa], [nsl])
109 AC_SEARCH_LIBS([socket], [socket])
110 AC_SEARCH_LIBS([inet_aton], [resolv])
111 AC_SEARCH_LIBS([clock_gettime], [rt])
112 AC_SEARCH_LIBS([sendfile], [sendfile])
114 dnl - check if the macro WIN32 is defined on this compiler.
115 dnl - (this is how we check for a windows version of GCC)
116 AC_MSG_CHECKING(for WIN32)
117 AC_TRY_COMPILE(,
118         [
119 #ifndef WIN32
120 die horribly
121 #endif
122         ],
123         bwin32=true; AC_MSG_RESULT(yes),
124         bwin32=false; AC_MSG_RESULT(no),
127 dnl - check if the macro __CYGWIN__ is defined on this compiler.
128 dnl - (this is how we check for a cygwin version of GCC)
129 AC_MSG_CHECKING(for CYGWIN)
130 AC_TRY_COMPILE(,
131         [
132 #ifndef __CYGWIN__
133 die horribly
134 #endif
135         ],
136         cygwin=true; AC_MSG_RESULT(yes),
137         cygwin=false; AC_MSG_RESULT(no),
140 AC_CHECK_HEADERS([zlib.h])
142 if test "x$ac_cv_header_zlib_h" = "xyes"; then
143 dnl Determine if we have zlib for regression tests
144 dnl Don't put this one in LIBS
145 save_LIBS="$LIBS"
146 LIBS=""
147 ZLIB_LIBS=""
148 have_zlib=no
149 AC_SEARCH_LIBS([inflateEnd], [z],
150         [have_zlib=yes
151         ZLIB_LIBS="$LIBS"
152         AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
153 LIBS="$save_LIBS"
154 AC_SUBST(ZLIB_LIBS)
156 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
158 dnl See if we have openssl.  This doesn't go in LIBS either.
159 if test "$bwin32" = true; then
160   EV_LIB_WS32=-lws2_32
161   EV_LIB_GDI=-lgdi32
162 else
163   EV_LIB_WS32=
164   EV_LIB_GDI=
166 AC_SUBST(EV_LIB_WS32)
167 AC_SUBST(EV_LIB_GDI)
168 AC_SUBST(OPENSSL_LIBADD)
170 AC_CHECK_HEADERS([openssl/bio.h])
172 if test "$enable_openssl" = "yes"; then
173 save_LIBS="$LIBS"
174 LIBS=""
175 OPENSSL_LIBS=""
176 have_openssl=no
177 AC_SEARCH_LIBS([SSL_new], [ssl],
178         [have_openssl=yes
179         OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
180         AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
181         [have_openssl=no],
182         [-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
183 LIBS="$save_LIBS"
184 AC_SUBST(OPENSSL_LIBS)
187 dnl Checks for header files.
188 AC_HEADER_STDC
189 AC_CHECK_HEADERS([fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.h unistd.h sys/epoll.h sys/time.h sys/queue.h sys/event.h sys/param.h sys/ioctl.h sys/select.h sys/devpoll.h port.h netinet/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h sys/eventfd.h sys/mman.h sys/sendfile.h sys/wait.h netdb.h])
190 AC_CHECK_HEADERS([sys/stat.h])
191 AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
192 #ifdef HAVE_SYS_PARAM_H
193 #include <sys/param.h>
194 #endif
196 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
197         AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
198         AC_EGREP_CPP(yes,
200 #include <sys/queue.h>
201 #ifdef TAILQ_FOREACH
202  yes
203 #endif
204 ],      [AC_MSG_RESULT(yes)
205          AC_DEFINE(HAVE_TAILQFOREACH, 1,
206                 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
207         AC_MSG_RESULT(no)
208         )
211 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
212         AC_MSG_CHECKING(for timeradd in sys/time.h)
213         AC_EGREP_CPP(yes,
215 #include <sys/time.h>
216 #ifdef timeradd
217  yes
218 #endif
219 ],      [ AC_DEFINE(HAVE_TIMERADD, 1,
220                 [Define if timeradd is defined in <sys/time.h>])
221           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
225 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
226         AC_MSG_CHECKING(for timercmp in sys/time.h)
227         AC_EGREP_CPP(yes,
229 #include <sys/time.h>
230 #ifdef timercmp
231  yes
232 #endif
233 ],      [ AC_DEFINE(HAVE_TIMERCMP, 1,
234                 [Define if timercmp is defined in <sys/time.h>])
235           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
239 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
240         AC_MSG_CHECKING(for timerclear in sys/time.h)
241         AC_EGREP_CPP(yes,
243 #include <sys/time.h>
244 #ifdef timerclear
245  yes
246 #endif
247 ],      [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
248                 [Define if timerclear is defined in <sys/time.h>])
249           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
253 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
254         AC_MSG_CHECKING(for timerisset in sys/time.h)
255         AC_EGREP_CPP(yes,
257 #include <sys/time.h>
258 #ifdef timerisset
259  yes
260 #endif
261 ],      [ AC_DEFINE(HAVE_TIMERISSET, 1,
262                 [Define if timerisset is defined in <sys/time.h>])
263           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
267 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
268         AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
269            [[#include <sys/types.h>
270              #include <sys/sysctl.h>]]
271         )
274 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
275 AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
276 AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue)
278 if test x$bwin32 = xtrue; then
279    AC_SEARCH_LIBS([getservbyname],[ws2_32])
282 dnl Checks for typedefs, structures, and compiler characteristics.
283 AC_C_CONST
284 AC_C_INLINE
285 AC_HEADER_TIME
287 dnl Checks for library functions.
288 AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep])
289 AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getprotobynumber setenv unsetenv putenv sysctl])
290 AC_CHECK_FUNCS([umask])
292 AC_CACHE_CHECK(
293     [for getaddrinfo],
294     [libevent_cv_getaddrinfo],
295     [AC_LINK_IFELSE(
296         [AC_LANG_PROGRAM(
297             [[
298                 #ifdef HAVE_NETDB_H
299                 #include <netdb.h>
300                 #endif
301             ]],
302             [[
303                 getaddrinfo;
304             ]]
305         )],
306         [libevent_cv_getaddrinfo=yes],
307         [libevent_cv_getaddrinfo=no]
308     )]
310 if test "$libevent_cv_getaddrinfo" = "yes" ; then
311     AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
312 else
314 AC_CHECK_FUNCS([getservbyname])
315 # Check for gethostbyname_r in all its glorious incompatible versions.
316 #   (This is cut-and-pasted from Tor, which based its logic on
317 #   Python's configure.in.)
318 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
319   [Define this if you have any gethostbyname_r()])
321 AC_CHECK_FUNC(gethostbyname_r, [
322   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
323   OLD_CFLAGS=$CFLAGS
324   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
325   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
326 #include <netdb.h>
327   ], [[
328     char *cp1, *cp2;
329     struct hostent *h1, *h2;
330     int i1, i2;
331     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
332   ]])],[
333     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
334     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
335      [Define this if gethostbyname_r takes 6 arguments])
336     AC_MSG_RESULT(6)
337   ], [
338     AC_TRY_COMPILE([
339 #include <netdb.h>
340     ], [
341       char *cp1, *cp2;
342       struct hostent *h1;
343       int i1, i2;
344       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
345     ], [
346       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
347       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
348         [Define this if gethostbyname_r takes 5 arguments])
349       AC_MSG_RESULT(5)
350    ], [
351       AC_TRY_COMPILE([
352 #include <netdb.h>
353      ], [
354        char *cp1;
355        struct hostent *h1;
356        struct hostent_data hd;
357        (void) gethostbyname_r(cp1,h1,&hd);
358      ], [
359        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
360        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
361          [Define this if gethostbyname_r takes 3 arguments])
362        AC_MSG_RESULT(3)
363      ], [
364        AC_MSG_RESULT(0)
365      ])
366   ])
367  ])
368  CFLAGS=$OLD_CFLAGS
373 AC_CHECK_SIZEOF(long)
375 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
376 AC_EGREP_CPP(yes,
378 #define _GNU_SOURCE
379 #include <fcntl.h>
380 #ifdef F_SETFD
382 #endif
383 ],      [ AC_DEFINE(HAVE_SETFD, 1,
384               [Define if F_SETFD is defined in <fcntl.h>])
385           AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
387 needsignal=no
388 haveselect=no
389 if test x$bwin32 != xtrue; then
390     AC_CHECK_FUNCS(select, [haveselect=yes], )
391     if test "x$haveselect" = "xyes" ; then
392         needsignal=yes
393     fi
395 AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
397 havepoll=no
398 AC_CHECK_FUNCS(poll, [havepoll=yes], )
399 if test "x$havepoll" = "xyes" ; then
400         needsignal=yes
402 AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
404 havedevpoll=no
405 if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
406         AC_DEFINE(HAVE_DEVPOLL, 1,
407                     [Define if /dev/poll is available])
409 AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
411 havekqueue=no
412 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
413         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
414         if test "x$havekqueue" = "xyes" ; then
415                 AC_MSG_CHECKING(for working kqueue)
416                 AC_TRY_RUN(
417 #include <sys/types.h>
418 #include <sys/time.h>
419 #include <sys/event.h>
420 #include <stdio.h>
421 #include <unistd.h>
422 #include <fcntl.h>
425 main(int argc, char **argv)
427         int kq;
428         int n;
429         int fd[[2]];
430         struct kevent ev;
431         struct timespec ts;
432         char buf[[8000]];
434         if (pipe(fd) == -1)
435                 exit(1);
436         if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
437                 exit(1);
439         while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
440                 ;
442         if ((kq = kqueue()) == -1)
443                 exit(1);
445         memset(&ev, 0, sizeof(ev));
446         ev.ident = fd[[1]];
447         ev.filter = EVFILT_WRITE;
448         ev.flags = EV_ADD | EV_ENABLE;
449         n = kevent(kq, &ev, 1, NULL, 0, NULL);
450         if (n == -1)
451                 exit(1);
453         read(fd[[0]], buf, sizeof(buf));
455         ts.tv_sec = 0;
456         ts.tv_nsec = 0;
457         n = kevent(kq, NULL, 0, &ev, 1, &ts);
458         if (n == -1 || n == 0)
459                 exit(1);
461         exit(0);
462 }, [AC_MSG_RESULT(yes)
463     AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
464                 [Define if kqueue works correctly with pipes])
465     havekqueue=yes
466     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
467         fi
469 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
471 haveepollsyscall=no
472 haveepoll=no
473 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
474 if test "x$haveepoll" = "xyes" ; then
475         AC_DEFINE(HAVE_EPOLL, 1,
476                 [Define if your system supports the epoll system calls])
477         needsignal=yes
479 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
480         if test "x$haveepoll" = "xno" ; then
481                 AC_MSG_CHECKING(for epoll system call)
482                 AC_TRY_RUN(
483 #include <stdint.h>
484 #include <sys/param.h>
485 #include <sys/types.h>
486 #include <sys/syscall.h>
487 #include <sys/epoll.h>
488 #include <unistd.h>
491 epoll_create(int size)
493         return (syscall(__NR_epoll_create, size));
497 main(int argc, char **argv)
499         int epfd;
501         epfd = epoll_create(256);
502         exit (epfd == -1 ? 1 : 0);
503 }, [AC_MSG_RESULT(yes)
504     AC_DEFINE(HAVE_EPOLL, 1,
505         [Define if your system supports the epoll system calls])
506     needsignal=yes
507     have_epoll=yes
508     AC_LIBOBJ(epoll_sub)
509     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
510         fi
512 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
514 haveeventports=no
515 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
516 if test "x$haveeventports" = "xyes" ; then
517         AC_DEFINE(HAVE_EVENT_PORTS, 1,
518                 [Define if your system supports event ports])
519         needsignal=yes
521 AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
523 if test "x$bwin32" = "xtrue"; then
524         needsignal=yes
527 AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
529 AC_TYPE_PID_T
530 AC_TYPE_SIZE_T
531 AC_TYPE_SSIZE_T
533 AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
534 [#ifdef HAVE_STDINT_H
535 #include <stdint.h>
536 #elif defined(HAVE_INTTYPES_H)
537 #include <inttypes.h>
538 #endif
539 #ifdef HAVE_SYS_TYPES_H
540 #include <sys/types.h>
541 #endif])
543 AC_CHECK_TYPES([fd_mask], , ,
544 [#ifdef HAVE_SYS_TYPES_H
545 #include <sys/types.h>
546 #endif
547 #ifdef HAVE_SYS_SELECT_H
548 #include <sys/select.h>
549 #endif])
551 AC_CHECK_SIZEOF(long long)
552 AC_CHECK_SIZEOF(long)
553 AC_CHECK_SIZEOF(int)
554 AC_CHECK_SIZEOF(short)
555 AC_CHECK_SIZEOF(size_t)
556 AC_CHECK_SIZEOF(void *)
558 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
559 [#define _GNU_SOURCE
560 #include <sys/types.h>
561 #ifdef HAVE_NETINET_IN_H
562 #include <netinet/in.h>
563 #endif
564 #ifdef HAVE_NETINET_IN6_H
565 #include <netinet/in6.h>
566 #endif
567 #ifdef HAVE_SYS_SOCKET_H
568 #include <sys/socket.h>
569 #endif
570 #ifdef HAVE_NETDB_H
571 #include <netdb.h>
572 #endif
573 #ifdef WIN32
574 #define WIN32_WINNT 0x400
575 #define _WIN32_WINNT 0x400
576 #define WIN32_LEAN_AND_MEAN
577 #if defined(_MSC_VER) && (_MSC_VER < 1300)
578 #include <winsock.h>
579 #else
580 #include <winsock2.h>
581 #include <ws2tcpip.h>
582 #endif
583 #endif
585 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len, struct sockaddr_storage.ss_family, struct sockaddr_storage.__ss_family], , ,
586 [#include <sys/types.h>
587 #ifdef HAVE_NETINET_IN_H
588 #include <netinet/in.h>
589 #endif
590 #ifdef HAVE_NETINET_IN6_H
591 #include <netinet/in6.h>
592 #endif
593 #ifdef HAVE_SYS_SOCKET_H
594 #include <sys/socket.h>
595 #endif
596 #ifdef WIN32
597 #define WIN32_WINNT 0x400
598 #define _WIN32_WINNT 0x400
599 #define WIN32_LEAN_AND_MEAN
600 #if defined(_MSC_VER) && (_MSC_VER < 1300)
601 #include <winsock.h>
602 #else
603 #include <winsock2.h>
604 #include <ws2tcpip.h>
605 #endif
606 #endif
609 AC_MSG_CHECKING([for socklen_t])
610 AC_TRY_COMPILE([
611  #include <sys/types.h>
612  #include <sys/socket.h>],
613   [socklen_t x;],
614   AC_MSG_RESULT([yes]),
615   [AC_MSG_RESULT([no])
616   AC_DEFINE(socklen_t, unsigned int,
617         [Define to unsigned int if you dont have it])]
620 AC_MSG_CHECKING([whether our compiler supports __func__])
621 AC_TRY_COMPILE([],
622  [ const char *cp = __func__; ],
623  AC_MSG_RESULT([yes]),
624  AC_MSG_RESULT([no])
625  AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
626  AC_TRY_COMPILE([],
627    [ const char *cp = __FUNCTION__; ],
628    AC_MSG_RESULT([yes])
629    AC_DEFINE(__func__, __FUNCTION__,
630          [Define to appropriate substitue if compiler doesnt have __func__]),
631    AC_MSG_RESULT([no])
632    AC_DEFINE(__func__, __FILE__,
633          [Define to appropriate substitue if compiler doesnt have __func__])))
636 # check if we can compile with pthreads
637 have_pthreads=no
638 if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
639   ACX_PTHREAD([
640         AC_DEFINE(HAVE_PTHREADS, 1,
641                 [Define if we have pthreads on this system])
642         have_pthreads=yes])
643   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
644   AC_CHECK_SIZEOF(pthread_t, ,
645      [AC_INCLUDES_DEFAULT()
646       #include <pthread.h> ]
647   )
649 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
651 # check if we should compile locking into the library
652 if test x$enable_thread_support = xno; then
653    AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
654         [Define if libevent should not be compiled with thread support])
657 # check if we should hard-code the mm functions.
658 if test x$enable_malloc_replacement = xno; then
659   AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
660         [Define if libevent should not allow replacing the mm functions])
663 # check if we should hard-code debugging out
664 if test x$enable_debug_mode = xno; then
665   AC_DEFINE(DISABLE_DEBUG_MODE, 1,
666         [Define if libevent should build without support for a debug mode])
669 # check if we have and should use openssl
670 AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
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 && test "$GCC" = "yes"; 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   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
687 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
688 #error
689 #endif])], have_gcc45=yes, have_gcc45=no)
691   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
692 #if !defined(__clang__)
693 #error
694 #endif])], have_clang=yes, have_clang=no)
696   CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror"
697   CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
699   if test x$have_gcc4 = xyes ; then
700     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
701     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
702     #CFLAGS="$CFLAGS -Wold-style-definition"
703   fi
705   if test x$have_gcc42 = xyes ; then
706     # These warnings break gcc 4.0.2 and work on gcc 4.2
707     CFLAGS="$CFLAGS -Waddress"
708   fi
710   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
711     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
712     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
713   fi
715   if test x$have_gcc45 = xyes ; then
716     # These warnings work on gcc 4.5
717     CFLAGS="$CFLAGS -Wlogical-op"
718   fi
720   if test x$have_clang = xyes; then
721     # Disable the unused-function warnings, because these trigger
722     # for minheap-internal.h related code.
723     CFLAGS="$CFLAGS -Wno-unused-function"
724   fi
726 ##This will break the world on some 64-bit architectures
727 # CFLAGS="$CFLAGS -Winline"
731 LIBEVENT_GC_SECTIONS=
732 if test "$GCC" = yes && test "$enable_function_sections" = yes ; then
733     AC_CACHE_CHECK(
734         [if linker supports omitting unused code and data],
735         [libevent_cv_gc_sections_runs],
736         [
737             dnl  NetBSD will link but likely not run with --gc-sections
738             dnl  http://bugs.ntp.org/1844
739             dnl  http://gnats.netbsd.org/40401
740             dnl  --gc-sections causes attempt to load as linux elf, with
741             dnl  wrong syscalls in place.  Test a little gauntlet of
742             dnl  simple stdio read code checking for errors, expecting
743             dnl  enough syscall differences that the NetBSD code will
744             dnl  fail even with Linux emulation working as designed.
745             dnl  A shorter test could be refined by someone with access
746             dnl  to a NetBSD host with Linux emulation working.
747             origCFLAGS="$CFLAGS"
748             CFLAGS="$CFLAGS -Wl,--gc-sections"
749             AC_LINK_IFELSE(
750                 [AC_LANG_PROGRAM(
751                     [[
752                         #include <stdlib.h>
753                         #include <stdio.h>
754                     ]],
755                     [[
756                         FILE *  fpC;
757                         char    buf[32];
758                         size_t  cch;
759                         int     read_success_once;
761                         fpC = fopen("conftest.c", "r");
762                         if (NULL == fpC)
763                                 exit(1);
764                         do {
765                                 cch = fread(buf, sizeof(buf), 1, fpC);
766                                 read_success_once |= (0 != cch);
767                         } while (0 != cch);
768                         if (!read_success_once)
769                                 exit(2);
770                         if (!feof(fpC))
771                                 exit(3);
772                         if (0 != fclose(fpC))
773                                 exit(4);
775                         exit(EXIT_SUCCESS);
776                     ]]
777                 )],
778                 [
779                     dnl We have to do this invocation manually so that we can
780                     dnl get the output of conftest.err to make sure it doesn't
781                     dnl mention gc-sections.
782                     if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
783                         libevent_cv_gc_sections_runs=no
784                     else
785                         libevent_cv_gc_sections_runs=no
786                         ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
787                     fi
788                 ],
789                 [libevent_cv_gc_sections_runs=no]
790             )
791             CFLAGS="$origCFLAGS"
792             AS_UNSET([origCFLAGS])
793         ]
794     )
795     case "$libevent_cv_gc_sections_runs" in
796      yes)
797         CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
798         LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
799         ;;
800     esac
802 AC_SUBST([LIBEVENT_GC_SECTIONS])
804 AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
806 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] )
807 AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile)