star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 346491e98df26b37b21db72ba10a6f7077dfcee8
parent 6e0ccab1076c28a4f0d20bde62b60d595bbae147
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sun,  7 May 2023 22:15:23 +0200

Rework the library compilation by the POSIX Makefile

Add the LIB_TYPE macro which can take the value SHARED or STATIC define
the private libraries, i.e. the libraries that Star-3D depends on for
linking against it statically. The pkg-config file is thus updated as
well as the list of libraries against which the tests are linked
according to the LIB_TYPE macro.

Differentiate the linker flags according to BUILD_TYPE. In release, the
entire symbol table and relocation information is removed from the
executables (option -s).

Add the CFLAGS used during compilation. This follows the recommendation
of the GCC manual for the -shared option: "For predictable results, you
must also specify the same set of options used for compilation".

Fixed the compilation of some tests that were not linked to the m
library when they should be.

Diffstat:
M.gitignore | 2+-
MMakefile | 61++++++++++++++++++++++++++++++++++++++++++-------------------
Mconfig.mk | 15+++++++++++----
Ms3d.pc.in | 1+
4 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -10,4 +10,4 @@ test* .test tags s3d.pc - +s3d-local.pc diff --git a/Makefile b/Makefile @@ -33,6 +33,9 @@ VERSION = 0.8.0 include config.mk +LIBNAME_STATIC = libs3d.a +LIBNAME_SHARED = libs3d.so + ################################################################################ # Star-3D building ################################################################################ @@ -52,12 +55,16 @@ OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) build_library: .config $(DEP) - @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs3d.so + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) $(LIBNAME_$(LIB_TYPE)) $(OBJ): config.mk -libs3d.so: $(OBJ) - $(CC) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(LIBS) +$(LIBNAME_SHARED): $(OBJ) + $(CC) -std=c99 $(CFLAGS_$(BUILD_TYPE)) -o $@ $(OBJ) $(LDFLAGS_$(BUILD_TYPE)) $(SOFLAGS) $(LIBS) + +$(LIBNAME_STATIC): $(OBJ) + $(AR) -rc $@ $? + $(RANLIB) $@ .config: Makefile @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ @@ -84,20 +91,29 @@ pkg: -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g' \ s3d.pc.in > s3d.pc +s3d-local.pc: + @sed -e '1d' \ + -e 's#^includedir=.*#includedir=./src/#' \ + -e 's#^libdir=.*#libdir=./#' \ + -e 's#@VERSION@#$(VERSION)#g' \ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ + -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g' \ + s3d.pc.in > $@ + install: build_library pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" libs3d.so + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME_$(LIB_TYPE)) @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" s3d.pc @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/s3d.h @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-3d"\ COPYING.en COPYING.fr README.md uninstall: - rm -f $(DESTDIR)$(PREFIX)/lib/libs3d.so - rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s3d.pc - rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.en - rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.fr - rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/README.md - rm -f $(DESTDIR)$(PREFIX)/include/star/s3d.h + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME_$(LIB_TYPE))" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/s3d.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.en" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.fr" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/star/s3d.h" ################################################################################ # Miscellaneous targets @@ -105,7 +121,7 @@ uninstall: all: build_library build_tests clean: clean_test - @rm -f $(OBJ) $(TEST_OBJ) libs3d.so .test s3d.pc .config + @rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME_$(LIB_TYPE)) .test s3d.pc .config distclean: clean @rm -f $(DEP) $(TEST_DEP) @@ -137,6 +153,11 @@ TEST_SRC =\ TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) +S3D_CFLAGS_STATIC = $$($(PKG_CONFIG) --with-path=./ --static --cflags s3d-local.pc) +S3D_CFLAGS_SHARED = $$($(PKG_CONFIG) --with-path=./ --shared --cflags s3d-local.pc) +S3D_LIBS_STATIC = $$($(PKG_CONFIG) --with-path=./ --static --libs s3d-local.pc) +S3D_LIBS_SHARED = $$($(PKG_CONFIG) --with-path=./ --shared --libs s3d-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 @@ -144,31 +165,33 @@ test: build_tests @$(SHELL) make.sh run_test $(TEST_SRC) .test: Makefile - @echo "Setup tests" @$(SHELL) make.sh config_test $(TEST_SRC) > .test clean_test: @$(SHELL) make.sh clean_test $(TEST_SRC) -$(TEST_OBJ): config.mk - $(CC) -std=c89 $(CFLAGS_$(BUILD_TYPE)) $(RSYS_INC) -c $(@:.o=.c) -o $@ +$(TEST_OBJ): config.mk s3d-local.pc + $(CC) -std=c89 $(CFLAGS_$(BUILD_TYPE)) $(S3D_CFLAGS_$(LIB_TYPE)) -c $(@:.o=.c) -o $@ -test_s3d_accel_struct_conf \ -test_s3d_closest_point \ test_s3d_device \ test_s3d_primitive \ test_s3d_sampler \ -test_s3d_sample_sphere \ test_s3d_scene \ test_s3d_scene_view_aabb \ test_s3d_scene_view \ test_s3d_seams \ test_s3d_shape \ +: s3d-local.pc + $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) $(S3D_LIBS_$(LIB_TYPE)) + +test_s3d_accel_struct_conf \ +test_s3d_closest_point \ +test_s3d_sample_sphere \ test_s3d_sphere_box \ test_s3d_sphere \ test_s3d_sphere_instance \ test_s3d_trace_ray \ test_s3d_trace_ray_instance \ test_s3d_trace_ray_sphere \ -: - $(CC) -o $@ src/$@.o $(LDFLAGS) -L$$(pwd) -ls3d $(RSYS_LIB) +: s3d-local.pc + $(CC) -o $@ src/$@.o $(LDFLAGS_$(BUILD_TYPE)) $(S3D_LIBS_$(LIB_TYPE)) -lm diff --git a/config.mk b/config.mk @@ -1,13 +1,18 @@ PREFIX = /usr/local -LIBSUFFIX = so # Shared library -#LIBSUFFIX = a # Static library +LIB_TYPE = SHARED +#LIB_TYPE = STATIC BUILD_TYPE = RELEASE #BUILD_TYPE = DEBUG +################################################################################ +# Tools +################################################################################ +AR = ar CC = cc PKG_CONFIG = pkg-config +RANLIB = ranlib ################################################################################ # Dependencies @@ -21,7 +26,7 @@ EMBREE_INC = $$($(PKG_CONFIG) --cflags embree4) EMBREE_LIB = $$($(PKG_CONFIG) --libs embree4) INCS=$(RSYS_INC) $(EMBREE_INC) -LIBS=$(RSYS_LIB) $(EMBREE_LIB) +LIBS=$(RSYS_LIB) $(EMBREE_LIB) -lm ################################################################################ # Compilation options @@ -49,4 +54,6 @@ CFLAGS_DEBUG = -g $(CFLAGS_COMMON) # Linker options ################################################################################ SOFLAGS = -shared -Wl,--no-undefined -LDFLAGS = + +LDFLAGS_DEBUG = +LDFLAGS_RELEASE = -s diff --git a/s3d.pc.in b/s3d.pc.in @@ -8,4 +8,5 @@ Name: Star-3D Description: Star-3D library Version: @VERSION@ Libs: -L${libdir} -ls3d +Libs.private: -lm CFlags: -I${includedir}