1# stdarg.m4 serial 7
2dnl Copyright (C) 2006, 2008-2020 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8dnl Provide a working va_copy in combination with <stdarg.h>.
9
10AC_DEFUN([gl_STDARG_H],
11[
12  STDARG_H=''
13  NEXT_STDARG_H='<stdarg.h>'
14  AC_CACHE_CHECK([for va_copy],
15    [gl_cv_func_va_copy],
16    [AC_COMPILE_IFELSE(
17       [AC_LANG_PROGRAM(
18          [[#include <stdarg.h>]],
19          [[
20#ifndef va_copy
21void (*func) (va_list, va_list) = va_copy;
22#endif
23          ]])],
24       [gl_cv_func_va_copy=yes],
25       [gl_cv_func_va_copy=no])
26    ])
27  if test $gl_cv_func_va_copy = no; then
28    dnl Provide a substitute.
29    dnl Usually a simple definition in <config.h> is enough. Not so on AIX 5
30    dnl with some versions of the /usr/vac/bin/cc compiler. It has an <stdarg.h>
31    dnl which does '#undef va_copy', leading to a missing va_copy symbol. For
32    dnl this platform, we use an <stdarg.h> substitute. But we cannot use this
33    dnl approach on other platforms, because <stdarg.h> often defines only
34    dnl preprocessor macros and gl_ABSOLUTE_HEADER, gl_CHECK_NEXT_HEADERS do
35    dnl not work in this situation.
36    AC_EGREP_CPP([vaccine],
37      [#if defined _AIX && !defined __GNUC__
38        AIX vaccine
39       #endif
40      ], [gl_aixcc=yes], [gl_aixcc=no])
41    if test $gl_aixcc = yes; then
42      dnl Provide a substitute <stdarg.h> file.
43      STDARG_H=stdarg.h
44      gl_NEXT_HEADERS([stdarg.h])
45      dnl Fallback for the case when <stdarg.h> contains only macro definitions.
46      if test "$gl_cv_next_stdarg_h" = '""'; then
47        gl_cv_next_stdarg_h='"///usr/include/stdarg.h"'
48        NEXT_STDARG_H="$gl_cv_next_stdarg_h"
49      fi
50    else
51      dnl Provide a substitute in <config.h>, either __va_copy or as a simple
52      dnl assignment.
53      gl_CACHE_VAL_SILENT([gl_cv_func___va_copy], [
54        AC_COMPILE_IFELSE(
55          [AC_LANG_PROGRAM(
56             [[#include <stdarg.h>]],
57             [[
58#ifndef __va_copy
59error, bail out
60#endif
61             ]])],
62          [gl_cv_func___va_copy=yes],
63          [gl_cv_func___va_copy=no])])
64      if test $gl_cv_func___va_copy = yes; then
65        AC_DEFINE([va_copy], [__va_copy],
66          [Define as a macro for copying va_list variables.])
67      else
68        AH_VERBATIM([gl_VA_COPY], [/* A replacement for va_copy, if needed.  */
69#define gl_va_copy(a,b) ((a) = (b))])
70        AC_DEFINE([va_copy], [gl_va_copy],
71          [Define as a macro for copying va_list variables.])
72      fi
73    fi
74  fi
75  AC_SUBST([STDARG_H])
76  AM_CONDITIONAL([GL_GENERATE_STDARG_H], [test -n "$STDARG_H"])
77  AC_SUBST([NEXT_STDARG_H])
78])
79