Make <netinet/in.h> self-contained, i.e. allow it to be included without
authorBruno Haible <bruno@clisp.org>
Wed, 7 Mar 2007 23:11:37 +0000 (23:11 +0000)
committerBruno Haible <bruno@clisp.org>
Wed, 7 Mar 2007 23:11:37 +0000 (23:11 +0000)
prior <sys/types.h>.

ChangeLog
lib/netinet_in_.h [new file with mode: 0644]
m4/netinet_in_h.m4
modules/netinet_in

index ce766ebf9453d41fdeeecf7310c907ebbefb7069..8dee0e79c7698013a53b02ea460c632d2bdaaee9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-03-02  Bruno Haible  <bruno@clisp.org>
+
+       * lib/netinet_in_.h: New file.
+       * m4/netinet_in_h.m4 (gl_HEADER_NETINET_IN): Test whether netinet/in.h
+       is self-contained. Set ABSOLUTE_NETINET_IN_H, HAVE_NETINET_IN_H.
+       * modules/netinet_in (Files): Add lib/netinet_in_.h.
+       (Depends-on): Add absolute-header.
+       (Makefile.am): Substitute ABSOLUTE_NETINET_IN_H, HAVE_NETINET_IN_H
+       into netinet/in.h.
+
 2007-03-03  Bruno Haible  <bruno@clisp.org>
 
        * lib/sys_select_.h: New file.
diff --git a/lib/netinet_in_.h b/lib/netinet_in_.h
new file mode 100644 (file)
index 0000000..4a53605
--- /dev/null
@@ -0,0 +1,37 @@
+/* Substitute for <netinet/in.h>.
+   Copyright (C) 2007 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _GL_NETINET_IN_H
+#define _GL_NETINET_IN_H
+
+#if @HAVE_NETINET_IN_H@
+
+/* On many platforms, <netinet/in.h> assumes prior inclusion of
+   <sys/types.h>.  */
+
+# include <sys/types.h>
+# include @ABSOLUTE_NETINET_IN_H@
+
+#else
+
+/* A platform that lacks <netinet/in.h>.  */
+
+# include <sys/socket.h>
+
+#endif
+
+#endif /* _GL_NETINET_IN_H */
index d73531a051eb2b0d2474797c3472f86f89bb0cdd..966bfe6a11c6ea7bc354846f86c12ea03d3b4f22 100644 (file)
@@ -1,18 +1,32 @@
-# netinet_in_h.m4 serial 1
-dnl Copyright (C) 2006 Free Software Foundation, Inc.
+# netinet_in_h.m4 serial 2
+dnl Copyright (C) 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.
 
-dnl Written by Simon Josefsson
-
 AC_DEFUN([gl_HEADER_NETINET_IN],
 [
-  AC_CHECK_HEADERS_ONCE([netinet/in.h])
-  if test $ac_cv_header_netinet_in_h = yes; then
+  AC_CACHE_CHECK([whether <netinet/in.h> is self-contained],
+    [gl_cv_header_netinet_in_h_selfcontained],
+    [
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netinet/in.h>], [])],
+        [gl_cv_header_netinet_in_h_selfcontained=yes],
+        [gl_cv_header_netinet_in_h_selfcontained=no])
+    ])
+  if test $gl_cv_header_netinet_in_h_selfcontained = yes; then
     NETINET_IN_H=''
   else
     NETINET_IN_H='netinet/in.h'
+    AC_CHECK_HEADERS([netinet/in.h])
+    gl_ABSOLUTE_HEADER([netinet/in.h])
+    ABSOLUTE_NETINET_IN_H=\"$gl_cv_absolute_netinet_in_h\"
+    AC_SUBST([ABSOLUTE_NETINET_IN_H])
+    if test $ac_cv_header_netinet_in_h = yes; then
+      HAVE_NETINET_IN_H=1
+    else
+      HAVE_NETINET_IN_H=0
+    fi
+    AC_SUBST([HAVE_NETINET_IN_H])
   fi
-  AC_SUBST(NETINET_IN_H)
+  AC_SUBST([NETINET_IN_H])
 ])
index 6e6665903d5ed7d2f97021c184eefca94a436cbe..af836befa916586443519ccec8811da8561782e8 100644 (file)
@@ -1,10 +1,12 @@
 Description:
-A <netinet/in.h> for systems lacking it (e.g., Mingw).
+A <netinet/in.h> for systems lacking it.
 
 Files:
+lib/netinet_in_.h
 m4/netinet_in_h.m4
 
 Depends-on:
+absolute-header
 sys_socket
 
 configure.ac:
@@ -20,7 +22,9 @@ netinet/in.h:
        @MKDIR_P@ netinet
        rm -f $@-t $@
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         echo '#include <sys/socket.h>'; \
+         sed -e 's|@''ABSOLUTE_NETINET_IN_H''@|$(ABSOLUTE_NETINET_IN_H)|g' \
+             -e 's|@''HAVE_NETINET_IN_H''@|$(HAVE_NETINET_IN_H)|g' \
+             < $(srcdir)/netinet_in_.h; \
        } > $@-t
        mv $@-t $@
 MOSTLYCLEANFILES += netinet/in.h netinet/in.h-t