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