libevent: updated to 2.0.22
[tomato.git] / release / src-rt-6.x.4708 / router / libevent / configure.ac
blobd42edd880ea4fcb763c78b4a67e398b42d913f8c
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.59)
10 AC_INIT(event.c)
12 AC_CONFIG_MACRO_DIR([m4])
14 AM_INIT_AUTOMAKE(libevent,2.0.22-stable)
15 AC_CONFIG_HEADERS(config.h)
16 AC_DEFINE(NUMERIC_VERSION, 0x02001600, [Numeric representation of the version])
18 dnl Initialize prefix.
19 if test "$prefix" = "NONE"; then
20    prefix="/usr/local"
23 AC_CANONICAL_BUILD
24 AC_CANONICAL_HOST
25 dnl the 'build' machine is where we run configure and compile
26 dnl the 'host' machine is where the resulting stuff runs.
28 case "$host_os" in
30  osf5*)
31     CFLAGS="$CFLAGS -D_OSF_SOURCE"
32     ;;
33 esac
35 dnl Checks for programs.
36 AC_PROG_CC
37 AM_PROG_CC_C_O
38 AC_PROG_INSTALL
39 AC_PROG_LN_S
40 # AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
42 # AC_PROG_SED is only available in Autoconf >= 2.59b; workaround for older
43 # versions
44 ifdef([AC_PROG_SED], [AC_PROG_SED], [
45 AC_CHECK_PROGS(SED, [gsed sed])
48 AC_PROG_GCC_TRADITIONAL
50 # We need to test for at least gcc 2.95 here, because older versions don't
51 # have -fno-strict-aliasing
52 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
53 #if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
54 #error
55 #endif])], have_gcc295=yes, have_gcc295=no)
57 if test "$GCC" = "yes" ; then
58         # Enable many gcc warnings by default...
59         CFLAGS="$CFLAGS -Wall"
60         # And disable the strict-aliasing optimization, since it breaks
61         # our sockaddr-handling code in strange ways.
62         if test x$have_gcc295 = xyes; then
63                 CFLAGS="$CFLAGS -fno-strict-aliasing"
64         fi
67 # OS X Lion started deprecating the system openssl. Let's just disable
68 # all deprecation warnings on OS X.
69 case "$host_os" in
71  darwin*)
72     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
73     ;;
74 esac
76 AC_ARG_ENABLE(gcc-warnings,
77      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
78 AC_ARG_ENABLE(thread-support,
79      AS_HELP_STRING(--disable-thread-support, disable support for threading),
80         [], [enable_thread_support=yes])
81 AC_ARG_ENABLE(malloc-replacement,
82      AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
83         [], [enable_malloc_replacement=yes])
84 AC_ARG_ENABLE(openssl,
85      AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
86         [], [enable_openssl=yes])
87 AC_ARG_ENABLE(debug-mode,
88      AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
89         [], [enable_debug_mode=yes])
90 AC_ARG_ENABLE([libevent-install],
91      AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
92         [], [enable_libevent_install=yes])
93 AC_ARG_ENABLE([libevent-regress],
94      AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
95         [], [enable_libevent_regress=yes])
96 AC_ARG_ENABLE([function-sections],
97      AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
98         [], [enable_function_sections=no])
101 AC_PROG_LIBTOOL
103 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
104 dnl   built by default.  You can also turn shared libs on and off from
105 dnl   the command line with --enable-shared and --disable-shared.
106 dnl AC_DISABLE_SHARED
107 AC_SUBST(LIBTOOL_DEPS)
109 AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
111 dnl Checks for libraries.
112 AC_SEARCH_LIBS([inet_ntoa], [nsl])
113 AC_SEARCH_LIBS([socket], [socket])
114 AC_SEARCH_LIBS([inet_aton], [resolv])
115 AC_SEARCH_LIBS([clock_gettime], [rt])
116 AC_SEARCH_LIBS([sendfile], [sendfile])
118 dnl - check if the macro WIN32 is defined on this compiler.
119 dnl - (this is how we check for a windows version of GCC)
120 AC_MSG_CHECKING(for WIN32)
121 AC_TRY_COMPILE(,
122         [
123 #ifndef WIN32
124 die horribly
125 #endif
126         ],
127         bwin32=true; AC_MSG_RESULT(yes),
128         bwin32=false; AC_MSG_RESULT(no),
131 dnl - check if the macro __CYGWIN__ is defined on this compiler.
132 dnl - (this is how we check for a cygwin version of GCC)
133 AC_MSG_CHECKING(for CYGWIN)
134 AC_TRY_COMPILE(,
135         [
136 #ifndef __CYGWIN__
137 die horribly
138 #endif
139         ],
140         cygwin=true; AC_MSG_RESULT(yes),
141         cygwin=false; AC_MSG_RESULT(no),
144 AC_CHECK_HEADERS([zlib.h])
146 if test "x$ac_cv_header_zlib_h" = "xyes"; then
147 dnl Determine if we have zlib for regression tests
148 dnl Don't put this one in LIBS
149 save_LIBS="$LIBS"
150 LIBS=""
151 ZLIB_LIBS=""
152 have_zlib=no
153 AC_SEARCH_LIBS([inflateEnd], [z],
154         [have_zlib=yes
155         ZLIB_LIBS="$LIBS"
156         AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
157 LIBS="$save_LIBS"
158 AC_SUBST(ZLIB_LIBS)
160 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
162 dnl See if we have openssl.  This doesn't go in LIBS either.
163 if test "$bwin32" = true; then
164   EV_LIB_WS32=-lws2_32
165   EV_LIB_GDI=-lgdi32
166 else
167   EV_LIB_WS32=
168   EV_LIB_GDI=
170 AC_SUBST(EV_LIB_WS32)
171 AC_SUBST(EV_LIB_GDI)
172 AC_SUBST(OPENSSL_LIBADD)
174 AC_CHECK_HEADERS([openssl/bio.h])
176 if test "$enable_openssl" = "yes"; then
177 save_LIBS="$LIBS"
178 LIBS=""
179 OPENSSL_LIBS=""
180 have_openssl=no
181 AC_SEARCH_LIBS([SSL_new], [ssl],
182         [have_openssl=yes
183         OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
184         AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
185         [have_openssl=no],
186         [-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
187 LIBS="$save_LIBS"
188 AC_SUBST(OPENSSL_LIBS)
191 dnl Checks for header files.
192 AC_HEADER_STDC
193 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])
194 AC_CHECK_HEADERS([sys/stat.h])
195 AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
196 #ifdef HAVE_SYS_PARAM_H
197 #include <sys/param.h>
198 #endif
200 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
201         AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
202         AC_EGREP_CPP(yes,
204 #include <sys/queue.h>
205 #ifdef TAILQ_FOREACH
206  yes
207 #endif
208 ],      [AC_MSG_RESULT(yes)
209          AC_DEFINE(HAVE_TAILQFOREACH, 1,
210                 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
211         AC_MSG_RESULT(no)
212         )
215 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
216         AC_MSG_CHECKING(for timeradd in sys/time.h)
217         AC_EGREP_CPP(yes,
219 #include <sys/time.h>
220 #ifdef timeradd
221  yes
222 #endif
223 ],      [ AC_DEFINE(HAVE_TIMERADD, 1,
224                 [Define if timeradd is defined in <sys/time.h>])
225           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
229 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
230         AC_MSG_CHECKING(for timercmp in sys/time.h)
231         AC_EGREP_CPP(yes,
233 #include <sys/time.h>
234 #ifdef timercmp
235  yes
236 #endif
237 ],      [ AC_DEFINE(HAVE_TIMERCMP, 1,
238                 [Define if timercmp is defined in <sys/time.h>])
239           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
243 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
244         AC_MSG_CHECKING(for timerclear in sys/time.h)
245         AC_EGREP_CPP(yes,
247 #include <sys/time.h>
248 #ifdef timerclear
249  yes
250 #endif
251 ],      [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
252                 [Define if timerclear is defined in <sys/time.h>])
253           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
257 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
258         AC_MSG_CHECKING(for timerisset in sys/time.h)
259         AC_EGREP_CPP(yes,
261 #include <sys/time.h>
262 #ifdef timerisset
263  yes
264 #endif
265 ],      [ AC_DEFINE(HAVE_TIMERISSET, 1,
266                 [Define if timerisset is defined in <sys/time.h>])
267           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
271 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
272         AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
273            [[#include <sys/types.h>
274              #include <sys/sysctl.h>]]
275         )
278 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
279 AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
280 AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue)
282 if test x$bwin32 = xtrue; then
283    AC_SEARCH_LIBS([getservbyname],[ws2_32])
286 dnl Checks for typedefs, structures, and compiler characteristics.
287 AC_C_CONST
288 AC_C_INLINE
289 AC_HEADER_TIME
291 dnl Checks for library functions.
292 AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep])
293 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])
294 AC_CHECK_FUNCS([umask])
296 AC_CACHE_CHECK(
297     [for getaddrinfo],
298     [libevent_cv_getaddrinfo],
299     [AC_LINK_IFELSE(
300         [AC_LANG_PROGRAM(
301             [[
302                 #ifdef HAVE_NETDB_H
303                 #include <netdb.h>
304                 #endif
305             ]],
306             [[
307                 getaddrinfo;
308             ]]
309         )],
310         [libevent_cv_getaddrinfo=yes],
311         [libevent_cv_getaddrinfo=no]
312     )]
314 if test "$libevent_cv_getaddrinfo" = "yes" ; then
315     AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
316 else
318 AC_CHECK_FUNCS([getservbyname])
319 # Check for gethostbyname_r in all its glorious incompatible versions.
320 #   (This is cut-and-pasted from Tor, which based its logic on
321 #   Python's configure.in.)
322 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
323   [Define this if you have any gethostbyname_r()])
325 AC_CHECK_FUNC(gethostbyname_r, [
326   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
327   OLD_CFLAGS=$CFLAGS
328   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
329   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
330 #include <netdb.h>
331   ], [[
332     char *cp1, *cp2;
333     struct hostent *h1, *h2;
334     int i1, i2;
335     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
336   ]])],[
337     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
338     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
339      [Define this if gethostbyname_r takes 6 arguments])
340     AC_MSG_RESULT(6)
341   ], [
342     AC_TRY_COMPILE([
343 #include <netdb.h>
344     ], [
345       char *cp1, *cp2;
346       struct hostent *h1;
347       int i1, i2;
348       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
349     ], [
350       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
351       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
352         [Define this if gethostbyname_r takes 5 arguments])
353       AC_MSG_RESULT(5)
354    ], [
355       AC_TRY_COMPILE([
356 #include <netdb.h>
357      ], [
358        char *cp1;
359        struct hostent *h1;
360        struct hostent_data hd;
361        (void) gethostbyname_r(cp1,h1,&hd);
362      ], [
363        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
364        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
365          [Define this if gethostbyname_r takes 3 arguments])
366        AC_MSG_RESULT(3)
367      ], [
368        AC_MSG_RESULT(0)
369      ])
370   ])
371  ])
372  CFLAGS=$OLD_CFLAGS
377 AC_CHECK_SIZEOF(long)
379 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
380 AC_EGREP_CPP(yes,
382 #define _GNU_SOURCE
383 #include <fcntl.h>
384 #ifdef F_SETFD
386 #endif
387 ],      [ AC_DEFINE(HAVE_SETFD, 1,
388               [Define if F_SETFD is defined in <fcntl.h>])
389           AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
391 needsignal=no
392 haveselect=no
393 if test x$bwin32 != xtrue; then
394     AC_CHECK_FUNCS(select, [haveselect=yes], )
395     if test "x$haveselect" = "xyes" ; then
396         needsignal=yes
397     fi
399 AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
401 havepoll=no
402 AC_CHECK_FUNCS(poll, [havepoll=yes], )
403 if test "x$havepoll" = "xyes" ; then
404         needsignal=yes
406 AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
408 havedevpoll=no
409 if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
410         AC_DEFINE(HAVE_DEVPOLL, 1,
411                     [Define if /dev/poll is available])
413 AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
415 havekqueue=no
416 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
417         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
418         if test "x$havekqueue" = "xyes" ; then
419                 AC_MSG_CHECKING(for working kqueue)
420                 AC_TRY_RUN(
421 #include <sys/types.h>
422 #include <sys/time.h>
423 #include <sys/event.h>
424 #include <stdio.h>
425 #include <unistd.h>
426 #include <fcntl.h>
429 main(int argc, char **argv)
431         int kq;
432         int n;
433         int fd[[2]];
434         struct kevent ev;
435         struct timespec ts;
436         char buf[[8000]];
438         if (pipe(fd) == -1)
439                 exit(1);
440         if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
441                 exit(1);
443         while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
444                 ;
446         if ((kq = kqueue()) == -1)
447                 exit(1);
449         memset(&ev, 0, sizeof(ev));
450         ev.ident = fd[[1]];
451         ev.filter = EVFILT_WRITE;
452         ev.flags = EV_ADD | EV_ENABLE;
453         n = kevent(kq, &ev, 1, NULL, 0, NULL);
454         if (n == -1)
455                 exit(1);
457         read(fd[[0]], buf, sizeof(buf));
459         ts.tv_sec = 0;
460         ts.tv_nsec = 0;
461         n = kevent(kq, NULL, 0, &ev, 1, &ts);
462         if (n == -1 || n == 0)
463                 exit(1);
465         exit(0);
466 }, [AC_MSG_RESULT(yes)
467     AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
468                 [Define if kqueue works correctly with pipes])
469     havekqueue=yes
470     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
471         fi
473 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
475 haveepollsyscall=no
476 haveepoll=no
477 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
478 if test "x$haveepoll" = "xyes" ; then
479         AC_DEFINE(HAVE_EPOLL, 1,
480                 [Define if your system supports the epoll system calls])
481         needsignal=yes
483 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
484         if test "x$haveepoll" = "xno" ; then
485                 AC_MSG_CHECKING(for epoll system call)
486                 AC_TRY_RUN(
487 #include <stdint.h>
488 #include <sys/param.h>
489 #include <sys/types.h>
490 #include <sys/syscall.h>
491 #include <sys/epoll.h>
492 #include <unistd.h>
495 epoll_create(int size)
497         return (syscall(__NR_epoll_create, size));
501 main(int argc, char **argv)
503         int epfd;
505         epfd = epoll_create(256);
506         exit (epfd == -1 ? 1 : 0);
507 }, [AC_MSG_RESULT(yes)
508     AC_DEFINE(HAVE_EPOLL, 1,
509         [Define if your system supports the epoll system calls])
510     needsignal=yes
511     have_epoll=yes
512     AC_LIBOBJ(epoll_sub)
513     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
514         fi
516 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
518 haveeventports=no
519 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
520 if test "x$haveeventports" = "xyes" ; then
521         AC_DEFINE(HAVE_EVENT_PORTS, 1,
522                 [Define if your system supports event ports])
523         needsignal=yes
525 AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
527 if test "x$bwin32" = "xtrue"; then
528         needsignal=yes
531 AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
533 AC_TYPE_PID_T
534 AC_TYPE_SIZE_T
535 AC_TYPE_SSIZE_T
537 AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
538 [#ifdef HAVE_STDINT_H
539 #include <stdint.h>
540 #elif defined(HAVE_INTTYPES_H)
541 #include <inttypes.h>
542 #endif
543 #ifdef HAVE_SYS_TYPES_H
544 #include <sys/types.h>
545 #endif])
547 AC_CHECK_TYPES([fd_mask], , ,
548 [#ifdef HAVE_SYS_TYPES_H
549 #include <sys/types.h>
550 #endif
551 #ifdef HAVE_SYS_SELECT_H
552 #include <sys/select.h>
553 #endif])
555 AC_CHECK_SIZEOF(long long)
556 AC_CHECK_SIZEOF(long)
557 AC_CHECK_SIZEOF(int)
558 AC_CHECK_SIZEOF(short)
559 AC_CHECK_SIZEOF(size_t)
560 AC_CHECK_SIZEOF(void *)
561 AC_CHECK_SIZEOF(off_t)
563 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
564 [#define _GNU_SOURCE
565 #include <sys/types.h>
566 #ifdef HAVE_NETINET_IN_H
567 #include <netinet/in.h>
568 #endif
569 #ifdef HAVE_NETINET_IN6_H
570 #include <netinet/in6.h>
571 #endif
572 #ifdef HAVE_SYS_SOCKET_H
573 #include <sys/socket.h>
574 #endif
575 #ifdef HAVE_NETDB_H
576 #include <netdb.h>
577 #endif
578 #ifdef WIN32
579 #define WIN32_WINNT 0x400
580 #define _WIN32_WINNT 0x400
581 #define WIN32_LEAN_AND_MEAN
582 #if defined(_MSC_VER) && (_MSC_VER < 1300)
583 #include <winsock.h>
584 #else
585 #include <winsock2.h>
586 #include <ws2tcpip.h>
587 #endif
588 #endif
590 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], , ,
591 [#include <sys/types.h>
592 #ifdef HAVE_NETINET_IN_H
593 #include <netinet/in.h>
594 #endif
595 #ifdef HAVE_NETINET_IN6_H
596 #include <netinet/in6.h>
597 #endif
598 #ifdef HAVE_SYS_SOCKET_H
599 #include <sys/socket.h>
600 #endif
601 #ifdef WIN32
602 #define WIN32_WINNT 0x400
603 #define _WIN32_WINNT 0x400
604 #define WIN32_LEAN_AND_MEAN
605 #if defined(_MSC_VER) && (_MSC_VER < 1300)
606 #include <winsock.h>
607 #else
608 #include <winsock2.h>
609 #include <ws2tcpip.h>
610 #endif
611 #endif
614 AC_MSG_CHECKING([for socklen_t])
615 AC_TRY_COMPILE([
616  #include <sys/types.h>
617  #include <sys/socket.h>],
618   [socklen_t x;],
619   AC_MSG_RESULT([yes]),
620   [AC_MSG_RESULT([no])
621   AC_DEFINE(socklen_t, unsigned int,
622         [Define to unsigned int if you dont have it])]
625 AC_MSG_CHECKING([whether our compiler supports __func__])
626 AC_TRY_COMPILE([],
627  [ const char *cp = __func__; ],
628  AC_MSG_RESULT([yes]),
629  AC_MSG_RESULT([no])
630  AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
631  AC_TRY_COMPILE([],
632    [ const char *cp = __FUNCTION__; ],
633    AC_MSG_RESULT([yes])
634    AC_DEFINE(__func__, __FUNCTION__,
635          [Define to appropriate substitue if compiler doesnt have __func__]),
636    AC_MSG_RESULT([no])
637    AC_DEFINE(__func__, __FILE__,
638          [Define to appropriate substitue if compiler doesnt have __func__])))
641 # check if we can compile with pthreads
642 have_pthreads=no
643 if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
644   ACX_PTHREAD([
645         AC_DEFINE(HAVE_PTHREADS, 1,
646                 [Define if we have pthreads on this system])
647         have_pthreads=yes])
648   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
649   AC_CHECK_SIZEOF(pthread_t, ,
650      [AC_INCLUDES_DEFAULT()
651       #include <pthread.h> ]
652   )
654 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
656 # check if we should compile locking into the library
657 if test x$enable_thread_support = xno; then
658    AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
659         [Define if libevent should not be compiled with thread support])
662 # check if we should hard-code the mm functions.
663 if test x$enable_malloc_replacement = xno; then
664   AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
665         [Define if libevent should not allow replacing the mm functions])
668 # check if we should hard-code debugging out
669 if test x$enable_debug_mode = xno; then
670   AC_DEFINE(DISABLE_DEBUG_MODE, 1,
671         [Define if libevent should build without support for a debug mode])
674 # check if we have and should use openssl
675 AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
677 # Add some more warnings which we use in development but not in the
678 # released versions.  (Some relevant gcc versions can't handle these.)
679 if test x$enable_gcc_warnings = xyes && test "$GCC" = "yes"; then
681   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
682 #if !defined(__GNUC__) || (__GNUC__ < 4)
683 #error
684 #endif])], have_gcc4=yes, have_gcc4=no)
686   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
687 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
688 #error
689 #endif])], have_gcc42=yes, have_gcc42=no)
691   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
692 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
693 #error
694 #endif])], have_gcc45=yes, have_gcc45=no)
696   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
697 #if !defined(__clang__)
698 #error
699 #endif])], have_clang=yes, have_clang=no)
701   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"
702   CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
704   if test x$have_gcc4 = xyes ; then
705     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
706     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
707     #CFLAGS="$CFLAGS -Wold-style-definition"
708   fi
710   if test x$have_gcc42 = xyes ; then
711     # These warnings break gcc 4.0.2 and work on gcc 4.2
712     CFLAGS="$CFLAGS -Waddress"
713   fi
715   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
716     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
717     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
718   fi
720   if test x$have_gcc45 = xyes ; then
721     # These warnings work on gcc 4.5
722     CFLAGS="$CFLAGS -Wlogical-op"
723   fi
725   if test x$have_clang = xyes; then
726     # Disable the unused-function warnings, because these trigger
727     # for minheap-internal.h related code.
728     CFLAGS="$CFLAGS -Wno-unused-function"
730     # clang on macosx emits warnigns for each directory specified which
731     # isn't "used" generating a lot of build noise (typically 3 warnings
732     # per file
733     case "$host_os" in
734         darwin*)
735             CFLAGS="$CFLAGS -Qunused-arguments"
736         ;;
737     esac
738   fi
740 ##This will break the world on some 64-bit architectures
741 # CFLAGS="$CFLAGS -Winline"
745 LIBEVENT_GC_SECTIONS=
746 if test "$GCC" = yes && test "$enable_function_sections" = yes ; then
747     AC_CACHE_CHECK(
748         [if linker supports omitting unused code and data],
749         [libevent_cv_gc_sections_runs],
750         [
751             dnl  NetBSD will link but likely not run with --gc-sections
752             dnl  http://bugs.ntp.org/1844
753             dnl  http://gnats.netbsd.org/40401
754             dnl  --gc-sections causes attempt to load as linux elf, with
755             dnl  wrong syscalls in place.  Test a little gauntlet of
756             dnl  simple stdio read code checking for errors, expecting
757             dnl  enough syscall differences that the NetBSD code will
758             dnl  fail even with Linux emulation working as designed.
759             dnl  A shorter test could be refined by someone with access
760             dnl  to a NetBSD host with Linux emulation working.
761             origCFLAGS="$CFLAGS"
762             CFLAGS="$CFLAGS -Wl,--gc-sections"
763             AC_LINK_IFELSE(
764                 [AC_LANG_PROGRAM(
765                     [[
766                         #include <stdlib.h>
767                         #include <stdio.h>
768                     ]],
769                     [[
770                         FILE *  fpC;
771                         char    buf[32];
772                         size_t  cch;
773                         int     read_success_once;
775                         fpC = fopen("conftest.c", "r");
776                         if (NULL == fpC)
777                                 exit(1);
778                         do {
779                                 cch = fread(buf, sizeof(buf), 1, fpC);
780                                 read_success_once |= (0 != cch);
781                         } while (0 != cch);
782                         if (!read_success_once)
783                                 exit(2);
784                         if (!feof(fpC))
785                                 exit(3);
786                         if (0 != fclose(fpC))
787                                 exit(4);
789                         exit(EXIT_SUCCESS);
790                     ]]
791                 )],
792                 [
793                     dnl We have to do this invocation manually so that we can
794                     dnl get the output of conftest.err to make sure it doesn't
795                     dnl mention gc-sections.
796                     if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
797                         libevent_cv_gc_sections_runs=no
798                     else
799                         libevent_cv_gc_sections_runs=no
800                         ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
801                     fi
802                 ],
803                 [libevent_cv_gc_sections_runs=no]
804             )
805             CFLAGS="$origCFLAGS"
806             AS_UNSET([origCFLAGS])
807         ]
808     )
809     case "$libevent_cv_gc_sections_runs" in
810      yes)
811         CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
812         LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
813         ;;
814     esac
816 AC_SUBST([LIBEVENT_GC_SECTIONS])
818 AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
820 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] )
821 AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile)