star-3dstl

Create star-3d geometries from StL files
git clone git://git.meso-star.fr/star-3dstl.git
Log | Files | Refs | README | LICENSE

commit 9b8679f110071960a892c70078801ddeedfbafd9
parent 4985ac7f508829ccbf53930d0b87c1f63cc4a183
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 23 Mar 2023 12:54:50 +0100

Write a POSIX Makefile as an alternative to CMake

Diffstat:
M.gitignore | 13+++++++------
AMakefile | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig.mk | 42++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
As3dstl.pc.in | 11+++++++++++
5 files changed, 279 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,11 +1,12 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aod] +*.so *~ +test* +!test*.[ch] +.pkg tags - +s3dstl.pc +*.stl diff --git a/Makefile b/Makefile @@ -0,0 +1,130 @@ +# Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com) +# +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +################################################################################ +# Star-3DAW building +################################################################################ +SRC = src/s3dstl.c + +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .pkg $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs3dstl.so + +$(OBJ) $(DEP): config.mk + +libs3dstl.so: $(OBJ) + @echo "LD $@" + @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ) + +.pkg: make.sh config.mk + @$(SHELL) make.sh config_pkg && echo "pkg done" > $@ || exit 1 + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + @echo "CC $@" + @$(CC) $(CFLAGS) $(INCS) -DS3DSTL_SHARED_BUILD -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +pkg: + @echo "Setup s3dstl.pc" + @sed -e 's#@PREFIX@#$(PREFIX)#g' \ + -e 's#@VERSION@#$(VERSION)#g' \ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \ + -e 's#@STAR-3D_VERSION@#$(STAR-3D_VERSION)#g' \ + -e 's#@STAR-STL_VERSION@#$(STAR-STL_VERSION)#g' \ + s3dstl.pc.in > s3dstl.pc + +install: build_library pkg + mkdir -p $(DESTDIR)$(PREFIX)/lib + mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig + mkdir -p $(DESTDIR)$(PREFIX)/include/star + mkdir -p $(DESTDIR)$(PREFIX)/share/doc/star-3dstl + cp libs3dstl.so $(DESTDIR)$(PREFIX)/lib + cp s3dstl.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig + cp src/s3dstl.h $(DESTDIR)$(PREFIX)/include/star + cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-3dstl + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/lib/libs3dstl.so + rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s3dstl.pc + rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3dstl/COPYING.en + rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3dstl/COPYING.fr + rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3dstl/README.md + rm -f $(DESTDIR)$(PREFIX)/include/star/s3dstl.h + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + @rm -f $(OBJ) $(TEST_OBJ) libs3d.so .test s3d.pc .pkg + +distclean: clean + @rm -f $(DEP) $(TEST_DEP) + +lint: + @shellcheck -o all make.sh + +################################################################################ +# Test +################################################################################ +TEST_OBJ = src/test_s3dstl.o +TEST_DEP = src/test_s3dstl.d + +test: build_tests + @$(SHELL) make.sh run_test test_s3dstl + +build_tests: src/test_s3dstl.d + @$(MAKE) -fMakefile -fsrc/test_s3dstl.d test_s3dstl + +clean_test: + @rm -f test_s3dstl test_empty.stl + +$(TEST_OBJ) $(TEST_DEP): config.mk + +src/test_s3dstl.o: src/test_s3dstl.c + @echo "CC $@" + @$(CC) $(CFLAGS) $(RSYS_INC) $(STAR-3D_INC) $(STAR-STL_INC) -c $< -o $@ + +test_s3dstl: src/test_s3dstl.o libs3dstl.so config.mk + @echo "LD $@" + @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -ls3dstl\ + $(RSYS_LIB) $(STAR-3D_LIB) $(STAR-STL_LIB) diff --git a/config.mk b/config.mk @@ -0,0 +1,42 @@ +VERSION = 0.3.2 # Library version + +PREFIX = /usr/local +PKG_CONFIG = pkg-config + +################################################################################ +# Dependencies +################################################################################ +RSYS_VERSION=0.3 +RSYS_INC = $$($(PKG_CONFIG) --cflags rsys) +RSYS_LIB = $$($(PKG_CONFIG) --libs rsys) + +STAR-3D_VERSION=0.3 +STAR-3D_INC = $$($(PKG_CONFIG) --cflags s3d) +STAR-3D_LIB = $$($(PKG_CONFIG) --libs s3d) + +STAR-STL_VERSION=0.3 +STAR-STL_INC = $$($(PKG_CONFIG) --cflags sstl) +STAR-STL_LIB = $$($(PKG_CONFIG) --libs sstl) + +INCS=$(RSYS_INC) $(STAR-3D_INC) $(STAR-STL_INC) +LIBS=$(RSYS_LIB) $(STAR-3D_LIB) $(STAR-STL_LIB) + +################################################################################ +# Compilation options +################################################################################ +CC = cc # Compiler + +CPPFLAGS = -DNDEBUG +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS = -O3 -std=c99 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\ + -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS) # Compiler options + +LDFLAGS = -shared # Linker options diff --git a/make.sh b/make.sh @@ -0,0 +1,89 @@ +#!/bin/sh -e + +# Copyright (C) 2015-2018, 2021 |Meso|Star> (contact@meso-star.com) +# +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. + +################################################################################ +# Helper functions +################################################################################ +# Print the value of a variable in config.mk +showvar() +{ + # To avoid messages from Make being displayed instead of the value of the + # queried variable, we redirect its output to /dev/null and open a new file + # descriptor to stdout to print the variable +<< EOF make -f 3>&1 1>/dev/null 2>&1 - || kill -HUP $$ +.POSIX: +include config.mk +showvar: + @1>&3 echo \$(${1}) +EOF + exec 3<&- # Close file descriptor 3 +} + +################################################################################ +# Main functions +################################################################################ +run_test() +{ + for i in "$@"; do + printf "%s " "${i}" + if ./"${i}" > /dev/null 2>&1; then + printf "\e[1;32mOK\e[m\n" + else + printf "\e[1;31mErreur\e[m\n" + fi + done +} + +config_pkg() +{ + pkg_config=$(showvar PKG_CONFIG) + + rsys_version=$(showvar RSYS_VERSION) + s3d_version=$(showvar STAR-3D_VERSION) + sstl_version=$(showvar STAR-STL_VERSION) + dependencies="\ + RSys rsys ${rsys_version} + Star-3D s3d ${s3d_version} + Star-STL sstl ${sstl_version}" + + printf "%s\n" "${dependencies}" | while read -r i; do + name=$(printf "%s" "${i}" | cut -d' ' -f1) + pc=$(printf "%s" "${i}" | cut -d' ' -f2) + version=$(printf "%s" "${i}" | cut -d' ' -f3) + + if ! "${pkg_config}" --atleast-version "${version}" "${pc}"; then + >&2 printf "\e[1;31merror\e[0m:%s %s: dependency is missing\n" \ + "${name}" "${version}" + exit 1 + fi + done || exit $? +} + +"$@" diff --git a/s3dstl.pc.in b/s3dstl.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@ +Requires.private: s3d >= @STAR-3D_VERSION@, sstl >= @STAR-STL_VERSION@ +Name: Star-3DSTL +Description: Star-3DSTL library +Version: @VERSION@ +Libs: -L${libdir} -ls3dstl +CFlags: -I${includedir}