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/mkosi.functions
15
16 MKOSI_CFLAGS="$MKOSI_CFLAGS -Wp,-U_FORTIFY_SOURCE"
17
18 # Override the default options. We specifically disable "strip", "zipman" and "lto" as they slow down builds
19 # significantly. OPTIONS= cannot be overridden on the makepkg command line so we append to /etc/makepkg.conf
20 # instead. The rootfs is overlaid with a writable tmpfs during the build script so these changes don't end up
21 # in the image itself.
22 tee --append /etc/makepkg.conf >/dev/null <<EOF
23 export CC="$( ((CC)) && echo "$CC" || ((LLVM)) && echo clang || echo gcc)"
24 export CXX="$( ((CXX)) && echo "$CXX" || ((LLVM)) && echo clang++ || echo g++)"
25 export CC_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)"
26 export CXX_LD="$( ((LD)) && echo "$LD" || ((LLVM)) && echo lld)"
27 export CFLAGS="\$CFLAGS $MKOSI_CFLAGS $CFLAGS"
28 export CXXFLAGS="\$CXXFLAGS $MKOSI_CFLAGS $CFLAGS"
29 export LDFLAGS="\$LDFLAGS $MKOSI_LDFLAGS $LDFLAGS"
30 OPTIONS=(
31 docs
32 !libtool
33 !staticlibs
34 emptydirs
35 !zipman
36 purge
37 $( ((WITH_DEBUG)) && echo strip || echo !strip)
38 $( ((WITH_DEBUG)) && echo debug || echo !debug)
39 !lto
40 )
41 EOF
42
43 TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
44
45 sed "pkg/$PKG_SUBDIR/PKGBUILD" \
46 --expression "/-Dsysvinit-path=/d" \
47 --expression "/-Dsysvrcnd-path=/d" \
48 --expression "s/^pkgver=.*/pkgver=$(cat meson.version)/" \
49 --expression "s/^pkgrel=.*/pkgrel=$(date "+%Y%m%d%H%M%S" --date "@$TS")/" >/tmp/PKGBUILD
50 mount --bind /tmp/PKGBUILD "pkg/$PKG_SUBDIR/PKGBUILD"
51
52 (
53 shopt -s nullglob
54 rm -f "$BUILDDIR"/*.pkg.tar
55 )
56
57 # We can't configure the source or build directory so we use symlinks instead to make sure they are in the
58 # expected locations. Because we run with --noextract we are responsible for making sure the source files
59 # appear in src/. This means not only the systemd source directory, but also the patches and configuration
60 # files that are shipped in the packaging repository. To achieve this, instead of symlinking the systemd
61 # sources and build directory directly into "pkg/$PKG_SUBDIR/src", we symlink them into "pkg/$PKG_SUBDIR" and
62 # then symlink "pkg/$PKG_SUBDIR" to "pkg/$PKG_SUBDIR/src".
63 trap 'rm -f "pkg/$PKG_SUBDIR/src" "pkg/$PKG_SUBDIR/build" "pkg/$PKG_SUBDIR/systemd"' EXIT
64 ln --symbolic "$SRCDIR" "pkg/$PKG_SUBDIR/systemd"
65 ln --symbolic "$BUILDDIR" "pkg/$PKG_SUBDIR/build"
66 ln --symbolic . "pkg/$PKG_SUBDIR/src"
67
68 # We get around makepkg's root check by setting EUID to something else.
69 # Linting the PKGBUILD takes multiple seconds every build so avoid that by nuking all the linting functions.
70 # shellcheck disable=SC2046
71 env --chdir="pkg/$PKG_SUBDIR" \
72 EUID=123 \
73 MAKEPKG_LINT_PKGBUILD=0 \
74 makepkg \
75 --noextract \
76 --noprepare \
77 $( ((WITH_TESTS)) || echo --nocheck) \
78 --clean \
79 --force \
80 _systemd_UPSTREAM=1 \
81 BUILDDIR="$PWD/pkg/$PKG_SUBDIR" \
82 PKGDEST="$BUILDDIR" \
83 PKGEXT=".pkg.tar" \
84 MESON_EXTRA_CONFIGURE_OPTIONS="$MKOSI_MESON_OPTIONS $MESON_OPTIONS"
85
86 cp "$BUILDDIR"/*.pkg.tar "$PACKAGEDIR"