152 lines
5.6 KiB
Bash
Executable File
152 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
set -e
|
|
|
|
. mkosi/mkosi.functions
|
|
|
|
if [[ "$1" == "clangd" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [[ ! -f "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" ]]; then
|
|
echo "spec not found at pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
|
|
exit 1
|
|
fi
|
|
|
|
TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
|
|
|
# The openSUSE filelists hardcode the manpage compression extension. This causes rpmbuild errors since we
|
|
# disable manpage compression as the files cannot be found. Fix the issue by removing the compression
|
|
# extension.
|
|
#
|
|
# TODO: remove manual cgroups-agent patch when the upstream spec is updated
|
|
while read -r filelist; do
|
|
sed 's/\.gz$//; /systemd-cgroups-agent/d' "$filelist" >"/tmp/$(basename "$filelist")"
|
|
mount --bind "/tmp/$(basename "$filelist")" "$filelist"
|
|
done < <(find "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}" -name "files.*")
|
|
|
|
if [[ "$(rpm --eval "%{lua:print(rpm.vercmp('$(rpm --version | cut -d ' ' -f3)', '4.20'))}")" == "-1" ]]; then
|
|
# Fix the %install override so debuginfo packages are generated.
|
|
tee --append /usr/lib/rpm/suse/macros <<'EOF'
|
|
%install %{debug_package}\
|
|
%%install\
|
|
%{nil}
|
|
EOF
|
|
fi
|
|
|
|
VERSION="$(cat meson.version)"
|
|
RELEASE="$(date "+%Y%m%d%H%M%S" --date "@$TS")"
|
|
|
|
MKOSI_CFLAGS="-O0 -g -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
|
|
|
|
# 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 "${MKOSI_LDFLAGS// }" ]]; then
|
|
MKOSI_LDFLAGS="%{nil}"
|
|
fi
|
|
|
|
MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none}"
|
|
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.
|
|
#
|
|
# TODO: remove manual default-hierarchy patch when the upstream spec is updated
|
|
sed "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec" -e '1062,1075d' -e '/integration-tests\/README/d' -e '/default-hierarchy/ d' >/tmp/systemd.spec
|
|
mount --bind /tmp/systemd.spec "pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
|
|
|
|
build() {
|
|
IFS=
|
|
# 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)" \
|
|
CXX_LD="$( ((LLVM)) && echo lld)" \
|
|
rpmbuild \
|
|
-bb \
|
|
--noprep \
|
|
--build-in-place \
|
|
--with upstream \
|
|
$( ((WITH_TESTS)) || echo "--nocheck") \
|
|
--define "_topdir /var/tmp" \
|
|
--define "_sourcedir $PWD/pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}" \
|
|
--define "_rpmdir $BUILDDIR" \
|
|
${BUILDDIR:+"--define=_vpath_builddir $BUILDDIR"} \
|
|
--define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
|
|
--define "_binary_payload w.ufdio" \
|
|
$( ((WITH_DEBUG)) || echo "--define=debug_package %{nil}") \
|
|
--define "vendor openSUSE" \
|
|
--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}") $MKOSI_CFLAGS $CFLAGS" \
|
|
--define "build_cxxflags $(rpm --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
|
|
--define "build_ldflags $MKOSI_LDFLAGS $LDFLAGS" \
|
|
$( ((MESON_VERBOSE)) || echo "--undefine=__meson_verbose") \
|
|
--define "meson_extra_configure_options $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
|
|
--define "__os_install_post /usr/lib/rpm/brp-suse %{nil}" \
|
|
--define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
|
|
--define "__script_requires %{nil}" \
|
|
--define "_find_debuginfo_dwz_opts %{nil}" \
|
|
--define "_find_debuginfo_opts --unique-debug-src-base \"%{name}\"" \
|
|
"$@" \
|
|
"pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/systemd.spec"
|
|
|
|
EXIT_STATUS=$?
|
|
|
|
# TODO: Remove when the opensuse spec cleans these up itself (https://build.opensuse.org/request/show/1251175).
|
|
rm -f \
|
|
systemd.lang \
|
|
debugfiles.list \
|
|
debuglinks.list \
|
|
debugsourcefiles.list \
|
|
debugsources.list \
|
|
elfbins.list
|
|
|
|
# Make sure we don't reconfigure twice.
|
|
MKOSI_MESON_OPTIONS="${MKOSI_MESON_OPTIONS//"--wipe"/}"
|
|
|
|
return $EXIT_STATUS
|
|
}
|
|
|
|
(
|
|
shopt -s nullglob
|
|
rm -f "$BUILDDIR"/*.rpm
|
|
)
|
|
|
|
if ! build; then
|
|
if [[ ! -s /tmp/unpackaged-files ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
grep -v ".debug" /tmp/unpackaged-files >>"pkg/$PKG_SUBDIR${GIT_SUBDIR:+/$GIT_SUBDIR}/files.systemd"
|
|
build --noprep --nocheck
|
|
fi
|
|
|
|
cp "$BUILDDIR"/*.rpm "$PACKAGEDIR"
|
|
|
|
make_sysext_unsigned /var/tmp/BUILD/*/BUILDROOT
|