public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] newlib: libm: merge build up a directory
@ 2022-02-12 20:34 Mike Frysinger
  2022-02-16  8:50 ` [HEADSUP] " Corinna Vinschen
  2022-02-17  4:42 ` [PATCH v2] " Mike Frysinger
  0 siblings, 2 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-12 20:34 UTC (permalink / raw)
  To: newlib

Convert all the libm/ subdir makes into the top-level Makefile.  This
allows us to build all of libm from the top Makefile without using any
recursive make calls.  This is faster and avoids the funky lib.a logic
where we unpack subdir archives to repack into a single libm.a.  The
machine override logic is maintained though by way of Makefile include
ordering, and source file accumulation in libm_a_SOURCES.

One thing to note is that this will require GNU Make because of:
	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
This was the only way I could find to supporting per-dir compiler
settings, and I couldn't find a POSIX compatible way of transforming
the variable content.  I don't think this is a big deal as other
Makefiles in the tree are using GNU Make-specific syntax, but I call
this out as it's the only one so far in the new automake code that
I've been writing.

Automake doesn't provide precise control over the output object names
(by design).  This is fine by default as we get consistent names in all
the subdirs: libm_a-<source>.o.  But this relies on using the same set
of compiler flags for all objects.  We currently compile libm/common/
with different optimizations than the rest.

If we want to compile objects differently, we can create an intermediate
archive with the subset of objects with unique flags, and then add those
objects to the main archive.  But Automake will use a different prefix
for the objects, and thus we can't rely on ordering to override.

But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
since $@ contains /, Automake complains it's an invalid name.  While
GNU Make supports this, it's a POSIX extension, so Automake flags it.
Using $(subst) avoids the Automake warning to get a POSIX compliant
name, albeit with a GNU Make extension.
---
 newlib/Makefile.am                       |   39 +-
 newlib/Makefile.in                       | 7738 +++++++++++++++++++++-
 newlib/configure                         |  202 +-
 newlib/libm/Makefile.am                  |   28 -
 newlib/libm/Makefile.in                  |  594 --
 newlib/libm/Makefile.inc                 |   39 +
 newlib/libm/acinclude.m4                 |   31 +-
 newlib/libm/common/Makefile.am           |   51 -
 newlib/libm/common/Makefile.in           | 1553 -----
 newlib/libm/common/Makefile.inc          |   79 +
 newlib/libm/complex/Makefile.am          |   29 -
 newlib/libm/complex/Makefile.in          | 1007 ---
 newlib/libm/complex/Makefile.inc         |   23 +
 newlib/libm/fenv/Makefile.am             |   15 -
 newlib/libm/fenv/Makefile.in             |  610 --
 newlib/libm/fenv/Makefile.inc            |    7 +
 newlib/libm/machine/aarch64/Makefile.am  |   52 -
 newlib/libm/machine/aarch64/Makefile.in  |  842 ---
 newlib/libm/machine/aarch64/Makefile.inc |   45 +
 newlib/libm/machine/arm/Makefile.am      |   42 -
 newlib/libm/machine/arm/Makefile.in      |  760 ---
 newlib/libm/machine/arm/Makefile.inc     |   34 +
 newlib/libm/machine/i386/Makefile.am     |   21 -
 newlib/libm/machine/i386/Makefile.in     |  789 ---
 newlib/libm/machine/i386/Makefile.inc    |   12 +
 newlib/libm/machine/mips/Makefile.am     |   23 -
 newlib/libm/machine/mips/Makefile.in     |  612 --
 newlib/libm/machine/mips/Makefile.inc    |   17 +
 newlib/libm/machine/nds32/Makefile.am    |   18 -
 newlib/libm/machine/nds32/Makefile.in    |  533 --
 newlib/libm/machine/nds32/Makefile.inc   |   10 +
 newlib/libm/machine/powerpc/Makefile.am  |   13 -
 newlib/libm/machine/powerpc/Makefile.in  |  608 --
 newlib/libm/machine/powerpc/Makefile.inc |    6 +
 newlib/libm/machine/pru/Makefile.am      |   12 -
 newlib/libm/machine/pru/Makefile.in      |  594 --
 newlib/libm/machine/pru/Makefile.inc     |    5 +
 newlib/libm/machine/riscv/Makefile.am    |   25 -
 newlib/libm/machine/riscv/Makefile.in    |  803 ---
 newlib/libm/machine/riscv/Makefile.inc   |   18 +
 newlib/libm/machine/sparc/Makefile.am    |   14 -
 newlib/libm/machine/sparc/Makefile.in    |  609 --
 newlib/libm/machine/sparc/Makefile.inc   |    7 +
 newlib/libm/machine/spu/Makefile.am      |   32 -
 newlib/libm/machine/spu/Makefile.in      | 1362 ----
 newlib/libm/machine/spu/Makefile.inc     |   25 +
 newlib/libm/machine/x86_64/Makefile.am   |   13 -
 newlib/libm/machine/x86_64/Makefile.in   |  608 --
 newlib/libm/machine/x86_64/Makefile.inc  |    6 +
 newlib/libm/math/Makefile.am             |   60 -
 newlib/libm/math/Makefile.in             | 1453 ----
 newlib/libm/math/Makefile.inc            |   53 +
 newlib/libm/mathfp/Makefile.am           |   50 -
 newlib/libm/mathfp/Makefile.in           | 1172 ----
 newlib/libm/mathfp/Makefile.inc          |   43 +
 55 files changed, 8078 insertions(+), 15368 deletions(-)
 delete mode 100644 newlib/libm/Makefile.am
 delete mode 100644 newlib/libm/Makefile.in
 delete mode 100644 newlib/libm/common/Makefile.am
 delete mode 100644 newlib/libm/common/Makefile.in
 delete mode 100644 newlib/libm/complex/Makefile.am
 delete mode 100644 newlib/libm/complex/Makefile.in
 delete mode 100644 newlib/libm/fenv/Makefile.am
 delete mode 100644 newlib/libm/fenv/Makefile.in
 delete mode 100644 newlib/libm/machine/aarch64/Makefile.am
 delete mode 100644 newlib/libm/machine/aarch64/Makefile.in
 create mode 100644 newlib/libm/machine/aarch64/Makefile.inc
 delete mode 100644 newlib/libm/machine/arm/Makefile.am
 delete mode 100644 newlib/libm/machine/arm/Makefile.in
 create mode 100644 newlib/libm/machine/arm/Makefile.inc
 delete mode 100644 newlib/libm/machine/i386/Makefile.am
 delete mode 100644 newlib/libm/machine/i386/Makefile.in
 create mode 100644 newlib/libm/machine/i386/Makefile.inc
 delete mode 100644 newlib/libm/machine/mips/Makefile.am
 delete mode 100644 newlib/libm/machine/mips/Makefile.in
 create mode 100644 newlib/libm/machine/mips/Makefile.inc
 delete mode 100644 newlib/libm/machine/nds32/Makefile.am
 delete mode 100644 newlib/libm/machine/nds32/Makefile.in
 create mode 100644 newlib/libm/machine/nds32/Makefile.inc
 delete mode 100644 newlib/libm/machine/powerpc/Makefile.am
 delete mode 100644 newlib/libm/machine/powerpc/Makefile.in
 create mode 100644 newlib/libm/machine/powerpc/Makefile.inc
 delete mode 100644 newlib/libm/machine/pru/Makefile.am
 delete mode 100644 newlib/libm/machine/pru/Makefile.in
 create mode 100644 newlib/libm/machine/pru/Makefile.inc
 delete mode 100644 newlib/libm/machine/riscv/Makefile.am
 delete mode 100644 newlib/libm/machine/riscv/Makefile.in
 create mode 100644 newlib/libm/machine/riscv/Makefile.inc
 delete mode 100644 newlib/libm/machine/sparc/Makefile.am
 delete mode 100644 newlib/libm/machine/sparc/Makefile.in
 create mode 100644 newlib/libm/machine/sparc/Makefile.inc
 delete mode 100644 newlib/libm/machine/spu/Makefile.am
 delete mode 100644 newlib/libm/machine/spu/Makefile.in
 create mode 100644 newlib/libm/machine/spu/Makefile.inc
 delete mode 100644 newlib/libm/machine/x86_64/Makefile.am
 delete mode 100644 newlib/libm/machine/x86_64/Makefile.in
 create mode 100644 newlib/libm/machine/x86_64/Makefile.inc
 delete mode 100644 newlib/libm/math/Makefile.am
 delete mode 100644 newlib/libm/math/Makefile.in
 delete mode 100644 newlib/libm/mathfp/Makefile.am
 delete mode 100644 newlib/libm/mathfp/Makefile.in

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 5767f8524fd0..df9e033cae5e 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -59,7 +59,7 @@ AM_MAKEFLAGS = \
 
 FLAGS_TO_PASS=$(AM_MAKEFLAGS)
 
-SUBDIRS = libc libm .
+SUBDIRS = libc .
 
 tooldir = $(exec_prefix)/$(host_alias)
 toollibdir = $(tooldir)/lib$(MULTISUBDIR)
@@ -84,19 +84,19 @@ toollib_DATA = $(CRT0) $(CRT1)
 # both libc.a and libm.a.  We build them in libm.a and copy them over,
 # along with some required supporting routines.
 MATHOBJS_IN_LIBC = \
-	$(lpfx)s_fpclassify.o $(lpfx)sf_fpclassify.o \
-	$(lpfx)s_isinf.o $(lpfx)sf_isinf.o \
-	$(lpfx)s_isnan.o $(lpfx)sf_isnan.o \
-	$(lpfx)s_isinfd.o $(lpfx)sf_isinff.o \
-	$(lpfx)s_isnand.o $(lpfx)sf_isnanf.o \
-	$(lpfx)s_nan.o $(lpfx)sf_nan.o \
-	$(lpfx)s_ldexp.o $(lpfx)sf_ldexp.o \
-	$(lpfx)s_frexp.o $(lpfx)sf_frexp.o $(lpfx)frexpl.o \
-	$(lpfx)s_modf.o \
-	$(lpfx)sf_modf.o $(lpfx)s_scalbn.o \
-	$(lpfx)sf_scalbn.o \
-	$(lpfx)s_finite.o $(lpfx)sf_finite.o \
-	$(lpfx)s_copysign.o $(lpfx)sf_copysign.o
+	libm_a-s_fpclassify.o libm_a-sf_fpclassify.o \
+	libm_a-s_isinf.o libm_a-sf_isinf.o \
+	libm_a-s_isnan.o libm_a-sf_isnan.o \
+	libm_a-s_isinfd.o libm_a-sf_isinff.o \
+	libm_a-s_isnand.o libm_a-sf_isnanf.o \
+	libm_a-s_nan.o libm_a-sf_nan.o \
+	libm_a-s_ldexp.o libm_a-sf_ldexp.o \
+	libm_a-s_frexp.o libm_a-sf_frexp.o libm_a-frexpl.o \
+	libm_a-s_modf.o \
+	libm_a-sf_modf.o libm_a-s_scalbn.o \
+	libm_a-sf_scalbn.o \
+	libm_a-s_finite.o libm_a-sf_finite.o \
+	libm_a-s_copysign.o libm_a-sf_copysign.o
 
 libc.a: libc/libc.a libm.a
 	rm -rf libc.a libg.a tmp
@@ -111,11 +111,12 @@ libc.a: libc/libc.a libm.a
 
 libc/libc.a: ; @true
 
-libm.a: libm/libm.a
-	rm -f $@
-	ln $< $@ >/dev/null 2>/dev/null || cp $< $@
-
-libm/libm.a: ; @true
+libm_a_SOURCES =
+libm_a_CFLAGS = $(AM_CFLAGS) $(libm_a_CFLAGS_$(subst /,_,$(@D)))
+libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D)))
+libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D)))
+libm_a_LIBADD =
+libm_a_DEPENDENCIES =
 
 if HAVE_MULTISUBDIR
 $(BUILD_MULTISUBDIR):
