Debian Codegraph @

mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.build.chroot

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 . mkosi/mkosi.functions
6
7 if [[ "$1" == "clangd" ]]; then
8 exit 0
9 fi
10
11 if [[ ! -f "pkg/$PKG_SUBDIR/systemd.spec" ]]; then
12 echo "spec not found at pkg/$PKG_SUBDIR/systemd.spec, run mkosi once with -ff to make sure the spec is cloned" >&2
13 exit 1
14 fi
15
16 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
17
18 if [[ "$(rpm --eval "%{lua:print(rpm.vercmp('$(rpm --version | cut -d ' ' -f3)', '4.19.91'))}")" == "-1" ]]; then
19 # Fix the %install override so debuginfo packages are generated even when --build-in-place is used.
20 # See https://github.com/rpm-software-management/rpm/issues/3042.
21 tee --append /usr/lib/rpm/redhat/macros <<'EOF'
22 %install %{?_enable_debug_packages:%{debug_package}}\
23 %%install\
24 %{nil}
25 EOF
26 fi
27
28 VERSION="$(cat meson.version)"
29 RELEASE="$(date "+%Y%m%d%H%M%S" --date "@$TS")"
30
31 COMMON_MACRO_OVERRIDES=(
32 --define "toolchain $( ((LLVM)) && echo clang || echo gcc)"
33 --define "_fortify_level 0"
34 --undefine _lto_cflags
35 # TODO: Remove once redhat-rpm-config 292 is available everywhere.
36 --define "_hardening_clang_cflags --config=/usr/lib/rpm/redhat/redhat-hardened-clang.cfg"
37 --define "_hardening_clang_ldflags --config=/usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg"
38 )
39
40 # TODO: Drop -U_FORTIFY_SOURCE when we switch to CentOS Stream 10.
41 MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE"
42 if ((WITH_DEBUG)); then
43 MKOSI_CFLAGS="$MKOSI_CFLAGS -fdebug-prefix-map=../src=/usr/src/debug/systemd"
44 fi
45 if ((LLVM)); then
46 # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
47 MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
48 fi
49
50 MKOSI_LDFLAGS=""
51 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
52 MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
53 fi
54
55 MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
56 if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
57 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
58 fi
59 if ((COVERAGE)); then
60 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
61 MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
62 fi
63
64 (
65 shopt -s nullglob
66 rm -f "$BUILDDIR"/*.rpm
67 )
68
69 IFS=
70 # TODO: Replace meson_build and meson_install overrides with "--undefine __meson_verbose" once
71 # https://github.com/mesonbuild/meson/pull/12835 is available.
72 # shellcheck disable=SC2046
73 env \
74 --unset=CFLAGS \
75 --unset=CXXFLAGS \
76 --unset=LDFLAGS \
77 ANNOBIN="no-active-checks" \
78 CC_LD="$( ((LLVM)) && echo lld)" \
79 CXX_LD="$( ((LLVM)) && echo lld)" \
80 rpmbuild \
81 -bb \
82 --noprep \
83 --build-in-place \
84 --with upstream \
85 --without lto \
86 $( ((WITH_TESTS)) || echo "--nocheck") \
87 $( ((WITH_DOCS)) || echo "--without=docs") \
88 --define "_topdir /var/tmp" \
89 --define "_sourcedir $PWD/pkg/$PKG_SUBDIR" \
90 --define "_rpmdir $BUILDDIR" \
91 ${BUILDDIR:+"--define=_vpath_builddir $BUILDDIR"} \
92 --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
93 --define "_binary_payload w.ufdio" \
94 $( ((WITH_DEBUG)) || echo "--define=debug_package %{nil}") \
95 --define "version_override $VERSION" \
96 --define "release_override $RELEASE" \
97 "${COMMON_MACRO_OVERRIDES[@]}" \
98 --define "build_cflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cflags}") $MKOSI_CFLAGS $CFLAGS" \
99 --define "build_cxxflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_cxxflags}") $MKOSI_CFLAGS $CFLAGS" \
100 --define "build_ldflags $(rpm "${COMMON_MACRO_OVERRIDES[@]}" --eval "%{?build_ldflags}") $MKOSI_LDFLAGS $LDFLAGS" \
101 --define "meson_build %{shrink:%{__meson} compile -C %{_vpath_builddir} -j %{_smp_build_ncpus} $( ((MESON_VERBOSE)) && echo --verbose) %{nil}}" \
102 --define "meson_install %{shrink:DESTDIR=%{buildroot} %{__meson} install -C %{_vpath_builddir} --no-rebuild --quiet %{nil}}" \
103 --define "meson_extra_configure_options $MKOSI_MESON_OPTIONS $MESON_OPTIONS" \
104 $( ((WITH_DEBUG)) || echo "--define=__brp_strip %{nil}") \
105 --define "__brp_compress %{nil}" \
106 --define "__brp_mangle_shebangs %{nil}" \
107 --define "__brp_strip_comment_note %{nil}" \
108 --define "__brp_strip_static_archive %{nil}" \
109 --define "__brp_check_rpaths %{nil}" \
110 --define "__elf_exclude_path ^/usr/lib/systemd/tests/unit-tests/.*$" \
111 --define "__script_requires %{nil}" \
112 --define "_find_debuginfo_opts --unique-debug-src-base \"%{name}\"" \
113 --define "_find_debuginfo_dwz_opts %{nil}" \
114 --undefine _package_note_flags \
115 "pkg/$PKG_SUBDIR/systemd.spec"
116
117 cp "$BUILDDIR"/*.rpm "$PACKAGEDIR"
118
119 make_sysext_unsigned /var/tmp/BUILD/*/BUILDROOT