Update `THANKS'.
[bpt/guile.git] / m4 / sys_socket_h.m4
CommitLineData
f4c79b3c 1# sys_socket_h.m4 serial 16
61cd9dc9 2dnl Copyright (C) 2005-2010 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])
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
8912421c
LC
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
8912421c
LC
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
8912421c
LC
56 fi
57 if test $ac_cv_type_sa_family_t = no; then
58 HAVE_SA_FAMILY_T=0
8912421c 59 fi
f4c79b3c 60 gl_PREREQ_SYS_H_WINSOCK2
61cd9dc9
LC
61
62 dnl Check for declarations of anything we want to poison if the
63 dnl corresponding gnulib module is not in use.
64 gl_WARN_ON_USE_PREPARE([[
65/* Some systems require prerequisite headers. */
66#include <sys/types.h>
67#if !defined __GLIBC__ && HAVE_SYS_TIME_H
68# include <sys/time.h>
69#endif
70#include <sys/select.h>
71 ]], [socket connect accept bind getpeername getsockname getsockopt
72 listen recv send recvfrom sendto setsockopt shutdown accept4])
8912421c
LC
73])
74
75AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
76[
77 dnl Check prerequisites of the <sys/socket.h> replacement.
78 gl_CHECK_NEXT_HEADERS([sys/socket.h])
79 if test $ac_cv_header_sys_socket_h = yes; then
80 HAVE_SYS_SOCKET_H=1
81 HAVE_WS2TCPIP_H=0
82 else
83 HAVE_SYS_SOCKET_H=0
84 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
85 dnl the check for those headers unconditional; yet cygwin reports
86 dnl that the headers are present but cannot be compiled (since on
87 dnl cygwin, all socket information should come from sys/socket.h).
88 AC_CHECK_HEADERS([ws2tcpip.h])
89 if test $ac_cv_header_ws2tcpip_h = yes; then
90 HAVE_WS2TCPIP_H=1
91 else
92 HAVE_WS2TCPIP_H=0
93 fi
94 fi
95 AC_SUBST([HAVE_SYS_SOCKET_H])
96 AC_SUBST([HAVE_WS2TCPIP_H])
97])
98
99# Common prerequisites of the <sys/socket.h> replacement and of the
100# <sys/select.h> replacement.
101# Sets and substitutes HAVE_WINSOCK2_H.
102AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
103[
104 m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
105 m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
106 AC_CHECK_HEADERS_ONCE([sys/socket.h])
107 if test $ac_cv_header_sys_socket_h != yes; then
108 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
109 dnl the check for those headers unconditional; yet cygwin reports
110 dnl that the headers are present but cannot be compiled (since on
111 dnl cygwin, all socket information should come from sys/socket.h).
112 AC_CHECK_HEADERS([winsock2.h])
113 fi
114 if test "$ac_cv_header_winsock2_h" = yes; then
115 HAVE_WINSOCK2_H=1
116 UNISTD_H_HAVE_WINSOCK2_H=1
117 SYS_IOCTL_H_HAVE_WINSOCK2_H=1
118 else
119 HAVE_WINSOCK2_H=0
120 fi
121 AC_SUBST([HAVE_WINSOCK2_H])
122])
123
124AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
125[
126 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
127 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
128 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
f4c79b3c
LC
129 dnl Define it also as a C macro, for the benefit of the unit tests.
130 gl_MODULE_INDICATOR([$1])
8912421c
LC
131])
132
133AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
134[
135 GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
136 GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
137 GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
138 GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
139 GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
140 GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
141 GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
142 GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
143 GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
144 GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
145 GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
146 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
147 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
148 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
149 GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
150 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
151 HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
152 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
153])