]>
Commit | Line | Data |
---|---|---|
7629744a | 1 | #!/bin/sh |
8f5bcd61 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
1394a3ec | 3 | set -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. | |
13 | PATH="$BUILDDIR:$PATH" | |
14 | export 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. | |
19 | for bpftool in /usr/lib/linux-tools/*/bpftool; do | |
a1cfe390 DDM |
20 | [ -x "$bpftool" ] || continue |
21 | ln -sf "$bpftool" "$BUILDDIR"/bpftool | |
22 | break | |
37d35150 DDM |
23 | done |
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. | |
28 | if [ "$(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 |
31 | if [ "\$1" = --version ]; then | |
a1cfe390 | 32 | echo 5.6.0 |
6afeac1d | 33 | else |
a1cfe390 | 34 | exec /usr/sbin/bpftool \$@ |
6afeac1d DDM |
35 | fi |
36 | EOF | |
a1cfe390 | 37 | chmod +x "$BUILDDIR"/bpftool |
6afeac1d DDM |
38 | fi |
39 | ||
c81a2569 | 40 | if [ ! -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" \ | |
9f94d274 DDM |
66 | -D default-timeout-sec=${DEFAULT_TIMEOUT_SEC:-10} \ |
67 | -D default-user-timeout-sec=${DEFAULT_TIMEOUT_SEC:-10} \ | |
a1cfe390 DDM |
68 | -D man=false \ |
69 | -D translations=false \ | |
70 | -D version-tag="${VERSION_TAG}" \ | |
71 | -D mode=developer \ | |
72 | -D b_sanitize="${SANITIZERS:-none}" \ | |
73 | -D install-tests=true \ | |
74 | -D tests=unsafe \ | |
75 | -D slow-tests=true \ | |
76 | -D utmp=true \ | |
77 | -D hibernate=true \ | |
78 | -D ldconfig=true \ | |
79 | -D resolve=true \ | |
80 | -D efi=true \ | |
81 | -D tpm=true \ | |
82 | -D environment-d=true \ | |
83 | -D binfmt=true \ | |
84 | -D repart=true \ | |
85 | -D sysupdate=true \ | |
86 | -D coredump=true \ | |
87 | -D pstore=true \ | |
88 | -D oomd=true \ | |
89 | -D logind=true \ | |
90 | -D hostnamed=true \ | |
91 | -D localed=true \ | |
92 | -D machined=true \ | |
93 | -D portabled=true \ | |
94 | -D sysext=true \ | |
95 | -D userdb=true \ | |
96 | -D homed=true \ | |
97 | -D networkd=true \ | |
98 | -D timedated=true \ | |
99 | -D timesyncd=true \ | |
100 | -D remote=true \ | |
101 | -D nss-myhostname=true \ | |
102 | -D nss-mymachines=true \ | |
103 | -D nss-resolve=true \ | |
104 | -D nss-systemd=true \ | |
105 | -D firstboot=true \ | |
106 | -D randomseed=true \ | |
107 | -D backlight=true \ | |
108 | -D vconsole=true \ | |
109 | -D quotacheck=true \ | |
110 | -D sysusers=true \ | |
111 | -D tmpfiles=true \ | |
112 | -D importd=true \ | |
113 | -D hwdb=true \ | |
114 | -D rfkill=true \ | |
115 | -D xdg-autostart=true \ | |
116 | -D translations=true \ | |
117 | -D polkit=true \ | |
118 | -D acl=true \ | |
119 | -D audit=true \ | |
120 | -D blkid=true \ | |
121 | -D fdisk=true \ | |
122 | -D kmod=true \ | |
123 | -D pam=true \ | |
124 | -D pwquality=true \ | |
125 | -D microhttpd=true \ | |
126 | -D libcryptsetup=true \ | |
127 | -D libcurl=true \ | |
128 | -D idn=true \ | |
129 | -D libidn2=true \ | |
130 | -D qrencode=true \ | |
131 | -D gcrypt=true \ | |
132 | -D gnutls=true \ | |
133 | -D openssl=true \ | |
134 | -D cryptolib=openssl \ | |
135 | -D p11kit=true \ | |
136 | -D libfido2=true \ | |
137 | -D tpm2=true \ | |
138 | -D elfutils=true \ | |
139 | -D zstd=true \ | |
140 | -D xkbcommon=true \ | |
141 | -D pcre2=true \ | |
142 | -D glib=true \ | |
143 | -D dbus=true \ | |
dfca5587 | 144 | -D bootloader=true \ |
a1cfe390 DDM |
145 | -D kernel-install=true \ |
146 | -D analyze=true \ | |
147 | -D bpf-framework=true \ | |
148 | -D ukify=true | |
c82ce4f2 LP |
149 | fi |
150 | ||
d2a0ca24 | 151 | ninja -C "$BUILDDIR" "$@" |
ff549982 | 152 | if [ "$WITH_TESTS" = 1 ] ; then |
a1cfe390 | 153 | if [ -n "$SANITIZERS" ]; then |
01a07564 DDM |
154 | export ASAN_OPTIONS="$MKOSI_ASAN_OPTIONS" |
155 | export UBSAN_OPTIONS="$MKOSI_UBSAN_OPTIONS" | |
a1cfe390 DDM |
156 | TIMEOUT_MULTIPLIER=3 |
157 | else | |
158 | TIMEOUT_MULTIPLIER=1 | |
159 | fi | |
160 | ||
d2a0ca24 | 161 | meson test -C "$BUILDDIR" --print-errorlogs --timeout-multiplier=$TIMEOUT_MULTIPLIER |
ff549982 | 162 | fi |
fe2b7631 | 163 | |
fc4b61d0 | 164 | meson install -C "$BUILDDIR" --quiet --no-rebuild --only-changed |
6344a7eb | 165 | |
d12e9bdc | 166 | if [ -d mkosi.kernel/ ]; then |
d2a0ca24 DDM |
167 | SRCDIR="$SRCDIR/mkosi.kernel" |
168 | BUILDDIR="$BUILDDIR/mkosi.kernel" | |
169 | cd "$SRCDIR" | |
170 | mkdir -p "$BUILDDIR" | |
d12e9bdc | 171 | |
a1cfe390 DDM |
172 | # Ensure fast incremental builds by fixating these values which usually change for each build. |
173 | export KBUILD_BUILD_TIMESTAMP="Fri Jun 5 15:58:00 CEST 2015" | |
174 | export KBUILD_BUILD_HOST="mkosi" | |
6c2ff4a0 | 175 | |
d2a0ca24 | 176 | scripts/kconfig/merge_config.sh -O "$BUILDDIR" \ |
a1cfe390 DDM |
177 | ../mkosi.kernel.config \ |
178 | tools/testing/selftests/bpf/config.x86_64 \ | |
179 | tools/testing/selftests/bpf/config | |
d12e9bdc | 180 | |
d2a0ca24 | 181 | make O="$BUILDDIR" -j "$(nproc)" |
d12e9bdc | 182 | |
d2a0ca24 | 183 | KERNEL_RELEASE=$(make O="$BUILDDIR" -s kernelrelease) |
a1cfe390 | 184 | mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" |
d2a0ca24 DDM |
185 | make O="$BUILDDIR" INSTALL_MOD_PATH="$DESTDIR/usr" modules_install |
186 | make O="$BUILDDIR" INSTALL_PATH="$DESTDIR/usr/lib/modules/$KERNEL_RELEASE" install | |
a1cfe390 | 187 | mkdir -p "$DESTDIR/usr/lib/kernel/selftests" |
d2a0ca24 | 188 | make -C tools/testing/selftests -j "$(nproc)" O="$BUILDDIR" KSFT_INSTALL_PATH="$DESTDIR/usr/lib/kernel/selftests" SKIP_TARGETS="" install |
31aba196 | 189 | |
a1cfe390 | 190 | ln -sf /usr/lib/kernel/selftests/bpf/bpftool "$DESTDIR/usr/bin/bpftool" |
d12e9bdc | 191 | fi |