star-uvm

Spatial structuring of unstructured volumetric meshes
git clone git://git.meso-star.fr/star-uvm.git
Log | Files | Refs | README | LICENSE

commit 51045b63e4763ab9a5c19622d83e1f71984c0ab0
parent 3a2deb29bcf559cd393981cbc5167683f3604901
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 20 Feb 2025 16:50:31 +0100

Rewriting the Makefile

Delete the make.sh script. It implemented functions which, while
contributing to the clarity of the Makefile, made the build system less
compact. All these functions can be implemented with just a few lines of
shell code, without any major impact on the clarity of the Makefile.
Perhaps on the contrary, since it's all in one place.

The construction of the suvm-voxelize utility has been rewritten. It is
no longer built as a test, but as part of the "utils" target, which the
user can now activate with the ADDONS macro. Its name has also been
updated: the '_' character has been replaced by the '-' character, more
common in executable names than the underscore character.

Diffstat:
M.gitignore | 17++++++++---------
MMakefile | 174++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mconfig.mk | 28++++++++++++++--------------
Mdoc/suvm-voxelize.1 | 4++--
Dmake.sh | 70----------------------------------------------------------------------
Msrc/suvm_voxelize.c | 2+-
6 files changed, 136 insertions(+), 159 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,14 +1,13 @@ -.gitignore -[Bb]uild* -*.sw[po] +*~ *.[aod] +.config +.config_utils +.gitignore +*.pc *.so -*~ +suvm-voxelize +*.sw[po] +tags test* !test*.[ch] -.config -.test -tags -*.pc *.vtk -suvm_voxelize diff --git a/Makefile b/Makefile @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. */ .POSIX: -.SUFFIXES: # Clean up default inference rules +.SUFFIXES: .b .c .d .o include config.mk @@ -22,6 +22,9 @@ LIBNAME_STATIC = libsuvm.a LIBNAME_SHARED = libsuvm.so LIBNAME = $(LIBNAME_$(LIB_TYPE)) +default: library $(ADDONS) +all: default tests + ################################################################################ # Library building ################################################################################ @@ -34,7 +37,7 @@ SRC =\ OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) -build_library: .config $(DEP) +library: .config $(DEP) @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ $$(if [ -n "$(LIBNAME)" ]; then\ echo "$(LIBNAME)";\ @@ -45,7 +48,7 @@ build_library: .config $(DEP) $(DEP) $(OBJ): config.mk $(LIBNAME_SHARED): $(OBJ) - $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + $(CC) -std=c99 $(CFLAGS_SO) $(INCS) -o $@ $(OBJ) $(LDFLAGS_SO) $(LIBS) $(LIBNAME_STATIC): libsuvm.o $(AR) -rc $@ $? @@ -56,18 +59,19 @@ libsuvm.o: $(OBJ) $(OBJCOPY) $(OCPFLAGS) $@ .config: config.mk - @if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then \ - echo "embree4 $(EMBREE_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ - echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4 + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys @echo "config done" > $@ -.SUFFIXES: .c .d .o .c.d: - @$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) -std=c99 $(CFLAGS_SO) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -DSUVM_SHARED_BUILD -c $< -o $@ + $(CC) -std=c99 $(CFLAGS_SO) $(INCS) -DSUVM_SHARED_BUILD -c $< -o $@ + +clean: clean_test clean_utils + rm -f $(DEP) $(OBJ) $(LIBNAME) + rm -f .config libsuvm.o suvm.pc suvm-local.pc ################################################################################ # Installation @@ -88,34 +92,81 @@ suvm-local.pc: suvm.pc.in -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ suvm.pc.in > $@ -install: build_library pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" suvm.pc - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/suvm.h - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-uvm" COPYING README.md - -uninstall: - rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" - rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/suvm.pc" - rm -f "$(DESTDIR)$(PREFIX)/include/star/suvm.h" +install: library pkg $(INSTALL_$(ADDON)) + mkdir -p "$(DESTDIR)$(INCPREFIX)/star" + mkdir -p "$(DESTDIR)$(LIBPREFIX)" + mkdir -p "$(DESTDIR)$(LIBPREFIX)/pkgconfig" + mkdir -p "$(DESTDIR)$(PREFIX)/share/doc/star-uvm" + cp $(LIBNAME) "$(DESTDIR)$(LIBPREFIX)" + cp suvm.pc "$(DESTDIR)$(LIBPREFIX)/pkgconfig" + cp src/suvm.h "$(DESTDIR)$(INCPREFIX)/star" + cp COPYING README.md "$(DESTDIR)$(PREFIX)/share/doc/star-uvm" + chmod 755 "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + chmod 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig/suvm.pc" + chmod 644 "$(DESTDIR)$(INCPREFIX)/star/suvm.h" + chmod 644 "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/COPYING" + chmod 644 "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/README.md" + @for i in $(ADDONS); do $(MAKE) -fMakefile install_"$${i}"; done + +uninstall: uninstall_utils + rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/suvm.pc" + rm -f "$(DESTDIR)$(INCPREFIX)/star/suvm.h" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uvm/README.md" -################################################################################ -# Miscellaneous targets -################################################################################ -all: build_library build_tests +lint: lint_utils -clean: clean_test - rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) - rm -f .config .test libsuvm.o suvm.pc suvm-local.pc - rm -f ball.vtk box.vtk +################################################################################# +# Utils +################################################################################# +UTIL_SRC = src/suvm_voxelize.c +UTIL_OBJ = $(UTIL_SRC:.c=.o) +UTIL_DEP = $(UTIL_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) -distclean: clean - rm -f $(DEP) $(TEST_DEP) +INCS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys smsh suvm-local.pc) +LIBS_UTIL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys smsh suvm-local.pc) -lm + +CFLAGS_UTIL = -std=c89 $(CFLAGS_EXE) $(INCS_UTIL) +LDFLAGS_UTIL = $(LDFLAGS_EXE) $(LIBS_UTIL) + +utils: library .config_utils + @$(MAKE) $(UTIL_DEP); \ + $(MAKE) -f Makefile -f src/suvm_voxelize.d suvm-voxelize + +.config_utils: config.mk + $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh + @echo "config done" > $@ + +src/suvm_voxelize.d: config.mk suvm-local.pc + @$(CC) -std=c89 $(CFLAGS_UTIL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/suvm_voxelize.o: config.mk suvm-local.pc + $(CC) -std=c89 $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@ -lint: - shellcheck -o all make.sh +suvm-voxelize: config.mk suvm-local.pc $(LIBNAME) src/suvm_voxelize.o + $(CC) -std=c89 $(CFLAGS_UTIL) -o $@ src/suvm_voxelize.o $(LDFLAGS_UTIL) + +clean_utils: + rm -f $(UTIL_DEP) $(UTIL_OBJ) suvm-voxelize + rm -f .config_utils + +install_utils: utils + mkdir -p "$(DESTDIR)$(BINPREFIX)" + mkdir -p "$(DESTDIR)$(MANPREFIX)/man1" + cp suvm-voxelize "$(DESTDIR)$(BINPREFIX)" + cp suvm-voxelize.1 "$(DESTDIR)$(MANPREFIX)/man1/" + chmod 755 "$(DESTDIR)$(BINPREFIX)/suvm-voxelize" + chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/suvm-voxelize.1" + +uninstall_utils: + rm -f "$(DESTDIR)$(BINPREFIX)/suvm-voxelize" + rm -f "$(DESTDIR)$(MANPREFIX)/man1/suvm-voxelize.1" + +lint_utils: + mandoc -Tlint -Wall doc/suvm-voxelize.1 || [ $$? -le 1 ] ################################################################################ # Tests @@ -126,51 +177,48 @@ TEST_SRC =\ src/test_suvm_primitive_intersection.c TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) +TEST_BIN = $(TEST_SRC:.c=.b) -SMSH_FOUND = $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys suvm-local.pc) +LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys suvm-local.pc) -lm -PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) -SUVM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags suvm-local.pc) -SUVM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs suvm-local.pc) +CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) + +test: tests + @for i in $(TEST_SRC); do \ + bin="$$(basename "$${i}" ".c")"; \ + "./$${bin}" > /dev/null 2>&1 \ + || >&2 printf '%s: error %s\n' "$${bin}" "$$?"; \ + done + @echo "Tests done" -build_tests: build_library $(TEST_DEP) .test - @if $(SMSH_FOUND); then $(MAKE) src/suvm_voxelize.d; fi; \ - $(MAKE) -fMakefile -f.test \ +tests: library $(TEST_DEP) $(TEST_BIN) + @$(MAKE) -fMakefile \ $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ - $$($(SMSH_FOUND) && echo "-fsrc/suvm_voxelize.d") \ + $$(for i in $(TEST_BIN); do echo -f"$${i}"; done) \ test_bin -test: build_tests - @$(SHELL) make.sh run_test $(TEST_SRC) - -.test: Makefile - @{ $(SHELL) make.sh config_test $(TEST_SRC); \ - if $(SMSH_FOUND); then \ - $(SHELL) make.sh config_test src/suvm_voxelize.c; fi \ +.c.b: + @{ \ + bin="$$(basename "$<" ".c")"; \ + printf '%s: %s\n' "$${bin}" $(<:.c=.o); \ + printf 'test_bin: %s\n' "$${bin}"; \ } > $@ -clean_test: - $(SHELL) make.sh clean_test $(TEST_SRC) src/suvm_voxelize.c - $(TEST_DEP): config.mk suvm-local.pc - @$(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) \ - -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ - -src/suvm_voxelize.d: config.mk suvm-local.pc - @$(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) $(SMSH_CFLAGS) \ - -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ $(TEST_OBJ): config.mk suvm-local.pc - $(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) -c $(@:.o=.c) -o $@ - -src/suvm_voxelize.o: config.mk suvm-local.pc - $(CC) -std=c89 $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SUVM_CFLAGS) $(SMSH_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ test_suvm_device \ test_suvm_volume \ test_suvm_primitive_intersection \ : config.mk suvm-local.pc $(LIBNAME) - $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SUVM_LIBS) $(RSYS_LIBS) -lm + $(CC) -std=c89 $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) -suvm_voxelize: config.mk suvm-local.pc $(LIBNAME) - $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SUVM_LIBS) $(RSYS_LIBS) $(SMSH_LIBS) -lm +clean_test: + rm -f $(TEST_BIN) $(TEST_DEP) $(TEST_OBJ) + rm -f ball.vtk box.vtk + for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done diff --git a/config.mk b/config.mk @@ -4,8 +4,17 @@ PREFIX = /usr/local LIB_TYPE = SHARED #LIB_TYPE = STATIC -BUILD_TYPE = RELEASE -#BUILD_TYPE = DEBUG +#BUILD_TYPE = RELEASE +BUILD_TYPE = DEBUG + +BINPREFIX = $(PREFIX)/bin +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include/stardis +MANPREFIX = $(PREFIX)/share/man + +# Define additional targets +# Comment it to build and install the library only +#ADDONS = utils ################################################################################ # Tools @@ -24,20 +33,11 @@ PCFLAGS_STATIC = --static PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) EMBREE_VERSION = 4.0 -EMBREE_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags embree4) -EMBREE_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs embree4) - RSYS_VERSION = 0.14 -RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) -RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) - -# Optional (required only by suvm_voxelize tool) -SMSH_VERSION = 0.1 -SMSH_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags smsh) -SMSH_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs smsh) +SMSH_VERSION = 0.1 # Optional (required by utils) -DPDC_CFLAGS = $(EMBREE_CFLAGS) $(RSYS_CFLAGS) -DPDC_LIBS = $(EMBREE_LIBS) $(RSYS_LIBS) -lm +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags embree4 rsys) +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs embree4 rsys) -lm ################################################################################ # Compilation options diff --git a/doc/suvm-voxelize.1 b/doc/suvm-voxelize.1 @@ -14,11 +14,11 @@ .\" along with this program. If not, see <http://www.gnu.org/licenses/>. .Dd February 20, 2025 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -.Dt SUVM_VOXELIZE 1 +.Dt SUVM-VOXELIZE 1 .Os .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh NAME -.Nm suvm_voxelize +.Nm suvm-voxelize .Nd voxelize a tetrahedral mesh .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh SYNOPSIS diff --git a/make.sh b/make.sh @@ -1,70 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2020-2023 |Méso|Star> (contact@meso-star.com) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -set -e - -config_test() -{ - for i in "$@"; do - test=$(basename "${i}" ".c") - test_list="${test_list} ${test}" - printf "%s: %s\n" "${test}" "src/${test}.o" - done - printf "test_bin: %s\n" "${test_list}" -} - -run_test() -{ - for i in "$@"; do - test=$(basename "${i}" ".c") - - printf "%s " "${test}" - if "./${test}" > /dev/null 2>&1; then - printf "\033[1;32mOK\033[m\n" - else - printf "\033[1;31mError\033[m\n" - fi - done 2> /dev/null -} - -clean_test() -{ - for i in "$@"; do - rm -f "$(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 -} - -"$@" diff --git a/src/suvm_voxelize.c b/src/suvm_voxelize.c @@ -49,7 +49,7 @@ static INLINE void usage(FILE* stream) { fprintf(stream, - "usage: suvm_voxelize [-hnv] [-d x,y,z] [-o output] [input]\n"); + "usage: suvm-voxelize [-hnv] [-d x,y,z] [-o output] [input]\n"); } static void