c7bd6646a6ea4a7059ced424215b5fd6be0d3075
[gnulib.git] / m4 / sockets.m4
1 # sockets.m4 serial 2
2 dnl Copyright (C) 2008 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     AC_CACHE_CHECK([whether setsockopt requires -lsocket], [gl_cv_lib_socket], [
36       gl_cv_lib_socket=no
37       AC_TRY_LINK([extern
38 #ifdef __cplusplus
39 "C"
40 #endif
41 char setsockopt();], [setsockopt();],
42         [],
43         [gl_save_LIBS="$LIBS"
44          LIBS="$LIBS -lsocket"
45          AC_TRY_LINK([extern
46 #ifdef __cplusplus
47 "C"
48 #endif
49 char setsockopt();], [setsockopt();],
50            [gl_cv_lib_socket=yes])
51          LIBS="$gl_save_LIBS"
52         ])
53     ])
54     if test $gl_cv_lib_socket = yes; then
55       LIBSOCKET='-lsocket'
56     fi
57   fi
58   AC_SUBST([LIBSOCKET])
59   gl_PREREQ_SOCKETS
60 ])
61
62 # Prerequisites of lib/sockets.c.
63 AC_DEFUN([gl_PREREQ_SOCKETS], [
64   :
65 ])