commit 370851afae62315ddfab9d941e978095011eef12
parent 14bea6fcdcc47536096d90cccc4d1b368d01437a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 24 Mar 2023 11:06:55 +0100
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 12 | +++++++----- |
| A | Makefile | | | 148 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 34 | ++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | s3dut.pc.in | | | 10 | ++++++++++ |
5 files changed, 248 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,10 +1,12 @@
.gitignore
-CMakeCache.txt
-CMakeFiles
-Makefile
-tmp
[Bb]uild*
*.sw[po]
-*.[ao]
+*.[aod]
+*.so
*~
+test*
+!test*.[ch]
+.pkg
+.test
tags
+s3dut.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,148 @@
+# Copyright (C) 2016, 2017, 2020, 2021 |Meso|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
+
+################################################################################
+# Star-3D building
+################################################################################
+SRC =\
+ src/s3dut_cuboid.c\
+ src/s3dut_cylinder.c\
+ src/s3dut_mesh.c\
+ src/s3dut_sphere.c\
+ src/s3dut_super_shape.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .pkg $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs3dut.so
+
+$(OBJ): config.mk
+
+libs3dut.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) -DS3DUT_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup s3dut.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ s3dut.pc.in > s3dut.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-3dut
+ cp libs3dut.so $(DESTDIR)$(PREFIX)/lib
+ cp s3dut.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/s3dut.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING README.md $(DESTDIR)$(PREFIX)/share/doc/star-3dut
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libs3dut.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s3dut.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3dut/COPYING
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3dut/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/s3dut.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libs3dut.so .test .pkg s3dut.pc
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+lint:
+ @shellcheck -o all make.sh
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_s3dut_cuboid.c\
+ src/test_s3dut_cylinder.c\
+ src/test_s3dut_hemisphere.c\
+ src/test_s3dut_sphere.c\
+ src/test_s3dut_super_shape.c\
+ src/test_s3dut_thick_cylinder.c\
+ src/test_s3dut_thick_truncated_sphere.c\
+ src/test_s3dut_thick_truncated_super_shape.c\
+ src/test_s3dut_thin_cylinder.c\
+ src/test_s3dut_truncated_sphere.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:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+$(TEST_OBJ): config.mk
+
+test_s3dut_cuboid \
+test_s3dut_cylinder \
+test_s3dut_hemisphere \
+test_s3dut_sphere \
+test_s3dut_super_shape \
+test_s3dut_thick_cylinder \
+test_s3dut_thick_truncated_sphere \
+test_s3dut_thick_truncated_super_shape \
+test_s3dut_thin_cylinder \
+test_s3dut_truncated_sphere \
+: libs3dut.so config.mk
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -ls3dut $(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.3.3 # 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,49 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015, 2016, 2019, 2021 |Meso|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/>.
+
+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 " "${test}"
+ 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/s3dut.pc.in b/s3dut.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Name: Star-3DUT
+Description: Star 3D Utility Toolkit library
+Version: @VERSION@
+Libs: -L${libdir} -ls3dut
+CFlags: -I${includedir}