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