star-schiff

Library for estimating radiative properties
git clone git://git.meso-star.com/star-schiff.git
Log | Files | Refs | README | LICENSE

commit bd3891b42e548e0f239c3c3610bc808df56bd31e
parent 82c77fb069073aae8fa264f1916791f631e2c3f5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 13 May 2026 14:53:26 +0200

Several updates to 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.

Add the LIBPREFIX and INCPREFIX macros to control the subdirectories
into which libraries and header files are copied. Systems may use
locations other than those proposed by default.

Remove the "distclean" Makefile target. In fact, it does the wrong
thing. distclean, in addition to a normal cleanup target, should also
delete files created by a dist target, i.e.  a target generating files
for distribution, such as a compressed archive. But it was used to
delete automatically generated dependency files. These files can simply
be removed by normal cleanup. What's more, as the project is designed to
be installed by compiling its sources directly, no distribution target
is implemented, so no distclean is required.

Dependencies are grouped in the INCS and LIBS macros using a single call
to the pkg-config program. In the Makefile, the CFLAGS and LDFLAGS
variables for the library and tests have been written into their own
macro to make the command lines more compact.

Dependency checking is now performed with as few call to pkg-config,
without any additional code, because displaying a hand-written error
message adds no value to the clarity of what is being done and what
happens in case of missing dependencies.

