Debian Codegraph @

mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot

raw
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -e
4
5 if [[ "$1" == "clangd" ]]; then
6 exit 0
7 fi
8
9 if [[ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]]; then
10 echo "PKGBUILD not found at pkg/$PKG_SUBDIR/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
11 exit 1
12 fi
13
14 MKOSI_CFLAGS="-O0 -g -Wp,-U_FORTIFY_SOURCE"
15 if ((LLVM)); then
16 # TODO: Remove -fno-sanitize-function when https://github.com/systemd/systemd/issues/29972 is fixed.
17 MKOSI_CFLAGS="$MKOSI_CFLAGS -shared-libasan -fno-sanitize=function"
18 fi
19
20 MKOSI_LDFLAGS=""
21 if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
22 MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(realpath "$(clang --print-runtime-dir)")"
23 fi
24
25 MKOSI_MESON_OPTIONS="-D mode=developer -D vcs-tag=${VCS_TAG:-true} -D b_sanitize=${SANITIZERS:-none} -Dtime-epoch=1744207869"
26 if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
27 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
28 fi
29 if ((COVERAGE)); then
30 MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS -D b_coverage=true"
31 MKOSI_CFLAGS="$MKOSI_CFLAGS -fprofile-dir=/coverage"
32 fi
33
34 # Override the default options. We specifically disable "strip", "zipman" and "lto" as they slow down builds
35 # significantly. OPTIONS= cannot be overridden on the makepkg command line so we append to /etc/makepkg.conf
36 # instead. The rootfs is overlaid with a writable tmpfs during the build script so these changes don't end up
37 # in the image itself.
38 tee --append /etc/makepkg.conf >/dev/null <<EOF
39 export CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)"
40 export CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)"
41 export CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)"
42 export CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)"
43 export CFLAGS="\$CFLAGS $MKOSI_CFLAGS $CFLAGS"
44 export CXXFLAGS="\$CXXFLAGS $MKOSI_CFLAGS $CFLAGS"
45 export LDFLAGS="\$LDFLAGS $MKOSI_LDFLAGS $LDFLAGS"
46 OPTIONS=(
47 docs
48 !libtool
49 !staticlibs
50 emptydirs
51 !zipman
52 purge
53 $( ((WITH_DEBUG)) && echo strip || echo !strip)
54 $( ((WITH_DEBUG)) && echo debug || echo !debug)
55 !lto
56 )
57 EOF
58
59 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
60
61 sed "pkg/$PKG_SUBDIR/PKGBUILD" \
62 --expression "/-Dsysvinit-path=/d" \
63 --expression "/-Dsysvrcnd-path=/d" \
64 --expression "s/^pkgver=.*/pkgver=$(cat meson.version)/" \
65 --expression "s/^pkgrel=.*/pkgrel=$(date "+%Y%m%d%H%M%S" --date "@$TS")/" >/tmp/PKGBUILD
66 mount --bind /tmp/PKGBUILD "pkg/$PKG_SUBDIR/PKGBUILD"
67
68 (
69 shopt -s nullglob
70 rm -f "$BUILDDIR"/*.pkg.tar
71 )
72
73 # We can't configure the source or build directory so we use symlinks instead to make sure they are in the
74 # expected locations. Because we run with --noextract we are responsible for making sure the source files
75 # appear in src/. This means not only the systemd source directory, but also the patches and configuration
76 # files that are shipped in the packaging repository. To achieve this, instead of symlinking the systemd
77 # sources and build directory directly into "pkg/$PKG_SUBDIR/src", we symlink them into "pkg/$PKG_SUBDIR" and
78 # then symlink "pkg/$PKG_SUBDIR" to "pkg/$PKG_SUBDIR/src".
79 trap 'rm -f "pkg/$PKG_SUBDIR/src" "pkg/$PKG_SUBDIR/build" "pkg/$PKG_SUBDIR/systemd"' EXIT
80 ln --symbolic "$SRCDIR" "pkg/$PKG_SUBDIR/systemd"
81 ln --symbolic "$BUILDDIR" "pkg/$PKG_SUBDIR/build"
82 ln --symbolic . "pkg/$PKG_SUBDIR/src"
83
84 # We get around makepkg's root check by setting EUID to something else.
85 # Linting the PKGBUILD takes multiple seconds every build so avoid that by nuking all the linting functions.
86 # shellcheck disable=SC2046
87 env --chdir="pkg/$PKG_SUBDIR" \
88 EUID=123 \
89 MAKEPKG_LINT_PKGBUILD=0 \
90 makepkg \
91 --noextract \
92 --noprepare \
93 $( ((WITH_TESTS)) || echo --nocheck) \
94 --clean \
95 --force \
96 _systemd_UPSTREAM=1 \
97 BUILDDIR="$PWD/pkg/$PKG_SUBDIR" \
98 PKGDEST="$BUILDDIR" \
99 PKGEXT=".pkg.tar" \
100 MESON_EXTRA_CONFIGURE_OPTIONS="$MKOSI_MESON_OPTIONS $MESON_OPTIONS"
101
102 cp "$BUILDDIR"/*.pkg.tar "$PACKAGEDIR"