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 700a148..f06e766 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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 ~.
        * MODULES.html.sh: Likewise.
 
index fc0c246..710cb16 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 e1afee3..af00c93 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 def6e14..ed000c8 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 03acba0..bad1377 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>