rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit bc124e21ba3107b8b91095fb877283cc3cc8efa7
parent e3740a566294ffed6868565d2c8b3db7b2837412
Author: vaplv <vaplv@free.fr>
Date:   Wed, 18 Oct 2023 09:06:29 +0200

Update tests compilation

Use pkg-config when editing links with the local RSys library. This is a
pleasant and practical way of managing compilation and linker flags. At
the same time, it allows us to test the pc file.

Finally, add the RSys library as a dependency of the tests that must be
linked to it. This forces make to rerun the linker if the library is
changed.

Diffstat:
M.gitignore | 2+-
MMakefile | 61+++++++++++++++++++++++++++++++++++++++----------------------
Mconfig.mk | 6++++++
3 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -8,4 +8,4 @@ test* !test*.[ch] .test tags -rsys.pc +*.pc diff --git a/Makefile b/Makefile @@ -131,10 +131,25 @@ API =\ src/text_reader.h 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 + +# Remove the include directive rather than setting it to "./src". to prevent +# the source directory from having a higher priority than the system include +# directories. In such a situation, the local "math.h" file could be included +# instead of the "math.h" header provided by the C standard library. Note that +# this is no longer a problem with the common pc file: the "math.h" file is +# installed in the "rsys" subdirectory, which is therefore a prefix of the +# header file allowing it to be distinguished from the header of the standard +# library +rsys-local.pc: rsys.pc.in + sed -e '1,2d'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#-I$${includedir}##g'\ + rsys.pc.in > $@ install: build_library pkg @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/" $(LIBNAME) @@ -155,8 +170,10 @@ uninstall: all: build_library build_tests clean: clean_test - rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) libtest_lib.so test_lib.o \ -.test rsys.pc .test.ppm test_text_reader.txt test.ppm + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) + rm -f rsys.pc rsys-local.pc + rm -f libtest_lib.so test_lib.o + rm -f .test rsys.pc .test.ppm test_text_reader.txt test.ppm distclean: clean rm -f $(DEP) $(TEST_DEP) @@ -211,9 +228,9 @@ TEST_SRC =\ TEST_OBJ = $(TEST_SRC:.c=.o) 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)) +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +RSYS_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys-local.pc) +RSYS_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys-local.pc) build_tests: build_library $(TEST_DEP) .test @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin @@ -268,14 +285,14 @@ src/test_stretchy_array.o \ src/test_text_reader.o \ src/test_time.o \ src/test_vmacros.o \ -: - $(CC) $(CFLAGS) -c $(@:.o=.c) -o $@ +: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ -src/test_cstr.o: - $(CC) $(CFLAGS) -Wno-long-long -c $(@:.o=.c) -o $@ +src/test_cstr.o: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS) $(RSYS_CFLAGS) -Wno-long-long -c $(@:.o=.c) -o $@ -src/test_condition.o src/test_mutex.o: - $(CC) $(CFLAGS) -fopenmp -c $(@:.o=.c) -o $@ +src/test_condition.o src/test_mutex.o: config.mk rsys-local.pc $(LIBNAME) + $(CC) $(CFLAGS) $(RSYS_CFLAGS) -fopenmp -c $(@:.o=.c) -o $@ test_algorithm \ test_atomic \ @@ -285,7 +302,7 @@ test_misc \ test_morton \ test_ref \ test_vmacros \ -: +: config.mk $(CC) -o $@ src/$@.o $(LDFLAGS) test_double22 \ @@ -301,7 +318,7 @@ test_float3 \ test_float44 \ test_float4 \ test_math \ -: +: config.mk $(CC) -o $@ src/$@.o $(LDFLAGS) -lm test_binary_heap\ @@ -320,19 +337,19 @@ test_str \ test_stretchy_array \ test_text_reader \ test_time \ -: +: config.mk rsys-local.pc $(LIBNAME) $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -test_quaternion: +test_quaternion: config.mk rsys-local.pc $(LIBNAME) $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm -test_condition test_mutex: +test_condition test_mutex: config.mk rsys-local.pc $(LIBNAME) $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSYS_LIBS) -lm -fopenmp -test_lib.o: src/test_library.c src/rsys.h +test_lib.o: src/test_library.c src/rsys.h config.mk $(CC) $(CFLAGS) -c src/test_library.c -DTEST_LIBRARY_BUILD_LIB -o $@ -libtest_lib.so: test_lib.o +libtest_lib.so: test_lib.o config.mk $(CC) $(CFLAGS) -o $@ test_lib.o $(LDFLAGS) $(SOFLAGS) test_library: libtest_lib.so diff --git a/config.mk b/config.mk @@ -12,8 +12,14 @@ BUILD_TYPE = RELEASE ################################################################################ CC = cc AR = ar +PKG_CONFIG = pkg-config RANLIB = ranlib +# pkg-config flags +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + ################################################################################ # Compilation options ################################################################################