From: Yu Watanabe Date: Fri, 5 Jun 2026 19:41:21 +0000 (+0900) Subject: mkosi: extract common build settings X-Git-Tag: v261-rc4~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49d22fefcbbf065498c2aca5fed67b9de4bb4d58;p=thirdparty%2Fsystemd.git mkosi: extract common build settings This also makes mkosi.functions included after the trivial execution checks. --- diff --git a/mkosi/mkosi.functions b/mkosi/mkosi.functions index c1a4a1dee53..32fcab70a65 100644 --- a/mkosi/mkosi.functions +++ b/mkosi/mkosi.functions @@ -1,5 +1,32 @@ # 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() { if ! ((SYSEXT)); then return diff --git a/mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot b/mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot index e6299ae3bac..40d8e15a989 100755 --- a/mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot +++ b/mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot @@ -11,25 +11,9 @@ if [[ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]]; then exit 1 fi -MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE" -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/mkosi.functions -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 +MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE" # 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 diff --git a/mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot b/mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot index 1665d7eba3f..29eb23ac6e5 100755 --- a/mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot +++ b/mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot @@ -2,8 +2,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later set -e -. mkosi/mkosi.functions - if [[ "$1" == "clangd" ]]; then exit 0 fi @@ -13,6 +11,8 @@ if [[ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]]; then exit 1 fi +. mkosi/mkosi.functions + TS="${SOURCE_DATE_EPOCH:-$(date +%s)}" 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. -MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE" +MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE" if ((WITH_DEBUG)); then MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd" 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 diff --git a/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot b/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot index 02d4c3e5cb9..6a26dbc7642 100755 --- a/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot +++ b/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot @@ -11,25 +11,7 @@ if [[ ! -d "pkg/$PKG_SUBDIR/debian" ]]; then exit 1 fi -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 +. mkosi/mkosi.functions # We transplant the debian/ folder from the deb package sources into the upstream sources. mount --mkdir --bind "$SRCDIR/pkg/$PKG_SUBDIR/debian" "$SRCDIR"/debian diff --git a/mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot b/mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot index abc6829b40b..864b403dd87 100755 --- a/mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot +++ b/mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot @@ -2,8 +2,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later set -e -. mkosi/mkosi.functions - if [[ "$1" == "clangd" ]]; then exit 0 fi @@ -13,6 +11,8 @@ if [[ ! -f "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" ]]; then exit 1 fi +. mkosi/mkosi.functions + TS="${SOURCE_DATE_EPOCH:-$(date +%s)}" # The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we @@ -39,19 +39,12 @@ fi VERSION="$(cat meson.version)" 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 MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd" 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}")" -if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then - MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")" -fi +MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}") $MKOSI_LDFLAGS" # 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. @@ -59,15 +52,6 @@ if [[ -z "${MKOSI_LDFLAGS// }" ]]; then MKOSI_LDFLAGS="%{nil}" 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 # 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.