mkosi: extract common build settings

This also makes mkosi.functions included after the trivial execution checks.
This commit is contained in:
Yu Watanabe
2026-06-11 10:32:19 +02:00
committed by Daan De Meyer
parent c7eebff27e
commit 49d22fefcb
5 changed files with 37 additions and 78 deletions
+27
View File
@@ -1,5 +1,32 @@
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
# This is intended to be included by mkosi.build.chroot,
# and sets the following variables and one common function:
# - $MKOSI_CFLAGS
# - $MKOSI_LDFLAGS
# - $MKOSI_MESON_OPTIONS
MKOSI_CFLAGS="-O0 -g"
if ((LLVM)); then
# TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
fi
MKOSI_LDFLAGS=""
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
fi
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi
if ((COVERAGE)); then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
fi
make_sysext_unsigned() { make_sysext_unsigned() {
if ! ((SYSEXT)); then if ! ((SYSEXT)); then
return return
@@ -11,25 +11,9 @@ if [[ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]]; then
exit 1 exit 1
fi fi
MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE" . mkosi/mkosi.functions
if ((LLVM)); then
# TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
fi
MKOSI_LDFLAGS="" MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE"
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
fi
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi
if ((COVERAGE)); then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
fi
# Override the default options. We specifically disable "strip", "zipman" and "lto" as they slow down builds # Override the default options. We specifically disable "strip", "zipman" and "lto" as they slow down builds
# significantly. OPTIONS= cannot be overridden on the makepkg command line so we append to /etc/makepkg.conf # significantly. OPTIONS= cannot be overridden on the makepkg command line so we append to /etc/makepkg.conf
@@ -2,8 +2,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -e set -e
. mkosi/mkosi.functions
if [[ "$1" == "clangd" ]]; then if [[ "$1" == "clangd" ]]; then
exit 0 exit 0
fi fi
@@ -13,6 +11,8 @@ if [[ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]]; then
exit 1 exit 1
fi fi
. mkosi/mkosi.functions
TS="${SOURCE_DATE_EPOCH:-$(date +%s)}" TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
if [[ "$(rpm --eval "%{lua:print(rpm.vercmp('$(rpm --version | cut -d ' ' -f3)', '4.19.91'))}")" == "-1" ]]; then if [[ "$(rpm --eval "%{lua:print(rpm.vercmp('$(rpm --version | cut -d ' ' -f3)', '4.19.91'))}")" == "-1" ]]; then
@@ -38,28 +38,10 @@ COMMON_MACRO_OVERRIDES=(
) )
# TODO: Drop -U_FORTIFY_SOURCE when we switch to CentOS Stream 10. # TODO: Drop -U_FORTIFY_SOURCE when we switch to CentOS Stream 10.
MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE" MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE"
if ((WITH_DEBUG)); then if ((WITH_DEBUG)); then
MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd" MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd"
fi fi
if ((LLVM)); then
# TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
fi
MKOSI_LDFLAGS=""
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
fi
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi
if ((COVERAGE)); then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
fi
( (
shopt -s nullglob shopt -s nullglob
@@ -11,25 +11,7 @@ if [[ ! -d "pkg/$PKG_SUBDIR/debian" ]]; then
exit 1 exit 1
fi fi
MKOSI_CFLAGS="-O0 -g" . mkosi/mkosi.functions
if ((LLVM)); then
# TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
fi
MKOSI_LDFLAGS=""
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
fi
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi
if ((COVERAGE)); then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
fi
# We transplant the debian/ folder from the deb package sources into the upstream sources. # We transplant the debian/ folder from the deb package sources into the upstream sources.
mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian
@@ -2,8 +2,6 @@
# SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-License-Identifier: LGPL-2.1-or-later
set -e set -e
. mkosi/mkosi.functions
if [[ "$1" == "clangd" ]]; then if [[ "$1" == "clangd" ]]; then
exit 0 exit 0
fi fi
@@ -13,6 +11,8 @@ if [[ ! -f "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" ]]; then
exit 1 exit 1
fi fi
. mkosi/mkosi.functions
TS="${SOURCE_DATE_EPOCH:-$(date +%s)}" TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
# The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we # The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we
@@ -39,19 +39,12 @@ fi
VERSION="$(cat meson.version)" VERSION="$(cat meson.version)"
RELEASE="$(date "+%Y%m%d%H%M%S" --date "@$TS")" RELEASE="$(date "+%Y%m%d%H%M%S" --date "@$TS")"
MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE" MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE"
if ((WITH_DEBUG)); then if ((WITH_DEBUG)); then
MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd" MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd"
fi fi
if ((LLVM)); then
# TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
fi
MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}")" MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}") $MKOSI_LDFLAGS"
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
fi
# A macro can't have an empty body and currently opensuse does not specify any of its own linker flags so # A macro can't have an empty body and currently opensuse does not specify any of its own linker flags so
# set LDFLAGS to %{nil} if there are no linker flags. # set LDFLAGS to %{nil} if there are no linker flags.
@@ -59,15 +52,6 @@ if [[ -z "${MKOSI_LDFLAGS// }" ]]; then
MKOSI_LDFLAGS="%{nil}" MKOSI_LDFLAGS="%{nil}"
fi fi
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi
if ((COVERAGE)); then
MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
fi
# The opensuse spec tars up stuff in test/ and unpacks it in test/integration-tests, which we now use for our # The opensuse spec tars up stuff in test/ and unpacks it in test/integration-tests, which we now use for our
# own purposes, so let's get rid of that specific bit of logic in the opensuse spec until they've had a chance # own purposes, so let's get rid of that specific bit of logic in the opensuse spec until they've had a chance
# to adapt. # to adapt.