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