star-schiff

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

commit bd09b0edcf81dc3e2cc81c3c2d955ffac4911a39
parent dddb6d83cfc96380cff1db18415967ddc629e33b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 12 Oct 2023 12:06:19 +0200

Write a POSIX Makefile to replace CMake

The build procedure is written in POSIX make, which the user can
configure via the config.mk file. The make.sh script contains commands
that could be found directly in POSIX make, but which are placed here to
simplify writing the Makefile. Finally, a pkg-config file is provided to
link the library as an external dependency.

In addition to the features already provided in its CMake alternative,
this Makefile supports the construction of static libraries and provides
an uninstall target. In any case, the main motivation behind its writing
is to use a good old well-established standard with simple features,
available on all UNIX systems, thus simplifying its portability and
support while being much lighter.

Diffstat:
M.gitignore | 15++++++++-------
AMakefile | 169+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig.mk | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asschiff.pc.in | 15+++++++++++++++
5 files changed, 344 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,11 +1,12 @@ +.config .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp -[Bb]uild* +.test +*.[aod] +*.pc +*.so *.sw[po] -*.[ao] *~ +[Bb]uild* tags - +test* +!test*.[ch] diff --git a/Makefile b/Makefile @@ -0,0 +1,169 @@ +# Copyright (C) 2020, 2021 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2015, 2016 CNRS +# +# 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/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libsschiff.a +LIBNAME_SHARED = libsschiff.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Star-3D building +################################################################################ +SRC =\ + src/sschiff_device.c\ + src/sschiff_estimator.c\ + src/sschiff_scattering_angles_distributions.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) \ + $$(if [ -n "$(LIBNAME)" ]; then \ + echo "$(LIBNAME)"; \ + else \ + echo "$(LIBNAME_SHARED)"; \ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS) + +$(LIBNAME_STATIC): libsschiff.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libsschiff.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(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" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS) $(DPDC_CFLAGS) -DSSCHIFF_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@GSL_VERSION@#$(GSL_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ + -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ + sschiff.pc.in > sschiff.pc + +sschiff-local.pc: sschiff.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@GSL_VERSION@#$(GSL_VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ + -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 + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sschiff.pc" + 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 + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_sschiff_device.c\ + src/test_sschiff_estimator_cylinder.c\ + src/test_sschiff_estimator_rhodo.c\ + src/test_sschiff_estimator_sphere.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +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 + +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + +.test: Makefile + @$(SHELL) make.sh config_test $(TEST_SRC) > .test + +clean_test: + @$(SHELL) make.sh clean_test $(TEST_SRC) + +$(TEST_DEP): config.mk sschiff-local.pc + @$(CC) $(CFLAGS) $(TEST_DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ): config.mk sschiff-local.pc + $(CC) $(CFLAGS) $(TEST_DPDC_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sschiff_device\ +test_sschiff_estimator_cylinder\ +test_sschiff_estimator_rhodo\ +test_sschiff_estimator_sphere\ +: config.mk sschiff-local.pc $(LIBNAME) + $(CC) -o $@ src/$@.o $(LDFLAGS) $(TEST_DPDC_LIBS) diff --git a/config.mk b/config.mk @@ -0,0 +1,81 @@ +VERSION = 0.4.1 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +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 + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fPIC\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(WFLAGS) + +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +################################################################################ +# Linker options +################################################################################ +SOFLAGS = -shared -Wl,--no-undefined + +LDFLAGS_DEBUG = +LDFLAGS_RELEASE = -s +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# Copyright (C) 2020, 2021 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2015, 2016 CNRS +# +# 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 +} + +"$@" diff --git a/sschiff.pc.in b/sschiff.pc.in @@ -0,0 +1,15 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Requires.private:\ + gsl >= @GSL_VERSION@,\ + s3d >= @S3D_VERSION@,\ + star-sp >= @SSP_VERSION@ +Name: Star Schiff +Description: Star Schiff library +Version: @VERSION@ +Libs: -L${libdir} -lsschiff +Libs.private: -lm -fopenmp +CFlags: -I${includedir}