solstice-anim

Geometry animation library of the solstice app
git clone git://git.meso-star.com/solstice-anim.git
Log | Files | Refs | README | LICENSE

commit e1750f8ebcb57ca73a008e69b6a052c125af540e
parent 13f7534a321f2c291b92c4a6daa4ab23d9269f6c
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 13 May 2026 16:57:23 +0200

Replace CMake with a POSIX Makefile

The build procedure is written in POSIX make and can be configured via
the config.mk file. A pkg-config file is also provided to link the
library as an external dependency.

Compared to the CMake alternative, this Makefile adds support for static
libraries and an uninstall target. It also enables compiler and linker
flags for various hardening features, improving the security and
robustness of generated binaries. More broadly, the motivation for this
rewrite is to rely on a well-established standard with a simple feature
set, available on all UNIX systems - reducing portability concerns and
maintenance burden while remaining significantly lighter.

Diffstat:
M.gitignore | 12+++++++-----
AMakefile | 209+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dcmake/CMakeLists.txt | 116-------------------------------------------------------------------------------
Aconfig.mk | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asanim.pc.in | 12++++++++++++
Asrc/sanim_version.h.in | 23+++++++++++++++++++++++
6 files changed, 335 insertions(+), 121 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,14 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aodt] *.orig +*.so *~ tags - +*.pc +test_sanim_* +!test_sanim_*.[ch] +src/sanim_version.h +src/.config* diff --git a/Makefile b/Makefile @@ -0,0 +1,209 @@ +# Copyright (C) 2016-2018 CNRS, 2018-2026 |Meso|Star> +# +# 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 = libsanim.a +LIBNAME_SHARED = libsanim.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +default: library +all: default tests + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/sanim_node.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +# Headers to configure +HDR=\ + src/sanim_version.h + +CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DSANIM_SHARED_BUILD +LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS) + +$(LIBNAME_SHARED) $(DEP) $(OBJ): src/.config + +library: $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then \ + echo "$(LIBNAME)"; \ + else \ + echo "$(LIBNAME_SHARED)"; \ + fi) + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB) + +$(LIBNAME_STATIC): src/libsanim.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +src/libsanim.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +src/.config: config.mk + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + @echo "config done" > $@ + +$(DEP) : $(HDR) src/sanim.pc + @$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(OBJ) : $(HDR) src/sanim.pc + $(CC) $(CFLAGS_LIB) -c $(@:.o=.c) -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: src/sanim.pc + +src/sanim.pc: sanim.pc.in src/.config + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + sanim.pc.in > $@ + +src/sanim_version.h: src/sanim_version.h.in src/.config + sed -e 's#@VERSION_MAJOR@#$(VERSION_MAJOR)#g' \ + -e 's#@VERSION_MINOR@#$(VERSION_MINOR)#g' \ + -e 's#@VERSION_PATCH@#$(VERSION_PATCH)#g' \ + src/sanim_version.h.in > $@ + +install: library pkg + install() { mode="$$1"; prefix="$$2"; shift 2; \ + mkdir -p "$${prefix}"; \ + cp "$$@" "$${prefix}"; \ + chmod "$${mode}" "$${prefix}/$${@##*/}"; \ + }; \ + if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \ + install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" src/sanim.pc; \ + install 644 "$(DESTDIR)$(INCPREFIX)/solstice" src/sanim.h; \ + install 644 "$(DESTDIR)$(INCPREFIX)/solstice" src/sanim_version.h; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/solstice-anim" COPYING; \ + install 644 "$(DESTDIR)$(PREFIX)/share/doc/solstice-anim" README.md + +uninstall: + rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sanim.pc" + rm -f "$(DESTDIR)$(INCPREFIX)/solstice/sanim.h" + rm -f "$(DESTDIR)$(INCPREFIX)/solstice/sanim_version.h" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/solstice-anim/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/solstice-anim/README.md" + +clean: clean_test + rm -f $(HDR) $(DEP) $(OBJ) $(LIBNAME) + rm -f src/.config src/.config_test src/libsanim.o src/sanim.pc + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_sanim_node.c\ + src/test_sanim_node_pivot.c\ + src/test_sanim_node_transform.c\ + src/test_sanim_search.c\ + src/test_sanim_visit.c +TEST_OBJ =\ + $(TEST_SRC:.c=.o)\ + src/test_sanim_utils.o +TEST_DEP =\ + $(TEST_SRC:.c=.d)\ + src/test_sanim_utils.d +TEST_TGT =\ + $(TEST_SRC:.c=.t)\ + src/test_sanim_utils.t + +src/sanim-local.pc: sanim.pc.in config.mk + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + sanim.pc.in > $@ + +# Regular cflags +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="src:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sanim-local) +LIBS_TEST = src/test_sanim_utils.o\ + $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sanim-local)\ + -lm + +tests: library src/sanim-local.pc $(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 + +$(TEST_TGT): + @{ \ + exe="$$(basename "$@" ".t")"; \ + printf '%s: %s\n' "$${exe}" $(@:.t=.o); \ + printf 'test_list: %s\n' "$${exe}"; \ + } > $@ + +src/.config_test: config.mk + $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys + @echo "config done" > $@ + +clean_test: + rm -f src/sanim-local.pc src/.config_test + for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done + rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) + +test: tests + @err=0; \ + check() { name="$$1"; prog="$$2"; shift 2; \ + printf '%s' "$${name}"; \ + if PATH=./:"$${PATH}" "$${prog}" $$@ > /dev/null 2>&1; then \ + printf '\n'; \ + else \ + printf ': error %s\n' "$$?"; \ + err=$$((err+1)); \ + fi; \ + }; \ + \ + for i in $(TEST_SRC); do \ + test="$$(basename "$${i}" ".c")"; \ + check "$${test}" "$${test}"; \ + done; \ + \ + [ "$${err}" -eq 0 ] + +################################################################################ +# Regular tests +################################################################################ +CFLAGS_TEST = $(CFLAGS_EXE) $(INCS_TEST) +LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) + +$(TEST_DEP) : src/.config_test src/sanim-local.pc + @$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +$(TEST_OBJ) : src/.config_test src/sanim-local.pc + $(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@ + +test_sanim_node\ +test_sanim_node_pivot\ +test_sanim_node_transform\ +test_sanim_search\ +test_sanim_visit\ +: config.mk src/sanim-local.pc $(LIBNAME) src/test_sanim_utils.o + $(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,116 +0,0 @@ -# Copyright (C) 2018, 2020, 2021 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2016, 2017 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/>. - -cmake_minimum_required(VERSION 3.1) -project(solstice-anim C) -enable_testing() - -set(SANIM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.10 REQUIRED) -find_package(OpenMP 1.2 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories( - ${RSys_INCLUDE_DIR}) - -rcmake_append_runtime_dirs(_runtime_dirs RSys) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 2) -set(VERSION_PATCH 4) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(SANIM_FILES_SRC - sanim_node.c) - -set(SANIM_FILES_INC_API - sanim.h) - -set(SANIM_FILES_INC - sanim_node_c.h) - -set(SANIM_FILES_DOC COPYING README.md) - -# Prepend each file in the `SANIM_FILES_<SRC|INC>' list by `SANIM_SOURCE_DIR' -rcmake_prepend_path(SANIM_FILES_SRC ${SANIM_SOURCE_DIR}) -rcmake_prepend_path(SANIM_FILES_INC ${SANIM_SOURCE_DIR}) -rcmake_prepend_path(SANIM_FILES_INC_API ${SANIM_SOURCE_DIR}) -rcmake_prepend_path(SANIM_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_library(solstice-anim SHARED ${SANIM_FILES_SRC} ${SANIM_FILES_INC} ${SANIM_FILES_INC_API}) -target_link_libraries(solstice-anim RSys) - -if(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(solstice-anim m) -endif() - -set_target_properties(solstice-anim PROPERTIES - DEFINE_SYMBOL SANIM_SHARED_BUILD - COMPILE_FLAGS ${OpenMP_C_FLAGS} - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(solstice-anim PROPERTIES - LINK_FLAGS ${OpenMP_C_FLAGS}) -endif() - -rcmake_setup_devel(solstice-anim SolAnim ${VERSION} solstice/sanim_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(new_test _name) - add_executable(${_name} ${SANIM_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} solstice-anim-test solstice-anim RSys) - add_test(${_name} ${_name}) - rcmake_set_test_runtime_dirs(${_name} _runtime_dirs) - endfunction() - - add_library(solstice-anim-test STATIC - ${SANIM_SOURCE_DIR}/test_sanim_utils.h - ${SANIM_SOURCE_DIR}/test_sanim_utils.c) - - new_test(test_sanim_node) - new_test(test_sanim_node_transform) - new_test(test_sanim_node_pivot) - new_test(test_sanim_search) - new_test(test_sanim_visit) -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS solstice-anim - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${SANIM_FILES_INC_API} DESTINATION include/solstice) -install(FILES ${SANIM_FILES_DOC} DESTINATION share/doc/solstice-anim) - diff --git a/config.mk b/config.mk @@ -0,0 +1,84 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 2 +VERSION_PATCH = 4 +VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) + +PREFIX = /usr/local +LIBPREFIX = $(PREFIX)/lib +INCPREFIX = $(PREFIX)/include + +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)) + +RSYS_VERSION = 0.15 + +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) -lm + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/sanim.pc.in b/sanim.pc.in @@ -0,0 +1,12 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: \ + rsys >= @RSYS_VERSION@ +Name: sanim +Description: Solstice Anim +Version: @VERSION@ +Libs: -L${libdir} -lsanim +Libs.private: -lm +CFlags: -I${includedir} diff --git a/src/sanim_version.h.in b/src/sanim_version.h.in @@ -0,0 +1,23 @@ +/* Copyright (C) 2016-2018 CNRS, 2018-2026 |Meso|Star> + * + * 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/>. */ + +#ifndef SANIM_VERSION_H +#define SANIM_VERSION_H + +#define SANIM_VERSION_MAJOR @VERSION_MAJOR@ +#define SANIM_VERSION_MINOR @VERSION_MINOR@ +#define SANIM_VERSION_PATCH @VERSION_PATCH@ + +#endif /* SANIM_VERSION_H */