diff --git a/Makefile b/Makefile index f2169360..29631e28 100644 --- a/Makefile +++ b/Makefile @@ -351,7 +351,8 @@ rpm: tarball $(SED) 's/__VERSION__/$(VERSION)/g' mergerfs.spec > \ rpmbuild/SOURCES/mergerfs.spec cp -ar mergerfs-$(VERSION).tar.gz rpmbuild/SOURCES - $(RPMBUILD) $(RPMBUILD_FLAGS) -ba rpmbuild/SOURCES/mergerfs.spec \ + ./buildtools/run-rpmbuild $(RPMBUILD) $(RPMBUILD_FLAGS) \ + -ba rpmbuild/SOURCES/mergerfs.spec \ --define "_topdir $(CURDIR)/rpmbuild" .PHONY: install-build-pkgs diff --git a/buildtools/build-mergerfs b/buildtools/build-mergerfs index a82d2364..fd37db89 100755 --- a/buildtools/build-mergerfs +++ b/buildtools/build-mergerfs @@ -8,15 +8,6 @@ if [ -e "$BUILD_ENV" ]; then . "$BUILD_ENV" fi -rpmbuild_flags() -{ - case "$(command -v "${CXX:-g++}")" in - /opt/rh/*) - printf '%s' '--undefine _annotated_build' - ;; - esac -} - if [ $# -ne 2 ]; then echo "usage: $0 " echo "argv: $@" @@ -44,9 +35,9 @@ mkdir "/build" if [ -e /usr/bin/apt-get ]; then make deb elif [ -e /usr/bin/dnf ]; then - make RPMBUILD_FLAGS="$(rpmbuild_flags)" rpm + make rpm elif [ -e /usr/bin/yum ]; then - make RPMBUILD_FLAGS="$(rpmbuild_flags)" rpm + make rpm elif [ -e /sbin/apk ]; then echo "NOT YET SUPPORTED" exit 1 diff --git a/buildtools/run-rpmbuild b/buildtools/run-rpmbuild new file mode 100755 index 00000000..63c6633f --- /dev/null +++ b/buildtools/run-rpmbuild @@ -0,0 +1,85 @@ +#!/bin/sh +# +# usage: run-rpmbuild [args...] +# +# Run rpmbuild with a C++20 capable compiler. +# +# If CXX is unset and the default g++ can't build C++20 (ex: EL8's g++ +# 8) the newest installed GCC Toolset / devtoolset is activated. +# +# redhat-rpm-config's %{optflags} load the annobin GCC plugin which +# toolset compilers often don't have ("inaccessible plugin file +# plugin/annobin.so"). If the selected compiler fails with %{optflags} +# but works with annotation disabled `--undefine _annotated_build` is +# passed to rpmbuild. + +set -e + +if [ $# -lt 1 ]; then + echo "usage: $0 [args...]" >&2 + exit 1 +fi + +cxx20_ok() +{ + printf 'int main(){return 0;}\n' | \ + "${CXX:-g++}" -std=c++20 -x c++ -fsyntax-only - >/dev/null 2>&1 +} + +# Print " " for each toolset activation script. +toolset_scripts() +{ + for f in \ + /usr/lib/gcc-toolset/*-env.source \ + /opt/rh/gcc-toolset-*/enable \ + /opt/rh/devtoolset-*/enable + do + [ -f "$f" ] || continue + v="$(printf '%s\n' "$f" | sed -n \ + -e 's,^/usr/lib/gcc-toolset/\([0-9][0-9]*\)-env\.source$,\1,p' \ + -e 's,^/opt/rh/gcc-toolset-\([0-9][0-9]*\)/enable$,\1,p' \ + -e 's,^/opt/rh/devtoolset-\([0-9][0-9]*\)/enable$,\1,p')" + [ -n "$v" ] && printf '%s %s\n' "$v" "$f" + done +} + +activate_toolset() +{ + for f in $(toolset_scripts | sort -k1,1nr | cut -d' ' -f2); do + if (. "$f" || :; cxx20_ok); then + echo "run-rpmbuild: activating $f" >&2 + . "$f" || : + export CC=gcc + export CXX=g++ + return 0 + fi + done + return 1 +} + +optflags_ok() +{ + flags="$(rpm "$@" --eval '%{optflags}')" || return 1 + printf 'int main(){return 0;}\n' | \ + "${CXX:-g++}" $flags -x c++ -c -o /dev/null - >/dev/null 2>&1 +} + +if [ -z "${CXX}" ] && ! cxx20_ok; then + if ! activate_toolset; then + echo "run-rpmbuild: warning: g++ lacks C++20 support and no" \ + "usable GCC Toolset was found (see buildtools/install-build-pkgs)" >&2 + fi +fi + +extra_flags= +if command -v rpm >/dev/null 2>&1 && \ + ! optflags_ok && \ + optflags_ok --undefine _annotated_build +then + echo "run-rpmbuild: ${CXX:-g++} can't use annobin; disabling _annotated_build" >&2 + extra_flags="--undefine _annotated_build" +fi + +rpmbuild="$1" +shift +exec "$rpmbuild" $extra_flags "$@" diff --git a/mkdocs/docs/setup/build.md b/mkdocs/docs/setup/build.md index f4af7151..abb1d90b 100644 --- a/mkdocs/docs/setup/build.md +++ b/mkdocs/docs/setup/build.md @@ -45,10 +45,23 @@ Distributions that enforce RPM signature checking reject the unsigned local build. When installing a locally built RPM that you built and trust, pass `--nosignature` to `rpm`. -Rocky Linux container builds activate newer GCC Toolsets when available. -Both the Rocky 10 `/usr/lib/gcc-toolset/-env.source` activation -script and the older `/opt/rh/gcc-toolset-/enable` layout are -supported. +mergerfs requires a C++20 compiler and the system `g++` on RHEL / +Rocky 8 is too old. On RHEL / Rocky `install-build-pkgs` installs the +newest GCC Toolset when it is newer than the system compiler, and the +Rocky Linux container builds use it. When `CXX` is unset and the +default `g++` can't build C++20, `make rpm` activates the newest +installed GCC Toolset automatically. If the selected compiler lacks +the annobin plugin that the RPM build flags load, `make rpm` also +disables RPM's annobin annotations (`--undefine _annotated_build`). +Both the Rocky 10 `/usr/lib/gcc-toolset/-env.source` +activation script and the older `/opt/rh/gcc-toolset-/enable` +layout are supported. To build outside of `make rpm` on such systems +(for example `make` or `make install`) activate the toolset first: + +``` +# . /opt/rh/gcc-toolset-/enable +# make +``` ## Container packages