From: Bruno Haible Date: Wed, 7 Mar 2007 23:04:53 +0000 (+0000) Subject: Make self-contained, so that it can be included without X-Git-Tag: cvs-readonly~841 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=b22f3b41a0494955d22a6be29480f12558e2c0b4;p=gnulib.git Make self-contained, so that it can be included without prior . --- diff --git a/ChangeLog b/ChangeLog index c771ec452..696306399 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2007-03-02 Bruno Haible + * lib/socket_.h: If sys/socket.h exists, include that and + before it. Turn HAVE_WINSOCK2_H and HAVE_WS2TCPIP_H into configute-time + values. + * m4/sys_socket_h.m4 (gl_HEADER_SYS_SOCKET): Test also whether + is self-contained. Set ABSOLUTE_SYS_SOCKET_H, + HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H, HAVE_WS2TCPIP_H. + * modules/sys_socket (Depends-on): Add absolute-header. + (Makefile.am): Substitute ABSOLUTE_SYS_SOCKET_H, HAVE_SYS_SOCKET_H, + HAVE_WINSOCK2_H, HAVE_WS2TCPIP_H into sys/socket.h. + (Include): Remove requirement of inclusion of . + +2007-03-02 Bruno Haible + * lib/byteswap_.h (bswap_32): Fix formula. 2007-03-06 Bruno Haible diff --git a/lib/socket_.h b/lib/socket_.h index 8b28b5ed3..623c98c2f 100644 --- a/lib/socket_.h +++ b/lib/socket_.h @@ -1,5 +1,5 @@ /* Provide a sys/socket header file for systems lacking it (read: MinGW). - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. Written by Simon Josefsson. This program is free software; you can redistribute it and/or modify @@ -16,12 +16,25 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H +#ifndef _GL_SYS_SOCKET_H +#define _GL_SYS_SOCKET_H -/* This file is supposed to be used on platforms that lack - sys/socket.h. It is intended to provide definitions and prototypes - needed by an application. +/* This file is supposed to be used on platforms that lack + and on platforms where cannot be included standalone. + It is intended to provide definitions and prototypes needed by an + application. */ + +#if @HAVE_SYS_SOCKET_H@ + +/* On many platforms, assumes prior inclusion of + . */ + +# include +# include @ABSOLUTE_SYS_SOCKET_H@ + +#else + +/* A platform that lacks . Currently only MinGW is supported. See the gnulib manual regarding Windows sockets. MinGW has the header files winsock2.h and @@ -39,32 +52,34 @@ releases. */ -#if HAVE_WINSOCK2_H -# include -#endif -#if HAVE_WS2TCPIP_H -# include -#endif +# if @HAVE_WINSOCK2_H@ +# include +# endif +# if @HAVE_WS2TCPIP_H@ +# include +# endif /* For shutdown(). */ -#if !defined SHUT_RD && defined SD_RECEIVE -# define SHUT_RD SD_RECEIVE -#endif -#if !defined SHUT_WR && defined SD_SEND -# define SHUT_WR SD_SEND -#endif -#if !defined SHUT_RDWR && defined SD_BOTH -# define SHUT_RDWR SD_BOTH -#endif - -#if defined _WIN32 || defined __WIN32__ -# define ENOTSOCK WSAENOTSOCK -# define EADDRINUSE WSAEADDRINUSE -# define ENETRESET WSAENETRESET -# define ECONNABORTED WSAECONNABORTED -# define ECONNRESET WSAECONNRESET -# define ENOTCONN WSAENOTCONN -# define ESHUTDOWN WSAESHUTDOWN -#endif - -#endif /* _SYS_SOCKET_H */ +# if !defined SHUT_RD && defined SD_RECEIVE +# define SHUT_RD SD_RECEIVE +# endif +# if !defined SHUT_WR && defined SD_SEND +# define SHUT_WR SD_SEND +# endif +# if !defined SHUT_RDWR && defined SD_BOTH +# define SHUT_RDWR SD_BOTH +# endif + +# if defined _WIN32 || defined __WIN32__ +# define ENOTSOCK WSAENOTSOCK +# define EADDRINUSE WSAEADDRINUSE +# define ENETRESET WSAENETRESET +# define ECONNABORTED WSAECONNABORTED +# define ECONNRESET WSAECONNRESET +# define ENOTCONN WSAENOTCONN +# define ESHUTDOWN WSAESHUTDOWN +# endif + +#endif /* HAVE_SYS_SOCKET_H */ + +#endif /* _GL_SYS_SOCKET_H */ diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4 index d3e45b48c..ce5acf6e2 100644 --- a/m4/sys_socket_h.m4 +++ b/m4/sys_socket_h.m4 @@ -1,5 +1,5 @@ -# sys_socket_h.m4 serial 2 -dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +# sys_socket_h.m4 serial 3 +dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -8,16 +8,47 @@ dnl From Simon Josefsson. AC_DEFUN([gl_HEADER_SYS_SOCKET], [ - AC_CHECK_HEADERS_ONCE([sys/socket.h]) - if test $ac_cv_header_sys_socket_h = yes; then + AC_CACHE_CHECK([whether is self-contained], + [gl_cv_header_sys_socket_h_selfcontained], + [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], [])], + [gl_cv_header_sys_socket_h_selfcontained=yes], + [gl_cv_header_sys_socket_h_selfcontained=no]) + ]) + if test $gl_cv_header_sys_socket_h_selfcontained = yes; then SYS_SOCKET_H='' else - dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make - dnl the check for those headers unconditional; yet cygwin reports - dnl that the headers are present but cannot be compiled (since on - dnl cygwin, all socket information should come from sys/socket.h). - AC_CHECK_HEADERS([winsock2.h ws2tcpip.h]) SYS_SOCKET_H='sys/socket.h' + + AC_CHECK_HEADERS([sys/socket.h]) + gl_ABSOLUTE_HEADER([sys/socket.h]) + ABSOLUTE_SYS_SOCKET_H=\"$gl_cv_absolute_sys_socket_h\" + AC_SUBST([ABSOLUTE_SYS_SOCKET_H]) + if test $ac_cv_header_sys_socket_h = yes; then + HAVE_SYS_SOCKET_H=1 + HAVE_WINSOCK2_H=0 + HAVE_WS2TCPIP_H=0 + else + HAVE_SYS_SOCKET_H=0 + dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make + dnl the check for those headers unconditional; yet cygwin reports + dnl that the headers are present but cannot be compiled (since on + dnl cygwin, all socket information should come from sys/socket.h). + AC_CHECK_HEADERS([winsock2.h ws2tcpip.h]) + if test $ac_cv_header_winsock2_h = yes; then + HAVE_WINSOCK2_H=1 + else + HAVE_WINSOCK2_H=0 + fi + if test $ac_cv_header_ws2tcpip_h = yes; then + HAVE_WS2TCPIP_H=1 + else + HAVE_WS2TCPIP_H=0 + fi + fi + AC_SUBST([HAVE_SYS_SOCKET_H]) + AC_SUBST([HAVE_WINSOCK2_H]) + AC_SUBST([HAVE_WS2TCPIP_H]) fi - AC_SUBST(SYS_SOCKET_H) + AC_SUBST([SYS_SOCKET_H]) ]) diff --git a/modules/sys_socket b/modules/sys_socket index a1785aaa9..9e0c6b534 100644 --- a/modules/sys_socket +++ b/modules/sys_socket @@ -7,6 +7,7 @@ m4/sys_socket_h.m4 m4/sockpfaf.m4 Depends-on: +absolute-header configure.ac: gl_HEADER_SYS_SOCKET @@ -20,14 +21,17 @@ BUILT_SOURCES += $(SYS_SOCKET_H) sys/socket.h: socket_.h @MKDIR_P@ sys { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ - cat $(srcdir)/socket_.h; \ + sed -e 's|@''ABSOLUTE_SYS_SOCKET_H''@|$(ABSOLUTE_SYS_SOCKET_H)|g' \ + -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \ + -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \ + < $(srcdir)/socket_.h; \ } > $@-t mv -f $@-t $@ MOSTLYCLEANFILES += sys/socket.h sys/socket.h-t MOSTLYCLEANDIRS += sys Include: -#include #include License: