]> git.ipfire.org Git - thirdparty/systemd.git/blame - mkosi.build
Merge pull request #26650 from yuwata/udev-trigger
[thirdparty/systemd.git] / mkosi.build
CommitLineData
7629744a 1#!/bin/sh
8f5bcd61 2# SPDX-License-Identifier: LGPL-2.1-or-later
1394a3ec 3set -e
1b0ff615 4
1b0ff615
LP
5# This is a build script for OS image generation using mkosi (https://github.com/systemd/mkosi).
6# Simply invoke "mkosi" in the project directory to build an OS image.
7
70e760e3
LP
8# If mkosi.builddir/ exists mkosi will set $BUILDDIR to it, let's then use it
9# as out-of-tree build dir. Otherwise, let's make up our own builddir.
84a4af2c
DDM
10[ -z "$BUILDDIR" ] && BUILDDIR="$PWD"/build
11
12# Let's make sure we're using stuff from the build directory first if available there.
13PATH="$BUILDDIR:$PATH"
14export PATH
70e760e3 15
37d35150
DDM
16# The bpftool script shipped by Ubuntu tries to find the actual program to run via querying `uname -r` and
17# using the current kernel version. This obviously doesn't work in containers. As a workaround, we override
18# the ubuntu script with a symlink to the first bpftool program we can find.
19for bpftool in /usr/lib/linux-tools/*/bpftool; do
a1cfe390
DDM
20 [ -x "$bpftool" ] || continue
21 ln -sf "$bpftool" "$BUILDDIR"/bpftool
22 break
37d35150
DDM
23done
24
6afeac1d
DDM
25# CentOS Stream 8 includes bpftool 4.18.0 which is lower than what we need. However, they've backported the
26# specific feature we need ("gen skeleton") to this version, so we replace bpftool with a script that reports
27# version 5.6.0 to satisfy meson which makes bpf work on CentOS Stream 8 as well.
28if [ "$(grep '^ID=' /etc/os-release)" = "ID=\"centos\"" ] && [ "$(grep '^VERSION=' /etc/os-release)" = "VERSION=\"8\"" ]; then
a1cfe390 29 cat >"$BUILDDIR"/bpftool <<EOF
6afeac1d
DDM
30#!/bin/sh
31if [ "\$1" = --version ]; then
a1cfe390 32 echo 5.6.0
6afeac1d 33else
a1cfe390 34 exec /usr/sbin/bpftool \$@
6afeac1d
DDM
35fi
36EOF
a1cfe390 37 chmod +x "$BUILDDIR"/bpftool
6afeac1d
DDM
38fi
39
c81a2569 40if [ ! -f "$BUILDDIR"/build.ninja ] ; then
a1cfe390
DDM
41 sysvinit_path=$(realpath /etc/init.d)
42
43 init_path=$(realpath /sbin/init 2>/dev/null)
44 if [ -z "$init_path" ] ; then
45 rootprefix=""
46 else
47 rootprefix=${init_path%/lib/systemd/systemd}
48 rootprefix=/${rootprefix#/}
49 fi
50
51 # On debian-like systems the library directory is not /usr/lib64 but /usr/lib/<arch-triplet>/.
52 # It is important to use the right one especially for cryptsetup plugins, otherwise they will be
53 # installed in the wrong directory and not be found by cryptsetup. Assume native build.
54 if grep -q -e "ID=debian" -e "ID_LIKE=debian" /etc/os-release && command -v dpkg 2>/dev/null; then
55 LIBDIR="-Drootlibdir=/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
56 PAMDIR="-Dpamlibdir=/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/security"
57 fi
58
59 # Cannot quote $LIBDIR and $PAMDIR, because they may be empty, and meson will fail.
60 # shellcheck disable=SC2086
61 meson setup "$BUILDDIR" \
62 ${LIBDIR:-} \
63 ${PAMDIR:-} \
64 -D "sysvinit-path=$sysvinit_path" \
65 -D "rootprefix=$rootprefix" \
66 -D man=false \
67 -D translations=false \
68 -D version-tag="${VERSION_TAG}" \
69 -D mode=developer \
70 -D b_sanitize="${SANITIZERS:-none}" \
71 -D install-tests=true \
72 -D tests=unsafe \
73 -D slow-tests=true \
74 -D utmp=true \
75 -D hibernate=true \
76 -D ldconfig=true \
77 -D resolve=true \
78 -D efi=true \
79 -D tpm=true \
80 -D environment-d=true \
81 -D binfmt=true \
82 -D repart=true \
83 -D sysupdate=true \
84 -D coredump=true \
85 -D pstore=true \
86 -D oomd=true \
87 -D logind=true \
88 -D hostnamed=true \
89 -D localed=true \
90 -D machined=true \
91 -D portabled=true \
92 -D sysext=true \
93 -D userdb=true \
94 -D homed=true \
95 -D networkd=true \
96 -D timedated=true \
97 -D timesyncd=true \
98 -D remote=true \
99 -D nss-myhostname=true \
100 -D nss-mymachines=true \
101 -D nss-resolve=true \
102 -D nss-systemd=true \
103 -D firstboot=true \
104 -D randomseed=true \
105 -D backlight=true \
106 -D vconsole=true \
107 -D quotacheck=true \
108 -D sysusers=true \
109 -D tmpfiles=true \
110 -D importd=true \
111 -D hwdb=true \
112 -D rfkill=true \
113 -D xdg-autostart=true \
114 -D translations=true \
115 -D polkit=true \
116 -D acl=true \
117 -D audit=true \
118 -D blkid=true \
119 -D fdisk=true \
120 -D kmod=true \
121 -D pam=true \
122 -D pwquality=true \
123 -D microhttpd=true \
124 -D libcryptsetup=true \
125 -D libcurl=true \
126 -D idn=true \
127 -D libidn2=true \
128 -D qrencode=true \
129 -D gcrypt=true \
130 -D gnutls=true \
131 -D openssl=true \
132 -D cryptolib=openssl \
133 -D p11kit=true \
134 -D libfido2=true \
135 -D tpm2=true \
136 -D elfutils=true \
137 -D zstd=true \
138 -D xkbcommon=true \
139 -D pcre2=true \
140 -D glib=true \
141 -D dbus=true \
142 -D gnu-efi=true \
143 -D kernel-install=true \
144 -D analyze=true \
145 -D bpf-framework=true \
146 -D ukify=true
c82ce4f2
LP
147fi
148
d2a0ca24 149ninja -C "$BUILDDIR" "$@"
ff549982 150if [ "$WITH_TESTS" = 1 ] ; then
a1cfe390 151 if [ -n "$SANITIZERS" ]; then
01a07564
DDM
152 export ASAN_OPTIONS="$MKOSI_ASAN_OPTIONS"
153 export UBSAN_OPTIONS="$MKOSI_UBSAN_OPTIONS"
a1cfe390
DDM
154 TIMEOUT_MULTIPLIER=3
155 else
156 TIMEOUT_MULTIPLIER=1
157 fi
158
d2a0ca24 159 meson test -C "$BUILDDIR" --print-errorlogs --timeout-multiplier=$TIMEOUT_MULTIPLIER
ff549982 160fi
fe2b7631 161
fc4b61d0 162meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed
6344a7eb 163
d12e9bdc 164if [ -d mkosi.kernel/ ]; then
d2a0ca24
DDM
165 SRCDIR="$SRCDIR/mkosi.kernel"
166 BUILDDIR="$BUILDDIR/mkosi.kernel"
167 cd "$SRCDIR"
168 mkdir -p "$BUILDDIR"
d12e9bdc 169
a1cfe390
DDM
170 # Ensure fast incremental builds by fixating these values which usually change for each build.
171 export KBUILD_BUILD_TIMESTAMP="Fri Jun 5 15:58:00 CEST 2015"
172 export KBUILD_BUILD_HOST="mkosi"
6c2ff4a0 173
d2a0ca24 174 scripts/kconfig/merge_config.sh -O "$BUILDDIR" \
a1cfe390
DDM
175 ../mkosi.kernel.config \
176 tools/testing/selftests/bpf/config.x86_64 \
177 tools/testing/selftests/bpf/config
d12e9bdc 178
d2a0ca24 179 make O="$BUILDDIR" -j "$(nproc)"
d12e9bdc 180
d2a0ca24 181 KERNEL_RELEASE=$(make O="$BUILDDIR" -s kernelrelease)
a1cfe390 182 mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE"
d2a0ca24
DDM
183 make O="$BUILDDIR" INSTALL_MOD_PATH="$DESTDIR/usr" modules_install
184 make O="$BUILDDIR" INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install
a1cfe390 185 mkdir -p "$DESTDIR/usr/lib/kernel/selftests"
d2a0ca24 186 make -C tools/testing/selftests -j "$(nproc)" O="$BUILDDIR" KSFT_INSTALL_PATH="$DESTDIR/usr/lib/kernel/selftests" SKIP_TARGETS="" install
31aba196 187
a1cfe390 188 ln -sf /usr/lib/kernel/selftests/bpf/bpftool "$DESTDIR/usr/bin/bpftool"
d12e9bdc 189fi