| 1 | #
|
|---|
| 2 | # This is a collection of useful autoconf macros
|
|---|
| 3 | #
|
|---|
| 4 |
|
|---|
| 5 | ############################################
|
|---|
| 6 | # Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags
|
|---|
| 7 | # Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action)
|
|---|
| 8 | # changes CFLAGS to add -AC99 or -c99 if needed
|
|---|
| 9 | AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT],
|
|---|
| 10 | [
|
|---|
| 11 | saved_CFLAGS="$CFLAGS";
|
|---|
| 12 | c99_init=no
|
|---|
| 13 | if test x"$c99_init" = x"no"; then
|
|---|
| 14 | AC_MSG_CHECKING(for C99 designated initializers)
|
|---|
| 15 | CFLAGS="$saved_CFLAGS";
|
|---|
| 16 | AC_TRY_COMPILE([#include <stdio.h>],
|
|---|
| 17 | [ struct foo {int x;char y;};
|
|---|
| 18 | struct foo bar = { .y = 'X', .x = 1 };
|
|---|
| 19 | ],
|
|---|
| 20 | [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
|---|
| 21 | fi
|
|---|
| 22 | if test x"$c99_init" = x"no"; then
|
|---|
| 23 | AC_MSG_CHECKING(for C99 designated initializers with -AC99)
|
|---|
| 24 | CFLAGS="$saved_CFLAGS -AC99";
|
|---|
| 25 | AC_TRY_COMPILE([#include <stdio.h>],
|
|---|
| 26 | [ struct foo {int x;char y;};
|
|---|
| 27 | struct foo bar = { .y = 'X', .x = 1 };
|
|---|
| 28 | ],
|
|---|
| 29 | [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
|---|
| 30 | fi
|
|---|
| 31 | if test x"$c99_init" = x"no"; then
|
|---|
| 32 | AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=extc99)
|
|---|
| 33 | CFLAGS="$saved_CFLAGS -qlanglvl=extc99";
|
|---|
| 34 | AC_TRY_COMPILE([#include <stdio.h>],
|
|---|
| 35 | [ struct foo {int x;char y;};
|
|---|
| 36 | struct foo bar = { .y = 'X', .x = 1 };
|
|---|
| 37 | ],
|
|---|
| 38 | [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
|---|
| 39 | fi
|
|---|
| 40 | if test x"$c99_init" = x"no"; then
|
|---|
| 41 | AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=stdc99)
|
|---|
| 42 | CFLAGS="$saved_CFLAGS -qlanglvl=stdc99";
|
|---|
| 43 | AC_TRY_COMPILE([#include <stdio.h>],
|
|---|
| 44 | [ struct foo {int x;char y;};
|
|---|
| 45 | struct foo bar = { .y = 'X', .x = 1 };
|
|---|
| 46 | ],
|
|---|
| 47 | [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
|---|
| 48 | fi
|
|---|
| 49 | if test x"$c99_init" = x"no"; then
|
|---|
| 50 | AC_MSG_CHECKING(for C99 designated initializers with -c99)
|
|---|
| 51 | CFLAGS="$saved_CFLAGS -c99"
|
|---|
| 52 | AC_TRY_COMPILE([#include <stdio.h>],
|
|---|
| 53 | [ struct foo {int x;char y;};
|
|---|
| 54 | struct foo bar = { .y = 'X', .x = 1 };
|
|---|
| 55 | ],
|
|---|
| 56 | [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)])
|
|---|
|
|---|