xref: /freebsd/contrib/ntp/sntp/libevent/configure.ac (revision a466cc55)
12b15cb3dSCy Schubertdnl Copyright 2000-2007 Niels Provos
22b15cb3dSCy Schubertdnl Copyright 2007-2012 Niels Provos and Nick Mathewson
32b15cb3dSCy Schubertdnl
42b15cb3dSCy Schubertdnl See LICENSE for copying information.
52b15cb3dSCy Schubertdnl
62b15cb3dSCy Schubertdnl Original version Dug Song <dugsong@monkey.org>
72b15cb3dSCy Schubert
8*a466cc55SCy SchubertAC_INIT(libevent,2.1.12-stable)
9*a466cc55SCy SchubertAC_PREREQ(2.67)
102b15cb3dSCy SchubertAC_CONFIG_SRCDIR(event.c)
112b15cb3dSCy Schubert
122b15cb3dSCy SchubertAC_CONFIG_MACRO_DIR([m4])
132b15cb3dSCy SchubertAC_CONFIG_AUX_DIR([build-aux])
142b15cb3dSCy SchubertAM_INIT_AUTOMAKE
152b15cb3dSCy Schubertdnl AM_SILENT_RULES req. automake 1.11.  [no] defaults V=1
16*a466cc55SCy SchubertAM_SILENT_RULES([yes])
172b15cb3dSCy SchubertAC_CONFIG_HEADERS(config.h  evconfig-private.h:evconfig-private.h.in)
18*a466cc55SCy SchubertAC_DEFINE(NUMERIC_VERSION, 0x02010c00, [Numeric representation of the version])
192b15cb3dSCy Schubert
202b15cb3dSCy Schubertdnl Initialize prefix.
21*a466cc55SCy SchubertAC_PREFIX_DEFAULT([/usr/local])
222b15cb3dSCy Schubert
232b15cb3dSCy Schubertdnl Try and get a full POSIX environment on obscure systems
242b15cb3dSCy SchubertAC_USE_SYSTEM_EXTENSIONS
252b15cb3dSCy Schubert
262b15cb3dSCy SchubertAC_CANONICAL_BUILD
272b15cb3dSCy SchubertAC_CANONICAL_HOST
282b15cb3dSCy Schubertdnl the 'build' machine is where we run configure and compile
292b15cb3dSCy Schubertdnl the 'host' machine is where the resulting stuff runs.
302b15cb3dSCy Schubert
312b15cb3dSCy Schubert#case "$host_os" in
322b15cb3dSCy Schubert#
332b15cb3dSCy Schubert# osf5*)
342b15cb3dSCy Schubert#    CFLAGS="$CFLAGS -D_OSF_SOURCE"
352b15cb3dSCy Schubert#    ;;
362b15cb3dSCy Schubert#esac
372b15cb3dSCy Schubert
382b15cb3dSCy Schubertdnl Checks for programs.
392b15cb3dSCy SchubertAM_PROG_CC_C_O
402b15cb3dSCy SchubertAC_PROG_INSTALL
412b15cb3dSCy SchubertAC_PROG_LN_S
422b15cb3dSCy Schubert# AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
432b15cb3dSCy Schubert
44*a466cc55SCy SchubertAC_PROG_SED
452b15cb3dSCy Schubert
462b15cb3dSCy SchubertAC_PROG_GCC_TRADITIONAL
472b15cb3dSCy Schubert
482b15cb3dSCy Schubert# We need to test for at least gcc 2.95 here, because older versions don't
492b15cb3dSCy Schubert# have -fno-strict-aliasing
502b15cb3dSCy SchubertAC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
512b15cb3dSCy Schubert#if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
522b15cb3dSCy Schubert#error
532b15cb3dSCy Schubert#endif])], have_gcc295=yes, have_gcc295=no)
542b15cb3dSCy Schubert
552b15cb3dSCy Schubertif test "$GCC" = "yes" ; then
562b15cb3dSCy Schubert        # Enable many gcc warnings by default...
572b15cb3dSCy Schubert        CFLAGS="$CFLAGS -Wall"
582b15cb3dSCy Schubert	# And disable the strict-aliasing optimization, since it breaks
592b15cb3dSCy Schubert	# our sockaddr-handling code in strange ways.
602b15cb3dSCy Schubert	if test x$have_gcc295 = xyes; then
612b15cb3dSCy Schubert		CFLAGS="$CFLAGS -fno-strict-aliasing"
622b15cb3dSCy Schubert	fi
632b15cb3dSCy Schubertfi
642b15cb3dSCy Schubert
652b15cb3dSCy Schubert# OS X Lion started deprecating the system openssl. Let's just disable
66*a466cc55SCy Schubert# all deprecation warnings on OS X; but do so only for gcc...
67*a466cc55SCy Schubertif test "$GCC" = "yes" ; then
682b15cb3dSCy Schubert	case "$host_os" in
692b15cb3dSCy Schubert	 darwin*)
702b15cb3dSCy Schubert	    CFLAGS="$CFLAGS -Wno-deprecated-declarations"
712b15cb3dSCy Schubert	    ;;
722b15cb3dSCy Schubert	esac
73*a466cc55SCy Schubertfi
742b15cb3dSCy Schubert
752b15cb3dSCy SchubertAC_ARG_ENABLE(gcc-warnings,
762b15cb3dSCy Schubert     AS_HELP_STRING(--disable-gcc-warnings, disable verbose warnings with GCC))
772b15cb3dSCy Schubert
782b15cb3dSCy SchubertAC_ARG_ENABLE(gcc-hardening,
792b15cb3dSCy Schubert     AS_HELP_STRING(--enable-gcc-hardening, enable compiler security checks),
802b15cb3dSCy Schubert[if test x$enableval = xyes; then
812b15cb3dSCy Schubert    CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector-all"
822b15cb3dSCy Schubert    CFLAGS="$CFLAGS -fwrapv -fPIE -Wstack-protector"
832b15cb3dSCy Schubert    CFLAGS="$CFLAGS --param ssp-buffer-size=1"
842b15cb3dSCy Schubertfi])
852b15cb3dSCy Schubert
862b15cb3dSCy SchubertAC_ARG_ENABLE(thread-support,
872b15cb3dSCy Schubert     AS_HELP_STRING(--disable-thread-support, disable support for threading),
882b15cb3dSCy Schubert	[], [enable_thread_support=yes])
892b15cb3dSCy SchubertAC_ARG_ENABLE(malloc-replacement,
902b15cb3dSCy Schubert     AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
912b15cb3dSCy Schubert        [], [enable_malloc_replacement=yes])
922b15cb3dSCy SchubertAC_ARG_ENABLE(openssl,
932b15cb3dSCy Schubert     AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
942b15cb3dSCy Schubert        [], [enable_openssl=yes])
952b15cb3dSCy SchubertAC_ARG_ENABLE(debug-mode,
962b15cb3dSCy Schubert     AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
972b15cb3dSCy Schubert        [], [enable_debug_mode=yes])
982b15cb3dSCy SchubertAC_ARG_ENABLE([libevent-install],
992b15cb3dSCy Schubert     AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
1002b15cb3dSCy Schubert	[], [enable_libevent_install=yes])
1012b15cb3dSCy SchubertAC_ARG_ENABLE([libevent-regress],
1022b15cb3dSCy Schubert     AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
1032b15cb3dSCy Schubert	[], [enable_libevent_regress=yes])
104a25439b6SCy SchubertAC_ARG_ENABLE([samples],
105a25439b6SCy Schubert     AS_HELP_STRING([--disable-samples, skip building of sample programs]),
106a25439b6SCy Schubert	[], [enable_samples=yes])
1072b15cb3dSCy SchubertAC_ARG_ENABLE([function-sections],
1082b15cb3dSCy Schubert     AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
1092b15cb3dSCy Schubert	[], [enable_function_sections=no])
1102b15cb3dSCy SchubertAC_ARG_ENABLE([verbose-debug],
1112b15cb3dSCy Schubert		AS_HELP_STRING([--enable-verbose-debug, verbose debug logging]),
1122b15cb3dSCy Schubert	[], [enable_verbose_debug=no])
113*a466cc55SCy SchubertAC_ARG_ENABLE([clock-gettime],
114*a466cc55SCy Schubert     AS_HELP_STRING(--disable-clock-gettime, do not use clock_gettime even if it is available),
115*a466cc55SCy Schubert  [], [enable_clock_gettime=yes])
1162b15cb3dSCy Schubert
1172b15cb3dSCy Schubert
118*a466cc55SCy SchubertLT_PREREQ([2.4.2])
119*a466cc55SCy SchubertLT_INIT
1202b15cb3dSCy Schubert
1212b15cb3dSCy Schubertdnl   Uncomment "AC_DISABLE_SHARED" to make shared libraries not get
1222b15cb3dSCy Schubertdnl   built by default.  You can also turn shared libs on and off from
1232b15cb3dSCy Schubertdnl   the command line with --enable-shared and --disable-shared.
1242b15cb3dSCy Schubertdnl AC_DISABLE_SHARED
1252b15cb3dSCy SchubertAC_SUBST(LIBTOOL_DEPS)
1262b15cb3dSCy Schubert
127a25439b6SCy SchubertAM_CONDITIONAL([BUILD_SAMPLES], [test "$enable_samples" = "yes"])
1282b15cb3dSCy SchubertAM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
1292b15cb3dSCy Schubert
1302b15cb3dSCy Schubertdnl Checks for libraries.
1312b15cb3dSCy SchubertAC_SEARCH_LIBS([inet_ntoa], [nsl])
1322b15cb3dSCy SchubertAC_SEARCH_LIBS([socket], [socket])
1332b15cb3dSCy SchubertAC_SEARCH_LIBS([inet_aton], [resolv])
134*a466cc55SCy Schubertif test "x$enable_clock_gettime" = "xyes"; then
1352b15cb3dSCy Schubert  AC_SEARCH_LIBS([clock_gettime], [rt])
136*a466cc55SCy Schubert  AC_CHECK_FUNCS([clock_gettime])
137*a466cc55SCy Schubertfi
1382b15cb3dSCy SchubertAC_SEARCH_LIBS([sendfile], [sendfile])
1392b15cb3dSCy Schubert
1402b15cb3dSCy Schubertdnl - check if the macro _WIN32 is defined on this compiler.
1412b15cb3dSCy Schubertdnl - (this is how we check for a windows compiler)
1422b15cb3dSCy SchubertAC_MSG_CHECKING(for WIN32)
143*a466cc55SCy SchubertAC_COMPILE_IFELSE(
144*a466cc55SCy Schubert  [AC_LANG_PROGRAM([],
1452b15cb3dSCy Schubert    [
1462b15cb3dSCy Schubert#ifndef _WIN32
1472b15cb3dSCy Schubertdie horribly
1482b15cb3dSCy Schubert#endif
149*a466cc55SCy Schubert    ]
150*a466cc55SCy Schubert  )],
151*a466cc55SCy Schubert	[bwin32=true; AC_MSG_RESULT(yes)],
152*a466cc55SCy Schubert	[bwin32=false; AC_MSG_RESULT(no)]
153*a466cc55SCy Schubert)
154*a466cc55SCy Schubert
155*a466cc55SCy Schubertdnl - check if the macro __midipix__ is defined on this compiler.
156*a466cc55SCy Schubertdnl - (this is how we check for a midipix version of GCC)
157*a466cc55SCy SchubertAC_MSG_CHECKING(for MIDIPIX)
158*a466cc55SCy SchubertAC_COMPILE_IFELSE(
159*a466cc55SCy Schubert  [AC_LANG_PROGRAM([],
160*a466cc55SCy Schubert    [
161*a466cc55SCy Schubert#ifndef __midipix__
162*a466cc55SCy Schubertdie horribly
163*a466cc55SCy Schubert#endif
164*a466cc55SCy Schubert    ]
165*a466cc55SCy Schubert  )],
166*a466cc55SCy Schubert	[midipix=true; AC_MSG_RESULT(yes)],
167*a466cc55SCy Schubert	[midipix=false; AC_MSG_RESULT(no)]
1682b15cb3dSCy Schubert)
1692b15cb3dSCy Schubert
1702b15cb3dSCy Schubertdnl - check if the macro __CYGWIN__ is defined on this compiler.
1712b15cb3dSCy Schubertdnl - (this is how we check for a cygwin version of GCC)
1722b15cb3dSCy SchubertAC_MSG_CHECKING(for CYGWIN)
173*a466cc55SCy SchubertAC_COMPILE_IFELSE(
174*a466cc55SCy Schubert  [AC_LANG_PROGRAM([],
1752b15cb3dSCy Schubert    [
1762b15cb3dSCy Schubert#ifndef __CYGWIN__
1772b15cb3dSCy Schubertdie horribly
1782b15cb3dSCy Schubert#endif
179*a466cc55SCy Schubert    ]
180*a466cc55SCy Schubert  )],
181*a466cc55SCy Schubert	[cygwin=true; AC_MSG_RESULT(yes)],
182*a466cc55SCy Schubert	[cygwin=false; AC_MSG_RESULT(no)]
1832b15cb3dSCy Schubert)
1842b15cb3dSCy Schubert
1852b15cb3dSCy SchubertAC_CHECK_HEADERS([zlib.h])
1862b15cb3dSCy Schubert
1872b15cb3dSCy Schubertif test "x$ac_cv_header_zlib_h" = "xyes"; then
1882b15cb3dSCy Schubertdnl Determine if we have zlib for regression tests
1892b15cb3dSCy Schubertdnl Don't put this one in LIBS
1902b15cb3dSCy Schubertsave_LIBS="$LIBS"
1912b15cb3dSCy SchubertLIBS=""
1922b15cb3dSCy SchubertZLIB_LIBS=""
1932b15cb3dSCy Schuberthave_zlib=no
1942b15cb3dSCy SchubertAC_SEARCH_LIBS([inflateEnd], [z],
1952b15cb3dSCy Schubert	[have_zlib=yes
1962b15cb3dSCy Schubert	ZLIB_LIBS="$LIBS"
1972b15cb3dSCy Schubert	AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
1982b15cb3dSCy SchubertLIBS="$save_LIBS"
1992b15cb3dSCy SchubertAC_SUBST(ZLIB_LIBS)
2002b15cb3dSCy Schubertfi
2012b15cb3dSCy SchubertAM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
2022b15cb3dSCy Schubert
2032b15cb3dSCy Schubertdnl See if we have openssl.  This doesn't go in LIBS either.
2042b15cb3dSCy Schubertif test "$bwin32" = true; then
2052b15cb3dSCy Schubert  EV_LIB_WS32=-lws2_32
2062b15cb3dSCy Schubert  EV_LIB_GDI=-lgdi32
2072b15cb3dSCy Schubertelse
2082b15cb3dSCy Schubert  EV_LIB_WS32=
2092b15cb3dSCy Schubert  EV_LIB_GDI=
2102b15cb3dSCy Schubertfi
2112b15cb3dSCy SchubertAC_SUBST(EV_LIB_WS32)
2122b15cb3dSCy SchubertAC_SUBST(EV_LIB_GDI)
2132b15cb3dSCy SchubertAC_SUBST(OPENSSL_LIBADD)
2142b15cb3dSCy Schubert
2152b15cb3dSCy SchubertAC_SYS_LARGEFILE
2162b15cb3dSCy Schubert
2172b15cb3dSCy SchubertLIBEVENT_OPENSSL
2182b15cb3dSCy Schubert
2192b15cb3dSCy Schubertdnl Checks for header files.
2202b15cb3dSCy SchubertAC_CHECK_HEADERS([ \
2212b15cb3dSCy Schubert  arpa/inet.h \
2222b15cb3dSCy Schubert  fcntl.h \
2232b15cb3dSCy Schubert  ifaddrs.h \
2242b15cb3dSCy Schubert  mach/mach_time.h \
225*a466cc55SCy Schubert  mach/mach.h \
2262b15cb3dSCy Schubert  netdb.h \
2272b15cb3dSCy Schubert  netinet/in.h \
2282b15cb3dSCy Schubert  netinet/in6.h \
2292b15cb3dSCy Schubert  netinet/tcp.h \
230*a466cc55SCy Schubert  sys/un.h \
2312b15cb3dSCy Schubert  poll.h \
2322b15cb3dSCy Schubert  port.h \
2332b15cb3dSCy Schubert  stdarg.h \
2342b15cb3dSCy Schubert  stddef.h \
2352b15cb3dSCy Schubert  sys/devpoll.h \
2362b15cb3dSCy Schubert  sys/epoll.h \
2372b15cb3dSCy Schubert  sys/event.h \
2382b15cb3dSCy Schubert  sys/eventfd.h \
2392b15cb3dSCy Schubert  sys/ioctl.h \
2402b15cb3dSCy Schubert  sys/mman.h \
2412b15cb3dSCy Schubert  sys/param.h \
2422b15cb3dSCy Schubert  sys/queue.h \
2432b15cb3dSCy Schubert  sys/resource.h \
2442b15cb3dSCy Schubert  sys/select.h \
2452b15cb3dSCy Schubert  sys/sendfile.h \
2462b15cb3dSCy Schubert  sys/socket.h \
2472b15cb3dSCy Schubert  sys/stat.h \
2482b15cb3dSCy Schubert  sys/time.h \
2492b15cb3dSCy Schubert  sys/timerfd.h \
2502b15cb3dSCy Schubert  sys/uio.h \
2512b15cb3dSCy Schubert  sys/wait.h \
252*a466cc55SCy Schubert  sys/random.h \
253*a466cc55SCy Schubert  errno.h \
254*a466cc55SCy Schubert  afunix.h \
2552b15cb3dSCy Schubert])
2562b15cb3dSCy Schubert
257*a466cc55SCy Schubertcase "${host_os}" in
258*a466cc55SCy Schubert    linux*) ;;
259*a466cc55SCy Schubert    *)
2602b15cb3dSCy Schubert        AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
2612b15cb3dSCy Schubert        #ifdef HAVE_SYS_PARAM_H
2622b15cb3dSCy Schubert        #include <sys/param.h>
2632b15cb3dSCy Schubert        #endif
2642b15cb3dSCy Schubert        ])
265*a466cc55SCy Schubertesac
266*a466cc55SCy Schubert
2672b15cb3dSCy Schubertif test "x$ac_cv_header_sys_queue_h" = "xyes"; then
2682b15cb3dSCy Schubert	AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
2692b15cb3dSCy Schubert	AC_EGREP_CPP(yes,
2702b15cb3dSCy Schubert[
2712b15cb3dSCy Schubert#include <sys/queue.h>
2722b15cb3dSCy Schubert#ifdef TAILQ_FOREACH
2732b15cb3dSCy Schubert yes
2742b15cb3dSCy Schubert#endif
2752b15cb3dSCy Schubert],	[AC_MSG_RESULT(yes)
2762b15cb3dSCy Schubert	 AC_DEFINE(HAVE_TAILQFOREACH, 1,
2772b15cb3dSCy Schubert		[Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
2782b15cb3dSCy Schubert	AC_MSG_RESULT(no)
2792b15cb3dSCy Schubert	)
2802b15cb3dSCy Schubertfi
2812b15cb3dSCy Schubert
2822b15cb3dSCy Schubertif test "x$ac_cv_header_sys_time_h" = "xyes"; then
2832b15cb3dSCy Schubert	AC_MSG_CHECKING(for timeradd in sys/time.h)
2842b15cb3dSCy Schubert	AC_EGREP_CPP(yes,
2852b15cb3dSCy Schubert[
2862b15cb3dSCy Schubert#include <sys/time.h>
2872b15cb3dSCy Schubert#ifdef timeradd
2882b15cb3dSCy Schubert yes
2892b15cb3dSCy Schubert#endif
2902b15cb3dSCy Schubert],	[ AC_DEFINE(HAVE_TIMERADD, 1,
2912b15cb3dSCy Schubert		[Define if timeradd is defined in <sys/time.h>])
2922b15cb3dSCy Schubert	  AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
2932b15cb3dSCy Schubert)
2942b15cb3dSCy Schubertfi
2952b15cb3dSCy Schubert
2962b15cb3dSCy Schubertif test "x$ac_cv_header_sys_time_h" = "xyes"; then
2972b15cb3dSCy Schubert	AC_MSG_CHECKING(for timercmp in sys/time.h)
2982b15cb3dSCy Schubert	AC_EGREP_CPP(yes,
2992b15cb3dSCy Schubert[
3002b15cb3dSCy Schubert#include <sys/time.h>
3012b15cb3dSCy Schubert#ifdef timercmp
3022b15cb3dSCy Schubert yes
3032b15cb3dSCy Schubert#endif
3042b15cb3dSCy Schubert],	[ AC_DEFINE(HAVE_TIMERCMP, 1,
3052b15cb3dSCy Schubert		[Define if timercmp is defined in <sys/time.h>])
3062b15cb3dSCy Schubert	  AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
3072b15cb3dSCy Schubert)
3082b15cb3dSCy Schubertfi
3092b15cb3dSCy Schubert
3102b15cb3dSCy Schubertif test "x$ac_cv_header_sys_time_h" = "xyes"; then
3112b15cb3dSCy Schubert	AC_MSG_CHECKING(for timerclear in sys/time.h)
3122b15cb3dSCy Schubert	AC_EGREP_CPP(yes,
3132b15cb3dSCy Schubert[
3142b15cb3dSCy Schubert#include <sys/time.h>
3152b15cb3dSCy Schubert#ifdef timerclear
3162b15cb3dSCy Schubert yes
3172b15cb3dSCy Schubert#endif
3182b15cb3dSCy Schubert],	[ AC_DEFINE(HAVE_TIMERCLEAR, 1,
3192b15cb3dSCy Schubert		[Define if timerclear is defined in <sys/time.h>])
3202b15cb3dSCy Schubert	  AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
3212b15cb3dSCy Schubert)
3222b15cb3dSCy Schubertfi
3232b15cb3dSCy Schubert
3242b15cb3dSCy Schubertif test "x$ac_cv_header_sys_time_h" = "xyes"; then
3252b15cb3dSCy Schubert	AC_MSG_CHECKING(for timerisset in sys/time.h)
3262b15cb3dSCy Schubert	AC_EGREP_CPP(yes,
3272b15cb3dSCy Schubert[
3282b15cb3dSCy Schubert#include <sys/time.h>
3292b15cb3dSCy Schubert#ifdef timerisset
3302b15cb3dSCy Schubert yes
3312b15cb3dSCy Schubert#endif
3322b15cb3dSCy Schubert],	[ AC_DEFINE(HAVE_TIMERISSET, 1,
3332b15cb3dSCy Schubert		[Define if timerisset is defined in <sys/time.h>])
3342b15cb3dSCy Schubert	  AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
3352b15cb3dSCy Schubert)
3362b15cb3dSCy Schubertfi
3372b15cb3dSCy Schubert
3382b15cb3dSCy Schubertif test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
339*a466cc55SCy Schubert	AC_CHECK_DECLS([CTL_KERN, KERN_ARND], [], [],
3402b15cb3dSCy Schubert	   [[#include <sys/types.h>
3412b15cb3dSCy Schubert	     #include <sys/sysctl.h>]]
3422b15cb3dSCy Schubert	)
3432b15cb3dSCy Schubertfi
3442b15cb3dSCy Schubert
3452b15cb3dSCy SchubertAM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
3462b15cb3dSCy SchubertAM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
347*a466cc55SCy SchubertAM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue)
348*a466cc55SCy SchubertAM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue)
3492b15cb3dSCy Schubert
3502b15cb3dSCy Schubertif test x$bwin32 = xtrue; then
351*a466cc55SCy Schubert  AC_HAVE_LIBRARY([ws2_32])
3522b15cb3dSCy Schubertfi
3532b15cb3dSCy Schubert
3542b15cb3dSCy Schubertdnl Checks for typedefs, structures, and compiler characteristics.
3552b15cb3dSCy SchubertAC_C_CONST
3562b15cb3dSCy SchubertAC_C_INLINE
3572b15cb3dSCy SchubertAC_HEADER_TIME
3582b15cb3dSCy Schubert
3592b15cb3dSCy Schubertdnl Checks for library functions.
3602b15cb3dSCy SchubertAC_CHECK_FUNCS([ \
3612b15cb3dSCy Schubert  accept4 \
3622b15cb3dSCy Schubert  arc4random \
3632b15cb3dSCy Schubert  arc4random_buf \
364*a466cc55SCy Schubert  arc4random_addrandom \
3652b15cb3dSCy Schubert  eventfd \
3662b15cb3dSCy Schubert  epoll_create1 \
3672b15cb3dSCy Schubert  fcntl \
3682b15cb3dSCy Schubert  getegid \
3692b15cb3dSCy Schubert  geteuid \
3702b15cb3dSCy Schubert  getifaddrs \
3712b15cb3dSCy Schubert  gettimeofday \
3722b15cb3dSCy Schubert  issetugid \
3732b15cb3dSCy Schubert  mach_absolute_time \
3742b15cb3dSCy Schubert  mmap \
3752b15cb3dSCy Schubert  nanosleep \
3762b15cb3dSCy Schubert  pipe \
3772b15cb3dSCy Schubert  pipe2 \
3782b15cb3dSCy Schubert  putenv \
3792b15cb3dSCy Schubert  sendfile \
3802b15cb3dSCy Schubert  setenv \
3812b15cb3dSCy Schubert  setrlimit \
3822b15cb3dSCy Schubert  sigaction \
3832b15cb3dSCy Schubert  signal \
3842b15cb3dSCy Schubert  splice \
3852b15cb3dSCy Schubert  strlcpy \
3862b15cb3dSCy Schubert  strsep \
3872b15cb3dSCy Schubert  strtok_r \
3882b15cb3dSCy Schubert  strtoll \
3892b15cb3dSCy Schubert  sysctl \
3902b15cb3dSCy Schubert  timerfd_create \
3912b15cb3dSCy Schubert  umask \
3922b15cb3dSCy Schubert  unsetenv \
3932b15cb3dSCy Schubert  usleep \
3942b15cb3dSCy Schubert  vasprintf \
395*a466cc55SCy Schubert  getrandom \
3962b15cb3dSCy Schubert])
397*a466cc55SCy Schubert
398*a466cc55SCy SchubertAS_IF([test x$bwin32 = xtrue],
399*a466cc55SCy Schubert  AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)])
400*a466cc55SCy Schubert)
401*a466cc55SCy Schubert
4022b15cb3dSCy SchubertAM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
4032b15cb3dSCy Schubert
404*a466cc55SCy Schubertm4_define([funcstochk],
405*a466cc55SCy Schubert  [getnameinfo
406*a466cc55SCy Schubert  getprotobynumber
407*a466cc55SCy Schubert  getservbyname
408*a466cc55SCy Schubert  inet_ntop
409*a466cc55SCy Schubert  inet_pton]
410*a466cc55SCy Schubert)
411*a466cc55SCy Schubert
412*a466cc55SCy SchubertAS_IF([test x$bwin32 = xtrue],
413*a466cc55SCy Schubert  [AX_CHECK_DECLS_EX([funcstochk getaddrinfo],
414*a466cc55SCy Schubert    [#ifdef _WIN32
415*a466cc55SCy Schubert    #include <winsock2.h>
416*a466cc55SCy Schubert    #include <ws2tcpip.h>
417*a466cc55SCy Schubert    #endif])],
418*a466cc55SCy Schubert  [AC_CHECK_FUNCS(m4_normalize(funcstochk))]
419*a466cc55SCy Schubert)
420*a466cc55SCy Schubert
421*a466cc55SCy Schubertm4_undefine([funcstochk])
422*a466cc55SCy Schubert
423*a466cc55SCy Schubertdnl check getaddrinfo and gethostbyname_r for non-windows
424*a466cc55SCy SchubertAS_IF([test x$bwin32 = xfalse], [
4252b15cb3dSCy SchubertAC_CACHE_CHECK(
4262b15cb3dSCy Schubert    [for getaddrinfo],
4272b15cb3dSCy Schubert    [libevent_cv_getaddrinfo],
4282b15cb3dSCy Schubert    [AC_LINK_IFELSE(
4292b15cb3dSCy Schubert	[AC_LANG_PROGRAM(
4302b15cb3dSCy Schubert	    [[
4312b15cb3dSCy Schubert		#ifdef HAVE_NETDB_H
4322b15cb3dSCy Schubert		#include <netdb.h>
4332b15cb3dSCy Schubert		#endif
4342b15cb3dSCy Schubert	    ]],
4352b15cb3dSCy Schubert	    [[
4362b15cb3dSCy Schubert		getaddrinfo;
4372b15cb3dSCy Schubert	    ]]
4382b15cb3dSCy Schubert	)],
4392b15cb3dSCy Schubert	[libevent_cv_getaddrinfo=yes],
4402b15cb3dSCy Schubert	[libevent_cv_getaddrinfo=no]
4412b15cb3dSCy Schubert    )]
4422b15cb3dSCy Schubert)
4432b15cb3dSCy Schubertif test "$libevent_cv_getaddrinfo" = "yes" ; then
4442b15cb3dSCy Schubert    AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
4452b15cb3dSCy Schubertelse
4462b15cb3dSCy Schubert
4472b15cb3dSCy Schubert# Check for gethostbyname_r in all its glorious incompatible versions.
4482b15cb3dSCy Schubert#   (This is cut-and-pasted from Tor, which based its logic on
4492b15cb3dSCy Schubert#   Python's configure.in.)
4502b15cb3dSCy SchubertAH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
4512b15cb3dSCy Schubert  [Define this if you have any gethostbyname_r()])
4522b15cb3dSCy Schubert
4532b15cb3dSCy SchubertAC_CHECK_FUNC(gethostbyname_r, [
4542b15cb3dSCy Schubert  AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
4552b15cb3dSCy Schubert  OLD_CFLAGS=$CFLAGS
4562b15cb3dSCy Schubert  CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
4572b15cb3dSCy Schubert  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
4582b15cb3dSCy Schubert#include <netdb.h>
4592b15cb3dSCy Schubert  ], [[
4602b15cb3dSCy Schubert    char *cp1, *cp2;
4612b15cb3dSCy Schubert    struct hostent *h1, *h2;
4622b15cb3dSCy Schubert    int i1, i2;
4632b15cb3dSCy Schubert    (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
4642b15cb3dSCy Schubert  ]])],[
4652b15cb3dSCy Schubert    AC_DEFINE(HAVE_GETHOSTBYNAME_R)
4662b15cb3dSCy Schubert    AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
4672b15cb3dSCy Schubert     [Define this if gethostbyname_r takes 6 arguments])
4682b15cb3dSCy Schubert    AC_MSG_RESULT(6)
4692b15cb3dSCy Schubert  ], [
470*a466cc55SCy Schubert    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
4712b15cb3dSCy Schubert#include <netdb.h>
4722b15cb3dSCy Schubert    ], [
4732b15cb3dSCy Schubert      char *cp1, *cp2;
4742b15cb3dSCy Schubert      struct hostent *h1;
4752b15cb3dSCy Schubert      int i1, i2;
4762b15cb3dSCy Schubert      (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
477*a466cc55SCy Schubert    ])], [
4782b15cb3dSCy Schubert      AC_DEFINE(HAVE_GETHOSTBYNAME_R)
4792b15cb3dSCy Schubert      AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
4802b15cb3dSCy Schubert        [Define this if gethostbyname_r takes 5 arguments])
4812b15cb3dSCy Schubert      AC_MSG_RESULT(5)
4822b15cb3dSCy Schubert    ], [
483*a466cc55SCy Schubert      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
4842b15cb3dSCy Schubert#include <netdb.h>
4852b15cb3dSCy Schubert     ], [
4862b15cb3dSCy Schubert       char *cp1;
4872b15cb3dSCy Schubert       struct hostent *h1;
4882b15cb3dSCy Schubert       struct hostent_data hd;
4892b15cb3dSCy Schubert       (void) gethostbyname_r(cp1,h1,&hd);
490*a466cc55SCy Schubert     ])], [
4912b15cb3dSCy Schubert       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
4922b15cb3dSCy Schubert       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
4932b15cb3dSCy Schubert         [Define this if gethostbyname_r takes 3 arguments])
4942b15cb3dSCy Schubert       AC_MSG_RESULT(3)
4952b15cb3dSCy Schubert     ], [
4962b15cb3dSCy Schubert       AC_MSG_RESULT(0)
4972b15cb3dSCy Schubert     ])
4982b15cb3dSCy Schubert  ])
4992b15cb3dSCy Schubert ])
5002b15cb3dSCy Schubert CFLAGS=$OLD_CFLAGS
5012b15cb3dSCy Schubert])
5022b15cb3dSCy Schubert
5032b15cb3dSCy Schubertfi
504*a466cc55SCy Schubert]) dnl end of checking getaddrinfo and gethostbyname_r
5052b15cb3dSCy Schubert
5062b15cb3dSCy SchubertAC_MSG_CHECKING(for F_SETFD in fcntl.h)
5072b15cb3dSCy SchubertAC_EGREP_CPP(yes,
5082b15cb3dSCy Schubert[
509*a466cc55SCy Schubert#define _GNU_SOURCE 1
5102b15cb3dSCy Schubert#include <fcntl.h>
5112b15cb3dSCy Schubert#ifdef F_SETFD
5122b15cb3dSCy Schubertyes
5132b15cb3dSCy Schubert#endif
5142b15cb3dSCy Schubert],	[ AC_DEFINE(HAVE_SETFD, 1,
5152b15cb3dSCy Schubert	      [Define if F_SETFD is defined in <fcntl.h>])
5162b15cb3dSCy Schubert	  AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
5172b15cb3dSCy Schubert
5182b15cb3dSCy Schubertneedsignal=no
5192b15cb3dSCy Schuberthaveselect=no
5202b15cb3dSCy Schubertif test x$bwin32 != xtrue; then
5212b15cb3dSCy Schubert    AC_CHECK_FUNCS(select, [haveselect=yes], )
5222b15cb3dSCy Schubert    if test "x$haveselect" = "xyes" ; then
5232b15cb3dSCy Schubert 	needsignal=yes
5242b15cb3dSCy Schubert    fi
5252b15cb3dSCy Schubertfi
5262b15cb3dSCy SchubertAM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
5272b15cb3dSCy Schubert
5282b15cb3dSCy Schuberthavepoll=no
5292b15cb3dSCy SchubertAC_CHECK_FUNCS(poll, [havepoll=yes], )
5302b15cb3dSCy Schubertif test "x$havepoll" = "xyes" ; then
5312b15cb3dSCy Schubert	needsignal=yes
5322b15cb3dSCy Schubertfi
5332b15cb3dSCy SchubertAM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
5342b15cb3dSCy Schubert
5352b15cb3dSCy Schuberthavedevpoll=no
5362b15cb3dSCy Schubertif test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
5372b15cb3dSCy Schubert	AC_DEFINE(HAVE_DEVPOLL, 1,
5382b15cb3dSCy Schubert		    [Define if /dev/poll is available])
5392b15cb3dSCy Schubertfi
5402b15cb3dSCy SchubertAM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
5412b15cb3dSCy Schubert
5422b15cb3dSCy Schuberthavekqueue=no
5432b15cb3dSCy Schubertif test "x$ac_cv_header_sys_event_h" = "xyes"; then
5442b15cb3dSCy Schubert	AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
5452b15cb3dSCy Schubert	if test "x$havekqueue" = "xyes" ; then
5462b15cb3dSCy Schubert		AC_MSG_CHECKING(for working kqueue)
547*a466cc55SCy Schubert		AC_RUN_IFELSE(
548*a466cc55SCy Schubert      [AC_LANG_PROGRAM([
549*a466cc55SCy Schubert#ifdef HAVE_STDLIB_H
550*a466cc55SCy Schubert#include <stdlib.h>
551*a466cc55SCy Schubert#endif
552*a466cc55SCy Schubert#ifdef HAVE_STRING_H
553*a466cc55SCy Schubert#include <string.h>
554*a466cc55SCy Schubert#endif
5552b15cb3dSCy Schubert#include <sys/types.h>
5562b15cb3dSCy Schubert#include <sys/time.h>
5572b15cb3dSCy Schubert#include <sys/event.h>
5582b15cb3dSCy Schubert#include <stdio.h>
5592b15cb3dSCy Schubert#include <unistd.h>
5602b15cb3dSCy Schubert#include <fcntl.h>
561*a466cc55SCy Schubert        ], [[
5622b15cb3dSCy Schubert	int kq;
5632b15cb3dSCy Schubert	int n;
564*a466cc55SCy Schubert	int fd[2];
5652b15cb3dSCy Schubert	struct kevent ev;
5662b15cb3dSCy Schubert	struct timespec ts;
567*a466cc55SCy Schubert	char buf[80000];
5682b15cb3dSCy Schubert
5692b15cb3dSCy Schubert	if (pipe(fd) == -1)
570*a466cc55SCy Schubert  		return 1;
571*a466cc55SCy Schubert	if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
572*a466cc55SCy Schubert		return 1;
5732b15cb3dSCy Schubert
574*a466cc55SCy Schubert	while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
5752b15cb3dSCy Schubert		;
5762b15cb3dSCy Schubert
5772b15cb3dSCy Schubert	if ((kq = kqueue()) == -1)
578*a466cc55SCy Schubert		return 1;
5792b15cb3dSCy Schubert
5802b15cb3dSCy Schubert	memset(&ev, 0, sizeof(ev));
581*a466cc55SCy Schubert	ev.ident = fd[1];
5822b15cb3dSCy Schubert	ev.filter = EVFILT_WRITE;
5832b15cb3dSCy Schubert	ev.flags = EV_ADD | EV_ENABLE;
5842b15cb3dSCy Schubert	n = kevent(kq, &ev, 1, NULL, 0, NULL);
5852b15cb3dSCy Schubert	if (n == -1)
586*a466cc55SCy Schubert		return 1;
5872b15cb3dSCy Schubert
588*a466cc55SCy Schubert	read(fd[0], buf, sizeof(buf));
5892b15cb3dSCy Schubert
5902b15cb3dSCy Schubert	ts.tv_sec = 0;
5912b15cb3dSCy Schubert	ts.tv_nsec = 0;
5922b15cb3dSCy Schubert	n = kevent(kq, NULL, 0, &ev, 1, &ts);
5932b15cb3dSCy Schubert	if (n == -1 || n == 0)
594*a466cc55SCy Schubert		return 1;
5952b15cb3dSCy Schubert
596*a466cc55SCy Schubert	return 0;
597*a466cc55SCy Schubert        ]]
598*a466cc55SCy Schubert      )],
599*a466cc55SCy Schubert      [AC_MSG_RESULT(yes)
6002b15cb3dSCy Schubert      AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
6012b15cb3dSCy Schubert        [Define if kqueue works correctly with pipes])
6022b15cb3dSCy Schubert      havekqueue=yes
603*a466cc55SCy Schubert      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
604*a466cc55SCy Schubert    )
6052b15cb3dSCy Schubert	fi
6062b15cb3dSCy Schubertfi
6072b15cb3dSCy SchubertAM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
6082b15cb3dSCy Schubert
6092b15cb3dSCy Schuberthaveepollsyscall=no
6102b15cb3dSCy Schuberthaveepoll=no
6112b15cb3dSCy SchubertAC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
6122b15cb3dSCy Schubertif test "x$haveepoll" = "xyes" ; then
6132b15cb3dSCy Schubert	AC_DEFINE(HAVE_EPOLL, 1,
6142b15cb3dSCy Schubert		[Define if your system supports the epoll system calls])
6152b15cb3dSCy Schubert	needsignal=yes
6162b15cb3dSCy Schubertfi
6172b15cb3dSCy Schubertif test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
6182b15cb3dSCy Schubert	if test "x$haveepoll" = "xno" ; then
6192b15cb3dSCy Schubert		AC_MSG_CHECKING(for epoll system call)
620*a466cc55SCy Schubert		AC_RUN_IFELSE(
621*a466cc55SCy Schubert      [AC_LANG_PROGRAM([[
6222b15cb3dSCy Schubert#include <stdint.h>
6232b15cb3dSCy Schubert#include <sys/param.h>
6242b15cb3dSCy Schubert#include <sys/types.h>
6252b15cb3dSCy Schubert#include <sys/syscall.h>
6262b15cb3dSCy Schubert#include <sys/epoll.h>
6272b15cb3dSCy Schubert#include <unistd.h>
6282b15cb3dSCy Schubert
6292b15cb3dSCy Schubertint
6302b15cb3dSCy Schubertepoll_create(int size)
6312b15cb3dSCy Schubert{
6322b15cb3dSCy Schubert	return (syscall(__NR_epoll_create, size));
6332b15cb3dSCy Schubert}
634*a466cc55SCy Schubert        ]],[[
6352b15cb3dSCy Schubert	int epfd;
6362b15cb3dSCy Schubert
6372b15cb3dSCy Schubert	epfd = epoll_create(256);
638*a466cc55SCy Schubert	return (epfd == -1 ? 1 : 0);
639*a466cc55SCy Schubert        ]]
640*a466cc55SCy Schubert      )],
641*a466cc55SCy Schubert      [AC_MSG_RESULT(yes)
6422b15cb3dSCy Schubert      AC_DEFINE(HAVE_EPOLL, 1,
6432b15cb3dSCy Schubert	      [Define if your system supports the epoll system calls])
6442b15cb3dSCy Schubert      needsignal=yes
6452b15cb3dSCy Schubert      have_epoll=yes
6462b15cb3dSCy Schubert      AC_LIBOBJ(epoll_sub)
647*a466cc55SCy Schubert      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
648*a466cc55SCy Schubert    )
6492b15cb3dSCy Schubert	fi
6502b15cb3dSCy Schubertfi
6512b15cb3dSCy SchubertAM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
6522b15cb3dSCy Schubert
6532b15cb3dSCy Schuberthaveeventports=no
6542b15cb3dSCy SchubertAC_CHECK_FUNCS(port_create, [haveeventports=yes], )
6552b15cb3dSCy Schubertif test "x$haveeventports" = "xyes" ; then
6562b15cb3dSCy Schubert	AC_DEFINE(HAVE_EVENT_PORTS, 1,
6572b15cb3dSCy Schubert		[Define if your system supports event ports])
6582b15cb3dSCy Schubert	needsignal=yes
6592b15cb3dSCy Schubertfi
6602b15cb3dSCy SchubertAM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
6612b15cb3dSCy Schubert
6622b15cb3dSCy Schubertif test "x$bwin32" = "xtrue"; then
6632b15cb3dSCy Schubert	needsignal=yes
6642b15cb3dSCy Schubertfi
6652b15cb3dSCy Schubert
6662b15cb3dSCy SchubertAM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
6672b15cb3dSCy Schubert
6682b15cb3dSCy SchubertAC_TYPE_PID_T
6692b15cb3dSCy SchubertAC_TYPE_SIZE_T
6702b15cb3dSCy SchubertAC_TYPE_SSIZE_T
6712b15cb3dSCy Schubert
6722b15cb3dSCy SchubertAC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
6732b15cb3dSCy Schubert[#ifdef HAVE_STDINT_H
6742b15cb3dSCy Schubert#include <stdint.h>
6752b15cb3dSCy Schubert#elif defined(HAVE_INTTYPES_H)
6762b15cb3dSCy Schubert#include <inttypes.h>
6772b15cb3dSCy Schubert#endif
6782b15cb3dSCy Schubert#ifdef HAVE_SYS_TYPES_H
6792b15cb3dSCy Schubert#include <sys/types.h>
6802b15cb3dSCy Schubert#endif])
6812b15cb3dSCy Schubert
6822b15cb3dSCy SchubertAC_CHECK_TYPES([fd_mask], , ,
6832b15cb3dSCy Schubert[#ifdef HAVE_SYS_TYPES_H
6842b15cb3dSCy Schubert#include <sys/types.h>
6852b15cb3dSCy Schubert#endif
6862b15cb3dSCy Schubert#ifdef HAVE_SYS_SELECT_H
6872b15cb3dSCy Schubert#include <sys/select.h>
6882b15cb3dSCy Schubert#endif])
6892b15cb3dSCy Schubert
6902b15cb3dSCy SchubertAC_CHECK_SIZEOF(long long)
6912b15cb3dSCy SchubertAC_CHECK_SIZEOF(long)
6922b15cb3dSCy SchubertAC_CHECK_SIZEOF(int)
6932b15cb3dSCy SchubertAC_CHECK_SIZEOF(short)
6942b15cb3dSCy SchubertAC_CHECK_SIZEOF(size_t)
6952b15cb3dSCy SchubertAC_CHECK_SIZEOF(void *)
6962b15cb3dSCy SchubertAC_CHECK_SIZEOF(off_t)
697*a466cc55SCy SchubertAC_CHECK_SIZEOF(time_t)
6982b15cb3dSCy Schubert
699*a466cc55SCy SchubertAC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, struct sockaddr_un, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
700*a466cc55SCy Schubert[#define _GNU_SOURCE 1
7012b15cb3dSCy Schubert#include <sys/types.h>
7022b15cb3dSCy Schubert#ifdef HAVE_NETINET_IN_H
7032b15cb3dSCy Schubert#include <netinet/in.h>
7042b15cb3dSCy Schubert#endif
7052b15cb3dSCy Schubert#ifdef HAVE_NETINET_IN6_H
7062b15cb3dSCy Schubert#include <netinet/in6.h>
7072b15cb3dSCy Schubert#endif
708*a466cc55SCy Schubert#ifdef HAVE_SYS_UN_H
709*a466cc55SCy Schubert#include <sys/un.h>
710*a466cc55SCy Schubert#endif
7112b15cb3dSCy Schubert#ifdef HAVE_SYS_SOCKET_H
7122b15cb3dSCy Schubert#include <sys/socket.h>
7132b15cb3dSCy Schubert#endif
7142b15cb3dSCy Schubert#ifdef HAVE_NETDB_H
7152b15cb3dSCy Schubert#include <netdb.h>
7162b15cb3dSCy Schubert#endif
7172b15cb3dSCy Schubert#ifdef _WIN32
7182b15cb3dSCy Schubert#define WIN32_WINNT 0x400
7192b15cb3dSCy Schubert#define _WIN32_WINNT 0x400
7202b15cb3dSCy Schubert#define WIN32_LEAN_AND_MEAN
7212b15cb3dSCy Schubert#if defined(_MSC_VER) && (_MSC_VER < 1300)
7222b15cb3dSCy Schubert#include <winsock.h>
7232b15cb3dSCy Schubert#else
7242b15cb3dSCy Schubert#include <winsock2.h>
7252b15cb3dSCy Schubert#include <ws2tcpip.h>
7262b15cb3dSCy Schubert#endif
7272b15cb3dSCy Schubert#endif
7282b15cb3dSCy Schubert])
7292b15cb3dSCy SchubertAC_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], , ,
7302b15cb3dSCy Schubert[#include <sys/types.h>
7312b15cb3dSCy Schubert#ifdef HAVE_NETINET_IN_H
7322b15cb3dSCy Schubert#include <netinet/in.h>
7332b15cb3dSCy Schubert#endif
7342b15cb3dSCy Schubert#ifdef HAVE_NETINET_IN6_H
7352b15cb3dSCy Schubert#include <netinet/in6.h>
7362b15cb3dSCy Schubert#endif
7372b15cb3dSCy Schubert#ifdef HAVE_SYS_SOCKET_H
7382b15cb3dSCy Schubert#include <sys/socket.h>
7392b15cb3dSCy Schubert#endif
7402b15cb3dSCy Schubert#ifdef _WIN32
7412b15cb3dSCy Schubert#define WIN32_WINNT 0x400
7422b15cb3dSCy Schubert#define _WIN32_WINNT 0x400
7432b15cb3dSCy Schubert#define WIN32_LEAN_AND_MEAN
7442b15cb3dSCy Schubert#if defined(_MSC_VER) && (_MSC_VER < 1300)
7452b15cb3dSCy Schubert#include <winsock.h>
7462b15cb3dSCy Schubert#else
7472b15cb3dSCy Schubert#include <winsock2.h>
7482b15cb3dSCy Schubert#include <ws2tcpip.h>
7492b15cb3dSCy Schubert#endif
7502b15cb3dSCy Schubert#endif
7512b15cb3dSCy Schubert])
7522b15cb3dSCy Schubert
753*a466cc55SCy SchubertAC_CHECK_TYPES([struct linger],,,
7542b15cb3dSCy Schubert[
7552b15cb3dSCy Schubert#ifdef HAVE_SYS_SOCKET_H
7562b15cb3dSCy Schubert#include <sys/socket.h>
7572b15cb3dSCy Schubert#endif
758*a466cc55SCy Schubert#ifdef _WIN32
759*a466cc55SCy Schubert#include <winsock2.h>
760*a466cc55SCy Schubert#endif
7612b15cb3dSCy Schubert])
7622b15cb3dSCy Schubert
7632b15cb3dSCy SchubertAC_MSG_CHECKING([for socklen_t])
764*a466cc55SCy SchubertAC_COMPILE_IFELSE(
765*a466cc55SCy Schubert  [AC_LANG_PROGRAM([
7662b15cb3dSCy Schubert #include <sys/types.h>
767*a466cc55SCy Schubert #ifdef _WIN32
768*a466cc55SCy Schubert #include <ws2tcpip.h>
769*a466cc55SCy Schubert #else
770*a466cc55SCy Schubert #include <sys/socket.h>
771*a466cc55SCy Schubert #endif
772*a466cc55SCy Schubert    ],[socklen_t x;]
773*a466cc55SCy Schubert  )],
774*a466cc55SCy Schubert	[AC_MSG_RESULT([yes])],
7752b15cb3dSCy Schubert  [AC_MSG_RESULT([no])
7762b15cb3dSCy Schubert  AC_DEFINE(socklen_t, unsigned int,
7772b15cb3dSCy Schubert	  [Define to unsigned int if you dont have it])]
7782b15cb3dSCy Schubert)
7792b15cb3dSCy Schubert
780*a466cc55SCy Schubert# __func__/__FUNCTION__ is not a macros in general
7812b15cb3dSCy SchubertAC_MSG_CHECKING([whether our compiler supports __func__])
782*a466cc55SCy SchubertAC_COMPILE_IFELSE(
783*a466cc55SCy Schubert  [AC_LANG_PROGRAM([],
784*a466cc55SCy Schubert    [ const char *cp = __func__; ]
785*a466cc55SCy Schubert  )],
786*a466cc55SCy Schubert	[ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__])
7872b15cb3dSCy Schubert    AC_MSG_RESULT([yes])
788*a466cc55SCy Schubert  ],
789*a466cc55SCy Schubert  [AC_MSG_RESULT([no])]
790*a466cc55SCy Schubert)
791*a466cc55SCy SchubertAC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
792*a466cc55SCy SchubertAC_COMPILE_IFELSE(
793*a466cc55SCy Schubert  [AC_LANG_PROGRAM([],
794*a466cc55SCy Schubert    [ const char *cp = __FUNCTION__; ]
795*a466cc55SCy Schubert  )],
796*a466cc55SCy Schubert	[ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__])
797*a466cc55SCy Schubert    AC_MSG_RESULT([yes])
798*a466cc55SCy Schubert  ],
799*a466cc55SCy Schubert  [AC_MSG_RESULT([no])]
800*a466cc55SCy Schubert)
8012b15cb3dSCy Schubert
8022b15cb3dSCy Schubert# check if we can compile with pthreads
8032b15cb3dSCy Schuberthave_pthreads=no
8042b15cb3dSCy Schubertif test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
805a25439b6SCy Schubert  ACX_PTHREAD([
806a25439b6SCy Schubert	AC_DEFINE(HAVE_PTHREADS, 1,
807a25439b6SCy Schubert		[Define if we have pthreads on this system])
808a25439b6SCy Schubert	have_pthreads=yes])
8092b15cb3dSCy Schubert  CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
810a25439b6SCy Schubert  AC_CHECK_SIZEOF(pthread_t, ,
811a25439b6SCy Schubert     [AC_INCLUDES_DEFAULT()
812a25439b6SCy Schubert      #include <pthread.h> ]
8132b15cb3dSCy Schubert  )
8142b15cb3dSCy Schubertfi
815*a466cc55SCy SchubertAM_CONDITIONAL(THREADS, [test "$enable_thread_support" != "no"])
816*a466cc55SCy SchubertAM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
8172b15cb3dSCy Schubert
8182b15cb3dSCy Schubert# check if we should compile locking into the library
8192b15cb3dSCy Schubertif test x$enable_thread_support = xno; then
8202b15cb3dSCy Schubert   AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
8212b15cb3dSCy Schubert	[Define if libevent should not be compiled with thread support])
8222b15cb3dSCy Schubertfi
8232b15cb3dSCy Schubert
8242b15cb3dSCy Schubert# check if we should hard-code the mm functions.
8252b15cb3dSCy Schubertif test x$enable_malloc_replacement = xno; then
8262b15cb3dSCy Schubert  AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
8272b15cb3dSCy Schubert        [Define if libevent should not allow replacing the mm functions])
8282b15cb3dSCy Schubertfi
8292b15cb3dSCy Schubert
8302b15cb3dSCy Schubert# check if we should hard-code debugging out
8312b15cb3dSCy Schubertif test x$enable_debug_mode = xno; then
8322b15cb3dSCy Schubert  AC_DEFINE(DISABLE_DEBUG_MODE, 1,
8332b15cb3dSCy Schubert        [Define if libevent should build without support for a debug mode])
8342b15cb3dSCy Schubertfi
8352b15cb3dSCy Schubert
8362b15cb3dSCy Schubert# check if we should enable verbose debugging
8372b15cb3dSCy Schubertif test x$enable_verbose_debug = xyes; then
8382b15cb3dSCy Schubert	CFLAGS="$CFLAGS -DUSE_DEBUG"
8392b15cb3dSCy Schubertfi
8402b15cb3dSCy Schubert
8412b15cb3dSCy Schubert# check if we have and should use openssl
8422b15cb3dSCy SchubertAM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
8432b15cb3dSCy Schubert
8442b15cb3dSCy Schubert# Add some more warnings which we use in development but not in the
8452b15cb3dSCy Schubert# released versions.  (Some relevant gcc versions can't handle these.)
8462b15cb3dSCy Schubertif test x$enable_gcc_warnings != xno && test "$GCC" = "yes"; then
8472b15cb3dSCy Schubert
8482b15cb3dSCy Schubert  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
8492b15cb3dSCy Schubert#if !defined(__GNUC__) || (__GNUC__ < 4)
8502b15cb3dSCy Schubert#error
8512b15cb3dSCy Schubert#endif])], have_gcc4=yes, have_gcc4=no)
8522b15cb3dSCy Schubert
8532b15cb3dSCy Schubert  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
8542b15cb3dSCy Schubert#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
8552b15cb3dSCy Schubert#error
8562b15cb3dSCy Schubert#endif])], have_gcc42=yes, have_gcc42=no)
8572b15cb3dSCy Schubert
8582b15cb3dSCy Schubert  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
8592b15cb3dSCy Schubert#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
8602b15cb3dSCy Schubert#error
8612b15cb3dSCy Schubert#endif])], have_gcc45=yes, have_gcc45=no)
8622b15cb3dSCy Schubert
8632b15cb3dSCy Schubert  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
8642b15cb3dSCy Schubert#if !defined(__clang__)
8652b15cb3dSCy Schubert#error
8662b15cb3dSCy Schubert#endif])], have_clang=yes, have_clang=no)
8672b15cb3dSCy Schubert
868*a466cc55SCy Schubert  # -W is the same as -Wextra
869*a466cc55SCy Schubert  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wnested-externs -Wbad-function-cast"
8702b15cb3dSCy Schubert  if test x$enable_gcc_warnings = xyes; then
8712b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Werror"
8722b15cb3dSCy Schubert  fi
8732b15cb3dSCy Schubert
8742b15cb3dSCy Schubert  CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
8752b15cb3dSCy Schubert
8762b15cb3dSCy Schubert  if test x$have_gcc4 = xyes ; then
8772b15cb3dSCy Schubert    # These warnings break gcc 3.3.5 and work on gcc 4.0.2
8782b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
8792b15cb3dSCy Schubert    #CFLAGS="$CFLAGS -Wold-style-definition"
8802b15cb3dSCy Schubert  fi
8812b15cb3dSCy Schubert
8822b15cb3dSCy Schubert  if test x$have_gcc42 = xyes ; then
8832b15cb3dSCy Schubert    # These warnings break gcc 4.0.2 and work on gcc 4.2
8842b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Waddress"
8852b15cb3dSCy Schubert  fi
8862b15cb3dSCy Schubert
8872b15cb3dSCy Schubert  if test x$have_gcc42 = xyes && test x$have_clang = xno; then
8882b15cb3dSCy Schubert    # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
8892b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
8902b15cb3dSCy Schubert  fi
8912b15cb3dSCy Schubert
8922b15cb3dSCy Schubert  if test x$have_gcc45 = xyes ; then
8932b15cb3dSCy Schubert    # These warnings work on gcc 4.5
8942b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Wlogical-op"
8952b15cb3dSCy Schubert  fi
8962b15cb3dSCy Schubert
8972b15cb3dSCy Schubert  if test x$have_clang = xyes; then
8982b15cb3dSCy Schubert    # Disable the unused-function warnings, because these trigger
8992b15cb3dSCy Schubert    # for minheap-internal.h related code.
9002b15cb3dSCy Schubert    CFLAGS="$CFLAGS -Wno-unused-function"
9012b15cb3dSCy Schubert
902*a466cc55SCy Schubert    # clang on macosx emits warnings for each directory specified which
9032b15cb3dSCy Schubert    # isn't "used" generating a lot of build noise (typically 3 warnings
9042b15cb3dSCy Schubert    # per file
9052b15cb3dSCy Schubert    case "$host_os" in
9062b15cb3dSCy Schubert        darwin*)
9072b15cb3dSCy Schubert            CFLAGS="$CFLAGS -Qunused-arguments"
9082b15cb3dSCy Schubert        ;;
9092b15cb3dSCy Schubert    esac
9102b15cb3dSCy Schubert  fi
9112b15cb3dSCy Schubert
9122b15cb3dSCy Schubert##This will break the world on some 64-bit architectures
9132b15cb3dSCy Schubert# CFLAGS="$CFLAGS -Winline"
9142b15cb3dSCy Schubert
9152b15cb3dSCy Schubertfi
9162b15cb3dSCy Schubert
9172b15cb3dSCy SchubertLIBEVENT_GC_SECTIONS=
9182b15cb3dSCy Schubertif test "$GCC" = yes && test "$enable_function_sections" = yes ; then
9192b15cb3dSCy Schubert    AC_CACHE_CHECK(
9202b15cb3dSCy Schubert	[if linker supports omitting unused code and data],
9212b15cb3dSCy Schubert	[libevent_cv_gc_sections_runs],
9222b15cb3dSCy Schubert	[
9232b15cb3dSCy Schubert	    dnl  NetBSD will link but likely not run with --gc-sections
9242b15cb3dSCy Schubert	    dnl  http://bugs.ntp.org/1844
9252b15cb3dSCy Schubert	    dnl  http://gnats.netbsd.org/40401
9262b15cb3dSCy Schubert	    dnl  --gc-sections causes attempt to load as linux elf, with
9272b15cb3dSCy Schubert	    dnl  wrong syscalls in place.  Test a little gauntlet of
9282b15cb3dSCy Schubert	    dnl  simple stdio read code checking for errors, expecting
9292b15cb3dSCy Schubert	    dnl  enough syscall differences that the NetBSD code will
9302b15cb3dSCy Schubert	    dnl  fail even with Linux emulation working as designed.
9312b15cb3dSCy Schubert	    dnl  A shorter test could be refined by someone with access
9322b15cb3dSCy Schubert	    dnl  to a NetBSD host with Linux emulation working.
9332b15cb3dSCy Schubert	    origCFLAGS="$CFLAGS"
9342b15cb3dSCy Schubert	    CFLAGS="$CFLAGS -Wl,--gc-sections"
9352b15cb3dSCy Schubert	    AC_LINK_IFELSE(
9362b15cb3dSCy Schubert		[AC_LANG_PROGRAM(
9372b15cb3dSCy Schubert		    [[
9382b15cb3dSCy Schubert			#include <stdlib.h>
9392b15cb3dSCy Schubert			#include <stdio.h>
9402b15cb3dSCy Schubert		    ]],
9412b15cb3dSCy Schubert		    [[
9422b15cb3dSCy Schubert			FILE *	fpC;
9432b15cb3dSCy Schubert			char	buf[32];
9442b15cb3dSCy Schubert			size_t	cch;
9452b15cb3dSCy Schubert			int	read_success_once;
9462b15cb3dSCy Schubert
9472b15cb3dSCy Schubert			fpC = fopen("conftest.c", "r");
9482b15cb3dSCy Schubert			if (NULL == fpC)
9492b15cb3dSCy Schubert				exit(1);
9502b15cb3dSCy Schubert			do {
9512b15cb3dSCy Schubert				cch = fread(buf, sizeof(buf), 1, fpC);
9522b15cb3dSCy Schubert				read_success_once |= (0 != cch);
9532b15cb3dSCy Schubert			} while (0 != cch);
9542b15cb3dSCy Schubert			if (!read_success_once)
9552b15cb3dSCy Schubert				exit(2);
9562b15cb3dSCy Schubert			if (!feof(fpC))
9572b15cb3dSCy Schubert				exit(3);
9582b15cb3dSCy Schubert			if (0 != fclose(fpC))
9592b15cb3dSCy Schubert				exit(4);
9602b15cb3dSCy Schubert
9612b15cb3dSCy Schubert			exit(EXIT_SUCCESS);
9622b15cb3dSCy Schubert		    ]]
9632b15cb3dSCy Schubert		)],
9642b15cb3dSCy Schubert		[
9652b15cb3dSCy Schubert                    dnl We have to do this invocation manually so that we can
9662b15cb3dSCy Schubert                    dnl get the output of conftest.err to make sure it doesn't
9672b15cb3dSCy Schubert                    dnl mention gc-sections.
9682b15cb3dSCy Schubert		    if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
9692b15cb3dSCy Schubert			libevent_cv_gc_sections_runs=no
9702b15cb3dSCy Schubert		    else
9712b15cb3dSCy Schubert			libevent_cv_gc_sections_runs=no
9722b15cb3dSCy Schubert			./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
9732b15cb3dSCy Schubert		    fi
9742b15cb3dSCy Schubert		],
9752b15cb3dSCy Schubert		[libevent_cv_gc_sections_runs=no]
9762b15cb3dSCy Schubert	    )
9772b15cb3dSCy Schubert	    CFLAGS="$origCFLAGS"
9782b15cb3dSCy Schubert	    AS_UNSET([origCFLAGS])
9792b15cb3dSCy Schubert	]
9802b15cb3dSCy Schubert    )
9812b15cb3dSCy Schubert    case "$libevent_cv_gc_sections_runs" in
9822b15cb3dSCy Schubert     yes)
9832b15cb3dSCy Schubert	CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
9842b15cb3dSCy Schubert	LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
9852b15cb3dSCy Schubert	;;
9862b15cb3dSCy Schubert    esac
9872b15cb3dSCy Schubertfi
9882b15cb3dSCy SchubertAC_SUBST([LIBEVENT_GC_SECTIONS])
9892b15cb3dSCy Schubert
9902b15cb3dSCy SchubertAM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
9912b15cb3dSCy Schubert
992*a466cc55SCy Schubert# Doxygen support
993*a466cc55SCy SchubertDX_HTML_FEATURE(ON)
994*a466cc55SCy SchubertDX_MAN_FEATURE(OFF)
995*a466cc55SCy SchubertDX_RTF_FEATURE(OFF)
996*a466cc55SCy SchubertDX_XML_FEATURE(OFF)
997*a466cc55SCy SchubertDX_PDF_FEATURE(OFF)
998*a466cc55SCy SchubertDX_PS_FEATURE(OFF)
999*a466cc55SCy SchubertDX_CHM_FEATURE(OFF)
1000*a466cc55SCy SchubertDX_CHI_FEATURE(OFF)
1001*a466cc55SCy SchubertDX_INIT_DOXYGEN([libevent], [${top_srcdir}/Doxyfile], [doxygen])
1002f0574f5cSXin LI
1003*a466cc55SCy SchubertAM_CONDITIONAL([ENABLE_DOXYGEN], [test "$DX_FLAG_doc" = "1"])
1004*a466cc55SCy SchubertAM_CONDITIONAL([ENABLE_DOXYGEN_MAN], [test "$DX_FLAG_man" = "1"])
1005*a466cc55SCy Schubert
1006*a466cc55SCy SchubertAC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc libevent_core.pc libevent_extra.pc] )
10072b15cb3dSCy SchubertAC_OUTPUT(Makefile)
1008