Part of https://github.com/gentoo/gentoo/pull/37281
From c88eee66089333fbcee6377b5f580e70a4ec2a8c Mon Sep 17 00:00:00 2001
From: Andrew Ammerlaan <andrewammerl...@gentoo.org>
Date: Mon, 24 Jun 2024 22:18:46 +0200
Subject: [PATCH] kernel-build.eclass: identify dist-kernels, and warn users
Many, many, new users at some point make the mistake of running "make ...."
in the source directory of a distribution kernel.
This returns a vague error due to the absence of the kernel source files:
make[2]: *** No rule to make target
'arch/x86/entry/syscalls/syscall_32.tbl', needed by
'arch/x86/include/generated/uapi/asm/unistd_32.h'. Stop.
make[1]: *** [arch/x86/Makefile:248: archheaders] Error 2
make: *** [Makefile:234: __sub-make] Error 2
Here we append to the kernel Makefile a warning that should make it more
clear
what is going wrong. "$(shell [ -t 0 ] && echo 1)" is a trick to show this
warning when an user is executing "make" from their shell, but not when
they are
compiling out-of-tree kernel modules (which is the reason we need to install
these makefiles to begin with).
We also add a "dist-kernel" file containing the package atom of the
ebuild that
installed this kernel. This makes it possible for ebuilds/eclasses or
whatever
other tools to check if a kernel is a Gentoo distribution kernel. This
identifier will be overwritten in gentoo-kernel-bin.ebuild.
Signed-off-by: Andrew Ammerlaan <andrewammerl...@gentoo.org>
---
eclass/kernel-build.eclass | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7922638be6e1c..86c7cd4a172d5 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -382,6 +382,22 @@ kernel-build_src_install() {
local module_ver
module_ver=$(<"${relfile}") || die
+ # warn when trying to "make" a dist-kernel
+ cat <<-EOF >> "${ED}${kernel_dir}/Makefile" || die
+
+ _GENTOO_IS_USER_SHELL:=\$(shell [ -t 0 ] && echo 1)
+ ifdef _GENTOO_IS_USER_SHELL
+ \$(warning !!!! WARNING !!!!)
+ \$(warning This kernel was configured and installed by the package
manager.)
+ \$(warning "make" should not be run manually here.)
+ \$(warning See also:
https://wiki.gentoo.org/wiki/Project:Distribution_Kernel)
+ \$(warning See also:
https://wiki.gentoo.org/wiki/Kernel/Configuration)
+ \$(warning !!!! WARNING !!!!)
+ endif
+ EOF
+ # add a dist-kernel identifier file
+ echo "${CATEGORY}/${PF}:${SLOT}" > "${ED}${kernel_dir}/dist-kernel" ||
die
+
# fix source tree and build dir symlinks
dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/build"
dosym "../../../${kernel_dir}" "/lib/modules/${module_ver}/source"