libguile/Makefile.am (snarfcppopts): Remove CFLAGS
[bpt/guile.git] / m4 / poll.m4
1 # poll.m4 serial 17
2 dnl Copyright (c) 2003, 2005-2007, 2009-2014 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_POLL],
8 [
9 AC_REQUIRE([gl_POLL_H])
10 AC_REQUIRE([gl_SOCKETS])
11 if test $ac_cv_header_poll_h = no; then
12 ac_cv_func_poll=no
13 gl_cv_func_poll=no
14 else
15 AC_CHECK_FUNC([poll],
16 [# Check whether poll() works on special files (like /dev/null) and
17 # and ttys (like /dev/tty). On Mac OS X 10.4.0 and AIX 5.3, it doesn't.
18 AC_RUN_IFELSE([AC_LANG_SOURCE([[
19 #include <fcntl.h>
20 #include <poll.h>
21 int main()
22 {
23 int result = 0;
24 struct pollfd ufd;
25 /* Try /dev/null for reading. */
26 ufd.fd = open ("/dev/null", O_RDONLY);
27 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
28 if (ufd.fd >= 0)
29 {
30 ufd.events = POLLIN;
31 ufd.revents = 0;
32 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLIN))
33 result |= 1;
34 }
35 /* Try /dev/null for writing. */
36 ufd.fd = open ("/dev/null", O_WRONLY);
37 /* If /dev/null does not exist, it's not Mac OS X nor AIX. */
38 if (ufd.fd >= 0)
39 {
40 ufd.events = POLLOUT;
41 ufd.revents = 0;
42 if (!(poll (&ufd, 1, 0) == 1 && ufd.revents == POLLOUT))
43 result |= 2;
44 }
45 /* Trying /dev/tty may be too environment dependent. */
46 return result;
47 }]])],
48 [gl_cv_func_poll=yes],
49 [gl_cv_func_poll=no],
50 [# When cross-compiling, assume that poll() works everywhere except on
51 # Mac OS X or AIX, regardless of its version.
52 AC_EGREP_CPP([MacOSX], [
53 #if (defined(__APPLE__) && defined(__MACH__)) || defined(_AIX)
54 This is MacOSX or AIX
55 #endif
56 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
57 fi
58 if test $gl_cv_func_poll != yes; then
59 AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
60 if test $ac_cv_func_poll = no; then
61 HAVE_POLL=0
62 else
63 REPLACE_POLL=1
64 fi
65 fi
66 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
67 :
68 else
69 AC_DEFINE([HAVE_POLL], [1],
70 [Define to 1 if you have the 'poll' function and it works.])
71 fi
72
73 dnl Determine the needed libraries.
74 LIB_POLL="$LIBSOCKET"
75 if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
76 case "$host_os" in
77 mingw*)
78 dnl On the MSVC platform, the function MsgWaitForMultipleObjects
79 dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
80 dnl it is implicit.
81 AC_LINK_IFELSE(
82 [AC_LANG_SOURCE([[
83 #define WIN32_LEAN_AND_MEAN
84 #include <windows.h>
85 int
86 main ()
87 {
88 MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
89 return 0;
90 }]])],
91 [],
92 [LIB_POLL="$LIB_POLL -luser32"])
93 ;;
94 esac
95 fi
96 AC_SUBST([LIB_POLL])
97 ])
98
99 # Prerequisites of lib/poll.c.
100 AC_DEFUN([gl_PREREQ_POLL],
101 [
102 AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/filio.h])
103 ])