public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: newlib@sourceware.org
Subject: [PATCH 6/6] newlib: libc: move stdlib multiplex logic from build to source files
Date: Tue,  1 Mar 2022 20:36:23 -0500	[thread overview]
Message-ID: <20220302013623.368-7-vapier@gentoo.org> (raw)
In-Reply-To: <20220302013623.368-1-vapier@gentoo.org>

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


  parent reply	other threads:[~2022-03-02  1:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules " Mike Frysinger
2022-03-02  1:36 ` [PATCH 1/6] newlib: move nano-malloc logic from build " Mike Frysinger
2022-03-02  1:36 ` [PATCH 2/6] newlib: rename mallocr.c to _mallocr.c Mike Frysinger
2022-03-02  1:36 ` [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling Mike Frysinger
2022-03-02  9:46   ` Corinna Vinschen
2022-03-09  9:23     ` Mike Frysinger
2022-03-10  8:12       ` Corinna Vinschen
2022-03-10  8:00     ` Sebastian Huber
2022-03-02  1:36 ` [PATCH 4/6] newlib: xstormy16: break up mallocr stubs Mike Frysinger
2022-03-02  1:36 ` [PATCH 5/6] newlib: xstormy16: move malloc multiplex logic from build to source files Mike Frysinger
2022-03-02  1:36 ` Mike Frysinger [this message]
2022-03-02  9:47 ` [PATCH 0/6] rework malloc logic from build rules " Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220302013623.368-7-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).