commit 13729a0e017870bb962af48c263de4602ce1303c
parent 0eb9d8c3eb8657ea7e9de6091afef68c297df95e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 21 Mar 2023 14:32:51 +0100
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 13 | +++++++------ |
| A | Makefile | | | 149 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 38 | ++++++++++++++++++++++++++++++++++++++ |
| A | make.sh | | | 82 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | s2d.pc.in | | | 11 | +++++++++++ |
5 files changed, 287 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]
+.config
+.test
tags
-
+s2d.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,149 @@
+# Copyright (C) 2016-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-2D building
+################################################################################
+SRC =\
+ src/s2d_device.c\
+ src/s2d_geometry.c\
+ src/s2d_line_segments.c\
+ src/s2d_primitive.c\
+ src/s2d_scene.c\
+ src/s2d_scene_view.c\
+ src/s2d_scene_view_closest_point.c\
+ src/s2d_shape.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: .config $(DEP)
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs2d.so
+
+$(OBJ): config.mk
+
+libs2d.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.config: Makefile
+ @echo "Find packages"
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
+ echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then \
+ echo "embree $(EMBREE_VERSION) not found" >&2; exit 1; fi
+ @echo "config done" > .config
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -DS2D_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ @echo "Setup s2d.pc"
+ @sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g' \
+ s2d.pc.in > s2d.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-2d
+ cp libs2d.so $(DESTDIR)$(PREFIX)/lib
+ cp s2d.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/s2d.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-2d
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libs2d.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s2d.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-2d/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-2d/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-2d/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/s2d.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libs2d.so .test s2d.pc .config
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_s2d_closest_point.c\
+ src/test_s2d_device.c\
+ src/test_s2d_primitive.c\
+ src/test_s2d_raytrace.c\
+ src/test_s2d_sample.c\
+ src/test_s2d_shape.c\
+ src/test_s2d_scene.c\
+ src/test_s2d_scene_view.c\
+ src/test_s2d_scene_view2.c\
+ src/test_s2d_trace_ray.c\
+ src/test_s2d_trace_ray_3d.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 make.sh
+ @echo "Setup tests"
+ @$(SHELL) make.sh config_test $(TEST_SRC) > .test
+
+clean_test:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+$(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,38 @@
+VERSION = 0.5.1 # 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)
+
+EMBREE_VERSION=4.0
+EMBREE_INC = $$($(PKG_CONFIG) --cflags embree4)
+EMBREE_LIB = $$($(PKG_CONFIG) --libs embree4)
+
+INCS=$(RSYS_INC) $(EMBREE_INC)
+LIBS=$(RSYS_LIB) $(EMBREE_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,82 @@
+#!/bin/sh -e
+
+# Copyright (C) 2016-2021 |Meso|Star> (contact@meso-star.com)
+#
+# This software is a computer program whose purpose is to generate files used
+# to build the Star-3D library.
+#
+# 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} ${test_list}"
+ printf "%s: %s\n" "${test}" "src/${test}.o"
+ done
+ printf "%s: libs2d.so\n" "${test_list}"
+ printf "\t@echo \"LD \$@\"\n"
+ printf "\t@\$(CC) \$(CFLAGS) -o \$@ src/\$@.o -L\$\$(pwd) -ls2d \$(RSYS_LIB)\n"
+
+ printf "test_bin: %s\n" "${test_list}"
+}
+
+check()
+{
+ if [ $# -lt 1 ]; then
+ echo "usage: check <name> <prog>" >&2
+ exit 1
+ fi
+
+ name="$1"
+ prog="$2"
+ shift 2
+ printf "%s " "${name}"
+ if ./"${prog}" "$@" > /dev/null 2>&1; then
+ printf "\e[1;32mOK\e[m\n"
+ else
+ printf "\e[1;31mError\e[m\n"
+ fi
+}
+
+run_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ check "${test}" "${test}"
+ done
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ rm -f "${test}"
+ done
+}
+
+"$@"
diff --git a/s2d.pc.in b/s2d.pc.in
@@ -0,0 +1,11 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires: rsys >= @RSYS_VERSION@
+Requires.private: embree >= @EMBREE_VERSION@
+Name: Star-2D
+Description: Star-2D library
+Version: @VERSION@
+Libs: -L${libdir} -ls2d
+CFlags: -I${includedir}