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 7040437fd26cab9f514423f6451eb891f62431a9
parent 3a937a09c54b33deccd487a90057e410c0c0bd87
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Sat,  6 May 2023 18:42:02 +0200

Rework the POSIX Makefile

The linker is no longer invoked with the list of useless CFLAGS. In
addition, the linker flags are now separated into 2 different macros:
- The SOFLAGS macro defines the flags when creating a shared object,
  i.e. a dynamic library.
- And the LDFLAGS macro defines the linker options for all linking
  operations, i.e. when creating a shared object or an executable

Add the BUILD_TYPE macro which controls if the compilation is done in
RELEASE or in DEBUG.

Move the VERSION macro from the config.mk file to the Makefile because
it is not a variable that the user should update for his needs.

Compile the tests directly in the src directory. This avoids the
explicit definition of the targets, which is a source of error as it is
easy to forget a test. Instead, we use the TEST_SRC variable to deduce
them from the sources by simply removing the "*.c" suffix.

Do not hide the compiler commands anymore (except for the file
dependency check). There is no particular advantage in doing this and it
is sane to see the compiler options used.

Diffstat:
MMakefile | 62++++++++++++++++++++------------------------------------------
Mconfig.mk | 30++++++++++++++++++++++--------
Mmake.sh | 36+++++++++++++++++++++++++-----------
3 files changed, 67 insertions(+), 61 deletions(-)

diff --git a/Makefile b/Makefile @@ -29,6 +29,8 @@ .POSIX: .SUFFIXES: # Clean up default inference rules +VERSION = 0.8.0 + include config.mk ################################################################################ @@ -46,7 +48,6 @@ SRC =\ src/s3d_scene_view_trace_ray.c\ src/s3d_shape.c\ src/s3d_sphere.c - OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) @@ -56,11 +57,9 @@ build_library: .config $(DEP) $(OBJ): config.mk libs3d.so: $(OBJ) - @echo "LD $@" - @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ) + $(CC) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(LIBS) .config: Makefile - @echo "Find packages" @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi @if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then \ @@ -69,11 +68,10 @@ libs3d.so: $(OBJ) .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) -std=c99 $(CFLAGS_$(BUILD_TYPE)) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - @echo "CC $@" - @$(CC) $(CFLAGS) $(INCS) -DS3D_SHARED_BUILD -c $< -o $@ + $(CC) -std=c99 $(CFLAGS_$(BUILD_TYPE)) $(INCS) -DS3D_SHARED_BUILD -c $< -o $@ ################################################################################ # Installation @@ -87,14 +85,11 @@ pkg: s3d.pc.in > s3d.pc install: build_library pkg - mkdir -p $(DESTDIR)$(PREFIX)/lib - mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig - mkdir -p $(DESTDIR)$(PREFIX)/include/star - mkdir -p $(DESTDIR)$(PREFIX)/share/doc/star-3d - cp libs3d.so $(DESTDIR)$(PREFIX)/lib - cp s3d.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig - cp src/s3d.h $(DESTDIR)$(PREFIX)/include/star - cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-3d + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" libs3d.so + @$(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 @@ -115,6 +110,9 @@ clean: clean_test distclean: clean @rm -f $(DEP) $(TEST_DEP) +lint: + @shellcheck -o all make.sh + ################################################################################ # Tests ################################################################################ @@ -136,16 +134,15 @@ TEST_SRC =\ src/test_s3d_trace_ray.c\ src/test_s3d_trace_ray_instance.c\ src/test_s3d_trace_ray_sphere.c - TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) -test: build_tests - @$(SHELL) make.sh run_test $(TEST_SRC) - build_tests: build_library $(TEST_DEP) .test @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + .test: Makefile @echo "Setup tests" @$(SHELL) make.sh config_test $(TEST_SRC) > .test @@ -153,27 +150,8 @@ build_tests: build_library $(TEST_DEP) .test clean_test: @$(SHELL) make.sh clean_test $(TEST_SRC) -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 \ -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 \ -: libs3d.so - @echo "LD $@" - @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -ls3d $(RSYS_LIB) - $(TEST_OBJ): config.mk - @echo "CC $@" - @$(CC) $(CFLAGS) $(RSYS_INC) -c $(@:.o=.c) -o $@ + $(CC) -std=c89 $(CFLAGS_$(BUILD_TYPE)) $(RSYS_INC) -c $(@:.o=.c) -o $@ + +$(TEST_OBJ:.o=): + $(CC) -o $@ $@.o $(LDFLAGS) -L$$(pwd) -ls3d $(RSYS_LIB) diff --git a/config.mk b/config.mk @@ -1,6 +1,12 @@ -VERSION = 0.8.0 # Library version - PREFIX = /usr/local + +LIBSUFFIX = so # Shared library +#LIBSUFFIX = a # Static library + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +CC = cc PKG_CONFIG = pkg-config ################################################################################ @@ -20,9 +26,6 @@ LIBS=$(RSYS_LIB) $(EMBREE_LIB) ################################################################################ # Compilation options ################################################################################ -CC = cc # Compiler - -CPPFLAGS = -DNDEBUG WFLAGS =\ -Wall\ -Wcast-align\ @@ -32,7 +35,18 @@ WFLAGS =\ -Wmissing-prototypes\ -Wshadow -CFLAGS = -O3 -std=c99 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\ - -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) # Compiler options +CFLAGS_COMMON =\ + -pedantic\ + -fPIC\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(WFLAGS) + +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) -LDFLAGS = -shared # Linker options +################################################################################ +# Linker options +################################################################################ +SOFLAGS = -shared -Wl,--no-undefined +LDFLAGS = diff --git a/make.sh b/make.sh @@ -31,25 +31,21 @@ config_test() { for i in "$@"; do - test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/') - test_list="${test_list} ${test}" - printf "%s: %s\n" "${test}" "src/${test}.o" + test=$(basename "${i}" ".c") + test_list="${test_list} src/${test}" + printf "%s: %s\n" "src/${test}" "src/${test}.o" done printf "test_bin: %s\n" "${test_list}" } check() { - if [ $# -lt 1 ]; then - echo "usage: check <name> <prog>" >&2 - exit 1 - fi - name="$1" prog="$2" shift 2 + printf "%s " "${name}" - if ./"${prog}" "$@" > /dev/null 2>&1; then + if ./src/"${prog}" "$@" > /dev/null 2>&1; then printf "\e[1;32mOK\e[m\n" else printf "\e[1;31mError\e[m\n" @@ -73,8 +69,26 @@ run_test() clean_test() { for i in "$@"; do - test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/') - rm -f "${test}" + rm -f "src/$(basename "${i}" ".c")" + done +} + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi done }