[PATCH 6/6] newlib: libc: move stdlib multiplex logic from build to source files

Mike Frysinger <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Rather than define per-object rules in the Makefile, have small files
that define & include the right content.  This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object.  It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.

This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.

Also take the opportunity to clean up the unnecessary header deps in
here.  Automake provides dependency generation for free now.
---
 newlib/libc/stdlib/Makefile.am  |  92 ++-----------
 newlib/libc/stdlib/Makefile.in  | 230 ++++++++++++++++----------------
 newlib/libc/stdlib/callocr.c    |   2 +
 newlib/libc/stdlib/cfreer.c     |   2 +
 newlib/libc/stdlib/freer.c      |   2 +
 newlib/libc/stdlib/malignr.c    |   2 +
 newlib/libc/stdlib/mallinfor.c  |   2 +
 newlib/libc/stdlib/mallocr.c    |   2 +
 newlib/libc/stdlib/malloptr.c   |   2 +
 newlib/libc/stdlib/mallstatsr.c |   2 +
 newlib/libc/stdlib/msizer.c     |   2 +
 newlib/libc/stdlib/pvallocr.c   |   2 +
 newlib/libc/stdlib/reallocr.c   |   2 +
 newlib/libc/stdlib/vallocr.c    |   2 +
 14 files changed, 153 insertions(+), 193 deletions(-)
 create mode 100644 newlib/libc/stdlib/callocr.c
 create mode 100644 newlib/libc/stdlib/cfreer.c
 create mode 100644 newlib/libc/stdlib/freer.c
 create mode 100644 newlib/libc/stdlib/malignr.c
 create mode 100644 newlib/libc/stdlib/mallinfor.c
 create mode 100644 newlib/libc/stdlib/mallocr.c
 create mode 100644 newlib/libc/stdlib/malloptr.c
 create mode 100644 newlib/libc/stdlib/mallstatsr.c
 create mode 100644 newlib/libc/stdlib/msizer.c
 create mode 100644 newlib/libc/stdlib/pvallocr.c
 create mode 100644 newlib/libc/stdlib/reallocr.c
 create mode 100644 newlib/libc/stdlib/vallocr.c

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index cb2fbe850b85..b06b66014b79 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -19,6 +19,8 @@ GENERAL_SOURCES = \
 	atoi.c  	\
 	atol.c		\
 	calloc.c	\
+	callocr.c	\
+	cfreer.c	\
 	div.c  		\
 	dtoa.c 		\
 	dtoastub.c 	\
@@ -26,6 +28,7 @@ GENERAL_SOURCES = \
 	envlock.c	\
 	eprintf.c	\
 	exit.c 		\
+	freer.c		\
 	gdtoa-gethex.c	\
 	gdtoa-hexnan.c	\
 	getenv.c  	\
@@ -40,7 +43,10 @@ GENERAL_SOURCES = \
 	gdtoa-gdtoa.c	\
 	gdtoa-dmisc.c	\
 	gdtoa-gmisc.c	\
+	mallinfor.c	\
 	malloc.c  	\
+	mallocr.c	\
+	mallstatsr.c	\
 	mblen.c		\
 	mblen_r.c	\
 	mbstowcs.c	\
@@ -49,6 +55,7 @@ GENERAL_SOURCES = \
 	mbtowc_r.c	\
 	mlock.c		\
 	mprec.c		\
+	msizer.c	\
 	mstats.c	\
 	on_exit_args.c	\
 	quick_exit.c	\
@@ -58,6 +65,7 @@ GENERAL_SOURCES = \
 	realloc.c	\
 	reallocarray.c	\
 	reallocf.c	\
+	reallocr.c	\
 	sb_charsets.c	\
 	strtod.c	\
 	strtoimax.c	\
@@ -121,24 +129,22 @@ ELIX_2_SOURCES = \
 	getsubopt.c	\
 	l64a.c		\
 	malign.c	\
+	malignr.c	\
+	malloptr.c	\
 	mbrlen.c	\
 	mbrtowc.c	\
 	mbsinit.c	\
 	mbsnrtowcs.c	\
 	mbsrtowcs.c	\
 	on_exit.c	\
+	pvallocr.c	\
 	valloc.c	\
+	vallocr.c	\
 	wcrtomb.c	\
 	wcsnrtombs.c	\
 	wcsrtombs.c	\
 	wctob.c
 
-ELIX_2_OBJS = \
-	$(lpfx)malignr.o	\
-	$(lpfx)malloptr.o \
-	$(lpfx)pvallocr.o	\
-	$(lpfx)vallocr.o
-
 ELIX_3_SOURCES = \
 	putenv.c	\
 	putenv_r.c	\
@@ -151,91 +157,19 @@ ELIX_4_SOURCES = \
 
 if ELIX_LEVEL_1
 ELIX_SOURCES =
