star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

commit 96814e24f568a9a7a5603db303a174df7beae6b4
parent 4a8529893889a5248f3fa4d8cb2fff5785620753
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 24 Apr 2024 15:14:53 +0200

Merge branch 'release_0.2'

Diffstat:
M.gitignore | 15++++++++-------
AMakefile | 227+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 49++++++++++++++++++++++++++++++-------------------
Dcmake/CMakeLists.txt | 208-------------------------------------------------------------------------------
Aconfig.mk | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asg3d.pc.in | 11+++++++++++
Msrc/sg3d.h | 2+-
Msrc/sg3d_device.c | 2+-
Msrc/sg3d_device.h | 2+-
Msrc/sg3d_geometry.c | 2+-
Msrc/sg3d_geometry.h | 2+-
Msrc/sg3d_misc.h | 2+-
Msrc/sg3d_sXd_helper.h | 2+-
Msrc/sg3d_sdisXd_helper.h | 2+-
Msrc/sg3d_sencXd_helper.h | 2+-
Msrc/sgX3d.h | 2+-
Msrc/sgX3d_undefs.h | 2+-
Msrc/test_sg3d_cube_behind_cube.c | 2+-
Msrc/test_sg3d_cube_in_cube.c | 2+-
Msrc/test_sg3d_cube_on_cube.c | 2+-
Msrc/test_sg3d_device.c | 2+-
Msrc/test_sg3d_geometry.c | 2+-
Msrc/test_sg3d_geometry_2.c | 2+-
Msrc/test_sg3d_invalid_models.c | 2+-
Msrc/test_sg3d_many_enclosures.c | 2+-
Msrc/test_sg3d_many_triangles.c | 2+-
Msrc/test_sg3d_multi_media.c | 2+-
Msrc/test_sg3d_some_enclosures.c | 2+-
Msrc/test_sg3d_some_triangles.c | 2+-
Msrc/test_sg3d_unspecified_properties.c | 2+-
Msrc/test_sg3d_utils.h | 2+-
Msrc/test_sg3d_utils2.h | 2+-
33 files changed, 454 insertions(+), 260 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,13 @@ -compile_commands.json .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.config_test +.test tags - +*.pc diff --git a/Makefile b/Makefile @@ -0,0 +1,227 @@ +# Copyright (C) 2019, 2020, 2023, 2024 |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/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libsg3d.a +LIBNAME_SHARED = libsg3d.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +################################################################################ +# Library building +################################################################################ +SRC =\ + src/sg3d_device.c\ + src/sg3d_geometry.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_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) -lm + +$(LIBNAME_STATIC): libsg3d.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libsg3d.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DSG3D_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + sg3d.pc.in > sg3d.pc + +sg3d-local.pc: sg3d.pc.in + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + sg3d.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" sg3d.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sXd_helper.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sencXd_helper.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sdisXd_helper.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sgX3d.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sgX3d_undefs.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d" \ + COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sg3d.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d.h" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sXd_helper.h" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sencXd_helper.h" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sdisXd_helper.h" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sgX3d.h" + rm -f "$(DESTDIR)$(PREFIX)/include/star/sgX3d_undefs.h" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_S3DUT) $(LIBNAME) + rm -f .config .config_test .test libsg3d.o sg3d.pc sg3d-local.pc + +distclean: clean + rm -f $(DEP) $(TEST_DEP) $(TEST_DEP_S3DUT) + +lint: + shellcheck -o all make.sh + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_sg3d_cube_behind_cube.c\ + src/test_sg3d_cube_in_cube.c\ + src/test_sg3d_cube_on_cube.c\ + src/test_sg3d_device.c\ + src/test_sg3d_geometry_2.c\ + src/test_sg3d_geometry.c\ + src/test_sg3d_invalid_models.c\ + src/test_sg3d_multi_media.c\ + src/test_sg3d_unspecified_properties.c +TEST_OBJ = $(TEST_SRC:.c=.o) +TEST_DEP = $(TEST_SRC:.c=.d) + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +SG3D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sg3d-local.pc) +SG3D_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sg3d-local.pc) + +# Regular Compiler and linker flags +TEST_CFLAGS = $(CFLAGS_EXE) $(SG3D_CFLAGS) $(RSYS_CFLAGS) +TEST_LIBS = $(LDFLAGS_EXE) $(SG3D_LIBS) $(RSYS_LIBS) + +build_tests: .config_test build_library $(TEST_DEP) .test + @$(MAKE) -fMakefile -f.test \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + test_bin + +.config_test: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut; then \ + echo "s3dut $(S3DUT_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +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) + +################################################################################ +# Regular tests +################################################################################ +src/test_sg3d_cube_behind_cube.d \ +src/test_sg3d_cube_in_cube.d \ +src/test_sg3d_cube_on_cube.d \ +src/test_sg3d_device.d \ +src/test_sg3d_geometry_2.d \ +src/test_sg3d_geometry.d \ +src/test_sg3d_invalid_models.d \ +src/test_sg3d_multi_media.d \ +src/test_sg3d_unspecified_properties.d \ +: config.mk sg3d-local.pc + @$(CC) $(TEST_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sg3d_cube_behind_cube.o \ +src/test_sg3d_cube_in_cube.o \ +src/test_sg3d_cube_on_cube.o \ +src/test_sg3d_device.o \ +src/test_sg3d_geometry_2.o \ +src/test_sg3d_geometry.o \ +src/test_sg3d_invalid_models.o \ +src/test_sg3d_multi_media.o \ +src/test_sg3d_unspecified_properties.o \ +: config.mk sg3d-local.pc + $(CC) $(TEST_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sg3d_cube_behind_cube \ +test_sg3d_cube_in_cube \ +test_sg3d_cube_on_cube \ +test_sg3d_device \ +test_sg3d_geometry_2 \ +test_sg3d_geometry \ +test_sg3d_invalid_models \ +test_sg3d_multi_media \ +test_sg3d_unspecified_properties \ +: config.mk sg3d-local.pc $(LIBNAME) + $(CC) $(TEST_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) + +################################################################################ +# Test based on Star-3DUT +################################################################################ +src/test_sg3d_many_enclosures.d \ +src/test_sg3d_many_triangles.d \ +src/test_sg3d_some_enclosures.d \ +src/test_sg3d_some_triangles.d \ +: config.mk sg3d-local.pc + @$(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sg3d_many_enclosures.o \ +src/test_sg3d_many_triangles.o \ +src/test_sg3d_some_enclosures.o \ +src/test_sg3d_some_triangles.o \ +: config.mk sg3d-local.pc + $(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sg3d_many_enclosures \ +test_sg3d_many_triangles \ +test_sg3d_some_enclosures \ +test_sg3d_some_triangles \ +: config.mk sg3d-local.pc $(LIBNAME) + $(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) $(S3DUT_LIBS) diff --git a/README.md b/README.md @@ -7,26 +7,35 @@ mechanisms to construct triangle-related app data, detect inconsistencies and dump the resulting geometry in various formats (OBJ, VTK, C code chunks). -## How to build +## Requirements -Star-geometry-3d relies on the [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) package to build and -depends on the [RSys](https://gitlab.com/vaplv/rsys/) library. Some tests -also depend on the [SD3UT](https://gitlab.com/meso-star/star-3dut/) -library. +- C compiler +- POSIX make +- pkg-config +- [RSys](https://gitlab.com/vaplv/rsys) +- [Star 3DUT](https://gitlab.com/meso-star/star-3dut) (optional) -First ensure that CMake and a C compiler that is compliant with C89 are -installed on your system. Then install the RCMake package as well as all -the aforementioned prerequisites. Finally generate the project from the -`cmake/CMakeLists.txt` file by appending to the `CMAKE_PREFIX_PATH` -variable the install directories of its dependencies. +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes +### Version 0.2 + +- Replace CMake by Makefile as build system. +- Update compiler and linker flags to increase the security and + robustness of generated binaries. +- Provide a pkg-config file to link the library as an external + dependency. + ### Version 0.1.3 -- BugFix: when property conflicts where found, a wrong triangle was flaged. - As a consequence, geometry dumps of conflicting geometries where wrong. +- BugFix: when property conflicts where found, a wrong triangle was + flaged. As a consequence, geometry dumps of conflicting geometries + where wrong. ### Version 0.1.2 @@ -41,13 +50,15 @@ variable the install directories of its dependencies. First version and implementation of the star-geometry-3d API. -- Creation of geometries in multiple steps, allowing advanced deduplication and - application-data management +- Creation of geometries in multiple steps, allowing advanced + deduplication and application-data management - Dump of geometries as OBJ or VTK files or as C code chunks ## License -Copyright © 2019, 2020, 2023 [|Méso|Star>](https://www.meso-star.com) -(<contact@meso-star.com>). It is free software released under the GPLv3+ -license: GNU GPL version 3 or later. You are welcome to redistribute it under -certain conditions; refer to the COPYING files for details. +Copyright © 2019, 2020, 2023, 2024 +[|Méso|Star>](https://www.meso-star.com) (contact@meso-star.com) + +It is free software released under the GPLv3+ license: GNU GPL version 3 +or later. You are welcome to redistribute it under certain conditions; +refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,208 +0,0 @@ -# Copyright (C) 2019, 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/>. - -cmake_minimum_required(VERSION 3.1) -project(star-geometry-3d C) -enable_testing() - -include(CMakeDependentOption) - -set(STAR_GEOM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST - "Do not build tests" - OFF) - -cmake_dependent_option(SMALL_ADDITIONAL_TESTS - "Build small additional tests originally written for star-enclosures" OFF - "NOT NO_TEST" OFF) - -cmake_dependent_option(HUGE_ADDITIONAL_TESTS - "Build additional tests originally written for star-enclosures that involve \ -millions of triangles" OFF - "NOT NO_TEST" OFF) - -################################################################################ -# Check dependencies -################################################################################ -find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.8.1 REQUIRED) - -if(NOT NO_TEST) - find_package(Star3DUT 0.3.1 REQUIRED) -endif() - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories( - ${RSys_INCLUDE_DIR} - ${StarEnc_INCLUDE_DIR}) - -if(NOT NO_TEST) - rcmake_append_runtime_dirs(_runtime_dirs RSys StarEnc Star3DUT) -else() - rcmake_append_runtime_dirs(_runtime_dirs RSys StarEnc) -endif() - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 1) -set(VERSION_PATCH 3) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(SG3D_FILES_SRC - sg3d_device.c - sg3d_geometry.c -) - -set(SG3D_FILES_INC_API - sg3d.h - sg3d_sXd_helper.h - sg3d_sencXd_helper.h - sg3d_sdisXd_helper.h - sgX3d.h - sgX3d_undefs.h -) - -set(SG3D_FILES_INC - sg3d_device.h - sg3d_geometry.h - sg3d_misc.h -) - -set(SG3D_FILES_DOC COPYING README.md) - -# Prepend each file by `STAR_GEOM_SOURCE_DIR' -rcmake_prepend_path(SG3D_FILES_SRC ${STAR_GEOM_SOURCE_DIR}) -rcmake_prepend_path(SG3D_FILES_INC ${STAR_GEOM_SOURCE_DIR}) -rcmake_prepend_path(SG3D_FILES_INC_API ${STAR_GEOM_SOURCE_DIR}) -rcmake_prepend_path(SG3D_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) -endif() - -if(MSVC) - -endif() - -add_library(sg3d SHARED - ${SG3D_FILES_SRC} - ${SG3D_FILES_INC} - ${SG3D_FILES_INC_API}) -target_link_libraries(sg3d RSys ${MATH_LIB}) - -set_target_properties(sg3d PROPERTIES -# C99 needed in case of printf "PRTF_API" used -# C_STANDARD 99 - DEFINE_SYMBOL SG3D_SHARED_BUILD - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) -rcmake_copy_runtime_libraries(sg3d) - -rcmake_setup_devel(sg3d StarGeom3D ${VERSION} star/sg3d_version.h) - -################################################################################ -# Add tests -################################################################################ -if(NOT NO_TEST) - function(build_test _name) - add_executable(${_name} - ${STAR_GEOM_SOURCE_DIR}/${_name}.c - ${STAR_GEOM_SOURCE_DIR}/test_sg3d_utils.h) - foreach(other ${ARGN}) - target_sources(${_name} - PUBLIC ${STAR_GEOM_SOURCE_DIR}/${other}) - endforeach() - target_link_libraries(${_name} RSys sg3d) - endfunction() - - function(register_test _name) - add_test(${_name} ${ARGN}) - rcmake_set_test_runtime_dirs(${_name} _runtime_dirs) - endfunction() - - function(new_test _name) - build_test(${_name} ${ARGN}) - register_test(${_name} ${_name}) - endfunction() - - new_test(test_sg3d_device) - new_test(test_sg3d_geometry) - new_test(test_sg3d_geometry_2) - - build_test(test_sg3d_cube_behind_cube) - build_test(test_sg3d_cube_in_cube) - build_test(test_sg3d_cube_on_cube) - build_test(test_sg3d_invalid_models) - build_test(test_sg3d_multi_media) - build_test(test_sg3d_some_enclosures test_sg3d_utils2.h) - build_test(test_sg3d_some_triangles test_sg3d_utils2.h) - build_test(test_sg3d_unspecified_properties) - - build_test(test_sg3d_many_enclosures test_sg3d_utils2.h) - build_test(test_sg3d_many_triangles test_sg3d_utils2.h) - - target_link_libraries(test_sg3d_some_enclosures Star3DUT) - target_link_libraries(test_sg3d_some_triangles Star3DUT) - target_link_libraries(test_sg3d_many_enclosures Star3DUT) - target_link_libraries(test_sg3d_many_triangles Star3DUT) - - rcmake_copy_runtime_libraries(test_sg3d_device) - rcmake_copy_runtime_libraries(test_sg3d_geometry) - rcmake_copy_runtime_libraries(test_sg3d_geometry_2) - - rcmake_copy_runtime_libraries(test_sg3d_cube_behind_cube) - rcmake_copy_runtime_libraries(test_sg3d_cube_in_cube) - rcmake_copy_runtime_libraries(test_sg3d_cube_on_cube) - rcmake_copy_runtime_libraries(test_sg3d_invalid_models) - rcmake_copy_runtime_libraries(test_sg3d_multi_media) - rcmake_copy_runtime_libraries(test_sg3d_some_enclosures) - rcmake_copy_runtime_libraries(test_sg3d_some_triangles) - rcmake_copy_runtime_libraries(test_sg3d_unspecified_properties) - - rcmake_copy_runtime_libraries(test_sg3d_many_enclosures) - rcmake_copy_runtime_libraries(test_sg3d_many_triangles) - - if(SMALL_ADDITIONAL_TESTS) - add_test(test_sg3d_cube_behind_cube test_sg3d_cube_behind_cube) - add_test(test_sg3d_cube_in_cube test_sg3d_cube_in_cube) - add_test(test_sg3d_cube_on_cube test_sg3d_cube_on_cube) - add_test(test_sg3d_invalid_models test_sg3d_invalid_models) - add_test(test_sg3d_multi_media test_sg3d_multi_media) - add_test(test_sg3d_some_enclosures test_sg3d_some_enclosures) - add_test(test_sg3d_some_triangles test_sg3d_some_triangles) - add_test(test_sg3d_unspecified_properties test_sg3d_unspecified_properties) - endif() - - if(HUGE_ADDITIONAL_TESTS) - add_test(test_sg3d_many_enclosures test_sg3d_many_enclosures) - add_test(test_sg3d_many_triangles test_sg3d_many_triangles) - endif() - -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS sg3d - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${SG3D_FILES_INC_API} DESTINATION include/star) -install(FILES ${SG3D_FILES_DOC} DESTINATION share/doc/star-geometry-3d) diff --git a/config.mk b/config.mk @@ -0,0 +1,82 @@ +VERSION = 0.2 +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)) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +# Optional dependency +S3DUT_VERSION = 0.4 +S3DUT_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3dut) +S3DUT_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3dut) + +################################################################################ +# 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 = -O3 -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/make.sh b/make.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +# Copyright (C) 2019, 2020, 2023, 2024 |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/sg3d.pc.in b/sg3d.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Name: sg3d +Description: Star Geometry 3D library +Version: @VERSION@ +Libs: -L${libdir} -lsg3d +Libs.private: -lm +CFlags: -I${includedir} diff --git a/src/sg3d.h b/src/sg3d.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_device.c b/src/sg3d_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_device.h b/src/sg3d_device.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_geometry.c b/src/sg3d_geometry.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_geometry.h b/src/sg3d_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_misc.h b/src/sg3d_misc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_sXd_helper.h b/src/sg3d_sXd_helper.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_sdisXd_helper.h b/src/sg3d_sdisXd_helper.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sg3d_sencXd_helper.h b/src/sg3d_sencXd_helper.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sgX3d.h b/src/sgX3d.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/sgX3d_undefs.h b/src/sgX3d_undefs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_cube_behind_cube.c b/src/test_sg3d_cube_behind_cube.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_cube_in_cube.c b/src/test_sg3d_cube_in_cube.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_cube_on_cube.c b/src/test_sg3d_cube_on_cube.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_device.c b/src/test_sg3d_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_geometry.c b/src/test_sg3d_geometry.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_geometry_2.c b/src/test_sg3d_geometry_2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_invalid_models.c b/src/test_sg3d_invalid_models.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_many_enclosures.c b/src/test_sg3d_many_enclosures.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_many_triangles.c b/src/test_sg3d_many_triangles.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_multi_media.c b/src/test_sg3d_multi_media.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_some_enclosures.c b/src/test_sg3d_some_enclosures.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_some_triangles.c b/src/test_sg3d_some_triangles.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_unspecified_properties.c b/src/test_sg3d_unspecified_properties.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_utils.h b/src/test_sg3d_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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 diff --git a/src/test_sg3d_utils2.h b/src/test_sg3d_utils2.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com) +/* Copyright (C) 2019, 2020, 2023, 2024 |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