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