This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Automated the generation of the __NEWLIB__, __NEWLIB_MINOR__ and __NEWLIB_PATCHLEVEL__ macros.
- From: Pieter du Preez <pdupreez at gmail dot com>
- To: newlib at sourceware dot org
- Date: Sun, 14 Feb 2016 11:35:17 +0100
- Subject: Re: [PATCH] Automated the generation of the __NEWLIB__, __NEWLIB_MINOR__ and __NEWLIB_PATCHLEVEL__ macros.
- Authentication-results: sourceware.org; auth=none
- References: <20160125201938 dot GA19917 at bling> <20160128103806 dot GD10851 at calimero dot vinschen dot de> <2044933968 dot 16515818 dot 1453987626889 dot JavaMail dot zimbra at redhat dot com> <20160129142013 dot GA28886 at bling> <1805653431 dot 17249188 dot 1454080285047 dot JavaMail dot zimbra at redhat dot com> <1430949434 dot 69566 dot 1454255799762 dot JavaMail dot zimbra at embedded-brains dot de> <20160131205738 dot GB14801 at bling> <524249855 dot 18807677 dot 1454456445016 dot JavaMail dot zimbra at redhat dot com>
On Tue, Feb 02, 2016 at 06:40:45PM -0500, Jeff Johnston wrote:
> Yes, but we should probably call it _newlib_version.h.
Will the attached patch be acceptable?
--
Pieter du Preez
>From 403c47e170ced149434e08b193479c8ffdd34602 Mon Sep 17 00:00:00 2001
From: Pieter du Preez <pdupreez@gmail.com>
Date: Sun, 14 Feb 2016 11:12:06 +0100
Subject: [PATCH] Define the newlib version macros in one place:
_newlib_version.h.
Currently, the newlib version information needs to be updated in two places:
- newlib/acinclude.m4
- newlib/libc/include/sys/features.h
The goal of this patch is to:
- supply a single location for defining the newlib version
information: newlib/acinclude.m4
- define __NEWLIB__, __NEWLIB_MINOR__ and __NEWLIB_PATCHLEVEL__
This is in line with what gcc does for its version macros. See:
https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
This patch moves the definition of the _NEWLIB_VERSION, __NEWLIB__
and __NEWLIB_MINOR__ macros from newlib/libc/include/sys/features.h,
to the newly generated newlib/_newlib_version.h file. Additionally,
the __NEWLIB_PATCHLEVEL__ macro was created, for completeness.
In order to stay backwards compatible, newlib/_newlib_version.h gets
included by newlib/newlib.h and newlib/libc/include/sys/features.h.
Note: This patch does _not_ include the modifications to the following
files, as these should all be generated any way.
*Makefile.in,
*aclocal.m4,
*configure
stamp-* files
Signed-off-by: Pieter du Preez <pdupreez@gmail.com>
---
newlib/Makefile.am | 23 +++++++++++++++++++----
newlib/_newlib_version.hin | 11 +++++++++++
newlib/acinclude.m4 | 6 ++++--
newlib/configure.in | 7 +++++--
newlib/libc/include/sys/features.h | 6 +-----
newlib/newlib.hin | 2 +-
6 files changed, 41 insertions(+), 14 deletions(-)
create mode 100644 newlib/_newlib_version.hin
diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 5ecce4c..9b30cd3 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -191,7 +191,19 @@ crt1.o: $(CRT1_DIR)$(CRT1)
$(CRT1_DIR)$(CRT1): ; @true
-$(srcdir)/newlib.hin:
+targ-include:
+ mkdir $@
+
+targ-include/newlib.h: targ-include/_newlib_version.h
+
+targ-include/sys targ-include/machine targ-include/bits: targ-include/_newlib_version.h targ-include/newlib.h
+ mkdir $@
+
+targ-include/newlib.h: newlib.h targ-include
+ cp newlib.h $@
+
+targ-include/_newlib_version.h: _newlib_version.h targ-include
+ cp _newlib_version.h $@
all-recursive: stmp-targ-include
@@ -200,8 +212,10 @@ all-recursive: stmp-targ-include
# used while building.
stmp-targ-include: config.status
-rm -rf targ-include stmp-targ-include
- mkdir targ-include targ-include/sys targ-include/machine targ-include/bits
- cp newlib.h targ-include/newlib.h
+ $(MAKE) targ-include/sys \
+ targ-include/machine \
+ targ-include/bits \
+ targ-include/newlib.h
-for i in $(srcdir)/libc/machine/$(machine_dir)/machine/*.h; do \
if [ -f $$i ]; then \
cp $$i targ-include/machine/`basename $$i`; \
@@ -274,6 +288,7 @@ endif
$(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
done; \
$(INSTALL_DATA) newlib.h $(DESTDIR)$(tooldir)/include/newlib.h; \
+ $(INSTALL_DATA) _newlib_version.h $(DESTDIR)$(tooldir)/include/_newlib_version.h; \
$(mkinstalldirs) $(DESTDIR)$(tooldir)/include/machine; \
for i in $(srcdir)/libc/include/machine/*.h; do \
$(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/machine/`basename $$i`; \
@@ -441,4 +456,4 @@ check-DEJAGNU: site.exp
fi
clean-local:
- -rm -rf targ-include
+ -rm -rf targ-include newlib.h _newlib_version.h stamp-*
diff --git a/newlib/_newlib_version.hin b/newlib/_newlib_version.hin
new file mode 100644
index 0000000..03d4e3d
--- /dev/null
+++ b/newlib/_newlib_version.hin
@@ -0,0 +1,11 @@
+/* Version macros for internal and downstream use. */
+#ifndef _NEWLIB_VERSION_H__
+#define _NEWLIB_VERSION_H__ 1
+
+#undef _NEWLIB_VERSION
+#undef __NEWLIB__
+#undef __NEWLIB_MINOR__
+#undef __NEWLIB_PATCHLEVEL__
+
+#endif /* !_NEWLIB_VERSION_H__ */
+
diff --git a/newlib/acinclude.m4 b/newlib/acinclude.m4
index 9fefa32..a35264e 100644
--- a/newlib/acinclude.m4
+++ b/newlib/acinclude.m4
@@ -1,8 +1,10 @@
dnl This provides configure definitions used by all the newlib
dnl configure.in files.
-AC_DEFUN([DEF_NEWLIB_VERSION],
-m4_define([NEWLIB_VERSION],[2.3.0]))
+AC_DEFUN([DEF_NEWLIB_MAJOR_VERSION],m4_define([NEWLIB_MAJOR_VERSION],[2]))
+AC_DEFUN([DEF_NEWLIB_MINOR_VERSION],m4_define([NEWLIB_MINOR_VERSION],[3]))
+AC_DEFUN([DEF_NEWLIB_PATCHLEVEL_VERSION],m4_define([NEWLIB_PATCHLEVEL_VERSION],[0]))
+AC_DEFUN([DEF_NEWLIB_VERSION],m4_define([NEWLIB_VERSION],[NEWLIB_MAJOR_VERSION.NEWLIB_MINOR_VERSION.NEWLIB_PATCHLEVEL_VERSION]))
dnl Basic newlib configury. This calls basic introductory stuff,
dnl including AM_INIT_AUTOMAKE and AC_CANONICAL_HOST. It also runs
diff --git a/newlib/configure.in b/newlib/configure.in
index 9465787..01c6367 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -4,7 +4,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT([newlib],[NEWLIB_VERSION])
AC_CONFIG_SRCDIR([libc])
-AC_CONFIG_HEADER(newlib.h:newlib.hin)
+AC_CONFIG_HEADERS([_newlib_version.h:_newlib_version.hin newlib.h:newlib.hin])
dnl Can't be done in NEWLIB_CONFIGURE because that confuses automake.
AC_CONFIG_AUX_DIR(..)
@@ -384,7 +384,10 @@ if test "${newlib_iconv_external_ccs}" = "yes"; then
AC_DEFINE_UNQUOTED(_ICONV_ENABLE_EXTERNAL_CCS)
fi
-AC_DEFINE_UNQUOTED(_NEWLIB_VERSION,"NEWLIB_VERSION")
+AC_DEFINE(_NEWLIB_VERSION,"NEWLIB_VERSION","The newlib version in string format.")
+AC_DEFINE(__NEWLIB__,NEWLIB_MAJOR_VERSION,"The newlib major version number.")
+AC_DEFINE(__NEWLIB_MINOR__,NEWLIB_MINOR_VERSION,"The newlib minor version number.")
+AC_DEFINE(__NEWLIB_PATCHLEVEL__,NEWLIB_PATCHLEVEL_VERSION,"The newlib patch level.")
if test "${multilib}" = "yes"; then
multilib_arg="--enable-multilib"
diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
index 4ad7fbd..9743aec 100644
--- a/newlib/libc/include/sys/features.h
+++ b/newlib/libc/include/sys/features.h
@@ -25,11 +25,7 @@
extern "C" {
#endif
-/* Macros to determine that newlib is being used. Put in this header to
- * be similar to where glibc stores its version of these macros.
- */
-#define __NEWLIB__ 2
-#define __NEWLIB_MINOR__ 2
+#include <_newlib_version.h>
/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
#ifndef __GNUC_PREREQ
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index eadafc8..d03dfac 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -10,7 +10,7 @@
#undef _ELIX_LEVEL
/* Newlib version */
-#undef _NEWLIB_VERSION
+#include <_newlib_version.h>
/* C99 formats support (such as %a, %zu, ...) in IO functions like
* printf/scanf enabled */
--
2.7.0