Make it possible to #include <stdbool.h> without any #ifdefs.
authorBruno Haible <bruno@clisp.org>
Thu, 9 Jan 2003 13:35:14 +0000 (13:35 +0000)
committerBruno Haible <bruno@clisp.org>
Thu, 9 Jan 2003 13:35:14 +0000 (13:35 +0000)
ChangeLog
lib/ChangeLog
lib/stdbool.h.in [new file with mode: 0644]
m4/ChangeLog
m4/stdbool.m4
modules/stdbool

index 700a14858a50616bf19e756257c2e0a59aae68af..f06e766b1a96de2d33275289418bb58f66dc1b91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * modules/stdbool: Change configure.ac, Makefile.am requirements.
+       Simplify Include requirements.
+
 2003-01-09  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool (func_all_modules): Ignore files ending in ~.
index fc0c246343edc489b9db63bd156b65b87a439ab8..710cb16d0b85de911a8a9748e1a3c7455e11adec 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * stdbool.h.in: New file.
+
 2003-01-08  Bruno Haible  <bruno@clisp.org>
 
        * safe-read.c: Include specification header first, to ensure its
diff --git a/lib/stdbool.h.in b/lib/stdbool.h.in
new file mode 100644 (file)
index 0000000..69f6ef7
--- /dev/null
@@ -0,0 +1,47 @@
+/* Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+
+/* ISO C 99 <stdbool.h> for platforms that lack it.  */
+
+/* 7.16. Boolean type and values */
+
+/* BeOS <sys/socket.h> already #defines false 0, true 1.  We use the same
+   definitions below, but temporarily we have to #undef them.  */
+#ifdef __BEOS__
+# undef false
+# undef true
+#endif
+
+/* For the sake of symbolic names in gdb, define _Bool as an enum type.  */
+#ifndef __cplusplus
+# if !@HAVE__BOOL@
+typedef enum { false = 0, true = 1 } _Bool;
+# endif
+#else
+typedef bool _Bool;
+#endif
+#define bool _Bool
+
+/* The other macros must be usable in preprocessor directives.  */
+#define false 0
+#define true 1
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H */
index e1afee3a6bf479203a75d347deaa406f44e080b9..af00c93d8b4d5c9fe24a7cc12582e7897f43bac4 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-09  Bruno Haible  <bruno@clisp.org>
+
+       * stdbool.m4 (AM_STDBOOL_H): New macro.
+
 2002-12-31  Paul Eggert  <eggert@twinsun.com>
 
        * memcoll.m4 (gl_MEMCOLL): Require AC_FUNC_MEMCMP.
index def6e147f8ab06c362a6217e5eae4646022ef4ea..ed000c816376ddb7ab9072eefafdb5894e663cbb 100644 (file)
@@ -1,6 +1,6 @@
 # Check for stdbool.h that conforms to C99.
 
-# Copyright (C) 2002 Free Software Foundation, Inc.
+# Copyright (C) 2002-2003 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 # 02111-1307, USA.
 
-# This file is only needed in autoconf <= 2.54.  Newer versions of autoconf
+# Prepare for substituting <stdbool.h> if it is not supported.
+
+AC_DEFUN([AM_STDBOOL_H],
+[
+  AC_REQUIRE([AC_HEADER_STDBOOL])
+
+  # Define two additional variables used in the Makefile substitution.
+
+  if test "$ac_cv_header_stdbool_h" = yes; then
+    STDBOOL_H=''
+  else
+    STDBOOL_H='stdbool.h'
+  fi
+  AC_SUBST([STDBOOL_H])
+
+  if test "$ac_cv_type__Bool" = yes; then
+    HAVE__BOOL=1
+  else
+    HAVE__BOOL=0
+  fi
+  AC_SUBST([HAVE__BOOL])
+])
+
+# This macro is only needed in autoconf <= 2.54.  Newer versions of autoconf
 # have this macro built-in.
 
 AC_DEFUN([AC_HEADER_STDBOOL],
index 03acba0c868fee538f80b6c5c9d1619de12eb940..bad1377a7f9d62a63e5c2e09252871e82af62f01 100644 (file)
@@ -6,24 +6,18 @@ m4/stdbool.m4
 Depends-on:
 
 configure.ac:
-AC_HEADER_STDBOOL
+AM_STDBOOL_H
 
 Makefile.am:
+EXTRA_DIST += stdbool.h.in
+
+# The following is needed in order to create an <stdbool.h> when the system
+# doesn't have one that works.
+all-local: @STDBOOL_H@
+stdbool.h: stdbool.h.in
+       sed -e 's/@''HAVE__BOOL''@/@HAVE__BOOL@/g' < $(srcdir)/stdbool.h.in > stdbool.h
+MOSTLYCLEANFILES += stdbool.h
 
 Include:
-#if HAVE_STDBOOL_H
-# include <stdbool.h>
-#else
-# if ! HAVE__BOOL
-#  ifdef __cplusplus
-typedef bool _Bool;
-#  else
-typedef enum {false = 0, true = 1} _Bool;
-#  endif
-# endif
-# define bool _Bool
-# define false 0
-# define true 1
-# define __bool_true_false_are_defined 1
-#endif
+#include <stdbool.h>