1dnl Check for support for variadic macros.
2dnl $Id: vamacros.m4 10246 2018-02-16 21:12:42Z iulius $
3dnl
4dnl This file defines two macros for probing for compiler support for variadic
5dnl macros.  Provided are INN_C_C99_VAMACROS, which checks for support for the
6dnl C99 variadic macro syntax, namely:
7dnl
8dnl     #define macro(...) fprintf(stderr, __VA_ARGS__)
9dnl
10dnl and INN_C_GNU_VAMACROS, which checks for support for the older GNU
11dnl variadic macro syntax, namely:
12dnl
13dnl    #define macro(args...) fprintf(stderr, args)
14dnl
15dnl They set HAVE_C99_VAMACROS or HAVE_GNU_VAMACROS as appropriate.
16dnl
17dnl The canonical version of this file is maintained in the rra-c-util
18dnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
19dnl
20dnl Written by Russ Allbery <eagle@eyrie.org>
21dnl Copyright 2006, 2008-2009
22dnl     The Board of Trustees of the Leland Stanford Junior University
23dnl
24dnl This file is free software; the authors give unlimited permission to copy
25dnl and/or distribute it, with or without modifications, as long as this
26dnl notice is preserved.
27dnl
28dnl SPDX-License-Identifier: FSFULLR
29
30AC_DEFUN([_INN_C_C99_VAMACROS_SOURCE], [[
31#include <stdio.h>
32#define error(...) fprintf(stderr, __VA_ARGS__)
33
34int
35main(void) {
36    error("foo");
37    error("foo %d", 0);
38    return 0;
39}
40]])
41
42AC_DEFUN([INN_C_C99_VAMACROS],
43[AC_CACHE_CHECK([for C99 variadic macros], [inn_cv_c_c99_vamacros],
44    [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_INN_C_C99_VAMACROS_SOURCE])],
45        [inn_cv_c_c99_vamacros=yes],
46        [inn_cv_c_c99_vamacros=no])])
47 AS_IF([test x"$inn_cv_c_c99_vamacros" = xyes],
48    [AC_DEFINE([HAVE_C99_VAMACROS], 1,
49        [Define if the compiler supports C99 variadic macros.])])])
50
51AC_DEFUN([_INN_C_GNU_VAMACROS_SOURCE], [[
52#include <stdio.h>
53#define error(args...) fprintf(stderr, args)
54
55int
56main(void) {
57    error("foo");
58    error("foo %d", 0);
59    return 0;
60}
61]])
62
63AC_DEFUN([INN_C_GNU_VAMACROS],
64[AC_CACHE_CHECK([for GNU-style variadic macros], [inn_cv_c_gnu_vamacros],
65    [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_INN_C_GNU_VAMACROS_SOURCE])],
66        [inn_cv_c_gnu_vamacros=yes],
67        [inn_cv_c_gnu_vamacros=no])])
68 AS_IF([test x"$inn_cv_c_gnu_vamacros" = xyes],
69    [AC_DEFINE([HAVE_GNU_VAMACROS], 1,
70        [Define if the compiler supports GNU-style variadic macros.])])])
71