1dnl configure.in for libevent 2dnl Dug Song <dugsong@monkey.org> 3AC_INIT(event.c) 4 5AM_INIT_AUTOMAKE(libevent,1.4.13-stable) 6AM_CONFIG_HEADER(config.h) 7dnl AM_MAINTAINER_MODE 8 9dnl Initialize prefix. 10if test "$prefix" = "NONE"; then 11 prefix="/usr/local" 12fi 13 14dnl Checks for programs. 15AC_PROG_CC 16AC_PROG_INSTALL 17AC_PROG_LN_S 18 19AC_PROG_GCC_TRADITIONAL 20if test "$GCC" = yes ; then 21 CFLAGS="$CFLAGS -Wall" 22 # And disable the strict-aliasing optimization, since it breaks 23 # our sockaddr-handling code in strange ways. 24 CFLAGS="$CFLAGS -fno-strict-aliasing" 25fi 26 27AC_ARG_ENABLE(gcc-warnings, 28 AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC)) 29 30AC_PROG_LIBTOOL 31 32dnl Uncomment "AC_DISABLE_SHARED" to make shared librraries not get 33dnl built by default. You can also turn shared libs on and off from 34dnl the command line with --enable-shared and --disable-shared. 35dnl AC_DISABLE_SHARED 36AC_SUBST(LIBTOOL_DEPS) 37 38dnl Checks for libraries. 39AC_CHECK_LIB(socket, socket) 40AC_CHECK_LIB(resolv, inet_aton) 41AC_CHECK_LIB(rt, clock_gettime) 42AC_CHECK_LIB(nsl, inet_ntoa) 43 44dnl Checks for header files. 45AC_HEADER_STDC 46AC_CHECK_HEADERS(fcntl.h stdarg.h inttypes.h stdint.h poll.h signal.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/in6.h sys/socket.h) 47if test "x$ac_cv_header_sys_queue_h" = "xyes"; then 48 AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h) 49 AC_EGREP_CPP(yes, 50[ 51#include <sys/queue.h> 52#ifdef TAILQ_FOREACH 53 yes 54#endif 55], [AC_MSG_RESULT(yes) 56 AC_DEFINE(HAVE_TAILQFOREACH, 1, 57 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])], 58 AC_MSG_RESULT(no) 59 ) 60fi 61 62if test "x$ac_cv_header_sys_time_h" = "xyes"; then 63 AC_MSG_CHECKING(for timeradd in sys/time.h) 64 AC_EGREP_CPP(yes, 65[ 66#include <sys/time.h> 67#ifdef timeradd 68 yes 69#endif 70], [ AC_DEFINE(HAVE_TIMERADD, 1, 71 [Define if timeradd is defined in <sys/time.h>]) 72 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no) 73) 74fi 75 76if test "x$ac_cv_header_sys_time_h" = "xyes"; then 77 AC_MSG_CHECKING(for timercmp in sys/time.h) 78 AC_EGREP_CPP(yes, 79[ 80#include <sys/time.h> 81#ifdef timercmp 82 yes 83#endif 84], [ AC_DEFINE(HAVE_TIMERCMP, 1, 85 [Define if timercmp is defined in <sys/time.h>]) 86 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no) 87) 88fi 89 90if test "x$ac_cv_header_sys_time_h" = "xyes"; then 91 AC_MSG_CHECKING(for timerclear in sys/time.h) 92 AC_EGREP_CPP(yes, 93[ 94#include <sys/time.h> 95#ifdef timerclear 96 yes 97#endif 98], [ AC_DEFINE(HAVE_TIMERCLEAR, 1, 99 [Define if timerclear is defined in <sys/time.h>]) 100 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no) 101) 102fi 103 104if test "x$ac_cv_header_sys_time_h" = "xyes"; then 105 AC_MSG_CHECKING(for timerisset in sys/time.h) 106 AC_EGREP_CPP(yes, 107[ 108#include <sys/time.h> 109#ifdef timerisset 110 yes 111#endif 112], [ AC_DEFINE(HAVE_TIMERISSET, 1, 113 [Define if timerisset is defined in <sys/time.h>]) 114 AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no) 115) 116fi 117 118dnl - check if the macro WIN32 is defined on this compiler. 119dnl - (this is how we check for a windows version of GCC) 120AC_MSG_CHECKING(for WIN32) 121AC_TRY_COMPILE(, 122 [ 123#ifndef WIN32 124die horribly 125#endif 126 ], 127 bwin32=true; AC_MSG_RESULT(yes), 128 bwin32=false; AC_MSG_RESULT(no), 129) 130 131AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue) 132 133dnl Checks for typedefs, structures, and compiler characteristics. 134AC_C_CONST 135AC_C_INLINE 136AC_HEADER_TIME 137 138dnl Checks for library functions. 139AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop signal sigaction strtoll issetugid geteuid getegid) 140 141AC_CHECK_SIZEOF(long) 142 143if test "x$ac_cv_func_clock_gettime" = "xyes"; then 144 AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is available in libc]) 145else 146 AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define is no secure id variant is available]) 147fi 148 149AC_MSG_CHECKING(for F_SETFD in fcntl.h) 150AC_EGREP_CPP(yes, 151[ 152#define _GNU_SOURCE 153#include <fcntl.h> 154#ifdef F_SETFD 155yes 156#endif 157], [ AC_DEFINE(HAVE_SETFD, 1, 158 [Define if F_SETFD is defined in <fcntl.h>]) 159 AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no)) 160 161needsignal=no 162haveselect=no 163AC_CHECK_FUNCS(select, [haveselect=yes], ) 164if test "x$haveselect" = "xyes" ; then 165 AC_LIBOBJ(select) 166 needsignal=yes 167fi 168 169havepoll=no 170AC_CHECK_FUNCS(poll, [havepoll=yes], ) 171if test "x$havepoll" = "xyes" ; then 172 AC_LIBOBJ(poll) 173 needsignal=yes 174fi 175 176haveepoll=no 177AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], ) 178if test "x$haveepoll" = "xyes" ; then 179 AC_DEFINE(HAVE_EPOLL, 1, 180 [Define if your system supports the epoll system calls]) 181 AC_LIBOBJ(epoll) 182 needsignal=yes 183fi 184 185havedevpoll=no 186if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then 187 AC_DEFINE(HAVE_DEVPOLL, 1, 188 [Define if /dev/poll is available]) 189 AC_LIBOBJ(devpoll) 190fi 191 192havekqueue=no 193if test "x$ac_cv_header_sys_event_h" = "xyes"; then 194 AC_CHECK_FUNCS(kqueue, [havekqueue=yes], ) 195 if test "x$havekqueue" = "xyes" ; then 196 AC_MSG_CHECKING(for working kqueue) 197 AC_TRY_RUN( 198#include <sys/types.h> 199#include <sys/time.h> 200#include <sys/event.h> 201#include <stdio.h> 202#include <unistd.h> 203#include <fcntl.h> 204 205int 206main(int argc, char **argv) 207{ 208 int kq; 209 int n; 210 int fd[[2]]; 211 struct kevent ev; 212 struct timespec ts; 213 char buf[[8000]]; 214 215 if (pipe(fd) == -1) 216 exit(1); 217 if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1) 218 exit(1); 219 220 while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf)) 221 ; 222 223 if ((kq = kqueue()) == -1) 224 exit(1); 225 226 ev.ident = fd[[1]]; 227 ev.filter = EVFILT_WRITE; 228 ev.flags = EV_ADD | EV_ENABLE; 229 n = kevent(kq, &ev, 1, NULL, 0, NULL); 230 if (n == -1) 231 exit(1); 232 233 read(fd[[0]], buf, sizeof(buf)); 234 235 ts.tv_sec = 0; 236 ts.tv_nsec = 0; 237 n = kevent(kq, NULL, 0, &ev, 1, &ts); 238 if (n == -1 || n == 0) 239 exit(1); 240 241 exit(0); 242}, [AC_MSG_RESULT(yes) 243 AC_DEFINE(HAVE_WORKING_KQUEUE, 1, 244 [Define if kqueue works correctly with pipes]) 245 AC_LIBOBJ(kqueue)], AC_MSG_RESULT(no), AC_MSG_RESULT(no)) 246 fi 247fi 248 249haveepollsyscall=no 250if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then 251 if test "x$haveepoll" = "xno" ; then 252 AC_MSG_CHECKING(for epoll system call) 253 AC_TRY_RUN( 254#include <stdint.h> 255#include <sys/param.h> 256#include <sys/types.h> 257#include <sys/syscall.h> 258#include <sys/epoll.h> 259#include <unistd.h> 260 261int 262epoll_create(int size) 263{ 264 return (syscall(__NR_epoll_create, size)); 265} 266 267int 268main(int argc, char **argv) 269{ 270 int epfd; 271 272 epfd = epoll_create(256); 273 exit (epfd == -1 ? 1 : 0); 274}, [AC_MSG_RESULT(yes) 275 AC_DEFINE(HAVE_EPOLL, 1, 276 [Define if your system supports the epoll system calls]) 277 needsignal=yes 278 AC_LIBOBJ(epoll_sub) 279 AC_LIBOBJ(epoll)], AC_MSG_RESULT(no), AC_MSG_RESULT(no)) 280 fi 281fi 282 283haveeventports=no 284AC_CHECK_FUNCS(port_create, [haveeventports=yes], ) 285if test "x$haveeventports" = "xyes" ; then 286 AC_DEFINE(HAVE_EVENT_PORTS, 1, 287 [Define if your system supports event ports]) 288 AC_LIBOBJ(evport) 289 needsignal=yes 290fi 291if test "x$bwin32" = "xtrue"; then 292 needsignal=yes 293fi 294if test "x$bwin32" = "xtrue"; then 295 needsignal=yes 296fi 297if test "x$needsignal" = "xyes" ; then 298 AC_LIBOBJ(signal) 299fi 300 301AC_TYPE_PID_T 302AC_TYPE_SIZE_T 303AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t], , , 304[#ifdef HAVE_STDINT_H 305#include <stdint.h> 306#elif defined(HAVE_INTTYPES_H) 307#include <inttypes.h> 308#endif 309#ifdef HAVE_SYS_TYPES_H 310#include <sys/types.h> 311#endif]) 312AC_CHECK_TYPES([fd_mask], , , 313[#ifdef HAVE_SYS_TYPES_H 314#include <sys/types.h> 315#endif 316#ifdef HAVE_SELECT_H 317#include <select.h> 318#endif]) 319 320AC_CHECK_SIZEOF(long long) 321AC_CHECK_SIZEOF(int) 322AC_CHECK_SIZEOF(short) 323AC_CHECK_TYPES([struct in6_addr], , , 324[#ifdef WIN32 325#include <winsock2.h> 326#else 327#include <sys/types.h> 328#include <netinet/in.h> 329#include <sys/socket.h> 330#endif 331#ifdef HAVE_NETINET_IN6_H 332#include <netinet/in6.h> 333#endif]) 334 335AC_MSG_CHECKING([for socklen_t]) 336AC_TRY_COMPILE([ 337 #include <sys/types.h> 338 #include <sys/socket.h>], 339 [socklen_t x;], 340 AC_MSG_RESULT([yes]), 341 [AC_MSG_RESULT([no]) 342 AC_DEFINE(socklen_t, unsigned int, 343 [Define to unsigned int if you dont have it])] 344) 345 346AC_MSG_CHECKING([whether our compiler supports __func__]) 347AC_TRY_COMPILE([], 348 [ const char *cp = __func__; ], 349 AC_MSG_RESULT([yes]), 350 AC_MSG_RESULT([no]) 351 AC_MSG_CHECKING([whether our compiler supports __FUNCTION__]) 352 AC_TRY_COMPILE([], 353 [ const char *cp = __FUNCTION__; ], 354 AC_MSG_RESULT([yes]) 355 AC_DEFINE(__func__, __FUNCTION__, 356 [Define to appropriate substitue if compiler doesnt have __func__]), 357 AC_MSG_RESULT([no]) 358 AC_DEFINE(__func__, __FILE__, 359 [Define to appropriate substitue if compiler doesnt have __func__]))) 360 361 362# Add some more warnings which we use in development but not in the 363# released versions. (Some relevant gcc versions can't handle these.) 364if test x$enable_gcc_warnings = xyes; then 365 366 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [ 367#if !defined(__GNUC__) || (__GNUC__ < 4) 368#error 369#endif]), have_gcc4=yes, have_gcc4=no) 370 371 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([], [ 372#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2) 373#error 374#endif]), have_gcc42=yes, have_gcc42=no) 375 376 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror" 377 CFLAGS="$CFLAGS -Wno-unused-parameter -Wno-sign-compare -Wstrict-aliasing" 378 379 if test x$have_gcc4 = xyes ; then 380 # These warnings break gcc 3.3.5 and work on gcc 4.0.2 381 CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement" 382 #CFLAGS="$CFLAGS -Wold-style-definition" 383 fi 384 385 if test x$have_gcc42 = xyes ; then 386 # These warnings break gcc 4.0.2 and work on gcc 4.2 387 CFLAGS="$CFLAGS -Waddress -Wnormalized=id -Woverride-init" 388 fi 389 390##This will break the world on some 64-bit architectures 391# CFLAGS="$CFLAGS -Winline" 392 393fi 394 395AC_OUTPUT(Makefile test/Makefile sample/Makefile) 396