diff --git a/newlib/libm/Makefile.am b/newlib/libm/Makefile.am
deleted file mode 100644
index 0ab26cda852c..000000000000
--- a/newlib/libm/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-if NEWLIB_HW_FP
-MATHDIR = mathfp
-else
-MATHDIR = math
-endif
-
-SUBDIRS = $(MATHDIR) common complex fenv
-if HAVE_LIBM_MACHINE_DIR
-SUBDIRS += $(LIBM_MACHINE_DIR)
-endif
-
-SUBLIBS = $(MATHDIR)/lib.a common/lib.a complex/lib.a fenv/lib.a $(LIBM_MACHINE_LIB)
-noinst_LIBRARIES = libm.a
-libm.a: $(SUBLIBS)
-	rm -f $@
-	rm -rf tmp
-	mkdir tmp
-	cd tmp; \
-	  for i in $(SUBLIBS); do \
-	    $(AR) x ../$$i; \
-	done; \
-	$(AR) $(AR_FLAGS) ../$@ *.o
-	$(RANLIB) $@
-	rm -rf tmp
-
-$(SUBLIBS):
diff --git a/newlib/libm/Makefile.inc b/newlib/libm/Makefile.inc
index 7fdea0ca518e..829a9ed5708a 100644
--- a/newlib/libm/Makefile.inc
+++ b/newlib/libm/Makefile.inc
@@ -34,6 +34,11 @@ man: %C%_man
 	$(INSTALL_DATA) %D%/*.3 $(DESTDIR)$(mandir)/man3/
 install-man: %C%_install-man
 
+## NB: Ordering of subdirs here is important.  The machine dirs in particular
+## must be last so that their objects are last in the list of source files.
+## This allows them to override common files when adding to libm.a via $AR.
+## We don't currently use this pattern for other files, but conceivably could.
+
 include %D%/common/Makefile.inc
 include %D%/complex/Makefile.inc
 include %D%/fenv/Makefile.inc
@@ -43,6 +48,40 @@ else
 include %D%/math/Makefile.inc
 endif
 
+if HAVE_LIBM_MACHINE_AARCH64
+include %D%/machine/aarch64/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_ARM
+include %D%/machine/arm/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_I386
+include %D%/machine/i386/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_MIPS
+include %D%/machine/mips/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_NDS32
+include %D%/machine/nds32/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_POWERPC
+include %D%/machine/powerpc/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_PRU
+include %D%/machine/pru/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_SPARC
+include %D%/machine/sparc/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_SPU
+include %D%/machine/spu/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_RISCV
+include %D%/machine/riscv/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_X86_64
+include %D%/machine/x86_64/Makefile.inc
+endif
+
 CLEANFILES += \
 	%D%/targetdep.tex \
 	%D%/targetdep.tex.stamp \
diff --git a/newlib/libm/acinclude.m4 b/newlib/libm/acinclude.m4
index 6b59715fce70..0be95a3b29dd 100644
--- a/newlib/libm/acinclude.m4
+++ b/newlib/libm/acinclude.m4
@@ -2,28 +2,9 @@ dnl We have to include these unconditionally since machines might want to use
 dnl AM_CONDITIONAL in their subdirs.
 m4_include([libm/machine/nds32/acinclude.m4])
 
-LIBM_MACHINE_LIB=
-if test -n "${libm_machine_dir}"; then
-  case ${libm_machine_dir} in
-    aarch64) AC_CONFIG_FILES([libm/machine/aarch64/Makefile]) ;;
-    arm) AC_CONFIG_FILES([libm/machine/arm/Makefile]) ;;
-    i386) AC_CONFIG_FILES([libm/machine/i386/Makefile]) ;;
-    nds32) AC_CONFIG_FILES([libm/machine/nds32/Makefile]) ;;
-    pru) AC_CONFIG_FILES([libm/machine/pru/Makefile]) ;;
-    spu) AC_CONFIG_FILES([libm/machine/spu/Makefile]) ;;
-    riscv) AC_CONFIG_FILES([libm/machine/riscv/Makefile]) ;;
-    x86_64) AC_CONFIG_FILES([libm/machine/x86_64/Makefile]) ;;
-    powerpc) AC_CONFIG_FILES([libm/machine/powerpc/Makefile]) ;;
-    sparc) AC_CONFIG_FILES([libm/machine/sparc/Makefile]) ;;
-    mips) AC_CONFIG_FILES([libm/machine/mips/Makefile]) ;;
-    *) AC_MSG_ERROR([unsupported libm_machine_dir "${libm_machine_dir}"]) ;;
-  esac
-
-  LIBM_MACHINE_DIR=machine/${libm_machine_dir}
-  LIBM_MACHINE_LIB=${LIBM_MACHINE_DIR}/lib.a
-fi
-AM_CONDITIONAL(HAVE_LIBM_MACHINE_DIR, test "x${LIBM_MACHINE_DIR}" != x)
-AC_SUBST(LIBM_MACHINE_DIR)
-AC_SUBST(LIBM_MACHINE_LIB)
-
-AC_CONFIG_FILES([libm/Makefile libm/math/Makefile libm/mathfp/Makefile libm/common/Makefile libm/complex/Makefile libm/fenv/Makefile])
+dnl Define HAVE_LIBM_MACHINE_<machine> automake conditionals.
+m4_foreach_w([MACHINE], [
+  aarch64 arm i386 mips nds32 powerpc pru sparc spu riscv x86_64
+], [dnl
+  AM_CONDITIONAL([HAVE_LIBM_MACHINE_]m4_toupper(MACHINE), test "${libm_machine_dir}" = "MACHINE")
+])
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
deleted file mode 100644
index 5000406fe350..000000000000
--- a/newlib/libm/common/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src = 	s_finite.c s_copysign.c s_modf.c s_scalbn.c \
-	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
-	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
-	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
-	s_rint.c s_logb.c s_log2.c \
-	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
-	s_lrint.c s_llrint.c \
-	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
-	s_signbit.c s_trunc.c \
-	exp.c exp2.c exp_data.c math_err.c log.c log_data.c log2.c log2_data.c \
-	pow.c pow_log_data.c
-
-fsrc =	sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
-	sf_cbrt.c sf_exp10.c sf_expm1.c sf_ilogb.c \
-	sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
-	sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
-	sf_rint.c sf_logb.c \
-	sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c \
-	sf_lrint.c sf_llrint.c \
-	sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
-	sf_scalbln.c sf_trunc.c \
-	sf_exp.c sf_exp2.c sf_exp2_data.c sf_log.c sf_log_data.c \
-	sf_log2.c sf_log2_data.c sf_pow_log2_data.c sf_pow.c \
-	sinf.c cosf.c sincosf.c sincosf_data.c math_errf.c
-
-lsrc =	atanl.c cosl.c sinl.c tanl.c tanhl.c frexpl.c modfl.c ceill.c fabsl.c \
-	floorl.c log1pl.c expm1l.c acosl.c asinl.c atan2l.c coshl.c sinhl.c \
-	expl.c ldexpl.c logl.c log10l.c powl.c sqrtl.c fmodl.c hypotl.c \
-	copysignl.c nanl.c ilogbl.c asinhl.c cbrtl.c nextafterl.c rintl.c \
-	scalbnl.c exp2l.c scalblnl.c tgammal.c nearbyintl.c lrintl.c llrintl.c \
-	roundl.c lroundl.c llroundl.c truncl.c remquol.c fdiml.c fmaxl.c fminl.c \
-	fmal.c acoshl.c atanhl.c remainderl.c lgammal.c erfl.c erfcl.c \
-	logbl.c nexttowardf.c nexttoward.c nexttowardl.c log2l.c \
-	sl_finite.c
-
-lib_a_CFLAGS = -fbuiltin -fno-math-errno
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc)
-if HAVE_LONG_DOUBLE
-lib_a_SOURCES += $(lsrc)
-endif # HAVE_LONG_DOUBLE
-lib_a_CFLAGS += $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h fdlibm.h
diff --git a/newlib/libm/common/Makefile.inc b/newlib/libm/common/Makefile.inc
index b0d3013c522b..8b54acab6f4a 100644
--- a/newlib/libm/common/Makefile.inc
+++ b/newlib/libm/common/Makefile.inc
@@ -1,3 +1,82 @@
+%C%_src = \
+	%D%/s_finite.c \
+	%D%/s_copysign.c \
+	%D%/s_modf.c \
+	%D%/s_scalbn.c \
+	%D%/s_cbrt.c \
+	%D%/s_exp10.c \
+	%D%/s_expm1.c \
+	%D%/s_ilogb.c \
+	%D%/s_infinity.c \
+	%D%/s_isinf.c \
+	%D%/s_isinfd.c \
+	%D%/s_isnan.c \
+	%D%/s_isnand.c \
+	%D%/s_log1p.c \
+	%D%/s_nan.c \
+	%D%/s_nextafter.c \
+	%D%/s_pow10.c \
+	%D%/s_rint.c \
+	%D%/s_logb.c \
+	%D%/s_log2.c \
+	%D%/s_fdim.c \
+	%D%/s_fma.c \
+	%D%/s_fmax.c \
+	%D%/s_fmin.c \
+	%D%/s_fpclassify.c \
+	%D%/s_lrint.c \
+	%D%/s_llrint.c \
+	%D%/s_lround.c \
+	%D%/s_llround.c \
+	%D%/s_nearbyint.c \
+	%D%/s_remquo.c \
+	%D%/s_round.c \
+	%D%/s_scalbln.c \
+	%D%/s_signbit.c \
+	%D%/s_trunc.c \
+	%D%/exp.c \
+	%D%/exp2.c \
+	%D%/exp_data.c \
+	%D%/math_err.c \
+	%D%/log.c \
+	%D%/log_data.c \
+	%D%/log2.c \
+	%D%/log2_data.c \
+	%D%/pow.c \
+	%D%/pow_log_data.c
+
+%C%_fsrc = \
+	%D%/sf_finite.c %D%/sf_copysign.c %D%/sf_modf.c %D%/sf_scalbn.c \
+	%D%/sf_cbrt.c %D%/sf_exp10.c %D%/sf_expm1.c %D%/sf_ilogb.c \
+	%D%/sf_infinity.c %D%/sf_isinf.c %D%/sf_isinff.c %D%/sf_isnan.c %D%/sf_isnanf.c \
+	%D%/sf_log1p.c %D%/sf_nan.c %D%/sf_nextafter.c %D%/sf_pow10.c \
+	%D%/sf_rint.c %D%/sf_logb.c \
+	%D%/sf_fdim.c %D%/sf_fma.c %D%/sf_fmax.c %D%/sf_fmin.c %D%/sf_fpclassify.c \
+	%D%/sf_lrint.c %D%/sf_llrint.c \
+	%D%/sf_lround.c %D%/sf_llround.c %D%/sf_nearbyint.c %D%/sf_remquo.c %D%/sf_round.c \
+	%D%/sf_scalbln.c %D%/sf_trunc.c \
+	%D%/sf_exp.c %D%/sf_exp2.c %D%/sf_exp2_data.c %D%/sf_log.c %D%/sf_log_data.c \
+	%D%/sf_log2.c %D%/sf_log2_data.c %D%/sf_pow_log2_data.c %D%/sf_pow.c \
+	%D%/sinf.c %D%/cosf.c %D%/sincosf.c %D%/sincosf_data.c %D%/math_errf.c
+
+%C%_lsrc = \
+	%D%/atanl.c %D%/cosl.c %D%/sinl.c %D%/tanl.c %D%/tanhl.c %D%/frexpl.c %D%/modfl.c %D%/ceill.c %D%/fabsl.c \
+	%D%/floorl.c %D%/log1pl.c %D%/expm1l.c %D%/acosl.c %D%/asinl.c %D%/atan2l.c %D%/coshl.c %D%/sinhl.c \
+	%D%/expl.c %D%/ldexpl.c %D%/logl.c %D%/log10l.c %D%/powl.c %D%/sqrtl.c %D%/fmodl.c %D%/hypotl.c \
+	%D%/copysignl.c %D%/nanl.c %D%/ilogbl.c %D%/asinhl.c %D%/cbrtl.c %D%/nextafterl.c %D%/rintl.c \
+	%D%/scalbnl.c %D%/exp2l.c %D%/scalblnl.c %D%/tgammal.c %D%/nearbyintl.c %D%/lrintl.c %D%/llrintl.c \
+	%D%/roundl.c %D%/lroundl.c %D%/llroundl.c %D%/truncl.c %D%/remquol.c %D%/fdiml.c %D%/fmaxl.c %D%/fminl.c \
+	%D%/fmal.c %D%/acoshl.c %D%/atanhl.c %D%/remainderl.c %D%/lgammal.c %D%/erfl.c %D%/erfcl.c \
+	%D%/logbl.c %D%/nexttowardf.c %D%/nexttoward.c %D%/nexttowardl.c %D%/log2l.c \
+	%D%/sl_finite.c
+
+libm_a_CFLAGS_%C% = -fbuiltin -fno-math-errno
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc)
+if HAVE_LONG_DOUBLE
+libm_a_SOURCES += $(%C%_lsrc)
+endif # HAVE_LONG_DOUBLE
+
 LIBM_CHEWOUT_FILES += \
 	%D%/s_cbrt.def %D%/s_copysign.def %D%/s_exp10.def %D%/s_expm1.def %D%/s_ilogb.def \
 	%D%/s_infinity.def %D%/s_isnan.def %D%/s_log1p.def %D%/s_modf.def \
diff --git a/newlib/libm/complex/Makefile.am b/newlib/libm/complex/Makefile.am
deleted file mode 100644
index a92990e3edbd..000000000000
--- a/newlib/libm/complex/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common -I$(srcdir)/ $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src = cabs.c cacos.c cacosh.c carg.c casin.c casinh.c \
-      catan.c catanh.c ccos.c ccosh.c cephes_subr.c \
-      cexp.c cimag.c  clog.c clog10.c conj.c  \
-      cpow.c cproj.c  creal.c  \
-      csin.c csinh.c csqrt.c ctan.c ctanh.c
-
-lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c \
-       clogl.c csqrtl.c cargl.c cprojl.c cexpl.c \
-       cephes_subrl.c cacosl.c ccosl.c casinl.c \
-       catanhl.c conjl.c cpowl.c ctanhl.c ctanl.c \
-       casinhl.c csinhl.c csinl.c catanl.c
-
-fsrc =	cabsf.c casinf.c ccosf.c cimagf.c cprojf.c  \
-        csqrtf.c cacosf.c casinhf.c ccoshf.c clogf.c clog10f.c \
-        crealf.c ctanf.c cacoshf.c catanf.c   \
-        cephes_subrf.c conjf.c csinf.c ctanhf.c \
-        cargf.c catanhf.c cexpf.c cpowf.c csinhf.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc) $(lsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/complex.h $(srcdir)/cephes_subr.h $(srcdir)/cephes_subrf.h  $(srcdir)/cephes_subrl.h
diff --git a/newlib/libm/complex/Makefile.inc b/newlib/libm/complex/Makefile.inc
index 94288082ea32..88a460910d36 100644
--- a/newlib/libm/complex/Makefile.inc
+++ b/newlib/libm/complex/Makefile.inc
@@ -1,3 +1,26 @@
+%C%_src = \
+	%D%/cabs.c %D%/cacos.c %D%/cacosh.c %D%/carg.c %D%/casin.c %D%/casinh.c \
+	%D%/catan.c %D%/catanh.c %D%/ccos.c %D%/ccosh.c %D%/cephes_subr.c \
+	%D%/cexp.c %D%/cimag.c %D%/clog.c %D%/clog10.c %D%/conj.c \
+	%D%/cpow.c %D%/cproj.c %D%/creal.c \
+	%D%/csin.c %D%/csinh.c %D%/csqrt.c %D%/ctan.c %D%/ctanh.c
+
+%C%_lsrc = \
+	%D%/cabsl.c %D%/creall.c %D%/cimagl.c %D%/ccoshl.c %D%/cacoshl.c \
+	%D%/clogl.c %D%/csqrtl.c %D%/cargl.c %D%/cprojl.c %D%/cexpl.c \
+	%D%/cephes_subrl.c %D%/cacosl.c %D%/ccosl.c %D%/casinl.c \
+	%D%/catanhl.c %D%/conjl.c %D%/cpowl.c %D%/ctanhl.c %D%/ctanl.c \
+	%D%/casinhl.c %D%/csinhl.c %D%/csinl.c %D%/catanl.c
+
+%C%_fsrc = \
+	%D%/cabsf.c %D%/casinf.c %D%/ccosf.c %D%/cimagf.c %D%/cprojf.c \
+	%D%/csqrtf.c %D%/cacosf.c %D%/casinhf.c %D%/ccoshf.c %D%/clogf.c %D%/clog10f.c \
+	%D%/crealf.c %D%/ctanf.c %D%/cacoshf.c %D%/catanf.c \
+	%D%/cephes_subrf.c %D%/conjf.c %D%/csinf.c %D%/ctanhf.c \
+	%D%/cargf.c %D%/catanhf.c %D%/cexpf.c %D%/cpowf.c %D%/csinhf.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc) $(%C%_lsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/cabs.def %D%/cacos.def %D%/cacosh.def %D%/carg.def \
 	%D%/casin.def %D%/casinh.def %D%/catan.def %D%/catanh.def \
diff --git a/newlib/libm/fenv/Makefile.am b/newlib/libm/fenv/Makefile.am
deleted file mode 100644
index 58cda3806822..000000000000
--- a/newlib/libm/fenv/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src =	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/fenv.h
diff --git a/newlib/libm/fenv/Makefile.inc b/newlib/libm/fenv/Makefile.inc
index 0399638ad603..a9585d9bbac6 100644
--- a/newlib/libm/fenv/Makefile.inc
+++ b/newlib/libm/fenv/Makefile.inc
@@ -1,3 +1,10 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/feclearexcept.def %D%/fegetenv.def \
 	%D%/fegetexceptflag.def %D%/fegetround.def %D%/feholdexcept.def \
diff --git a/newlib/libm/machine/aarch64/Makefile.am b/newlib/libm/machine/aarch64/Makefile.am
deleted file mode 100644
index 6310f72b680d..000000000000
--- a/newlib/libm/machine/aarch64/Makefile.am
+++ /dev/null
@@ -1,52 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	e_sqrt.c \
-	ef_sqrt.c \
-	s_ceil.c \
-	s_fabs.c \
-	s_floor.c \
-	s_fma.c \
-	s_fmax.c \
-	s_fmin.c \
-	s_llrint.c \
-	s_llround.c \
-	s_lrint.c \
-	s_lround.c \
-	s_nearbyint.c \
-	s_rint.c \
-	s_round.c \
-	s_trunc.c \
-	sf_ceil.c \
-	sf_fabs.c \
-	sf_floor.c \
-	sf_fma.c \
-	sf_fmax.c \
-	sf_fmin.c \
-	sf_llrint.c \
-	sf_llround.c \
-	sf_lrint.c \
-	sf_lround.c \
-	sf_nearbyint.c \
-	sf_rint.c \
-	sf_round.c \
-	sf_trunc.c \
-	fenv.c \
-	feclearexcept.c \
-	fegetenv.c \
-	fegetexceptflag.c \
-	fegetround.c \
-	feholdexcept.c \
-	feraiseexcept.c \
-	fesetenv.c \
-	fesetexceptflag.c \
-	fesetround.c \
-	fetestexcept.c \
-	feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/aarch64/Makefile.inc b/newlib/libm/machine/aarch64/Makefile.inc
new file mode 100644
index 000000000000..478aaeed8b05
--- /dev/null
+++ b/newlib/libm/machine/aarch64/Makefile.inc
@@ -0,0 +1,45 @@
+%C%_src = \
+	%D%/e_sqrt.c \
+	%D%/ef_sqrt.c \
+	%D%/s_ceil.c \
+	%D%/s_fabs.c \
+	%D%/s_floor.c \
+	%D%/s_fma.c \
+	%D%/s_fmax.c \
+	%D%/s_fmin.c \
+	%D%/s_llrint.c \
+	%D%/s_llround.c \
+	%D%/s_lrint.c \
+	%D%/s_lround.c \
+	%D%/s_nearbyint.c \
+	%D%/s_rint.c \
+	%D%/s_round.c \
+	%D%/s_trunc.c \
+	%D%/sf_ceil.c \
+	%D%/sf_fabs.c \
+	%D%/sf_floor.c \
+	%D%/sf_fma.c \
+	%D%/sf_fmax.c \
+	%D%/sf_fmin.c \
+	%D%/sf_llrint.c \
+	%D%/sf_llround.c \
+	%D%/sf_lrint.c \
+	%D%/sf_lround.c \
+	%D%/sf_nearbyint.c \
+	%D%/sf_rint.c \
+	%D%/sf_round.c \
+	%D%/sf_trunc.c \
+	%D%/fenv.c \
+	%D%/feclearexcept.c \
+	%D%/fegetenv.c \
+	%D%/fegetexceptflag.c \
+	%D%/fegetround.c \
+	%D%/feholdexcept.c \
+	%D%/feraiseexcept.c \
+	%D%/fesetenv.c \
+	%D%/fesetexceptflag.c \
+	%D%/fesetround.c \
+	%D%/fetestexcept.c \
+	%D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/arm/Makefile.am b/newlib/libm/machine/arm/Makefile.am
deleted file mode 100644
index f8a542bb3599..000000000000
--- a/newlib/libm/machine/arm/Makefile.am
+++ /dev/null
@@ -1,42 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	e_sqrt.c \
-	ef_sqrt.c \
-	s_ceil.c \
-	s_floor.c \
-	s_fma_arm.c \
-	s_nearbyint.c \
-	s_rint.c \
-	s_round.c \
-	s_trunc.c \
-	sf_ceil.c \
-	sf_floor.c \
-	sf_fma_arm.c \
-	sf_nearbyint.c \
-	sf_rint.c \
-	sf_round.c \
-	sf_trunc.c \
-	feclearexcept.c \
-	fe_dfl_env.c\
-	fegetenv.c \
-	fegetexceptflag.c \
-	fegetround.c \
-	feholdexcept.c \
-	fegetexcept.c \
-	feraiseexcept.c \
-	fesetenv.c \
-	fesetexceptflag.c \
-	fesetround.c \
-	fetestexcept.c \
-	feupdateenv.c \
-	feenableexcept.c \
-	fedisableexcept.c
-
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/arm/Makefile.inc b/newlib/libm/machine/arm/Makefile.inc
new file mode 100644
index 000000000000..988e2340006c
--- /dev/null
+++ b/newlib/libm/machine/arm/Makefile.inc
@@ -0,0 +1,34 @@
+%C%_src = \
+	%D%/e_sqrt.c \
+	%D%/ef_sqrt.c \
+	%D%/s_ceil.c \
+	%D%/s_floor.c \
+	%D%/s_fma_arm.c \
+	%D%/s_nearbyint.c \
+	%D%/s_rint.c \
+	%D%/s_round.c \
+	%D%/s_trunc.c \
+	%D%/sf_ceil.c \
+	%D%/sf_floor.c \
+	%D%/sf_fma_arm.c \
+	%D%/sf_nearbyint.c \
+	%D%/sf_rint.c \
+	%D%/sf_round.c \
+	%D%/sf_trunc.c \
+	%D%/feclearexcept.c \
+	%D%/fe_dfl_env.c\
+	%D%/fegetenv.c \
+	%D%/fegetexceptflag.c \
+	%D%/fegetround.c \
+	%D%/feholdexcept.c \
+	%D%/fegetexcept.c \
+	%D%/feraiseexcept.c \
+	%D%/fesetenv.c \
+	%D%/fesetexceptflag.c \
+	%D%/fesetround.c \
+	%D%/fetestexcept.c \
+	%D%/feupdateenv.c \
+	%D%/feenableexcept.c \
+	%D%/fedisableexcept.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/i386/Makefile.am b/newlib/libm/machine/i386/Makefile.am
deleted file mode 100644
index d5caa4577d2a..000000000000
--- a/newlib/libm/machine/i386/Makefile.am
+++ /dev/null
@@ -1,21 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-AM_CCASFLAGS = $(AM_CPPFLAGS)
-
-LIB_SOURCES = \
-	f_atan2.S f_atan2f.S f_exp.c f_expf.c \
-	f_frexp.S f_frexpf.S f_llrint.c f_llrintf.c f_llrintl.c \
-	f_log.S f_logf.S f_log10.S f_log10f.S \
-	f_ldexp.S f_ldexpf.S f_lrint.c f_lrintf.c f_lrintl.c \
-	f_pow.c f_powf.c f_rint.c f_rintf.c f_rintl.c \
-	f_tan.S f_tanf.S f_math.h i386mach.h \
-	fenv.c feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
-lib_a_CCASFLAGS = $(AM_CCASFLAGS)
diff --git a/newlib/libm/machine/i386/Makefile.inc b/newlib/libm/machine/i386/Makefile.inc
new file mode 100644
index 000000000000..420d25fbd4df
--- /dev/null
+++ b/newlib/libm/machine/i386/Makefile.inc
@@ -0,0 +1,12 @@
+%C%_src = \
+	%D%/f_atan2.S %D%/f_atan2f.S %D%/f_exp.c %D%/f_expf.c \
+	%D%/f_frexp.S %D%/f_frexpf.S %D%/f_llrint.c %D%/f_llrintf.c %D%/f_llrintl.c \
+	%D%/f_log.S %D%/f_logf.S %D%/f_log10.S %D%/f_log10f.S \
+	%D%/f_ldexp.S %D%/f_ldexpf.S %D%/f_lrint.c %D%/f_lrintf.c %D%/f_lrintl.c \
+	%D%/f_pow.c %D%/f_powf.c %D%/f_rint.c %D%/f_rintf.c %D%/f_rintl.c \
+	%D%/f_tan.S %D%/f_tanf.S %D%/f_math.h %D%/i386mach.h \
+	%D%/fenv.c %D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/mips/Makefile.am b/newlib/libm/machine/mips/Makefile.am
deleted file mode 100644
index 07c2f424e5d0..000000000000
--- a/newlib/libm/machine/mips/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-LIBADD_OBJS = \
-	lib_a-fenv.$(OBJEXT)
-
-# fenv.c cannot be compiled as mips16 since it uses the cfc1 instruction
-lib_a-fenv.o: fenv.c
-	$(COMPILE) -mno-mips16 -c -o $@ `test -f 'fenv.c' || echo '$(srcdir)/'`fenv.c
-
-lib_a-fenv.obj: fenv.c
-	$(COMPILE) -mno-mips16 -c -o $@ `if test -f 'fenv.c'; then $(CYGPATH_W) 'fenv.c'; else $(CYGPATH_W) '$(srcdir)/fenv.c'; fi`
diff --git a/newlib/libm/machine/mips/Makefile.inc b/newlib/libm/machine/mips/Makefile.inc
new file mode 100644
index 000000000000..d64aecd4d693
--- /dev/null
+++ b/newlib/libm/machine/mips/Makefile.inc
@@ -0,0 +1,17 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
+
+## This is dead code already !?
+##LIBADD_OBJS = \
+##	lib_a-fenv.$(OBJEXT)
+##
+## # fenv.c cannot be compiled as mips16 since it uses the cfc1 instruction
+##lib_a-fenv.o: fenv.c
+##	$(COMPILE) -mno-mips16 -c -o $@ `test -f 'fenv.c' || echo '$(srcdir)/'`fenv.c
+##
+##lib_a-fenv.obj: fenv.c
+##	$(COMPILE) -mno-mips16 -c -o $@ `if test -f 'fenv.c'; then $(CYGPATH_W) 'fenv.c'; else $(CYGPATH_W) '$(srcdir)/fenv.c'; fi`
diff --git a/newlib/libm/machine/nds32/Makefile.am b/newlib/libm/machine/nds32/Makefile.am
deleted file mode 100644
index b07c188180b1..000000000000
--- a/newlib/libm/machine/nds32/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src =
-
-if HAS_NDS32_FPU_SP
-src += wf_sqrt.S
-endif
-
-if HAS_NDS32_FPU_DP
-src += w_sqrt.S
-endif
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/nds32/Makefile.inc b/newlib/libm/machine/nds32/Makefile.inc
new file mode 100644
index 000000000000..e404baac2742
--- /dev/null
+++ b/newlib/libm/machine/nds32/Makefile.inc
@@ -0,0 +1,10 @@
+%C%_src =
+if HAS_NDS32_FPU_SP
+%C%_src += %D%/wf_sqrt.S
+endif
+
+if HAS_NDS32_FPU_DP
+%C%_src += %D%/w_sqrt.S
+endif
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/powerpc/Makefile.am b/newlib/libm/machine/powerpc/Makefile.am
deleted file mode 100644
index 020a3ac7aeec..000000000000
--- a/newlib/libm/machine/powerpc/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c fenv.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/powerpc/Makefile.inc b/newlib/libm/machine/powerpc/Makefile.inc
new file mode 100644
index 000000000000..79fc26103092
--- /dev/null
+++ b/newlib/libm/machine/powerpc/Makefile.inc
@@ -0,0 +1,6 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/fenv.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/pru/Makefile.am b/newlib/libm/machine/pru/Makefile.am
deleted file mode 100644
index 6e055a34b972..000000000000
--- a/newlib/libm/machine/pru/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	fpclassify.c fpclassifyf.c isfinite.c isfinitef.c isinf.c \
-	isinff.c isnan.c isnanf.c isnormal.c isnormalf.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/pru/Makefile.inc b/newlib/libm/machine/pru/Makefile.inc
new file mode 100644
index 000000000000..e711d0872821
--- /dev/null
+++ b/newlib/libm/machine/pru/Makefile.inc
@@ -0,0 +1,5 @@
+%C%_src = \
+	%D%/fpclassify.c %D%/fpclassifyf.c %D%/isfinite.c %D%/isfinitef.c %D%/isinf.c \
+	%D%/isinff.c %D%/isnan.c %D%/isnanf.c %D%/isnormal.c %D%/isnormalf.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
deleted file mode 100644
index 0e23cd615f82..000000000000
--- a/newlib/libm/machine/riscv/Makefile.am
+++ /dev/null
@@ -1,25 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c \
-	s_fmax.c s_fmin.c sf_fmax.c sf_fmin.c \
-	s_fabs.c sf_fabs.c \
-	s_fpclassify.c sf_fpclassify.c \
-	s_finite.c sf_finite.c \
-	s_isinf.c sf_isinf.c \
-	s_isnan.c sf_isnan.c \
-	s_copysign.c sf_copysign.c \
-	s_lrint.c sf_lrint.c \
-	s_lround.c sf_lround.c \
-	s_llrint.c sf_llrint.c \
-	s_llround.c sf_llround.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/riscv/Makefile.inc b/newlib/libm/machine/riscv/Makefile.inc
new file mode 100644
index 000000000000..9ce71e7be622
--- /dev/null
+++ b/newlib/libm/machine/riscv/Makefile.inc
@@ -0,0 +1,18 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/s_fma.c %D%/e_sqrt.c %D%/sf_fma.c %D%/ef_sqrt.c \
+	%D%/s_fmax.c %D%/s_fmin.c %D%/sf_fmax.c %D%/sf_fmin.c \
+	%D%/s_fabs.c %D%/sf_fabs.c \
+	%D%/s_fpclassify.c %D%/sf_fpclassify.c \
+	%D%/s_finite.c %D%/sf_finite.c \
+	%D%/s_isinf.c %D%/sf_isinf.c \
+	%D%/s_isnan.c %D%/sf_isnan.c \
+	%D%/s_copysign.c %D%/sf_copysign.c \
+	%D%/s_lrint.c %D%/sf_lrint.c \
+	%D%/s_lround.c %D%/sf_lround.c \
+	%D%/s_llrint.c %D%/sf_llrint.c \
+	%D%/s_llround.c %D%/sf_llround.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/sparc/Makefile.am b/newlib/libm/machine/sparc/Makefile.am
deleted file mode 100644
index c0e6c510c4ce..000000000000
--- a/newlib/libm/machine/sparc/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c  fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	fenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/sparc/Makefile.inc b/newlib/libm/machine/sparc/Makefile.inc
new file mode 100644
index 000000000000..df510a4da9d2
--- /dev/null
+++ b/newlib/libm/machine/sparc/Makefile.inc
@@ -0,0 +1,7 @@
+%C%_src = \
+	%D%/feclearexcept.c  %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/fenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/spu/Makefile.am b/newlib/libm/machine/spu/Makefile.am
deleted file mode 100644
index 87be8d429576..000000000000
--- a/newlib/libm/machine/spu/Makefile.am
+++ /dev/null
@@ -1,32 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	llrint.c llrintf.c llround.c llroundf.c log2.c log2f.c s_asinh.c \
-	s_atan.c s_cbrt.c s_ceil.c s_copysign.c s_cos.c s_erf.c s_expm1.c \
-	s_fabs.c sf_asinh.c sf_atan.c sf_cbrt.c sf_ceil.c sf_copysign.c \
-	sf_cos.c s_fdim.c sf_erf.c sf_expm1.c sf_fabs.c sf_fdim.c \
-	sf_finite.c sf_floor.c sf_fma.c sf_fmax.c sf_fmin.c \
-	sf_fpclassify.c sf_frexp.c sf_ilogb.c sf_isinf.c sf_isinff.c \
-	sf_isnan.c sf_isnanf.c sf_ldexp.c sf_log1p.c sf_logb.c s_floor.c \
-	sf_lrint.c sf_lround.c s_fma.c s_fmax.c s_fmin.c sf_nan.c \
-	sf_nearbyint.c sf_nextafter.c sf_remquo.c s_frexp.c sf_rint.c \
-	sf_round.c sf_scalbn.c sf_sin.c sf_tan.c sf_tanh.c sf_trunc.c \
-	s_ilogb.c s_isnan.c s_ldexp.c s_log1p.c s_lrint.c s_lround.c \
-	s_nearbyint.c s_nextafter.c s_remquo.c s_rint.c s_round.c \
-	s_scalbn.c s_sin.c s_tan.c s_tanh.c s_trunc.c w_acos.c w_acosh.c \
-	w_asin.c w_atan2.c w_atanh.c w_cosh.c w_exp2.c w_exp.c wf_acos.c \
-	wf_acosh.c wf_asin.c wf_atan2.c wf_atanh.c wf_cosh.c wf_exp2.c \
-	wf_exp.c wf_fmod.c wf_hypot.c wf_lgamma.c wf_log10.c wf_log.c \
-	w_fmod.c wf_pow.c wf_remainder.c wf_sincos.c wf_sinh.c wf_sqrt.c \
-	wf_tgamma.c w_hypot.c w_lgamma.c w_log10.c w_log.c w_pow.c \
-	w_remainder.c w_sincos.c w_sinh.c w_sqrt.c w_tgamma.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/spu/Makefile.inc b/newlib/libm/machine/spu/Makefile.inc
new file mode 100644
index 000000000000..8dec3dedc536
--- /dev/null
+++ b/newlib/libm/machine/spu/Makefile.inc
@@ -0,0 +1,25 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/llrint.c %D%/llrintf.c %D%/llround.c %D%/llroundf.c %D%/log2.c %D%/log2f.c %D%/s_asinh.c \
+	%D%/s_atan.c %D%/s_cbrt.c %D%/s_ceil.c %D%/s_copysign.c %D%/s_cos.c %D%/s_erf.c %D%/s_expm1.c \
+	%D%/s_fabs.c %D%/sf_asinh.c %D%/sf_atan.c %D%/sf_cbrt.c %D%/sf_ceil.c %D%/sf_copysign.c \
+	%D%/sf_cos.c %D%/s_fdim.c %D%/sf_erf.c %D%/sf_expm1.c %D%/sf_fabs.c %D%/sf_fdim.c \
+	%D%/sf_finite.c %D%/sf_floor.c %D%/sf_fma.c %D%/sf_fmax.c %D%/sf_fmin.c \
+	%D%/sf_fpclassify.c %D%/sf_frexp.c %D%/sf_ilogb.c %D%/sf_isinf.c %D%/sf_isinff.c \
+	%D%/sf_isnan.c %D%/sf_isnanf.c %D%/sf_ldexp.c %D%/sf_log1p.c %D%/sf_logb.c %D%/s_floor.c \
+	%D%/sf_lrint.c %D%/sf_lround.c %D%/s_fma.c %D%/s_fmax.c %D%/s_fmin.c %D%/sf_nan.c \
+	%D%/sf_nearbyint.c %D%/sf_nextafter.c %D%/sf_remquo.c %D%/s_frexp.c %D%/sf_rint.c \
+	%D%/sf_round.c %D%/sf_scalbn.c %D%/sf_sin.c %D%/sf_tan.c %D%/sf_tanh.c %D%/sf_trunc.c \
+	%D%/s_ilogb.c %D%/s_isnan.c %D%/s_ldexp.c %D%/s_log1p.c %D%/s_lrint.c %D%/s_lround.c \
+	%D%/s_nearbyint.c %D%/s_nextafter.c %D%/s_remquo.c %D%/s_rint.c %D%/s_round.c \
+	%D%/s_scalbn.c %D%/s_sin.c %D%/s_tan.c %D%/s_tanh.c %D%/s_trunc.c %D%/w_acos.c %D%/w_acosh.c \
+	%D%/w_asin.c %D%/w_atan2.c %D%/w_atanh.c %D%/w_cosh.c %D%/w_exp2.c %D%/w_exp.c %D%/wf_acos.c \
+	%D%/wf_acosh.c %D%/wf_asin.c %D%/wf_atan2.c %D%/wf_atanh.c %D%/wf_cosh.c %D%/wf_exp2.c \
+	%D%/wf_exp.c %D%/wf_fmod.c %D%/wf_hypot.c %D%/wf_lgamma.c %D%/wf_log10.c %D%/wf_log.c \
+	%D%/w_fmod.c %D%/wf_pow.c %D%/wf_remainder.c %D%/wf_sincos.c %D%/wf_sinh.c %D%/wf_sqrt.c \
+	%D%/wf_tgamma.c %D%/w_hypot.c %D%/w_lgamma.c %D%/w_log10.c %D%/w_log.c %D%/w_pow.c \
+	%D%/w_remainder.c %D%/w_sincos.c %D%/w_sinh.c %D%/w_sqrt.c %D%/w_tgamma.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/x86_64/Makefile.am b/newlib/libm/machine/x86_64/Makefile.am
deleted file mode 100644
index 9fc16c247f1c..000000000000
--- a/newlib/libm/machine/x86_64/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) \
-	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c fegetround.c \
-	feholdexcept.c fenv.c feraiseexcept.c fesetenv.c fesetexceptflag.c \
-	fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/x86_64/Makefile.inc b/newlib/libm/machine/x86_64/Makefile.inc
new file mode 100644
index 000000000000..48a1f71b276f
--- /dev/null
+++ b/newlib/libm/machine/x86_64/Makefile.inc
@@ -0,0 +1,6 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c %D%/fegetround.c \
+	%D%/feholdexcept.c %D%/fenv.c %D%/feraiseexcept.c %D%/fesetenv.c %D%/fesetexceptflag.c \
+	%D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/math/Makefile.am b/newlib/libm/math/Makefile.am
deleted file mode 100644
index c755d464e72e..000000000000
--- a/newlib/libm/math/Makefile.am
+++ /dev/null
@@ -1,60 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src = 	k_standard.c k_rem_pio2.c \
-	k_cos.c k_sin.c k_tan.c \
-	e_acos.c e_acosh.c e_asin.c e_atan2.c \
-	e_atanh.c e_cosh.c e_exp.c e_fmod.c \
-	e_tgamma.c e_hypot.c e_j0.c \
-	e_j1.c e_jn.c er_lgamma.c \
-	e_log.c e_log10.c e_pow.c e_rem_pio2.c e_remainder.c \
-	e_scalb.c e_sinh.c e_sqrt.c \
-	w_acos.c w_acosh.c w_asin.c w_atan2.c \
-	w_atanh.c w_cosh.c w_exp.c w_fmod.c \
-	w_gamma.c wr_gamma.c w_hypot.c w_j0.c \
-	w_j1.c w_jn.c w_lgamma.c wr_lgamma.c \
-	w_log.c w_log10.c w_pow.c w_remainder.c \
-	w_scalb.c w_sinh.c w_sqrt.c \
-	w_sincos.c \
-	w_drem.c \
-	s_asinh.c s_atan.c s_ceil.c \
-	s_cos.c s_erf.c s_fabs.c s_floor.c \
-	s_frexp.c s_ldexp.c \
-	s_signif.c s_sin.c \
-	s_tan.c s_tanh.c \
-	w_exp2.c w_tgamma.c
-
-fsrc =	kf_rem_pio2.c \
-	kf_cos.c kf_sin.c kf_tan.c \
-	ef_acos.c ef_acosh.c ef_asin.c ef_atan2.c \
-	ef_atanh.c ef_cosh.c ef_exp.c ef_fmod.c \
-	ef_tgamma.c ef_hypot.c ef_j0.c \
-	ef_j1.c ef_jn.c erf_lgamma.c \
-	ef_log.c ef_log10.c ef_pow.c ef_rem_pio2.c ef_remainder.c \
-	ef_scalb.c ef_sinh.c ef_sqrt.c \
-	wf_acos.c wf_acosh.c wf_asin.c wf_atan2.c \
-	wf_atanh.c wf_cosh.c wf_exp.c wf_fmod.c \
-	wf_gamma.c wrf_gamma.c wf_hypot.c wf_j0.c \
-	wf_j1.c wf_jn.c wf_lgamma.c wrf_lgamma.c \
-	wf_log.c wf_log10.c wf_pow.c wf_remainder.c \
-	wf_scalb.c wf_sinh.c wf_sqrt.c \
-	wf_sincos.c \
-	wf_drem.c \
-	sf_asinh.c sf_atan.c sf_ceil.c \
-	sf_cos.c sf_erf.c sf_fabs.c sf_floor.c \
-	sf_frexp.c sf_ldexp.c \
-	sf_signif.c sf_sin.c \
-	sf_tan.c sf_tanh.c \
-	wf_exp2.c wf_tgamma.c \
-	wf_log2.c
-
-lsrc = el_hypot.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc) $(lsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h $(srcdir)/../common/fdlibm.h
diff --git a/newlib/libm/math/Makefile.inc b/newlib/libm/math/Makefile.inc
index bc3205e0b156..1b61d6dd30d5 100644
--- a/newlib/libm/math/Makefile.inc
+++ b/newlib/libm/math/Makefile.inc
@@ -1,3 +1,56 @@
+%C%_src = \
+	%D%/k_standard.c %D%/k_rem_pio2.c \
+	%D%/k_cos.c %D%/k_sin.c %D%/k_tan.c \
+	%D%/e_acos.c %D%/e_acosh.c %D%/e_asin.c %D%/e_atan2.c \
+	%D%/e_atanh.c %D%/e_cosh.c %D%/e_exp.c %D%/e_fmod.c \
+	%D%/e_tgamma.c %D%/e_hypot.c %D%/e_j0.c \
+	%D%/e_j1.c %D%/e_jn.c %D%/er_lgamma.c \
+	%D%/e_log.c %D%/e_log10.c %D%/e_pow.c %D%/e_rem_pio2.c %D%/e_remainder.c \
+	%D%/e_scalb.c %D%/e_sinh.c %D%/e_sqrt.c \
+	%D%/w_acos.c %D%/w_acosh.c %D%/w_asin.c %D%/w_atan2.c \
+	%D%/w_atanh.c %D%/w_cosh.c %D%/w_exp.c %D%/w_fmod.c \
+	%D%/w_gamma.c %D%/wr_gamma.c %D%/w_hypot.c %D%/w_j0.c \
+	%D%/w_j1.c %D%/w_jn.c %D%/w_lgamma.c %D%/wr_lgamma.c \
+	%D%/w_log.c %D%/w_log10.c %D%/w_pow.c %D%/w_remainder.c \
+	%D%/w_scalb.c %D%/w_sinh.c %D%/w_sqrt.c \
+	%D%/w_sincos.c \
+	%D%/w_drem.c \
+	%D%/s_asinh.c %D%/s_atan.c %D%/s_ceil.c \
+	%D%/s_cos.c %D%/s_erf.c %D%/s_fabs.c %D%/s_floor.c \
+	%D%/s_frexp.c %D%/s_ldexp.c \
+	%D%/s_signif.c %D%/s_sin.c \
+	%D%/s_tan.c %D%/s_tanh.c \
+	%D%/w_exp2.c %D%/w_tgamma.c
+
+%C%_fsrc = \
+	%D%/kf_rem_pio2.c \
+	%D%/kf_cos.c %D%/kf_sin.c %D%/kf_tan.c \
+	%D%/ef_acos.c %D%/ef_acosh.c %D%/ef_asin.c %D%/ef_atan2.c \
+	%D%/ef_atanh.c %D%/ef_cosh.c %D%/ef_exp.c %D%/ef_fmod.c \
+	%D%/ef_tgamma.c %D%/ef_hypot.c %D%/ef_j0.c \
+	%D%/ef_j1.c %D%/ef_jn.c %D%/erf_lgamma.c \
+	%D%/ef_log.c %D%/ef_log10.c %D%/ef_pow.c %D%/ef_rem_pio2.c %D%/ef_remainder.c \
+	%D%/ef_scalb.c %D%/ef_sinh.c %D%/ef_sqrt.c \
+	%D%/wf_acos.c %D%/wf_acosh.c %D%/wf_asin.c %D%/wf_atan2.c \
+	%D%/wf_atanh.c %D%/wf_cosh.c %D%/wf_exp.c %D%/wf_fmod.c \
+	%D%/wf_gamma.c %D%/wrf_gamma.c %D%/wf_hypot.c %D%/wf_j0.c \
+	%D%/wf_j1.c %D%/wf_jn.c %D%/wf_lgamma.c %D%/wrf_lgamma.c \
+	%D%/wf_log.c %D%/wf_log10.c %D%/wf_pow.c %D%/wf_remainder.c \
+	%D%/wf_scalb.c %D%/wf_sinh.c %D%/wf_sqrt.c \
+	%D%/wf_sincos.c \
+	%D%/wf_drem.c \
+	%D%/sf_asinh.c %D%/sf_atan.c %D%/sf_ceil.c \
+	%D%/sf_cos.c %D%/sf_erf.c %D%/sf_fabs.c %D%/sf_floor.c \
+	%D%/sf_frexp.c %D%/sf_ldexp.c \
+	%D%/sf_signif.c %D%/sf_sin.c \
+	%D%/sf_tan.c %D%/sf_tanh.c \
+	%D%/wf_exp2.c %D%/wf_tgamma.c \
+	%D%/wf_log2.c
+
+%C%_lsrc = %D%/el_hypot.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc) $(%C%_lsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/w_acos.def %D%/w_acosh.def %D%/w_asin.def %D%/s_asinh.def \
 	%D%/s_atan.def %D%/w_atan2.def %D%/w_atanh.def %D%/w_j0.def \
diff --git a/newlib/libm/mathfp/Makefile.am b/newlib/libm/mathfp/Makefile.am
deleted file mode 100644
index ada632326997..000000000000
--- a/newlib/libm/mathfp/Makefile.am
+++ /dev/null
@@ -1,50 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
-
-src =	s_acos.c s_frexp.c s_mathcnst.c \
-	s_cos.c s_sinh.c \
-	s_asin.c\
-	s_asine.c s_cosh.c s_ispos.c s_numtest.c s_sqrt.c \
-	s_exp.c s_ldexp.c s_pow.c s_tan.c \
-	s_atan.c \
-	s_atan2.c s_fabs.c s_log.c s_tanh.c \
-	s_log10.c s_sin.c \
-	s_floor.c s_sine.c \
-	s_sincos.c \
-	s_atangent.c s_logarithm.c \
-	s_sineh.c \
-	s_ceil.c \
-	e_acosh.c e_atanh.c e_remainder.c \
-	er_gamma.c er_lgamma.c \
-	s_erf.c e_j0.c e_j1.c w_jn.c e_hypot.c \
-	w_cabs.c w_drem.c s_asinh.c s_fmod.c \
-	e_scalb.c s_signif.c \
-	s_exp2.c s_tgamma.c
-
-fsrc =	sf_ceil.c \
-	sf_acos.c sf_frexp.c \
-	sf_cos.c sf_sinh.c \
-	sf_asine.c sf_cosh.c sf_ispos.c sf_numtest.c sf_sqrt.c \
-	sf_asin.c \
-	sf_exp.c sf_ldexp.c sf_pow.c sf_tan.c \
-	sf_atan2.c sf_fabs.c sf_tanh.c \
-	sf_atan.c sf_log10.c sf_sin.c\
-	sf_floor.c sf_sine.c \
-	sf_sincos.c \
-	sf_atangent.c sf_logarithm.c sf_sineh.c \
-	sf_log.c sf_sineh.c \
-	ef_acosh.c ef_atanh.c ef_remainder.c \
-	erf_gamma.c erf_lgamma.c \
-	sf_erf.c ef_j0.c ef_j1.c wf_jn.c ef_hypot.c \
-	wf_cabs.c wf_drem.c sf_asinh.c sf_fmod.c \
-	ef_scalb.c sf_signif.c \
-	sf_exp2.c sf_tgamma.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h $(srcdir)/../common/fdlibm.h
diff --git a/newlib/libm/mathfp/Makefile.inc b/newlib/libm/mathfp/Makefile.inc
index 739e41f16d0b..f1e6da83211a 100644
--- a/newlib/libm/mathfp/Makefile.inc
+++ b/newlib/libm/mathfp/Makefile.inc
@@ -1,3 +1,46 @@
+%C%_src = \
+	%D%/s_acos.c %D%/s_frexp.c %D%/s_mathcnst.c \
+	%D%/s_cos.c %D%/s_sinh.c \
+	%D%/s_asin.c\
+	%D%/s_asine.c %D%/s_cosh.c %D%/s_ispos.c %D%/s_numtest.c %D%/s_sqrt.c \
+	%D%/s_exp.c %D%/s_ldexp.c %D%/s_pow.c %D%/s_tan.c \
+	%D%/s_atan.c \
+	%D%/s_atan2.c %D%/s_fabs.c %D%/s_log.c %D%/s_tanh.c \
+	%D%/s_log10.c %D%/s_sin.c \
+	%D%/s_floor.c %D%/s_sine.c \
+	%D%/s_sincos.c \
+	%D%/s_atangent.c %D%/s_logarithm.c \
+	%D%/s_sineh.c \
+	%D%/s_ceil.c \
+	%D%/e_acosh.c %D%/e_atanh.c %D%/e_remainder.c \
+	%D%/er_gamma.c %D%/er_lgamma.c \
+	%D%/s_erf.c %D%/e_j0.c %D%/e_j1.c %D%/w_jn.c %D%/e_hypot.c \
+	%D%/w_cabs.c %D%/w_drem.c %D%/s_asinh.c %D%/s_fmod.c \
+	%D%/e_scalb.c %D%/s_signif.c \
+	%D%/s_exp2.c %D%/s_tgamma.c
+
+%C%_fsrc = \
+	%D%/sf_ceil.c \
+	%D%/sf_acos.c %D%/sf_frexp.c \
+	%D%/sf_cos.c %D%/sf_sinh.c \
+	%D%/sf_asine.c %D%/sf_cosh.c %D%/sf_ispos.c %D%/sf_numtest.c %D%/sf_sqrt.c \
+	%D%/sf_asin.c \
+	%D%/sf_exp.c %D%/sf_ldexp.c %D%/sf_pow.c %D%/sf_tan.c \
+	%D%/sf_atan2.c %D%/sf_fabs.c %D%/sf_tanh.c \
+	%D%/sf_atan.c %D%/sf_log10.c %D%/sf_sin.c\
+	%D%/sf_floor.c %D%/sf_sine.c \
+	%D%/sf_sincos.c \
+	%D%/sf_atangent.c %D%/sf_logarithm.c %D%/sf_sineh.c \
+	%D%/sf_log.c %D%/sf_sineh.c \
+	%D%/ef_acosh.c %D%/ef_atanh.c %D%/ef_remainder.c \
+	%D%/erf_gamma.c %D%/erf_lgamma.c \
+	%D%/sf_erf.c %D%/ef_j0.c %D%/ef_j1.c %D%/wf_jn.c %D%/ef_hypot.c \
+	%D%/wf_cabs.c %D%/wf_drem.c %D%/sf_asinh.c %D%/sf_fmod.c \
+	%D%/ef_scalb.c %D%/sf_signif.c \
+	%D%/sf_exp2.c %D%/sf_tgamma.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/e_acosh.def \
 	%D%/e_atanh.def \
-- 
2.34.1


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

* [HEADSUP] Re: [PATCH] newlib: libm: merge build up a directory
  2022-02-12 20:34 [PATCH] newlib: libm: merge build up a directory Mike Frysinger
@ 2022-02-16  8:50 ` Corinna Vinschen
  2022-02-16  9:40   ` Sebastian Huber
  2022-02-17  4:38   ` Mike Frysinger
  2022-02-17  4:42 ` [PATCH v2] " Mike Frysinger
  1 sibling, 2 replies; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-16  8:50 UTC (permalink / raw)
  To: newlib

On Feb 12 15:34, Mike Frysinger wrote:
> Convert all the libm/ subdir makes into the top-level Makefile.  This
> allows us to build all of libm from the top Makefile without using any
> recursive make calls.  This is faster and avoids the funky lib.a logic
> where we unpack subdir archives to repack into a single libm.a.  The
> machine override logic is maintained though by way of Makefile include
> ordering, and source file accumulation in libm_a_SOURCES.

What targets did you test this with?

> One thing to note is that this will require GNU Make because of:
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Anybody here having a problem with that?


Corinna


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

* Re: [HEADSUP] Re: [PATCH] newlib: libm: merge build up a directory
  2022-02-16  8:50 ` [HEADSUP] " Corinna Vinschen
@ 2022-02-16  9:40   ` Sebastian Huber
  2022-02-16 10:48     ` Corinna Vinschen
  2022-02-17  4:38   ` Mike Frysinger
  1 sibling, 1 reply; 25+ messages in thread
From: Sebastian Huber @ 2022-02-16  9:40 UTC (permalink / raw)
  To: newlib

On 16/02/2022 09:50, Corinna Vinschen wrote:
>> One thing to note is that this will require GNU Make because of:
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Anybody here having a problem with that?

GNU Make is also required to build GCC:

https://gcc.gnu.org/install/prerequisites.html

-- 
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] 25+ messages in thread

* Re: [HEADSUP] Re: [PATCH] newlib: libm: merge build up a directory
  2022-02-16  9:40   ` Sebastian Huber
@ 2022-02-16 10:48     ` Corinna Vinschen
  0 siblings, 0 replies; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-16 10:48 UTC (permalink / raw)
  To: newlib

On Feb 16 10:40, Sebastian Huber wrote:
> On 16/02/2022 09:50, Corinna Vinschen wrote:
> > > One thing to note is that this will require GNU Make because of:
> >    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > Anybody here having a problem with that?
> 
> GNU Make is also required to build GCC:
> 
> https://gcc.gnu.org/install/prerequisites.html

Good point.  I'm just exercising caution...


Corinna


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

* Re: [HEADSUP] Re: [PATCH] newlib: libm: merge build up a directory
  2022-02-16  8:50 ` [HEADSUP] " Corinna Vinschen
  2022-02-16  9:40   ` Sebastian Huber
@ 2022-02-17  4:38   ` Mike Frysinger
  1 sibling, 0 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-17  4:38 UTC (permalink / raw)
  To: newlib

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

On 16 Feb 2022 09:50, Corinna Vinschen wrote:
> On Feb 12 15:34, Mike Frysinger wrote:
> > Convert all the libm/ subdir makes into the top-level Makefile.  This
> > allows us to build all of libm from the top Makefile without using any
> > recursive make calls.  This is faster and avoids the funky lib.a logic
> > where we unpack subdir archives to repack into a single libm.a.  The
> > machine override logic is maintained though by way of Makefile include
> > ordering, and source file accumulation in libm_a_SOURCES.
> 
> What targets did you test this with?

testing these targets:
aarch64-elf arc-elf arm-eabi
bfin-elf
cr16-elf cris-elf csky-elf
epiphany-elf
frv-elf
h8300-elf
i386-elf i686-pc-cygwin iq2000-elf
m68k-elf microblaze-elf mips-elf mn10300-elf moxie-elf
nds32le-elf
or1k-elf
powerpc-elf
sparc-elf sparc-rtems
v850e-elf visium-elf
xstormy16-elf

the actual testing:
- build w/out the patch
make install DESTDIR=$PWD/old.root
ar t every library
objdump -d every object
- build w/the patch
make install DESTDIR=$PWD/new.root
ar t every library
objdump -d every object

run `diff -ur` on the 2 roots.  they install the same set of files, and
the disassembly of the objects is the same.

so should be good to go.  only needed about 30G to determine this :p.

> > One thing to note is that this will require GNU Make because of:
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Anybody here having a problem with that?

while i couldn't find any prior usage in newlib specifically (i think all
the code i looked through is portable make), libgloss def has GNUisms in
at least 12 of its ports:
aarch64 arm bfin cris csky m68k msp430 nios2 or1k riscv visium xstormy16

no one seems to have complained so far :).
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH v2] newlib: libm: merge build up a directory
  2022-02-12 20:34 [PATCH] newlib: libm: merge build up a directory Mike Frysinger
  2022-02-16  8:50 ` [HEADSUP] " Corinna Vinschen
@ 2022-02-17  4:42 ` Mike Frysinger
  2022-02-17 12:08   ` Corinna Vinschen
  2022-02-21 11:20   ` Corinna Vinschen
  1 sibling, 2 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-17  4:42 UTC (permalink / raw)
  To: newlib

Convert all the libm/ subdir makes into the top-level Makefile.  This
allows us to build all of libm from the top Makefile without using any
recursive make calls.  This is faster and avoids the funky lib.a logic
where we unpack subdir archives to repack into a single libm.a.  The
machine override logic is maintained though by way of Makefile include
ordering, and source file accumulation in libm_a_SOURCES.

One thing to note is that this will require GNU Make because of:
	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
This was the only way I could find to supporting per-dir compiler
settings, and I couldn't find a POSIX compatible way of transforming
the variable content.  I don't think this is a big deal as other
Makefiles in the tree are using GNU Make-specific syntax, but I call
this out as it's the only one so far in the new automake code that
I've been writing.

Automake doesn't provide precise control over the output object names
(by design).  This is fine by default as we get consistent names in all
the subdirs: libm_a-<source>.o.  But this relies on using the same set
of compiler flags for all objects.  We currently compile libm/common/
with different optimizations than the rest.

If we want to compile objects differently, we can create an intermediate
archive with the subset of objects with unique flags, and then add those
objects to the main archive.  But Automake will use a different prefix
for the objects, and thus we can't rely on ordering to override.

But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
since $@ contains /, Automake complains it's an invalid name.  While
GNU Make supports this, it's a POSIX extension, so Automake flags it.
Using $(subst) avoids the Automake warning to get a POSIX compliant
name, albeit with a GNU Make extension.
---
v2
- rebased onto latest tree
- fixed a parallel build issue with generated newlib headers & libm objects

 newlib/Makefile.am                       |   39 +-
 newlib/Makefile.in                       | 7756 +++++++++++++++++++++-
 newlib/configure                         |  202 +-
 newlib/libm/Makefile.am                  |   28 -
 newlib/libm/Makefile.in                  |  594 --
 newlib/libm/Makefile.inc                 |   45 +-
 newlib/libm/acinclude.m4                 |   31 +-
 newlib/libm/common/Makefile.am           |   51 -
 newlib/libm/common/Makefile.in           | 1553 -----
 newlib/libm/common/Makefile.inc          |   79 +
 newlib/libm/complex/Makefile.am          |   29 -
 newlib/libm/complex/Makefile.in          | 1007 ---
 newlib/libm/complex/Makefile.inc         |   23 +
 newlib/libm/fenv/Makefile.am             |   15 -
 newlib/libm/fenv/Makefile.in             |  610 --
 newlib/libm/fenv/Makefile.inc            |    7 +
 newlib/libm/machine/aarch64/Makefile.am  |   51 -
 newlib/libm/machine/aarch64/Makefile.in  |  840 ---
 newlib/libm/machine/aarch64/Makefile.inc |   45 +
 newlib/libm/machine/arm/Makefile.am      |   41 -
 newlib/libm/machine/arm/Makefile.in      |  758 ---
 newlib/libm/machine/arm/Makefile.inc     |   34 +
 newlib/libm/machine/i386/Makefile.am     |   21 -
 newlib/libm/machine/i386/Makefile.in     |  789 ---
 newlib/libm/machine/i386/Makefile.inc    |   12 +
 newlib/libm/machine/mips/Makefile.am     |   22 -
 newlib/libm/machine/mips/Makefile.in     |  610 --
 newlib/libm/machine/mips/Makefile.inc    |   10 +
 newlib/libm/machine/nds32/Makefile.am    |   17 -
 newlib/libm/machine/nds32/Makefile.in    |  531 --
 newlib/libm/machine/nds32/Makefile.inc   |   10 +
 newlib/libm/machine/powerpc/Makefile.am  |   12 -
 newlib/libm/machine/powerpc/Makefile.in  |  606 --
 newlib/libm/machine/powerpc/Makefile.inc |    6 +
 newlib/libm/machine/pru/Makefile.am      |   11 -
 newlib/libm/machine/pru/Makefile.in      |  592 --
 newlib/libm/machine/pru/Makefile.inc     |    5 +
 newlib/libm/machine/riscv/Makefile.am    |   24 -
 newlib/libm/machine/riscv/Makefile.in    |  801 ---
 newlib/libm/machine/riscv/Makefile.inc   |   18 +
 newlib/libm/machine/sparc/Makefile.am    |   13 -
 newlib/libm/machine/sparc/Makefile.in    |  607 --
 newlib/libm/machine/sparc/Makefile.inc   |    7 +
 newlib/libm/machine/spu/Makefile.am      |   31 -
 newlib/libm/machine/spu/Makefile.in      | 1360 ----
 newlib/libm/machine/spu/Makefile.inc     |   25 +
 newlib/libm/machine/x86_64/Makefile.am   |   12 -
 newlib/libm/machine/x86_64/Makefile.in   |  606 --
 newlib/libm/machine/x86_64/Makefile.inc  |    6 +
 newlib/libm/math/Makefile.am             |   60 -
 newlib/libm/math/Makefile.in             | 1453 ----
 newlib/libm/math/Makefile.inc            |   53 +
 newlib/libm/mathfp/Makefile.am           |   50 -
 newlib/libm/mathfp/Makefile.in           | 1172 ----
 newlib/libm/mathfp/Makefile.inc          |   43 +
 55 files changed, 8090 insertions(+), 15343 deletions(-)
 delete mode 100644 newlib/libm/Makefile.am
 delete mode 100644 newlib/libm/Makefile.in
 delete mode 100644 newlib/libm/common/Makefile.am
 delete mode 100644 newlib/libm/common/Makefile.in
 delete mode 100644 newlib/libm/complex/Makefile.am
 delete mode 100644 newlib/libm/complex/Makefile.in
 delete mode 100644 newlib/libm/fenv/Makefile.am
 delete mode 100644 newlib/libm/fenv/Makefile.in
 delete mode 100644 newlib/libm/machine/aarch64/Makefile.am
 delete mode 100644 newlib/libm/machine/aarch64/Makefile.in
 create mode 100644 newlib/libm/machine/aarch64/Makefile.inc
 delete mode 100644 newlib/libm/machine/arm/Makefile.am
 delete mode 100644 newlib/libm/machine/arm/Makefile.in
 create mode 100644 newlib/libm/machine/arm/Makefile.inc
 delete mode 100644 newlib/libm/machine/i386/Makefile.am
 delete mode 100644 newlib/libm/machine/i386/Makefile.in
 create mode 100644 newlib/libm/machine/i386/Makefile.inc
 delete mode 100644 newlib/libm/machine/mips/Makefile.am
 delete mode 100644 newlib/libm/machine/mips/Makefile.in
 create mode 100644 newlib/libm/machine/mips/Makefile.inc
 delete mode 100644 newlib/libm/machine/nds32/Makefile.am
 delete mode 100644 newlib/libm/machine/nds32/Makefile.in
 create mode 100644 newlib/libm/machine/nds32/Makefile.inc
 delete mode 100644 newlib/libm/machine/powerpc/Makefile.am
 delete mode 100644 newlib/libm/machine/powerpc/Makefile.in
 create mode 100644 newlib/libm/machine/powerpc/Makefile.inc
 delete mode 100644 newlib/libm/machine/pru/Makefile.am
 delete mode 100644 newlib/libm/machine/pru/Makefile.in
 create mode 100644 newlib/libm/machine/pru/Makefile.inc
 delete mode 100644 newlib/libm/machine/riscv/Makefile.am
 delete mode 100644 newlib/libm/machine/riscv/Makefile.in
 create mode 100644 newlib/libm/machine/riscv/Makefile.inc
 delete mode 100644 newlib/libm/machine/sparc/Makefile.am
 delete mode 100644 newlib/libm/machine/sparc/Makefile.in
 create mode 100644 newlib/libm/machine/sparc/Makefile.inc
 delete mode 100644 newlib/libm/machine/spu/Makefile.am
 delete mode 100644 newlib/libm/machine/spu/Makefile.in
 create mode 100644 newlib/libm/machine/spu/Makefile.inc
 delete mode 100644 newlib/libm/machine/x86_64/Makefile.am
 delete mode 100644 newlib/libm/machine/x86_64/Makefile.in
 create mode 100644 newlib/libm/machine/x86_64/Makefile.inc
 delete mode 100644 newlib/libm/math/Makefile.am
 delete mode 100644 newlib/libm/math/Makefile.in
 delete mode 100644 newlib/libm/mathfp/Makefile.am
 delete mode 100644 newlib/libm/mathfp/Makefile.in

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 6d3b60b330b0..0a966beca6c2 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -59,11 +59,12 @@ AM_MAKEFLAGS = \
 
 FLAGS_TO_PASS=$(AM_MAKEFLAGS)
 
-SUBDIRS = libc libm .
+SUBDIRS = libc .
 
 tooldir = $(exec_prefix)/$(host_alias)
 toollibdir = $(tooldir)/lib$(MULTISUBDIR)
 
+AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
 AR_FLAGS = rc
 
 noinst_DATA += stmp-targ-include
@@ -84,19 +85,19 @@ toollib_DATA = $(CRT0) $(CRT1)
 # both libc.a and libm.a.  We build them in libm.a and copy them over,
 # along with some required supporting routines.
 MATHOBJS_IN_LIBC = \
-	$(lpfx)s_fpclassify.o $(lpfx)sf_fpclassify.o \
-	$(lpfx)s_isinf.o $(lpfx)sf_isinf.o \
-	$(lpfx)s_isnan.o $(lpfx)sf_isnan.o \
-	$(lpfx)s_isinfd.o $(lpfx)sf_isinff.o \
-	$(lpfx)s_isnand.o $(lpfx)sf_isnanf.o \
-	$(lpfx)s_nan.o $(lpfx)sf_nan.o \
-	$(lpfx)s_ldexp.o $(lpfx)sf_ldexp.o \
-	$(lpfx)s_frexp.o $(lpfx)sf_frexp.o $(lpfx)frexpl.o \
-	$(lpfx)s_modf.o \
-	$(lpfx)sf_modf.o $(lpfx)s_scalbn.o \
-	$(lpfx)sf_scalbn.o \
-	$(lpfx)s_finite.o $(lpfx)sf_finite.o \
-	$(lpfx)s_copysign.o $(lpfx)sf_copysign.o
+	libm_a-s_fpclassify.o libm_a-sf_fpclassify.o \
+	libm_a-s_isinf.o libm_a-sf_isinf.o \
+	libm_a-s_isnan.o libm_a-sf_isnan.o \
+	libm_a-s_isinfd.o libm_a-sf_isinff.o \
+	libm_a-s_isnand.o libm_a-sf_isnanf.o \
+	libm_a-s_nan.o libm_a-sf_nan.o \
+	libm_a-s_ldexp.o libm_a-sf_ldexp.o \
+	libm_a-s_frexp.o libm_a-sf_frexp.o libm_a-frexpl.o \
+	libm_a-s_modf.o \
+	libm_a-sf_modf.o libm_a-s_scalbn.o \
+	libm_a-sf_scalbn.o \
+	libm_a-s_finite.o libm_a-sf_finite.o \
+	libm_a-s_copysign.o libm_a-sf_copysign.o
 
 libc.a: libc/libc.a libm.a
 	rm -rf libc.a libg.a tmp
@@ -111,11 +112,11 @@ libc.a: libc/libc.a libm.a
 
 libc/libc.a: ; @true
 
-libm.a: libm/libm.a
-	rm -f $@
-	ln $< $@ >/dev/null 2>/dev/null || cp $< $@
-
-libm/libm.a: ; @true
+libm_a_SOURCES =
+libm_a_CFLAGS = $(AM_CFLAGS) $(libm_a_CFLAGS_$(subst /,_,$(@D))) $(libm_a_CFLAGS_$(subst /,_,$(@D)_$(<F)))
+libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm_a_CCASFLAGS_$(subst /,_,$(@D)_$(<F)))
+libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst /,_,$(@D)_$(<F)))
+$(libm_a_OBJECTS): stmp-targ-include
 
 if HAVE_MULTISUBDIR
 $(BUILD_MULTISUBDIR):
diff --git a/newlib/libm/Makefile.am b/newlib/libm/Makefile.am
deleted file mode 100644
index 0ab26cda852c..000000000000
--- a/newlib/libm/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-if NEWLIB_HW_FP
-MATHDIR = mathfp
-else
-MATHDIR = math
-endif
-
-SUBDIRS = $(MATHDIR) common complex fenv
-if HAVE_LIBM_MACHINE_DIR
-SUBDIRS += $(LIBM_MACHINE_DIR)
-endif
-
-SUBLIBS = $(MATHDIR)/lib.a common/lib.a complex/lib.a fenv/lib.a $(LIBM_MACHINE_LIB)
-noinst_LIBRARIES = libm.a
-libm.a: $(SUBLIBS)
-	rm -f $@
-	rm -rf tmp
-	mkdir tmp
-	cd tmp; \
-	  for i in $(SUBLIBS); do \
-	    $(AR) x ../$$i; \
-	done; \
-	$(AR) $(AR_FLAGS) ../$@ *.o
-	$(RANLIB) $@
-	rm -rf tmp
-
-$(SUBLIBS):
diff --git a/newlib/libm/Makefile.inc b/newlib/libm/Makefile.inc
index 7fdea0ca518e..e43ec7855087 100644
--- a/newlib/libm/Makefile.inc
+++ b/newlib/libm/Makefile.inc
@@ -34,14 +34,53 @@ man: %C%_man
 	$(INSTALL_DATA) %D%/*.3 $(DESTDIR)$(mandir)/man3/
 install-man: %C%_install-man
 
-include %D%/common/Makefile.inc
-include %D%/complex/Makefile.inc
-include %D%/fenv/Makefile.inc
+## The order of includes is important for two reasons:
+## * The integrated documentation (chapter ordering).
+## * Object overridding -- machine dir must come last.
+## Do not change the order without considering the doc impact.
+
 if NEWLIB_HW_FP
 include %D%/mathfp/Makefile.inc
 else
 include %D%/math/Makefile.inc
 endif
+include %D%/common/Makefile.inc
+include %D%/complex/Makefile.inc
+include %D%/fenv/Makefile.inc
+
+if HAVE_LIBM_MACHINE_AARCH64
+include %D%/machine/aarch64/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_ARM
+include %D%/machine/arm/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_I386
+include %D%/machine/i386/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_MIPS
+include %D%/machine/mips/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_NDS32
+include %D%/machine/nds32/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_POWERPC
+include %D%/machine/powerpc/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_PRU
+include %D%/machine/pru/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_SPARC
+include %D%/machine/sparc/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_SPU
+include %D%/machine/spu/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_RISCV
+include %D%/machine/riscv/Makefile.inc
+endif
+if HAVE_LIBM_MACHINE_X86_64
+include %D%/machine/x86_64/Makefile.inc
+endif
 
 CLEANFILES += \
 	%D%/targetdep.tex \
diff --git a/newlib/libm/acinclude.m4 b/newlib/libm/acinclude.m4
index 6b59715fce70..0be95a3b29dd 100644
--- a/newlib/libm/acinclude.m4
+++ b/newlib/libm/acinclude.m4
@@ -2,28 +2,9 @@ dnl We have to include these unconditionally since machines might want to use
 dnl AM_CONDITIONAL in their subdirs.
 m4_include([libm/machine/nds32/acinclude.m4])
 
-LIBM_MACHINE_LIB=
-if test -n "${libm_machine_dir}"; then
-  case ${libm_machine_dir} in
-    aarch64) AC_CONFIG_FILES([libm/machine/aarch64/Makefile]) ;;
-    arm) AC_CONFIG_FILES([libm/machine/arm/Makefile]) ;;
-    i386) AC_CONFIG_FILES([libm/machine/i386/Makefile]) ;;
-    nds32) AC_CONFIG_FILES([libm/machine/nds32/Makefile]) ;;
-    pru) AC_CONFIG_FILES([libm/machine/pru/Makefile]) ;;
-    spu) AC_CONFIG_FILES([libm/machine/spu/Makefile]) ;;
-    riscv) AC_CONFIG_FILES([libm/machine/riscv/Makefile]) ;;
-    x86_64) AC_CONFIG_FILES([libm/machine/x86_64/Makefile]) ;;
-    powerpc) AC_CONFIG_FILES([libm/machine/powerpc/Makefile]) ;;
-    sparc) AC_CONFIG_FILES([libm/machine/sparc/Makefile]) ;;
-    mips) AC_CONFIG_FILES([libm/machine/mips/Makefile]) ;;
-    *) AC_MSG_ERROR([unsupported libm_machine_dir "${libm_machine_dir}"]) ;;
-  esac
-
-  LIBM_MACHINE_DIR=machine/${libm_machine_dir}
-  LIBM_MACHINE_LIB=${LIBM_MACHINE_DIR}/lib.a
-fi
-AM_CONDITIONAL(HAVE_LIBM_MACHINE_DIR, test "x${LIBM_MACHINE_DIR}" != x)
-AC_SUBST(LIBM_MACHINE_DIR)
-AC_SUBST(LIBM_MACHINE_LIB)
-
-AC_CONFIG_FILES([libm/Makefile libm/math/Makefile libm/mathfp/Makefile libm/common/Makefile libm/complex/Makefile libm/fenv/Makefile])
+dnl Define HAVE_LIBM_MACHINE_<machine> automake conditionals.
+m4_foreach_w([MACHINE], [
+  aarch64 arm i386 mips nds32 powerpc pru sparc spu riscv x86_64
+], [dnl
+  AM_CONDITIONAL([HAVE_LIBM_MACHINE_]m4_toupper(MACHINE), test "${libm_machine_dir}" = "MACHINE")
+])
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
deleted file mode 100644
index 90a02b9d313f..000000000000
--- a/newlib/libm/common/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src = 	s_finite.c s_copysign.c s_modf.c s_scalbn.c \
-	s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
-	s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
-	s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
-	s_rint.c s_logb.c s_log2.c \
-	s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
-	s_lrint.c s_llrint.c \
-	s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
-	s_signbit.c s_trunc.c \
-	exp.c exp2.c exp_data.c math_err.c log.c log_data.c log2.c log2_data.c \
-	pow.c pow_log_data.c
-
-fsrc =	sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
-	sf_cbrt.c sf_exp10.c sf_expm1.c sf_ilogb.c \
-	sf_infinity.c sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c \
-	sf_log1p.c sf_nan.c sf_nextafter.c sf_pow10.c \
-	sf_rint.c sf_logb.c \
-	sf_fdim.c sf_fma.c sf_fmax.c sf_fmin.c sf_fpclassify.c \
-	sf_lrint.c sf_llrint.c \
-	sf_lround.c sf_llround.c sf_nearbyint.c sf_remquo.c sf_round.c \
-	sf_scalbln.c sf_trunc.c \
-	sf_exp.c sf_exp2.c sf_exp2_data.c sf_log.c sf_log_data.c \
-	sf_log2.c sf_log2_data.c sf_pow_log2_data.c sf_pow.c \
-	sinf.c cosf.c sincosf.c sincosf_data.c math_errf.c
-
-lsrc =	atanl.c cosl.c sinl.c tanl.c tanhl.c frexpl.c modfl.c ceill.c fabsl.c \
-	floorl.c log1pl.c expm1l.c acosl.c asinl.c atan2l.c coshl.c sinhl.c \
-	expl.c ldexpl.c logl.c log10l.c powl.c sqrtl.c fmodl.c hypotl.c \
-	copysignl.c nanl.c ilogbl.c asinhl.c cbrtl.c nextafterl.c rintl.c \
-	scalbnl.c exp2l.c scalblnl.c tgammal.c nearbyintl.c lrintl.c llrintl.c \
-	roundl.c lroundl.c llroundl.c truncl.c remquol.c fdiml.c fmaxl.c fminl.c \
-	fmal.c acoshl.c atanhl.c remainderl.c lgammal.c erfl.c erfcl.c \
-	logbl.c nexttowardf.c nexttoward.c nexttowardl.c log2l.c \
-	sl_finite.c
-
-lib_a_CFLAGS = -fbuiltin -fno-math-errno
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc)
-if HAVE_LONG_DOUBLE
-lib_a_SOURCES += $(lsrc)
-endif # HAVE_LONG_DOUBLE
-lib_a_CFLAGS += $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h fdlibm.h
diff --git a/newlib/libm/common/Makefile.inc b/newlib/libm/common/Makefile.inc
index b0d3013c522b..8b54acab6f4a 100644
--- a/newlib/libm/common/Makefile.inc
+++ b/newlib/libm/common/Makefile.inc
@@ -1,3 +1,82 @@
+%C%_src = \
+	%D%/s_finite.c \
+	%D%/s_copysign.c \
+	%D%/s_modf.c \
+	%D%/s_scalbn.c \
+	%D%/s_cbrt.c \
+	%D%/s_exp10.c \
+	%D%/s_expm1.c \
+	%D%/s_ilogb.c \
+	%D%/s_infinity.c \
+	%D%/s_isinf.c \
+	%D%/s_isinfd.c \
+	%D%/s_isnan.c \
+	%D%/s_isnand.c \
+	%D%/s_log1p.c \
+	%D%/s_nan.c \
+	%D%/s_nextafter.c \
+	%D%/s_pow10.c \
+	%D%/s_rint.c \
+	%D%/s_logb.c \
+	%D%/s_log2.c \
+	%D%/s_fdim.c \
+	%D%/s_fma.c \
+	%D%/s_fmax.c \
+	%D%/s_fmin.c \
+	%D%/s_fpclassify.c \
+	%D%/s_lrint.c \
+	%D%/s_llrint.c \
+	%D%/s_lround.c \
+	%D%/s_llround.c \
+	%D%/s_nearbyint.c \
+	%D%/s_remquo.c \
+	%D%/s_round.c \
+	%D%/s_scalbln.c \
+	%D%/s_signbit.c \
+	%D%/s_trunc.c \
+	%D%/exp.c \
+	%D%/exp2.c \
+	%D%/exp_data.c \
+	%D%/math_err.c \
+	%D%/log.c \
+	%D%/log_data.c \
+	%D%/log2.c \
+	%D%/log2_data.c \
+	%D%/pow.c \
+	%D%/pow_log_data.c
+
+%C%_fsrc = \
+	%D%/sf_finite.c %D%/sf_copysign.c %D%/sf_modf.c %D%/sf_scalbn.c \
+	%D%/sf_cbrt.c %D%/sf_exp10.c %D%/sf_expm1.c %D%/sf_ilogb.c \
+	%D%/sf_infinity.c %D%/sf_isinf.c %D%/sf_isinff.c %D%/sf_isnan.c %D%/sf_isnanf.c \
+	%D%/sf_log1p.c %D%/sf_nan.c %D%/sf_nextafter.c %D%/sf_pow10.c \
+	%D%/sf_rint.c %D%/sf_logb.c \
+	%D%/sf_fdim.c %D%/sf_fma.c %D%/sf_fmax.c %D%/sf_fmin.c %D%/sf_fpclassify.c \
+	%D%/sf_lrint.c %D%/sf_llrint.c \
+	%D%/sf_lround.c %D%/sf_llround.c %D%/sf_nearbyint.c %D%/sf_remquo.c %D%/sf_round.c \
+	%D%/sf_scalbln.c %D%/sf_trunc.c \
+	%D%/sf_exp.c %D%/sf_exp2.c %D%/sf_exp2_data.c %D%/sf_log.c %D%/sf_log_data.c \
+	%D%/sf_log2.c %D%/sf_log2_data.c %D%/sf_pow_log2_data.c %D%/sf_pow.c \
+	%D%/sinf.c %D%/cosf.c %D%/sincosf.c %D%/sincosf_data.c %D%/math_errf.c
+
+%C%_lsrc = \
+	%D%/atanl.c %D%/cosl.c %D%/sinl.c %D%/tanl.c %D%/tanhl.c %D%/frexpl.c %D%/modfl.c %D%/ceill.c %D%/fabsl.c \
+	%D%/floorl.c %D%/log1pl.c %D%/expm1l.c %D%/acosl.c %D%/asinl.c %D%/atan2l.c %D%/coshl.c %D%/sinhl.c \
+	%D%/expl.c %D%/ldexpl.c %D%/logl.c %D%/log10l.c %D%/powl.c %D%/sqrtl.c %D%/fmodl.c %D%/hypotl.c \
+	%D%/copysignl.c %D%/nanl.c %D%/ilogbl.c %D%/asinhl.c %D%/cbrtl.c %D%/nextafterl.c %D%/rintl.c \
+	%D%/scalbnl.c %D%/exp2l.c %D%/scalblnl.c %D%/tgammal.c %D%/nearbyintl.c %D%/lrintl.c %D%/llrintl.c \
+	%D%/roundl.c %D%/lroundl.c %D%/llroundl.c %D%/truncl.c %D%/remquol.c %D%/fdiml.c %D%/fmaxl.c %D%/fminl.c \
+	%D%/fmal.c %D%/acoshl.c %D%/atanhl.c %D%/remainderl.c %D%/lgammal.c %D%/erfl.c %D%/erfcl.c \
+	%D%/logbl.c %D%/nexttowardf.c %D%/nexttoward.c %D%/nexttowardl.c %D%/log2l.c \
+	%D%/sl_finite.c
+
+libm_a_CFLAGS_%C% = -fbuiltin -fno-math-errno
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc)
+if HAVE_LONG_DOUBLE
+libm_a_SOURCES += $(%C%_lsrc)
+endif # HAVE_LONG_DOUBLE
+
 LIBM_CHEWOUT_FILES += \
 	%D%/s_cbrt.def %D%/s_copysign.def %D%/s_exp10.def %D%/s_expm1.def %D%/s_ilogb.def \
 	%D%/s_infinity.def %D%/s_isnan.def %D%/s_log1p.def %D%/s_modf.def \
diff --git a/newlib/libm/complex/Makefile.am b/newlib/libm/complex/Makefile.am
deleted file mode 100644
index 49c1e6b1638a..000000000000
--- a/newlib/libm/complex/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common -I$(srcdir)/ $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src = cabs.c cacos.c cacosh.c carg.c casin.c casinh.c \
-      catan.c catanh.c ccos.c ccosh.c cephes_subr.c \
-      cexp.c cimag.c  clog.c clog10.c conj.c  \
-      cpow.c cproj.c  creal.c  \
-      csin.c csinh.c csqrt.c ctan.c ctanh.c
-
-lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c \
-       clogl.c csqrtl.c cargl.c cprojl.c cexpl.c \
-       cephes_subrl.c cacosl.c ccosl.c casinl.c \
-       catanhl.c conjl.c cpowl.c ctanhl.c ctanl.c \
-       casinhl.c csinhl.c csinl.c catanl.c
-
-fsrc =	cabsf.c casinf.c ccosf.c cimagf.c cprojf.c  \
-        csqrtf.c cacosf.c casinhf.c ccoshf.c clogf.c clog10f.c \
-        crealf.c ctanf.c cacoshf.c catanf.c   \
-        cephes_subrf.c conjf.c csinf.c ctanhf.c \
-        cargf.c catanhf.c cexpf.c cpowf.c csinhf.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc) $(lsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/complex.h $(srcdir)/cephes_subr.h $(srcdir)/cephes_subrf.h  $(srcdir)/cephes_subrl.h
diff --git a/newlib/libm/complex/Makefile.inc b/newlib/libm/complex/Makefile.inc
index 94288082ea32..88a460910d36 100644
--- a/newlib/libm/complex/Makefile.inc
+++ b/newlib/libm/complex/Makefile.inc
@@ -1,3 +1,26 @@
+%C%_src = \
+	%D%/cabs.c %D%/cacos.c %D%/cacosh.c %D%/carg.c %D%/casin.c %D%/casinh.c \
+	%D%/catan.c %D%/catanh.c %D%/ccos.c %D%/ccosh.c %D%/cephes_subr.c \
+	%D%/cexp.c %D%/cimag.c %D%/clog.c %D%/clog10.c %D%/conj.c \
+	%D%/cpow.c %D%/cproj.c %D%/creal.c \
+	%D%/csin.c %D%/csinh.c %D%/csqrt.c %D%/ctan.c %D%/ctanh.c
+
+%C%_lsrc = \
+	%D%/cabsl.c %D%/creall.c %D%/cimagl.c %D%/ccoshl.c %D%/cacoshl.c \
+	%D%/clogl.c %D%/csqrtl.c %D%/cargl.c %D%/cprojl.c %D%/cexpl.c \
+	%D%/cephes_subrl.c %D%/cacosl.c %D%/ccosl.c %D%/casinl.c \
+	%D%/catanhl.c %D%/conjl.c %D%/cpowl.c %D%/ctanhl.c %D%/ctanl.c \
+	%D%/casinhl.c %D%/csinhl.c %D%/csinl.c %D%/catanl.c
+
+%C%_fsrc = \
+	%D%/cabsf.c %D%/casinf.c %D%/ccosf.c %D%/cimagf.c %D%/cprojf.c \
+	%D%/csqrtf.c %D%/cacosf.c %D%/casinhf.c %D%/ccoshf.c %D%/clogf.c %D%/clog10f.c \
+	%D%/crealf.c %D%/ctanf.c %D%/cacoshf.c %D%/catanf.c \
+	%D%/cephes_subrf.c %D%/conjf.c %D%/csinf.c %D%/ctanhf.c \
+	%D%/cargf.c %D%/catanhf.c %D%/cexpf.c %D%/cpowf.c %D%/csinhf.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc) $(%C%_lsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/cabs.def %D%/cacos.def %D%/cacosh.def %D%/carg.def \
 	%D%/casin.def %D%/casinh.def %D%/catan.def %D%/catanh.def \
diff --git a/newlib/libm/fenv/Makefile.am b/newlib/libm/fenv/Makefile.am
deleted file mode 100644
index ccd40c1a8134..000000000000
--- a/newlib/libm/fenv/Makefile.am
+++ /dev/null
@@ -1,15 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src =	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/fenv.h
diff --git a/newlib/libm/fenv/Makefile.inc b/newlib/libm/fenv/Makefile.inc
index 0399638ad603..a9585d9bbac6 100644
--- a/newlib/libm/fenv/Makefile.inc
+++ b/newlib/libm/fenv/Makefile.inc
@@ -1,3 +1,10 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/feclearexcept.def %D%/fegetenv.def \
 	%D%/fegetexceptflag.def %D%/fegetround.def %D%/feholdexcept.def \
diff --git a/newlib/libm/machine/aarch64/Makefile.am b/newlib/libm/machine/aarch64/Makefile.am
deleted file mode 100644
index 96e782f4a341..000000000000
--- a/newlib/libm/machine/aarch64/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	e_sqrt.c \
-	ef_sqrt.c \
-	s_ceil.c \
-	s_fabs.c \
-	s_floor.c \
-	s_fma.c \
-	s_fmax.c \
-	s_fmin.c \
-	s_llrint.c \
-	s_llround.c \
-	s_lrint.c \
-	s_lround.c \
-	s_nearbyint.c \
-	s_rint.c \
-	s_round.c \
-	s_trunc.c \
-	sf_ceil.c \
-	sf_fabs.c \
-	sf_floor.c \
-	sf_fma.c \
-	sf_fmax.c \
-	sf_fmin.c \
-	sf_llrint.c \
-	sf_llround.c \
-	sf_lrint.c \
-	sf_lround.c \
-	sf_nearbyint.c \
-	sf_rint.c \
-	sf_round.c \
-	sf_trunc.c \
-	fenv.c \
-	feclearexcept.c \
-	fegetenv.c \
-	fegetexceptflag.c \
-	fegetround.c \
-	feholdexcept.c \
-	feraiseexcept.c \
-	fesetenv.c \
-	fesetexceptflag.c \
-	fesetround.c \
-	fetestexcept.c \
-	feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/aarch64/Makefile.inc b/newlib/libm/machine/aarch64/Makefile.inc
new file mode 100644
index 000000000000..478aaeed8b05
--- /dev/null
+++ b/newlib/libm/machine/aarch64/Makefile.inc
@@ -0,0 +1,45 @@
+%C%_src = \
+	%D%/e_sqrt.c \
+	%D%/ef_sqrt.c \
+	%D%/s_ceil.c \
+	%D%/s_fabs.c \
+	%D%/s_floor.c \
+	%D%/s_fma.c \
+	%D%/s_fmax.c \
+	%D%/s_fmin.c \
+	%D%/s_llrint.c \
+	%D%/s_llround.c \
+	%D%/s_lrint.c \
+	%D%/s_lround.c \
+	%D%/s_nearbyint.c \
+	%D%/s_rint.c \
+	%D%/s_round.c \
+	%D%/s_trunc.c \
+	%D%/sf_ceil.c \
+	%D%/sf_fabs.c \
+	%D%/sf_floor.c \
+	%D%/sf_fma.c \
+	%D%/sf_fmax.c \
+	%D%/sf_fmin.c \
+	%D%/sf_llrint.c \
+	%D%/sf_llround.c \
+	%D%/sf_lrint.c \
+	%D%/sf_lround.c \
+	%D%/sf_nearbyint.c \
+	%D%/sf_rint.c \
+	%D%/sf_round.c \
+	%D%/sf_trunc.c \
+	%D%/fenv.c \
+	%D%/feclearexcept.c \
+	%D%/fegetenv.c \
+	%D%/fegetexceptflag.c \
+	%D%/fegetround.c \
+	%D%/feholdexcept.c \
+	%D%/feraiseexcept.c \
+	%D%/fesetenv.c \
+	%D%/fesetexceptflag.c \
+	%D%/fesetround.c \
+	%D%/fetestexcept.c \
+	%D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/arm/Makefile.am b/newlib/libm/machine/arm/Makefile.am
deleted file mode 100644
index d8842f91705b..000000000000
--- a/newlib/libm/machine/arm/Makefile.am
+++ /dev/null
@@ -1,41 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	e_sqrt.c \
-	ef_sqrt.c \
-	s_ceil.c \
-	s_floor.c \
-	s_fma_arm.c \
-	s_nearbyint.c \
-	s_rint.c \
-	s_round.c \
-	s_trunc.c \
-	sf_ceil.c \
-	sf_floor.c \
-	sf_fma_arm.c \
-	sf_nearbyint.c \
-	sf_rint.c \
-	sf_round.c \
-	sf_trunc.c \
-	feclearexcept.c \
-	fe_dfl_env.c\
-	fegetenv.c \
-	fegetexceptflag.c \
-	fegetround.c \
-	feholdexcept.c \
-	fegetexcept.c \
-	feraiseexcept.c \
-	fesetenv.c \
-	fesetexceptflag.c \
-	fesetround.c \
-	fetestexcept.c \
-	feupdateenv.c \
-	feenableexcept.c \
-	fedisableexcept.c
-
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/arm/Makefile.inc b/newlib/libm/machine/arm/Makefile.inc
new file mode 100644
index 000000000000..988e2340006c
--- /dev/null
+++ b/newlib/libm/machine/arm/Makefile.inc
@@ -0,0 +1,34 @@
+%C%_src = \
+	%D%/e_sqrt.c \
+	%D%/ef_sqrt.c \
+	%D%/s_ceil.c \
+	%D%/s_floor.c \
+	%D%/s_fma_arm.c \
+	%D%/s_nearbyint.c \
+	%D%/s_rint.c \
+	%D%/s_round.c \
+	%D%/s_trunc.c \
+	%D%/sf_ceil.c \
+	%D%/sf_floor.c \
+	%D%/sf_fma_arm.c \
+	%D%/sf_nearbyint.c \
+	%D%/sf_rint.c \
+	%D%/sf_round.c \
+	%D%/sf_trunc.c \
+	%D%/feclearexcept.c \
+	%D%/fe_dfl_env.c\
+	%D%/fegetenv.c \
+	%D%/fegetexceptflag.c \
+	%D%/fegetround.c \
+	%D%/feholdexcept.c \
+	%D%/fegetexcept.c \
+	%D%/feraiseexcept.c \
+	%D%/fesetenv.c \
+	%D%/fesetexceptflag.c \
+	%D%/fesetround.c \
+	%D%/fetestexcept.c \
+	%D%/feupdateenv.c \
+	%D%/feenableexcept.c \
+	%D%/fedisableexcept.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/i386/Makefile.am b/newlib/libm/machine/i386/Makefile.am
deleted file mode 100644
index 4b9781883899..000000000000
--- a/newlib/libm/machine/i386/Makefile.am
+++ /dev/null
@@ -1,21 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-AM_CCASFLAGS = $(AM_CPPFLAGS)
-
-LIB_SOURCES = \
-	f_atan2.S f_atan2f.S f_exp.c f_expf.c \
-	f_frexp.S f_frexpf.S f_llrint.c f_llrintf.c f_llrintl.c \
-	f_log.S f_logf.S f_log10.S f_log10f.S \
-	f_ldexp.S f_ldexpf.S f_lrint.c f_lrintf.c f_lrintl.c \
-	f_pow.c f_powf.c f_rint.c f_rintf.c f_rintl.c \
-	f_tan.S f_tanf.S f_math.h i386mach.h \
-	fenv.c feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
-lib_a_CCASFLAGS = $(AM_CCASFLAGS)
diff --git a/newlib/libm/machine/i386/Makefile.inc b/newlib/libm/machine/i386/Makefile.inc
new file mode 100644
index 000000000000..420d25fbd4df
--- /dev/null
+++ b/newlib/libm/machine/i386/Makefile.inc
@@ -0,0 +1,12 @@
+%C%_src = \
+	%D%/f_atan2.S %D%/f_atan2f.S %D%/f_exp.c %D%/f_expf.c \
+	%D%/f_frexp.S %D%/f_frexpf.S %D%/f_llrint.c %D%/f_llrintf.c %D%/f_llrintl.c \
+	%D%/f_log.S %D%/f_logf.S %D%/f_log10.S %D%/f_log10f.S \
+	%D%/f_ldexp.S %D%/f_ldexpf.S %D%/f_lrint.c %D%/f_lrintf.c %D%/f_lrintl.c \
+	%D%/f_pow.c %D%/f_powf.c %D%/f_rint.c %D%/f_rintf.c %D%/f_rintl.c \
+	%D%/f_tan.S %D%/f_tanf.S %D%/f_math.h %D%/i386mach.h \
+	%D%/fenv.c %D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/mips/Makefile.am b/newlib/libm/machine/mips/Makefile.am
deleted file mode 100644
index e72cd764aaa5..000000000000
--- a/newlib/libm/machine/mips/Makefile.am
+++ /dev/null
@@ -1,22 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-lib_a_LIBADD = \
-	lib_a-fenv.$(OBJEXT)
-
-# fenv.c cannot be compiled as mips16 since it uses the cfc1 instruction
-lib_a-fenv.o: fenv.c
-	$(COMPILE) -mno-mips16 -c -o $@ `test -f 'fenv.c' || echo '$(srcdir)/'`fenv.c
-
-lib_a-fenv.obj: fenv.c
-	$(COMPILE) -mno-mips16 -c -o $@ `if test -f 'fenv.c'; then $(CYGPATH_W) 'fenv.c'; else $(CYGPATH_W) '$(srcdir)/fenv.c'; fi`
diff --git a/newlib/libm/machine/mips/Makefile.inc b/newlib/libm/machine/mips/Makefile.inc
new file mode 100644
index 000000000000..febae0d070d0
--- /dev/null
+++ b/newlib/libm/machine/mips/Makefile.inc
@@ -0,0 +1,10 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/fenv.c
+
+libm_a_SOURCES += $(%C%_src)
+
+# fenv.c cannot be compiled as mips16 since it uses the cfc1 instruction.
+libm_a_CFLAGS_%C%_fenv.c = -mno-mips16
diff --git a/newlib/libm/machine/nds32/Makefile.am b/newlib/libm/machine/nds32/Makefile.am
deleted file mode 100644
index 8810f17f9409..000000000000
--- a/newlib/libm/machine/nds32/Makefile.am
+++ /dev/null
@@ -1,17 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src =
-
-if HAS_NDS32_FPU_SP
-src += wf_sqrt.S
-endif
-
-if HAS_NDS32_FPU_DP
-src += w_sqrt.S
-endif
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/nds32/Makefile.inc b/newlib/libm/machine/nds32/Makefile.inc
new file mode 100644
index 000000000000..e404baac2742
--- /dev/null
+++ b/newlib/libm/machine/nds32/Makefile.inc
@@ -0,0 +1,10 @@
+%C%_src =
+if HAS_NDS32_FPU_SP
+%C%_src += %D%/wf_sqrt.S
+endif
+
+if HAS_NDS32_FPU_DP
+%C%_src += %D%/w_sqrt.S
+endif
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/powerpc/Makefile.am b/newlib/libm/machine/powerpc/Makefile.am
deleted file mode 100644
index 9a10297992ea..000000000000
--- a/newlib/libm/machine/powerpc/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c fenv.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/powerpc/Makefile.inc b/newlib/libm/machine/powerpc/Makefile.inc
new file mode 100644
index 000000000000..79fc26103092
--- /dev/null
+++ b/newlib/libm/machine/powerpc/Makefile.inc
@@ -0,0 +1,6 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/fenv.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/pru/Makefile.am b/newlib/libm/machine/pru/Makefile.am
deleted file mode 100644
index b530c97f84f2..000000000000
--- a/newlib/libm/machine/pru/Makefile.am
+++ /dev/null
@@ -1,11 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	fpclassify.c fpclassifyf.c isfinite.c isfinitef.c isinf.c \
-	isinff.c isnan.c isnanf.c isnormal.c isnormalf.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/pru/Makefile.inc b/newlib/libm/machine/pru/Makefile.inc
new file mode 100644
index 000000000000..e711d0872821
--- /dev/null
+++ b/newlib/libm/machine/pru/Makefile.inc
@@ -0,0 +1,5 @@
+%C%_src = \
+	%D%/fpclassify.c %D%/fpclassifyf.c %D%/isfinite.c %D%/isfinitef.c %D%/isinf.c \
+	%D%/isinff.c %D%/isnan.c %D%/isnanf.c %D%/isnormal.c %D%/isnormalf.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/riscv/Makefile.am b/newlib/libm/machine/riscv/Makefile.am
deleted file mode 100644
index 1d228a868a3a..000000000000
--- a/newlib/libm/machine/riscv/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	s_fma.c e_sqrt.c sf_fma.c ef_sqrt.c \
-	s_fmax.c s_fmin.c sf_fmax.c sf_fmin.c \
-	s_fabs.c sf_fabs.c \
-	s_fpclassify.c sf_fpclassify.c \
-	s_finite.c sf_finite.c \
-	s_isinf.c sf_isinf.c \
-	s_isnan.c sf_isnan.c \
-	s_copysign.c sf_copysign.c \
-	s_lrint.c sf_lrint.c \
-	s_lround.c sf_lround.c \
-	s_llrint.c sf_llrint.c \
-	s_llround.c sf_llround.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/riscv/Makefile.inc b/newlib/libm/machine/riscv/Makefile.inc
new file mode 100644
index 000000000000..9ce71e7be622
--- /dev/null
+++ b/newlib/libm/machine/riscv/Makefile.inc
@@ -0,0 +1,18 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/s_fma.c %D%/e_sqrt.c %D%/sf_fma.c %D%/ef_sqrt.c \
+	%D%/s_fmax.c %D%/s_fmin.c %D%/sf_fmax.c %D%/sf_fmin.c \
+	%D%/s_fabs.c %D%/sf_fabs.c \
+	%D%/s_fpclassify.c %D%/sf_fpclassify.c \
+	%D%/s_finite.c %D%/sf_finite.c \
+	%D%/s_isinf.c %D%/sf_isinf.c \
+	%D%/s_isnan.c %D%/sf_isnan.c \
+	%D%/s_copysign.c %D%/sf_copysign.c \
+	%D%/s_lrint.c %D%/sf_lrint.c \
+	%D%/s_lround.c %D%/sf_lround.c \
+	%D%/s_llrint.c %D%/sf_llrint.c \
+	%D%/s_llround.c %D%/sf_llround.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/sparc/Makefile.am b/newlib/libm/machine/sparc/Makefile.am
deleted file mode 100644
index d0addf6702a3..000000000000
--- a/newlib/libm/machine/sparc/Makefile.am
+++ /dev/null
@@ -1,13 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c  fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	fenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/sparc/Makefile.inc b/newlib/libm/machine/sparc/Makefile.inc
new file mode 100644
index 000000000000..df510a4da9d2
--- /dev/null
+++ b/newlib/libm/machine/sparc/Makefile.inc
@@ -0,0 +1,7 @@
+%C%_src = \
+	%D%/feclearexcept.c  %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/fenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/spu/Makefile.am b/newlib/libm/machine/spu/Makefile.am
deleted file mode 100644
index c1c6b4ac0c9a..000000000000
--- a/newlib/libm/machine/spu/Makefile.am
+++ /dev/null
@@ -1,31 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fe_dfl_env.c fegetenv.c fegetexceptflag.c \
-	fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c \
-	fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c \
-	llrint.c llrintf.c llround.c llroundf.c log2.c log2f.c s_asinh.c \
-	s_atan.c s_cbrt.c s_ceil.c s_copysign.c s_cos.c s_erf.c s_expm1.c \
-	s_fabs.c sf_asinh.c sf_atan.c sf_cbrt.c sf_ceil.c sf_copysign.c \
-	sf_cos.c s_fdim.c sf_erf.c sf_expm1.c sf_fabs.c sf_fdim.c \
-	sf_finite.c sf_floor.c sf_fma.c sf_fmax.c sf_fmin.c \
-	sf_fpclassify.c sf_frexp.c sf_ilogb.c sf_isinf.c sf_isinff.c \
-	sf_isnan.c sf_isnanf.c sf_ldexp.c sf_log1p.c sf_logb.c s_floor.c \
-	sf_lrint.c sf_lround.c s_fma.c s_fmax.c s_fmin.c sf_nan.c \
-	sf_nearbyint.c sf_nextafter.c sf_remquo.c s_frexp.c sf_rint.c \
-	sf_round.c sf_scalbn.c sf_sin.c sf_tan.c sf_tanh.c sf_trunc.c \
-	s_ilogb.c s_isnan.c s_ldexp.c s_log1p.c s_lrint.c s_lround.c \
-	s_nearbyint.c s_nextafter.c s_remquo.c s_rint.c s_round.c \
-	s_scalbn.c s_sin.c s_tan.c s_tanh.c s_trunc.c w_acos.c w_acosh.c \
-	w_asin.c w_atan2.c w_atanh.c w_cosh.c w_exp2.c w_exp.c wf_acos.c \
-	wf_acosh.c wf_asin.c wf_atan2.c wf_atanh.c wf_cosh.c wf_exp2.c \
-	wf_exp.c wf_fmod.c wf_hypot.c wf_lgamma.c wf_log10.c wf_log.c \
-	w_fmod.c wf_pow.c wf_remainder.c wf_sincos.c wf_sinh.c wf_sqrt.c \
-	wf_tgamma.c w_hypot.c w_lgamma.c w_log10.c w_log.c w_pow.c \
-	w_remainder.c w_sincos.c w_sinh.c w_sqrt.c w_tgamma.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/spu/Makefile.inc b/newlib/libm/machine/spu/Makefile.inc
new file mode 100644
index 000000000000..8dec3dedc536
--- /dev/null
+++ b/newlib/libm/machine/spu/Makefile.inc
@@ -0,0 +1,25 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fe_dfl_env.c %D%/fegetenv.c %D%/fegetexceptflag.c \
+	%D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fesetenv.c \
+	%D%/fesetexceptflag.c %D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c \
+	%D%/llrint.c %D%/llrintf.c %D%/llround.c %D%/llroundf.c %D%/log2.c %D%/log2f.c %D%/s_asinh.c \
+	%D%/s_atan.c %D%/s_cbrt.c %D%/s_ceil.c %D%/s_copysign.c %D%/s_cos.c %D%/s_erf.c %D%/s_expm1.c \
+	%D%/s_fabs.c %D%/sf_asinh.c %D%/sf_atan.c %D%/sf_cbrt.c %D%/sf_ceil.c %D%/sf_copysign.c \
+	%D%/sf_cos.c %D%/s_fdim.c %D%/sf_erf.c %D%/sf_expm1.c %D%/sf_fabs.c %D%/sf_fdim.c \
+	%D%/sf_finite.c %D%/sf_floor.c %D%/sf_fma.c %D%/sf_fmax.c %D%/sf_fmin.c \
+	%D%/sf_fpclassify.c %D%/sf_frexp.c %D%/sf_ilogb.c %D%/sf_isinf.c %D%/sf_isinff.c \
+	%D%/sf_isnan.c %D%/sf_isnanf.c %D%/sf_ldexp.c %D%/sf_log1p.c %D%/sf_logb.c %D%/s_floor.c \
+	%D%/sf_lrint.c %D%/sf_lround.c %D%/s_fma.c %D%/s_fmax.c %D%/s_fmin.c %D%/sf_nan.c \
+	%D%/sf_nearbyint.c %D%/sf_nextafter.c %D%/sf_remquo.c %D%/s_frexp.c %D%/sf_rint.c \
+	%D%/sf_round.c %D%/sf_scalbn.c %D%/sf_sin.c %D%/sf_tan.c %D%/sf_tanh.c %D%/sf_trunc.c \
+	%D%/s_ilogb.c %D%/s_isnan.c %D%/s_ldexp.c %D%/s_log1p.c %D%/s_lrint.c %D%/s_lround.c \
+	%D%/s_nearbyint.c %D%/s_nextafter.c %D%/s_remquo.c %D%/s_rint.c %D%/s_round.c \
+	%D%/s_scalbn.c %D%/s_sin.c %D%/s_tan.c %D%/s_tanh.c %D%/s_trunc.c %D%/w_acos.c %D%/w_acosh.c \
+	%D%/w_asin.c %D%/w_atan2.c %D%/w_atanh.c %D%/w_cosh.c %D%/w_exp2.c %D%/w_exp.c %D%/wf_acos.c \
+	%D%/wf_acosh.c %D%/wf_asin.c %D%/wf_atan2.c %D%/wf_atanh.c %D%/wf_cosh.c %D%/wf_exp2.c \
+	%D%/wf_exp.c %D%/wf_fmod.c %D%/wf_hypot.c %D%/wf_lgamma.c %D%/wf_log10.c %D%/wf_log.c \
+	%D%/w_fmod.c %D%/wf_pow.c %D%/wf_remainder.c %D%/wf_sincos.c %D%/wf_sinh.c %D%/wf_sqrt.c \
+	%D%/wf_tgamma.c %D%/w_hypot.c %D%/w_lgamma.c %D%/w_log10.c %D%/w_log.c %D%/w_pow.c \
+	%D%/w_remainder.c %D%/w_sincos.c %D%/w_sinh.c %D%/w_sqrt.c %D%/w_tgamma.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/x86_64/Makefile.am b/newlib/libm/machine/x86_64/Makefile.am
deleted file mode 100644
index 5815dc91e6af..000000000000
--- a/newlib/libm/machine/x86_64/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I $(abs_newlib_basedir)/libm/common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-LIB_SOURCES = \
-	feclearexcept.c fegetenv.c fegetexceptflag.c fegetround.c \
-	feholdexcept.c fenv.c feraiseexcept.c fesetenv.c fesetexceptflag.c \
-	fesetround.c fetestexcept.c feupdateenv.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(LIB_SOURCES)
-lib_a_CFLAGS = $(AM_CFLAGS)
diff --git a/newlib/libm/machine/x86_64/Makefile.inc b/newlib/libm/machine/x86_64/Makefile.inc
new file mode 100644
index 000000000000..48a1f71b276f
--- /dev/null
+++ b/newlib/libm/machine/x86_64/Makefile.inc
@@ -0,0 +1,6 @@
+%C%_src = \
+	%D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexceptflag.c %D%/fegetround.c \
+	%D%/feholdexcept.c %D%/fenv.c %D%/feraiseexcept.c %D%/fesetenv.c %D%/fesetexceptflag.c \
+	%D%/fesetround.c %D%/fetestexcept.c %D%/feupdateenv.c
+
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/math/Makefile.am b/newlib/libm/math/Makefile.am
deleted file mode 100644
index 2baefb069e51..000000000000
--- a/newlib/libm/math/Makefile.am
+++ /dev/null
@@ -1,60 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src = 	k_standard.c k_rem_pio2.c \
-	k_cos.c k_sin.c k_tan.c \
-	e_acos.c e_acosh.c e_asin.c e_atan2.c \
-	e_atanh.c e_cosh.c e_exp.c e_fmod.c \
-	e_tgamma.c e_hypot.c e_j0.c \
-	e_j1.c e_jn.c er_lgamma.c \
-	e_log.c e_log10.c e_pow.c e_rem_pio2.c e_remainder.c \
-	e_scalb.c e_sinh.c e_sqrt.c \
-	w_acos.c w_acosh.c w_asin.c w_atan2.c \
-	w_atanh.c w_cosh.c w_exp.c w_fmod.c \
-	w_gamma.c wr_gamma.c w_hypot.c w_j0.c \
-	w_j1.c w_jn.c w_lgamma.c wr_lgamma.c \
-	w_log.c w_log10.c w_pow.c w_remainder.c \
-	w_scalb.c w_sinh.c w_sqrt.c \
-	w_sincos.c \
-	w_drem.c \
-	s_asinh.c s_atan.c s_ceil.c \
-	s_cos.c s_erf.c s_fabs.c s_floor.c \
-	s_frexp.c s_ldexp.c \
-	s_signif.c s_sin.c \
-	s_tan.c s_tanh.c \
-	w_exp2.c w_tgamma.c
-
-fsrc =	kf_rem_pio2.c \
-	kf_cos.c kf_sin.c kf_tan.c \
-	ef_acos.c ef_acosh.c ef_asin.c ef_atan2.c \
-	ef_atanh.c ef_cosh.c ef_exp.c ef_fmod.c \
-	ef_tgamma.c ef_hypot.c ef_j0.c \
-	ef_j1.c ef_jn.c erf_lgamma.c \
-	ef_log.c ef_log10.c ef_pow.c ef_rem_pio2.c ef_remainder.c \
-	ef_scalb.c ef_sinh.c ef_sqrt.c \
-	wf_acos.c wf_acosh.c wf_asin.c wf_atan2.c \
-	wf_atanh.c wf_cosh.c wf_exp.c wf_fmod.c \
-	wf_gamma.c wrf_gamma.c wf_hypot.c wf_j0.c \
-	wf_j1.c wf_jn.c wf_lgamma.c wrf_lgamma.c \
-	wf_log.c wf_log10.c wf_pow.c wf_remainder.c \
-	wf_scalb.c wf_sinh.c wf_sqrt.c \
-	wf_sincos.c \
-	wf_drem.c \
-	sf_asinh.c sf_atan.c sf_ceil.c \
-	sf_cos.c sf_erf.c sf_fabs.c sf_floor.c \
-	sf_frexp.c sf_ldexp.c \
-	sf_signif.c sf_sin.c \
-	sf_tan.c sf_tanh.c \
-	wf_exp2.c wf_tgamma.c \
-	wf_log2.c
-
-lsrc = el_hypot.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc) $(lsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h $(srcdir)/../common/fdlibm.h
diff --git a/newlib/libm/math/Makefile.inc b/newlib/libm/math/Makefile.inc
index bc3205e0b156..1b61d6dd30d5 100644
--- a/newlib/libm/math/Makefile.inc
+++ b/newlib/libm/math/Makefile.inc
@@ -1,3 +1,56 @@
+%C%_src = \
+	%D%/k_standard.c %D%/k_rem_pio2.c \
+	%D%/k_cos.c %D%/k_sin.c %D%/k_tan.c \
+	%D%/e_acos.c %D%/e_acosh.c %D%/e_asin.c %D%/e_atan2.c \
+	%D%/e_atanh.c %D%/e_cosh.c %D%/e_exp.c %D%/e_fmod.c \
+	%D%/e_tgamma.c %D%/e_hypot.c %D%/e_j0.c \
+	%D%/e_j1.c %D%/e_jn.c %D%/er_lgamma.c \
+	%D%/e_log.c %D%/e_log10.c %D%/e_pow.c %D%/e_rem_pio2.c %D%/e_remainder.c \
+	%D%/e_scalb.c %D%/e_sinh.c %D%/e_sqrt.c \
+	%D%/w_acos.c %D%/w_acosh.c %D%/w_asin.c %D%/w_atan2.c \
+	%D%/w_atanh.c %D%/w_cosh.c %D%/w_exp.c %D%/w_fmod.c \
+	%D%/w_gamma.c %D%/wr_gamma.c %D%/w_hypot.c %D%/w_j0.c \
+	%D%/w_j1.c %D%/w_jn.c %D%/w_lgamma.c %D%/wr_lgamma.c \
+	%D%/w_log.c %D%/w_log10.c %D%/w_pow.c %D%/w_remainder.c \
+	%D%/w_scalb.c %D%/w_sinh.c %D%/w_sqrt.c \
+	%D%/w_sincos.c \
+	%D%/w_drem.c \
+	%D%/s_asinh.c %D%/s_atan.c %D%/s_ceil.c \
+	%D%/s_cos.c %D%/s_erf.c %D%/s_fabs.c %D%/s_floor.c \
+	%D%/s_frexp.c %D%/s_ldexp.c \
+	%D%/s_signif.c %D%/s_sin.c \
+	%D%/s_tan.c %D%/s_tanh.c \
+	%D%/w_exp2.c %D%/w_tgamma.c
+
+%C%_fsrc = \
+	%D%/kf_rem_pio2.c \
+	%D%/kf_cos.c %D%/kf_sin.c %D%/kf_tan.c \
+	%D%/ef_acos.c %D%/ef_acosh.c %D%/ef_asin.c %D%/ef_atan2.c \
+	%D%/ef_atanh.c %D%/ef_cosh.c %D%/ef_exp.c %D%/ef_fmod.c \
+	%D%/ef_tgamma.c %D%/ef_hypot.c %D%/ef_j0.c \
+	%D%/ef_j1.c %D%/ef_jn.c %D%/erf_lgamma.c \
+	%D%/ef_log.c %D%/ef_log10.c %D%/ef_pow.c %D%/ef_rem_pio2.c %D%/ef_remainder.c \
+	%D%/ef_scalb.c %D%/ef_sinh.c %D%/ef_sqrt.c \
+	%D%/wf_acos.c %D%/wf_acosh.c %D%/wf_asin.c %D%/wf_atan2.c \
+	%D%/wf_atanh.c %D%/wf_cosh.c %D%/wf_exp.c %D%/wf_fmod.c \
+	%D%/wf_gamma.c %D%/wrf_gamma.c %D%/wf_hypot.c %D%/wf_j0.c \
+	%D%/wf_j1.c %D%/wf_jn.c %D%/wf_lgamma.c %D%/wrf_lgamma.c \
+	%D%/wf_log.c %D%/wf_log10.c %D%/wf_pow.c %D%/wf_remainder.c \
+	%D%/wf_scalb.c %D%/wf_sinh.c %D%/wf_sqrt.c \
+	%D%/wf_sincos.c \
+	%D%/wf_drem.c \
+	%D%/sf_asinh.c %D%/sf_atan.c %D%/sf_ceil.c \
+	%D%/sf_cos.c %D%/sf_erf.c %D%/sf_fabs.c %D%/sf_floor.c \
+	%D%/sf_frexp.c %D%/sf_ldexp.c \
+	%D%/sf_signif.c %D%/sf_sin.c \
+	%D%/sf_tan.c %D%/sf_tanh.c \
+	%D%/wf_exp2.c %D%/wf_tgamma.c \
+	%D%/wf_log2.c
+
+%C%_lsrc = %D%/el_hypot.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc) $(%C%_lsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/w_acos.def %D%/w_acosh.def %D%/w_asin.def %D%/s_asinh.def \
 	%D%/s_atan.def %D%/w_atan2.def %D%/w_atanh.def %D%/w_j0.def \
diff --git a/newlib/libm/mathfp/Makefile.am b/newlib/libm/mathfp/Makefile.am
deleted file mode 100644
index bd77fb16de6d..000000000000
--- a/newlib/libm/mathfp/Makefile.am
+++ /dev/null
@@ -1,50 +0,0 @@
-## Process this file with automake to generate Makefile.in
-
-AM_CPPFLAGS = -I$(srcdir)/../common $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
-
-src =	s_acos.c s_frexp.c s_mathcnst.c \
-	s_cos.c s_sinh.c \
-	s_asin.c\
-	s_asine.c s_cosh.c s_ispos.c s_numtest.c s_sqrt.c \
-	s_exp.c s_ldexp.c s_pow.c s_tan.c \
-	s_atan.c \
-	s_atan2.c s_fabs.c s_log.c s_tanh.c \
-	s_log10.c s_sin.c \
-	s_floor.c s_sine.c \
-	s_sincos.c \
-	s_atangent.c s_logarithm.c \
-	s_sineh.c \
-	s_ceil.c \
-	e_acosh.c e_atanh.c e_remainder.c \
-	er_gamma.c er_lgamma.c \
-	s_erf.c e_j0.c e_j1.c w_jn.c e_hypot.c \
-	w_cabs.c w_drem.c s_asinh.c s_fmod.c \
-	e_scalb.c s_signif.c \
-	s_exp2.c s_tgamma.c
-
-fsrc =	sf_ceil.c \
-	sf_acos.c sf_frexp.c \
-	sf_cos.c sf_sinh.c \
-	sf_asine.c sf_cosh.c sf_ispos.c sf_numtest.c sf_sqrt.c \
-	sf_asin.c \
-	sf_exp.c sf_ldexp.c sf_pow.c sf_tan.c \
-	sf_atan2.c sf_fabs.c sf_tanh.c \
-	sf_atan.c sf_log10.c sf_sin.c\
-	sf_floor.c sf_sine.c \
-	sf_sincos.c \
-	sf_atangent.c sf_logarithm.c sf_sineh.c \
-	sf_log.c sf_sineh.c \
-	ef_acosh.c ef_atanh.c ef_remainder.c \
-	erf_gamma.c erf_lgamma.c \
-	sf_erf.c ef_j0.c ef_j1.c wf_jn.c ef_hypot.c \
-	wf_cabs.c wf_drem.c sf_asinh.c sf_fmod.c \
-	ef_scalb.c sf_signif.c \
-	sf_exp2.c sf_tgamma.c
-
-noinst_LIBRARIES = lib.a
-lib_a_SOURCES = $(src) $(fsrc)
-lib_a_CFLAGS = $(AM_CFLAGS)
-
-# A partial dependency list.
-
-$(lib_a_OBJECTS): $(srcdir)/../../libc/include/math.h $(srcdir)/../common/fdlibm.h
diff --git a/newlib/libm/mathfp/Makefile.inc b/newlib/libm/mathfp/Makefile.inc
index 739e41f16d0b..f1e6da83211a 100644
--- a/newlib/libm/mathfp/Makefile.inc
+++ b/newlib/libm/mathfp/Makefile.inc
@@ -1,3 +1,46 @@
+%C%_src = \
+	%D%/s_acos.c %D%/s_frexp.c %D%/s_mathcnst.c \
+	%D%/s_cos.c %D%/s_sinh.c \
+	%D%/s_asin.c\
+	%D%/s_asine.c %D%/s_cosh.c %D%/s_ispos.c %D%/s_numtest.c %D%/s_sqrt.c \
+	%D%/s_exp.c %D%/s_ldexp.c %D%/s_pow.c %D%/s_tan.c \
+	%D%/s_atan.c \
+	%D%/s_atan2.c %D%/s_fabs.c %D%/s_log.c %D%/s_tanh.c \
+	%D%/s_log10.c %D%/s_sin.c \
+	%D%/s_floor.c %D%/s_sine.c \
+	%D%/s_sincos.c \
+	%D%/s_atangent.c %D%/s_logarithm.c \
+	%D%/s_sineh.c \
+	%D%/s_ceil.c \
+	%D%/e_acosh.c %D%/e_atanh.c %D%/e_remainder.c \
+	%D%/er_gamma.c %D%/er_lgamma.c \
+	%D%/s_erf.c %D%/e_j0.c %D%/e_j1.c %D%/w_jn.c %D%/e_hypot.c \
+	%D%/w_cabs.c %D%/w_drem.c %D%/s_asinh.c %D%/s_fmod.c \
+	%D%/e_scalb.c %D%/s_signif.c \
+	%D%/s_exp2.c %D%/s_tgamma.c
+
+%C%_fsrc = \
+	%D%/sf_ceil.c \
+	%D%/sf_acos.c %D%/sf_frexp.c \
+	%D%/sf_cos.c %D%/sf_sinh.c \
+	%D%/sf_asine.c %D%/sf_cosh.c %D%/sf_ispos.c %D%/sf_numtest.c %D%/sf_sqrt.c \
+	%D%/sf_asin.c \
+	%D%/sf_exp.c %D%/sf_ldexp.c %D%/sf_pow.c %D%/sf_tan.c \
+	%D%/sf_atan2.c %D%/sf_fabs.c %D%/sf_tanh.c \
+	%D%/sf_atan.c %D%/sf_log10.c %D%/sf_sin.c\
+	%D%/sf_floor.c %D%/sf_sine.c \
+	%D%/sf_sincos.c \
+	%D%/sf_atangent.c %D%/sf_logarithm.c %D%/sf_sineh.c \
+	%D%/sf_log.c %D%/sf_sineh.c \
+	%D%/ef_acosh.c %D%/ef_atanh.c %D%/ef_remainder.c \
+	%D%/erf_gamma.c %D%/erf_lgamma.c \
+	%D%/sf_erf.c %D%/ef_j0.c %D%/ef_j1.c %D%/wf_jn.c %D%/ef_hypot.c \
+	%D%/wf_cabs.c %D%/wf_drem.c %D%/sf_asinh.c %D%/sf_fmod.c \
+	%D%/ef_scalb.c %D%/sf_signif.c \
+	%D%/sf_exp2.c %D%/sf_tgamma.c
+
+libm_a_SOURCES += $(%C%_src) $(%C%_fsrc)
+
 LIBM_CHEWOUT_FILES += \
 	%D%/e_acosh.def \
 	%D%/e_atanh.def \
-- 
2.34.1


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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-17  4:42 ` [PATCH v2] " Mike Frysinger
@ 2022-02-17 12:08   ` Corinna Vinschen
  2022-02-21 11:20   ` Corinna Vinschen
  1 sibling, 0 replies; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-17 12:08 UTC (permalink / raw)
  To: newlib

On Feb 16 23:42, Mike Frysinger wrote:
> Convert all the libm/ subdir makes into the top-level Makefile.  This
> allows us to build all of libm from the top Makefile without using any
> recursive make calls.  This is faster and avoids the funky lib.a logic
> where we unpack subdir archives to repack into a single libm.a.  The
> machine override logic is maintained though by way of Makefile include
> ordering, and source file accumulation in libm_a_SOURCES.
> 
> One thing to note is that this will require GNU Make because of:
> 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
> This was the only way I could find to supporting per-dir compiler
> settings, and I couldn't find a POSIX compatible way of transforming
> the variable content.  I don't think this is a big deal as other
> Makefiles in the tree are using GNU Make-specific syntax, but I call
> this out as it's the only one so far in the new automake code that
> I've been writing.
> 
> Automake doesn't provide precise control over the output object names
> (by design).  This is fine by default as we get consistent names in all
> the subdirs: libm_a-<source>.o.  But this relies on using the same set
> of compiler flags for all objects.  We currently compile libm/common/
> with different optimizations than the rest.
> 
> If we want to compile objects differently, we can create an intermediate
> archive with the subset of objects with unique flags, and then add those
> objects to the main archive.  But Automake will use a different prefix
> for the objects, and thus we can't rely on ordering to override.
> 
> But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
> on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
> since $@ contains /, Automake complains it's an invalid name.  While
> GNU Make supports this, it's a POSIX extension, so Automake flags it.
> Using $(subst) avoids the Automake warning to get a POSIX compliant
> name, albeit with a GNU Make extension.
> ---
> v2
> - rebased onto latest tree
> - fixed a parallel build issue with generated newlib headers & libm objects

Ok, do your thing.


Thx,
Corinna


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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-17  4:42 ` [PATCH v2] " Mike Frysinger
  2022-02-17 12:08   ` Corinna Vinschen
@ 2022-02-21 11:20   ` Corinna Vinschen
  2022-02-21 18:00     ` Mike Frysinger
  2022-02-21 20:43     ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
  1 sibling, 2 replies; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-21 11:20 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: newlib

Hi Mike,

On Feb 16 23:42, Mike Frysinger wrote:
> Convert all the libm/ subdir makes into the top-level Makefile.  This
> allows us to build all of libm from the top Makefile without using any
> recursive make calls.  This is faster and avoids the funky lib.a logic
> where we unpack subdir archives to repack into a single libm.a.  The
> machine override logic is maintained though by way of Makefile include
> ordering, and source file accumulation in libm_a_SOURCES.
> 
> One thing to note is that this will require GNU Make because of:
> 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
> This was the only way I could find to supporting per-dir compiler
> settings, and I couldn't find a POSIX compatible way of transforming
> the variable content.  I don't think this is a big deal as other
> Makefiles in the tree are using GNU Make-specific syntax, but I call
> this out as it's the only one so far in the new automake code that
> I've been writing.
> 
> Automake doesn't provide precise control over the output object names
> (by design).  This is fine by default as we get consistent names in all
> the subdirs: libm_a-<source>.o.  But this relies on using the same set
> of compiler flags for all objects.  We currently compile libm/common/
> with different optimizations than the rest.
> 
> If we want to compile objects differently, we can create an intermediate
> archive with the subset of objects with unique flags, and then add those
> objects to the main archive.  But Automake will use a different prefix
> for the objects, and thus we can't rely on ordering to override.
> 
> But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
> on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
> since $@ contains /, Automake complains it's an invalid name.  While
> GNU Make supports this, it's a POSIX extension, so Automake flags it.
> Using $(subst) avoids the Automake warning to get a POSIX compliant
> name, albeit with a GNU Make extension.
> ---
> v2
> - rebased onto latest tree
> - fixed a parallel build issue with generated newlib headers & libm objects

This patch breaks Cygwin.  Unfortunately I didn't try to build myself,
but only inspected the patch, so I didn't realize the problem.

First of all, Cygwin takes libm.a from newlib/libm/, not from newlib.
This is easily fixable.

However, even after fixing this, we get a link stage error for *all*
fenv functions:

ld: x86_64-pc-cygwin/newlib/libm.a(libm_a-fenv.o): in function `fegetenv':
  newlib/libm/machine/x86_64/../shared_x86/fenv.c:160:
    multiple definition of `fegetenv';
x86_64-pc-cygwin/newlib/libm.a(libm_a-fegetenv.o):
  newlib/libm/fenv/fegetenv.c:65:
    first defined here

For some reason, libm.a contains both definitions of the fenv functions,
the x86_64 definitions from newlib/libm/machine/shared_x86, as well as
the fallback definitions from newlib/libm/fenv.

Can you please take a look?


Thanks,
Corinna


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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 11:20   ` Corinna Vinschen
@ 2022-02-21 18:00     ` Mike Frysinger
  2022-02-21 18:04       ` Jon Turney
  2022-02-21 18:28       ` Mike Frysinger
  2022-02-21 20:43     ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
  1 sibling, 2 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 18:00 UTC (permalink / raw)
  To: newlib

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

On 21 Feb 2022 12:20, Corinna Vinschen wrote:
> On Feb 16 23:42, Mike Frysinger wrote:
> > Convert all the libm/ subdir makes into the top-level Makefile.  This
> > allows us to build all of libm from the top Makefile without using any
> > recursive make calls.  This is faster and avoids the funky lib.a logic
> > where we unpack subdir archives to repack into a single libm.a.  The
> > machine override logic is maintained though by way of Makefile include
> > ordering, and source file accumulation in libm_a_SOURCES.
> > 
> > One thing to note is that this will require GNU Make because of:
> > 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
> > This was the only way I could find to supporting per-dir compiler
> > settings, and I couldn't find a POSIX compatible way of transforming
> > the variable content.  I don't think this is a big deal as other
> > Makefiles in the tree are using GNU Make-specific syntax, but I call
> > this out as it's the only one so far in the new automake code that
> > I've been writing.
> > 
> > Automake doesn't provide precise control over the output object names
> > (by design).  This is fine by default as we get consistent names in all
> > the subdirs: libm_a-<source>.o.  But this relies on using the same set
> > of compiler flags for all objects.  We currently compile libm/common/
> > with different optimizations than the rest.
> > 
> > If we want to compile objects differently, we can create an intermediate
> > archive with the subset of objects with unique flags, and then add those
> > objects to the main archive.  But Automake will use a different prefix
> > for the objects, and thus we can't rely on ordering to override.
> > 
> > But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
> > on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
> > since $@ contains /, Automake complains it's an invalid name.  While
> > GNU Make supports this, it's a POSIX extension, so Automake flags it.
> > Using $(subst) avoids the Automake warning to get a POSIX compliant
> > name, albeit with a GNU Make extension.
> > ---
> > v2
> > - rebased onto latest tree
> > - fixed a parallel build issue with generated newlib headers & libm objects
> 
> This patch breaks Cygwin.  Unfortunately I didn't try to build myself,
> but only inspected the patch, so I didn't realize the problem.
> 
> First of all, Cygwin takes libm.a from newlib/libm/, not from newlib.
> This is easily fixable.
> 
> However, even after fixing this, we get a link stage error for *all*
> fenv functions:
> 
> ld: x86_64-pc-cygwin/newlib/libm.a(libm_a-fenv.o): in function `fegetenv':
>   newlib/libm/machine/x86_64/../shared_x86/fenv.c:160:
>     multiple definition of `fegetenv';
> x86_64-pc-cygwin/newlib/libm.a(libm_a-fegetenv.o):
>   newlib/libm/fenv/fegetenv.c:65:
>     first defined here
> 
> For some reason, libm.a contains both definitions of the fenv functions,
> the x86_64 definitions from newlib/libm/machine/shared_x86, as well as
> the fallback definitions from newlib/libm/fenv.
> 
> Can you please take a look?

how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
$ ./configure --target=i686-pc-cygwin && make
$ ./configure --target=x86_64-pc-cygwin && make
these are passing for me
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 18:00     ` Mike Frysinger
@ 2022-02-21 18:04       ` Jon Turney
  2022-02-21 18:30         ` Mike Frysinger
  2022-02-21 20:31         ` Mike Frysinger
  2022-02-21 18:28       ` Mike Frysinger
  1 sibling, 2 replies; 25+ messages in thread
From: Jon Turney @ 2022-02-21 18:04 UTC (permalink / raw)
  To: Mike Frysinger, newlib

On 21/02/2022 18:00, Mike Frysinger wrote:
> On 21 Feb 2022 12:20, Corinna Vinschen wrote:
>> On Feb 16 23:42, Mike Frysinger wrote:
>>> Convert all the libm/ subdir makes into the top-level Makefile.  This
>>> allows us to build all of libm from the top Makefile without using any
>>> recursive make calls.  This is faster and avoids the funky lib.a logic
>>> where we unpack subdir archives to repack into a single libm.a.  The
>>> machine override logic is maintained though by way of Makefile include
>>> ordering, and source file accumulation in libm_a_SOURCES.
>>>
>>> One thing to note is that this will require GNU Make because of:
>>> 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
>>> This was the only way I could find to supporting per-dir compiler
>>> settings, and I couldn't find a POSIX compatible way of transforming
>>> the variable content.  I don't think this is a big deal as other
>>> Makefiles in the tree are using GNU Make-specific syntax, but I call
>>> this out as it's the only one so far in the new automake code that
>>> I've been writing.
>>>
>>> Automake doesn't provide precise control over the output object names
>>> (by design).  This is fine by default as we get consistent names in all
>>> the subdirs: libm_a-<source>.o.  But this relies on using the same set
>>> of compiler flags for all objects.  We currently compile libm/common/
>>> with different optimizations than the rest.
>>>
>>> If we want to compile objects differently, we can create an intermediate
>>> archive with the subset of objects with unique flags, and then add those
>>> objects to the main archive.  But Automake will use a different prefix
>>> for the objects, and thus we can't rely on ordering to override.
>>>
>>> But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
>>> on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
>>> since $@ contains /, Automake complains it's an invalid name.  While
>>> GNU Make supports this, it's a POSIX extension, so Automake flags it.
>>> Using $(subst) avoids the Automake warning to get a POSIX compliant
>>> name, albeit with a GNU Make extension.
>>> ---
>>> v2
>>> - rebased onto latest tree
>>> - fixed a parallel build issue with generated newlib headers & libm objects
>>
>> This patch breaks Cygwin.  Unfortunately I didn't try to build myself,
>> but only inspected the patch, so I didn't realize the problem.
>>
>> First of all, Cygwin takes libm.a from newlib/libm/, not from newlib.
>> This is easily fixable.
>>
>> However, even after fixing this, we get a link stage error for *all*
>> fenv functions:
>>
>> ld: x86_64-pc-cygwin/newlib/libm.a(libm_a-fenv.o): in function `fegetenv':
>>    newlib/libm/machine/x86_64/../shared_x86/fenv.c:160:
>>      multiple definition of `fegetenv';
>> x86_64-pc-cygwin/newlib/libm.a(libm_a-fegetenv.o):
>>    newlib/libm/fenv/fegetenv.c:65:
>>      first defined here
>>
>> For some reason, libm.a contains both definitions of the fenv functions,
>> the x86_64 definitions from newlib/libm/machine/shared_x86, as well as
>> the fallback definitions from newlib/libm/fenv.
>>
>> Can you please take a look?
> 
> how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
> $ ./configure --target=i686-pc-cygwin && make
> $ ./configure --target=x86_64-pc-cygwin && make
> these are passing for me

You'll need to apply this patch:

https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html

Otherwise, you are linking with a stale libm.a left in your builddir 
from before these changes.

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 18:00     ` Mike Frysinger
  2022-02-21 18:04       ` Jon Turney
@ 2022-02-21 18:28       ` Mike Frysinger
  1 sibling, 0 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 18:28 UTC (permalink / raw)
  To: newlib

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

On 21 Feb 2022 13:00, Mike Frysinger wrote:
> On 21 Feb 2022 12:20, Corinna Vinschen wrote:
> > On Feb 16 23:42, Mike Frysinger wrote:
> > > Convert all the libm/ subdir makes into the top-level Makefile.  This
> > > allows us to build all of libm from the top Makefile without using any
> > > recursive make calls.  This is faster and avoids the funky lib.a logic
> > > where we unpack subdir archives to repack into a single libm.a.  The
> > > machine override logic is maintained though by way of Makefile include
> > > ordering, and source file accumulation in libm_a_SOURCES.
> > > 
> > > One thing to note is that this will require GNU Make because of:
> > > 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
> > > This was the only way I could find to supporting per-dir compiler
> > > settings, and I couldn't find a POSIX compatible way of transforming
> > > the variable content.  I don't think this is a big deal as other
> > > Makefiles in the tree are using GNU Make-specific syntax, but I call
> > > this out as it's the only one so far in the new automake code that
> > > I've been writing.
> > > 
> > > Automake doesn't provide precise control over the output object names
> > > (by design).  This is fine by default as we get consistent names in all
> > > the subdirs: libm_a-<source>.o.  But this relies on using the same set
> > > of compiler flags for all objects.  We currently compile libm/common/
> > > with different optimizations than the rest.
> > > 
> > > If we want to compile objects differently, we can create an intermediate
> > > archive with the subset of objects with unique flags, and then add those
> > > objects to the main archive.  But Automake will use a different prefix
> > > for the objects, and thus we can't rely on ordering to override.
> > > 
> > > But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
> > > on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
> > > since $@ contains /, Automake complains it's an invalid name.  While
> > > GNU Make supports this, it's a POSIX extension, so Automake flags it.
> > > Using $(subst) avoids the Automake warning to get a POSIX compliant
> > > name, albeit with a GNU Make extension.
> > > ---
> > > v2
> > > - rebased onto latest tree
> > > - fixed a parallel build issue with generated newlib headers & libm objects
> > 
> > This patch breaks Cygwin.  Unfortunately I didn't try to build myself,
> > but only inspected the patch, so I didn't realize the problem.
> > 
> > First of all, Cygwin takes libm.a from newlib/libm/, not from newlib.
> > This is easily fixable.
> > 
> > However, even after fixing this, we get a link stage error for *all*
> > fenv functions:
> > 
> > ld: x86_64-pc-cygwin/newlib/libm.a(libm_a-fenv.o): in function `fegetenv':
> >   newlib/libm/machine/x86_64/../shared_x86/fenv.c:160:
> >     multiple definition of `fegetenv';
> > x86_64-pc-cygwin/newlib/libm.a(libm_a-fegetenv.o):
> >   newlib/libm/fenv/fegetenv.c:65:
> >     first defined here
> > 
> > For some reason, libm.a contains both definitions of the fenv functions,
> > the x86_64 definitions from newlib/libm/machine/shared_x86, as well as
> > the fallback definitions from newlib/libm/fenv.
> > 
> > Can you please take a look?
> 
> how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
> $ ./configure --target=i686-pc-cygwin && make
> $ ./configure --target=x86_64-pc-cygwin && make
> these are passing for me

i still want to know how to repro your failure so i can make sure my local
testing is sufficient, but i might have figured it out.  we seem to have hit
a bug in `ar` :(.

this should workaround it.  i'll take it upstream to binutils once we settle
things here.
-mike

--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -124,6 +124,13 @@ libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm
 libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst /,_,$(@D)_$(<F)))
 $(libm_a_OBJECTS): stmp-targ-include

+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
+	$(AM_V_AR)for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?; done; \
+	   $(AR) $(ARFLAGS) $@ $@.tmp/*.o
+	$(AM_V_at)rm -rf $@.tmp
+	$(AM_V_at)$(RANLIB) $@
+
 if HAVE_MULTISUBDIR
 $(BUILD_MULTISUBDIR):
 	$(MKDIR_P) $@
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -3248,11 +3248,6 @@ libm/machine/x86_64/libm_a-fetestexcept.$(OBJEXT):  \
 libm/machine/x86_64/libm_a-feupdateenv.$(OBJEXT):  \
 	libm/machine/x86_64/$(am__dirstamp)
 
-libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES) $(EXTRA_libm_a_DEPENDENCIES) 
-	$(AM_V_at)-rm -f libm.a
-	$(AM_V_AR)$(libm_a_AR) libm.a $(libm_a_OBJECTS) $(libm_a_LIBADD)
-	$(AM_V_at)$(RANLIB) libm.a
-
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
 	-rm -f libm/common/*.$(OBJEXT)
@@ -8650,6 +8645,13 @@ libg.a: libc.a
 	$(AM_V_GEN)ln libc.a libg.a >/dev/null 2>/dev/null || cp libc.a libg.a
 $(libm_a_OBJECTS): stmp-targ-include
 
+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
+	$(AM_V_AR)for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?; done; \
+	   $(AR) $(ARFLAGS) $@ $@.tmp/*.o
+	$(AM_V_at)rm -rf $@.tmp
+	$(AM_V_at)$(RANLIB) $@
+
 @HAVE_MULTISUBDIR_TRUE@$(BUILD_MULTISUBDIR):
 @HAVE_MULTISUBDIR_TRUE@	$(MKDIR_P) $@
 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 18:04       ` Jon Turney
@ 2022-02-21 18:30         ` Mike Frysinger
  2022-02-21 19:12           ` Jon Turney
  2022-02-21 20:31         ` Mike Frysinger
  1 sibling, 1 reply; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 18:30 UTC (permalink / raw)
  To: Jon Turney; +Cc: newlib

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

On 21 Feb 2022 18:04, Jon Turney wrote:
> On 21/02/2022 18:00, Mike Frysinger wrote:
> > On 21 Feb 2022 12:20, Corinna Vinschen wrote:
> >> On Feb 16 23:42, Mike Frysinger wrote:
> >>> Convert all the libm/ subdir makes into the top-level Makefile.  This
> >>> allows us to build all of libm from the top Makefile without using any
> >>> recursive make calls.  This is faster and avoids the funky lib.a logic
> >>> where we unpack subdir archives to repack into a single libm.a.  The
> >>> machine override logic is maintained though by way of Makefile include
> >>> ordering, and source file accumulation in libm_a_SOURCES.
> >>>
> >>> One thing to note is that this will require GNU Make because of:
> >>> 	libm_a_CFLAGS = ... $(libm_a_CFLAGS_$(subst /,_,$(@D)))
> >>> This was the only way I could find to supporting per-dir compiler
> >>> settings, and I couldn't find a POSIX compatible way of transforming
> >>> the variable content.  I don't think this is a big deal as other
> >>> Makefiles in the tree are using GNU Make-specific syntax, but I call
> >>> this out as it's the only one so far in the new automake code that
> >>> I've been writing.
> >>>
> >>> Automake doesn't provide precise control over the output object names
> >>> (by design).  This is fine by default as we get consistent names in all
> >>> the subdirs: libm_a-<source>.o.  But this relies on using the same set
> >>> of compiler flags for all objects.  We currently compile libm/common/
> >>> with different optimizations than the rest.
> >>>
> >>> If we want to compile objects differently, we can create an intermediate
> >>> archive with the subset of objects with unique flags, and then add those
> >>> objects to the main archive.  But Automake will use a different prefix
> >>> for the objects, and thus we can't rely on ordering to override.
> >>>
> >>> But if we leverage $@, we can turn Automake's CFLAGS into a multiplex
> >>> on a per-dir (and even per-file if we wanted) basis.  Unfortunately,
> >>> since $@ contains /, Automake complains it's an invalid name.  While
> >>> GNU Make supports this, it's a POSIX extension, so Automake flags it.
> >>> Using $(subst) avoids the Automake warning to get a POSIX compliant
> >>> name, albeit with a GNU Make extension.
> >>> ---
> >>> v2
> >>> - rebased onto latest tree
> >>> - fixed a parallel build issue with generated newlib headers & libm objects
> >>
> >> This patch breaks Cygwin.  Unfortunately I didn't try to build myself,
> >> but only inspected the patch, so I didn't realize the problem.
> >>
> >> First of all, Cygwin takes libm.a from newlib/libm/, not from newlib.
> >> This is easily fixable.
> >>
> >> However, even after fixing this, we get a link stage error for *all*
> >> fenv functions:
> >>
> >> ld: x86_64-pc-cygwin/newlib/libm.a(libm_a-fenv.o): in function `fegetenv':
> >>    newlib/libm/machine/x86_64/../shared_x86/fenv.c:160:
> >>      multiple definition of `fegetenv';
> >> x86_64-pc-cygwin/newlib/libm.a(libm_a-fegetenv.o):
> >>    newlib/libm/fenv/fegetenv.c:65:
> >>      first defined here
> >>
> >> For some reason, libm.a contains both definitions of the fenv functions,
> >> the x86_64 definitions from newlib/libm/machine/shared_x86, as well as
> >> the fallback definitions from newlib/libm/fenv.
> >>
> >> Can you please take a look?
> > 
> > how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
> > $ ./configure --target=i686-pc-cygwin && make
> > $ ./configure --target=x86_64-pc-cygwin && make
> > these are passing for me
> 
> You'll need to apply this patch:
> 
> https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html
> 
> Otherwise, you are linking with a stale libm.a left in your builddir 
> from before these changes.

while i often test incremental changes, i `rm -rf` the build dir when running
the full test suite to avoid possible issues like this.  and in this case,
both targets pass from a fresh build.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 18:30         ` Mike Frysinger
@ 2022-02-21 19:12           ` Jon Turney
  2022-02-21 19:24             ` Corinna Vinschen
  0 siblings, 1 reply; 25+ messages in thread
From: Jon Turney @ 2022-02-21 19:12 UTC (permalink / raw)
  To: Mike Frysinger, newlib

On 21/02/2022 18:30, Mike Frysinger wrote:
>>>>
>>>> Can you please take a look?
>>>
>>> how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
>>> $ ./configure --target=i686-pc-cygwin && make
>>> $ ./configure --target=x86_64-pc-cygwin && make
>>> these are passing for me
>>
>> You'll need to apply this patch:
>>
>> https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html
>>
>> Otherwise, you are linking with a stale libm.a left in your builddir
>> from before these changes.
> 
> while i often test incremental changes, i `rm -rf` the build dir when running
> the full test suite to avoid possible issues like this.  and in this case,
> both targets pass from a fresh build.

Have you run autogen.sh in the winsup/ directory?  The top-level will 
just ignore it if there is no ./configure there, and it's not checked in.

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 19:12           ` Jon Turney
@ 2022-02-21 19:24             ` Corinna Vinschen
  2022-02-21 20:30               ` Mike Frysinger
  0 siblings, 1 reply; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-21 19:24 UTC (permalink / raw)
  To: newlib

On Feb 21 19:12, Jon Turney wrote:
> On 21/02/2022 18:30, Mike Frysinger wrote:
> > > > > 
> > > > > Can you please take a look?
> > > > 
> > > > how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
> > > > $ ./configure --target=i686-pc-cygwin && make
> > > > $ ./configure --target=x86_64-pc-cygwin && make
> > > > these are passing for me
> > > 
> > > You'll need to apply this patch:
> > > 
> > > https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html
> > > 
> > > Otherwise, you are linking with a stale libm.a left in your builddir
> > > from before these changes.
> > 
> > while i often test incremental changes, i `rm -rf` the build dir when running
> > the full test suite to avoid possible issues like this.  and in this case,
> > both targets pass from a fresh build.
> 
> Have you run autogen.sh in the winsup/ directory?  The top-level will just
> ignore it if there is no ./configure there, and it's not checked in.

Also, always build in an external build dir.  This may not be a problem
anymore, but in the olden days a build in the sourcedir was broken.


Corinna


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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 19:24             ` Corinna Vinschen
@ 2022-02-21 20:30               ` Mike Frysinger
  0 siblings, 0 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 20:30 UTC (permalink / raw)
  To: newlib

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

On 21 Feb 2022 20:24, Corinna Vinschen wrote:
> On Feb 21 19:12, Jon Turney wrote:
> > On 21/02/2022 18:30, Mike Frysinger wrote:
> > > > > > 
> > > > > > Can you please take a look?
> > > > > 
> > > > > how do you build cygwin ?  i've just been doing w/newlib-cygwin git checkout:
> > > > > $ ./configure --target=i686-pc-cygwin && make
> > > > > $ ./configure --target=x86_64-pc-cygwin && make
> > > > > these are passing for me
> > > > 
> > > > You'll need to apply this patch:
> > > > 
> > > > https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html
> > > > 
> > > > Otherwise, you are linking with a stale libm.a left in your builddir
> > > > from before these changes.
> > > 
> > > while i often test incremental changes, i `rm -rf` the build dir when running
> > > the full test suite to avoid possible issues like this.  and in this case,
> > > both targets pass from a fresh build.
> > 
> > Have you run autogen.sh in the winsup/ directory?  The top-level will just
> > ignore it if there is no ./configure there, and it's not checked in.
> 
> Also, always build in an external build dir.  This may not be a problem
> anymore, but in the olden days a build in the sourcedir was broken.

i always build in sep dir since i'm building ~30 targets in parallel

looks like i needed -U_FORTIFY_SOURCE and --with-cross-bootstrap too.
my patch for libm.a fixes linking of the dll files afaict.  there's
some build errors in the docs that i don't understand, but they don't
seem relevant.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] newlib: libm: merge build up a directory
  2022-02-21 18:04       ` Jon Turney
  2022-02-21 18:30         ` Mike Frysinger
@ 2022-02-21 20:31         ` Mike Frysinger
  1 sibling, 0 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 20:31 UTC (permalink / raw)
  To: Jon Turney; +Cc: newlib

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

On 21 Feb 2022 18:04, Jon Turney wrote:
> You'll need to apply this patch:
> 
> https://cygwin.com/pipermail/cygwin-patches/2022q1/011766.html

while you're there, you should adjust libc/libc.a to libc.a.  i'm going to
be dropping libc/libc.a entirely, and the top-level libc.a has been around
for a long time already.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH] newlib: libm: workaround ar duplicate member behavior
  2022-02-21 11:20   ` Corinna Vinschen
  2022-02-21 18:00     ` Mike Frysinger
@ 2022-02-21 20:43     ` Mike Frysinger
  2022-02-21 20:51       ` Joel Sherrill
  2022-02-22  0:21       ` [PATCH v2] " Mike Frysinger
  1 sibling, 2 replies; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 20:43 UTC (permalink / raw)
  To: newlib

GNU ar has undocumented behavior where it doesn't dedupe its inputs if
they're all on the same command line, so we have to dedupe ourselves.
---
 newlib/Makefile.am | 16 ++++++++++++++++
 newlib/Makefile.in | 15 ++++++++++-----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 80256952da3d..5bbe266cc4d5 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -124,6 +124,22 @@ libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm
 libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst /,_,$(@D)_$(<F)))
 $(libm_a_OBJECTS): stmp-targ-include
 
+## GNU ar has undocumented behavior when specifying the same name multiple times
+## in a single invocation, so we have to dedupe ourselves by copying objects to
+## a temporary directory.  We start with using ln to create fast hardlinks.  If
+## that fails, GNU cp has annoying behavior where you can't copy multiple files
+## to the same target filename, so have to run cp for each input in a loop.
+## https://sourceware.org/PR28917
+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
+	$(AM_V_AR)if ! ln $(libm_a_OBJECTS) $@.tmp/ 2>/dev/null; then \
+	   rm -f $@.tmp/*; \
+	   for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?; done; \
+	   fi; \
+	   $(AR) $(ARFLAGS) $@ $@.tmp/*.o
+	$(AM_V_at)rm -rf $@.tmp
+	$(AM_V_at)$(RANLIB) $@
+
 if HAVE_MULTISUBDIR
 $(BUILD_MULTISUBDIR):
 	$(MKDIR_P) $@
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 2b60ef1ca96c..84f3e0cbde37 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -3248,11 +3248,6 @@ libm/machine/x86_64/libm_a-fetestexcept.$(OBJEXT):  \
 libm/machine/x86_64/libm_a-feupdateenv.$(OBJEXT):  \
 	libm/machine/x86_64/$(am__dirstamp)
 
-libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES) $(EXTRA_libm_a_DEPENDENCIES) 
-	$(AM_V_at)-rm -f libm.a
-	$(AM_V_AR)$(libm_a_AR) libm.a $(libm_a_OBJECTS) $(libm_a_LIBADD)
-	$(AM_V_at)$(RANLIB) libm.a
-
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
 	-rm -f libm/common/*.$(OBJEXT)
@@ -8650,6 +8645,16 @@ libg.a: libc.a
 	$(AM_V_GEN)ln libc.a libg.a >/dev/null 2>/dev/null || cp libc.a libg.a
 $(libm_a_OBJECTS): stmp-targ-include
 
+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
+	$(AM_V_AR)if ! ln $(libm_a_OBJECTS) $@.tmp/ 2>/dev/null; then \
+	   rm -f $@.tmp/*; \
+	   for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?; done; \
+	   fi; \
+	   $(AR) $(ARFLAGS) $@ $@.tmp/*.o
+	$(AM_V_at)rm -rf $@.tmp
+	$(AM_V_at)$(RANLIB) $@
+
 @HAVE_MULTISUBDIR_TRUE@$(BUILD_MULTISUBDIR):
 @HAVE_MULTISUBDIR_TRUE@	$(MKDIR_P) $@
 
-- 
2.34.1


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

* Re: [PATCH] newlib: libm: workaround ar duplicate member behavior
  2022-02-21 20:43     ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
@ 2022-02-21 20:51       ` Joel Sherrill
  2022-02-21 22:12         ` Mike Frysinger
  2022-02-22  0:21       ` [PATCH v2] " Mike Frysinger
  1 sibling, 1 reply; 25+ messages in thread
From: Joel Sherrill @ 2022-02-21 20:51 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Newlib

Could this be de-duped with the gnu make sort command? That would avoid the
copy.

Alternatively, I see some awk one liners on the web to uniq the set. Or
just invoke uniq.

--joel

On Mon, Feb 21, 2022, 2:43 PM Mike Frysinger <vapier@gentoo.org> wrote:

> GNU ar has undocumented behavior where it doesn't dedupe its inputs if
> they're all on the same command line, so we have to dedupe ourselves.
> ---
>  newlib/Makefile.am | 16 ++++++++++++++++
>  newlib/Makefile.in | 15 ++++++++++-----
>  2 files changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/newlib/Makefile.am b/newlib/Makefile.am
> index 80256952da3d..5bbe266cc4d5 100644
> --- a/newlib/Makefile.am
> +++ b/newlib/Makefile.am
> @@ -124,6 +124,22 @@ libm_a_CCASFLAGS = $(AM_CCASFLAGS)
> $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm
>  libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common
> $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst
> /,_,$(@D)_$(<F)))
>  $(libm_a_OBJECTS): stmp-targ-include
>
> +## GNU ar has undocumented behavior when specifying the same name
> multiple times
> +## in a single invocation, so we have to dedupe ourselves by copying
> objects to
> +## a temporary directory.  We start with using ln to create fast
> hardlinks.  If
> +## that fails, GNU cp has annoying behavior where you can't copy multiple
> files
> +## to the same target filename, so have to run cp for each input in a
> loop.
> +## https://sourceware.org/PR28917
> +libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
> +       $(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
> +       $(AM_V_AR)if ! ln $(libm_a_OBJECTS) $@.tmp/ 2>/dev/null; then \
> +          rm -f $@.tmp/*; \
> +          for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?;
> done; \
> +          fi; \
> +          $(AR) $(ARFLAGS) $@ $@.tmp/*.o
> +       $(AM_V_at)rm -rf $@.tmp
> +       $(AM_V_at)$(RANLIB) $@
> +
>  if HAVE_MULTISUBDIR
>  $(BUILD_MULTISUBDIR):
>         $(MKDIR_P) $@
> diff --git a/newlib/Makefile.in b/newlib/Makefile.in
> index 2b60ef1ca96c..84f3e0cbde37 100644
> --- a/newlib/Makefile.in
> +++ b/newlib/Makefile.in
> @@ -3248,11 +3248,6 @@ libm/machine/x86_64/libm_a-fetestexcept.$(OBJEXT):
> \
>  libm/machine/x86_64/libm_a-feupdateenv.$(OBJEXT):  \
>         libm/machine/x86_64/$(am__dirstamp)
>
> -libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
> $(EXTRA_libm_a_DEPENDENCIES)
> -       $(AM_V_at)-rm -f libm.a
> -       $(AM_V_AR)$(libm_a_AR) libm.a $(libm_a_OBJECTS) $(libm_a_LIBADD)
> -       $(AM_V_at)$(RANLIB) libm.a
> -
>  mostlyclean-compile:
>         -rm -f *.$(OBJEXT)
>         -rm -f libm/common/*.$(OBJEXT)
> @@ -8650,6 +8645,16 @@ libg.a: libc.a
>         $(AM_V_GEN)ln libc.a libg.a >/dev/null 2>/dev/null || cp libc.a
> libg.a
>  $(libm_a_OBJECTS): stmp-targ-include
>
> +libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
> +       $(AM_V_at)rm -rf $@ $@.tmp && mkdir $@.tmp
> +       $(AM_V_AR)if ! ln $(libm_a_OBJECTS) $@.tmp/ 2>/dev/null; then \
> +          rm -f $@.tmp/*; \
> +          for o in $(libm_a_OBJECTS); do cp $$o $@.tmp/ || exit $$?;
> done; \
> +          fi; \
> +          $(AR) $(ARFLAGS) $@ $@.tmp/*.o
> +       $(AM_V_at)rm -rf $@.tmp
> +       $(AM_V_at)$(RANLIB) $@
> +
>  @HAVE_MULTISUBDIR_TRUE@$(BUILD_MULTISUBDIR):
>  @HAVE_MULTISUBDIR_TRUE@        $(MKDIR_P) $@
>
> --
> 2.34.1
>
>

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

* Re: [PATCH] newlib: libm: workaround ar duplicate member behavior
  2022-02-21 20:51       ` Joel Sherrill
@ 2022-02-21 22:12         ` Mike Frysinger
  2022-02-21 22:14           ` Joel Sherrill
  0 siblings, 1 reply; 25+ messages in thread
From: Mike Frysinger @ 2022-02-21 22:12 UTC (permalink / raw)
  To: Joel Sherrill; +Cc: Newlib

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

On 21 Feb 2022 14:51, Joel Sherrill wrote:
> Could this be de-duped with the gnu make sort command? That would avoid the
> copy.
> 
> Alternatively, I see some awk one liners on the web to uniq the set. Or
> just invoke uniq.

the inputs need to be deduped based on basename and the order specified.  so
i'd build a hashmap/associative array from the basename to the full path, and
then output the resulting set.

this isn't something sort/uniq can accomplish.

it is possible to do in awk, i've just been a bit shy about using it as i'm
not confident in portability aspects (beyond POSIX).  if we agree POSIX is
fine (which, for newlib, i think is OK), then yes, we can do that.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] newlib: libm: workaround ar duplicate member behavior
  2022-02-21 22:12         ` Mike Frysinger
@ 2022-02-21 22:14           ` Joel Sherrill
  0 siblings, 0 replies; 25+ messages in thread
From: Joel Sherrill @ 2022-02-21 22:14 UTC (permalink / raw)
  To: Joel Sherrill, Newlib

On Mon, Feb 21, 2022, 4:12 PM Mike Frysinger <vapier@gentoo.org> wrote:

> On 21 Feb 2022 14:51, Joel Sherrill wrote:
> > Could this be de-duped with the gnu make sort command? That would avoid
> the
> > copy.
> >
> > Alternatively, I see some awk one liners on the web to uniq the set. Or
> > just invoke uniq.
>
> the inputs need to be deduped based on basename and the order specified.
> so
> i'd build a hashmap/associative array from the basename to the full path,
> and
> then output the resulting set.
>
> this isn't something sort/uniq can accomplish.
>
> it is possible to do in awk, i've just been a bit shy about using it as i'm
> not confident in portability aspects (beyond POSIX).  if we agree POSIX is
> fine (which, for newlib, i think is OK), then yes, we can do that.
>

That's not my call. If GCC needs awk, we really haven't added much of a
dependency.

--joel

-mike
>

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

* [PATCH v2] newlib: libm: workaround ar duplicate member behavior
  2022-02-21 20:43     ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
  2022-02-21 20:51       ` Joel Sherrill
@ 2022-02-22  0:21       ` Mike Frysinger
  2022-02-22 11:31         ` Corinna Vinschen
  1 sibling, 1 reply; 25+ messages in thread
From: Mike Frysinger @ 2022-02-22  0:21 UTC (permalink / raw)
  To: newlib

GNU ar has undocumented behavior where it doesn't dedupe its inputs if
they're all on the same command line, so we have to dedupe ourselves.
---
v2
- use awk to dedupe the object list

 newlib/Makefile.am | 22 ++++++++++++++++++++++
 newlib/Makefile.in | 24 +++++++++++++++++++-----
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 80256952da3d..116332eb2ab9 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -85,6 +85,22 @@ toollib_DATA = $(CRT0) $(CRT1)
 
 CLEANFILES += libg.a
 
+## GNU ar has undocumented behavior when specifying the same name multiple times
+## in a single invocation, so we have to dedupe ourselves.
+## https://sourceware.org/PR28917
+AWK_UNIQUE_OBJS = $(AWK) '{ \
+  for (i = NF; i > 0; --i) { \
+    split($$i, parts, "/"); \
+    name = parts[length(parts)]; \
+    if (!(name in seen)) { \
+      objs[i] = $$i; \
+      seen[name] = 1; \
+    } \
+  } \
+  for (i in objs) \
+    print objs[i]; \
+}'
+
 # The functions ldexp, frexp and modf are traditionally supplied in
 # both libc.a and libm.a.  We build them in libm.a and copy them over,
 # along with some required supporting routines.
@@ -124,6 +140,12 @@ libm_a_CCASFLAGS = $(AM_CCASFLAGS) $(libm_a_CCASFLAGS_$(subst /,_,$(@D))) $(libm
 libm_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libm/common $(libm_a_CPPFLAGS_$(subst /,_,$(@D))) $(libm_a_CPPFLAGS_$(subst /,_,$(@D)_$(<F)))
 $(libm_a_OBJECTS): stmp-targ-include
 
+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -f $@
+	$(AM_V_AR)objs=`echo $(libm_a_OBJECTS) | $(AWK_UNIQUE_OBJS)` || exit $$?; \
+	  $(AR) $(ARFLAGS) $@ $$objs
+	$(AM_V_at)$(RANLIB) $@
+
 if HAVE_MULTISUBDIR
 $(BUILD_MULTISUBDIR):
 	$(MKDIR_P) $@
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 2b60ef1ca96c..cc7afc70451b 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -1361,6 +1361,19 @@ toollib_LIBRARIES = libm.a \
 
 @HAVE_MULTISUBDIR_TRUE@BUILD_MULTISUBDIR = $(builddir)$(MULTISUBDIR)
 toollib_DATA = $(CRT0) $(CRT1)
+AWK_UNIQUE_OBJS = $(AWK) '{ \
+  for (i = NF; i > 0; --i) { \
+    split($$i, parts, "/"); \
+    name = parts[length(parts)]; \
+    if (!(name in seen)) { \
+      objs[i] = $$i; \
+      seen[name] = 1; \
+    } \
+  } \
+  for (i in objs) \
+    print objs[i]; \
+}'
+
 
 # The functions ldexp, frexp and modf are traditionally supplied in
 # both libc.a and libm.a.  We build them in libm.a and copy them over,
@@ -3248,11 +3261,6 @@ libm/machine/x86_64/libm_a-fetestexcept.$(OBJEXT):  \
 libm/machine/x86_64/libm_a-feupdateenv.$(OBJEXT):  \
 	libm/machine/x86_64/$(am__dirstamp)
 
-libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES) $(EXTRA_libm_a_DEPENDENCIES) 
-	$(AM_V_at)-rm -f libm.a
-	$(AM_V_AR)$(libm_a_AR) libm.a $(libm_a_OBJECTS) $(libm_a_LIBADD)
-	$(AM_V_at)$(RANLIB) libm.a
-
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
 	-rm -f libm/common/*.$(OBJEXT)
@@ -8650,6 +8658,12 @@ libg.a: libc.a
 	$(AM_V_GEN)ln libc.a libg.a >/dev/null 2>/dev/null || cp libc.a libg.a
 $(libm_a_OBJECTS): stmp-targ-include
 
+libm.a: $(libm_a_OBJECTS) $(libm_a_DEPENDENCIES)
+	$(AM_V_at)rm -f $@
+	$(AM_V_AR)objs=`echo $(libm_a_OBJECTS) | $(AWK_UNIQUE_OBJS)` || exit $$?; \
+	  $(AR) $(ARFLAGS) $@ $$objs
+	$(AM_V_at)$(RANLIB) $@
+
 @HAVE_MULTISUBDIR_TRUE@$(BUILD_MULTISUBDIR):
 @HAVE_MULTISUBDIR_TRUE@	$(MKDIR_P) $@
 
-- 
2.34.1


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

* Re: [PATCH v2] newlib: libm: workaround ar duplicate member behavior
  2022-02-22  0:21       ` [PATCH v2] " Mike Frysinger
@ 2022-02-22 11:31         ` Corinna Vinschen
  2022-02-22 12:34           ` Jon Turney
  0 siblings, 1 reply; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-22 11:31 UTC (permalink / raw)
  To: newlib

On Feb 21 19:21, Mike Frysinger wrote:
> GNU ar has undocumented behavior where it doesn't dedupe its inputs if
> they're all on the same command line, so we have to dedupe ourselves.
> ---
> v2
> - use awk to dedupe the object list

This seems to work.

However, what do we have to do in future to make sure the order is
always correct?

And the heritic question: Wouldn't it be safer to keep the old
per-subdir lib.a logic?


Thanks,
Corinna


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

* Re: [PATCH v2] newlib: libm: workaround ar duplicate member behavior
  2022-02-22 11:31         ` Corinna Vinschen
@ 2022-02-22 12:34           ` Jon Turney
  2022-02-22 17:17             ` Mike Frysinger
  0 siblings, 1 reply; 25+ messages in thread
From: Jon Turney @ 2022-02-22 12:34 UTC (permalink / raw)
  To: newlib

On 22/02/2022 11:31, Corinna Vinschen wrote:
> On Feb 21 19:21, Mike Frysinger wrote:
>> GNU ar has undocumented behavior where it doesn't dedupe its inputs if
>> they're all on the same command line, so we have to dedupe ourselves.
>> ---
>> v2
>> - use awk to dedupe the object list

I think this could still at least use a comment about how the ordering 
of the inputs relates to which duplicate object are dropped and which 
are kept.

(I'm assuming cpu-specific ones are meant to be kept in preference to 
generic routines, but how does this achieve that?)

> This seems to work.
> 
> However, what do we have to do in future to make sure the order is
> always correct?
> 
> And the heritic question: Wouldn't it be safer to keep the old
> per-subdir lib.a logic?

Considering the problem in the next larger context: why are we doing 
this at all?

Is this just so the generic fenv routines are chewed on as they contain 
the doc markup?  In which case it would be simpler to do that explicitly.

If it's so that a cpu- specific fenv doesn't need to provide all the 
objects, well, that could be done explicitly as well, I think?

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

* Re: [PATCH v2] newlib: libm: workaround ar duplicate member behavior
  2022-02-22 12:34           ` Jon Turney
@ 2022-02-22 17:17             ` Mike Frysinger
  2022-02-23  8:56               ` Corinna Vinschen
  0 siblings, 1 reply; 25+ messages in thread
From: Mike Frysinger @ 2022-02-22 17:17 UTC (permalink / raw)
  To: Jon Turney; +Cc: newlib

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

On 22 Feb 2022 12:34, Jon Turney wrote:
> On 22/02/2022 11:31, Corinna Vinschen wrote:
> > On Feb 21 19:21, Mike Frysinger wrote:
> >> GNU ar has undocumented behavior where it doesn't dedupe its inputs if
> >> they're all on the same command line, so we have to dedupe ourselves.
> >> ---
> >> v2
> >> - use awk to dedupe the object list
> 
> I think this could still at least use a comment about how the ordering 
> of the inputs relates to which duplicate object are dropped and which 
> are kept.

i had updated the comment locally already and just hadn't posted it:
## GNU ar has undocumented behavior when specifying the same name multiple times
## in a single invocation, so we have to dedupe ourselves.  The algorithm here:
## - Generates the set of unique objects based on the basename.
## - Favors objects later in the list (since machine objects come last).
## - Outputs object list in same order as input for reproducibility.

> (I'm assuming cpu-specific ones are meant to be kept in preference to 
> generic routines, but how does this achieve that?)
> 
> > This seems to work.
> > 
> > However, what do we have to do in future to make sure the order is
> > always correct?

i've documented this in 3 places, so think it's fine.

(1) libc/Makefile.inc & (2) libm/Makefile.inc both have:
## The order of includes is important for two reasons:
## * The integrated documentation (chapter ordering).
## * Object overridding -- machine dir must come last.
## Do not change the order without considering the doc impact.

(3) in the heavily rewritten build documentation i sent out [1].
it's pending review from folks, so hasn't been merged yet.

> > And the heritic question: Wouldn't it be safer to keep the old
> > per-subdir lib.a logic?

i think this is a false dichotomy.  the lib.a logic has the same problem,
albeit it was never documented: if the order of SUBDIRS isn't maintained,
then the machine overrides do not work correctly.  if the order of the
lib.a unpacking was not done correctly, then the machine overrides do not
work correctly.  the fact that it's been "stable for so long" isn't due
to the code being written well (no offense), it's because it's been so
dense & undocumented that no one has wanted to touch it with a 3m pole :P.

> Considering the problem in the next larger context: why are we doing 
> this at all?
> 
> Is this just so the generic fenv routines are chewed on as they contain 
> the doc markup?  In which case it would be simpler to do that explicitly.
> 
> If it's so that a cpu- specific fenv doesn't need to provide all the 
> objects, well, that could be done explicitly as well, I think?

assuming you're asking about the machine-override logic specifically and
not "why am i changing the build system at all", then the current newlib
design supports more than fenv.  fortunately, i believe i already wrote
up all the docs you want :).  please give it a look and see if i missed
anything.
[1] https://sourceware.org/pipermail/newlib/2022/019275.html
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2] newlib: libm: workaround ar duplicate member behavior
  2022-02-22 17:17             ` Mike Frysinger
@ 2022-02-23  8:56               ` Corinna Vinschen
  0 siblings, 0 replies; 25+ messages in thread
From: Corinna Vinschen @ 2022-02-23  8:56 UTC (permalink / raw)
  To: newlib

On Feb 22 12:17, Mike Frysinger wrote:
> On 22 Feb 2022 12:34, Jon Turney wrote:
> > On 22/02/2022 11:31, Corinna Vinschen wrote:
> > > On Feb 21 19:21, Mike Frysinger wrote:
> > >> GNU ar has undocumented behavior where it doesn't dedupe its inputs if
> > >> they're all on the same command line, so we have to dedupe ourselves.
> > >> ---
> > >> v2
> > >> - use awk to dedupe the object list
> > 
> > I think this could still at least use a comment about how the ordering 
> > of the inputs relates to which duplicate object are dropped and which 
> > are kept.
> 
> i had updated the comment locally already and just hadn't posted it:
> ## GNU ar has undocumented behavior when specifying the same name multiple times
> ## in a single invocation, so we have to dedupe ourselves.  The algorithm here:
> ## - Generates the set of unique objects based on the basename.
> ## - Favors objects later in the list (since machine objects come last).
> ## - Outputs object list in same order as input for reproducibility.
> 
> > (I'm assuming cpu-specific ones are meant to be kept in preference to 
> > generic routines, but how does this achieve that?)
> > 
> > > This seems to work.
> > > 
> > > However, what do we have to do in future to make sure the order is
> > > always correct?
> 
> i've documented this in 3 places, so think it's fine.
> 
> (1) libc/Makefile.inc & (2) libm/Makefile.inc both have:
> ## The order of includes is important for two reasons:
> ## * The integrated documentation (chapter ordering).
> ## * Object overridding -- machine dir must come last.
> ## Do not change the order without considering the doc impact.
> 
> (3) in the heavily rewritten build documentation i sent out [1].
> it's pending review from folks, so hasn't been merged yet.
> 
> > > And the heritic question: Wouldn't it be safer to keep the old
> > > per-subdir lib.a logic?
> 
> i think this is a false dichotomy.  the lib.a logic has the same problem,
> albeit it was never documented: if the order of SUBDIRS isn't maintained,
> then the machine overrides do not work correctly.  if the order of the
> lib.a unpacking was not done correctly, then the machine overrides do not
> work correctly.  the fact that it's been "stable for so long" isn't due
> to the code being written well (no offense), it's because it's been so
> dense & undocumented that no one has wanted to touch it with a 3m pole :P.
> 
> > Considering the problem in the next larger context: why are we doing 
> > this at all?
> > 
> > Is this just so the generic fenv routines are chewed on as they contain 
> > the doc markup?  In which case it would be simpler to do that explicitly.
> > 
> > If it's so that a cpu- specific fenv doesn't need to provide all the 
> > objects, well, that could be done explicitly as well, I think?
> 
> assuming you're asking about the machine-override logic specifically and
> not "why am i changing the build system at all", then the current newlib
> design supports more than fenv.  fortunately, i believe i already wrote
> up all the docs you want :).  please give it a look and see if i missed
> anything.
> [1] https://sourceware.org/pipermail/newlib/2022/019275.html
> -mike

Ok, thanks, please push.


Corinna


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

end of thread, other threads:[~2022-02-23  8:56 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-12 20:34 [PATCH] newlib: libm: merge build up a directory Mike Frysinger
2022-02-16  8:50 ` [HEADSUP] " Corinna Vinschen
2022-02-16  9:40   ` Sebastian Huber
2022-02-16 10:48     ` Corinna Vinschen
2022-02-17  4:38   ` Mike Frysinger
2022-02-17  4:42 ` [PATCH v2] " Mike Frysinger
2022-02-17 12:08   ` Corinna Vinschen
2022-02-21 11:20   ` Corinna Vinschen
2022-02-21 18:00     ` Mike Frysinger
2022-02-21 18:04       ` Jon Turney
2022-02-21 18:30         ` Mike Frysinger
2022-02-21 19:12           ` Jon Turney
2022-02-21 19:24             ` Corinna Vinschen
2022-02-21 20:30               ` Mike Frysinger
2022-02-21 20:31         ` Mike Frysinger
2022-02-21 18:28       ` Mike Frysinger
2022-02-21 20:43     ` [PATCH] newlib: libm: workaround ar duplicate member behavior Mike Frysinger
2022-02-21 20:51       ` Joel Sherrill
2022-02-21 22:12         ` Mike Frysinger
2022-02-21 22:14           ` Joel Sherrill
2022-02-22  0:21       ` [PATCH v2] " Mike Frysinger
2022-02-22 11:31         ` Corinna Vinschen
2022-02-22 12:34           ` Jon Turney
2022-02-22 17:17             ` Mike Frysinger
2022-02-23  8:56               ` Corinna Vinschen

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).