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