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