]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Allow setting custom CFLAGS and LDFLAGS
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 1 Jun 2024 10:58:29 +0000 (12:58 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 3 Jun 2024 10:58:16 +0000 (12:58 +0200)
mkosi.images/system/mkosi.conf.d/10-arch/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-centos-fedora/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-debian-ubuntu/mkosi.build.chroot
mkosi.images/system/mkosi.conf.d/10-opensuse/mkosi.build.chroot

index 12575eef6a342b6eb990c165af50166ef92a0ed3..0085bb1166b870d14ed1397c5118611ddbcef99a 100755 (executable)
@@ -24,15 +24,15 @@ ln --symbolic . "pkg/$ID/src"
 # shellcheck source=/dev/null
 . /etc/makepkg.conf
 
-CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
+MKOSI_CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
 if ((LLVM)); then
     # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
-    CFLAGS="$CFLAGS -shared-libasan -fno-sanitize=function"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
 fi
 
-LDFLAGS=""
+MKOSI_LDFLAGS=""
 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
-    LDFLAGS="$LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
+    MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
 fi
 
 # Override the default options. Disable FORTIFY_SOURCE because it doesn't work with O0. We specifically
@@ -44,9 +44,9 @@ export CC="$( ((LLVM)) && echo clang || echo gcc)"
 export CXX="$( ((LLVM)) && echo clang++ || echo g++)"
 export CC_LD="$( ((LLVM)) && echo lld)"
 export CXX_LD="$( ((LLVM)) && echo lld)"
-export CFLAGS="\$CFLAGS $CFLAGS"
-export CXXFLAGS="\$CXXFLAGS $CFLAGS"
-export LDFLAGS="\$LDFLAGS $LDFLAGS"
+export CFLAGS="\$CFLAGS $MKOSI_CFLAGS $CFLAGS"
+export CXXFLAGS="\$CXXFLAGS $MKOSI_CFLAGS $CFLAGS"
+export LDFLAGS="\$LDFLAGS $MKOSI_LDFLAGS $LDFLAGS"
 OPTIONS=(
     docs
     !libtool
index 3bac3fbce9e401f036957b44604f41053f10d586..bd55e4d971bda680b114439fd7ef808bacdcb1ad 100755 (executable)
@@ -47,18 +47,18 @@ COMMON_MACRO_OVERRIDES=(
 )
 
 # TODO: Drop -U_FORTIFY_SOURCE when we switch to CentOS Stream 10.
-CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
+MKOSI_CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
 if ((WITH_DEBUG)); then
-    CFLAGS="$CFLAGS -fdebug-prefix-map=../src=$SRCDEST"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=$SRCDEST"
 fi
 if ((LLVM)); then
     # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
-    CFLAGS="$CFLAGS -shared-libasan -fno-sanitize=function"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
 fi
 
-LDFLAGS=""
+MKOSI_LDFLAGS=""
 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
-    LDFLAGS="$LDFLAGS -Wl,-rpath=$(dirname "$(clang --print-file-name=libclang_rt.asan.so)")"
+    MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(dirname "$(clang --print-file-name=libclang_rt.asan.so)")"
 fi
 
 IFS=
@@ -66,6 +66,9 @@ IFS=
 # https://github.com/mesonbuild/meson/pull/12835 is available.
 # shellcheck disable=SC2046
 env \
+--unset=CFLAGS \
+--unset=CXXFLAGS \
+--unset=LDFLAGS \
 ANNOBIN="no-active-checks" \
 CC_LD="$( ((LLVM)) && echo lld)" \
 CXX_LD="$( ((LLVM)) && echo lld)" \
@@ -85,9 +88,9 @@ CXX_LD="$( ((LLVM)) && echo lld)" \
     --define "version_override $VERSION" \
     --define "release_override $RELEASE" \
     "${COMMON_MACRO_OVERRIDES[@]}" \
-    --define "build_cflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cflags}") $CFLAGS" \
-    --define "build_cxxflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cxxflags}") $CFLAGS" \
-    --define "build_ldflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_ldflags}") $LDFLAGS" \
+    --define "build_cflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cflags}") $MKOSI_CFLAGS $CFLAGS" \
+    --define "build_cxxflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
+    --define "build_ldflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_ldflags}") $MKOSI_LDFLAGS $LDFLAGS" \
     --define "meson_build %{shrink:%{__meson} compile -C %{_vpath_builddir} -j %{_smp_build_ncpus} %{nil}}" \
     --define "meson_install %{shrink:DESTDIR=%{buildroot} %{__meson} install -C %{_vpath_builddir} --no-rebuild --quiet %{nil}}" \
     --define "meson_extra_configure_options -D mode=developer -D b_sanitize=${SANITIZERS:-none}" \
index 8cdfdb719ed05f59392e7d2e703287f1f9b8835c..1db5b7afa964437d9280d031c61a9d5a21caf8cb 100755 (executable)
@@ -44,15 +44,15 @@ EOF
 cat debian/changelog >>debian/changelog.new
 mv debian/changelog.new debian/changelog
 
