]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: extract common build settings
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Jun 2026 19:41:21 +0000 (04:41 +0900)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 Jun 2026 08:32:19 +0000 (10:32 +0200)
This also makes mkosi.functions included after the trivial execution checks.

mkosi/mkosi.functions
mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot
mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot
mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.build.chroot
mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.build.chroot

index c1a4a1dee536a8e75cc313938c89c5e13f631c7d..32fcab70a654e92268f241251db7acba4b667d39 100644 (file)
@@ -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
index e6299ae3bac23ed810ba411ca1e8ccc496db4a13..40d8e15a9898247d62662ec7efa01b88bfaadddb 100755 (executable)
@@ -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
index 1665d7eba3f4f4b01dbaf5d2c61e486a9a3f609a..29eb23ac6e549a7cf17de7d80661b8efd091539c 100755 (executable)
@@ -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
index 02d4c3e5cb9cff052ab4ac30d88bc12f704ca34e..6a26dbc7642af41649dcfeef2e50300094ba4caf 100755 (executable)
@@ -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
index abc6829b40b0a48186c6f00f5ae19d4e4cc44221..864b403dd871a89bd4668ce11ca00c2aa4b65ce0 100755 (executable)
@@ -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.