newlib: xstormy16: move malloc multiplex logic from build to source files

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.

We also realign the free & pvalloc definitions: common code puts these
in malloc.o & valloc.o respectively, not in free.o & pvalloc.o objects.

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.
This commit is contained in:
Mike Frysinger 2022-03-01 01:37:19 -05:00
parent 8c383e9ae7
commit b2d4dc167c
9 changed files with 84 additions and 85 deletions

View File

@ -7,50 +7,16 @@ AM_CCASFLAGS = $(AM_CPPFLAGS)
noinst_LIBRARIES = lib.a
lib_a_SOURCES = setjmp.S \
calloc.c \
callocr.c \
cfree.c \
freer.c \
malign.c \
malloc.c \
mallocr.c \
msize.c \
mstats.c \
reallocr.c
realloc.c \
reallocr.c \
valloc.c
lib_a_CFLAGS = $(AM_CFLAGS)
lib_a_LIBADD = $(lpfx)malloc.o \
$(lpfx)free.o \
$(lpfx)realloc.o \
$(lpfx)calloc.o \
$(lpfx)cfree.o \
$(lpfx)malign.o \
$(lpfx)valloc.o \
$(lpfx)pvalloc.o \
$(lpfx)msize.o
lib_a_DEPENDENCIES = $(lib_a_LIBADD)
MALLOC_COMPILE = $(COMPILE)
$(lpfx)malloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)free.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_FREE -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)realloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)calloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)cfree.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_CFREE -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)malign.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MEMALIGN -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)valloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_VALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)pvalloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)msize.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/tiny-malloc.c -o $@

View File