-ELIX_OBJS =
 else
 if ELIX_LEVEL_2
 ELIX_SOURCES = $(ELIX_2_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 else
 if ELIX_LEVEL_3
 ELIX_SOURCES = $(ELIX_2_SOURCES) $(ELIX_3_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 else
 ELIX_SOURCES = $(ELIX_2_SOURCES) $(ELIX_3_SOURCES) $(ELIX_4_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 endif
 endif
 endif
 
-# Because of how libtool moves objects around, mallocr must be built last.
-LIBADD_OBJS = $(lpfx)freer.o $(lpfx)reallocr.o \
-	$(lpfx)callocr.o $(lpfx)cfreer.o \
-	$(lpfx)mallinfor.o $(lpfx)mallstatsr.o \
-	$(lpfx)msizer.o $(lpfx)mallocr.o
-
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(GENERAL_SOURCES) $(EXTENDED_SOURCES) $(ELIX_SOURCES)
-lib_a_LIBADD = $(LIBADD_OBJS) $(ELIX_OBJS)
+lib_a_LIBADD =
 lib_a_CFLAGS = $(AM_CFLAGS)
-lib_a_DEPENDENCIES = $(LIBADD_OBJS) $(ELIX_OBJS)
-LIB_COMPILE = $(AM_V_CC)$(COMPILE)
-
-$(lpfx)mallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLOC -c $< -o $@
-
-$(lpfx)freer.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_FREE -c $< -o $@
-
-$(lpfx)reallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_REALLOC -c $< -o $@
-
-$(lpfx)callocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_CALLOC -c $< -o $@
-
-$(lpfx)cfreer.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_CFREE -c $< -o $@
-
-$(lpfx)malignr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $< -o $@
-
-$(lpfx)vallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_VALLOC -c $< -o $@
-
-$(lpfx)pvallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_PVALLOC -c $< -o $@
-
-$(lpfx)mallinfor.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLINFO -c $< -o $@
-
-$(lpfx)mallstatsr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $< -o $@
-
-$(lpfx)msizer.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $< -o $@
-
-$(lpfx)malloptr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLOPT -c $< -o $@
-
-$(lpfx)dtoa.o: dtoa.c mprec.h
-$(lpfx)ldtoa.o: ldtoa.c mprec.h gdtoa.h
-$(lpfx)gdtoa-ldtoa.o: gdtoa-ldtoa.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-gdtoa.o: gdtoa-gdtoa.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-dmisc.o: gdtoa-dmisc.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-gmisc.o: gdtoa-gmisc.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)ecvtbuf.o: ecvtbuf.c mprec.h
-$(lpfx)mbtowc_r.o: mbtowc_r.c mbctype.h
-$(lpfx)mprec.o: mprec.c mprec.h
-$(lpfx)strtod.o: strtod.c mprec.h
-$(lpfx)gdtoa-gethex.o: gdtoa-gethex.c mprec.h
-$(lpfx)gdtoa-hexnan.o: gdtoa-hexnan.c mprec.h
-$(lpfx)wctomb_r.o: wctomb_r.c mbctype.h
-$(lpfx)drand48.o: drand48.c rand48.h
-$(lpfx)erand48.o: erand48.c rand48.h
-$(lpfx)jrand48.o: jrand48.c rand48.h
-$(lpfx)lcong48.o: lcong48.c rand48.h
-$(lpfx)lrand48.o: lrand48.c rand48.h
-$(lpfx)mrand48.o: mrand48.c rand48.h
-$(lpfx)nrand48.o: nrand48.c rand48.h
-$(lpfx)rand48.o: rand48.c rand48.h
-$(lpfx)seed48.o: seed48.c rand48.h
-$(lpfx)srand48.o: srand48.c rand48.h
diff --git a/newlib/libc/stdlib/callocr.c b/newlib/libc/stdlib/callocr.c
new file mode 100644
index 000000000000..80fee60db585
--- /dev/null
+++ b/newlib/libc/stdlib/callocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_CALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/cfreer.c b/newlib/libc/stdlib/cfreer.c
new file mode 100644
index 000000000000..a644664ae59c
--- /dev/null
+++ b/newlib/libc/stdlib/cfreer.c
@@ -0,0 +1,2 @@
+#define DEFINE_CFREE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/freer.c b/newlib/libc/stdlib/freer.c
new file mode 100644
index 000000000000..1418d0c8f257
--- /dev/null
+++ b/newlib/libc/stdlib/freer.c
@@ -0,0 +1,2 @@
+#define DEFINE_FREE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/malignr.c b/newlib/libc/stdlib/malignr.c
new file mode 100644
index 000000000000..c48fbad0c4d9
--- /dev/null
+++ b/newlib/libc/stdlib/malignr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MEMALIGN
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallinfor.c b/newlib/libc/stdlib/mallinfor.c
new file mode 100644
index 000000000000..dc1a55d9d20a
--- /dev/null
+++ b/newlib/libc/stdlib/mallinfor.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLINFO
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
new file mode 100644
index 000000000000..c2ab1caadce1
--- /dev/null
+++ b/newlib/libc/stdlib/mallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/malloptr.c b/newlib/libc/stdlib/malloptr.c
new file mode 100644
index 000000000000..f67be247d75b
--- /dev/null
+++ b/newlib/libc/stdlib/malloptr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOPT
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallstatsr.c b/newlib/libc/stdlib/mallstatsr.c
new file mode 100644
index 000000000000..15cd7379de95
--- /dev/null
+++ b/newlib/libc/stdlib/mallstatsr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC_STATS
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/msizer.c b/newlib/libc/stdlib/msizer.c
new file mode 100644
index 000000000000..1d683f485027
--- /dev/null
+++ b/newlib/libc/stdlib/msizer.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC_USABLE_SIZE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/pvallocr.c b/newlib/libc/stdlib/pvallocr.c
new file mode 100644
index 000000000000..afc203860143
--- /dev/null
+++ b/newlib/libc/stdlib/pvallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_PVALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/reallocr.c b/newlib/libc/stdlib/reallocr.c
new file mode 100644
index 000000000000..45c21d2d2d7c
--- /dev/null
+++ b/newlib/libc/stdlib/reallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_REALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/vallocr.c b/newlib/libc/stdlib/vallocr.c
new file mode 100644
index 000000000000..9f05700a4e8f
--- /dev/null
+++ b/newlib/libc/stdlib/vallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_VALLOC
+#include "_mallocr.c"
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.