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