Home | History | Annotate | Download | only in libevent
      1 dnl configure.in for libevent
      2 dnl Dug Song <dugsong (a] monkey.org>
      3 AC_INIT(event.c)
      4 
      5 AM_INIT_AUTOMAKE(libevent,1.4.13-stable)
      6 AM_CONFIG_HEADER(config.h)
      7 dnl AM_MAINTAINER_MODE
      8 
      9 dnl Initialize prefix.
     10 if test "$prefix" = "NONE"; then
     11    prefix="/usr/local"
     12 fi
     13 
     14 dnl Checks for programs.
     15 AC_PROG_CC
     16 AC_PROG_INSTALL
     17 AC_PROG_LN_S
     18 
     19 AC_PROG_GCC_TRADITIONAL
     20 if 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"
     25 fi
     26 
     27 AC_ARG_ENABLE(gcc-warnings,
     28      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
     29 
     30 AC_PROG_LIBTOOL
     31 
     32 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
     33 dnl   built by default.  You can also turn shared libs on and off from 
     34 dnl   the command line with --enable-shared and --disable-shared.
     35 dnl AC_DISABLE_SHARED
     36 AC_SUBST(LIBTOOL_DEPS)
     37 
     38 dnl Checks for libraries.
     39 AC_CHECK_LIB(socket, socket)
     40 AC_CHECK_LIB(resolv, inet_aton)
     41 AC_CHECK_LIB(rt, clock_gettime)
     42 AC_CHECK_LIB(nsl, inet_ntoa)
     43 
     44 dnl Checks for header files.
     45 AC_HEADER_STDC
     46 AC_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)
     47 if 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 	)
     60 fi
     61 
     62 if 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 )
     74 fi
     75 
     76 if 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 )
     88 fi
     89 
     90 if 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 )
    102 fi
    103 
    104 if 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 )
    116 fi
    117 
    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),
    129 )
    130 
    131 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
    132 
    133 dnl Checks for typedefs, structures, and compiler characteristics.
    134 AC_C_CONST
    135 AC_C_INLINE
    136 AC_HEADER_TIME
    137 
    138 dnl Checks for library functions.
    139 AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop signal sigaction strtoll issetugid geteuid getegid)
    140 
    141 AC_CHECK_SIZEOF(long)
    142 
    143 if 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])
    145 else
    146    AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define is no secure id variant is available])
    147 fi
    148 
    149 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
    150 AC_EGREP_CPP(yes,
    151 [
    152 #define _GNU_SOURCE
    153 #include <fcntl.h>
    154 #ifdef F_SETFD
    155 yes
    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 
    161 needsignal=no
    162 haveselect=no
    163 AC_CHECK_FUNCS(select, [haveselect=yes], )
    164 if test "x$haveselect" = "xyes" ; then
    165 	AC_LIBOBJ(select)
    166 	needsignal=yes
    167 fi
    168 
    169 havepoll=no
    170 AC_CHECK_FUNCS(poll, [havepoll=yes], )
    171 if test "x$havepoll" = "xyes" ; then
    172 	AC_LIBOBJ(poll)
    173 	needsignal=yes
    174 fi
    175 
    176 haveepoll=no
    177 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
    178 if 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
    183 fi
    184 
    185 havedevpoll=no
    186 if 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)
    190 fi
    191 
    192 havekqueue=no
    193 if 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 
    205 int
    206 main(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
    247 fi
    248 
    249 haveepollsyscall=no
    250 if 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 
    261 int
    262 epoll_create(int size)
    263 {
    264 	return (syscall(__NR_epoll_create, size));
    265 }
    266 
    267 int
    268 main(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
    281 fi
    282 
    283 haveeventports=no
    284 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
    285 if 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
    290 fi
    291 if test "x$bwin32" = "xtrue"; then
    292 	needsignal=yes
    293 fi
    294 if test "x$bwin32" = "xtrue"; then
    295 	needsignal=yes
    296 fi
    297 if test "x$needsignal" = "xyes" ; then
    298 	AC_LIBOBJ(signal)
    299 fi
    300 
    301 AC_TYPE_PID_T
    302 AC_TYPE_SIZE_T
    303 AC_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])
    312 AC_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 
    320 AC_CHECK_SIZEOF(long long)
    321 AC_CHECK_SIZEOF(int)
    322 AC_CHECK_SIZEOF(short)
    323 AC_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 
    335 AC_MSG_CHECKING([for socklen_t])
    336 AC_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 
    346 AC_MSG_CHECKING([whether our compiler supports __func__])
    347 AC_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.)
    364 if 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 
    393 fi
    394 
    395 AC_OUTPUT(Makefile test/Makefile sample/Makefile)
    396