star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit 3fff1980723514fcfea153ea3a98d042566b05d5
parent 9352ba79e929e1e26841a18b89c8cf13904bde00
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  5 Mar 2025 14:25:05 +0100

Update the way tests are built

No longer depend on external scripting. 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, with no major impact on the clarity of the
Makefile. On the contrary, since everything is grouped together in the
same place.

In addition, compiler and linker options are now grouped together in
macros specific to the type of executable to be built: library or test.
This both makes compilation lines more compact, and avoids potential
problems, such as not using the same compiler options when link editing
"For predictable results, you must also specify the same set of options
used for compilation" (man gcc)

Diffstat:
M.gitignore | 2+-
MMakefile | 114++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mconfig.mk | 1-
Dmake.sh | 77-----------------------------------------------------------------------------
4 files changed, 74 insertions(+), 120 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,5 +1,5 @@ *~ -*.[abdo] +*.[adot] .config .test file.txt diff --git a/Makefile b/Makefile @@ -29,43 +29,50 @@ include config.mk LIBNAME = libsphin.so -default: build_library +default: library + +all: library tests -all: build_library build_tests ################################################################################ # Library building ################################################################################ -SRC = \ - src/sphin.c \ - src/sphin_brdf.c \ - src/sphin_config.c \ - src/sphin_geometry.c \ - src/sphin_sensor.c \ - src/sphin_source.c \ - src/sphin_surface.c \ - src/sphin_volume.c +SRC =\ + src/sphin.c\ + src/sphin_brdf.c\ + src/sphin_config.c\ + src/sphin_geometry.c\ + src/sphin_sensor.c\ + src/sphin_source.c\ + src/sphin_surface.c\ + src/sphin_volume.c OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) -build_library: .config $(DEP) - @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) $(LIBNAME) +# Compiler and linker options to build the library +CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DSPHIN_SHARED_BUILD +LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) + +library: .config $(DEP) + @$(MAKE) -fMakefile \ + $$(for i in $(DEP); do echo -f "$${i}"; done) \ + $(LIBNAME) $(DEP) $(OBJ): config.mk $(LIBNAME): $(OBJ) - $(CC) $(CFLAGS_SO) $(INCS) -o $@ $(OBJ) $(LDFLAGS_SO) $(LIBS) + $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) .config: config.mk $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys - $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl + $(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl echo "config done" > $@ .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS_SO) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) $(CFLAGS_SO) $(INCS) -DSPHIN_SHARED_BUILD -c $< -o $@ + $(CC) $(CFLAGS_LIB) -c $< -o $@ ################################################################################ # Installation @@ -91,9 +98,8 @@ install: uninstall: clean: clean_test - rm -f file.txt sphin-local.pc sphin.pc .test test_0.stl test_1.stl test_2.stl test_3.stl - rm -f $(OBJ) $(LIBNAME) $(TEST_OBJ) $(TEST_DEP) $(DEP) .config - + rm -f $(DEP) $(OBJ) $(LIBNAME) + rm -f .config sphin-local.pc sphin.pc ################################################################################ # Tests @@ -104,31 +110,57 @@ TEST_SRC =\ src/test_sphin_load_volume.c TEST_OBJ = $(TEST_SRC:.c=.o) TEST_DEP = $(TEST_SRC:.c=.d) +TEST_TGT = $(TEST_SRC:.c=.t) PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) -SPHIN_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sphin-local.pc) -SPHIN_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sphin-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 - -test: build_tests - @$(SHELL) make.sh run_test $(TEST_SRC) - -.test: Makefile - @$(SHELL) make.sh config_test $(TEST_SRC) > $@ - -clean_test: - $(SHELL) make.sh clean_test $(TEST_SRC) +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sphin-local) +LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sphin-local) -lm + +# Compiler and linker options to build the tests +CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) + +test: tests + @err=0; \ + for i in $(TEST_SRC); do \ + test="$$(basename "$${i}" ".c")"; \ + printf '%s' "$${test}"; \ + if "./$${test}" > /dev/null 2>&1; then \ + printf '\n'; \ + else \ + printf ': error %s\n' "$$?"; \ + err=$$((err+1)); \ + fi \ + done; \ + [ "$${err}" -eq 0 ] + + +tests: library $(TEST_DEP) $(TEST_TGT) + @$(MAKE) -f Makefile \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ + test_list + +$(TEST_TGT): + @{ \ + exe="$$(basename "$@" ".t")"; \ + printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ + printf 'test_list: %s\n' "$${exe}"; \ + } > $@ $(TEST_DEP): config.mk sphin-local.pc - @$(CC) -std=c89 $(CFLAGS_EXE) $(INCS) $(SPHIN_CFLAGS) \ - -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ $(TEST_OBJ): config.mk sphin-local.pc - $(CC) -std=c89 $(CFLAGS_EXE) $(INCS) $(SPHIN_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ -test_sphin\ -test_sphin_load_surface\ -test_sphin_load_volume: config.mk sphin-local.pc $(LIBNAME) - $(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SPHIN_LIBS) $(LIBS) -lm +test_sphin \ +test_sphin_load_surface \ +test_sphin_load_volume \ +: config.mk sphin-local.pc $(LIBNAME) + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) + +clean_test: + rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) + rm -f file.txt test_0.stl test_1.stl test_2.stl test_3.stl + for i in $(TEST_SRC); do rm -f "$$(basename "$${i})" ".c")"; done diff --git a/config.mk b/config.mk @@ -46,7 +46,6 @@ CFLAGS_HARDENED =\ -fstack-protector-strong CFLAGS_COMMON =\ - -std=c99\ -pedantic\ -fvisibility=hidden\ -fstrict-aliasing\ diff --git a/make.sh b/make.sh @@ -1,77 +0,0 @@ -# Copyright (C) 2024 Centre National de la Recherche Scientifique -# Copyright (C) 2024 Clermont Auvergne INP -# Copyright (C) 2024 INSA Lyon -# Copyright (C) 2024 Institut Mines Télécom Albi-Carmaux -# Copyright (C) 2024 Institut National Polytechnique de Toulouse -# Copyright (C) 2024 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2024 PhotonLyX (info@photonlyx.com) -# Copyright (C) 2024 Université de Lorraine -# Copyright (C) 2024 Université Paul Sabatier -# Copyright (C) 2024 Université Toulouse - Jean Jaurès -# -# 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: src/%s.o\n" "${test}" "${test}" - 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 -} - -"$@"