newlib: switch newlib.h to autoheader

Now that newlib.hin has been brought up to date and all of its defines
are produced by configure, we can switch it to using autoheader without
manual editing.  This relies on a few pieces:
* Moving the header & footer into configure.ac via AH_TOP & AH_BOTTOM.
* Running a post-process step on newlib.h to delete all the defines we
  didn't export ourselves.  Basically, anything without a _ prefix.

This will leave behind some spurious comments in newlib.h related to
the defines we filtered out, but should be harmless, so it's probably
not worth the effort to construct a more complicated sed expression to
also strip those out.
This commit is contained in:
Mike Frysinger 2022-01-17 20:10:38 -05:00
parent b86dc2dab4
commit 0a67325726
4 changed files with 100 additions and 22 deletions

View File

@ -112,7 +112,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno config.status.lineno
mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
CONFIG_HEADER = _newlib_version.h newlib.h
CONFIG_HEADER = newlib.h _newlib_version.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
@ -234,7 +234,7 @@ am__recursive_targets = \
AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
cscope
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
$(LISP)_newlib_version.hin newlib.hin
$(LISP)newlib.hin _newlib_version.hin
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
@ -548,7 +548,7 @@ MAKEOVERRIDES =
# dejagnu support
RUNTESTFLAGS =
@HAVE_DOC_TRUE@MKDOC = doc/makedoc$(EXEEXT_FOR_BUILD)
all: _newlib_version.h newlib.h
all: newlib.h _newlib_version.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
.SUFFIXES:
@ -588,28 +588,28 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
$(am__aclocal_m4_deps):
_newlib_version.h: stamp-h1
newlib.h: stamp-h1
@test -f $@ || rm -f stamp-h1
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1
stamp-h1: $(srcdir)/_newlib_version.hin $(top_builddir)/config.status
stamp-h1: $(srcdir)/newlib.hin $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status _newlib_version.h
$(srcdir)/_newlib_version.hin: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(SHELL) ./config.status newlib.h
$(srcdir)/newlib.hin: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
($(am__cd) $(top_srcdir) && $(AUTOHEADER))
rm -f stamp-h1
touch $@
newlib.h: stamp-h2
_newlib_version.h: stamp-h2
@test -f $@ || rm -f stamp-h2
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h2
stamp-h2: $(srcdir)/newlib.hin $(top_builddir)/config.status
stamp-h2: $(srcdir)/_newlib_version.hin $(top_builddir)/config.status
@rm -f stamp-h2
cd $(top_builddir) && $(SHELL) ./config.status newlib.h
cd $(top_builddir) && $(SHELL) ./config.status _newlib_version.h
distclean-hdr:
-rm -f _newlib_version.h stamp-h1 newlib.h stamp-h2
-rm -f newlib.h stamp-h1 _newlib_version.h stamp-h2
install-toollibLIBRARIES: $(toollib_LIBRARIES)
@$(NORMAL_INSTALL)
@list='$(toollib_LIBRARIES)'; test -n "$(toollibdir)" || list=; \
@ -852,8 +852,8 @@ distclean-DEJAGNU:
check-am: all-am
$(MAKE) $(AM_MAKEFLAGS) check-DEJAGNU
check: check-recursive
all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) $(DATA) _newlib_version.h \
newlib.h
all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) $(DATA) newlib.h \
_newlib_version.h
installdirs: installdirs-recursive
installdirs-am:
for dir in "$(DESTDIR)$(toollibdir)" "$(DESTDIR)$(toollibdir)" "$(DESTDIR)$(toollibdir)"; do \

15
newlib/configure vendored
View File

@ -2251,7 +2251,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
ac_config_headers="$ac_config_headers _newlib_version.h:_newlib_version.hin newlib.h:newlib.hin"
ac_config_headers="$ac_config_headers newlib.h:newlib.hin"
ac_config_headers="$ac_config_headers _newlib_version.h:_newlib_version.hin"
ac_aux_dir=
@ -11974,7 +11980,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11977 "configure"
#line 11983 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -12080,7 +12086,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 12083 "configure"
#line 12089 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -14451,8 +14457,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
for ac_config_target in $ac_config_targets
do
case $ac_config_target in
"_newlib_version.h") CONFIG_HEADERS="$CONFIG_HEADERS _newlib_version.h:_newlib_version.hin" ;;
"newlib.h") CONFIG_HEADERS="$CONFIG_HEADERS newlib.h:newlib.hin" ;;
"_newlib_version.h") CONFIG_HEADERS="$CONFIG_HEADERS _newlib_version.h:_newlib_version.hin" ;;
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
"libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
@ -15051,6 +15057,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 ;;
"depfiles":C) test x"$AMDEP_TRUE" != x"" || {
# Older Autoconf quotes --file arguments for eval, but not when files
# are listed without --file. Let's play safe and only enable the eval

View File

@ -3,7 +3,23 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT([newlib],[NEWLIB_VERSION])
AC_CONFIG_SRCDIR([libc])
AC_CONFIG_HEADERS([_newlib_version.h:_newlib_version.hin newlib.h:newlib.hin])
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 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])
AH_TOP([/* NB: The contents are filtered before being installed. */
#ifndef __NEWLIB_H__
#define __NEWLIB_H__ 1
/* Newlib version */
#include <_newlib_version.h>])
AH_BOTTOM([#endif /* !__NEWLIB_H__ */])
AC_CONFIG_HEADERS([_newlib_version.h:_newlib_version.hin])
dnl Can't be done in NEWLIB_CONFIGURE because that confuses automake.
AC_CONFIG_AUX_DIR(..)

View File

@ -1,13 +1,68 @@
/* newlib.hin. Manually edited from the output of autoheader to
remove all PACKAGE_ macros which will collide with any user
package using newlib header files and having its own package name,
version, etc... */
/* newlib.hin. Generated from configure.ac by autoheader. */
/* NB: The contents are filtered before being installed. */
#ifndef __NEWLIB_H__
#define __NEWLIB_H__ 1
/* Newlib version */
#include <_newlib_version.h>
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* If atexit() may dynamically allocate space for cleanup functions. */
#undef _ATEXIT_DYNAMIC_ALLOC