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