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