2 dnl -------------------------------------------------------
3 dnl Copyright (C) Stefan (metze) Metzmacher 2004,2005
4 dnl Released under the GNU GPL
5 dnl -------------------------------------------------------
7 dnl adapted for libreplace by Andrew Tridgell
9 ############################################
10 # Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags
11 # Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action)
12 # changes CFLAGS to add -AC99 or -c99 if needed
14 AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
16 saved_CFLAGS="$CFLAGS";
18 if test x"$c99_init" = x"no"; then
19 AC_MSG_CHECKING(for C99 designated initializers)
20 CFLAGS="$saved_CFLAGS";
21 AC_TRY_COMPILE([#include <stdio.h>],
22 [ struct foo {int x;char y;};
23 struct foo bar = { .y = 'X', .x = 1 };
25 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
27 if test x"$c99_init" = x"no"; then
28 AC_MSG_CHECKING(for C99 designated initializers with -AC99)
29 CFLAGS="$saved_CFLAGS -AC99";
30 AC_TRY_COMPILE([#include <stdio.h>],
31 [ struct foo {int x;char y;};
32 struct foo bar = { .y = 'X', .x = 1 };
34 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
36 if test x"$c99_init" = x"no"; then
37 AC_MSG_CHECKING(for C99 designated initializers with -c99)
38 CFLAGS="$saved_CFLAGS -c99"
39 AC_TRY_COMPILE([#include <stdio.h>],
40 [ struct foo {int x;char y;};
41 struct foo bar = { .y = 'X', .x = 1 };
43 [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
45 if test x"$c99_init" = x"yes"; then
49 CFLAGS="$saved_CFLAGS"