Bump to m4 1.4.19
[platform/upstream/m4.git] / m4 / sys_socket_h.m4
1 # sys_socket_h.m4 serial 28
2 dnl Copyright (C) 2005-2021 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_ONCE([gl_SYS_SOCKET_H],
10 [
11   AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
12   AC_REQUIRE([AC_CANONICAL_HOST])
13
14   dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have
15   dnl old-style declarations (with return type 'int' instead of 'ssize_t')
16   dnl unless _POSIX_PII_SOCKET is defined.
17   case "$host_os" in
18     osf*)
19       AC_DEFINE([_POSIX_PII_SOCKET], [1],
20         [Define to 1 in order to get the POSIX compatible declarations
21          of socket functions.])
22       ;;
23   esac
24
25   AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
26     [gl_cv_header_sys_socket_h_selfcontained],
27     [
28       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
29         [gl_cv_header_sys_socket_h_selfcontained=yes],
30         [gl_cv_header_sys_socket_h_selfcontained=no])
31     ])
32   if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
33     dnl If the shutdown function exists, <sys/socket.h> should define
34     dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
35     AC_CHECK_FUNCS([shutdown])
36     if test $ac_cv_func_shutdown = yes; then
37       AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
38         [gl_cv_header_sys_socket_h_shut],
39         [
40           AC_COMPILE_IFELSE(
41             [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
42                [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
43             [gl_cv_header_sys_socket_h_shut=yes],
44             [gl_cv_header_sys_socket_h_shut=no])
45         ])
46       if test $gl_cv_header_sys_socket_h_shut = no; then
47         SYS_SOCKET_H='sys/socket.h'
48       fi
49     fi
50   fi
51   # We need to check for ws2tcpip.h now.
52   gl_PREREQ_SYS_H_SOCKET
53   AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
54   /* sys/types.h is not needed according to POSIX, but the
55      sys/socket.h in i386-unknown-freebsd4.10 and
56      powerpc-apple-darwin5.5 required it. */
57 #include <sys/types.h>
58 #ifdef HAVE_SYS_SOCKET_H
59 #include <sys/socket.h>
60 #endif
61 #ifdef HAVE_WS2TCPIP_H
62 #include <ws2tcpip.h>
63 #endif
64 ])
65   if test $ac_cv_type_struct_sockaddr_storage = no; then
66     HAVE_STRUCT_SOCKADDR_STORAGE=0
67   fi
68   if test $ac_cv_type_sa_family_t = no; then
69     HAVE_SA_FAMILY_T=0
70   fi
71   if test $ac_cv_type_struct_sockaddr_storage != no; then
72     AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
73       [],
74       [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
75       [#include <sys/types.h>
76        #ifdef HAVE_SYS_SOCKET_H
77        #include <sys/socket.h>
78        #endif
79        #ifdef HAVE_WS2TCPIP_H
80        #include <ws2tcpip.h>
81        #endif
82       ])
83   fi
84   if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
85      || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
86     SYS_SOCKET_H='sys/socket.h'
87   fi
88   gl_PREREQ_SYS_H_WINSOCK2
89
90   dnl Check for declarations of anything we want to poison if the
91   dnl corresponding gnulib module is not in use.
92   gl_WARN_ON_USE_PREPARE([[
93 /* Some systems require prerequisite headers.  */
94 #include <sys/types.h>
95 #include <sys/socket.h>
96     ]], [socket connect accept bind getpeername getsockname getsockopt
97     listen recv send recvfrom sendto setsockopt shutdown accept4])
98
99   AC_REQUIRE([AC_C_RESTRICT])
100 ])
101
102 AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
103 [
104   dnl Check prerequisites of the <sys/socket.h> replacement.
105   AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
106   gl_CHECK_NEXT_HEADERS([sys/socket.h])
107   if test $ac_cv_header_sys_socket_h = yes; then
108     HAVE_SYS_SOCKET_H=1
109   else
110     HAVE_SYS_SOCKET_H=0
111   fi
112   AC_SUBST([HAVE_SYS_SOCKET_H])
113   gl_PREREQ_SYS_H_WS2TCPIP
114 ])
115
116 # Common prerequisites of the <sys/socket.h> replacement and of the
117 # <sys/select.h> replacement.
118 # Sets and substitutes HAVE_WINSOCK2_H.
119 AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
120 [
121   m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
122   m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
123   AC_CHECK_HEADERS_ONCE([sys/socket.h])
124   if test $ac_cv_header_sys_socket_h != yes; then
125     dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
126     dnl the check for those headers unconditional; yet cygwin reports
127     dnl that the headers are present but cannot be compiled (since on
128     dnl cygwin, all socket information should come from sys/socket.h).
129     AC_CHECK_HEADERS([winsock2.h])
130   fi
131   if test "$ac_cv_header_winsock2_h" = yes; then
132     HAVE_WINSOCK2_H=1
133     UNISTD_H_HAVE_WINSOCK2_H=1
134     SYS_IOCTL_H_HAVE_WINSOCK2_H=1
135   else
136     HAVE_WINSOCK2_H=0
137   fi
138   AC_SUBST([HAVE_WINSOCK2_H])
139 ])
140
141 # Common prerequisites of the <sys/socket.h> replacement and of the
142 # <arpa/inet.h> replacement.
143 # Sets and substitutes HAVE_WS2TCPIP_H.
144 AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
145 [
146   AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
147   if test $ac_cv_header_sys_socket_h = yes; then
148     HAVE_WS2TCPIP_H=0
149   else
150     if test $ac_cv_header_ws2tcpip_h = yes; then
151       HAVE_WS2TCPIP_H=1
152     else
153       HAVE_WS2TCPIP_H=0
154     fi
155   fi
156   AC_SUBST([HAVE_WS2TCPIP_H])
157 ])
158
159 # gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
160 # sets the shell variable that indicates the presence of the given module
161 # to a C preprocessor expression that will evaluate to 1.
162 # This macro invocation must not occur in macros that are AC_REQUIREd.
163 AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
164 [
165   dnl Ensure to expand the default settings once only.
166   gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
167   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
168   dnl Define it also as a C macro, for the benefit of the unit tests.
169   gl_MODULE_INDICATOR_FOR_TESTS([$1])
170 ])
171
172 # Initializes the default values for AC_SUBSTed shell variables.
173 # This macro must not be AC_REQUIREd.  It must only be invoked, and only
174 # outside of macros or in macros that are not AC_REQUIREd.
175 AC_DEFUN([gl_SYS_SOCKET_H_REQUIRE_DEFAULTS],
176 [
177   m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS], [
178     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SOCKET])
179     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CONNECT])
180     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT])
181     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BIND])
182     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPEERNAME])
183     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKNAME])
184     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKOPT])
185     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LISTEN])
186     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECV])
187     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SEND])
188     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECVFROM])
189     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SENDTO])
190     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETSOCKOPT])
191     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SHUTDOWN])
192     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT4])
193   ])
194   m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS])
195   AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
196 ])
197
198 AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
199 [
200   HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
201   HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
202                         AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
203   HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
204   HAVE_ACCEPT4=1;       AC_SUBST([HAVE_ACCEPT4])
205 ])