sys_socket_h.m4 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # sys_socket_h.m4 serial 12
  2. dnl Copyright (C) 2005-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. dnl From Simon Josefsson.
  7. AC_DEFUN([gl_HEADER_SYS_SOCKET],
  8. [
  9. AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
  10. AC_REQUIRE([AC_C_INLINE])
  11. AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
  12. [gl_cv_header_sys_socket_h_selfcontained],
  13. [
  14. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
  15. [gl_cv_header_sys_socket_h_selfcontained=yes],
  16. [gl_cv_header_sys_socket_h_selfcontained=no])
  17. ])
  18. if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
  19. SYS_SOCKET_H=''
  20. dnl If the shutdown function exists, <sys/socket.h> should define
  21. dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
  22. AC_CHECK_FUNCS([shutdown])
  23. if test $ac_cv_func_shutdown = yes; then
  24. AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
  25. [gl_cv_header_sys_socket_h_shut],
  26. [
  27. AC_COMPILE_IFELSE(
  28. [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
  29. [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
  30. [gl_cv_header_sys_socket_h_shut=yes],
  31. [gl_cv_header_sys_socket_h_shut=no])
  32. ])
  33. if test $gl_cv_header_sys_socket_h_shut = no; then
  34. SYS_SOCKET_H='sys/socket.h'
  35. fi
  36. fi
  37. else
  38. SYS_SOCKET_H='sys/socket.h'
  39. fi
  40. if test -n "$SYS_SOCKET_H"; then
  41. dnl Check prerequisites of the <sys/socket.h> replacement.
  42. gl_CHECK_NEXT_HEADERS([sys/socket.h])
  43. if test $ac_cv_header_sys_socket_h = yes; then
  44. HAVE_SYS_SOCKET_H=1
  45. HAVE_WS2TCPIP_H=0
  46. else
  47. HAVE_SYS_SOCKET_H=0
  48. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  49. dnl the check for those headers unconditional; yet cygwin reports
  50. dnl that the headers are present but cannot be compiled (since on
  51. dnl cygwin, all socket information should come from sys/socket.h).
  52. AC_CHECK_HEADERS([ws2tcpip.h])
  53. if test $ac_cv_header_ws2tcpip_h = yes; then
  54. HAVE_WS2TCPIP_H=1
  55. else
  56. HAVE_WS2TCPIP_H=0
  57. fi
  58. fi
  59. gl_PREREQ_SYS_H_WINSOCK2
  60. AC_SUBST([HAVE_SYS_SOCKET_H])
  61. AC_SUBST([HAVE_WS2TCPIP_H])
  62. fi
  63. AC_SUBST([SYS_SOCKET_H])
  64. ])
  65. # Common prerequisites of of the <sys/socket.h> replacement and of the
  66. # <sys/select.h> replacement.
  67. # Sets and substitutes HAVE_WINSOCK2_H.
  68. AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
  69. [
  70. m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
  71. m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
  72. AC_CHECK_HEADERS_ONCE([sys/socket.h])
  73. if test $ac_cv_header_sys_socket_h != yes; then
  74. dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
  75. dnl the check for those headers unconditional; yet cygwin reports
  76. dnl that the headers are present but cannot be compiled (since on
  77. dnl cygwin, all socket information should come from sys/socket.h).
  78. AC_CHECK_HEADERS([winsock2.h])
  79. fi
  80. if test "$ac_cv_header_winsock2_h" = yes; then
  81. HAVE_WINSOCK2_H=1
  82. UNISTD_H_HAVE_WINSOCK2_H=1
  83. SYS_IOCTL_H_HAVE_WINSOCK2_H=1
  84. else
  85. HAVE_WINSOCK2_H=0
  86. fi
  87. AC_SUBST([HAVE_WINSOCK2_H])
  88. ])
  89. AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
  90. [
  91. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  92. AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
  93. GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
  94. ])
  95. AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
  96. [
  97. GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
  98. GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
  99. GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
  100. GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
  101. GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
  102. GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
  103. GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
  104. GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
  105. GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
  106. GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
  107. GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
  108. GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
  109. GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
  110. GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
  111. ])