c7627cb94e6f103ce55ea88b4a9800ea7b44fe5b
[bpt/guile.git] / m4 / sys_socket_h.m4
1 # sys_socket_h.m4 serial 20
2 dnl Copyright (C) 2005-2010 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 dnl From Simon Josefsson.
8
9 AC_DEFUN([gl_HEADER_SYS_SOCKET],
10 [
11 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
12 AC_REQUIRE([AC_C_INLINE])
13
14 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
15 [gl_cv_header_sys_socket_h_selfcontained],
16 [
17 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
18 [gl_cv_header_sys_socket_h_selfcontained=yes],
19 [gl_cv_header_sys_socket_h_selfcontained=no])
20 ])
21 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
22 dnl If the shutdown function exists, <sys/socket.h> should define
23 dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
24 AC_CHECK_FUNCS([shutdown])
25 if test $ac_cv_func_shutdown = yes; then
26 AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
27 [gl_cv_header_sys_socket_h_shut],
28 [
29 AC_COMPILE_IFELSE(
30 [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
31 [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
32 [gl_cv_header_sys_socket_h_shut=yes],
33 [gl_cv_header_sys_socket_h_shut=no])
34 ])
35 if test $gl_cv_header_sys_socket_h_shut = no; then
36 SYS_SOCKET_H='sys/socket.h'
37 fi
38 fi
39 fi
40 # We need to check for ws2tcpip.h now.
41 gl_PREREQ_SYS_H_SOCKET
42 AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
43 /* sys/types.h is not needed according to POSIX, but the
44 sys/socket.h in i386-unknown-freebsd4.10 and
45 powerpc-apple-darwin5.5 required it. */
46 #include <sys/types.h>
47 #ifdef HAVE_SYS_SOCKET_H
48 #include <sys/socket.h>
49 #endif
50 #ifdef HAVE_WS2TCPIP_H
51 #include <ws2tcpip.h>
52 #endif
53 ])
54 if test $ac_cv_type_struct_sockaddr_storage = no; then
55 HAVE_STRUCT_SOCKADDR_STORAGE=0
56 fi
57 if test $ac_cv_type_sa_family_t = no; then
58 HAVE_SA_FAMILY_T=0
59 fi
60 if test $ac_cv_type_struct_sockaddr_storage != no; then
61 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
62 [],
63 [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
64 [#include <sys/types.h>
65 #ifdef HAVE_SYS_SOCKET_H
66 #include <sys/socket.h>
67 #endif
68 #ifdef HAVE_WS2TCPIP_H
69 #include <ws2tcpip.h>
70 #endif
71 ])
72 fi
73 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
74 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
75 SYS_SOCKET_H='sys/socket.h'
76 fi
77 gl_PREREQ_SYS_H_WINSOCK2
78
79 dnl Check for declarations of anything we want to poison if the
80 dnl corresponding gnulib module is not in use.
81 gl_WARN_ON_USE_PREPARE([[
82 /* Some systems require prerequisite headers. */
83 #include <sys/types.h>
84 #include <sys/socket.h>
85 ]], [socket connect accept bind getpeername getsockname getsockopt
86 listen recv send recvfrom sendto setsockopt shutdown accept4])
87 ])
88
89 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
90 [
91 dnl Check prerequisites of the <sys/socket.h> replacement.
92 gl_CHECK_NEXT_HEADERS([sys/socket.h])
93 if test $ac_cv_header_sys_socket_h = yes; then
94 HAVE_SYS_SOCKET_H=1
95 HAVE_WS2TCPIP_H=0
96 else
97 HAVE_SYS_SOCKET_H=0
98 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
99 dnl the check for those headers unconditional; yet cygwin reports
100 dnl that the headers are present but cannot be compiled (since on
101 dnl cygwin, all socket information should come from sys/socket.h).
102 AC_CHECK_HEADERS([ws2tcpip.h])
103 if test $ac_cv_header_ws2tcpip_h = yes; then
104 HAVE_WS2TCPIP_H=1
105 else
106 HAVE_WS2TCPIP_H=0
107 fi
108 fi
109 AC_SUBST([HAVE_SYS_SOCKET_H])
110 AC_SUBST([HAVE_WS2TCPIP_H])
111 ])
112
113 # Common prerequisites of the <sys/socket.h> replacement and of the
114 # <sys/select.h> replacement.
115 # Sets and substitutes HAVE_WINSOCK2_H.
116 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
117 [
118 m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
119 m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
120 AC_CHECK_HEADERS_ONCE([sys/socket.h])
121 if test $ac_cv_header_sys_socket_h != yes; then
122 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
123 dnl the check for those headers unconditional; yet cygwin reports
124 dnl that the headers are present but cannot be compiled (since on
125 dnl cygwin, all socket information should come from sys/socket.h).
126 AC_CHECK_HEADERS([winsock2.h])
127 fi
128 if test "$ac_cv_header_winsock2_h" = yes; then
129 HAVE_WINSOCK2_H=1
130 UNISTD_H_HAVE_WINSOCK2_H=1
131 SYS_IOCTL_H_HAVE_WINSOCK2_H=1
132 else
133 HAVE_WINSOCK2_H=0
134 fi
135 AC_SUBST([HAVE_WINSOCK2_H])
136 ])
137
138 AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
139 [
140 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
141 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
142 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
143 dnl Define it also as a C macro, for the benefit of the unit tests.
144 gl_MODULE_INDICATOR_FOR_TESTS([$1])
145 ])
146
147 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
148 [
149 GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
150 GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
151 GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
152 GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
153 GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
154 GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
155 GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
156 GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
157 GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
158 GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
159 GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
160 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
161 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
162 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
163 GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
164 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
165 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
166 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
167 HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
168 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
169 ])