Diffstat:
MMakefile | 125+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Mconfig.mk | 18+++++-------------
Dmake.sh | 71-----------------------------------------------------------------------
3 files changed, 76 insertions(+), 138 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2020, 2021 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2020, 2021, 2023 |Meso|Star> (contact@meso-star.com) # Copyright (C) 2015, 2016 CNRS # # This program is free software: you can redistribute it and/or modify @@ -23,6 +23,9 @@ LIBNAME_STATIC = libsschiff.a LIBNAME_SHARED = libsschiff.so LIBNAME = $(LIBNAME_$(LIB_TYPE)) +default: library +all: default tests + ################################################################################ # Star-3D building ################################################################################ @@ -33,7 +36,10 @@ SRC =\ OBJ = $(SRC:.c=.o) DEP = $(SRC:.c=.d) -build_library: .config $(DEP) +CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DSSCHIFF_SHARED_BUILD +LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) + +library: .config $(DEP) @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) \ $$(if [ -n "$(LIBNAME)" ]; then \ echo "$(LIBNAME)"; \ @@ -44,7 +50,7 @@ build_library: .config $(DEP) $(DEP) $(OBJ): config.mk $(LIBNAME_SHARED): $(OBJ) - $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) $(LIBNAME_STATIC): libsschiff.o $(AR) -rc $@ $? @@ -55,22 +61,18 @@ libsschiff.o: $(OBJ) $(OBJCOPY) $(OCPFLAGS) $@ .config: Makefile config.mk - @if ! $(PKG_CONFIG) --atleast-version $(GSL_VERSION) gsl; then \ - echo "gsl $(GSL_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 - @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then \ - echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi - @if ! $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp; then \ - echo "star-sp $(SSP_VERSION) not found" >&2; exit 1; fi - @echo "config done" > $@ + $(PKG_CONFIG) --atleast-version $(GSL_VERSION) gsl + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d + $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp + echo "config done" > $@ .SUFFIXES: .c .d .o .c.d: - @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DSSCHIFF_SHARED_BUILD -c $< -o $@ + $(CC) $(CFLAGS_LIB) -c $< -o $@ ################################################################################ # Installation @@ -95,34 +97,30 @@ sschiff-local.pc: sschiff.pc.in -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ sschiff.pc.in > $@ -install: build_library pkg - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" sschiff.pc - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sschiff.h - @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-schiff"\ - COPYING README.md +install: library pkg + install() { mode="$$1"; prefix="$$2"; shift 2; \ + mkdir -p "$${prefix}"; \ + cp "$$@" "$${prefix}"; \ + printf '%s\n' "$${@}" | while read -r i; do \ + chmod "$${mode}" "$${prefix}/$${i##*/}"; \ + done; \ + }; \ + if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \ + install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" sschiff.pc; \ + install 644 "$(DESTDIR)$(INCPREFIX)/star" src/sschiff.h; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-schiff" COPYING README.md uninstall: - rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" - rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sschiff.pc" + rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sschiff.pc" + rm -f "$(DESTDIR)$(INCPREFIX)/star/sschiff.h" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-schiff/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-schiff/README.md" - rm -f "$(DESTDIR)$(PREFIX)/include/star/sschiff.h" - -################################################################################ -# Miscellaneous targets -################################################################################ -all: build_library build_tests clean: clean_test - rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) - rm -f .config .test sschiff.pc sschiff-local.pc libsschiff.o - -distclean: clean - rm -f $(DEP) $(TEST_DEP) - -lint: - shellcheck -o all make.sh + rm -f $(OBJ) $(DEP) $(LIBNAME) + rm -f .config libsschiff.o sschiff.pc sschiff-local.pc ################################################################################ # Tests @@ -134,36 +132,55 @@ TEST_SRC =\ src/test_sschiff_estimator_sphere.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) -SSCHIFF_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sschiff-local.pc) -SSCHIFF_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs sschiff-local.pc) - -TEST_DPDC_CFLAGS = $(RSYS_CFLAGS) $(S3D_CFLAGS) $(SSP_CFLAGS) $(SSCHIFF_CFLAGS) -TEST_DPDC_LIBS = $(RSYS_LIBS) $(S3D_LIBS) $(SSP_LIBS) $(SSCHIFF_LIBS) -lm - -build_tests: build_library $(TEST_DEP) .test - @$(MAKE) -fMakefile -f.test \ - $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys s3d star-sp sschiff-local) +LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys s3d star-sp sschiff-local) -lm -test: build_tests - @$(SHELL) make.sh run_test $(TEST_SRC) +CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) -.test: Makefile - @$(SHELL) make.sh config_test $(TEST_SRC) > .test +tests: library $(TEST_DEP) $(TEST_TGT) + @$(MAKE) -fMakefile \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + $$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \ + test_list -clean_test: - @$(SHELL) make.sh clean_test $(TEST_SRC) +$(TEST_TGT): + @{ \ + exe="$$(basename "$@" ".t")"; \ + printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ + printf 'test_list: %s\n' "$${exe}"; \ + } > $@ $(TEST_DEP): config.mk sschiff-local.pc - @$(CC) $(CFLAGS_EXE) $(TEST_DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ $(TEST_OBJ): config.mk sschiff-local.pc - $(CC) $(CFLAGS_EXE) $(TEST_DPDC_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ + +clean_test: + rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) mixture.txt + for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done test_sschiff_device\ test_sschiff_estimator_cylinder\ test_sschiff_estimator_rhodo\ test_sschiff_estimator_sphere\ : config.mk sschiff-local.pc $(LIBNAME) - $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(TEST_DPDC_LIBS) + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_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 ] diff --git a/config.mk b/config.mk @@ -1,5 +1,8 @@ VERSION = 0.4.1 + PREFIX = /usr/local +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include LIB_TYPE = SHARED #LIB_TYPE = STATIC @@ -25,23 +28,12 @@ PCFLAGS_STATIC = --static PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) GSL_VERSION = 2.4 -GSL_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags gsl) -GSL_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs gsl) - RSYS_VERSION = 0.8 -RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) -RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) - S3D_VERSION = 0.8 -S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d) -S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d) - SSP_VERSION = 0.12 -SSP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags star-sp) -SSP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs star-sp) -DPDC_CFLAGS=$(GSL_CFLAGS) $(RSYS_CFLAGS) $(S3D_CFLAGS) $(SSP_CFLAGS) -fopenmp -DPDC_LIBS=$(GSL_LIBS) $(RSYS_LIBS) $(S3D_LIBS) $(SSP_LIBS) -lm -fopenmp +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags gsl rsys s3d star-sp) -fopenmp +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs gsl rsys s3d star-sp) -fopenmp -lm ################################################################################ # Compilation options diff --git a/make.sh b/make.sh @@ -1,71 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2020, 2021, 2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2015, 2016 Centre National de la Recherche Scientfique -# -# 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 "\e[1;32mOK\e[m\n" - else - printf "\e[1;31mError\e[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 -} - -"$@"