1 dnl configure.in for libevent
2 dnl Dug Song <dugsong@monkey.org>
6 AC_CONFIG_MACRO_DIR([m4])
8 AM_INIT_AUTOMAKE(libevent,2.0.10-stable)
9 AM_CONFIG_HEADER(config.h)
10 AC_DEFINE(NUMERIC_VERSION, 0x02000a00, [Numeric representation of the version])
12 dnl Initialize prefix.
13 if test "$prefix" = "NONE"; then
17 dnl Checks for programs.
23 AC_PROG_GCC_TRADITIONAL
25 if test "$GCC" = "yes" ; then
26 # Enable many gcc warnings by default...
27 CFLAGS="$CFLAGS -Wall"
28 # And disable the strict-aliasing optimization, since it breaks
29 # our sockaddr-handling code in strange ways.
30 CFLAGS="$CFLAGS -fno-strict-aliasing"
33 AC_ARG_ENABLE(gcc-warnings,
34 AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
35 AC_ARG_ENABLE(thread-support,
36 AS_HELP_STRING(--disable-thread-support, disable support for threading),
37 [], [enable_thread_support=yes])
38 AC_ARG_ENABLE(malloc-replacement,
39 AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
40 [], [enable_malloc_replacement=yes])
41 AC_ARG_ENABLE(openssl,
42 AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
43 [], [enable_openssl=yes])
44 AC_ARG_ENABLE(debug-mode,
45 AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
46 [], [enable_debug_mode=yes])
50 dnl Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
51 dnl built by default. You can also turn shared libs on and off from
52 dnl the command line with --enable-shared and --disable-shared.
54 AC_SUBST(LIBTOOL_DEPS)
56 dnl Checks for libraries.
57 AC_SEARCH_LIBS([inet_ntoa], [nsl])
58 AC_SEARCH_LIBS([socket], [socket])
59 AC_SEARCH_LIBS([inet_aton], [resolv])
60 AC_SEARCH_LIBS([clock_gettime], [rt])
61 AC_SEARCH_LIBS([sendfile], [sendfile])
63 dnl Determine if we have zlib for regression tests
64 dnl Don't put this one in LIBS
69 AC_SEARCH_LIBS([inflateEnd], [z],
72 AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
75 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
77 dnl See if we have openssl. This doesn't go in LIBS either.
78 if test "$enable_openssl" = "yes"; then
83 AC_SEARCH_LIBS([SSL_new], [ssl],
86 AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])])
88 AC_SUBST(OPENSSL_LIBS)
91 dnl Checks for header files.
93 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)
94 AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
95 #ifdef HAVE_SYS_PARAM_H
96 #include <sys/param.h>
99 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
100 AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
103 #include <sys/queue.h>
107 ], [AC_MSG_RESULT(yes)
108 AC_DEFINE(HAVE_TAILQFOREACH, 1,
109 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
114 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
115 AC_MSG_CHECKING(for timeradd in sys/time.h)
118 #include <sys/time.h>
122 ], [ AC_DEFINE(HAVE_TIMERADD, 1,
123 [Define if timeradd is defined in <sys/time.h>])
124 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
128 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
129 AC_MSG_CHECKING(for timercmp in sys/time.h)
132 #include <sys/time.h>
136 ], [ AC_DEFINE(HAVE_TIMERCMP, 1,
137 [Define if timercmp is defined in <sys/time.h>])
138 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
142 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
143 AC_MSG_CHECKING(for timerclear in sys/time.h)
146 #include <sys/time.h>
150 ], [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
151 [Define if timerclear is defined in <sys/time.h>])
152 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
156 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
157 AC_MSG_CHECKING(for timerisset in sys/time.h)
160 #include <sys/time.h>
164 ], [ AC_DEFINE(HAVE_TIMERISSET, 1,
165 [Define if timerisset is defined in <sys/time.h>])
166 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
170 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
171 AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
172 [[#include <sys/types.h>
173 #include <sys/sysctl.h>]]
177 dnl - check if the macro WIN32 is defined on this compiler.
178 dnl - (this is how we check for a windows version of GCC)
179 AC_MSG_CHECKING(for WIN32)
186 bwin32=true; AC_MSG_RESULT(yes),
187 bwin32=false; AC_MSG_RESULT(no),
190 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
192 if test x$bwin32 = xtrue; then
193 AC_SEARCH_LIBS([getservbyname],[ws2_32])
196 dnl Checks for typedefs, structures, and compiler characteristics.
201 dnl Checks for library functions.
202 AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getservbyname getprotobynumber setenv unsetenv putenv)
204 # Check for gethostbyname_r in all its glorious incompatible versions.
205 # (This is cut-and-pasted from Tor, which based its logic on
206 # Python's configure.in.)
207 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
208 [Define this if you have any gethostbyname_r()])
210 AC_CHECK_FUNC(gethostbyname_r, [
211 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
213 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
214 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([
218 struct hostent *h1, *h2;
220 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
222 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
223 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
224 [Define this if gethostbyname_r takes 6 arguments])
233 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
235 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
236 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
237 [Define this if gethostbyname_r takes 5 arguments])
245 struct hostent_data hd;
246 (void) gethostbyname_r(cp1,h1,&hd);
248 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
249 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
250 [Define this if gethostbyname_r takes 3 arguments])
261 AC_CHECK_SIZEOF(long)
263 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
271 ], [ AC_DEFINE(HAVE_SETFD, 1,
272 [Define if F_SETFD is defined in <fcntl.h>])
273 AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
277 if test x$bwin32 != xtrue; then
278 AC_CHECK_FUNCS(select, [haveselect=yes], )
279 if test "x$haveselect" = "xyes" ; then
283 AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
286 AC_CHECK_FUNCS(poll, [havepoll=yes], )
287 if test "x$havepoll" = "xyes" ; then
290 AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
293 if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
294 AC_DEFINE(HAVE_DEVPOLL, 1,
295 [Define if /dev/poll is available])
297 AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
300 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
301 AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
302 if test "x$havekqueue" = "xyes" ; then
303 AC_MSG_CHECKING(for working kqueue)
305 #include <sys/types.h>
306 #include <sys/time.h>
307 #include <sys/event.h>
313 main(int argc, char **argv)
324 if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
327 while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
330 if ((kq = kqueue()) == -1)
333 memset(&ev, 0, sizeof(ev));
335 ev.filter = EVFILT_WRITE;
336 ev.flags = EV_ADD | EV_ENABLE;
337 n = kevent(kq, &ev, 1, NULL, 0, NULL);
341 read(fd[[0]], buf, sizeof(buf));
345 n = kevent(kq, NULL, 0, &ev, 1, &ts);
346 if (n == -1 || n == 0)
350 }, [AC_MSG_RESULT(yes)
351 AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
352 [Define if kqueue works correctly with pipes])
354 ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
357 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
361 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
362 if test "x$haveepoll" = "xyes" ; then
363 AC_DEFINE(HAVE_EPOLL, 1,
364 [Define if your system supports the epoll system calls])
367 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
368 if test "x$haveepoll" = "xno" ; then
369 AC_MSG_CHECKING(for epoll system call)
372 #include <sys/param.h>
373 #include <sys/types.h>
374 #include <sys/syscall.h>
375 #include <sys/epoll.h>
379 epoll_create(int size)
381 return (syscall(__NR_epoll_create, size));
385 main(int argc, char **argv)
389 epfd = epoll_create(256);
390 exit (epfd == -1 ? 1 : 0);
391 }, [AC_MSG_RESULT(yes)
392 AC_DEFINE(HAVE_EPOLL, 1,
393 [Define if your system supports the epoll system calls])
397 ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
400 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
403 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
404 if test "x$haveeventports" = "xyes" ; then
405 AC_DEFINE(HAVE_EVENT_PORTS, 1,
406 [Define if your system supports event ports])
409 AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
411 if test "x$bwin32" = "xtrue"; then
415 AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
421 AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
422 [#ifdef HAVE_STDINT_H
424 #elif defined(HAVE_INTTYPES_H)
425 #include <inttypes.h>
427 #ifdef HAVE_SYS_TYPES_H
428 #include <sys/types.h>
431 AC_CHECK_TYPES([fd_mask], , ,
432 [#ifdef HAVE_SYS_TYPES_H
433 #include <sys/types.h>
435 #ifdef HAVE_SYS_SELECT_H
436 #include <sys/select.h>
439 AC_CHECK_SIZEOF(long long)
440 AC_CHECK_SIZEOF(long)
442 AC_CHECK_SIZEOF(short)
443 AC_CHECK_SIZEOF(size_t)
444 AC_CHECK_SIZEOF(void *)
446 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo], , ,
448 #include <sys/types.h>
449 #ifdef HAVE_NETINET_IN_H
450 #include <netinet/in.h>
452 #ifdef HAVE_NETINET_IN6_H
453 #include <netinet/in6.h>
455 #ifdef HAVE_SYS_SOCKET_H
456 #include <sys/socket.h>
462 #define WIN32_WINNT 0x400
463 #define _WIN32_WINNT 0x400
464 #define WIN32_LEAN_AND_MEAN
465 #if defined(_MSC_VER) && (_MSC_VER < 1300)
468 #include <winsock2.h>
469 #include <ws2tcpip.h>
473 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], , ,
474 [#include <sys/types.h>
475 #ifdef HAVE_NETINET_IN_H
476 #include <netinet/in.h>
478 #ifdef HAVE_NETINET_IN6_H
479 #include <netinet/in6.h>
481 #ifdef HAVE_SYS_SOCKET_H
482 #include <sys/socket.h>
485 #define WIN32_WINNT 0x400
486 #define _WIN32_WINNT 0x400
487 #define WIN32_LEAN_AND_MEAN
488 #if defined(_MSC_VER) && (_MSC_VER < 1300)
491 #include <winsock2.h>
492 #include <ws2tcpip.h>
497 AC_MSG_CHECKING([for socklen_t])
499 #include <sys/types.h>
500 #include <sys/socket.h>],
502 AC_MSG_RESULT([yes]),
504 AC_DEFINE(socklen_t, unsigned int,
505 [Define to unsigned int if you dont have it])]
508 AC_MSG_CHECKING([whether our compiler supports __func__])
510 [ const char *cp = __func__; ],
511 AC_MSG_RESULT([yes]),
513 AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
515 [ const char *cp = __FUNCTION__; ],
517 AC_DEFINE(__func__, __FUNCTION__,
518 [Define to appropriate substitue if compiler doesnt have __func__]),
520 AC_DEFINE(__func__, __FILE__,
521 [Define to appropriate substitue if compiler doesnt have __func__])))
524 # check if we can compile with pthreads
526 if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
528 AC_DEFINE(HAVE_PTHREADS, 1,
529 [Define if we have pthreads on this system])
531 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
532 AC_CHECK_SIZEOF(pthread_t, ,
533 [AC_INCLUDES_DEFAULT()
534 #include <pthread.h> ]
537 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
539 # check if we should compile locking into the library
540 if test x$enable_thread_support = xno; then
541 AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
542 [Define if libevent should not be compiled with thread support])
545 # check if we should hard-code the mm functions.
546 if test x$enable_malloc_replacement = xno; then
547 AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
548 [Define if libevent should not allow replacing the mm functions])
551 # check if we should hard-code debugging out
552 if test x$enable_debug_mode = xno; then
553 AC_DEFINE(DISABLE_DEBUG_MODE, 1,
554 [Define if libevent should build without support for a debug mode])
557 # check if we have and should use openssl
558 AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
560 # Add some more warnings which we use in development but not in the
561 # released versions. (Some relevant gcc versions can't handle these.)
562 if test x$enable_gcc_warnings = xyes; then
564 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
565 #if !defined(__GNUC__) || (__GNUC__ < 4)
567 #endif]), have_gcc4=yes, have_gcc4=no)
569 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
570 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
572 #endif]), have_gcc42=yes, have_gcc42=no)
574 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [
575 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
577 #endif]), have_gcc45=yes, have_gcc45=no)
579 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"
580 CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
582 if test x$have_gcc4 = xyes ; then
583 # These warnings break gcc 3.3.5 and work on gcc 4.0.2
584 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
585 #CFLAGS="$CFLAGS -Wold-style-definition"
588 if test x$have_gcc42 = xyes ; then
589 # These warnings break gcc 4.0.2 and work on gcc 4.2
590 CFLAGS="$CFLAGS -Waddress -Wnormalized=id -Woverride-init"
593 if test x$have_gcc45 = xyes ; then
594 # These warnings work on gcc 4.5
595 CFLAGS="$CFLAGS -Wlogical-op"
597 ##This will break the world on some 64-bit architectures
598 # CFLAGS="$CFLAGS -Winline"
602 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] )
603 AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile)