star-build

Automation tool for project installation
git clone git://git.meso-star.fr/star-build.git
Log | Files | Refs | README | LICENSE

commit e00e5729661ab9d81fc9cc7c96075f8441da1289
parent 15c564cf9ac03a8d79467301108e0bf6676c7047
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 29 Jul 2024 16:40:19 +0200

embree: can be installed from source

Add the EMBREE_BINDIST option which, when set to a value other than 0,
forces star-build to install Embree from its sources rather than from
precompiled binaries. This takes longer and the installed library may be
less optimized, but it solves the problem of binaries compiled with a
library incompatible with the one actually installed on the system.

This commit adds the showvar function to the build.sh script. It returns
the value of a given macro as defined in config.mk. This eliminates the
need to send all the necessary macros as environment variables to the
shell script that generates the Makefile. This is both cleaner and more
practical.

Note that currently, building Embree assumes that the system provides
the TBB library on which it is based. But this assumption is
over-optimistic: if Embree is not installed on the system and therefore
has to be installed by star-build, it's a safe bet that the system
doesn't have TBB either, which would also have to be installed by
star-build.

Diffstat:
MMakefile | 4+++-
Mconfig.mk | 4++++
Msrc/build.sh | 16++++++++++++++++
Asrc/embree4.mk.in | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/embree_4.0.1.sh | 21++++++++++++++++++---
5 files changed, 174 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -47,7 +47,9 @@ mirror: makefile makefile: cache @echo "Setup $(MK)" @{ \ - PATH="src:$${PATH}" USE_SIMD=$(USE_SIMD) \ + PATH="src:$${PATH}" \ + USE_SIMD=$(USE_SIMD) \ + MAKE=$(MAKE) \ $(SHELL) "$(BUILD)"; \ } > "$(MK)" diff --git a/config.mk b/config.mk @@ -39,6 +39,10 @@ CACHE = ./cache # download archives of precompiled binaries. CURL_OPT = --fail --retry 3 +# Uses a precompiled binary of the Embree library instead of compiling +# it locally +EMBREE_BINDIST = 1 + # Define the state of the network, either ONLINE or OFFLINE. # If the network is OFFLINE, the sources and precompiled binaries are # retrieved from the local MIRROR directory, which must therefore diff --git a/src/build.sh b/src/build.sh @@ -69,3 +69,19 @@ profile() { sed -e "s#@NAME@#$1#g" "src/profile.mk.in" } + +# 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 + # shellcheck disable=SC2154 # MAKE is referenced but not assigned +<< 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 +} diff --git a/src/embree4.mk.in b/src/embree4.mk.in @@ -0,0 +1,133 @@ +# Copyright (C) 2023, 2024 |Méso|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/>. + +# Configuration macros +EMBREE_TAG = @TAG@ +EMBREE_VERSION = @VERSION@ +EMBREE_URL_ONLINE = https://github.com/embree/embree/ +EMBREE_URL_OFFLINE = $(MIRROR)/embree +EMBREE_URL = $(EMBREE_URL_$(NETWORK)) + +# Helper macros +EMBREE_DIR = $(CACHE)/embree/$(SLEEF_TAG) +EMBREE_CMAKE_OPTIONS =\ + -G "Unix Makefiles"\ + -DCMAKE_BUILD_TYPE=Release\ + -DCMAKE_INSTALL_LIBDIR="lib"\ + -DEMBREE_BACKFACE_CULLING=OFF\ + -DEMBREE_COMPACT_POLYS=OFF\ + -DEMBREE_DISC_POINT_SELF_INTERSECTION_AVOIDANCE=OFF\ + -DEMBREE_FILTER_FUNCTION=ON\ + -DEMBREE_GEOMETRY_CURVE=OFF\ + -DEMBREE_GEOMETRY_GRID=OFF\ + -DEMBREE_GEOMETRY_INSTANCE=ON\ + -DEMBREE_GEOMETRY_POINT=OFF\ + -DEMBREE_GEOMETRY_QUAD=ON\ + -DEMBREE_GEOMETRY_SUBDIVISION=OFF\ + -DEMBREE_GEOMETRY_TRIANGLE=ON\ + -DEMBREE_GEOMETRY_USER=ON\ + -DEMBREE_MAX_ISA=AVX\ + -DEMBREE_RAY_PACKETS=OFF\ + -DEMBREE_STACK_PROTECTOR=OFF\ + -DEMBREE_STATIC_LIB=OFF\ + -DEMBREE_STAT_COUNTERS=OFF\ + -DEMBREE_SYCL_SUPPORT=OFF\ + -DEMBREE_TUTORIALS=OFF + +EMBREE_DOC =\ + $(EMBREE_DIR)/LICENSE.txt\ + $(EMBREE_DIR)/CHANGELOG.md\ + $(EMBREE_DIR)/third-party-programs.txt\ + $(EMBREE_DIR)/third-party-programs-TBB.txt\ + $(EMBREE_DIR)/third-party-programs-OIDN.txt\ + $(EMBREE_DIR)/third-party-programs-DPCPP.txt\ + $(EMBREE_DIR)/third-party-programs-oneAPI-DPCPP.txt + +EMBREE_LIB =\ + $(EMBREE_DIR)/build/libembree4.so\ + $(EMBREE_DIR)/build/libembree4.so.4 + +EMBREE_INC =\ + $(EMBREE_DIR)/include/embree4/rtcore.h \ + $(EMBREE_DIR)/include/embree4/rtcore_buffer.h \ + $(EMBREE_DIR)/include/embree4/rtcore_builder.h \ + $(EMBREE_DIR)/include/embree4/rtcore_common.h \ + $(EMBREE_DIR)/include/embree4/rtcore_config.h \ + $(EMBREE_DIR)/include/embree4/rtcore_device.h \ + $(EMBREE_DIR)/include/embree4/rtcore_geometry.h \ + $(EMBREE_DIR)/include/embree4/rtcore_quaternion.h \ + $(EMBREE_DIR)/include/embree4/rtcore_ray.h \ + $(EMBREE_DIR)/include/embree4/rtcore_scene.h + +embree4: build_embree4 prefix $(EMBREE_DIR)/embree4.pc + prefix="$$(cat .prefix)" && \ + mkdir -p "$${prefix}/lib" && \ + mkdir -p "$${prefix}/lib/pkgconfig" && \ + mkdir -p "$${prefix}/include/embree4" && \ + mkdir -p "$${prefix}/share/doc/embree4" && \ + cp -P $(EMBREE_LIB) "$${prefix}/lib/" && \ + cp -P $(EMBREE_DIR)/embree4.pc "$${prefix}/lib/pkgconfig/" && \ + cp -P $(EMBREE_INC) "$${prefix}/include/embree4/" && \ + cp -P $(EMBREE_DOC) "$${prefix}/share/doc/embree4/" + +build_embree4: $(EMBREE_DIR) + @cd -- $(EMBREE_DIR)/build && \ + cmake $(EMBREE_CMAKE_OPTIONS) .. && \ + $(MAKE) + +$(EMBREE_DIR)/embree4.pc: $(EMBREE_DIR) prefix + prefix="$$(cat .prefix)" && \ + { \ + printf 'prefix="%s"\n' "$${prefix}"; \ + printf 'includedir="$${prefix}/include"\n'; \ + printf 'libdir="$${prefix}/lib"\n'; \ + printf 'Name: embree4\n'; \ + printf 'Description: Embree ray tracing kernels\n'; \ + printf 'Version: %s\n' "$(EMBREE_VERSION)"; \ + printf 'Libs: -L$${libdir} -lembree4\n'; \ + printf 'Cflags: -I$${includedir}\n'; \ + } > "$@" + +$(EMBREE_DIR): + git clone --branch "$(EMBREE_TAG)" --depth 1 $(EMBREE_URL) "$@" + mkdir -p "$@/build" + +clean_embree4: + if [ -d $(EMBREE_DIR)/build ]; then\ + cd -- $(EMBREE_DIR)/build && $(MAKE) clean;\ + fi + +uninstall_embree4: prefix + prefix="$$(cat .prefix)" && \ + rm -f "$${prefix}/lib/pkgconfig/embree4.pc" && \ + for i in $(EMBREE_LIB); do rm -f "$${prefix}/lib/$${i##*/}"; done && \ + for i in $(EMBREE_INC); do rm -f "$${prefix}/include/embree4/$${i##*/}"; done && \ + for i in $(EMBREE_DOC); do rm -f "$${prefix}/share/doc/embree4/$${i##*/}"; done + +distclean_embree4: + rm -rf $(EMBREE_DIR) + +mirror_embree4: + repo="$$(echo $(EMBREE_URL) | sed 's/[\/]\{0,\}$$//g')" && \ + repo="$(MIRROR)/$${repo##*/}" && \ + rm -rf "$${repo}" && \ + git clone --bare --branch $(EMBREE_TAG) $(MIRROR_GIT_OPT) \ + $(EMBREE_URL) "$${repo}" + +clean_all: clean_embree4 +distclean_all: distclean_embree4 +install_all: embree4 +uninstall_all: uninstall_embree4 +mirror_all: mirror_embree4 diff --git a/src/embree_4.0.1.sh b/src/embree_4.0.1.sh @@ -22,6 +22,21 @@ export EMBREE_SH=1 . "build.sh" -name="embree4" -url="$\(REPO_BIN\)/embree_4.0.1_gnu_linux64.tgz" -bin_spkg +if [ -z "${EMBREE_BINDIST}" ]; then + EMBREE_BINDIST="$(MAKE="${MAKE}" showvar EMBREE_BINDIST)" +fi + +# Install from sources +if [ -z "${EMBREE_BINDIST}" ] || [ "${EMBREE_BINDIST}" -eq 0 ]; then + version=4.0.1 + tag="v${version}" + sed -e "s/@TAG@/${tag}/" \ + -e "s/@VERSION/${version}/" \ + "src/embree4.mk.in" + +# Install from precompiled binaries +else + name="embree4" + url="$\(REPO_BIN\)/embree_4.0.1_gnu_linux64.tgz" + bin_spkg +fi