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