stdbool.m4 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Check for stdbool.h that conforms to C99.
  2. # Copyright (C) 2002-2003 Free Software Foundation, Inc.
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2, or (at your option)
  6. # any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  14. # 02111-1307, USA.
  15. # Prepare for substituting <stdbool.h> if it is not supported.
  16. AC_DEFUN([AM_STDBOOL_H],
  17. [
  18. AC_REQUIRE([AC_HEADER_STDBOOL])
  19. # Define two additional variables used in the Makefile substitution.
  20. if test "$ac_cv_header_stdbool_h" = yes; then
  21. STDBOOL_H=''
  22. else
  23. STDBOOL_H='stdbool.h'
  24. fi
  25. AC_SUBST([STDBOOL_H])
  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. # This macro is only needed in autoconf <= 2.54. Newer versions of autoconf
  34. # have this macro built-in.
  35. AC_DEFUN([AC_HEADER_STDBOOL],
  36. [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
  37. [ac_cv_header_stdbool_h],
  38. [AC_TRY_COMPILE(
  39. [
  40. #include <stdbool.h>
  41. #ifndef bool
  42. "error: bool is not defined"
  43. #endif
  44. #ifndef false
  45. "error: false is not defined"
  46. #endif
  47. #if false
  48. "error: false is not 0"
  49. #endif
  50. #ifndef true
  51. "error: false is not defined"
  52. #endif
  53. #if true != 1
  54. "error: true is not 1"
  55. #endif
  56. #ifndef __bool_true_false_are_defined
  57. "error: __bool_true_false_are_defined is not defined"
  58. #endif
  59. struct s { _Bool s: 1; _Bool t; } s;
  60. char a[true == 1 ? 1 : -1];
  61. char b[false == 0 ? 1 : -1];
  62. char c[__bool_true_false_are_defined == 1 ? 1 : -1];
  63. char d[(bool) -0.5 == true ? 1 : -1];
  64. bool e = &s;
  65. char f[(_Bool) -0.0 == false ? 1 : -1];
  66. char g[true];
  67. char h[sizeof (_Bool)];
  68. char i[sizeof s.t];
  69. ],
  70. [ return !a + !b + !c + !d + !e + !f + !g + !h + !i; ],
  71. [ac_cv_header_stdbool_h=yes],
  72. [ac_cv_header_stdbool_h=no])])
  73. AC_CHECK_TYPES([_Bool])
  74. if test $ac_cv_header_stdbool_h = yes; then
  75. AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
  76. fi])