#!/bin/bash # Compiles the kernel and stages all artifacts into /out/staging. # Runs inside Docker; kernel source is bind-mounted at /src. set -e # Clean host-built tool artifacts that may reference wrong include paths make -C tools/objtool clean 2>/dev/null || true make olddefconfig make -j"$(nproc)" bzImage modules # Stage all artifacts so downstream packagers don't need to run make echo "=== Staging build artifacts ===" rm -rf /out/staging mkdir -p /out/staging/boot cp arch/x86/boot/bzImage /out/staging/boot/ cp System.map /out/staging/ cp .config /out/staging/ make modules_install INSTALL_MOD_PATH=/out/staging INSTALL_MOD_STRIP=1 # Remove dangling symlinks back into the source tree KVER=$(make -s kernelrelease) rm -f "/out/staging/lib/modules/$KVER/build" \ "/out/staging/lib/modules/$KVER/source" # Stage kernel headers for out-of-tree module builds echo "=== Staging kernel headers ===" HDR="/out/staging/headers" make headers_install INSTALL_HDR_PATH="$HDR/usr" # Use the kernel's own install-extmod-build script (same as deb-pkg uses) export srctree=/src SRCARCH=x86 CC="${CROSS_COMPILE}gcc" HOSTCC=gcc MAKE=make /src/scripts/package/install-extmod-build "$HDR/lib/modules/$KVER/build" echo "=== Build artifacts staged in /out/staging ==="