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