Update PUI to use ffi-curl
[sxemacs] / m4 / sxe-sockets.m4
1 dnl sxe-sockets.m4 -- socket and network functions
2
3 AC_DEFUN([SXE_CHECK_SOCKLEN_T], [dnl
4
5         SXE_CHECK_HEADERS([sys/types.h sys/socket.h])
6         AC_CHECK_TYPES([socklen_t], [], [], [
7 #ifdef HAVE_SYS_TYPES_H
8 #  include <sys/types.h>
9 #endif
10 #ifdef HAVE_SYS_SOCKET_H
11 #  include <sys/socket.h>
12 #endif
13                 ])
14
15         AC_MSG_CHECKING([whether `socklen_t' is actually `size_t'])
16         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
17 #ifdef HAVE_SYS_TYPES_H
18 #  include <sys/types.h>
19 #endif
20 #ifdef HAVE_SYS_SOCKET_H
21 #  include <sys/socket.h>
22 #endif
23                 ]], [[
24 int accept(int, struct sockaddr *, size_t *);
25                 ]])], [socklen_t_is_size_t="yes"], [socklen_t_is_size_t="no"])
26         AC_MSG_RESULT([$socklen_t_is_size_t])
27
28         AC_MSG_CHECKING([whether `socklen_t' is actually `int'])
29         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
30 #ifdef HAVE_SYS_TYPES_H
31 #  include <sys/types.h>
32 #endif
33 #ifdef HAVE_SYS_SOCKET_H
34 #  include <sys/socket.h>
35 #endif
36                 ]], [[
37 int accept(int, struct sockaddr *, int *);
38                 ]])], [socklen_t_is_int="yes"], [socklen_t_is_int="no"])
39         AC_MSG_RESULT([$socklen_t_is_int])
40
41         AC_MSG_CHECKING([what socklen_t is an alias for])
42         if test "$ac_cv_type_socklen_t" = "yes"; then
43                 socklen_t_is_actually="socklen_t"
44         elif test "$socklen_t_is_size_t" = "yes"; then
45                 socklen_t_is_actually="size_t"
46                 AC_DEFINE([socklen_t], [size_t],
47                         [A simple alias for Unix98's socklen_t])
48         elif test "$socklen_t_is_int" = "yes"; then
49                 socklen_t_is_actually="int"
50                 AC_DEFINE([socklen_t], [int],
51                         [A simple alias for Unix98's socklen_t])
52         else
53                 socklen_t_is_actually="bullcrap"
54         fi
55         AC_MSG_RESULT([$socklen_t_is_actually])
56
57 ])dnl SXE_CHECK_SOCKLEN_T
58
59
60 AC_DEFUN([_SXE_CHECK_GENERIC_SOCKFUN], [dnl
61         ## arg1 is the function to crawl for
62         pushdef([SOCKFUN], [$1])
63
64         SXE_CHECK_HEADERS([sys/types.h sys/socket.h])
65         AC_CHECK_FUNCS(SOCKFUN)
66         AC_CHECK_DECLS(SOCKFUN, [], [], [
67 #ifdef HAVE_SYS_TYPES_H
68 #  include <sys/types.h>
69 #endif
70 #ifdef HAVE_SYS_SOCKET_H
71 #  include <sys/socket.h>
72 #endif
73                 ])
74         ## libnet is for BeOS
75         SXE_CHECK_LIB_FUNCS([nsl socket net], SOCKFUN)
76
77         if test "$ac_cv_func_[]SOCKFUN" = "no" -a \
78                 "$ac_cv_lib_nsl___[]SOCKFUN" = "yes"; then
79                 ## whether we need to add -lnsl to LIBS
80                 SOCKET_LIBS="$SOCKET_LIBS -lnsl"
81                 ac_sxe_func_[]SOCKFUN="yes"
82
83         elif test "$ac_cv_func_[]SOCKFUN" = "no" -a \
84                 "$ac_cv_lib_socket___[]SOCKFUN" = "yes"; then
85                 ## whether we need to add -lsocket to LIBS
86                 SOCKET_LIBS="$SOCKET_LIBS -lsocket"
87                 ac_sxe_func_[]SOCKFUN="yes"
88
89         elif test "$ac_cv_func_[]SOCKFUN" = "no" -a \
90                 "$ac_cv_lib_net___[]SOCKFUN" = "yes"; then
91                 ## whether we need to add -lsocket to LIBS
92                 SOCKET_LIBS="$SOCKET_LIBS -lnet"
93                 ac_sxe_func_[]SOCKFUN="yes"
94
95         elif test "$ac_cv_func_[]SOCKFUN" = "yes"; then
96                 ## nothing to add to LIBS
97                 ac_sxe_func_[]SOCKFUN="yes"
98
99         else
100                 ac_sxe_func_[]SOCKFUN="no"
101
102         fi
103
104 dnl curl sez:
105 dnl   At least one system has been identified to require BOTH nsl and socket
106 dnl   libs at the same time to link properly.
107 dnl Howbeit, we currently do not provide a check for this very tragedy^Wstrategy
108
109         popdef([SOCKFUN])
110 ])dnl _SXE_CHECK_GENERIC_SOCKFUN
111
112
113 AC_DEFUN([SXE_CHECK_UNIX_DOMAIN_SOCKETS], [dnl
114         ## defines have_unix and HAVE_UNIX
115         have_unix="uncertain"
116
117         SXE_CHECK_HEADERS([sys/types.h sys/socket.h sys/un.h])
118         AC_CHECK_TYPE([struct sockaddr_un], [], [], [
119 #ifdef HAVE_SYS_TYPES_H
120 #  include <sys/types.h>
121 #endif
122 #ifdef HAVE_SYS_SOCKET_H
123 #  include <sys/socket.h>
124 #endif
125 #ifdef HAVE_SYS_UN_H
126 #  include <sys/un.h>
127 #endif
128                 ])
129
130         AC_CHECK_MEMBER([struct sockaddr_un.sun_len], [], [], [
131 #ifdef HAVE_SYS_TYPES_H
132 #  include <sys/types.h>
133 #endif
134 #ifdef HAVE_SYS_SOCKET_H
135 #  include <sys/socket.h>
136 #endif
137 #ifdef HAVE_SYS_UN_H
138 #  include <sys/un.h>
139 #endif
140                 ])
141
142         ## evaluating the results
143         if test "$ac_cv_type_struct_sockaddr_un" = "yes" -a \
144                 "$ac_cv_header_sys_socket_h" = "yes" -a \
145                 "$ac_cv_header_sys_un_h" = "yes"; then
146                 have_unix="yes"
147         else
148                 have_unix="no"
149         fi
150
151         ## legacy
152         if test "$ac_cv_member_struct_sockaddr_un_sun_len" = "yes"; then
153                 AC_DEFINE([HAVE_SOCKADDR_SUN_LEN], [1],
154                         [Legacy shit, use HAVE_STRUCT_SOCKADDR_UN_SUN_LEN!])
155         fi
156 ])dnl SXE_CHECK_UNIX_DOMAIN_SOCKETS
157
158 AC_DEFUN([SXE_CHECK_GETHOSTBYNAME], [_SXE_CHECK_GENERIC_SOCKFUN([gethostbyname])])
159 AC_DEFUN([SXE_CHECK_CONNECT], [_SXE_CHECK_GENERIC_SOCKFUN([connect])])
160 AC_DEFUN([SXE_CHECK_ACCEPT], [_SXE_CHECK_GENERIC_SOCKFUN([accept])])
161 AC_DEFUN([SXE_CHECK_SOCKET], [_SXE_CHECK_GENERIC_SOCKFUN([socket])])
162 AC_DEFUN([SXE_CHECK_GETHOSTNAME], [_SXE_CHECK_GENERIC_SOCKFUN([gethostname])])
163 AC_DEFUN([SXE_CHECK_GETNAMEINFO], [_SXE_CHECK_GENERIC_SOCKFUN([getnameinfo])])
164 AC_DEFUN([SXE_CHECK_GETADDRINFO], [_SXE_CHECK_GENERIC_SOCKFUN([getaddrinfo])])
165
166 AC_DEFUN([SXE_CHECK_SOCKET_IPV4], [dnl
167         SXE_CHECK_HEADERS([sys/types.h sys/socket.h])
168         AC_MSG_CHECKING([for IPv4])
169         AC_RUN_IFELSE([AC_LANG_SOURCE([[ /* is AF_INET available? */
170 #if defined HAVE_SYS_TYPES_H
171 #  include <sys/types.h>
172 #endif
173 #if defined HAVE_SYS_SOCKET_H
174 #  include <sys/socket.h>
175 #endif
176 main()
177 {
178         if (socket(AF_INET, SOCK_STREAM, 0) < 0)
179                 exit(1);
180         else
181                 exit(0);
182 }
183 ]])], [have_ipv4=yes], [have_ipv4=no], [have_ipv4=no])
184
185         AC_MSG_RESULT([$have_ipv4])
186 ])dnl SXE_CHECK_SOCKET_IPV4
187
188 AC_DEFUN([SXE_CHECK_SOCKET_IPV6], [dnl
189         SXE_CHECK_HEADERS([sys/types.h sys/socket.h])
190         AC_MSG_CHECKING([for IPv6])
191         AC_RUN_IFELSE([AC_LANG_SOURCE([[ /* is AF_INET6 available? */
192 #if defined HAVE_SYS_TYPES_H
193 #  include <sys/types.h>
194 #endif
195 #if defined HAVE_SYS_SOCKET_H
196 #  include <sys/socket.h>
197 #endif
198 main()
199 {
200         if (socket(AF_INET6, SOCK_STREAM, 0) < 0)
201                 exit(1);
202         else
203                 exit(0);
204 }
205 ]])], [have_ipv6=yes], [have_ipv6=no], [have_ipv6=no])
206
207         AC_MSG_RESULT([$have_ipv6])
208 ])dnl SXE_CHECK_SOCKET_IPV6
209
210
211 dnl CURL_CHECK_NONBLOCKING_SOCKET
212 dnl -------------------------------------------------
213 dnl Check for how to set a socket to non-blocking state. There seems to exist
214 dnl four known different ways, with the one used almost everywhere being POSIX
215 dnl and XPG3, while the other different ways for different systems (old BSD,
216 dnl Windows and Amiga).
217 dnl
218 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
219 dnl O_NONBLOCK define is found but does not work. This condition is attempted
220 dnl to get caught in this script by using an excessive number of #ifdefs...
221 dnl
222 AC_DEFUN([SXE_CHECK_NONBLOCKING_SOCKET], [dnl
223
224         SXE_CHECK_NONBLOCKING_SOCKET_O_NONBLOCK([nonblock])
225         SXE_CHECK_NONBLOCKING_SOCKET_FIONBIO([nonblock])
226         SXE_CHECK_NONBLOCKING_SOCKET_IOCTLSOCKET([nonblock])
227         SXE_CHECK_NONBLOCKING_SOCKET_SO_NONBLOCK([nonblock])
228
229         AC_MSG_CHECKING([for preferred non-blocking sockets style])
230         if test "$sxe_have_nonblocking_socket_O_NONBLOCK" = "yes"; then
231                 nonblock="O_NONBLOCK"
232                 AC_DEFINE([WITH_NONBLOCKING_SOCKET_O_NONBLOCK], [1],
233                         [Whether to use fnctl() with O_NONBLOCK])
234         elif test "$sxe_have_nonblocking_socket_FIONBIO" = "yes"; then
235                 nonblock="FIONBIO"
236                 AC_DEFINE([WITH_NONBLOCKING_SOCKET_O_NONBLOCK], [1],
237                         [Whether to use ioctl() with FIONBIO])
238         elif test "$sxe_have_nonblocking_socket_IoctlSocket" = "yes"; then
239                 nonblock="IoctlSocket"
240                 AC_DEFINE([WITH_NONBLOCKING_SOCKET_IOCTLSOCKET], [1],
241                         [Whether to use IoctlSocket() with FIONBIO])
242         elif test "$sxe_have_nonblocking_socket_SO_NONBLOCK" = "yes"; then
243                 nonblock="SO_NONBLOCK"
244                 AC_DEFINE([WITH_NONBLOCKING_SOCKET_SO_NONBLOCK], [1],
245                         [Whether to use setsockopt() with SO_NONBLOCK])
246         else
247                 nonblock="zilch"
248                 AC_DEFINE([WITH_NONBLOCKING_SOCKET_ZILCH], [1],
249                         [Whether not to use a non-blocking socket])
250         fi
251         AC_MSG_RESULT([$nonblock])
252 ])dnl SXE_CHECK_NONBLOCKING_SOCKET
253
254 AC_DEFUN([SXE_CHECK_NONBLOCKING_SOCKET_O_NONBLOCK], [dnl
255         ## arg1 - varname to put the socket implementation into
256         pushdef([VARNAME], [$1])
257
258         SXE_CHECK_HEADERS([sys/types.h unistd.h fcntl.h])
259         AC_CHECK_FUNCS([fcntl])
260         AC_CHECK_DECLS([fcntl], [], [], [
261 #if defined HAVE_SYS_TYPES_H
262 #include <sys/types.h>
263 #endif
264 #if defined HAVE_UNISTD_H
265 #include <unistd.h>
266 #endif
267 #if defined HAVE_FCNTL_H
268 #include <fcntl.h>
269 #endif
270                 ])
271         AC_MSG_CHECKING([whether fnctl() with O_NONBLOCK works])
272         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
273 /* headers for O_NONBLOCK test */
274 #if defined HAVE_SYS_TYPES_H
275 #include <sys/types.h>
276 #endif
277 #if defined HAVE_UNISTD_H
278 #include <unistd.h>
279 #endif
280 #if defined HAVE_FCNTL_H
281 #include <fcntl.h>
282 #endif
283                 ]], [[
284 /* try to compile O_NONBLOCK */
285 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
286 # if defined(__SVR4) || defined(__srv4__)
287 #  define PLATFORM_SOLARIS
288 # else
289 #  define PLATFORM_SUNOS4
290 # endif
291 #endif
292 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
293 # define PLATFORM_AIX_V3
294 #endif
295
296 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
297 #error "O_NONBLOCK does not work on this platform"
298 #endif
299 int socket;
300 int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
301                 ]])],
302                 [sxe_have_nonblocking_socket_O_NONBLOCK="yes"],
303                 [sxe_have_nonblocking_socket_O_NONBLOCK="no"])
304         AC_MSG_RESULT([$sxe_have_nonblocking_socket_O_NONBLOCK])
305
306         _SXE_EVALUATE_NONBLOCKING_SOCKET(VARNAME, [O_NONBLOCK])
307         popdef([VARNAME])
308 ])dnl SXE_CHECK_NONBLOCKING_SOCKET_O_NONBLOCK
309
310 AC_DEFUN([SXE_CHECK_NONBLOCKING_SOCKET_FIONBIO], [dnl
311         ## arg1 - varname to put the socket implementation into
312         pushdef([VARNAME], [$1])
313
314         SXE_CHECK_HEADERS([unistd.h stropts.h])
315         AC_CHECK_FUNCS([ioctl])
316         AC_CHECK_DECLS([ioctl], [], [], [
317 #if defined HAVE_UNISTD_H
318 #include <unistd.h>
319 #endif
320 #if defined HAVE_STROPTS_H
321 #include <stropts.h>
322 #endif
323                 ])
324         AC_MSG_CHECKING([whether ioctl() with FIONBIO works])
325         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
326 /* headers for FIONBIO test */
327 #if defined HAVE_UNISTD_H
328 #include <unistd.h>
329 #endif
330 #if defined HAVE_STROPTS_H
331 #include <stropts.h>
332 #endif
333                 ]],[[
334 /* FIONBIO source test (old-style unix) */
335 int socket;
336 int flags = ioctl(socket, FIONBIO, &flags);
337                 ]])],
338                 [sxe_have_nonblocking_socket_FIONBIO="yes"],
339                 [sxe_have_nonblocking_socket_FIONBIO="no"])
340         AC_MSG_RESULT([$sxe_have_nonblocking_socket_FIONBIO])
341
342         _SXE_EVALUATE_NONBLOCKING_SOCKET(VARNAME, [FIONBIO])
343         popdef([VARNAME])
344 ])dnl SXE_CHECK_NONBLOCKING_SOCKET_FIONBIO
345
346 AC_DEFUN([SXE_CHECK_NONBLOCKING_SOCKET_IOCTLSOCKET], [dnl
347         ## arg1 - varname to put the socket implementation into
348         pushdef([VARNAME], [$1])
349
350         SXE_CHECK_HEADERS([sys/ioctl.h])
351         AC_CHECK_FUNCS([IoctlSocket])
352         AC_CHECK_DECLS([IoctlSocket], [], [], [
353 #if defined HAVE_SYS_IOCTL_H
354 #include <sys/ioctl.h>
355 #endif
356                 ])
357         AC_MSG_CHECKING([whether IoctlSocket() with FIONBIO works])
358         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
359 /* headers for IoctlSocket test (Amiga?) */
360 #if defined HAVE_SYS_IOCTL_H
361 #include <sys/ioctl.h>
362 #endif
363                 ]], [[
364 /* IoctlSocket source code */
365 int socket;
366 int flags = IoctlSocket(socket, FIONBIO, (long)1);
367                 ]])],
368                 [sxe_have_nonblocking_socket_IoctlSocket="yes"],
369                 [sxe_have_nonblocking_socket_IoctlSocket="no"])
370         AC_MSG_RESULT([$sxe_have_nonblocking_socket_IoctlSocket])
371
372         _SXE_EVALUATE_NONBLOCKING_SOCKET(VARNAME, [IoctlSocket])
373         popdef([VARNAME])
374 ])dnl SXE_CHECK_NONBLOCKING_SOCKET_IOCTLSOCKET
375
376 AC_DEFUN([SXE_CHECK_NONBLOCKING_SOCKET_SO_NONBLOCK], [dnl
377         ## arg1 - varname to put the socket implementation into
378         pushdef([VARNAME], [$1])
379
380         SXE_CHECK_HEADERS([socket.h])
381         AC_CHECK_FUNCS([setsockopt])
382         AC_CHECK_DECLS([setsockopt], [], [], [
383 #if defined HAVE_SOCKET_H
384 #include <socket.h>
385 #endif
386                 ])
387         AC_MSG_CHECKING([whether setsockopt() with SO_NONBLOCK works])
388         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
389 /* headers for SO_NONBLOCK test (BeOS) */
390 #if defined HAVE_SOCKET_H
391 #include <socket.h>
392 #endif
393                 ]], [[
394 /* SO_NONBLOCK source code */
395 long b = 1;
396 int socket;
397 int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
398                 ]])],
399                 [sxe_have_nonblocking_socket_SO_NONBLOCK="yes"],
400                 [sxe_have_nonblocking_socket_SO_NONBLOCK="no"])
401         AC_MSG_RESULT([$sxe_have_nonblocking_socket_SO_NONBLOCK])
402
403         _SXE_EVALUATE_NONBLOCKING_SOCKET(VARNAME, [SO_NONBLOCK])
404         popdef([VARNAME])
405 ])dnl SXE_CHECK_NONBLOCKING_SOCKET_SO_NONBLOCK
406
407 AC_DEFUN([_SXE_EVALUATE_NONBLOCKING_SOCKET], [dnl
408         pushdef([VARNAME], [$1])
409         pushdef([TSTNAME], [$2])
410         if test "$sxe_have_nonblocking_socket_[]TSTNAME[]" = "yes"; then
411                 AC_DEFINE([HAVE_NONBLOCKING_SOCKET]TSTNAME, [1],
412                         [use ]TSTNAME[ for non-blocking sockets])
413                 if test -n "[]VARNAME[]"; then
414                         VARNAME="[]TSTNAME[]"
415                 fi
416         else
417                 :
418         fi
419         popdef([VARNAME])
420         popdef([TSTNAME])
421 ])dnl _SXE_EVALUATE_NONBLOCKING_SOCKET
422
423
424 AC_DEFUN([SXE_CHECK_TCPUDP_SOCKETS], [dnl
425         ## defines have_sockets and have_tcpudp
426         ## and HAVE_SOCKETS and HAVE_TCPUDP
427         have_sockets="uncertain"
428         have_tcpudp="uncertain"
429
430         SXE_CHECK_HEADERS([netinet/in.h])
431         SXE_CHECK_GETHOSTBYNAME
432         SXE_CHECK_GETHOSTNAME
433         SXE_CHECK_GETNAMEINFO
434         SXE_CHECK_GETADDRINFO
435         SXE_CHECK_CONNECT
436         SXE_CHECK_ACCEPT
437         SXE_CHECK_SOCKET
438         SXE_CHECK_INET_FUNS
439
440         SXE_CHECK_SOCKET_IPV4
441         SXE_CHECK_SOCKET_IPV6
442         SXE_CHECK_NONBLOCKING_SOCKET
443
444         ## evaluating the results
445         if test "$ac_cv_header_netinet_in_h" = "yes" -a \
446                 "$ac_cv_header_arpa_inet_h" = "yes" -a \
447                 "$ac_cv_header_netdb_h" = "yes"; then
448                 if test "$ac_sxe_func_socket" = "yes" -a \
449                         "$ac_sxe_func_gethostbyname" = "yes" -a \
450                         "$ac_sxe_func_gethostname" = "yes" -a \
451                         "$ac_sxe_func_getnameinfo" = "yes" -a \
452                         "$ac_sxe_func_getaddrinfo" = "yes"; then
453                         have_sockets="yes"
454                         have_tcpudp="yes"
455                 else
456                         have_sockets="no"
457                         have_tcpudp="no"
458                 fi
459         else
460                 have_sockets="no"
461                 have_tcpudp="no"
462         fi
463 ])dnl SXE_CHECK_TCPUDP_SOCKETS
464
465 AC_DEFUN([SXE_CHECK_SYSVIPC_MESSAGES], [dnl
466         ## defines have_sysvipc and HAVE_SYSVIPC
467         have_sysvipc="uncertain"
468
469         SXE_CHECK_HEADERS([sys/ipc.h sys/msg.h])
470         AC_CHECK_FUNCS([msgget])
471
472         ## evaluating the results
473         if test "$ac_cv_func_msgget" = "yes" -a \
474                 "$ac_cv_header_sys_ipc_h" = "yes" -o \
475                 "$ac_cv_func_msgget" = "yes" -a \
476                 "$ac_cv_header_sys_msg_h" = "yes"; then
477                 have_sysvipc="yes"
478         else
479                 have_sysvipc="no"
480         fi
481 ])dnl SXE_CHECK_SYSVIPC_MESSAGES
482
483 AC_DEFUN([SXE_CHECK_MULTICAST], [dnl
484         ## defines have_multicast and HAVE_MULTICAST
485         have_multicast="uncertain"
486
487         AC_CHECK_TYPE([struct ip_mreq], [], [], [
488 #ifdef HAVE_SYS_TYPES_H
489 #  include <sys/types.h>
490 #endif
491 #ifdef HAVE_NETINET_IN_H
492 #  include <netinet/in.h>
493 #endif
494                 ])
495
496         ## evaluating the results
497         have_multicast="no"
498         ## ... now test
499         if test "$ac_cv_type_struct_ip_mreq" = "yes"; then
500                 have_multicast="yes"
501         else
502                 have_multicast="no"
503         fi
504 ])dnl SXE_CHECK_MULTICAST
505
506 AC_DEFUN([SXE_CHECK_SOCKETS], [dnl
507         AC_DEFUN([SXE_CHECK_SOCKETS], [])
508
509         dnl Check for Internet sockets.
510         SXE_CHECK_HEADERS([sys/types.h sys/socket.h])
511         AC_HEADER_RESOLV
512
513         ## check for Unix98 socklen_t
514         SXE_CHECK_SOCKLEN_T
515
516         ## some real checks
517         SXE_CHECK_UNIX_DOMAIN_SOCKETS
518         SXE_CHECK_TCPUDP_SOCKETS
519         SXE_CHECK_SYSVIPC_MESSAGES
520         SXE_CHECK_MULTICAST
521 ])dnl SXE_CHECK_SOCKETS
522
523 dnl This isn't all that clever, it doesn't really properly test if
524 dnl -lbind is needed, just if it is present and defines inet_ntoa().
525 dnl There is also nothing preventing `-lbind' being added to $LDFLAGS
526 dnl _every_ time this macro is called. For the moment, it is only called
527 dnl once, so `-lbind' is only added once (or less) --SY.
528 dnl fixed? -hrop
529
530 AC_DEFUN([SXE_CHECK_INET_FUNS], [dnl
531         ## checks for various inet_footobar functions
532         ## if only defined in libbind, add that to LDFLAGS
533         ## defines sxe_cv_feat_inet_funs which can be 'native, 'libbind or 'no
534
535         ## check the preferred variant first
536         AC_REQUIRE([SXE_CHECK_LIBBIND_INET_FUNS])
537         ## just check for the native crap
538         AC_REQUIRE([SXE_CHECK_NATIVE_INET_FUNS])
539
540         AC_CACHE_CHECK([which set of inet_*() functions to use],
541                 [sxe_cv_feat_inet_funs], [_SXE_CHECK_INET_FUNS])
542 ])dnl SXE_CHECK_INET_FUNS
543
544 AC_DEFUN([_SXE_CHECK_INET_FUNS], [dnl
545         ## defines sxe_cv_feat_inet_funs, will be 'native, 'libbind or 'no
546
547         ## check the preferred variant first
548         AC_REQUIRE([SXE_CHECK_LIBBIND_INET_FUNS])
549         ## just check for the native crap
550         AC_REQUIRE([SXE_CHECK_NATIVE_INET_FUNS])
551
552         if test "$sxe_cv_feat_libbind_inet_funs" = "yes" -a \
553                 "$with_libbind" != "no"; then
554                 ## if libbind provides them all, just use them
555                 sxe_cv_feat_inet_funs="libbind"
556                 ## append the thing w/o messages
557                 LDFLAGS="${LDFLAGS} ${bind_ldflags} ${bind_libs}"
558                 CPPFLAGS="${CPPFLAGS} ${bind_cppflags}"
559         elif test "$sxe_cv_feat_libbind_inet_funs" = "yes" -a \
560                 "$sxe_cv_feat_native_inet_funs" = "yes"; then
561                 ## user obviously rather dispenses with libbind,
562                 ## give them native bind funs
563                 sxe_cv_feat_inet_funs="native"
564         elif test "$sxe_cv_feat_native_inet_funs" = "yes"; then
565                 ## next hop is using the native inet_*() funs
566                 sxe_cv_feat_inet_funs="native"
567         else
568                 ## go with no inet_*() funs at all
569                 sxe_cv_feat_inet_funs=""
570                 AC_MSG_RESULT([none])
571                 ## I feel we should spew a warning here
572                 AC_MSG_NOTICE([
573 You seem to have no internet address conversion functions.
574 That is, to be honest, utterly unusual and you will face a lot of
575 inconsistencies in many elisp packages because of that.
576
577 However, we do not judge your system nor undermine your authority
578 thereof and whence continue the build.
579
580 In case this is a misdetection consider setting your CPPFLAGS and
581 LDFLAGS, having them point to your libbind installation.
582 In case you don't know what we are talking about or you are on a
583 miserably feature-lacking system, consider
584   http://www.isc.org/
585 and downloading the latest version of bind.])
586         fi
587 ])dnl SXE_CHECK_INET_FUNS
588
589 AC_DEFUN([SXE_CHECK_NATIVE_INET_FUNS], [dnl
590         ## defines sxe_cv_feat_native_inet_funs, will be 'yes or 'no
591
592         ## check for the corresponding headers
593         AC_CHECK_HEADERS([netdb.h arpa/inet.h])
594         AC_CHECK_HEADERS([net/route.h resolv.h])
595
596         ## cache these?
597         AC_CHECK_FUNCS([inet_ntoa inet_aton])
598         AC_CHECK_FUNCS([inet_ntop inet_pton])
599         ## oops, seems the following two have disappeared all of a sudden
600         dnl AC_CHECK_FUNCS([inet_ntop4 inet_pton4])
601
602         ## for network/host fiddling also check these
603         AC_CHECK_FUNCS([inet_addr inet_network])
604         AC_CHECK_FUNCS([inet_makeaddr])
605         AC_CHECK_FUNCS([inet_lnaof inet_netof])
606
607         ## supplied 'em all?
608         AC_MSG_CHECKING([whether inet_*() are provided natively])
609         if test "$ac_cv_func_inet_ntoa" = "yes" -a \
610                 "$ac_cv_func_inet_aton" = "yes" -a \
611                 "$ac_cv_func_inet_ntop" = "yes" -a \
612                 "$ac_cv_func_inet_pton" = "yes" -a \
613                 "$ac_cv_func_inet_addr" = "yes" -a \
614                 "$ac_cv_func_inet_network" = "yes"; then
615                 ## in future versions we may require lnaof() as well as netof()
616                 ## but at the moment we are fine with the above stuff
617                 sxe_cv_feat_native_inet_funs="yes"
618         else
619                 sxe_cv_feat_native_inet_funs="no"
620         fi
621         AC_MSG_RESULT([$sxe_cv_feat_native_inet_funs])
622 ])dnl SXE_CHECK_NATIVE_INET_FUNS
623
624 AC_DEFUN([SXE_CHECK_LIBBIND_INET_FUNS], [dnl
625         ## defines sxe_cv_feat_libbind_inet_funs, will be 'yes or 'no
626         ## key question here is still how our ipv6 support concept looks like
627         ## of course it is an established thing today, but since other big
628         ## players, like isc's bind, socks, etc. can still be configured
629         ## without ipv6, and moreover, their ipv6 design may change any second
630         ## the wisest thing for us (we're just an app raping them) is to have
631         ## a switch --with-ipv6-support or the like
632         ## coherently, all the checks below would have to reflect at least the
633         ## following scenarios
634         ## - user/system knows a fuckall about v6 (and hence doesnt want it)
635         ## - user/system is aware of v6, but user wants SXE to be v4-only
636         ## - user/system is aware of v6 and SXE is meant to support it too
637
638         AC_ARG_WITH([libbind], AS_HELP_STRING([--with-libbind], [
639                 if applicable prefer libbind socket functions over libc's,
640                 Default: Autodetect]),
641                 [with_libbind="${withval}"], [with_libbind="yes"])
642
643         ## check for isc's isc-config.sh
644         SXE_SEARCH_CONFIG_PROG([isc-config.sh])
645
646         ## we should check headers too, no?
647         if test "$have_isc_config_sh" = "no" -o -z "$ISC_CONFIG_SH"; then
648                 bind_cppflags=
649                 bind_ldflags=
650                 bind_libs=
651         else
652                 ## now this is a nice question
653                 ## ISC has recently(?) determined it would be better for
654                 ## us developers NOT to be able to obtain the installation
655                 ## info ...
656                 ## Clap. Clap. Clap. <- This is for you, ISC guys, great work!
657
658                 ## grrrrrr, as for cppflags we just bang isc-config.sh --cflags
659                 ## and also isc-config.sh --cflags/bind and moreover, as
660                 ##    case "$includedir" in
661                 ##      '${prefix}/include')
662                 ##              includedir='${prefix}/bind/include'
663                 ##              ;;
664                 ##    esac
665                 ##    case "$libdir" in
666                 ##      '${prefix}/lib')
667                 ##              libdir='${prefix}/bind/lib'
668                 ##              ;;
669                 ##    esac
670                 ##               this is undocumented, don't abuse it ;)
671                 ##               vvvvvvvvvvvvv
672                 bind_cppflags="${BIND_CPPFLAGS} $(${ISC_CONFIG_SH} --cflags)"
673                 ## the next one just if existent
674                 if test -d "$(${ISC_CONFIG_SH} --prefix)/bind/include"; then
675                         bind_cppflags="${bind_cppflags} \
676                                 -I$(${ISC_CONFIG_SH} --prefix)/bind/include"
677                 fi
678
679                 ##              this is undocumented, don't abuse it ;)
680                 ##              vvvvvvvvvvvv
681                 bind_ldflags="${BIND_LDFLAGS} $(${ISC_CONFIG_SH} --libs)"
682                 ## the next one just if existent
683                 if test -d "$(${ISC_CONFIG_SH} --prefix)/bind/lib"; then
684                         bind_ldflags="${bind_ldflags} \
685                                 -L$(${ISC_CONFIG_SH} --prefix)/bind/lib"
686                 fi
687                 ## well, we just use "-lbind" now, let's see what the ISC crew
688                 ## deems necessary next ... *sigh*
689                 bind_libs="-lbind"
690         fi
691
692         SXE_DUMP_LIBS
693         CPPFLAGS="${CPPFLAGS} ${bind_cppflags}"
694         AC_CHECK_HEADERS([netdb.h arpa/inet.h])
695         ## normally the next one is quite important, since the isc has its
696         ## routing stuff somewhere else which would otherwise conflict with
697         ## libc's route.h ... however, something's wrong here, and we don't
698         ## know yet what's going on, so chuck it
699         dnl AC_CHECK_HEADERS([net/route.h])
700         SXE_RESTORE_LIBS
701
702         ## cache these?
703         SXE_DUMP_LIBS
704         LDFLAGS="${LDFLAGS} ${bind_ldflags}"
705         SXE_CHECK_LIB_FUNCS([bind], [inet_ntoa inet_aton])
706         SXE_CHECK_LIB_FUNCS([bind], [inet_ntop inet_pton])
707         ## oops, seems the following two have disappeared all of a sudden
708         dnl SXE_CHECK_LIB_FUNCS([bind], [inet_ntop4 inet_pton4])
709         ## for network/host fiddling also check these
710         SXE_CHECK_LIB_FUNCS([bind], [inet_addr inet_network])
711         SXE_CHECK_LIB_FUNCS([bind], [inet_makeaddr])
712         SXE_CHECK_LIB_FUNCS([bind], [inet_lnaof inet_netof])
713         SXE_RESTORE_LIBS
714
715         ## supplied 'em all?
716         AC_MSG_CHECKING([whether inet_*() are provided by libbind])
717         if test "$ac_cv_lib_bind___inet_ntoa" = "yes" -a \
718                 "$ac_cv_lib_bind___inet_aton" = "yes" -a \
719                 "$ac_cv_lib_bind___inet_ntop" = "yes" -a \
720                 "$ac_cv_lib_bind___inet_pton" = "yes" -a \
721                 "$ac_cv_lib_bind___inet_addr" = "yes" -a \
722                 "$ac_cv_lib_bind___inet_network" = "yes"; then
723                 ## in future versions we may require lnaof() as well as netof()
724                 ## but at the moment we are fine with the above stuff
725                 sxe_cv_feat_libbind_inet_funs="yes"
726         else
727                 sxe_cv_feat_libbind_inet_funs="no"
728         fi
729         AC_MSG_RESULT([$sxe_cv_feat_libbind_inet_funs])
730 ])dnl SXE_CHECK_LIBBIND_INET_FUNS
731
732 dnl sxe-sockets.m4 ends here