@ -117,9 +117,14 @@ am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@)
am__v_AR_0 = @echo " AR " $@;
am__v_AR_1 =
lib_a_AR = $(AR) $(ARFLAGS)
am_lib_a_OBJECTS = setjmp.$(OBJEXT) lib_a-callocr.$(OBJEXT) \
lib_a-freer.$(OBJEXT) lib_a-mallocr.$(OBJEXT) \
lib_a-mstats.$(OBJEXT) lib_a-reallocr.$(OBJEXT)
lib_a_LIBADD =
am_lib_a_OBJECTS = setjmp.$(OBJEXT) lib_a-calloc.$(OBJEXT) \
lib_a-callocr.$(OBJEXT) lib_a-cfree.$(OBJEXT) \
lib_a-freer.$(OBJEXT) lib_a-malign.$(OBJEXT) \
lib_a-malloc.$(OBJEXT) lib_a-mallocr.$(OBJEXT) \
lib_a-msize.$(OBJEXT) lib_a-mstats.$(OBJEXT) \
lib_a-realloc.$(OBJEXT) lib_a-reallocr.$(OBJEXT) \
lib_a-valloc.$(OBJEXT)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@ -316,25 +321,20 @@ AM_CPPFLAGS = $(NEWLIB_CFLAGS) $(TARGET_CFLAGS)
AM_CCASFLAGS = $(AM_CPPFLAGS)
noinst_LIBRARIES = lib.a
lib_a_SOURCES = setjmp.S \
calloc.c \
callocr.c \
cfree.c \
freer.c \
malign.c \
malloc.c \
mallocr.c \
msize.c \
mstats.c \
reallocr.c
realloc.c \
reallocr.c \
valloc.c
lib_a_CFLAGS = $(AM_CFLAGS)
lib_a_LIBADD = $(lpfx)malloc.o \
$(lpfx)free.o \
$(lpfx)realloc.o \
$(lpfx)calloc.o \
$(lpfx)cfree.o \
$(lpfx)malign.o \
$(lpfx)valloc.o \
$(lpfx)pvalloc.o \
$(lpfx)msize.o
lib_a_DEPENDENCIES = $(lib_a_LIBADD)
MALLOC_COMPILE = $(COMPILE)
all: all-am
.SUFFIXES:
@ -395,36 +395,78 @@ distclean-compile:
.c.obj:
$(AM_V_CC)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
lib_a-calloc.o: calloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-calloc.o `test -f 'calloc.c' || echo '$(srcdir)/'`calloc.c
lib_a-calloc.obj: calloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-calloc.obj `if test -f 'calloc.c'; then $(CYGPATH_W) 'calloc.c'; else $(CYGPATH_W) '$(srcdir)/calloc.c'; fi`
lib_a-callocr.o: callocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-callocr.o `test -f 'callocr.c' || echo '$(srcdir)/'`callocr.c
lib_a-callocr.obj: callocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-callocr.obj `if test -f 'callocr.c'; then $(CYGPATH_W) 'callocr.c'; else $(CYGPATH_W) '$(srcdir)/callocr.c'; fi`
lib_a-cfree.o: cfree.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-cfree.o `test -f 'cfree.c' || echo '$(srcdir)/'`cfree.c
lib_a-cfree.obj: cfree.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-cfree.obj `if test -f 'cfree.c'; then $(CYGPATH_W) 'cfree.c'; else $(CYGPATH_W) '$(srcdir)/cfree.c'; fi`
lib_a-freer.o: freer.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-freer.o `test -f 'freer.c' || echo '$(srcdir)/'`freer.c
lib_a-freer.obj: freer.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-freer.obj `if test -f 'freer.c'; then $(CYGPATH_W) 'freer.c'; else $(CYGPATH_W) '$(srcdir)/freer.c'; fi`
lib_a-malign.o: malign.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-malign.o `test -f 'malign.c' || echo '$(srcdir)/'`malign.c
lib_a-malign.obj: malign.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-malign.obj `if test -f 'malign.c'; then $(CYGPATH_W) 'malign.c'; else $(CYGPATH_W) '$(srcdir)/malign.c'; fi`
lib_a-malloc.o: malloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-malloc.o `test -f 'malloc.c' || echo '$(srcdir)/'`malloc.c
lib_a-malloc.obj: malloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-malloc.obj `if test -f 'malloc.c'; then $(CYGPATH_W) 'malloc.c'; else $(CYGPATH_W) '$(srcdir)/malloc.c'; fi`
lib_a-mallocr.o: mallocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mallocr.o `test -f 'mallocr.c' || echo '$(srcdir)/'`mallocr.c
lib_a-mallocr.obj: mallocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mallocr.obj `if test -f 'mallocr.c'; then $(CYGPATH_W) 'mallocr.c'; else $(CYGPATH_W) '$(srcdir)/mallocr.c'; fi`
lib_a-msize.o: msize.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-msize.o `test -f 'msize.c' || echo '$(srcdir)/'`msize.c
lib_a-msize.obj: msize.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-msize.obj `if test -f 'msize.c'; then $(CYGPATH_W) 'msize.c'; else $(CYGPATH_W) '$(srcdir)/msize.c'; fi`
lib_a-mstats.o: mstats.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mstats.o `test -f 'mstats.c' || echo '$(srcdir)/'`mstats.c
lib_a-mstats.obj: mstats.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mstats.obj `if test -f 'mstats.c'; then $(CYGPATH_W) 'mstats.c'; else $(CYGPATH_W) '$(srcdir)/mstats.c'; fi`
lib_a-realloc.o: realloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-realloc.o `test -f 'realloc.c' || echo '$(srcdir)/'`realloc.c
lib_a-realloc.obj: realloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-realloc.obj `if test -f 'realloc.c'; then $(CYGPATH_W) 'realloc.c'; else $(CYGPATH_W) '$(srcdir)/realloc.c'; fi`
lib_a-reallocr.o: reallocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-reallocr.o `test -f 'reallocr.c' || echo '$(srcdir)/'`reallocr.c
lib_a-reallocr.obj: reallocr.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-reallocr.obj `if test -f 'reallocr.c'; then $(CYGPATH_W) 'reallocr.c'; else $(CYGPATH_W) '$(srcdir)/reallocr.c'; fi`
lib_a-valloc.o: valloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-valloc.o `test -f 'valloc.c' || echo '$(srcdir)/'`valloc.c
lib_a-valloc.obj: valloc.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-valloc.obj `if test -f 'valloc.c'; then $(CYGPATH_W) 'valloc.c'; else $(CYGPATH_W) '$(srcdir)/valloc.c'; fi`
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
@ -595,33 +637,6 @@ uninstall-am:
.PRECIOUS: Makefile
$(lpfx)malloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)free.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_FREE -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)realloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)calloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)cfree.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_CFREE -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)malign.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MEMALIGN -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)valloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_VALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)pvalloc.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/tiny-malloc.c -o $@
$(lpfx)msize.o: tiny-malloc.c
$(MALLOC_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/tiny-malloc.c -o $@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@ -0,0 +1,2 @@
#define DEFINE_CALLOC
#include "tiny-malloc.c"

View File

@ -0,0 +1,2 @@
#define DEFINE_CFREE
#include "tiny-malloc.c"

View File

@ -0,0 +1,2 @@
#define DEFINE_MEMALIGN
#include "tiny-malloc.c"

View File

@ -0,0 +1,4 @@
/* stdlib/malloc.c defines all these symbols in this file. */
#define DEFINE_FREE
#define DEFINE_MALLOC
#include "tiny-malloc.c"

View File

@ -0,0 +1,2 @@
#define DEFINE_MALLOC_USABLE_SIZE
#include "tiny-malloc.c"

View File

@ -0,0 +1,2 @@
#define DEFINE_REALLOC
#include "tiny-malloc.c"

View File

@ -0,0 +1,4 @@
/* stdlib/valloc.c defines all these symbols in this file. */
#define DEFINE_PVALLOC
#define DEFINE_VALLOC
#include "tiny-malloc.c"