summaryrefslogtreecommitdiffstats
path: root/mkosi.images/base/mkosi.conf.d/10-arch/mkosi.build.chroot
blob: aff566f94c24fb409cce0f334bff3b760bd5fda7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -ex

if [ ! -f "pkg/$PKG_SUBDIR/PKGBUILD" ]; then
    echo "PKGBUILD not found at pkg/$PKG_SUBDIR/PKGBUILD, run mkosi once with -ff to make sure the PKGBUILD is cloned" >&2
    exit 1
fi

# We can't configure the source or build directory so we use bind mounts instead to make sure they are in the
# expected locations.
mount --mkdir --bind "$SRCDIR" "pkg/$PKG_SUBDIR/systemd-stable/"
mount --mkdir --bind "$BUILDDIR" "pkg/$PKG_SUBDIR/build/"
# Because we run with --noextract we are responsible for making sure the source files appear in src/.
mount --mkdir --rbind "$PWD/pkg/$PKG_SUBDIR" "pkg/$PKG_SUBDIR/src/"

# shellcheck source=/dev/null
. /etc/makepkg.conf

# Override the default options. Use -Og because -O0 doesn't work with FORTIFY_SOURCE. We specifically disable
# "strip", "zipman" and "lto" as they slow down builds significantly. OPTIONS= cannot be overridden on the
# makepkg command line so we append to /etc/makepkg.conf instead. The rootfs is overlaid with a writable
# tmpfs during the build script so these changes don't end up in the image itself.
tee --append /etc/makepkg.conf >/dev/null <<EOF
CFLAGS="$CFLAGS -Og"
OPTIONS=(!strip docs !libtool !staticlibs emptydirs !zipman purge debug !lto)
EOF

# Linting the PKGBUILD takes multiple seconds every build so avoid that by nuking all the linting functions.
rm /usr/share/makepkg/lint_pkgbuild/*

if [ -d .git/ ] && [ -z "$(git status --porcelain)" ]; then
    TS="$(git show --no-patch --format=%ct HEAD)"
else
    TS="${SOURCE_DATE_EPOCH:-$(date +%s)}"
fi

# We get around makepkg's root check by setting EUID to something else.
# shellcheck disable=SC2046
env --chdir="pkg/$PKG_SUBDIR" \
    EUID=123 \
    makepkg \
    --noextract \
    $( ((WITH_TESTS)) || echo --nocheck) \
    --force \
    UPSTREAM=1 \
    QUIET=1 \
    BUILDDIR="$PWD/pkg/$PKG_SUBDIR" \
    PKGDEST="$PACKAGEDIR" \
    PKGEXT=".pkg.tar" \
    PKGVER="$(cat meson.version)" \
    PKGREL="$(date "+%Y%m%d%H%M%S" --date "@$TS")" \
    MESON_EXTRA_CONFIGURE_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"