public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf
@ 2023-10-15  9:32 Mike Frysinger
  2023-10-17  5:40 ` Sebastian Huber
  2023-10-25 23:14 ` Jeff Johnston
  0 siblings, 2 replies; 3+ messages in thread
From: Mike Frysinger @ 2023-10-15  9:32 UTC (permalink / raw)
  To: newlib

We've been manually editing newlib.hin after generating it with
autoheader to drop the version defines that we keep in the separate
_newlib_version.h header.  This is confusing for people, and is an
easy source of mistakes/errors.

Since we're already running sed on newlib.h during configure to
filter out defines we don't want to expose, add the version macros
there too.  This way we don't have to manually edit newlib.hin.

This simplifies the autoreconf step in exchange for a slightly more
complicated configure+sed step, but seems worth the trade-off.
---
 newlib/configure    |  2 +-
 newlib/configure.ac |  5 ++++-
 newlib/newlib.hin   | 12 ++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/newlib/configure b/newlib/configure
index 0585e0ee8b33..b21d9bf45810 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -9269,7 +9269,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
 
 
   case $ac_file$ac_mode in
-    "newlib.h":H) sed -i.tmp -e '/^#define [^_]/d' -e '/^\/\* #undef [^_]/d' newlib.h && rm -f newlib.h.tmp ;;
+    "newlib.h":H) sed -i.tmp -E -e '/^#define [^_]/d' -e '/^\/\* #undef [^_]/d' -e '/_NEWLIB_VERSION|__NEWLIB_(MINOR|PATCHLEVEL)__|__NEWLIB__/d' newlib.h && rm -f newlib.h.tmp ;;
     "default-1":C)
 # Only add multilib support code if we just rebuilt the top-level
 # Makefile.
diff --git a/newlib/configure.ac b/newlib/configure.ac
index 94242c082d20..55e5a944689f 100644
--- a/newlib/configure.ac
+++ b/newlib/configure.ac
@@ -8,8 +8,11 @@ dnl Since we can't control what defines autoheader picks up (various autoconf
 dnl macros will add their own), filter out all the ones w/out a _ prefix.  All
 dnl the ones we want to export use a _ prefix, and all the rest we don't want
 dnl to export as it'll pollute the namespace of newlib users.
+dnl We also filter out version defines that we want in _newlib_version.h.
 dnl NB: newlib.h must be the first AC_CONFIG_HEADERS call for autoheader.
