Skip to contentSkip to conversation

backports: look for kernel headers in source dir too

PATCH New Baoli Zhang 1 participant 1 message Nov 26 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backports: look for kernel headers in source dir too

Debian splits the kernel headers: /lib/modules/<ver>/build only has .config, Module.symvers and the generated headers, include/linux is under /lib/modules/<ver>/source. The grep checks in compat/Kconfig then can't find the headers and all evaluate to n, so on 7.3 we redefine the spinlock_bh guards and fail to build.

Add KLIB_SRC for these checks. Use the build dir if it has include/linux, otherwise its source symlink (O= builds), and only then $(KLIB)/source, so that a custom KLIB_BUILD doesn't pick up the headers of the running kernel. Warn if no headers are found at all, instead of silently disabling the checks.

Fixes e0449c805011 ("backports: auto-detect spinlock_bh guard()")
Fixes e9e903010322 ("[BUGFIX] backports: Auto detect genlmsg_multicast_allns()")
Fixes 6bd0558a1593 ("[FROMGIT] netfilter: flowtable: restore ieee80211 forward path")
---
 Makefile       | 14 +++++++++++++-
 compat/Kconfig |  6 +++---
 2 files changed, 16 insertions(+), 4 deletions(-)
Makefile +13 -1
index 2b33a80c3..daba7181e 100644
@@ -19,8 +19,13 @@ KLIB_BUILD ?= $(KLIB)/build/
 KERNEL_CONFIG := $(KLIB_BUILD)/.config
 KERNEL_MAKEFILE := $(KLIB_BUILD)/Makefile
 CONFIG_MD5 := $(shell md5sum $(KERNEL_CONFIG) 2>/dev/null | sed 's/\s.*//')
+# Debian splits the headers, its build dir has no include/linux
+KLIB_SRC ?= $(patsubst %/include/linux,%,$(firstword $(wildcard	\
+	$(KLIB_BUILD)/include/linux					\
+	$(KLIB_BUILD)/source/include/linux				\
+	$(KLIB)/source/include/linux)))
 
-export KLIB KLIB_BUILD BACKPORT_DIR KMODDIR KMODPATH_ARG
+export KLIB KLIB_BUILD KLIB_SRC BACKPORT_DIR KMODDIR KMODPATH_ARG
 
 # disable built-in rules for this file
 .SUFFIXES:
@@ -60,6 +65,13 @@ mrproper:
 	echo "| (that isn't currently running.)"					;\
 	echo "\\--"									;\
 	false)
+	@test -n "$(KLIB_SRC)" || (							\
+	echo "/--------------"								;\
+	echo "| WARNING: kernel headers (include/linux) not found in"		;\
+	echo "| $(KLIB_BUILD) or its source dir, kernel feature"			;\
+	echo "| detection will not work. Set KLIB_SRC to the kernel"		;\
+	echo "| source tree to fix this."						;\
+	echo "\\--")
 	@set -e ; if [ "$$(cat .kernel_config_md5 2>/dev/null)" != "$(CONFIG_MD5)" ]	;\
 	then 										\
 		echo -n "Generating local configuration database from kernel ..."	;\
compat/Kconfig +3 -3
index 09663a8bc..e1db4dd71 100644
@@ -74,13 +74,13 @@ config BP_MODULES
 	for the "modules" directive to control the 'm' state.
 
 config KERNEL_HAS_SPINLOCK_BH_GUARD
-	def_bool $(success,grep -q DEFINE_LOCK_GUARD_1\$(left_paren)spinlock_bh$(comma) $(KLIB_BUILD)/include/linux/spinlock.h)
+	def_bool $(success,grep -q DEFINE_LOCK_GUARD_1\$(left_paren)spinlock_bh$(comma) $(KLIB_SRC)/include/linux/spinlock.h)
 
 config KERNEL_HAS_GENLMSG_MULTICAST_ALLNS_GFP
-	def_bool $(success,grep -A5 'int genlmsg_multicast_allns' $(KLIB_BUILD)/include/net/genetlink.h | grep -q gfp_t)
+	def_bool $(success,grep -A5 'int genlmsg_multicast_allns' $(KLIB_SRC)/include/net/genetlink.h | grep -q gfp_t)
 
 config KERNEL_HAS_DEV_PATH_IEEE80211
-	def_bool $(success,grep -q DEV_PATH_IEEE80211 $(KLIB_BUILD)/include/linux/netdevice.h)
+	def_bool $(success,grep -q DEV_PATH_IEEE80211 $(KLIB_SRC)/include/linux/netdevice.h)
 
 config BPAUTO_BUILD_NLATTR
 	def_bool y
Signature · 1 line
2.43.0