changeset 4151:3a0c83552f0e

Make it possible to #include <stdbool.h> without any #ifdefs.
author Bruno Haible <bruno@clisp.org>
date Thu, 09 Jan 2003 13:35:14 +0000
parents 60149b6a8a43
children 4f192d188eb0
files ChangeLog lib/ChangeLog lib/stdbool.h.in m4/ChangeLog m4/stdbool.m4 modules/stdbool
diffstat 6 files changed, 95 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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 ~.
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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
new file mode 100644
--- /dev/null
+++ b/lib/stdbool.h.in
@@ -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 */
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -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.
--- a/m4/stdbool.m4
+++ b/m4/stdbool.m4
@@ -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
@@ -17,7 +17,30 @@
 # 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],
--- a/modules/stdbool
+++ b/modules/stdbool
@@ -6,24 +6,18 @@
 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>