On Wed, Feb 27, 2008 at 05:03:01AM +0100, Bruno Haible wrote:

> Instead, how about generating the stdarg.h replacement only for
>   defined _AIX && !defined __GNUC__
> and letting it look like this:
> 
> #ifndef _GL_STDARG_H
> #include "/usr/include/stdarg.h"
> #ifndef va_copy
> #define va_copy(a,b) ((a) = (b))
> #endif
> #endif
> 
> It should be safe to assume that for non-GNU compilers on AIX the <stdarg.h>
> is in /usr/include.

I am not sure that I agree.

Since this problem will only exist on compilers and systems without
va_copy, __va_copy and #include_next, I think it is probably a safe
bet to hardcode ///usr/include/stdarg.h on all such systems.

The only system that we have that does not have #include_next with
the native compiler is aix4.3.3 with xlc. Even there #include_next is
available with -qlanglvl=extc89, or simply invoking the compiler with
cc rather than xlc.

This patch hardcodes ///usr/include/stdarg.h if the system does not
have #include_next, va_copy or __va_copy.

Peter 
diff --git a/doc/posix-functions/va_copy.texi b/doc/posix-functions/va_copy.texi
index c5a012b..a2ce0e3 100644
--- a/doc/posix-functions/va_copy.texi
+++ b/doc/posix-functions/va_copy.texi
@@ -10,6 +10,13 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This macro is missing on some platforms.
[EMAIL PROTECTED]
+On some platforms va_copy is available as __va_copy and so needs to be
+defined as such.
[EMAIL PROTECTED]
+On AIX systems with xlc, the @code{-qlanglvl=extc99} or
[EMAIL PROTECTED] is normally required for va_copy to be
+defined. This module makes it available even without that flag.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index e8e680a..1040df7 100644
--- a/m4/stdarg.m4
+++ b/m4/stdarg.m4
@@ -9,6 +9,10 @@ dnl Provide a working va_copy in combination with <stdarg.h>.
 
 AC_DEFUN([gl_STDARG_H],
 [
+  HAVE_VA_COPY=1
+  STDARG_H=
+  AC_SUBST([STDARG_H])
+  AC_SUBST([HAVE_VA_COPY])
   AC_MSG_CHECKING([for va_copy])
   AC_CACHE_VAL([gl_cv_func_va_copy], [
     AC_TRY_COMPILE([#include <stdarg.h>], [
@@ -31,10 +35,13 @@ error, bail out
       AC_DEFINE([va_copy], [__va_copy],
         [Define as a macro for copying va_list variables.])
     else
-      AH_VERBATIM([gl_VA_COPY], [/* A replacement for va_copy, if needed.  */
-#define gl_va_copy(a,b) ((a) = (b))])
-      AC_DEFINE([va_copy], [gl_va_copy],
-        [Define as a macro for copying va_list variables.])
+      STDARG_H=stdarg.h
+      HAVE_VA_COPY=0
+      gl_CHECK_NEXT_HEADERS([stdarg.h])
+      if test "x$gl_cv_next_stdarg_h" = "x\"\""; then
+        gl_cv_next_stdarg_h=\"///usr/include/stdarg.h\"
+        NEXT_STDARG_H=\"///usr/include/stdarg.h\"
+      fi
     fi
   fi
 ])
diff --git a/modules/stdarg b/modules/stdarg
index 48febb2..e386f3e 100644
--- a/modules/stdarg
+++ b/modules/stdarg
@@ -3,8 +3,10 @@ An <stdarg.h> that conforms to C99.
 
 Files:
 m4/stdarg.m4
+lib/stdarg.in.h
 
 Depends-on:
+include_next
 
 configure.ac-early:
 dnl Some compilers (e.g., AIX 5.3 cc) need to be in c99 mode
@@ -17,6 +19,21 @@ configure.ac:
 gl_STDARG_H
 
 Makefile.am:
+BUILT_SOURCES += $(STDARG_H)
+
+# We need the following in order to create <stdarg.h> when the system
+# doesn't have one that works with the given compiler.
+stdarg.h: stdarg.in.h
+       rm -f [EMAIL PROTECTED] $@
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+       sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
+               -e 's|@''NEXT_STDARG_H''@|$(NEXT_STDARG_H)|g' \
+               -e 's/@''HAVE_VA_COPY''@/$(HAVE_VA_COPY)/g' \
+       < $(srcdir)/stdarg.in.h; \
+       } > [EMAIL PROTECTED]
+       mv [EMAIL PROTECTED] $@
+
+MOSTLYCLEANFILES += stdarg.h stdarg.h-t
 
 Include:
 #include <stdarg.h>
--- /dev/null   Wed Feb 27 07:11:00 2008
+++ a/lib/stdarg.in.h   Tue Feb 26 21:18:57 2008
@@ -0,0 +1,31 @@
+/* 
+   Copyright (C) 2008 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 3, 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_STDARG_H
+
+/* The include_next requires a split double-inclusion guard.  */
[EMAIL PROTECTED]@ @NEXT_STDARG_H@
+
+#ifndef _GL_STDARG_H
+#define _GL_STDARG_H
+
+#ifndef va_copy
+#define va_copy(a,b) ((a) = (b))
+#endif
+
+#endif /* _GL_STDARG_H */
+#endif /* _GL_STDARG_H */

Reply via email to