2N/A# Check for stdbool.h that conforms to C99.
2N/A
2N/Adnl Copyright (C) 2002-2006, 2009-2010 Free Software Foundation, Inc.
2N/Adnl This file is free software; the Free Software Foundation
2N/Adnl gives unlimited permission to copy and/or distribute it,
2N/Adnl with or without modifications, as long as this notice is preserved.
2N/A
2N/A#serial 3
2N/A
2N/A# Prepare for substituting <stdbool.h> if it is not supported.
2N/A
2N/AAC_DEFUN([AM_STDBOOL_H],
2N/A[
2N/A AC_REQUIRE([AC_HEADER_STDBOOL])
2N/A
2N/A # Define two additional variables used in the Makefile substitution.
2N/A
2N/A if test "$ac_cv_header_stdbool_h" = yes; then
2N/A STDBOOL_H=''
2N/A else
2N/A STDBOOL_H='stdbool.h'
2N/A fi
2N/A AC_SUBST([STDBOOL_H])
2N/A
2N/A if test "$ac_cv_type__Bool" = yes; then
2N/A HAVE__BOOL=1
2N/A else
2N/A HAVE__BOOL=0
2N/A fi
2N/A AC_SUBST([HAVE__BOOL])
2N/A])
2N/A
2N/A# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
2N/AAC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
2N/A
2N/A# This version of the macro is needed in autoconf <= 2.67. Autoconf has
2N/A# it built in since 2.60, but we want the tweaks from the 2.68 version
2N/A# to avoid rejecting xlc and clang due to relying on extensions.
2N/A
2N/AAC_DEFUN([AC_HEADER_STDBOOL],
2N/A [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
2N/A [ac_cv_header_stdbool_h],
2N/A [AC_COMPILE_IFELSE(
2N/A [AC_LANG_PROGRAM(
2N/A [[
2N/A #include <stdbool.h>
2N/A #ifndef bool
2N/A "error: bool is not defined"
2N/A #endif
2N/A #ifndef false
2N/A "error: false is not defined"
2N/A #endif
2N/A #if false
2N/A "error: false is not 0"
2N/A #endif
2N/A #ifndef true
2N/A "error: true is not defined"
2N/A #endif
2N/A #if true != 1
2N/A "error: true is not 1"
2N/A #endif
2N/A #ifndef __bool_true_false_are_defined
2N/A "error: __bool_true_false_are_defined is not defined"
2N/A #endif
2N/A
2N/A struct s { _Bool s: 1; _Bool t; } s;
2N/A
2N/A char a[true == 1 ? 1 : -1];
2N/A char b[false == 0 ? 1 : -1];
2N/A char c[__bool_true_false_are_defined == 1 ? 1 : -1];
2N/A char d[(bool) 0.5 == true ? 1 : -1];
2N/A /* See body of main program for 'e'. */
2N/A char f[(_Bool) 0.0 == false ? 1 : -1];
2N/A char g[true];
2N/A char h[sizeof (_Bool)];
2N/A char i[sizeof s.t];
2N/A enum { j = false, k = true, l = false * true, m = true * 256 };
2N/A /* The following fails for
2N/A HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
2N/A _Bool n[m];
2N/A char o[sizeof n == m * sizeof n[0] ? 1 : -1];
2N/A char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
2N/A /* Catch a bug in an HP-UX C compiler. See
2N/A http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
2N/A http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
2N/A */
2N/A _Bool q = true;
2N/A _Bool *pq = &q;
2N/A ]],
2N/A [[
2N/A bool e = &s;
2N/A *pq |= q;
2N/A *pq |= ! q;
2N/A /* Refer to every declared value, to avoid compiler optimizations. */
2N/A return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
2N/A + !m + !n + !o + !p + !q + !pq);
2N/A ]])],
2N/A [ac_cv_header_stdbool_h=yes],
2N/A [ac_cv_header_stdbool_h=no])])
2N/A AC_CHECK_TYPES([_Bool])
2N/A if test $ac_cv_header_stdbool_h = yes; then
2N/A AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to C99.])
2N/A fi])