-CFLAGS="-O${OPTIMIZATION:-0}"
+MKOSI_CFLAGS="-O${OPTIMIZATION:-0}"
 if ((LLVM)); then
     # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
-    CFLAGS="$CFLAGS -shared-libasan -fno-sanitize=function"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
 fi
 
-LDFLAGS=""
+MKOSI_LDFLAGS=""
 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
-    LDFLAGS="$LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
+    MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
 fi
 
 # TODO: Drop GENSYMBOLS_LEVEL once https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=986746 is fixed.
@@ -75,9 +75,9 @@ build() {
         $( ((WITH_DOCS)) || echo nodoc) \
         pkg.systemd.upstream \
     ")" \
-    DEB_CFLAGS_APPEND="$CFLAGS" \
-    DEB_CXXFLAGS_APPEND="$CFLAGS" \
-    DEB_LDFLAGS_APPEND="$LDFLAGS" \
+    DEB_CFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \
+    DEB_CXXFLAGS_APPEND="$MKOSI_CFLAGS $CFLAGS" \
+    DEB_LDFLAGS_APPEND="$MKOSI_LDFLAGS $LDFLAGS" \
     DPKG_FORCE="unsafe-io" \
     DPKG_DEB_COMPRESSOR_TYPE="none" \
     DH_MISSING="--fail-missing" \
index 11be720453e72cf076b8c9805f9357f69e941c73..c6f4155f95e581ffcfcf7e24b25dca67da76b779 100755 (executable)
@@ -42,24 +42,24 @@ DIST="$(rpm --eval %dist)"
 ARCH="$(rpm --eval %_arch)"
 SRCDEST="/usr/src/debug/systemd-$VERSION-${RELEASE}${DIST}.$ARCH"
 
-CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
+MKOSI_CFLAGS="-O${OPTIMIZATION:-0} -Wp,-U_FORTIFY_SOURCE"
 if ((WITH_DEBUG)); then
-    CFLAGS="$CFLAGS -fdebug-prefix-map=../src=$SRCDEST"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=$SRCDEST"
 fi
 if ((LLVM)); then
     # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
-    CFLAGS="$CFLAGS -shared-libasan -fno-sanitize=function"
+    MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
 fi
 
-LDFLAGS="$(rpm --eval "%{?build_ldflags}") $LDFLAGS"
+MKOSI_LDFLAGS="$(rpm --eval "%{?build_ldflags}")"
 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
-    LDFLAGS="$LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
+    MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
 fi
 
 # 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.
-if [[ -z "${LDFLAGS// }" ]]; then
-    LDFLAGS="%{nil}"
+if [[ -z "${MKOSI_LDFLAGS// }" ]]; then
+    MKOSI_LDFLAGS="%{nil}"
 fi
 
 build() {
@@ -70,6 +70,9 @@ build() {
     # starts to use it.
     # shellcheck disable=SC2046
     env \
+    --unset CFLAGS \
+    --unset CXXFLAGS \
+    --unset LDFLAGS \
     CC="$( ((LLVM)) && echo clang || echo gcc)" \
     CXX="$( ((LLVM)) && echo clang++ || echo g++)" \
     CC_LD="$( ((LLVM)) && echo lld)" \
@@ -90,9 +93,9 @@ build() {
         --define "version_override $VERSION" \
         --define "release_override $RELEASE" \
         --define "__check_files sh -c '$(rpm --define "_topdir /var/tmp" --eval %__check_files) | tee /tmp/unpackaged-files'" \
-        --define "build_cflags $(rpm --eval "%{?build_cflags}") $CFLAGS" \
-        --define "build_cxxflags $(rpm --eval "%{?build_cxxflags}") $CFLAGS" \
-        --define "build_ldflags $LDFLAGS" \
+        --define "build_cflags $(rpm --eval "%{?build_cflags}") $MKOSI_CFLAGS $CFLAGS" \
+        --define "build_cxxflags $(rpm --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
+        --define "build_ldflags $MKOSI_LDFLAGS $LDFLAGS" \
         --define "meson_build %{shrink:%{__meson} compile -C %{_vpath_builddir} -j %{_smp_build_ncpus} %{nil}}" \
         --define "meson_install %{shrink:DESTDIR=%{buildroot} %{__meson} install -C %{_vpath_builddir} --no-rebuild --quiet %{nil}}" \
         --define "__meson_auto_features auto -D mode=developer -D b_sanitize=${SANITIZERS:-none}" \