commit 02ae314c63201aec44f7cfa4731076042995995f
parent 1914463852d767245d13eb1360978312d80a0b4e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 22 Mar 2023 10:50:35 +0100
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 14 | ++++++++------ |
| A | Makefile | | | 138 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 34 | ++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 62 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | sstl.pc.in | | | 10 | ++++++++++ |
5 files changed, 252 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,11 +1,13 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.pkg
+.test
tags
-
+sstl.pc
+*.stl
diff --git a/Makefile b/Makefile
@@ -0,0 +1,138 @@
+# Copyright (C) 2015, 2016, 2019, 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-3D building
+################################################################################
+SRC = src/sstl.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .pkg $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libsstl.so
+
+$(OBJ): config.mk
+
+libsstl.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.pkg: config.mk make.sh
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\
+ >&2 printf "\e[1;31merror\e[0m: RSys $(RSYS_VERSION): dependency is missing\n";\
+ exit 1;\
+ fi
+ @echo "config done" > $@
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -DSSTL_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup sstl.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ sstl.pc.in > sstl.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-stl
+ cp libsstl.so $(DESTDIR)$(PREFIX)/lib
+ cp sstl.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/sstl.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-stl
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libsstl.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/sstl.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-stl/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-stl/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-stl/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/sstl.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libsstl.so .test sstl.pc .pkg
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+lint:
+ @shellcheck -o all make.sh
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_sstl.c\
+ src/test_sstl_load.c
+
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+test: build_tests
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+build_tests: build_library $(TEST_DEP) .test
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
+
+.test: Makefile
+ @echo "Setup tests"
+ @$(SHELL) make.sh config_test $(TEST_SRC) > .test
+
+clean_test:
+ @rm -f corner.stl corner_bin.stl test_basic.stl test_basic2.stl
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+test_sstl test_sstl_load: libsstl.so config.mk
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -lsstl $(RSYS_LIB)
+
+$(TEST_OBJ): config.mk
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(RSYS_INC) -c $(@:.o=.c) -o $@
diff --git a/config.mk b/config.mk
@@ -0,0 +1,34 @@
+VERSION = 0.4.0 # Library version
+
+PREFIX = /usr/local
+PKG_CONFIG = pkg-config
+
+################################################################################
+# Dependencies
+################################################################################
+RSYS_VERSION=0.6
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+
+INCS=$(RSYS_INC)
+LIBS=$(RSYS_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,62 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015, 2016, 2019, 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.
+
+config_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ 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=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ printf "%s " "${i}"
+ if ./"${test}" > /dev/null 2>&1; then
+ printf "\e[1;32mOK\e[m\n"
+ else
+ printf "\e[1;31mErreur\e[m\n"
+ fi
+ done
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ rm -f "${test}"
+ done
+}
+
+"$@"
diff --git a/sstl.pc.in b/sstl.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Name: Star-STL
+Description: Star STereo Lithography library
+Version: @VERSION@
+Libs: -L${libdir} -lsstl
+CFlags: -I${includedir}