commit 1156d7886bf9e55ec40d82c3ca6d0d9ee2ce0634
parent 3ab9c7eab77aa90c4450b863b30e2571000042b2
Author: vaplv <vaplv@free.fr>
Date: Sun, 14 May 2023 10:35:32 +0200
Clean-up and solidify the Makefile
Until now, if the LIB_TYPE macro had an unexpected value, i.e. a value
that is not STATIC or SHARED, the build process would enter an infinite
loop: the target name would be empty. We correct this problem by setting
the target name to be the name of the shared library when the supplied
target is undefined.
Add the LIBNAME, CFLAGS and LDFLAGS macros defined from the LIB_TYPE and
BUILD_TYPE macros. This avoids the need to suffix each macro and
therefore makes writing easier.
Make the targets clean, distclean and lint verbose to show what they do.
Finally, remove the unnecessary PKG_CONFIG macro and move the VERSION
macro from the Makefile back to the config.mk file so that the versions
of the library and its dependencies are in one place.
Diffstat:
3 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/Makefile b/Makefile
@@ -16,12 +16,11 @@
.POSIX:
.SUFFIXES: # Clean up default inference rules
-VERSION = 0.13.0
-
include config.mk
LIBNAME_STATIC = librsys.a
LIBNAME_SHARED = librsys.so
+LIBNAME = $(LIBNAME_$(LIB_TYPE))
################################################################################
# RSys building
@@ -45,12 +44,17 @@ OBJ = $(SRC:.c=.o)
DEP = $(SRC:.c=.d)
build_library: $(DEP)
- @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) $(LIBNAME_$(LIB_TYPE))
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done)\
+ $$(if [ -n "$(LIBNAME)" ]; then\
+ echo "$(LIBNAME)";\
+ else\
+ echo "$(LIBNAME_SHARED)";\
+ fi)
$(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -o $@ $(OBJ) $(LDFLAGS_$(BUILD_TYPE)) $(SOFLAGS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(LIBS)
$(LIBNAME_STATIC): $(OBJ)
$(AR) -rc $@ $?
@@ -58,10 +62,10 @@ $(LIBNAME_STATIC): $(OBJ)
.SUFFIXES: .c .d .o
.c.d:
- @$(CC) $(CFLAGS_$(BUILD_TYPE)) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+ @$(CC) $(CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
.c.o:
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -DRSYS_SHARED_BUILD -c $< -o $@
+ $(CC) $(CFLAGS) -DRSYS_SHARED_BUILD -c $< -o $@
################################################################################
# Installation
@@ -128,16 +132,18 @@ API =\
pkg:
@echo "Setup rsys.pc"
- @sed -e 's#@PREFIX@#$(PREFIX)#g' -e 's#@VERSION@#$(VERSION)#g' rsys.pc.in > rsys.pc
+ @sed -e 's#@PREFIX@#$(PREFIX)#g'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ rsys.pc.in > rsys.pc
install: build_library pkg
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/" $(LIBNAME_$(LIB_TYPE))
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/" $(LIBNAME)
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/rsys" COPYING README.md
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" rsys.pc
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/rsys" $(API)
uninstall:
- rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME_$(LIB_TYPE))"
+ rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/rsys.pc"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rsys/COPYING"
rm -f "$(DESTDIR)$(PREFIX)/share/doc/rsys/README.md"
@@ -149,14 +155,14 @@ uninstall:
all: build_library build_tests
clean: clean_test
- @rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME_$(LIB_TYPE)) libtest_lib.so test_lib.o\
- .test rsys.pc .test.ppm test_text_reader.txt test.ppm
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) libtest_lib.so test_lib.o \
+.test rsys.pc .test.ppm test_text_reader.txt test.ppm
distclean: clean
- @rm -f $(DEP) $(TEST_DEP)
+ rm -f $(DEP) $(TEST_DEP)
lint:
- @shellcheck -o all make.sh
+ shellcheck -o all make.sh
################################################################################
# Tests
@@ -207,6 +213,7 @@ TEST_DEP = $(TEST_SRC:.c=.d)
RSYS_LIBS_STATIC = $(LIBNAME_STATIC) -ldl -lpthread -lm
RSYS_LIBS_SHARED = -L./ -lrsys
+RSYS_LIBS = $(RSYS_LIBS_$(LIB_TYPE))
build_tests: build_library $(TEST_DEP) .test
@$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
@@ -262,13 +269,13 @@ src/test_text_reader.o \
src/test_time.o \
src/test_vmacros.o \
:
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -c $(@:.o=.c) -o $@
+ $(CC) $(CFLAGS) -c $(@:.o=.c) -o $@
src/test_cstr.o:
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -Wno-long-long -c $(@:.o=.c) -o $@
+ $(CC) $(CFLAGS) -Wno-long-long -c $(@:.o=.c) -o $@
src/test_condition.o src/test_mutex.o:
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -fopenmp -c $(@:.o=.c) -o $@
+ $(CC) $(CFLAGS) -fopenmp -c $(@:.o=.c) -o $@
test_algorithm \
test_atomic \
@@ -279,7 +286,7 @@ test_morton \
test_ref \
test_vmacros \
:
- $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE))
+ $(CC) -o $@ src/$@.o $(LDFLAGS)
test_double22 \
test_double2 \
@@ -295,7 +302,7 @@ test_float44 \
test_float4 \
test_math \
:
- $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) -lm
+ $(CC) -o $@ src/$@.o $(LDFLAGS) -lm
test_binary_heap\
test_cstr \
@@ -314,18 +321,18 @@ test_stretchy_array \
test_text_reader \
test_time \
:
- $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) $(RSYS_LIBS_$(LIB_TYPE))
+ $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS)
test_quaternion:
- $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) $(RSYS_LIBS_$(LIB_TYPE)) -lm
+ $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm
test_condition test_mutex:
- $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) $(RSYS_LIBS_$(LIB_TYPE)) -lm -fopenmp
+ $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm -fopenmp
test_lib.o: src/test_library.c src/rsys.h
- $(CC) $(CFLAGS_$(BUILD_TYPE)) -c src/test_library.c -DTEST_LIBRARY_BUILD_LIB -o $@
+ $(CC) $(CFLAGS) -c src/test_library.c -DTEST_LIBRARY_BUILD_LIB -o $@
libtest_lib.so: test_lib.o
- $(CC) -o $@ test_lib.o $(LDFLAGS_$(BUILD_TYPE)) $(SOFLAGS)
+ $(CC) -o $@ test_lib.o $(LDFLAGS) $(SOFLAGS)
test_library: libtest_lib.so
diff --git a/config.mk b/config.mk
@@ -1,3 +1,4 @@
+VERSION = 0.13.0
PREFIX = /usr/local
LIB_TYPE = SHARED
@@ -12,7 +13,6 @@ BUILD_TYPE = RELEASE
CC = cc
AR = ar
RANLIB = ranlib
-PKG_CONFIG = pkg-config
################################################################################
# Compilation options
@@ -35,6 +35,7 @@ CFLAGS_COMMON =\
CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON)
CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
+CFLAGS = $(CFLAGS_$(BUILD_TYPE))
################################################################################
# Linker options
@@ -44,3 +45,4 @@ SOFLAGS = -shared -Wl,--no-undefined
LDFLAGS_DEBUG =
LDFLAGS_RELEASE = -s
+LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
diff --git a/src/mem_proxy_allocator.c b/src/mem_proxy_allocator.c
@@ -259,7 +259,6 @@ proxy_dump
/*******************************************************************************
* Exported functions
******************************************************************************/
-
res_T
mem_init_proxy_allocator
(struct mem_allocator* proxy_allocator,