Correct the va_copy definition for AIX 5.
authorBruno Haible <bruno@clisp.org>
Tue, 11 Mar 2008 04:36:15 +0000 (05:36 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 11 Mar 2008 04:36:15 +0000 (05:36 +0100)
ChangeLog
doc/posix-functions/va_copy.texi
m4/stdarg.m4
modules/stdarg

index 4266b9d..758d954 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-03-10  Peter O'Gorman  <bug-gnulib@mlists.thewrittenword.com>
+            Bruno Haible  <bruno@clisp.org>
+
+       Make va_copy work with some version of xlc on AIX 5.1.
+       * lib/stdarg.in.h: New file.
+       * m4/stdarg.m4 (gl_STDARG_H): Initialize STDARG_H and NEXT_STDARG_H.
+       On AIX, use a <stdarg.h> file substitute.
+       * modules/stdarg (Files): Add lib/stdarg.in.h.
+       (Depends-on): Add include_next.
+       (Makefile.am): Build a stdarg.h substitute if requested.
+       * doc/posix-functions/va_copy.texi: Document the platforms lacking it.
+
 2008-03-10  Bruno Haible  <bruno@clisp.org>
 
        * m4/include_next.m4 (gl_CHECK_NEXT_HEADERS): Document a restriction.
index c5a012b..9bba218 100644 (file)
@@ -9,7 +9,8 @@ Gnulib module: stdarg
 Portability problems fixed by Gnulib:
 @itemize
 @item
-This macro is missing on some platforms.
+This macro is missing on some platforms:
+AIX 5.1 with cc or xlc, HP-UX 11 with cc, IRIX 6.5 with cc, OSF/1 5.1 with cc.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index e8e680a..21910e4 100644 (file)
@@ -1,5 +1,5 @@
-# stdarg.m4 serial 1
-dnl Copyright (C) 2006 Free Software Foundation, Inc.
+# stdarg.m4 serial 2
+dnl Copyright (C) 2006, 2008 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.
@@ -9,6 +9,8 @@ dnl Provide a working va_copy in combination with <stdarg.h>.
 
 AC_DEFUN([gl_STDARG_H],
 [
+  STDARG_H='';                AC_SUBST([STDARG_H])
+  NEXT_STDARG_H='<stdarg.h>'; AC_SUBST([NEXT_STDARG_H])
   AC_MSG_CHECKING([for va_copy])
   AC_CACHE_VAL([gl_cv_func_va_copy], [
     AC_TRY_COMPILE([#include <stdarg.h>], [
@@ -19,22 +21,47 @@ void (*func) (va_list, va_list) = va_copy;
       [gl_cv_func_va_copy=yes], [gl_cv_func_va_copy=no])])
   AC_MSG_RESULT([$gl_cv_func_va_copy])
   if test $gl_cv_func_va_copy = no; then
-    # Provide a substitute, either __va_copy or as a simple assignment.
-    AC_CACHE_VAL([gl_cv_func___va_copy], [
-      AC_TRY_COMPILE([#include <stdarg.h>], [
+    dnl Provide a substitute.
+    dnl Usually a simple definition in <config.h> is enough. Not so on AIX 5
+    dnl with some versions of the /usr/vac/bin/cc compiler. It has an <stdarg.h>
+    dnl which does '#undef va_copy', leading to a missing va_copy symbol. For
+    dnl this platform, we use an <stdarg.h> substitute. But we cannot use this
+    dnl approach on other platforms, because <stdarg.h> often defines only
+    dnl preprocessor macros and gl_ABSOLUTE_HEADER, gl_CHECK_NEXT_HEADERS do
+    dnl not work in this situation.
+    AC_EGREP_CPP([vaccine],
+      [#if defined _AIX && !defined __GNUC__
+        AIX vaccine
+       #endif
+      ], [gl_aixcc=yes], [gl_aixcc=no])
+    if test $gl_aixcc = yes; then
+      dnl Provide a substitute <stdarg.h> file.
+      STDARG_H=stdarg.h
+      gl_CHECK_NEXT_HEADERS([stdarg.h])
+      dnl Fallback for the case when <stdarg.h> contains only macro definitions.
+      if test "$gl_cv_next_stdarg_h" = '""'; then
+        gl_cv_next_stdarg_h='"///usr/include/stdarg.h"'
+        NEXT_STDARG_H="$gl_cv_next_stdarg_h"
+      fi
+    else
+      dnl Provide a substitute in <config.h>, either __va_copy or as a simple
+      dnl assignment.
+      AC_CACHE_VAL([gl_cv_func___va_copy], [
+        AC_TRY_COMPILE([#include <stdarg.h>], [
 #ifndef __va_copy
 error, bail out
 #endif
 ],
-        [gl_cv_func___va_copy=yes], [gl_cv_func___va_copy=no])])
-    if test $gl_cv_func___va_copy = yes; then
-      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.  */
+          [gl_cv_func___va_copy=yes], [gl_cv_func___va_copy=no])])
+      if test $gl_cv_func___va_copy = yes; then
+        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.])
+        AC_DEFINE([va_copy], [gl_va_copy],
+          [Define as a macro for copying va_list variables.])
+      fi
     fi
   fi
 ])
index 48febb2..f0b630f 100644 (file)
@@ -2,9 +2,11 @@ Description:
 An <stdarg.h> that conforms to C99.
 
 Files:
+lib/stdarg.in.h
 m4/stdarg.m4
 
 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,19 @@ 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 $@-t $@
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e 's/@''INCLUDE_NEXT''@/$(INCLUDE_NEXT)/g' \
+             -e 's|@''NEXT_STDARG_H''@|$(NEXT_STDARG_H)|g' \
+             < $(srcdir)/stdarg.in.h; \
+       } > $@-t
+       mv $@-t $@
+MOSTLYCLEANFILES += stdarg.h stdarg.h-t
 
 Include:
 #include <stdarg.h>