Home | History | Annotate | Download | only in m4
      1 # Check for stdbool.h that conforms to C99.
      2 
      3 dnl Copyright (C) 2002-2006, 2009-2012 Free Software Foundation, Inc.
      4 dnl This file is free software; the Free Software Foundation
      5 dnl gives unlimited permission to copy and/or distribute it,
      6 dnl with or without modifications, as long as this notice is preserved.
      7 
      8 #serial 5
      9 
     10 # Prepare for substituting <stdbool.h> if it is not supported.
     11 
     12 AC_DEFUN([AM_STDBOOL_H],
     13 [
     14   AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
     15 
     16   # Define two additional variables used in the Makefile substitution.
     17 
     18   if test "$ac_cv_header_stdbool_h" = yes; then
     19     STDBOOL_H=''
     20   else
     21     STDBOOL_H='stdbool.h'
     22   fi
     23   AC_SUBST([STDBOOL_H])
     24   AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
     25 
     26   if test "$ac_cv_type__Bool" = yes; then
     27     HAVE__BOOL=1
     28   else
     29     HAVE__BOOL=0
     30   fi
     31   AC_SUBST([HAVE__BOOL])
     32 ])
     33 
     34 # AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
     35 AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
     36 
     37 # This version of the macro is needed in autoconf <= 2.68.
     38 
     39 AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
     40   [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
     41      [ac_cv_header_stdbool_h],
     42      [AC_COMPILE_IFELSE(
     43         [AC_LANG_PROGRAM(
     44            [[
     45              #include <stdbool.h>
     46              #ifndef bool
     47               "error: bool is not defined"
     48              #endif
     49              #ifndef false
     50               "error: false is not defined"
     51              #endif
     52              #if false
     53               "error: false is not 0"
     54              #endif
     55              #ifndef true
     56               "error: true is not defined"
     57              #endif
     58              #if true != 1
     59               "error: true is not 1"
     60              #endif
     61              #ifndef __bool_true_false_are_defined
     62               "error: __bool_true_false_are_defined is not defined"
     63              #endif
     64 
     65              struct s { _Bool s: 1; _Bool t; } s;
     66 
     67              char a[true == 1 ? 1 : -1];
     68              char b[false == 0 ? 1 : -1];
     69              char c[__bool_true_false_are_defined == 1 ? 1 : -1];
     70              char d[(bool) 0.5 == true ? 1 : -1];
     71              /* See body of main program for 'e'.  */
     72              char f[(_Bool) 0.0 == false ? 1 : -1];
     73              char g[true];
     74              char h[sizeof (_Bool)];
     75              char i[sizeof s.t];
     76              enum { j = false, k = true, l = false * true, m = true * 256 };
     77              /* The following fails for
     78                 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
     79              _Bool n[m];
     80              char o[sizeof n == m * sizeof n[0] ? 1 : -1];
     81              char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
     82              /* Catch a bug in an HP-UX C compiler.  See
     83                 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
     84                 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
     85               */
     86              _Bool q = true;
     87              _Bool *pq = &q;
     88            ]],
     89            [[
     90              bool e = &s;
     91              *pq |= q;
     92              *pq |= ! q;
     93              /* Refer to every declared value, to avoid compiler optimizations.  */
     94              return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
     95                      + !m + !n + !o + !p + !q + !pq);
     96            ]])],
     97         [ac_cv_header_stdbool_h=yes],
     98         [ac_cv_header_stdbool_h=no])])
     99    AC_CHECK_TYPES([_Bool])
    100 ])
    101