Blame gnulib/m4/stdarg.m4

Packit eba2e2
# stdarg.m4 serial 6
Packit eba2e2
dnl Copyright (C) 2006, 2008-2014 Free Software Foundation, Inc.
Packit eba2e2
dnl This file is free software; the Free Software Foundation
Packit eba2e2
dnl gives unlimited permission to copy and/or distribute it,
Packit eba2e2
dnl with or without modifications, as long as this notice is preserved.
Packit eba2e2
Packit eba2e2
dnl From Bruno Haible.
Packit eba2e2
dnl Provide a working va_copy in combination with <stdarg.h>.
Packit eba2e2
Packit eba2e2
AC_DEFUN([gl_STDARG_H],
Packit eba2e2
[
Packit eba2e2
  STDARG_H=''
Packit eba2e2
  NEXT_STDARG_H='<stdarg.h>'
Packit eba2e2
  AC_MSG_CHECKING([for va_copy])
Packit eba2e2
  AC_CACHE_VAL([gl_cv_func_va_copy], [
Packit eba2e2
    AC_COMPILE_IFELSE(
Packit eba2e2
      [AC_LANG_PROGRAM(
Packit eba2e2
         [[#include <stdarg.h>]],
Packit eba2e2
         [[
Packit eba2e2
#ifndef va_copy
Packit eba2e2
void (*func) (va_list, va_list) = va_copy;
Packit eba2e2
#endif
Packit eba2e2
         ]])],
Packit eba2e2
      [gl_cv_func_va_copy=yes],
Packit eba2e2
      [gl_cv_func_va_copy=no])])
Packit eba2e2
  AC_MSG_RESULT([$gl_cv_func_va_copy])
Packit eba2e2
  if test $gl_cv_func_va_copy = no; then
Packit eba2e2
    dnl Provide a substitute.
Packit eba2e2
    dnl Usually a simple definition in <config.h> is enough. Not so on AIX 5
Packit eba2e2
    dnl with some versions of the /usr/vac/bin/cc compiler. It has an <stdarg.h>
Packit eba2e2
    dnl which does '#undef va_copy', leading to a missing va_copy symbol. For
Packit eba2e2
    dnl this platform, we use an <stdarg.h> substitute. But we cannot use this
Packit eba2e2
    dnl approach on other platforms, because <stdarg.h> often defines only
Packit eba2e2
    dnl preprocessor macros and gl_ABSOLUTE_HEADER, gl_CHECK_NEXT_HEADERS do
Packit eba2e2
    dnl not work in this situation.
Packit eba2e2
    AC_EGREP_CPP([vaccine],
Packit eba2e2
      [#if defined _AIX && !defined __GNUC__
Packit eba2e2
        AIX vaccine
Packit eba2e2
       #endif
Packit eba2e2
      ], [gl_aixcc=yes], [gl_aixcc=no])
Packit eba2e2
    if test $gl_aixcc = yes; then
Packit eba2e2
      dnl Provide a substitute <stdarg.h> file.
Packit eba2e2
      STDARG_H=stdarg.h
Packit eba2e2
      gl_NEXT_HEADERS([stdarg.h])
Packit eba2e2
      dnl Fallback for the case when <stdarg.h> contains only macro definitions.
Packit eba2e2
      if test "$gl_cv_next_stdarg_h" = '""'; then
Packit eba2e2
        gl_cv_next_stdarg_h='"///usr/include/stdarg.h"'
Packit eba2e2
        NEXT_STDARG_H="$gl_cv_next_stdarg_h"
Packit eba2e2
      fi
Packit eba2e2
    else
Packit eba2e2
      dnl Provide a substitute in <config.h>, either __va_copy or as a simple
Packit eba2e2
      dnl assignment.
Packit eba2e2
      gl_CACHE_VAL_SILENT([gl_cv_func___va_copy], [
Packit eba2e2
        AC_COMPILE_IFELSE(
Packit eba2e2
          [AC_LANG_PROGRAM(
Packit eba2e2
             [[#include <stdarg.h>]],
Packit eba2e2
             [[
Packit eba2e2
#ifndef __va_copy
Packit eba2e2
error, bail out
Packit eba2e2
#endif
Packit eba2e2
             ]])],
Packit eba2e2
          [gl_cv_func___va_copy=yes],
Packit eba2e2
          [gl_cv_func___va_copy=no])])
Packit eba2e2
      if test $gl_cv_func___va_copy = yes; then
Packit eba2e2
        AC_DEFINE([va_copy], [__va_copy],
Packit eba2e2
          [Define as a macro for copying va_list variables.])
Packit eba2e2
      else
Packit eba2e2
        AH_VERBATIM([gl_VA_COPY], [/* A replacement for va_copy, if needed.  */
Packit eba2e2
#define gl_va_copy(a,b) ((a) = (b))])
Packit eba2e2
        AC_DEFINE([va_copy], [gl_va_copy],
Packit eba2e2
          [Define as a macro for copying va_list variables.])
Packit eba2e2
      fi
Packit eba2e2
    fi
Packit eba2e2
  fi
Packit eba2e2
  AC_SUBST([STDARG_H])
Packit eba2e2
  AM_CONDITIONAL([GL_GENERATE_STDARG_H], [test -n "$STDARG_H"])
Packit eba2e2
  AC_SUBST([NEXT_STDARG_H])
Packit eba2e2
])