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