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