Fixed issue with cmake version generation
[libevent.git] / configure.ac
blob6a669fb7015c290d27fc3e061af17eadbcc5e626
1 dnl Copyright 2000-2007 Niels Provos
2 dnl Copyright 2007-2012 Niels Provos and Nick Mathewson
3 dnl
4 dnl See LICENSE for copying information.
5 dnl
6 dnl Original version Dug Song <dugsong@monkey.org>
8 AC_INIT(libevent,2.1.5-beta)
9 AC_PREREQ(2.59)
10 AC_CONFIG_SRCDIR(event.c)
12 AC_CONFIG_MACRO_DIR([m4])
13 AM_INIT_AUTOMAKE
14 dnl AM_SILENT_RULES req. automake 1.11.  [no] defaults V=1
15 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
16 AC_CONFIG_HEADERS(config.h  evconfig-private.h:evconfig-private.h.in)
17 AC_DEFINE(NUMERIC_VERSION, 0x02010500, [Numeric representation of the version])
19 dnl Initialize prefix.
20 if test "$prefix" = "NONE"; then
21    prefix="/usr/local"
24 dnl Try and get a full POSIX environment on obscure systems
25 ifdef([AC_USE_SYSTEM_EXTENSIONS], [
26 AC_USE_SYSTEM_EXTENSIONS
27 ], [
28 AC_AIX
29 AC_GNU_SOURCE
30 AC_MINIX
33 AC_CANONICAL_BUILD
34 AC_CANONICAL_HOST
35 dnl the 'build' machine is where we run configure and compile
36 dnl the 'host' machine is where the resulting stuff runs.
38 #case "$host_os" in
40 # osf5*)
41 #    CFLAGS="$CFLAGS -D_OSF_SOURCE"
42 #    ;;
43 #esac
45 dnl Checks for programs.
46 AM_PROG_CC_C_O
47 AC_PROG_INSTALL
48 AC_PROG_LN_S
49 # AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
51 # AC_PROG_SED is only available in Autoconf >= 2.59b; workaround for older
52 # versions
53 ifdef([AC_PROG_SED], [AC_PROG_SED], [
54 AC_CHECK_PROGS(SED, [gsed sed])
57 AC_PROG_GCC_TRADITIONAL
59 # We need to test for at least gcc 2.95 here, because older versions don't
60 # have -fno-strict-aliasing
61 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
62 #if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
63 #error
64 #endif])], have_gcc295=yes, have_gcc295=no)
66 if test "$GCC" = "yes" ; then
67         # Enable many gcc warnings by default...
68         CFLAGS="$CFLAGS -Wall"
69         # And disable the strict-aliasing optimization, since it breaks
70         # our sockaddr-handling code in strange ways.
71         if test x$have_gcc295 = xyes; then
72                 CFLAGS="$CFLAGS -fno-strict-aliasing"
73         fi
76 # OS X Lion started deprecating the system openssl. Let's just disable
77 # all deprecation warnings on OS X.
78 case "$host_os" in
80  darwin*)
81     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
82     ;;
83 esac
85 AC_ARG_ENABLE(gcc-warnings,
86      AS_HELP_STRING(--disable-gcc-warnings, disable verbose warnings with GCC))
88 AC_ARG_ENABLE(gcc-hardening,
89      AS_HELP_STRING(--enable-gcc-hardening, enable compiler security checks),
90 [if test x$enableval = xyes; then
91     CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector-all"
92     CFLAGS="$CFLAGS -fwrapv -fPIE -Wstack-protector"
93     CFLAGS="$CFLAGS --param ssp-buffer-size=1"
94 fi])
96 AC_ARG_ENABLE(thread-support,
97      AS_HELP_STRING(--disable-thread-support, disable support for threading),
98         [], [enable_thread_support=yes])
99 AC_ARG_ENABLE(malloc-replacement,
100      AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
101         [], [enable_malloc_replacement=yes])
102 AC_ARG_ENABLE(openssl,
103      AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
104         [], [enable_openssl=yes])
105 AC_ARG_ENABLE(debug-mode,
106      AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
107         [], [enable_debug_mode=yes])
108 AC_ARG_ENABLE([libevent-install],
109      AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
110         [], [enable_libevent_install=yes])
111 AC_ARG_ENABLE([libevent-regress],
112      AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
113         [], [enable_libevent_regress=yes])
114 AC_ARG_ENABLE([samples],
115      AS_HELP_STRING([--disable-samples, skip building of sample programs]),
116         [], [enable_samples=yes])
117 AC_ARG_ENABLE([function-sections],
118      AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
119         [], [enable_function_sections=no])
120 AC_ARG_ENABLE([verbose-debug],
121                 AS_HELP_STRING([--enable-verbose-debug, verbose debug logging]),
122         [], [enable_verbose_debug=no])
125 AC_PROG_LIBTOOL
127 dnl   Uncomment "AC_DISABLE_SHARED" to make shared libraries not get
128 dnl   built by default.  You can also turn shared libs on and off from
129 dnl   the command line with --enable-shared and --disable-shared.
130 dnl AC_DISABLE_SHARED
131 AC_SUBST(LIBTOOL_DEPS)
133 AM_CONDITIONAL([BUILD_SAMPLES], [test "$enable_samples" = "yes"])
134 AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
136 dnl Checks for libraries.
137 AC_SEARCH_LIBS([inet_ntoa], [nsl])
138 AC_SEARCH_LIBS([socket], [socket])
139 AC_SEARCH_LIBS([inet_aton], [resolv])
140 AC_SEARCH_LIBS([clock_gettime], [rt])
141 AC_SEARCH_LIBS([sendfile], [sendfile])
143 dnl - check if the macro _WIN32 is defined on this compiler.
144 dnl - (this is how we check for a windows compiler)
145 AC_MSG_CHECKING(for WIN32)
146 AC_TRY_COMPILE(,
147         [
148 #ifndef _WIN32
149 die horribly
150 #endif
151         ],
152         bwin32=true; AC_MSG_RESULT(yes),
153         bwin32=false; AC_MSG_RESULT(no),
156 dnl - check if the macro __CYGWIN__ is defined on this compiler.
157 dnl - (this is how we check for a cygwin version of GCC)
158 AC_MSG_CHECKING(for CYGWIN)
159 AC_TRY_COMPILE(,
160         [
161 #ifndef __CYGWIN__
162 die horribly
163 #endif
164         ],
165         cygwin=true; AC_MSG_RESULT(yes),
166         cygwin=false; AC_MSG_RESULT(no),
169 AC_CHECK_HEADERS([zlib.h])
171 if test "x$ac_cv_header_zlib_h" = "xyes"; then
172 dnl Determine if we have zlib for regression tests
173 dnl Don't put this one in LIBS
174 save_LIBS="$LIBS"
175 LIBS=""
176 ZLIB_LIBS=""
177 have_zlib=no
178 AC_SEARCH_LIBS([inflateEnd], [z],
179         [have_zlib=yes
180         ZLIB_LIBS="$LIBS"
181         AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
182 LIBS="$save_LIBS"
183 AC_SUBST(ZLIB_LIBS)
185 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
187 dnl See if we have openssl.  This doesn't go in LIBS either.
188 if test "$bwin32" = true; then
189   EV_LIB_WS32=-lws2_32
190   EV_LIB_GDI=-lgdi32
191 else
192   EV_LIB_WS32=
193   EV_LIB_GDI=
195 AC_SUBST(EV_LIB_WS32)
196 AC_SUBST(EV_LIB_GDI)
197 AC_SUBST(OPENSSL_LIBADD)
199 AC_SYS_LARGEFILE
201 LIBEVENT_OPENSSL
203 dnl Checks for header files.
204 AC_CHECK_HEADERS([ \
205   arpa/inet.h \
206   fcntl.h \
207   ifaddrs.h \
208   mach/mach_time.h \
209   netdb.h \
210   netinet/in.h \
211   netinet/in6.h \
212   netinet/tcp.h \
213   poll.h \
214   port.h \
215   stdarg.h \
216   stddef.h \
217   sys/devpoll.h \
218   sys/epoll.h \
219   sys/event.h \
220   sys/eventfd.h \
221   sys/ioctl.h \
222   sys/mman.h \
223   sys/param.h \
224   sys/queue.h \
225   sys/resource.h \
226   sys/select.h \
227   sys/sendfile.h \
228   sys/socket.h \
229   sys/stat.h \
230   sys/time.h \
231   sys/timerfd.h \
232   sys/uio.h \
233   sys/wait.h \
236 AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
237 #ifdef HAVE_SYS_PARAM_H
238 #include <sys/param.h>
239 #endif
241 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
242         AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
243         AC_EGREP_CPP(yes,
245 #include <sys/queue.h>
246 #ifdef TAILQ_FOREACH
247  yes
248 #endif
249 ],      [AC_MSG_RESULT(yes)
250          AC_DEFINE(HAVE_TAILQFOREACH, 1,
251                 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
252         AC_MSG_RESULT(no)
253         )
256 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
257         AC_MSG_CHECKING(for timeradd in sys/time.h)
258         AC_EGREP_CPP(yes,
260 #include <sys/time.h>
261 #ifdef timeradd
262  yes
263 #endif
264 ],      [ AC_DEFINE(HAVE_TIMERADD, 1,
265                 [Define if timeradd is defined in <sys/time.h>])
266           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
270 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
271         AC_MSG_CHECKING(for timercmp in sys/time.h)
272         AC_EGREP_CPP(yes,
274 #include <sys/time.h>
275 #ifdef timercmp
276  yes
277 #endif
278 ],      [ AC_DEFINE(HAVE_TIMERCMP, 1,
279                 [Define if timercmp is defined in <sys/time.h>])
280           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
284 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
285         AC_MSG_CHECKING(for timerclear in sys/time.h)
286         AC_EGREP_CPP(yes,
288 #include <sys/time.h>
289 #ifdef timerclear
290  yes
291 #endif
292 ],      [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
293                 [Define if timerclear is defined in <sys/time.h>])
294           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
298 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
299         AC_MSG_CHECKING(for timerisset in sys/time.h)
300         AC_EGREP_CPP(yes,
302 #include <sys/time.h>
303 #ifdef timerisset
304  yes
305 #endif
306 ],      [ AC_DEFINE(HAVE_TIMERISSET, 1,
307                 [Define if timerisset is defined in <sys/time.h>])
308           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
312 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
313         AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
314            [[#include <sys/types.h>
315              #include <sys/sysctl.h>]]
316         )
319 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
320 AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
321 AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue)
323 if test x$bwin32 = xtrue; then
324    AC_SEARCH_LIBS([getservbyname],[ws2_32])
327 dnl Checks for typedefs, structures, and compiler characteristics.
328 AC_C_CONST
329 AC_C_INLINE
330 AC_HEADER_TIME
332 dnl Checks for library functions.
333 AC_CHECK_FUNCS([ \
334   accept4 \
335   arc4random \
336   arc4random_buf \
337   clock_gettime \
338   eventfd \
339   epoll_create1 \
340   fcntl \
341   getegid \
342   geteuid \
343   getifaddrs \
344   getnameinfo \
345   getprotobynumber \
346   gettimeofday \
347   inet_ntop \
348   inet_pton \
349   issetugid \
350   mach_absolute_time \
351   mmap \
352   nanosleep \
353   pipe \
354   pipe2 \
355   putenv \
356   sendfile \
357   setenv \
358   setrlimit \
359   sigaction \
360   signal \
361   splice \
362   strlcpy \
363   strsep \
364   strtok_r \
365   strtoll \
366   sysctl \
367   timerfd_create \
368   umask \
369   unsetenv \
370   usleep \
371   vasprintf \
372   getservbyname \
374 AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
376 AC_CACHE_CHECK(
377     [for getaddrinfo],
378     [libevent_cv_getaddrinfo],
379     [AC_LINK_IFELSE(
380         [AC_LANG_PROGRAM(
381             [[
382                 #ifdef HAVE_NETDB_H
383                 #include <netdb.h>
384                 #endif
385             ]],
386             [[
387                 getaddrinfo;
388             ]]
389         )],
390         [libevent_cv_getaddrinfo=yes],
391         [libevent_cv_getaddrinfo=no]
392     )]
394 if test "$libevent_cv_getaddrinfo" = "yes" ; then
395     AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
396 else
398 # Check for gethostbyname_r in all its glorious incompatible versions.
399 #   (This is cut-and-pasted from Tor, which based its logic on
400 #   Python's configure.in.)
401 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
402   [Define this if you have any gethostbyname_r()])
404 AC_CHECK_FUNC(gethostbyname_r, [
405   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
406   OLD_CFLAGS=$CFLAGS
407   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
408   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
409 #include <netdb.h>
410   ], [[
411     char *cp1, *cp2;
412     struct hostent *h1, *h2;
413     int i1, i2;
414     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
415   ]])],[
416     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
417     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
418      [Define this if gethostbyname_r takes 6 arguments])
419     AC_MSG_RESULT(6)
420   ], [
421     AC_TRY_COMPILE([
422 #include <netdb.h>
423     ], [
424       char *cp1, *cp2;
425       struct hostent *h1;
426       int i1, i2;
427       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
428     ], [
429       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
430       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
431         [Define this if gethostbyname_r takes 5 arguments])
432       AC_MSG_RESULT(5)
433    ], [
434       AC_TRY_COMPILE([
435 #include <netdb.h>
436      ], [
437        char *cp1;
438        struct hostent *h1;
439        struct hostent_data hd;
440        (void) gethostbyname_r(cp1,h1,&hd);
441      ], [
442        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
443        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
444          [Define this if gethostbyname_r takes 3 arguments])
445        AC_MSG_RESULT(3)
446      ], [
447        AC_MSG_RESULT(0)
448      ])
449   ])
450  ])
451  CFLAGS=$OLD_CFLAGS
456 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
457 AC_EGREP_CPP(yes,
459 #define _GNU_SOURCE
460 #include <fcntl.h>
461 #ifdef F_SETFD
463 #endif
464 ],      [ AC_DEFINE(HAVE_SETFD, 1,
465               [Define if F_SETFD is defined in <fcntl.h>])
466           AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
468 needsignal=no
469 haveselect=no
470 if test x$bwin32 != xtrue; then
471     AC_CHECK_FUNCS(select, [haveselect=yes], )
472     if test "x$haveselect" = "xyes" ; then
473         needsignal=yes
474     fi
476 AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
478 havepoll=no
479 AC_CHECK_FUNCS(poll, [havepoll=yes], )
480 if test "x$havepoll" = "xyes" ; then
481         needsignal=yes
483 AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
485 havedevpoll=no
486 if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
487         AC_DEFINE(HAVE_DEVPOLL, 1,
488                     [Define if /dev/poll is available])
490 AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
492 havekqueue=no
493 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
494         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
495         if test "x$havekqueue" = "xyes" ; then
496                 AC_MSG_CHECKING(for working kqueue)
497                 AC_TRY_RUN(
498 #include <sys/types.h>
499 #include <sys/time.h>
500 #include <sys/event.h>
501 #include <stdio.h>
502 #include <unistd.h>
503 #include <fcntl.h>
506 main(int argc, char **argv)
508         int kq;
509         int n;
510         int fd[[2]];
511         struct kevent ev;
512         struct timespec ts;
513         char buf[[8000]];
515         if (pipe(fd) == -1)
516                 exit(1);
517         if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
518                 exit(1);
520         while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
521                 ;
523         if ((kq = kqueue()) == -1)
524                 exit(1);
526         memset(&ev, 0, sizeof(ev));
527         ev.ident = fd[[1]];
528         ev.filter = EVFILT_WRITE;
529         ev.flags = EV_ADD | EV_ENABLE;
530         n = kevent(kq, &ev, 1, NULL, 0, NULL);
531         if (n == -1)
532                 exit(1);
534         read(fd[[0]], buf, sizeof(buf));
536         ts.tv_sec = 0;
537         ts.tv_nsec = 0;
538         n = kevent(kq, NULL, 0, &ev, 1, &ts);
539         if (n == -1 || n == 0)
540                 exit(1);
542         exit(0);
543 }, [AC_MSG_RESULT(yes)
544     AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
545                 [Define if kqueue works correctly with pipes])
546     havekqueue=yes
547     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
548         fi
550 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
552 haveepollsyscall=no
553 haveepoll=no
554 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
555 if test "x$haveepoll" = "xyes" ; then
556         AC_DEFINE(HAVE_EPOLL, 1,
557                 [Define if your system supports the epoll system calls])
558         needsignal=yes
560 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
561         if test "x$haveepoll" = "xno" ; then
562                 AC_MSG_CHECKING(for epoll system call)
563                 AC_TRY_RUN(
564 #include <stdint.h>
565 #include <sys/param.h>
566 #include <sys/types.h>
567 #include <sys/syscall.h>
568 #include <sys/epoll.h>
569 #include <unistd.h>
572 epoll_create(int size)
574         return (syscall(__NR_epoll_create, size));
578 main(int argc, char **argv)
580         int epfd;
582         epfd = epoll_create(256);
583         exit (epfd == -1 ? 1 : 0);
584 }, [AC_MSG_RESULT(yes)
585     AC_DEFINE(HAVE_EPOLL, 1,
586         [Define if your system supports the epoll system calls])
587     needsignal=yes
588     have_epoll=yes
589     AC_LIBOBJ(epoll_sub)
590     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
591         fi
593 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
595 haveeventports=no
596 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
597 if test "x$haveeventports" = "xyes" ; then
598         AC_DEFINE(HAVE_EVENT_PORTS, 1,
599                 [Define if your system supports event ports])
600         needsignal=yes
602 AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
604 if test "x$bwin32" = "xtrue"; then
605         needsignal=yes
608 AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
610 AC_TYPE_PID_T
611 AC_TYPE_SIZE_T
612 AC_TYPE_SSIZE_T
614 AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
615 [#ifdef HAVE_STDINT_H
616 #include <stdint.h>
617 #elif defined(HAVE_INTTYPES_H)
618 #include <inttypes.h>
619 #endif
620 #ifdef HAVE_SYS_TYPES_H
621 #include <sys/types.h>
622 #endif])
624 AC_CHECK_TYPES([fd_mask], , ,
625 [#ifdef HAVE_SYS_TYPES_H
626 #include <sys/types.h>
627 #endif
628 #ifdef HAVE_SYS_SELECT_H
629 #include <sys/select.h>
630 #endif])
632 AC_CHECK_SIZEOF(long long)
633 AC_CHECK_SIZEOF(long)
634 AC_CHECK_SIZEOF(int)
635 AC_CHECK_SIZEOF(short)
636 AC_CHECK_SIZEOF(size_t)
637 AC_CHECK_SIZEOF(void *)
638 AC_CHECK_SIZEOF(off_t)
640 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
641 [#define _GNU_SOURCE
642 #include <sys/types.h>
643 #ifdef HAVE_NETINET_IN_H
644 #include <netinet/in.h>
645 #endif
646 #ifdef HAVE_NETINET_IN6_H
647 #include <netinet/in6.h>
648 #endif
649 #ifdef HAVE_SYS_SOCKET_H
650 #include <sys/socket.h>
651 #endif
652 #ifdef HAVE_NETDB_H
653 #include <netdb.h>
654 #endif
655 #ifdef _WIN32
656 #define WIN32_WINNT 0x400
657 #define _WIN32_WINNT 0x400
658 #define WIN32_LEAN_AND_MEAN
659 #if defined(_MSC_VER) && (_MSC_VER < 1300)
660 #include <winsock.h>
661 #else
662 #include <winsock2.h>
663 #include <ws2tcpip.h>
664 #endif
665 #endif
667 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], , ,
668 [#include <sys/types.h>
669 #ifdef HAVE_NETINET_IN_H
670 #include <netinet/in.h>
671 #endif
672 #ifdef HAVE_NETINET_IN6_H
673 #include <netinet/in6.h>
674 #endif
675 #ifdef HAVE_SYS_SOCKET_H
676 #include <sys/socket.h>
677 #endif
678 #ifdef _WIN32
679 #define WIN32_WINNT 0x400
680 #define _WIN32_WINNT 0x400
681 #define WIN32_LEAN_AND_MEAN
682 #if defined(_MSC_VER) && (_MSC_VER < 1300)
683 #include <winsock.h>
684 #else
685 #include <winsock2.h>
686 #include <ws2tcpip.h>
687 #endif
688 #endif
691 AC_CHECK_TYPES([struct so_linger],
692 [#define HAVE_SO_LINGER], ,
694 #ifdef HAVE_SYS_SOCKET_H
695 #include <sys/socket.h>
696 #endif
699 AC_MSG_CHECKING([for socklen_t])
700 AC_TRY_COMPILE([
701  #include <sys/types.h>
702  #include <sys/socket.h>],
703   [socklen_t x;],
704   AC_MSG_RESULT([yes]),
705   [AC_MSG_RESULT([no])
706   AC_DEFINE(socklen_t, unsigned int,
707         [Define to unsigned int if you dont have it])]
710 AC_MSG_CHECKING([whether our compiler supports __func__])
711 AC_TRY_COMPILE([],
712  [ const char *cp = __func__; ],
713  AC_MSG_RESULT([yes]),
714  AC_MSG_RESULT([no])
715  AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
716  AC_TRY_COMPILE([],
717    [ const char *cp = __FUNCTION__; ],
718    AC_MSG_RESULT([yes])
719    AC_DEFINE(__func__, __FUNCTION__,
720          [Define to appropriate substitue if compiler doesnt have __func__]),
721    AC_MSG_RESULT([no])
722    AC_DEFINE(__func__, __FILE__,
723          [Define to appropriate substitue if compiler doesnt have __func__])))
726 # check if we can compile with pthreads
727 have_pthreads=no
728 if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
729   ACX_PTHREAD([
730         AC_DEFINE(HAVE_PTHREADS, 1,
731                 [Define if we have pthreads on this system])
732         have_pthreads=yes])
733   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
734   AC_CHECK_SIZEOF(pthread_t, ,
735      [AC_INCLUDES_DEFAULT()
736       #include <pthread.h> ]
737   )
739 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
741 # check if we should compile locking into the library
742 if test x$enable_thread_support = xno; then
743    AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
744         [Define if libevent should not be compiled with thread support])
747 # check if we should hard-code the mm functions.
748 if test x$enable_malloc_replacement = xno; then
749   AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
750         [Define if libevent should not allow replacing the mm functions])
753 # check if we should hard-code debugging out
754 if test x$enable_debug_mode = xno; then
755   AC_DEFINE(DISABLE_DEBUG_MODE, 1,
756         [Define if libevent should build without support for a debug mode])
759 # check if we should enable verbose debugging 
760 if test x$enable_verbose_debug = xyes; then
761         CFLAGS="$CFLAGS -DUSE_DEBUG"
764 # check if we have and should use openssl
765 AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
766 if test "x$enable_openssl" = "xyes"; then
767         AC_SEARCH_LIBS([ERR_remove_thread_state], [crypto],
768                 [AC_DEFINE(HAVE_ERR_REMOVE_THREAD_STATE, 1, [Define to 1 if you have ERR_remove_thread_stat().])])
771 # Add some more warnings which we use in development but not in the
772 # released versions.  (Some relevant gcc versions can't handle these.)
773 if test x$enable_gcc_warnings != xno && test "$GCC" = "yes"; then
775   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
776 #if !defined(__GNUC__) || (__GNUC__ < 4)
777 #error
778 #endif])], have_gcc4=yes, have_gcc4=no)
780   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
781 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
782 #error
783 #endif])], have_gcc42=yes, have_gcc42=no)
785   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
786 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
787 #error
788 #endif])], have_gcc45=yes, have_gcc45=no)
790   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
791 #if !defined(__clang__)
792 #error
793 #endif])], have_clang=yes, have_clang=no)
795   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"
796   if test x$enable_gcc_warnings = xyes; then
797     CFLAGS="$CFLAGS -Werror"
798   fi
800   CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
802   if test x$have_gcc4 = xyes ; then
803     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
804     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
805     #CFLAGS="$CFLAGS -Wold-style-definition"
806   fi
808   if test x$have_gcc42 = xyes ; then
809     # These warnings break gcc 4.0.2 and work on gcc 4.2
810     CFLAGS="$CFLAGS -Waddress"
811   fi
813   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
814     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
815     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
816   fi
818   if test x$have_gcc45 = xyes ; then
819     # These warnings work on gcc 4.5
820     CFLAGS="$CFLAGS -Wlogical-op"
821   fi
823   if test x$have_clang = xyes; then
824     # Disable the unused-function warnings, because these trigger
825     # for minheap-internal.h related code.
826     CFLAGS="$CFLAGS -Wno-unused-function"
828     # clang on macosx emits warnigns for each directory specified which
829     # isn't "used" generating a lot of build noise (typically 3 warnings
830     # per file
831     case "$host_os" in
832         darwin*)
833             CFLAGS="$CFLAGS -Qunused-arguments"
834         ;;
835     esac
836   fi
838 ##This will break the world on some 64-bit architectures
839 # CFLAGS="$CFLAGS -Winline"
843 LIBEVENT_GC_SECTIONS=
844 if test "$GCC" = yes && test "$enable_function_sections" = yes ; then
845     AC_CACHE_CHECK(
846         [if linker supports omitting unused code and data],
847         [libevent_cv_gc_sections_runs],
848         [
849             dnl  NetBSD will link but likely not run with --gc-sections
850             dnl  http://bugs.ntp.org/1844
851             dnl  http://gnats.netbsd.org/40401
852             dnl  --gc-sections causes attempt to load as linux elf, with
853             dnl  wrong syscalls in place.  Test a little gauntlet of
854             dnl  simple stdio read code checking for errors, expecting
855             dnl  enough syscall differences that the NetBSD code will
856             dnl  fail even with Linux emulation working as designed.
857             dnl  A shorter test could be refined by someone with access
858             dnl  to a NetBSD host with Linux emulation working.
859             origCFLAGS="$CFLAGS"
860             CFLAGS="$CFLAGS -Wl,--gc-sections"
861             AC_LINK_IFELSE(
862                 [AC_LANG_PROGRAM(
863                     [[
864                         #include <stdlib.h>
865                         #include <stdio.h>
866                     ]],
867                     [[
868                         FILE *  fpC;
869                         char    buf[32];
870                         size_t  cch;
871                         int     read_success_once;
873                         fpC = fopen("conftest.c", "r");
874                         if (NULL == fpC)
875                                 exit(1);
876                         do {
877                                 cch = fread(buf, sizeof(buf), 1, fpC);
878                                 read_success_once |= (0 != cch);
879                         } while (0 != cch);
880                         if (!read_success_once)
881                                 exit(2);
882                         if (!feof(fpC))
883                                 exit(3);
884                         if (0 != fclose(fpC))
885                                 exit(4);
887                         exit(EXIT_SUCCESS);
888                     ]]
889                 )],
890                 [
891                     dnl We have to do this invocation manually so that we can
892                     dnl get the output of conftest.err to make sure it doesn't
893                     dnl mention gc-sections.
894                     if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
895                         libevent_cv_gc_sections_runs=no
896                     else
897                         libevent_cv_gc_sections_runs=no
898                         ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
899                     fi
900                 ],
901                 [libevent_cv_gc_sections_runs=no]
902             )
903             CFLAGS="$origCFLAGS"
904             AS_UNSET([origCFLAGS])
905         ]
906     )
907     case "$libevent_cv_gc_sections_runs" in
908      yes)
909         CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
910         LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
911         ;;
912     esac
914 AC_SUBST([LIBEVENT_GC_SECTIONS])
916 AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
918 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] )
919 AC_OUTPUT(Makefile)