2017-12-24 09:53:20 +03:00
#!/bin/sh
2021-10-01 14:04:32 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2020-12-06 19:45:01 +03:00
set -e
2016-07-16 03:00:44 +03:00
# This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
# Simply invoke "mkosi" in the project directory to build an OS image.
2017-07-12 20:58:53 +03:00
# If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
# as out-of-tree build dir. Otherwise, let's make up our own builddir.
2023-01-29 17:04:13 +03:00
[ -z "$BUILDDIR" ] && BUILDDIR="$PWD"/build
# Let's make sure we're using stuff from the build directory first if available there.
PATH="$BUILDDIR:$PATH"
export PATH
2017-07-12 20:58:53 +03:00
2022-08-22 14:21:07 +03:00
# The bpftool script shipped by Ubuntu tries to find the actual program to run via querying `uname -r` and
# using the current kernel version. This obviously doesn't work in containers. As a workaround, we override
# the ubuntu script with a symlink to the first bpftool program we can find.
for bpftool in /usr/lib/linux-tools/*/bpftool; do
2023-02-21 16:22:52 +03:00
[ -x "$bpftool" ] || continue
ln -sf "$bpftool" "$BUILDDIR"/bpftool
break
2022-08-22 14:21:07 +03:00
done
2022-10-14 15:53:41 +03:00
# CentOS Stream 8 includes bpftool 4.18.0 which is lower than what we need. However, they've backported the
# specific feature we need ("gen skeleton") to this version, so we replace bpftool with a script that reports
# version 5.6.0 to satisfy meson which makes bpf work on CentOS Stream 8 as well.
if [ "$(grep '^ID=' /etc/os-release)" = "ID=\"centos\"" ] && [ "$(grep '^VERSION=' /etc/os-release)" = "VERSION=\"8\"" ]; then
2023-02-21 16:22:52 +03:00
cat >"$BUILDDIR"/bpftool <<EOF
2022-10-14 15:53:41 +03:00
#!/bin/sh
if [ "\$1" = --version ]; then
2023-02-21 16:22:52 +03:00
echo 5.6.0
2022-10-14 15:53:41 +03:00
else
2023-02-21 16:22:52 +03:00
exec /usr/sbin/bpftool \$@
2022-10-14 15:53:41 +03:00
fi
EOF
2023-02-21 16:22:52 +03:00
chmod +x "$BUILDDIR"/bpftool
2022-10-14 15:53:41 +03:00
fi
2018-02-09 21:22:40 +03:00
if [ ! -f "$BUILDDIR"/build.ninja ] ; then
2023-02-21 16:22:52 +03:00
sysvinit_path=$(realpath /etc/init.d)
init_path=$(realpath /sbin/init 2>/dev/null)
if [ -z "$init_path" ] ; then
rootprefix=""
else
rootprefix=${init_path%/lib/systemd/systemd}
rootprefix=/${rootprefix#/}
fi
# On debian-like systems the library directory is not /usr/lib64 but /usr/lib/<arch-triplet>/.
# It is important to use the right one especially for cryptsetup plugins, otherwise they will be
# installed in the wrong directory and not be found by cryptsetup. Assume native build.
if grep -q -e "ID=debian" -e "ID_LIKE=debian" /etc/os-release && command -v dpkg 2>/dev/null; then
LIBDIR="-Drootlibdir=/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
PAMDIR="-Dpamlibdir=/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security"
fi
# Cannot quote $LIBDIR and $PAMDIR, because they may be empty, and meson will fail.
# shellcheck disable=SC2086
meson setup "$BUILDDIR" \
${LIBDIR:-} \
${PAMDIR:-} \
-D "sysvinit-path=$sysvinit_path" \
-D "rootprefix=$rootprefix" \
-D man=false \
-D translations=false \
-D version-tag="${VERSION_TAG}" \
-D mode=developer \
-D b_sanitize="${SANITIZERS:-none}" \
-D install-tests=true \
-D tests=unsafe \
-D slow-tests=true \
-D utmp=true \
-D hibernate=true \
-D ldconfig=true \
-D resolve=true \
-D efi=true \
-D tpm=true \
-D environment-d=true \
-D binfmt=true \
-D repart=true \
-D sysupdate=true \
-D coredump=true \
-D pstore=true \
-D oomd=true \
-D logind=true \
-D hostnamed=true \
-D localed=true \
-D machined=true \
-D portabled=true \
-D sysext=true \
-D userdb=true \
-D homed=true \
-D networkd=true \
-D timedated=true \
-D timesyncd=true \
-D remote=true \
-D nss-myhostname=true \
-D nss-mymachines=true \
-D nss-resolve=true \
-D nss-systemd=true \
-D firstboot=true \
-D randomseed=true \
-D backlight=true \
-D vconsole=true \
-D quotacheck=true \
-D sysusers=true \
-D tmpfiles=true \
-D importd=true \
-D hwdb=true \
-D rfkill=true \
-D xdg-autostart=true \
-D translations=true \
-D polkit=true \
-D acl=true \
-D audit=true \
-D blkid=true \
-D fdisk=true \
-D kmod=true \
-D pam=true \
-D pwquality=true \
-D microhttpd=true \
-D libcryptsetup=true \
-D libcurl=true \
-D idn=true \
-D libidn2=true \
-D qrencode=true \
-D gcrypt=true \
-D gnutls=true \
-D openssl=true \
-D cryptolib=openssl \
-D p11kit=true \
-D libfido2=true \
-D tpm2=true \
-D elfutils=true \
-D zstd=true \
-D xkbcommon=true \
-D pcre2=true \
-D glib=true \
-D dbus=true \
-D gnu-efi=true \
-D kernel-install=true \
-D analyze=true \
-D bpf-framework=true \
-D ukify=true
2017-12-06 15:53:39 +03:00
fi
2023-02-21 17:19:06 +03:00
ninja -C "$BUILDDIR" "$@"
2020-04-22 02:58:44 +03:00
if [ "$WITH_TESTS" = 1 ] ; then
2023-02-21 16:22:52 +03:00
if [ -n "$SANITIZERS" ]; then
2023-02-21 17:09:38 +03:00
export ASAN_OPTIONS="$MKOSI_ASAN_OPTIONS"
export UBSAN_OPTIONS="$MKOSI_UBSAN_OPTIONS"
2023-02-21 16:22:52 +03:00
TIMEOUT_MULTIPLIER=3
else
TIMEOUT_MULTIPLIER=1
fi
2023-02-21 17:19:06 +03:00
meson test -C "$BUILDDIR" --print-errorlogs --timeout-multiplier=$TIMEOUT_MULTIPLIER
2020-04-22 02:58:44 +03:00
fi
2020-12-06 19:45:45 +03:00
2023-01-29 17:07:38 +03:00
meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
2016-12-07 01:17:57 +03:00
2022-09-09 09:53:37 +03:00
if [ -d mkosi.kernel/ ]; then
2023-02-21 17:19:06 +03:00
SRCDIR="$SRCDIR/mkosi.kernel"
BUILDDIR="$BUILDDIR/mkosi.kernel"
cd "$SRCDIR"
mkdir -p "$BUILDDIR"
2022-09-09 09:53:37 +03:00
2023-02-21 16:22:52 +03:00
# Ensure fast incremental builds by fixating these values which usually change for each build.
export KBUILD_BUILD_TIMESTAMP="Fri Jun 5 15:58:00 CEST 2015"
export KBUILD_BUILD_HOST="mkosi"
2022-11-02 14:19:11 +03:00
2023-02-21 17:19:06 +03:00
scripts/kconfig/merge_config.sh -O "$BUILDDIR" \
2023-02-21 16:22:52 +03:00
../mkosi.kernel.config \
tools/testing/selftests/bpf/config.x86_64 \
tools/testing/selftests/bpf/config
2022-09-09 09:53:37 +03:00
2023-02-21 17:19:06 +03:00
make O="$BUILDDIR" -j "$(nproc)"
2022-09-09 09:53:37 +03:00
2023-02-21 17:19:06 +03:00
KERNEL_RELEASE=$(make O="$BUILDDIR" -s kernelrelease)
2023-02-21 16:22:52 +03:00
mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE"
2023-02-21 17:19:06 +03:00
make O="$BUILDDIR" INSTALL_MOD_PATH="$DESTDIR/usr" modules_install
make O="$BUILDDIR" INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install
2023-02-21 16:22:52 +03:00
mkdir -p "$DESTDIR/usr/lib/kernel/selftests"
2023-02-21 17:19:06 +03:00
make -C tools/testing/selftests -j "$(nproc)" O="$BUILDDIR" KSFT_INSTALL_PATH="$DESTDIR/usr/lib/kernel/selftests" SKIP_TARGETS="" install
2022-12-02 22:40:22 +03:00
2023-02-21 16:22:52 +03:00
ln -sf /usr/lib/kernel/selftests/bpf/bpftool "$DESTDIR/usr/bin/bpftool"
2022-09-09 09:53:37 +03:00
fi