socketlib.m4 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # socketlib.m4 serial 3
  2. dnl Copyright (C) 2008-2021 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. dnl gl_SOCKETLIB
  7. dnl Determines the library to use for socket functions.
  8. dnl Sets and AC_SUBSTs LIBSOCKET.
  9. AC_DEFUN([gl_SOCKETLIB],
  10. [
  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. dnl If the function WSAStartup exists (declared in <winsock2.h> and
  16. dnl defined through -lws2_32), we need to call it.
  17. AC_CACHE_CHECK([for WSAStartup],
  18. [gl_cv_func_wsastartup], [
  19. gl_save_LIBS="$LIBS"
  20. LIBS="$LIBS -lws2_32"
  21. AC_LINK_IFELSE(
  22. [AC_LANG_PROGRAM([[
  23. #ifdef HAVE_WINSOCK2_H
  24. # include <winsock2.h>
  25. #endif]], [[
  26. WORD wVersionRequested = MAKEWORD(1, 1);
  27. WSADATA wsaData;
  28. int err = WSAStartup(wVersionRequested, &wsaData);
  29. WSACleanup ();
  30. ]])
  31. ],
  32. [gl_cv_func_wsastartup=yes],
  33. [gl_cv_func_wsastartup=no])
  34. LIBS="$gl_save_LIBS"
  35. ])
  36. if test "$gl_cv_func_wsastartup" = "yes"; then
  37. AC_DEFINE([WINDOWS_SOCKETS], [1], [Define if WSAStartup is needed.])
  38. LIBSOCKET='-lws2_32'
  39. fi
  40. else
  41. dnl Unix API.
  42. dnl Solaris has most socket functions in libsocket.
  43. dnl Haiku has most socket functions in libnetwork.
  44. dnl BeOS has most socket functions in libnet.
  45. dnl On HP-UX, do NOT link with libxnet, because in 64-bit mode this would
  46. dnl break code (e.g. in libraries) that invokes accept(), getpeername(),
  47. dnl getsockname(), getsockopt(), or recvfrom() with a 32-bit addrlen. See
  48. dnl "man xopen_networking" for details.
  49. AC_CACHE_CHECK([for library containing setsockopt], [gl_cv_lib_socket], [
  50. gl_cv_lib_socket=
  51. AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
  52. #ifdef __cplusplus
  53. "C"
  54. #endif
  55. char setsockopt();]], [[setsockopt();]])],
  56. [],
  57. [gl_save_LIBS="$LIBS"
  58. LIBS="$gl_save_LIBS -lsocket"
  59. AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
  60. #ifdef __cplusplus
  61. "C"
  62. #endif
  63. char setsockopt();]], [[setsockopt();]])],
  64. [gl_cv_lib_socket="-lsocket"])
  65. if test -z "$gl_cv_lib_socket"; then
  66. LIBS="$gl_save_LIBS -lnetwork"
  67. AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
  68. #ifdef __cplusplus
  69. "C"
  70. #endif
  71. char setsockopt();]], [[setsockopt();]])],
  72. [gl_cv_lib_socket="-lnetwork"])
  73. if test -z "$gl_cv_lib_socket"; then
  74. LIBS="$gl_save_LIBS -lnet"
  75. AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern
  76. #ifdef __cplusplus
  77. "C"
  78. #endif
  79. char setsockopt();]], [[setsockopt();]])],
  80. [gl_cv_lib_socket="-lnet"])
  81. fi
  82. fi
  83. LIBS="$gl_save_LIBS"
  84. ])
  85. if test -z "$gl_cv_lib_socket"; then
  86. gl_cv_lib_socket="none needed"
  87. fi
  88. ])
  89. if test "$gl_cv_lib_socket" != "none needed"; then
  90. LIBSOCKET="$gl_cv_lib_socket"
  91. fi
  92. fi
  93. AC_SUBST([LIBSOCKET])
  94. ])