r18144: make the logic a bit more cut&paste friendly
[ab/samba.git/.git] / source4 / lib / replace / cc_features.m4
1 dnl C99 compiler check
2 dnl -------------------------------------------------------
3 dnl  Copyright (C) Stefan (metze) Metzmacher 2004,2005
4 dnl  Released under the GNU GPL
5 dnl -------------------------------------------------------
6 dnl
7 dnl adapted for libreplace by Andrew Tridgell
8
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
13
14 AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
15 [
16 saved_CFLAGS="$CFLAGS";
17 c99_init=no
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 };    
24      ],
25      [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
26 fi
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 };    
33      ],
34      [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
35 fi
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 };    
42      ],
43      [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
44 fi
45 if test x"$c99_init" = x"yes"; then
46     saved_CFLAGS=""
47     $1
48 else
49     CFLAGS="$saved_CFLAGS"
50     saved_CFLAGS=""
51     $2
52 fi
53 ])