Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libevent / configure.in
blob27cb7adac1c9b218186f858b427e11ac7c76200a
1 dnl configure.in for libevent
2 dnl Copyright 2000-2007 Niels Provos
3 dnl Copyright 2007-2012 Niels Provos and Nick Mathewson
4 dnl
5 dnl See LICENSE for copying information.
6 dnl
7 dnl Original version Dug Song <dugsong@monkey.org>
9 AC_PREREQ(2.59c)
10 AC_INIT(event.c)
12 AC_CONFIG_MACRO_DIR([m4])
14 AM_INIT_AUTOMAKE(libevent,2.0.19-stable-dev)
15 AM_CONFIG_HEADER(config.h)
16 AC_DEFINE(NUMERIC_VERSION, 0x02001301, [Numeric representation of the version])
18 dnl Initialize prefix.
19 if test "$prefix" = "NONE"; then
20    prefix="/usr/local"
23 AC_CANONICAL_BUILD
24 AC_CANONICAL_HOST
25 dnl the 'build' machine is where we run configure and compile
26 dnl the 'host' machine is where the resulting stuff runs.
28 case "$host_os" in
30  osf5*)
31     CFLAGS="$CFLAGS -D_OSF_SOURCE"
32     ;;
33 esac
35 dnl Checks for programs.
36 AC_PROG_CC
37 AM_PROG_CC_C_O
38 AC_PROG_INSTALL
39 AC_PROG_LN_S
40 AC_PROG_MKDIR_P
42 AC_PROG_GCC_TRADITIONAL
44 # We need to test for at least gcc 2.95 here, because older versions don't
45 # have -fno-strict-aliasing
46 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
47 #if !defined(__GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
48 #error
49 #endif])], have_gcc295=yes, have_gcc295=no)
51 if test "$GCC" = "yes" ; then
52         # Enable many gcc warnings by default...
53         CFLAGS="$CFLAGS -Wall"
54         # And disable the strict-aliasing optimization, since it breaks
55         # our sockaddr-handling code in strange ways.
56         if test x$have_gcc295 = xyes; then
57                 CFLAGS="$CFLAGS -fno-strict-aliasing"
58         fi
61 # OS X Lion started deprecating the system openssl. Let's just disable
62 # all deprecation warnings on OS X.
63 case "$host_os" in
65  darwin*)
66     CFLAGS="$CFLAGS -Wno-deprecated-declarations"
67     ;;
68 esac
70 AC_ARG_ENABLE(gcc-warnings,
71      AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings with GCC))
72 AC_ARG_ENABLE(thread-support,
73      AS_HELP_STRING(--disable-thread-support, disable support for threading),
74         [], [enable_thread_support=yes])
75 AC_ARG_ENABLE(malloc-replacement,
76      AS_HELP_STRING(--disable-malloc-replacement, disable support for replacing the memory mgt functions),
77         [], [enable_malloc_replacement=yes])
78 AC_ARG_ENABLE(openssl,
79      AS_HELP_STRING(--disable-openssl, disable support for openssl encryption),
80         [], [enable_openssl=yes])
81 AC_ARG_ENABLE(debug-mode,
82      AS_HELP_STRING(--disable-debug-mode, disable support for running in debug mode),
83         [], [enable_debug_mode=yes])
84 AC_ARG_ENABLE([libevent-install],
85      AS_HELP_STRING([--disable-libevent-install, disable installation of libevent]),
86         [], [enable_libevent_install=yes])
87 AC_ARG_ENABLE([libevent-regress],
88      AS_HELP_STRING([--disable-libevent-regress, skip regress in make check]),
89         [], [enable_libevent_regress=yes])
90 AC_ARG_ENABLE([function-sections],
91      AS_HELP_STRING([--enable-function-sections, make static library allow smaller binaries with --gc-sections]),
92         [], [enable_function_sections=no])
95 AC_PROG_LIBTOOL
97 dnl   Uncomment "AC_DISABLE_SHARED" to make shared librraries not get
98 dnl   built by default.  You can also turn shared libs on and off from
99 dnl   the command line with --enable-shared and --disable-shared.
100 dnl AC_DISABLE_SHARED
101 AC_SUBST(LIBTOOL_DEPS)
103 AM_CONDITIONAL([BUILD_REGRESS], [test "$enable_libevent_regress" = "yes"])
105 dnl Checks for libraries.
106 AC_SEARCH_LIBS([inet_ntoa], [nsl])
107 AC_SEARCH_LIBS([socket], [socket])
108 AC_SEARCH_LIBS([inet_aton], [resolv])
109 AC_SEARCH_LIBS([clock_gettime], [rt])
110 AC_SEARCH_LIBS([sendfile], [sendfile])
112 dnl - check if the macro WIN32 is defined on this compiler.
113 dnl - (this is how we check for a windows version of GCC)
114 AC_MSG_CHECKING(for WIN32)
115 AC_TRY_COMPILE(,
116         [
117 #ifndef WIN32
118 die horribly
119 #endif
120         ],
121         bwin32=true; AC_MSG_RESULT(yes),
122         bwin32=false; AC_MSG_RESULT(no),
125 dnl - check if the macro __CYGWIN__ is defined on this compiler.
126 dnl - (this is how we check for a cygwin version of GCC)
127 AC_MSG_CHECKING(for CYGWIN)
128 AC_TRY_COMPILE(,
129         [
130 #ifndef __CYGWIN__
131 die horribly
132 #endif
133         ],
134         cygwin=true; AC_MSG_RESULT(yes),
135         cygwin=false; AC_MSG_RESULT(no),
138 AC_CHECK_HEADERS([zlib.h])
140 if test "x$ac_cv_header_zlib_h" = "xyes"; then
141 dnl Determine if we have zlib for regression tests
142 dnl Don't put this one in LIBS
143 save_LIBS="$LIBS"
144 LIBS=""
145 ZLIB_LIBS=""
146 have_zlib=no
147 AC_SEARCH_LIBS([inflateEnd], [z],
148         [have_zlib=yes
149         ZLIB_LIBS="$LIBS"
150         AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
151 LIBS="$save_LIBS"
152 AC_SUBST(ZLIB_LIBS)
154 AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
156 dnl See if we have openssl.  This doesn't go in LIBS either.
157 if test "$bwin32" = true; then
158   EV_LIB_WS32=-lws2_32
159   EV_LIB_GDI=-lgdi32
160 else
161   EV_LIB_WS32=
162   EV_LIB_GDI=
164 AC_SUBST(EV_LIB_WS32)
165 AC_SUBST(EV_LIB_GDI)
166 AC_SUBST(OPENSSL_LIBADD)
168 AC_CHECK_HEADERS([openssl/bio.h])
170 if test "$enable_openssl" = "yes"; then
171 save_LIBS="$LIBS"
172 LIBS=""
173 OPENSSL_LIBS=""
174 have_openssl=no
175 AC_SEARCH_LIBS([SSL_new], [ssl],
176         [have_openssl=yes
177         OPENSSL_LIBS="$LIBS -lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"
178         AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl])],
179         [have_openssl=no],
180         [-lcrypto $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD])
181 LIBS="$save_LIBS"
182 AC_SUBST(OPENSSL_LIBS)
185 dnl Checks for header files.
186 AC_HEADER_STDC
187 AC_CHECK_HEADERS([fcntl.h stdarg.h inttypes.h stdint.h stddef.h poll.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/in.h netinet/in6.h sys/socket.h sys/uio.h arpa/inet.h sys/eventfd.h sys/mman.h sys/sendfile.h sys/wait.h netdb.h])
188 AC_CHECK_HEADERS(sys/sysctl.h, [], [], [
189 #ifdef HAVE_SYS_PARAM_H
190 #include <sys/param.h>
191 #endif
193 if test "x$ac_cv_header_sys_queue_h" = "xyes"; then
194         AC_MSG_CHECKING(for TAILQ_FOREACH in sys/queue.h)
195         AC_EGREP_CPP(yes,
197 #include <sys/queue.h>
198 #ifdef TAILQ_FOREACH
199  yes
200 #endif
201 ],      [AC_MSG_RESULT(yes)
202          AC_DEFINE(HAVE_TAILQFOREACH, 1,
203                 [Define if TAILQ_FOREACH is defined in <sys/queue.h>])],
204         AC_MSG_RESULT(no)
205         )
208 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
209         AC_MSG_CHECKING(for timeradd in sys/time.h)
210         AC_EGREP_CPP(yes,
212 #include <sys/time.h>
213 #ifdef timeradd
214  yes
215 #endif
216 ],      [ AC_DEFINE(HAVE_TIMERADD, 1,
217                 [Define if timeradd is defined in <sys/time.h>])
218           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
222 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
223         AC_MSG_CHECKING(for timercmp in sys/time.h)
224         AC_EGREP_CPP(yes,
226 #include <sys/time.h>
227 #ifdef timercmp
228  yes
229 #endif
230 ],      [ AC_DEFINE(HAVE_TIMERCMP, 1,
231                 [Define if timercmp is defined in <sys/time.h>])
232           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
236 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
237         AC_MSG_CHECKING(for timerclear in sys/time.h)
238         AC_EGREP_CPP(yes,
240 #include <sys/time.h>
241 #ifdef timerclear
242  yes
243 #endif
244 ],      [ AC_DEFINE(HAVE_TIMERCLEAR, 1,
245                 [Define if timerclear is defined in <sys/time.h>])
246           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
250 if test "x$ac_cv_header_sys_time_h" = "xyes"; then
251         AC_MSG_CHECKING(for timerisset in sys/time.h)
252         AC_EGREP_CPP(yes,
254 #include <sys/time.h>
255 #ifdef timerisset
256  yes
257 #endif
258 ],      [ AC_DEFINE(HAVE_TIMERISSET, 1,
259                 [Define if timerisset is defined in <sys/time.h>])
260           AC_MSG_RESULT(yes)] ,AC_MSG_RESULT(no)
264 if test "x$ac_cv_header_sys_sysctl_h" = "xyes"; then
265         AC_CHECK_DECLS([CTL_KERN, KERN_RANDOM, RANDOM_UUID, KERN_ARND], [], [],
266            [[#include <sys/types.h>
267              #include <sys/sysctl.h>]]
268         )
271 AM_CONDITIONAL(BUILD_WIN32, test x$bwin32 = xtrue)
272 AM_CONDITIONAL(BUILD_CYGWIN, test x$cygwin = xtrue)
273 AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue)
275 if test x$bwin32 = xtrue; then
276    AC_SEARCH_LIBS([getservbyname],[ws2_32])
279 dnl Checks for typedefs, structures, and compiler characteristics.
280 AC_C_CONST
281 AC_C_INLINE
282 AC_HEADER_TIME
284 dnl Checks for library functions.
285 AC_CHECK_FUNCS([gettimeofday vasprintf fcntl clock_gettime strtok_r strsep])
286 AC_CHECK_FUNCS([getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random arc4random_buf issetugid geteuid getegid getprotobynumber setenv unsetenv putenv sysctl])
288 AC_CACHE_CHECK(
289     [for getaddrinfo],
290     [libevent_cv_getaddrinfo],
291     [AC_LINK_IFELSE(
292         [AC_LANG_PROGRAM(
293             [[
294                 #ifdef HAVE_NETDB_H
295                 #include <netdb.h>
296                 #endif
297             ]],
298             [[
299                 getaddrinfo;
300             ]]
301         )],
302         [libevent_cv_getaddrinfo=yes],
303         [libevent_cv_getaddrinfo=no]
304     )]
306 if test "$libevent_cv_getaddrinfo" = "yes" ; then
307     AC_DEFINE([HAVE_GETADDRINFO], [1], [Do we have getaddrinfo()?])
308 else
310 AC_CHECK_FUNCS([getservbyname])
311 # Check for gethostbyname_r in all its glorious incompatible versions.
312 #   (This is cut-and-pasted from Tor, which based its logic on
313 #   Python's configure.in.)
314 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
315   [Define this if you have any gethostbyname_r()])
317 AC_CHECK_FUNC(gethostbyname_r, [
318   AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
319   OLD_CFLAGS=$CFLAGS
320   CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
321   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
322 #include <netdb.h>
323   ], [[
324     char *cp1, *cp2;
325     struct hostent *h1, *h2;
326     int i1, i2;
327     (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
328   ]])],[
329     AC_DEFINE(HAVE_GETHOSTBYNAME_R)
330     AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
331      [Define this if gethostbyname_r takes 6 arguments])
332     AC_MSG_RESULT(6)
333   ], [
334     AC_TRY_COMPILE([
335 #include <netdb.h>
336     ], [
337       char *cp1, *cp2;
338       struct hostent *h1;
339       int i1, i2;
340       (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
341     ], [
342       AC_DEFINE(HAVE_GETHOSTBYNAME_R)
343       AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
344         [Define this if gethostbyname_r takes 5 arguments])
345       AC_MSG_RESULT(5)
346    ], [
347       AC_TRY_COMPILE([
348 #include <netdb.h>
349      ], [
350        char *cp1;
351        struct hostent *h1;
352        struct hostent_data hd;
353        (void) gethostbyname_r(cp1,h1,&hd);
354      ], [
355        AC_DEFINE(HAVE_GETHOSTBYNAME_R)
356        AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
357          [Define this if gethostbyname_r takes 3 arguments])
358        AC_MSG_RESULT(3)
359      ], [
360        AC_MSG_RESULT(0)
361      ])
362   ])
363  ])
364  CFLAGS=$OLD_CFLAGS
369 AC_CHECK_SIZEOF(long)
371 AC_MSG_CHECKING(for F_SETFD in fcntl.h)
372 AC_EGREP_CPP(yes,
374 #define _GNU_SOURCE
375 #include <fcntl.h>
376 #ifdef F_SETFD
378 #endif
379 ],      [ AC_DEFINE(HAVE_SETFD, 1,
380               [Define if F_SETFD is defined in <fcntl.h>])
381           AC_MSG_RESULT(yes) ], AC_MSG_RESULT(no))
383 needsignal=no
384 haveselect=no
385 if test x$bwin32 != xtrue; then
386     AC_CHECK_FUNCS(select, [haveselect=yes], )
387     if test "x$haveselect" = "xyes" ; then
388         needsignal=yes
389     fi
391 AM_CONDITIONAL(SELECT_BACKEND, [test "x$haveselect" = "xyes"])
393 havepoll=no
394 AC_CHECK_FUNCS(poll, [havepoll=yes], )
395 if test "x$havepoll" = "xyes" ; then
396         needsignal=yes
398 AM_CONDITIONAL(POLL_BACKEND, [test "x$havepoll" = "xyes"])
400 havedevpoll=no
401 if test "x$ac_cv_header_sys_devpoll_h" = "xyes"; then
402         AC_DEFINE(HAVE_DEVPOLL, 1,
403                     [Define if /dev/poll is available])
405 AM_CONDITIONAL(DEVPOLL_BACKEND, [test "x$ac_cv_header_sys_devpoll_h" = "xyes"])
407 havekqueue=no
408 if test "x$ac_cv_header_sys_event_h" = "xyes"; then
409         AC_CHECK_FUNCS(kqueue, [havekqueue=yes], )
410         if test "x$havekqueue" = "xyes" ; then
411                 AC_MSG_CHECKING(for working kqueue)
412                 AC_TRY_RUN(
413 #include <sys/types.h>
414 #include <sys/time.h>
415 #include <sys/event.h>
416 #include <stdio.h>
417 #include <unistd.h>
418 #include <fcntl.h>
421 main(int argc, char **argv)
423         int kq;
424         int n;
425         int fd[[2]];
426         struct kevent ev;
427         struct timespec ts;
428         char buf[[8000]];
430         if (pipe(fd) == -1)
431                 exit(1);
432         if (fcntl(fd[[1]], F_SETFL, O_NONBLOCK) == -1)
433                 exit(1);
435         while ((n = write(fd[[1]], buf, sizeof(buf))) == sizeof(buf))
436                 ;
438         if ((kq = kqueue()) == -1)
439                 exit(1);
441         memset(&ev, 0, sizeof(ev));
442         ev.ident = fd[[1]];
443         ev.filter = EVFILT_WRITE;
444         ev.flags = EV_ADD | EV_ENABLE;
445         n = kevent(kq, &ev, 1, NULL, 0, NULL);
446         if (n == -1)
447                 exit(1);
449         read(fd[[0]], buf, sizeof(buf));
451         ts.tv_sec = 0;
452         ts.tv_nsec = 0;
453         n = kevent(kq, NULL, 0, &ev, 1, &ts);
454         if (n == -1 || n == 0)
455                 exit(1);
457         exit(0);
458 }, [AC_MSG_RESULT(yes)
459     AC_DEFINE(HAVE_WORKING_KQUEUE, 1,
460                 [Define if kqueue works correctly with pipes])
461     havekqueue=yes
462     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
463         fi
465 AM_CONDITIONAL(KQUEUE_BACKEND, [test "x$havekqueue" = "xyes"])
467 haveepollsyscall=no
468 haveepoll=no
469 AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
470 if test "x$haveepoll" = "xyes" ; then
471         AC_DEFINE(HAVE_EPOLL, 1,
472                 [Define if your system supports the epoll system calls])
473         needsignal=yes
475 if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
476         if test "x$haveepoll" = "xno" ; then
477                 AC_MSG_CHECKING(for epoll system call)
478                 AC_TRY_RUN(
479 #include <stdint.h>
480 #include <sys/param.h>
481 #include <sys/types.h>
482 #include <sys/syscall.h>
483 #include <sys/epoll.h>
484 #include <unistd.h>
487 epoll_create(int size)
489         return (syscall(__NR_epoll_create, size));
493 main(int argc, char **argv)
495         int epfd;
497         epfd = epoll_create(256);
498         exit (epfd == -1 ? 1 : 0);
499 }, [AC_MSG_RESULT(yes)
500     AC_DEFINE(HAVE_EPOLL, 1,
501         [Define if your system supports the epoll system calls])
502     needsignal=yes
503     have_epoll=yes
504     AC_LIBOBJ(epoll_sub)
505     ], AC_MSG_RESULT(no), AC_MSG_RESULT(no))
506         fi
508 AM_CONDITIONAL(EPOLL_BACKEND, [test "x$haveepoll" = "xyes"])
510 haveeventports=no
511 AC_CHECK_FUNCS(port_create, [haveeventports=yes], )
512 if test "x$haveeventports" = "xyes" ; then
513         AC_DEFINE(HAVE_EVENT_PORTS, 1,
514                 [Define if your system supports event ports])
515         needsignal=yes
517 AM_CONDITIONAL(EVPORT_BACKEND, [test "x$haveeventports" = "xyes"])
519 if test "x$bwin32" = "xtrue"; then
520         needsignal=yes
523 AM_CONDITIONAL(SIGNAL_SUPPORT, [test "x$needsignal" = "xyes"])
525 AC_TYPE_PID_T
526 AC_TYPE_SIZE_T
527 AC_TYPE_SSIZE_T
529 AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, uintptr_t], , ,
530 [#ifdef HAVE_STDINT_H
531 #include <stdint.h>
532 #elif defined(HAVE_INTTYPES_H)
533 #include <inttypes.h>
534 #endif
535 #ifdef HAVE_SYS_TYPES_H
536 #include <sys/types.h>
537 #endif])
539 AC_CHECK_TYPES([fd_mask], , ,
540 [#ifdef HAVE_SYS_TYPES_H
541 #include <sys/types.h>
542 #endif
543 #ifdef HAVE_SYS_SELECT_H
544 #include <sys/select.h>
545 #endif])
547 AC_CHECK_SIZEOF(long long)
548 AC_CHECK_SIZEOF(long)
549 AC_CHECK_SIZEOF(int)
550 AC_CHECK_SIZEOF(short)
551 AC_CHECK_SIZEOF(size_t)
552 AC_CHECK_SIZEOF(void *)
554 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t, struct addrinfo, struct sockaddr_storage], , ,
555 [#define _GNU_SOURCE
556 #include <sys/types.h>
557 #ifdef HAVE_NETINET_IN_H
558 #include <netinet/in.h>
559 #endif
560 #ifdef HAVE_NETINET_IN6_H
561 #include <netinet/in6.h>
562 #endif
563 #ifdef HAVE_SYS_SOCKET_H
564 #include <sys/socket.h>
565 #endif
566 #ifdef HAVE_NETDB_H
567 #include <netdb.h>
568 #endif
569 #ifdef WIN32
570 #define WIN32_WINNT 0x400
571 #define _WIN32_WINNT 0x400
572 #define WIN32_LEAN_AND_MEAN
573 #if defined(_MSC_VER) && (_MSC_VER < 1300)
574 #include <winsock.h>
575 #else
576 #include <winsock2.h>
577 #include <ws2tcpip.h>
578 #endif
579 #endif
581 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], , ,
582 [#include <sys/types.h>
583 #ifdef HAVE_NETINET_IN_H
584 #include <netinet/in.h>
585 #endif
586 #ifdef HAVE_NETINET_IN6_H
587 #include <netinet/in6.h>
588 #endif
589 #ifdef HAVE_SYS_SOCKET_H
590 #include <sys/socket.h>
591 #endif
592 #ifdef WIN32
593 #define WIN32_WINNT 0x400
594 #define _WIN32_WINNT 0x400
595 #define WIN32_LEAN_AND_MEAN
596 #if defined(_MSC_VER) && (_MSC_VER < 1300)
597 #include <winsock.h>
598 #else
599 #include <winsock2.h>
600 #include <ws2tcpip.h>
601 #endif
602 #endif
605 AC_MSG_CHECKING([for socklen_t])
606 AC_TRY_COMPILE([
607  #include <sys/types.h>
608  #include <sys/socket.h>],
609   [socklen_t x;],
610   AC_MSG_RESULT([yes]),
611   [AC_MSG_RESULT([no])
612   AC_DEFINE(socklen_t, unsigned int,
613         [Define to unsigned int if you dont have it])]
616 AC_MSG_CHECKING([whether our compiler supports __func__])
617 AC_TRY_COMPILE([],
618  [ const char *cp = __func__; ],
619  AC_MSG_RESULT([yes]),
620  AC_MSG_RESULT([no])
621  AC_MSG_CHECKING([whether our compiler supports __FUNCTION__])
622  AC_TRY_COMPILE([],
623    [ const char *cp = __FUNCTION__; ],
624    AC_MSG_RESULT([yes])
625    AC_DEFINE(__func__, __FUNCTION__,
626          [Define to appropriate substitue if compiler doesnt have __func__]),
627    AC_MSG_RESULT([no])
628    AC_DEFINE(__func__, __FILE__,
629          [Define to appropriate substitue if compiler doesnt have __func__])))
632 # check if we can compile with pthreads
633 have_pthreads=no
634 if test x$bwin32 != xtrue && test "$enable_thread_support" != "no"; then
635   ACX_PTHREAD([
636         AC_DEFINE(HAVE_PTHREADS, 1,
637                 [Define if we have pthreads on this system])
638         have_pthreads=yes])
639   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
640   AC_CHECK_SIZEOF(pthread_t, ,
641      [AC_INCLUDES_DEFAULT()
642       #include <pthread.h> ]
643   )
645 AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
647 # check if we should compile locking into the library
648 if test x$enable_thread_support = xno; then
649    AC_DEFINE(DISABLE_THREAD_SUPPORT, 1,
650         [Define if libevent should not be compiled with thread support])
653 # check if we should hard-code the mm functions.
654 if test x$enable_malloc_replacement = xno; then
655   AC_DEFINE(DISABLE_MM_REPLACEMENT, 1,
656         [Define if libevent should not allow replacing the mm functions])
659 # check if we should hard-code debugging out
660 if test x$enable_debug_mode = xno; then
661   AC_DEFINE(DISABLE_DEBUG_MODE, 1,
662         [Define if libevent should build without support for a debug mode])
665 # check if we have and should use openssl
666 AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"])
668 # Add some more warnings which we use in development but not in the
669 # released versions.  (Some relevant gcc versions can't handle these.)
670 if test x$enable_gcc_warnings = xyes && test "$GCC" = "yes"; then
672   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
673 #if !defined(__GNUC__) || (__GNUC__ < 4)
674 #error
675 #endif])], have_gcc4=yes, have_gcc4=no)
677   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
678 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
679 #error
680 #endif])], have_gcc42=yes, have_gcc42=no)
682   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
683 #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
684 #error
685 #endif])], have_gcc45=yes, have_gcc45=no)
687   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
688 #if !defined(__clang__)
689 #error
690 #endif])], have_clang=yes, have_clang=no)
692   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 -Werror"
693   CFLAGS="$CFLAGS -Wno-unused-parameter -Wstrict-aliasing"
695   if test x$have_gcc4 = xyes ; then
696     # These warnings break gcc 3.3.5 and work on gcc 4.0.2
697     CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement"
698     #CFLAGS="$CFLAGS -Wold-style-definition"
699   fi
701   if test x$have_gcc42 = xyes ; then
702     # These warnings break gcc 4.0.2 and work on gcc 4.2
703     CFLAGS="$CFLAGS -Waddress"
704   fi
706   if test x$have_gcc42 = xyes && test x$have_clang = xno; then
707     # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
708     CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
709   fi
711   if test x$have_gcc45 = xyes ; then
712     # These warnings work on gcc 4.5
713     CFLAGS="$CFLAGS -Wlogical-op"
714   fi
716   if test x$have_clang = xyes; then
717     # Disable the unused-function warnings, because these trigger
718     # for minheap-internal.h related code.
719     CFLAGS="$CFLAGS -Wno-unused-function"
720   fi
722 ##This will break the world on some 64-bit architectures
723 # CFLAGS="$CFLAGS -Winline"
727 LIBEVENT_GC_SECTIONS=
728 if test "$GCC" = yes && test "$enable_function_sections" = yes ; then
729     AC_CACHE_CHECK(
730         [if linker supports omitting unused code and data],
731         [libevent_cv_gc_sections_runs],
732         [
733             dnl  NetBSD will link but likely not run with --gc-sections
734             dnl  http://bugs.ntp.org/1844
735             dnl  http://gnats.netbsd.org/40401
736             dnl  --gc-sections causes attempt to load as linux elf, with
737             dnl  wrong syscalls in place.  Test a little gauntlet of
738             dnl  simple stdio read code checking for errors, expecting
739             dnl  enough syscall differences that the NetBSD code will
740             dnl  fail even with Linux emulation working as designed.
741             dnl  A shorter test could be refined by someone with access
742             dnl  to a NetBSD host with Linux emulation working.
743             origCFLAGS="$CFLAGS"
744             CFLAGS="$CFLAGS -Wl,--gc-sections"
745             AC_LINK_IFELSE(
746                 [AC_LANG_PROGRAM(
747                     [[
748                         #include <stdlib.h>
749                         #include <stdio.h>
750                     ]],
751                     [[
752                         FILE *  fpC;
753                         char    buf[32];
754                         size_t  cch;
755                         int     read_success_once;
757                         fpC = fopen("conftest.c", "r");
758                         if (NULL == fpC)
759                                 exit(1);
760                         do {
761                                 cch = fread(buf, sizeof(buf), 1, fpC);
762                                 read_success_once |= (0 != cch);
763                         } while (0 != cch);
764                         if (!read_success_once)
765                                 exit(2);
766                         if (!feof(fpC))
767                                 exit(3);
768                         if (0 != fclose(fpC))
769                                 exit(4);
771                         exit(EXIT_SUCCESS);
772                     ]]
773                 )],
774                 [
775                     dnl We have to do this invocation manually so that we can
776                     dnl get the output of conftest.err to make sure it doesn't
777                     dnl mention gc-sections.
778                     if test "X$cross_compiling" = "Xyes" || grep gc-sections conftest.err ; then
779                         libevent_cv_gc_sections_runs=no
780                     else
781                         libevent_cv_gc_sections_runs=no
782                         ./conftest >/dev/null 2>&1 && libevent_cv_gc_sections_runs=yes
783                     fi
784                 ],
785                 [libevent_cv_gc_sections_runs=no]
786             )
787             CFLAGS="$origCFLAGS"
788             AS_UNSET([origCFLAGS])
789         ]
790     )
791     case "$libevent_cv_gc_sections_runs" in
792      yes)
793         CFLAGS="-ffunction-sections -fdata-sections $CFLAGS"
794         LIBEVENT_GC_SECTIONS="-Wl,--gc-sections"
795         ;;
796     esac
798 AC_SUBST([LIBEVENT_GC_SECTIONS])
800 AM_CONDITIONAL([INSTALL_LIBEVENT], [test "$enable_libevent_install" = "yes"])
802 AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] )
803 AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile)