mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 21:00:13 -05:00
86 lines
2.3 KiB
Text
86 lines
2.3 KiB
Text
|
|
#!/bin/sh
|
||
|
|
#
|
||
|
|
# usage: run-rpmbuild <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 <rpmbuild> [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 "<version> <path>" 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 "$@"
|