summaryrefslogtreecommitdiffstats
path: root/gl/m4/socketlib.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/socketlib.m4')
-rw-r--r--gl/m4/socketlib.m486
1 files changed, 86 insertions, 0 deletions
diff --git a/gl/m4/socketlib.m4 b/gl/m4/socketlib.m4
new file mode 100644
index 0000000..b08a72f
--- /dev/null
+++ b/gl/m4/socketlib.m4
@@ -0,0 +1,86 @@
1# socketlib.m4 serial 1
2dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
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 gl_SOCKETLIB
8dnl Determines the library to use for socket functions.
9dnl Sets and AC_SUBSTs LIBSOCKET.
10
11AC_DEFUN([gl_SOCKETLIB],
12[
13 gl_PREREQ_SYS_H_WINSOCK2 dnl for HAVE_WINSOCK2_H
14 LIBSOCKET=
15 if test $HAVE_WINSOCK2_H = 1; then
16 dnl Native Windows API (not Cygwin).
17 AC_CACHE_CHECK([if we need to call WSAStartup in winsock2.h and -lws2_32],
18 [gl_cv_func_wsastartup], [
19 gl_save_LIBS="$LIBS"
20 LIBS="$LIBS -lws2_32"
21 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
22#ifdef HAVE_WINSOCK2_H
23# include <winsock2.h>
24#endif]], [[
25 WORD wVersionRequested = MAKEWORD(1, 1);
26 WSADATA wsaData;
27 int err = WSAStartup(wVersionRequested, &wsaData);
28 WSACleanup ();]])],
29 gl_cv_func_wsastartup=yes, gl_cv_func_wsastartup=no)
30 LIBS="$gl_save_LIBS"
31 ])
32 if test "$gl_cv_func_wsastartup" = "yes"; then
33 AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
34 LIBSOCKET='-lws2_32'
35 fi
36 else
37 dnl Unix API.
38 dnl Solaris has most socket functions in libsocket.
39 dnl Haiku has most socket functions in libnetwork.
40 dnl BeOS has most socket functions in libnet.
41 AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
42 gl_cv_lib_socket=
43 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
44#ifdef __cplusplus
45"C"
46#endif
47char setsockopt();]], [[setsockopt();]])],
48 [],
49 [gl_save_LIBS="$LIBS"
50 LIBS="$gl_save_LIBS -lsocket"
51 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
52#ifdef __cplusplus
53"C"
54#endif
55char setsockopt();]], [[setsockopt();]])],
56 [gl_cv_lib_socket="-lsocket"])
57 if test -z "$gl_cv_lib_socket"; then
58 LIBS="$gl_save_LIBS -lnetwork"
59 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
60#ifdef __cplusplus
61"C"
62#endif
63char setsockopt();]], [[setsockopt();]])],
64 [gl_cv_lib_socket="-lnetwork"])
65 if test -z "$gl_cv_lib_socket"; then
66 LIBS="$gl_save_LIBS -lnet"
67 AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
68#ifdef __cplusplus
69"C"
70#endif
71char setsockopt();]], [[setsockopt();]])],
72 [gl_cv_lib_socket="-lnet"])
73 fi
74 fi
75 LIBS="$gl_save_LIBS"
76 ])
77 if test -z "$gl_cv_lib_socket"; then
78 gl_cv_lib_socket="none needed"
79 fi
80 ])
81 if test "$gl_cv_lib_socket" != "none needed"; then
82 LIBSOCKET="$gl_cv_lib_socket"
83 fi
84 fi
85 AC_SUBST([LIBSOCKET])
86])