commit 568dd3110970246f44b8244a54d302e578360b6d
parent 65018f89dc08b219023fd204963f4d7ee47f8bbe
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 15 Jun 2022 16:53:02 +0200
Write a POSIX Makefile as an alternative to CMake
Diffstat:
| M | .gitignore | | | 12 | +++++++----- |
| A | Makefile | | | 185 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | config.mk | | | 25 | +++++++++++++++++++++++++ |
| A | make.sh | | | 84 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | s3d.pc.in | | | 10 | ++++++++++ |
5 files changed, 311 insertions(+), 5 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]
+.config
+.test
tags
+s3d.pc
diff --git a/Makefile b/Makefile
@@ -0,0 +1,185 @@
+# Copyright (C) 2015-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.
+
+.POSIX:
+.SUFFIXES: # Clean up default inference rules
+
+include config.mk
+
+################################################################################
+# RSys building
+################################################################################
+SRC =\
+ src/s3d_device.c\
+ src/s3d_geometry.c\
+ src/s3d_instance.c\
+ src/s3d_mesh.c\
+ src/s3d_primitive.c\
+ src/s3d_scene.c\
+ src/s3d_scene_view.c\
+ src/s3d_scene_view_closest_point.c\
+ src/s3d_scene_view_trace_ray.c\
+ src/s3d_shape.c\
+ src/s3d_sphere.c
+
+OBJ = $(SRC:.c=.o)
+DEP = $(SRC:.c=.d)
+
+build_library: $(DEP) .config
+ @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) libs3d.so
+
+$(OBJ): config.mk
+
+libs3d.so: $(OBJ)
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $(OBJ)
+
+.config: Makefile
+ @echo "Setup .config"
+ @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
+ echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
+ @if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree; then \
+ echo "embree $(EMBREE_VERSION) not found"; exit 1; fi
+ @echo "config done" > .config
+
+.SUFFIXES: .c .d .o
+.c.d:
+ @echo "Computing dependencies for $<"
+ @$(CC) $(CFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
+
+.c.o:
+ @echo "CC $@"
+ @$(CC) $(CFLAGS) $(INCS) -DS3D_SHARED_BUILD -c $< -o $@
+
+################################################################################
+# Installation
+################################################################################
+pkg:
+ sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ s3d.pc.in > s3d.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-3d
+ cp libs3d.so $(DESTDIR)$(PREFIX)/lib
+ cp s3d.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig
+ cp src/s3d.h $(DESTDIR)$(PREFIX)/include/star
+ cp COPYING.en COPYING.fr README.md $(DESTDIR)$(PREFIX)/share/doc/star-3d
+
+uninstall:
+ rm -f $(DESTDIR)$(PREFIX)/lib/libs3d.so
+ rm -f $(DESTDIR)$(PREFIX)/lib/pkgconfig/s3d.pc
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.en
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING.fr
+ rm -f $(DESTDIR)$(PREFIX)/share/doc/star-3d/README.md
+ rm -f $(DESTDIR)$(PREFIX)/include/star/s3d.h
+
+################################################################################
+# Miscellaneous targets
+################################################################################
+all: build_library build_tests
+
+clean: clean_test
+ @rm -f $(OBJ) $(TEST_OBJ) libs3d.so .test s3d.pc .config
+ @rm -f $$(for i in $(TEST_SRC); do echo $${i} | sed 's/src\/\(.\{1,\}\).c$$/\1/'; done)
+
+distclean: clean
+ @rm -f $(DEP) $(TEST_DEP)
+
+################################################################################
+# Tests
+################################################################################
+TEST_SRC =\
+ src/test_s3d_accel_struct_conf.c\
+ src/test_s3d_closest_point.c\
+ src/test_s3d_device.c\
+ src/test_s3d_primitive.c\
+ src/test_s3d_sampler.c\
+ src/test_s3d_sample_sphere.c\
+ src/test_s3d_scene.c\
+ src/test_s3d_scene_view_aabb.c\
+ src/test_s3d_scene_view.c\
+ src/test_s3d_seams.c\
+ src/test_s3d_shape.c\
+ src/test_s3d_sphere_box.c\
+ src/test_s3d_sphere.c\
+ src/test_s3d_sphere_instance.c\
+ src/test_s3d_trace_ray.c\
+ src/test_s3d_trace_ray_instance.c\
+ src/test_s3d_trace_ray_sphere.c
+
+TEST_OBJ = $(TEST_SRC:.c=.o)
+TEST_DEP = $(TEST_SRC:.c=.d)
+
+test: build_tests
+ @$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_run
+
+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
+
+test_run: test_bin
+ @$(SHELL) make.sh run_test $(TEST_SRC)
+
+clean_test:
+ @$(SHELL) make.sh clean_test $(TEST_SRC)
+
+test_s3d_accel_struct_conf \
+test_s3d_closest_point \
+test_s3d_device \
+test_s3d_primitive \
+test_s3d_sampler \
+test_s3d_sample_sphere \
+test_s3d_scene \
+test_s3d_scene_view_aabb \
+test_s3d_scene_view \
+test_s3d_seams \
+test_s3d_shape \
+test_s3d_sphere_box \
+test_s3d_sphere \
+test_s3d_sphere_instance \
+test_s3d_trace_ray \
+test_s3d_trace_ray_instance \
+test_s3d_trace_ray_sphere \
+: libs3d.so
+ @echo "LD $@"
+ @$(CC) $(CFLAGS) -o $@ src/$@.o -L$$(pwd) -ls3d $(RSYS_LIB) $(EMBREE_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,25 @@
+VERSION = 0.8.0
+
+PREFIX = /usr/local
+
+PKG_CONFIG = pkg-config
+
+RSYS_INC = $$($(PKG_CONFIG) --cflags rsys)
+RSYS_LIB = $$($(PKG_CONFIG) --libs rsys)
+EMBREE_INC = $$($(PKG_CONFIG) --cflags embree)
+EMBREE_LIB = $$($(PKG_CONFIG) --libs embree)
+
+INCS=$(RSYS_INC) $(EMBREE_INC)
+LIBS=$(RSYS_LIB) $(EMBREE_LIB)
+
+CPPFLAGS = -DNDEBUG
+WFLAGS = -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wconversion -Wshadow
+CFLAGS = -O3 -std=c99 -pedantic -fPIC -fvisibility=hidden -fstrict-aliasing\
+ -Wl,--no-undefined $(WFLAGS) $(CPPFLAGS)
+LDFLAGS = -shared
+
+CC = cc
+
+# Dependency version
+RSYS_VERSION=0.6
+EMBREE_VERSION=3.13
diff --git a/make.sh b/make.sh
@@ -0,0 +1,84 @@
+#!/bin/sh -e
+
+# Copyright (C) 2015-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_list} ${test}"
+ printf "%s: %s\n" "${test}" "src/${test}.o"
+ done
+ 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/')
+ if [ "${test}" = "test_s3d_sphere_instance" ] \
+ || [ "${test}" = "test_s3d_trace_ray" ]; then
+ check "${test}_legacy" "${test}"
+ check "${test}_filter" "${test}" filter
+ else
+ check "${test}" "${test}"
+ fi
+ done
+}
+
+clean_test()
+{
+ for i in "$@"; do
+ test=$(echo "${i}" | sed 's/src\/\(.\{1,\}\).c$/\1/')
+ rm -f "${test}"
+ done
+}
+
+"$@"
diff --git a/s3d.pc.in b/s3d.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+includedir=${prefix}/include
+libdir=${prefix}/lib
+
+Requires.private: rsys >= @RSYS_VERSION@
+Name: Star-3D
+Description: Star-3D library
+Version: @VERSION@
+Libs: -L${libdir} -ls3d
+CFlags: -I${includedir}