summaryrefslogtreecommitdiffstats
path: root/mkosi.images/build/mkosi.conf.d/arch/mkosi.build.chroot
blob: 444f069b6f9e205eb2eca07cb8e3b6db0ac7d403 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e

# shellcheck source=/dev/null
. /usr/lib/os-release

if [[ ! -f "pkg/$ID/PKGBUILD" ]]; then
    echo "PKGBUILD not found at pkg/$ID/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 symlinks instead to make sure they are in the
# expected locations. Because we run with --noextract we are responsible for making sure the source files
# appear in src/. This means not only the systemd source directory, but also the patches and configuration
# files that are shipped in the packaging repository. To achieve this, instead of symlinking the systemd
# sources and build directory directly into "pkg/$ID/src", we symlink them into "pkg/$ID" and then symlink
# "pkg/$ID" to "pkg/$ID/src".
ln --symbolic "$SRCDIR" "pkg/$ID/systemd"
ln --symbolic "$BUILDDIR" "pkg/$ID/build"
ln --symbolic . "pkg/$ID/src"

MKOSI_CFLAGS="-O0 -Wp,-U_FORTIFY_SOURCE"
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=""
if ((LLVM)) && [[ -n "$SANITIZERS" ]]; then
    MKOSI_LDFLAGS="$MKOSI_LDFLAGS -Wl,-rpath=$(clang --print-file-name="")lib/linux"
fi

MKOSI_MESON_OPTIONS="-D mode=developer -D b_sanitize=${SANITIZERS:-none}"
if ((WIPE)) && [[ -d "$BUILDDIR/meson-private" ]]; then
    MKOSI_MESON_OPTIONS="$MKOSI_MESON_OPTIONS --wipe"
fi

# Override the default options. 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
export CC="$( ((LLVM)) && echo clang || echo gcc)"
export CXX="$( ((LLVM)) && echo clang++ || echo g++)"
export CC_LD="$( ((LLVM)) && echo lld)"
export CXX_LD="$( ((LLVM)) && echo lld)"
export CFLAGS="\$CFLAGS $MKOSI_CFLAGS $CFLAGS"
export CXXFLAGS="\$CXXFLAGS $MKOSI_CFLAGS $CFLAGS"
export LDFLAGS="\$LDFLAGS $MKOSI_LDFLAGS $LDFLAGS"
OPTIONS=(
    docs
    !libtool
    !staticlibs
    emptydirs
    !zipman
    purge
    $( ((WITH_DEBUG)) && echo strip || echo !strip)
    $( ((WITH_DEBUG)) && echo debug || echo !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

sed --in-place "pkg/$ID/PKGBUILD" \
    --expression "s/^_tag=.*/_tag=$(cat meson.version)/" \
    --expression "s/^pkgrel=.*/pkgrel=$(date "+%Y%m%d%H%M%S" --date "@$TS")/"

# We get around makepkg's root check by setting EUID to something else.
# shellcheck disable=SC2046
env --chdir="pkg/$ID" \
    EUID=123 \
    makepkg \
    --noextract \
    $( ((WITH_TESTS)) || echo --nocheck) \
    --force \
    _systemd_UPSTREAM=1 \
    _systemd_QUIET=$( ((MESON_VERBOSE)); echo $? ) \
    BUILDDIR="$PWD/pkg/$ID" \
    PKGDEST="$OUTPUTDIR" \
    PKGEXT=".pkg.tar" \
    MESON_EXTRA_CONFIGURE_OPTIONS="$MKOSI_MESON_OPTIONS $MESON_OPTIONS"

(
    shopt -s nullglob
    rm -f "$BUILDDIR"/*.pkg.tar
)

cp "$OUTPUTDIR"/*.pkg.tar "$PACKAGEDIR"
cp "$OUTPUTDIR"/*.pkg.tar "$BUILDDIR"