mirror of
https://github.com/systemd/systemd
synced 2024-10-01 13:55:20 +00:00
mkosi: Allow setting custom CFLAGS and LDFLAGS
This commit is contained in:
parent
0ccbd22f04
commit
51ce4c7864
|
@ -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
|
||||
|
|
|
@ -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}" \
|
||||
|
|
|
@ -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" \
|
||||
|
|
|
@ -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}" \
|
||||
|
|
Loading…
Reference in a new issue