-AC_CONFIG_HEADERS([newlib.h:newlib.hin], [sed -i.tmp -e '/^#define [^_]/d' -e '/^\/\* #undef [^_]/d' newlib.h && rm -f newlib.h.tmp])
+AC_CONFIG_HEADERS(
+  [newlib.h:newlib.hin],
+  [sed -i.tmp -E -e '/^#define [^_]/d' -e '/^\/\* #undef [^_]/d' -e '/_NEWLIB_VERSION|__NEWLIB_(MINOR|PATCHLEVEL)__|__NEWLIB__/d' newlib.h && rm -f newlib.h.tmp])
 AH_TOP([/* NB: The contents are filtered before being installed. */
 
 #ifndef __NEWLIB_H__
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index e87a5eabbb24..8318469400b0 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -375,6 +375,9 @@
 /* nano version of malloc is used. */
 #undef _NANO_MALLOC
 
+/* The newlib version in string format. */
+#undef _NEWLIB_VERSION
+
 /* Verify _REENT_CHECK macros allocate memory successfully. */
 #undef _REENT_CHECK_VERIFY
 
@@ -422,4 +425,13 @@
 /* Define if wide char orientation is supported. */
 #undef _WIDE_ORIENT
 
+/* The newlib minor version number. */
+#undef __NEWLIB_MINOR__
+
+/* The newlib patch level. */
+#undef __NEWLIB_PATCHLEVEL__
+
+/* The newlib major version number. */
+#undef __NEWLIB__
+
 #endif /* !__NEWLIB_H__ */
-- 
2.42.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf
  2023-10-15  9:32 [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf Mike Frysinger
@ 2023-10-17  5:40 ` Sebastian Huber
  2023-10-25 23:14 ` Jeff Johnston
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Huber @ 2023-10-17  5:40 UTC (permalink / raw)
  To: Mike Frysinger, newlib

On 15.10.23 11:32, Mike Frysinger wrote:
> We've been manually editing newlib.hin after generating it with 
> autoheader to drop the version defines that we keep in the separate 
> _newlib_version.h header. This is confusing for people, and is an easy 
> source of mistakes/errors. Since we're already running sed on newlib.h 
> during configure to filter out defines we don't want to expose, add the 
> version macros there too. This way we don't have to manually edit 
> newlib.hin. This simplifies the autoreconf step in exchange for a 
> slightly more complicated configure+sed step, but seems worth the trade-off.

Thanks, this is a nice improvement for occasional contributors like me.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf
  2023-10-15  9:32 [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf Mike Frysinger
  2023-10-17  5:40 ` Sebastian Huber
@ 2023-10-25 23:14 ` Jeff Johnston
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Johnston @ 2023-10-25 23:14 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 3489 bytes --]

Works well.  Feel free to push.

-- Jeff J.

On Sun, Oct 15, 2023 at 5:32 AM Mike Frysinger <vapier@gentoo.org> wrote:

> We've been manually editing newlib.hin after generating it with
> autoheader to drop the version defines that we keep in the separate
> _newlib_version.h header.  This is confusing for people, and is an
> easy source of mistakes/errors.
>
> Since we're already running sed on newlib.h during configure to
> filter out defines we don't want to expose, add the version macros
> there too.  This way we don't have to manually edit newlib.hin.
>
> This simplifies the autoreconf step in exchange for a slightly more
> complicated configure+sed step, but seems worth the trade-off.
> ---
>  newlib/configure    |  2 +-
>  newlib/configure.ac |  5 ++++-
>  newlib/newlib.hin   | 12 ++++++++++++
>  3 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/newlib/configure b/newlib/configure
> index 0585e0ee8b33..b21d9bf45810 100755
> --- a/newlib/configure
> +++ b/newlib/configure
> @@ -9269,7 +9269,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
>
>
>    case $ac_file$ac_mode in
> -    "newlib.h":H) sed -i.tmp -e '/^#define [^_]/d' -e '/^\/\* #undef
> [^_]/d' newlib.h && rm -f newlib.h.tmp ;;
> +    "newlib.h":H) sed -i.tmp -E -e '/^#define [^_]/d' -e '/^\/\* #undef
> [^_]/d' -e '/_NEWLIB_VERSION|__NEWLIB_(MINOR|PATCHLEVEL)__|__NEWLIB__/d'
> newlib.h && rm -f newlib.h.tmp ;;
>      "default-1":C)
>  # Only add multilib support code if we just rebuilt the top-level
>  # Makefile.
> diff --git a/newlib/configure.ac b/newlib/configure.ac
> index 94242c082d20..55e5a944689f 100644
> --- a/newlib/configure.ac
> +++ b/newlib/configure.ac
> @@ -8,8 +8,11 @@ dnl Since we can't control what defines autoheader picks
> up (various autoconf
>  dnl macros will add their own), filter out all the ones w/out a _
> prefix.  All
>  dnl the ones we want to export use a _ prefix, and all the rest we don't
> want
>  dnl to export as it'll pollute the namespace of newlib users.
> +dnl We also filter out version defines that we want in _newlib_version.h.
>  dnl NB: newlib.h must be the first AC_CONFIG_HEADERS call for autoheader.
> -AC_CONFIG_HEADERS([newlib.h:newlib.hin], [sed -i.tmp -e '/^#define
> [^_]/d' -e '/^\/\* #undef [^_]/d' newlib.h && rm -f newlib.h.tmp])
> +AC_CONFIG_HEADERS(
> +  [newlib.h:newlib.hin],
> +  [sed -i.tmp -E -e '/^#define [^_]/d' -e '/^\/\* #undef [^_]/d' -e
> '/_NEWLIB_VERSION|__NEWLIB_(MINOR|PATCHLEVEL)__|__NEWLIB__/d' newlib.h &&
> rm -f newlib.h.tmp])
>  AH_TOP([/* NB: The contents are filtered before being installed. */
>
>  #ifndef __NEWLIB_H__
> diff --git a/newlib/newlib.hin b/newlib/newlib.hin
> index e87a5eabbb24..8318469400b0 100644
> --- a/newlib/newlib.hin
> +++ b/newlib/newlib.hin
> @@ -375,6 +375,9 @@
>  /* nano version of malloc is used. */
>  #undef _NANO_MALLOC
>
> +/* The newlib version in string format. */
> +#undef _NEWLIB_VERSION
> +
>  /* Verify _REENT_CHECK macros allocate memory successfully. */
>  #undef _REENT_CHECK_VERIFY
>
> @@ -422,4 +425,13 @@
>  /* Define if wide char orientation is supported. */
>  #undef _WIDE_ORIENT
>
> +/* The newlib minor version number. */
> +#undef __NEWLIB_MINOR__
> +
> +/* The newlib patch level. */
> +#undef __NEWLIB_PATCHLEVEL__
> +
> +/* The newlib major version number. */
> +#undef __NEWLIB__
> +
>  #endif /* !__NEWLIB_H__ */
> --
> 2.42.0
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-25 23:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-15  9:32 [PATCH] newlib: filter out versions from newlib.h to simplify autoreconf Mike Frysinger
2023-10-17  5:40 ` Sebastian Huber
2023-10-25 23:14 ` Jeff Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).