1dnl Copyright 2000-2007 Niels Provos
2dnl Copyright 2007-2012 Niels Provos and Nick Mathewson
3dnl
4dnl See LICENSE for copying information.
5dnl
6dnl Original version Dug Song <dugsong@monkey.org>
7
8AC_INIT(libevent,2.1.12-stable)
9AC_PREREQ(2.67)
10AC_CONFIG_SRCDIR(event.c)
11
12AC_CONFIG_MACRO_DIR([m4])
13AC_CONFIG_AUX_DIR([build-aux])
14AM_INIT_AUTOMAKE
15dnl AM_SILENT_RULES req. automake 1.11.  [no] defaults V=1
16AM_SILENT_RULES([yes])
17AC_CONFIG_HEADERS(config.h  evconfig-private.h:evconfig-private.h.in)
18AC_DEFINE(NUMERIC_VERSION, 0x02010c00, [Numeric representation of the version])
19
20dnl Initialize prefix.
21AC_PREFIX_DEFAULT([/usr/local])
22
23dnl Try and get a full POSIX environment on obscure systems
24AC_USE_SYSTEM_EXTENSIONS
25
26AC_CANONICAL_BUILD
27AC_CANONICAL_HOST
28dnl the 'build' machine is where we run configure and compile
29dnl the 'host' machine is where the resulting stuff runs.
30
31#case "$host_os" in
32#
33# osf5*)
34#    CFLAGS="$CFLAGS -D_OSF_SOURCE"
35#    ;;
36#esac
37
38dnl Checks for programs.
39AM_PROG_CC_C_O
40AC_PROG_INSTALL
41AC_PROG_LN_S
42# AC_PROG_MKDIR_P - $(MKDIR_P) should be defined by AM_INIT_AUTOMAKE
43
44AC_PROG_SED
45
46AC_PROG_GCC_TRADITIONAL
47
48# We need to test for at least gcc 2.95 here, because older versions don't
49# have -fno-strict-aliasing
50AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
51#if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
52#error
53#endif])], have_gcc295=yes, have_gcc295=no)
54
55if test "$GCC" = "yes" ; then
56        # Enable many gcc warnings by default...
57        CFLAGS="$CFLAGS -Wall"
58          # And disable the strict-aliasing optimization, since it breaks
59          # our sockaddr-handling code in strange ways.
60          if test x$have_gcc295 = xyes; then
61                    CFLAGS="$CFLAGS -fno-strict-aliasing"
62          fi
63fi
64
65# OS X Lion started deprecating the system openssl. Let's just disable
66# all deprecation warnings on OS X; but do so only for gcc...
67if test "$GCC" = "yes" ; then
68          case "$host_os" in
69           darwin*)
70              CFLAGS="$CFLAGS -Wno-deprecated-declarations"
71              ;;
72          esac
73fi
74
75AC_ARG_ENABLE(gcc-warnings,
76     AS_HELP_STRING(--disable-gcc-warnings, disable verbose warnings with GCC))
77
78AC_ARG_ENABLE(gcc-hardening,
79     AS_HELP_STRING(--enable-gcc-hardening, enable compiler security checks),
80[if test x$enableval = xyes; then
81    CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector-all"
82    CFLAGS="$CFLAGS -fwrapv -fPIE -Wstack-protector"
83    CFLAGS="$CFLAGS --param ssp-buffer-size=1"
84fi])
85
86AC_ARG_ENABLE(thread-support,
87     AS_HELP_STRING(--disable-thread-support, disable support for threading),
88          [], [enable_thread_support=yes])
89AC_ARG_ENABLE(malloc-replacement,
90     AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
91        [], [enable_malloc_replacement=yes])
92AC_ARG_ENABLE(openssl,
93     AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
94        [], [enable_openssl=yes])
95AC_ARG_ENABLE(debug-mode,
96     AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
97        [], [enable_debug_mode=yes])
98AC_ARG_ENABLE([libevent-install],
99     AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
100          [], [enable_libevent_install=yes])
101AC_ARG_ENABLE([libevent-regress],
102     AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
103          [], [enable_libevent_regress=yes])
104AC_ARG_ENABLE([samples],
105     AS_HELP_STRING([--disable-samples, skip building of sample programs]),
106          [], [enable_samples=yes])
107AC_ARG_ENABLE([function-sections],
108     AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
109          [], [enable_function_sections=no])
110AC_ARG_ENABLE([verbose-debug],
111                    AS_HELP_STRING([--enable-verbose-debug, verbose debug logging]),
112          [], [enable_verbose_debug=no])
113AC_ARG_ENABLE([clock-gettime],
114     AS_HELP_STRING(--disable-clock-gettime, do not use clock_gettime even if it is available),
115  [], [enable_clock_gettime=yes])
116
117
118LT_PREREQ([2.4.2])
119LT_INIT
120
121dnl   Uncomment "AC_DISABLE_SHARED" to make shared libraries not get
122dnl   built by default.  You can also turn shared libs on and off from
123dnl   the command line with --enable-shared and --disable-shared.
124dnl AC_DISABLE_SHARED
125AC_SUBST(LIBTOOL_DEPS)
126
127AM_CONDITIONAL([BUILD_SAMPLES], [test "$enable_samples" = "yes"])
128AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
129
130dnl Checks for libraries.
131AC_SEARCH_LIBS([inet_ntoa], [nsl])
132AC_SEARCH_LIBS([socket], [socket])
133AC_SEARCH_LIBS([inet_aton], [resolv])
134if test "x$enable_clock_gettime" = "xyes"; then
135  AC_SEARCH_LIBS([clock_gettime], [rt])
136  AC_CHECK_FUNCS([clock_gettime])
137fi
138AC_SEARCH_LIBS([sendfile], [sendfile])
139
140dnl - check if the macro _WIN32 is defined on this compiler.
141dnl - (this is how we check for a windows compiler)
142AC_MSG_CHECKING(for WIN32)
143AC_COMPILE_IFELSE(
144  [AC_LANG_PROGRAM([],
145    [
146#ifndef _WIN32
147die horribly
148#endif
149    ]
150  )],
151          [bwin32=true; AC_MSG_RESULT(yes)],
152          [bwin32=false; AC_MSG_RESULT(no)]
153)
154
155dnl - check if the macro __midipix__ is defined on this compiler.
156dnl - (this is how we check for a midipix version of GCC)
157AC_MSG_CHECKING(for MIDIPIX)
158AC_COMPILE_IFELSE(
159  [AC_LANG_PROGRAM([],
160    [
161#ifndef __midipix__
162die horribly
163#endif
164    ]
165  )],
166          [midipix=true; AC_MSG_RESULT(yes)],
167          [midipix=false; AC_MSG_RESULT(no)]
168)
169
170dnl - check if the macro __CYGWIN__ is defined on this compiler.
171dnl - (this is how we check for a cygwin version of GCC)
172AC_MSG_CHECKING(for CYGWIN)
173AC_COMPILE_IFELSE(
174  [AC_LANG_PROGRAM([],
175    [
176#ifndef __CYGWIN__
177die horribly
178#endif
179    ]
180  )],
181          [cygwin=true; AC_MSG_RESULT(yes)],
182          [cygwin=false; AC_MSG_RESULT(no)]
183)
184
185AC_CHECK_HEADERS([zlib.h])
186
187if test "x$ac_cv_header_zlib_h" = "xyes"; then
188dnl Determine if we have zlib for regression tests
189dnl Don't put this one in LIBS
190save_LIBS="$LIBS"
191LIBS=""
192ZLIB_LIBS=""
193have_zlib=no
194AC_SEARCH_LIBS([inflateEnd], [z],
195          [have_zlib=yes
196          ZLIB_LIBS="$LIBS"
197          AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
198LIBS="$save_LIBS"
199AC_SUBST(ZLIB_LIBS)
200fi
201AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
202
203dnl See if we have openssl.  This doesn't go in LIBS either.
204if test "$bwin32" = true; then
205  EV_LIB_WS32=-lws2_32
206  EV_LIB_GDI=-lgdi32
207else
208  EV_LIB_WS32=
209  EV_LIB_GDI=
210fi
211AC_SUBST(EV_LIB_WS32)
212AC_SUBST(EV_LIB_GDI)
213AC_SUBST(OPENSSL_LIBADD)
214
215AC_SYS_LARGEFILE
216
217LIBEVENT_OPENSSL
218
219dnl Checks for header files.
220AC_CHECK_HEADERS([ \
221  arpa/inet.h \
222  fcntl.h \
223  ifaddrs.h \
224  mach/mach_time.h \
225  mach/mach.h \
226  netdb.h \
227  netinet/in.h \
228  netinet/in6.h \
229  netinet/tcp.h \
230  sys/un.h \
231  poll.h \
232  port.h \
233  stdarg.h \
234  stddef.h \
235  sys/devpoll.h \
236  sys/epoll.h \
237  sys/event.h \
238  sys/eventfd.h \
239  sys/ioctl.h \
240  sys/mman.h \
241  sys/param.h \
242  sys/queue.h \
243  sys/resource.h \
244  sys/select.h \
245  sys/sendfile.h \
246  sys/socket.h \
247  sys/stat.h \
248  sys/time.h \
249  sys/timerfd.h \
250  sys/uio.h \
251  sys/wait.h \
252  sys/random.h \
253  errno.h \
254  afunix.h \
255])
256
257case "${host_os}" in
258    linux*) ;;
259    *)
260        AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
261        #ifdef HAVE_SYS_PARAM_H
262        #include <sys/param.h>
263        #endif
264        ])
265esac
266
267if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
268          AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
269          AC_EGREP_CPP(yes,
270[
271#include <sys/queue.h>
272#ifdef TAILQ_FOREACH
273 yes
274#endif
275],        [AC_MSG_RESULT(yes)
276           AC_DEFINE(HAVE_TAILQFOREACH, 1,
277                    [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
278          AC_MSG_RESULT(no)
279          )
280fi
281
282if test "x$ac_cv_header_sys_time_h" = "xyes"; then
283          AC_MSG_CHECKING(for timeradd in sys/time.h)
284          AC_EGREP_CPP(yes,
285[
286#include <sys/time.h>
287#ifdef timeradd
288 yes
289#endif
290],        [ AC_DEFINE(HAVE_TIMERADD, 1,
291                    [Define if timeradd is defined in <sys/time.h>])
292            AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
293)
294fi
295
296if test "x$ac_cv_header_sys_time_h" = "xyes"; then
297          AC_MSG_CHECKING(for timercmp in sys/time.h)
298          AC_EGREP_CPP(yes,
299[
300#include <sys/time.h>
301#ifdef timercmp
302 yes
303#endif
304],        [ AC_DEFINE(HAVE_TIMERCMP, 1,
305                    [Define if timercmp is defined in <sys/time.h>])
306            AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
307)
308fi
309
310if test "x$ac_cv_header_sys_time_h" = "xyes"; then
311          AC_MSG_CHECKING(for timerclear in sys/time.h)
312          AC_EGREP_CPP(yes,
313[
314#include <sys/time.h>
315#ifdef timerclear
316 yes
317#endif
318],        [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
319                    [Define if timerclear is defined in <sys/time.h>])
320            AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
321)
322fi
323
324if test "x$ac_cv_header_sys_time_h" = "xyes"; then
325          AC_MSG_CHECKING(for timerisset in sys/time.h)
326          AC_EGREP_CPP(yes,
327[
328#include <sys/time.h>
329#ifdef timerisset
330 yes
331#endif
332],        [ AC_DEFINE(HAVE_TIMERISSET, 1,
333                    [Define if timerisset is defined in <sys/time.h>])
334            AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
335)
336fi
337
338if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
339          AC_CHECK_DECLS([CTL_KERN, KERN_ARND], [], [],
340             [[#include <sys/types.h>
341               #include <sys/sysctl.h>]]
342          )
343fi
344
345AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
346AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
347AM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue)
348AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue)
349
350if test x$bwin32 = xtrue; then
351  AC_CHECK_LIB([ws2_32], [main])
352fi
353
354dnl Checks for typedefs, structures, and compiler characteristics.
355AC_C_CONST
356AC_C_INLINE
357AC_HEADER_TIME
358
359dnl Checks for library functions.
360AC_CHECK_FUNCS([ \
361  accept4 \
362  arc4random \
363  arc4random_buf \
364  arc4random_addrandom \
365  eventfd \
366  epoll_create1 \
367  fcntl \
368  getegid \
369  geteuid \
370  getifaddrs \
371  gettimeofday \
372  issetugid \
373  mach_absolute_time \
374  mmap \
375  nanosleep \
376  pipe \
377  pipe2 \
378  putenv \
379  sendfile \
380  setenv \
381  setrlimit \
382  sigaction \
383  signal \
384  splice \
385  strlcpy \
386  strsep \
387  strtok_r \
388  strtoll \
389  sysctl \
390  timerfd_create \
391  umask \
392  unsetenv \
393  usleep \
394  vasprintf \
395  getrandom \
396])
397
398AS_IF([test x$bwin32 = xtrue],
399  AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)])
400)
401
402AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
403
404m4_define([funcstochk],
405  [getnameinfo
406  getprotobynumber
407  getservbyname
408  inet_ntop
409  inet_pton]
410)
411
412AS_IF([test x$bwin32 = xtrue],
413  [AX_CHECK_DECLS_EX([funcstochk getaddrinfo],
414    [#ifdef _WIN32
415    #include <winsock2.h>
416    #include <ws2tcpip.h>
417    #endif])],
418  [AC_CHECK_FUNCS(m4_normalize(funcstochk))]
419)
420
421m4_undefine([funcstochk])
422
423dnl check getaddrinfo and gethostbyname_r for non-windows
424AS_IF([test x$bwin32 = xfalse], [
425AC_CACHE_CHECK(
426    [for getaddrinfo],
427    [libevent_cv_getaddrinfo],
428    [AC_LINK_IFELSE(
429          [AC_LANG_PROGRAM(
430              [[
431                    #ifdef HAVE_NETDB_H
432                    #include <netdb.h>
433                    #endif
434              ]],
435              [[
436                    getaddrinfo;
437              ]]
438          )],
439          [libevent_cv_getaddrinfo=yes],
440          [libevent_cv_getaddrinfo=no]
441    )]
442)
443if test "$libevent_cv_getaddrinfo" = "yes" ; then
444    AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
445else
446
447# Check for gethostbyname_r in all its glorious incompatible versions.
448#   (This is cut-and-pasted from Tor, which based its logic on
449#   Python's configure.in.)
450AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
451  [Define this if you have any gethostbyname_r()])
452
453AC_CHECK_FUNC(gethostbyname_r, [
454  AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
455  OLD_CFLAGS=$CFLAGS
456  CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
457  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
458#include <netdb.h>
459  ], [[
460    char *cp1, *cp2;
461    struct hostent *h1, *h2;
462    int i1, i2;
463    (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
464  ]])],[
465    AC_DEFINE(HAVE_GETHOSTBYNAME_R)
466    AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
467     [Define this if gethostbyname_r takes 6 arguments])
468    AC_MSG_RESULT(6)
469  ], [
470    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
471#include <netdb.h>
472    ], [
473      char *cp1, *cp2;
474      struct hostent *h1;
475      int i1, i2;
476      (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
477    ])], [
478      AC_DEFINE(HAVE_GETHOSTBYNAME_R)
479      AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
480        [Define this if gethostbyname_r takes 5 arguments])
481      AC_MSG_RESULT(5)
482    ], [
483      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
484#include <netdb.h>
485     ], [
486       char *cp1;
487       struct hostent *h1;
488       struct hostent_data hd;
489       (void) gethostbyname_r(cp1,h1,&hd);
490     ])], [
491       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
492       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
493         [Define this if gethostbyname_r takes 3 arguments])
494       AC_MSG_RESULT(3)
495     ], [
496       AC_MSG_RESULT(0)
497     ])
498  ])
499 ])
500 CFLAGS=$OLD_CFLAGS
501])
502
503fi
504]) dnl end of checking getaddrinfo and gethostbyname_r
505
506AC_MSG_CHECKING(for F_SETFD in fcntl.h)
507AC_EGREP_CPP(yes,
508[
509#define _GNU_SOURCE 1
510#include <fcntl.h>
511#ifdef F_SETFD
512yes
513#endif
514],        [ AC_DEFINE(HAVE_SETFD, 1,
515                [Define if F_SETFD is defined in <fcntl.h>])
516            AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
517
518needsignal=no
519haveselect=no
520if test x$bwin32 != xtrue; then
521    AC_CHECK_FUNCS(select, [haveselect=yes], )
522    if test "x$haveselect" = "xyes" ; then
523          needsignal=yes
524    fi
525fi
526AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
527
528havepoll=no
529AC_CHECK_FUNCS(poll, [havepoll=yes], )
530if test "x$havepoll" = "xyes" ; then
531          needsignal=yes
532fi
533AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
534
535havedevpoll=no
536if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
537          AC_DEFINE(HAVE_DEVPOLL, 1,
538                        [Define if /dev/poll is available])
539fi
540AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
541
542havekqueue=no
543if test "x$ac_cv_header_sys_event_h" = "xyes"; then
544          AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
545          if test "x$havekqueue" = "xyes" ; then
546                    AC_MSG_CHECKING(for working kqueue)
547                    AC_RUN_IFELSE(
548      [AC_LANG_PROGRAM([
549#ifdef HAVE_STDLIB_H
550#include <stdlib.h>
551#endif
552#ifdef HAVE_STRING_H
553#include <string.h>
554#endif
555#include <sys/types.h>
556#include <sys/time.h>
557#include <sys/event.h>
558#include <stdio.h>
559#include <unistd.h>
560#include <fcntl.h>
561        ], [[
562          int kq;
563          int n;
564          int fd[2];
565          struct kevent ev;
566          struct timespec ts;
567          char buf[80000];
568
569          if (pipe(fd) == -1)
570                    return 1;
571          if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
572                    return 1;
573
574          while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
575                    ;
576
577          if ((kq = kqueue()) == -1)
578                    return 1;
579
580          memset(&ev, 0, sizeof(ev));
581          ev.ident = fd[1];
582          ev.filter = EVFILT_WRITE;
583          ev.flags = EV_ADD | EV_ENABLE;
584          n = kevent(kq, &ev, 1, NULL, 0, NULL);
585          if (n == -1)
586                    return 1;
587
588          read(fd[0], buf, sizeof(buf));
589
590          ts.tv_sec = 0;
591          ts.tv_nsec = 0;
592          n = kevent(kq, NULL, 0, &ev, 1, &ts);
593          if (n == -1 || n == 0)
594                    return 1;
595
596          return 0;
597        ]]
598      )],
599      [AC_MSG_RESULT(yes)
600      AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
601        [Define if kqueue works correctly with pipes])
602      havekqueue=yes
603      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
604    )
605          fi
606fi
607AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
608
609haveepollsyscall=no
610haveepoll=no
611AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
612if test "x$haveepoll" = "xyes" ; then
613          AC_DEFINE(HAVE_EPOLL, 1,
614                    [Define if your system supports the epoll system calls])
615          needsignal=yes
616fi
617if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
618          if test "x$haveepoll" = "xno" ; then
619                    AC_MSG_CHECKING(for epoll system call)
620                    AC_RUN_IFELSE(
621      [AC_LANG_PROGRAM([[
622#include <stdint.h>
623#include <sys/param.h>
624#include <sys/types.h>
625#include <sys/syscall.h>
626#include <sys/epoll.h>
627#include <unistd.h>
628
629int
630epoll_create(int size)
631{
632          return (syscall(__NR_epoll_create, size));
633}
634        ]],[[
635          int epfd;
636
637          epfd = epoll_create(256);
638          return (epfd == -1 ? 1 : 0);
639        ]]
640      )],
641      [AC_MSG_RESULT(yes)
642      AC_DEFINE(HAVE_EPOLL, 1,
643                [Define if your system supports the epoll system calls])
644      needsignal=yes
645      have_epoll=yes
646      AC_LIBOBJ(epoll_sub)
647      ], [AC_MSG_RESULT(no)], [AC_MSG_RESULT(no)]
648    )
649          fi
650fi
651AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
652
653haveeventports=no
654AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
655if test "x$haveeventports" = "xyes" ; then
656          AC_DEFINE(HAVE_EVENT_PORTS, 1,
657                    [Define if your system supports event ports])
658          needsignal=yes
659fi
660AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
661
662if test "x$bwin32" = "xtrue"; then
663          needsignal=yes
664fi
665
666AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
667
668AC_TYPE_PID_T
669AC_TYPE_SIZE_T
670AC_TYPE_SSIZE_T
671
672AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
673[#ifdef HAVE_STDINT_H
674#include <stdint.h>
675#elif defined(HAVE_INTTYPES_H)
676#include <inttypes.h>
677#endif
678#ifdef HAVE_SYS_TYPES_H
679#include <sys/types.h>
680#endif])
681
682AC_CHECK_TYPES([fd_mask], , ,
683[#ifdef HAVE_SYS_TYPES_H
684#include <sys/types.h>
685#endif
686#ifdef HAVE_SYS_SELECT_H
687#include <sys/select.h>
688#endif])
689
690AC_CHECK_SIZEOF(long long)
691AC_CHECK_SIZEOF(long)
692AC_CHECK_SIZEOF(int)
693AC_CHECK_SIZEOF(short)
694AC_CHECK_SIZEOF(size_t)
695AC_CHECK_SIZEOF(void *)
696AC_CHECK_SIZEOF(off_t)
697AC_CHECK_SIZEOF(time_t)
698
699AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, struct sockaddr_un, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
700[#define _GNU_SOURCE 1
701#include <sys/types.h>
702#ifdef HAVE_NETINET_IN_H
703#include <netinet/in.h>
704#endif
705#ifdef HAVE_NETINET_IN6_H
706#include <netinet/in6.h>
707#endif
708#ifdef HAVE_SYS_UN_H
709#include <sys/un.h>
710#endif
711#ifdef HAVE_SYS_SOCKET_H
712#include <sys/socket.h>
713#endif
714#ifdef HAVE_NETDB_H
715#include <netdb.h>
716#endif
717#ifdef _WIN32
718#define WIN32_WINNT 0x400
719#define _WIN32_WINNT 0x400
720#define WIN32_LEAN_AND_MEAN
721#if defined(_MSC_VER) && (_MSC_VER < 1300)
722#include <winsock.h>
723#else
724#include <winsock2.h>
725#include <ws2tcpip.h>
726#endif
727#endif
728])
729AC_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], , ,
730[#include <sys/types.h>
731#ifdef HAVE_NETINET_IN_H
732#include <netinet/in.h>
733#endif
734#ifdef HAVE_NETINET_IN6_H
735#include <netinet/in6.h>
736#endif
737#ifdef HAVE_SYS_SOCKET_H
738#include <sys/socket.h>
739#endif
740#ifdef _WIN32
741#define WIN32_WINNT 0x400
742#define _WIN32_WINNT 0x400
743#define WIN32_LEAN_AND_MEAN
744#if defined(_MSC_VER) && (_MSC_VER < 1300)
745#include <winsock.h>
746#else
747#include <winsock2.h>
748#include <ws2tcpip.h>
749#endif
750#endif
751])
752
753AC_CHECK_TYPES([struct linger],,,
754[
755#ifdef HAVE_SYS_SOCKET_H
756#include <sys/socket.h>
757#endif
758#ifdef _WIN32
759#include <winsock2.h>
760#endif
761])
762
763AC_MSG_CHECKING([for socklen_t])
764AC_COMPILE_IFELSE(
765  [AC_LANG_PROGRAM([
766 #include <sys/types.h>
767 #ifdef _WIN32
768 #include <ws2tcpip.h>
769 #else
770 #include <sys/socket.h>
771 #endif
772    ],[socklen_t x;]
773  )],
774          [AC_MSG_RESULT([yes])],
775  [AC_MSG_RESULT([no])
776  AC_DEFINE(socklen_t, unsigned int,
777            [Define to unsigned int if you dont have it])]
778)
779
780# __func__/__FUNCTION__ is not a macros in general
781AC_MSG_CHECKING([whether our compiler supports __func__])
782AC_COMPILE_IFELSE(
783  [AC_LANG_PROGRAM([],
784    [ const char *cp = __func__; ]
785  )],
786          [ AC_DEFINE(HAVE___func__, 1, [Define to 1 if compiler have __func__])
787    AC_MSG_RESULT([yes])
788  ],
789  [AC_MSG_RESULT([no])]
790)
791AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
792AC_COMPILE_IFELSE(
793  [AC_LANG_PROGRAM([],
794    [ const char *cp = __FUNCTION__; ]
795  )],
796          [ AC_DEFINE(HAVE___FUNCTION__, 1, [Define to 1 if compiler have __FUNCTION__])
797    AC_MSG_RESULT([yes])
798  ],
799  [AC_MSG_RESULT([no])]
800)
801
802# check if we can compile with pthreads
803have_pthreads=no
804if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
805  ACX_PTHREAD([
806          AC_DEFINE(HAVE_PTHREADS, 1,
807                    [Define if we have pthreads on this system])
808          have_pthreads=yes])
809  CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
810  AC_CHECK_SIZEOF(pthread_t, ,
811     [AC_INCLUDES_DEFAULT()
812      #include <pthread.h> ]
813  )
814fi
815AM_CONDITIONAL(THREADS, [test "$enable_thread_support" != "no"])
816AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
817
818# check if we should compile locking into the library
819if test x$enable_thread_support = xno; then
820   AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
821          [Define if libevent should not be compiled with thread support])
822fi
823
824# check if we should hard-code the mm functions.
825if test x$enable_malloc_replacement = xno; then
826  AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
827        [Define if libevent should not allow replacing the mm functions])
828fi
829
830# check if we should hard-code debugging out
831if test x$enable_debug_mode = xno; then
832  AC_DEFINE(DISABLE_DEBUG_MODE, 1,
833        [Define if libevent should build without support for a debug mode])
834fi
835
836# check if we should enable verbose debugging
837if test x$enable_verbose_debug = xyes; then
838          CFLAGS="$CFLAGS -DUSE_DEBUG"
839fi
840
841# check if we have and should use openssl
842AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
843
844# Add some more warnings which we use in development but not in the
845# released versions.  (Some relevant gcc versions can't handle these.)
846if test x$enable_gcc_warnings != xno && test "$GCC" = "yes"; then
847
848  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
849#if !defined(__GNUC__) || (__GNUC__ < 4)
850#error
851#endif])], have_gcc4=yes, have_gcc4=no)
852
853  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
854#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
855#error
856#endif])], have_gcc42=yes, have_gcc42=no)
857
858  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
859#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
860#error
861#endif])], have_gcc45=yes, have_gcc45=no)
862
863  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
864#if !defined(__clang__)
865#error
866#endif])], have_clang=yes, have_clang=no)
867
868  # -W is the same as -Wextra
869  CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wmissing-declarations -Wnested-externs -Wbad-function-cast"
870  if test x$enable_gcc_warnings = xyes; then
871    CFLAGS="$CFLAGS -Werror"
872  fi
873
874  CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
875
876  if test x$have_gcc4 = xyes ; then
877    # These warnings break gcc 3.3.5 and work on gcc 4.0.2
878    CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
879    #CFLAGS="$CFLAGS -Wold-style-definition"
880  fi
881
882  if test x$have_gcc42 = xyes ; then
883    # These warnings break gcc 4.0.2 and work on gcc 4.2
884    CFLAGS="$CFLAGS -Waddress"
885  fi
886
887  if test x$have_gcc42 = xyes && test x$have_clang = xno; then
888    # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
889    CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
890  fi
891
892  if test x$have_gcc45 = xyes ; then
893    # These warnings work on gcc 4.5
894    CFLAGS="$CFLAGS -Wlogical-op"
895  fi
896
897  if test x$have_clang = xyes; then
898    # Disable the unused-function warnings, because these trigger
899    # for minheap-internal.h related code.
900    CFLAGS="$CFLAGS -Wno-unused-function"
901
902    # clang on macosx emits warnings for each directory specified which
903    # isn't "used" generating a lot of build noise (typically 3 warnings
904    # per file
905    case "$host_os" in
906        darwin*)
907            CFLAGS="$CFLAGS -Qunused-arguments"
908        ;;
909    esac
910  fi
911
912##This will break the world on some 64-bit architectures
913# CFLAGS="$CFLAGS -Winline"
914
915fi
916
917LIBEVENT_GC_SECTIONS=
918if test "$GCC" = yes && test "$enable_function_sections" = yes ; then
919    AC_CACHE_CHECK(
920          [if linker supports omitting unused code and data],
921          [libevent_cv_gc_sections_runs],
922          [
923              dnl  NetBSD will link but likely not run with --gc-sections
924              dnl  http://bugs.ntp.org/1844
925              dnl  http://gnats.netbsd.org/40401
926              dnl  --gc-sections causes attempt to load as linux elf, with
927              dnl  wrong syscalls in place.  Test a little gauntlet of
928              dnl  simple stdio read code checking for errors, expecting
929              dnl  enough syscall differences that the NetBSD code will
930              dnl  fail even with Linux emulation working as designed.
931              dnl  A shorter test could be refined by someone with access
932              dnl  to a NetBSD host with Linux emulation working.
933              origCFLAGS="$CFLAGS"
934              CFLAGS="$CFLAGS -Wl,--gc-sections"
935              AC_LINK_IFELSE(
936                    [AC_LANG_PROGRAM(
937                        [[
938                              #include <stdlib.h>
939                              #include <stdio.h>
940                        ]],
941                        [[
942                              FILE *    fpC;
943                              char      buf[32];
944                              size_t    cch;
945                              int       read_success_once;
946
947                              fpC = fopen("conftest.c", "r");
948                              if (NULL == fpC)
949                                        exit(1);
950                              do {
951                                        cch = fread(buf, sizeof(buf), 1, fpC);
952                                        read_success_once |= (0 != cch);
953                              } while (0 != cch);
954                              if (!read_success_once)
955                                        exit(2);
956                              if (!feof(fpC))
957                                        exit(3);
958                              if (0 != fclose(fpC))
959                                        exit(4);
960
961                              exit(EXIT_SUCCESS);
962                        ]]
963                    )],
964                    [
965                    dnl We have to do this invocation manually so that we can
966                    dnl get the output of conftest.err to make sure it doesn't
967                    dnl mention gc-sections.
968                        if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
969                              libevent_cv_gc_sections_runs=no
970                        else
971                              libevent_cv_gc_sections_runs=no
972                              ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
973                        fi
974                    ],
975                    [libevent_cv_gc_sections_runs=no]
976              )
977              CFLAGS="$origCFLAGS"
978              AS_UNSET([origCFLAGS])
979          ]
980    )
981    case "$libevent_cv_gc_sections_runs" in
982     yes)
983          CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
984          LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
985          ;;
986    esac
987fi
988AC_SUBST([LIBEVENT_GC_SECTIONS])
989
990AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
991
992dnl Aloow addtional flags from a containing package such as NTP
993AC_SUBST([LIBEVENT_CFLAGS])
994AC_SUBST([LIBEVENT_CPPFLAGS])
995AC_SUBST([LIBEVENT_LDFLAGS])
996
997# Doxygen support
998DX_HTML_FEATURE(ON)
999DX_MAN_FEATURE(OFF)
1000DX_RTF_FEATURE(OFF)
1001DX_XML_FEATURE(OFF)
1002DX_PDF_FEATURE(OFF)
1003DX_PS_FEATURE(OFF)
1004DX_CHM_FEATURE(OFF)
1005DX_CHI_FEATURE(OFF)
1006DX_INIT_DOXYGEN([libevent], [${top_srcdir}/Doxyfile], [doxygen])
1007
1008AM_CONDITIONAL([ENABLE_DOXYGEN], [test "$DX_FLAG_doc" = "1"])
1009AM_CONDITIONAL([ENABLE_DOXYGEN_MAN], [test "$DX_FLAG_man" = "1"])
1010
1011AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc libevent_core.pc libevent_extra.pc] )
1012AC_OUTPUT(Makefile)
1013