1 # sockets.m4 serial 6
2 dnl Copyright (C) 2008, 2009, 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.
7 AC_DEFUN([gl_SOCKETS],
8 [
9 AC_REQUIRE([AC_C_INLINE])
11 gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
12 LIBSOCKET=
13 if test $HAVE_WINSOCK2_H = 1; then
14 dnl Native Windows API (not Cygwin).
15 AC_CACHE_CHECK([if we need to call WSAStartup in winsock2.h and -lws2_32],
16 [gl_cv_func_wsastartup], [
17 gl_save_LIBS="$LIBS"
18 LIBS="$LIBS -lws2_32"
19 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
20 #ifdef HAVE_WINSOCK2_H
21 # include <winsock2.h>
22 #endif]], [[
23 WORD wVersionRequested = MAKEWORD(1, 1);
24 WSADATA wsaData;
25 int err = WSAStartup(wVersionRequested, &wsaData);
26 WSACleanup ();]])],
27 gl_cv_func_wsastartup=yes, gl_cv_func_wsastartup=no)
28 LIBS="$gl_save_LIBS"
29 ])
30 if test "$gl_cv_func_wsastartup" = "yes"; then
31 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
32 LIBSOCKET='-lws2_32'
33 fi
34 else
35 dnl Unix API.
36 dnl Solaris has most socket functions in libsocket.
37 dnl Haiku has most socket functions in libnetwork.
38 dnl BeOS has most socket functions in libnet.
39 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
40 gl_cv_lib_socket=
41 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
42 #ifdef __cplusplus
43 "C"
44 #endif
45 char setsockopt();]], [[setsockopt();]])],
46 [],
47 [gl_save_LIBS="$LIBS"
48 LIBS="$gl_save_LIBS -lsocket"
49 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
50 #ifdef __cplusplus
51 "C"
52 #endif
53 char setsockopt();]], [[setsockopt();]])],
54 [gl_cv_lib_socket="-lsocket"])
55 if test -z "$gl_cv_lib_socket"; then
56 LIBS="$gl_save_LIBS -lnetwork"
57 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
58 #ifdef __cplusplus
59 "C"
60 #endif
61 char setsockopt();]], [[setsockopt();]])],
62 [gl_cv_lib_socket="-lnetwork"])
63 if test -z "$gl_cv_lib_socket"; then
64 LIBS="$gl_save_LIBS -lnet"
65 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
66 #ifdef __cplusplus
67 "C"
68 #endif
69 char setsockopt();]], [[setsockopt();]])],
70 [gl_cv_lib_socket="-lnet"])
71 fi
72 fi
73 LIBS="$gl_save_LIBS"
74 ])
75 if test -z "$gl_cv_lib_socket"; then
76 gl_cv_lib_socket="none needed"
77 fi
78 ])
79 if test "$gl_cv_lib_socket" != "none needed"; then
80 LIBSOCKET="$gl_cv_lib_socket"
81 fi
82 fi
83 AC_SUBST([LIBSOCKET])
84 gl_PREREQ_SOCKETS
85 ])
87 # Prerequisites of lib/sockets.c.
88 AC_DEFUN([gl_PREREQ_SOCKETS], [
89 :
90 ])