Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli via buildroot <buildroot@buildroot.org>
To: buildroot@buildroot.org
Cc: "Eric Le Bihan" <eric.le.bihan.dev@free.fr>,
	"Gary Bisson" <bisson.gary@gmail.com>,
	"Jérôme Pouiller" <jezz@sysmic.org>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Bernd Kuhls" <bernd@kuhls.net>,
	"Thomas Perale" <thomas.perale@mind.be>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	"Refik Tuzakli" <tuzakli.refik@gmail.com>,
	"Francois Perrad" <francois.perrad.86@gmail.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Arnout Vandecappelle" <arnout@rnout.be>,
	"Petr Vorel" <petr.vorel@gmail.com>,
	"Spenser Gilliland" <spenser@gillilanding.com>,
	"Giulio Benetti" <giulio.benetti@benettiengineering.com>,
	"Pascal de Bruijn" <p.debruijn@unilogic.nl>,
	"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
	"Romain Naour" <romain.naour@gmail.com>,
	"Mahyar Koshkouei" <mahyar.koshkouei@gmail.com>
Subject: [Buildroot] [PATCH v2 21/23] package/linux-tools: support an out-of-tree kernel build
Date: Wed, 28 Oct 2026 14:37:42 -0700	[thread overview]
Message-ID: <20261028213744.511429-22-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261028213744.511429-1-florian.fainelli@broadcom.com>

The kernel build directory no longer contains the kernel sources, so:

 - check which tools the kernel provides against $(LINUX_SRCDIR)/tools
   rather than $(LINUX_DIR)/tools;
 - build the tools, which build in-tree, in a shadow of the kernel
   sources so that the original sources are not modified. When the kernel
   is built in-tree, nothing changes.

Also: stop python from writing bytecode next to the real perf scripts,
and make the selftests find the headers installed in the kernel build
directory, which fixes a cold-build failure. The host-built net ynl
selftests are excluded from the target architecture check.

Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 package/linux-tools/linux-tool-cpupower.mk.in |  8 +++---
 package/linux-tools/linux-tool-gpio.mk.in     |  6 ++---
 package/linux-tools/linux-tool-hv.mk.in       |  6 ++---
 package/linux-tools/linux-tool-iio.mk.in      |  6 ++---
 package/linux-tools/linux-tool-mm.mk.in       | 10 +++----
 package/linux-tools/linux-tool-pci.mk.in      | 12 +++++----
 package/linux-tools/linux-tool-perf.mk.in     | 27 +++++++++++--------
 package/linux-tools/linux-tool-rtla.mk.in     | 10 +++----
 .../linux-tools/linux-tool-selftests.mk.in    | 15 ++++++-----
 package/linux-tools/linux-tool-tmon.mk.in     |  8 +++---
 package/linux-tools/linux-tool-usbtools.mk.in |  6 ++---
 package/linux-tools/linux-tools.mk            | 20 +++++++++++++-
 12 files changed, 81 insertions(+), 53 deletions(-)

diff --git a/package/linux-tools/linux-tool-cpupower.mk.in b/package/linux-tools/linux-tool-cpupower.mk.in
index 2a2d3e01dd5a..aca57ff02bcb 100644
--- a/package/linux-tools/linux-tool-cpupower.mk.in
+++ b/package/linux-tools/linux-tool-cpupower.mk.in
@@ -15,26 +15,26 @@ CPUPOWER_MAKE_OPTS = CROSS=$(TARGET_CROSS) \
 	DEBUG=false
 
 define CPUPOWER_BUILD_CMDS
-	$(Q)if test ! -f $(LINUX_DIR)/tools/power/cpupower/Makefile ; then \
+	$(Q)if test ! -f $(LINUX_TOOLS_KSRC)/power/cpupower/Makefile ; then \
 		echo "Your kernel version is too old and does not have the cpupower tool." ; \
 		echo "At least kernel 3.4 must be used." ; \
 		exit 1 ; \
 	fi
 
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(CPUPOWER_MAKE_OPTS) \
 		cpupower
 endef
 
 define CPUPOWER_INSTALL_STAGING_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(CPUPOWER_MAKE_OPTS) \
 		DESTDIR=$(STAGING_DIR) \
 		cpupower_install
 endef
 
 define CPUPOWER_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(CPUPOWER_MAKE_OPTS) \
 		DESTDIR=$(TARGET_DIR) \
 		cpupower_install
diff --git a/package/linux-tools/linux-tool-gpio.mk.in b/package/linux-tools/linux-tool-gpio.mk.in
index e825db1b1127..32e3343fc1aa 100644
--- a/package/linux-tools/linux-tool-gpio.mk.in
+++ b/package/linux-tools/linux-tool-gpio.mk.in
@@ -9,19 +9,19 @@ LINUX_TOOLS += gpio
 GPIO_MAKE_OPTS = $(LINUX_MAKE_FLAGS) LDFLAGS="$(TARGET_LDFLAGS)"
 
 define GPIO_BUILD_CMDS
-	$(Q)if ! grep install $(LINUX_DIR)/tools/gpio/Makefile >/dev/null 2>&1 ; then \
+	$(Q)if ! grep install $(LINUX_TOOLS_KSRC)/gpio/Makefile >/dev/null 2>&1 ; then \
 		echo "Your kernel version is too old and does not have the gpio tools." ; \
 		echo "At least kernel 4.8 must be used." ; \
 		exit 1 ; \
 	fi
 
-	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(GPIO_MAKE_OPTS) \
 		gpio
 endef
 
 define GPIO_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(GPIO_MAKE_OPTS) \
 		DESTDIR=$(TARGET_DIR) \
 		gpio_install
diff --git a/package/linux-tools/linux-tool-hv.mk.in b/package/linux-tools/linux-tool-hv.mk.in
index e638fecfc63e..73c20e3ed542 100644
--- a/package/linux-tools/linux-tool-hv.mk.in
+++ b/package/linux-tools/linux-tool-hv.mk.in
@@ -20,13 +20,13 @@ HV_MAKE_OPTS = CC="$(TARGET_CC)" CFLAGS="$(filter-out -g%,$(TARGET_CFLAGS))"
 
 define HV_BUILD_CMDS
 	$(Q)for prog in $(HV_PROGS_y); do \
-		if test ! -f $(LINUX_DIR)/tools/hv/$${prog}.c ; then \
+		if test ! -f $(LINUX_TOOLS_KSRC)/hv/$${prog}.c ; then \
 			printf "Your kernel version is too old and does not have the HyperV %s tool." "$${prog}" ; \
 			exit 1 ; \
 		fi; \
 	done
 
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools/hv \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools/hv \
 		$(HV_MAKE_OPTS) \
 		$(HV_PROGS_y)
 endef
@@ -40,7 +40,7 @@ endif
 
 define HV_INSTALL_TARGET_CMDS
 	$(foreach prog,$(HV_PROGS_y), \
-		$(INSTALL) -m 0755 -D $(LINUX_DIR)/tools/hv/$(prog) \
+		$(INSTALL) -m 0755 -D $(LINUX_TOOLS_KDIR)/tools/hv/$(prog) \
 			$(TARGET_DIR)/usr/sbin/$(HV_$(prog))
 	)
 	$(HV_KVP_HELPER)
diff --git a/package/linux-tools/linux-tool-iio.mk.in b/package/linux-tools/linux-tool-iio.mk.in
index 27ab0ed7ed63..b975a548e473 100644
--- a/package/linux-tools/linux-tool-iio.mk.in
+++ b/package/linux-tools/linux-tool-iio.mk.in
@@ -9,19 +9,19 @@ LINUX_TOOLS += iio
 IIO_MAKE_OPTS = $(LINUX_MAKE_FLAGS) LDFLAGS="$(TARGET_LDFLAGS)"
 
 define IIO_BUILD_CMDS
-	$(Q)if ! grep install $(LINUX_DIR)/tools/iio/Makefile >/dev/null 2>&1 ; then \
+	$(Q)if ! grep install $(LINUX_TOOLS_KSRC)/iio/Makefile >/dev/null 2>&1 ; then \
 		echo "Your kernel version is too old and does not have install section in the iio tools." ; \
 		echo "At least kernel 4.7 must be used." ; \
 		exit 1 ; \
 	fi
 
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools/iio \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools/iio \
 		$(IIO_MAKE_OPTS)
 endef
 
 # DESTDIR used since kernel version 4.14
 define IIO_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools/iio \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools/iio \
 		$(IIO_MAKE_OPTS) \
 		INSTALL_ROOT=$(TARGET_DIR) \
 		DESTDIR=$(TARGET_DIR) \
diff --git a/package/linux-tools/linux-tool-mm.mk.in b/package/linux-tools/linux-tool-mm.mk.in
index b2ec090fc086..703d3681ae43 100644
--- a/package/linux-tools/linux-tool-mm.mk.in
+++ b/package/linux-tools/linux-tool-mm.mk.in
@@ -7,16 +7,16 @@
 LINUX_TOOLS += mm
 
 define MM_BUILD_CMDS
-	$(Q)if test -f $(LINUX_DIR)/tools/vm/Makefile ; then \
+	$(Q)if test -f $(LINUX_TOOLS_KSRC)/vm/Makefile ; then \
 		MM_SUBDIR=vm; \
-	elif test -f $(LINUX_DIR)/tools/mm/Makefile ; then \
+	elif test -f $(LINUX_TOOLS_KSRC)/mm/Makefile ; then \
 		MM_SUBDIR=mm; \
 	else \
 		echo "Your kernel version is too old and does not have the mm tool." ; \
 		echo "At least kernel 3.4 must be used." ; \
 		exit 1 ; \
 	fi ; \
-	$(TARGET_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(MM_MAKE_OPTS) $${MM_SUBDIR}
 endef
 
@@ -24,12 +24,12 @@ endef
 # exists, because that was checked at build time already; we just
 # need to find which of the two: if not one, then the other.
 define MM_INSTALL_TARGET_CMDS
-	$(Q)if test -f $(LINUX_DIR)/tools/vm/Makefile ; then \
+	$(Q)if test -f $(LINUX_TOOLS_KSRC)/vm/Makefile ; then \
 		MM_SUBDIR=vm; \
 	else \
 		MM_SUBDIR=mm; \
 	fi ; \
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(LINUX_MAKE_FLAGS) \
 		INSTALL_ROOT=$(TARGET_DIR) \
 		DESTDIR=$(TARGET_DIR) \
diff --git a/package/linux-tools/linux-tool-pci.mk.in b/package/linux-tools/linux-tool-pci.mk.in
index 52d7639bb102..a6f6ef265643 100644
--- a/package/linux-tools/linux-tool-pci.mk.in
+++ b/package/linux-tools/linux-tool-pci.mk.in
@@ -7,11 +7,13 @@
 LINUX_TOOLS += pci
 
 # Linux 6.14 moved the PCI endpoint tests into Kselftests.
-PCI_SRCDIR = $(strip $(if $(wildcard $(LINUX_DIR)/tools/testing/selftests/pci_endpoint/Makefile),\
-	$(LINUX_DIR)/tools/testing/selftests/pci_endpoint,$(LINUX_DIR)/tools/pci))
+PCI_SUBDIR = $(strip $(if $(wildcard $(LINUX_TOOLS_KSRC)/testing/selftests/pci_endpoint/Makefile),\
+	testing/selftests/pci_endpoint,pci))
+PCI_SRCDIR = $(LINUX_TOOLS_KSRC)/$(PCI_SUBDIR)
+PCI_BUILDDIR = $(LINUX_TOOLS_KDIR)/tools/$(PCI_SUBDIR)
 
 PCI_MAKE_OPTS = $(LINUX_MAKE_FLAGS) \
-	OUTPUT=$(PCI_SRCDIR)/ \
+	OUTPUT=$(PCI_BUILDDIR)/ \
 	LDFLAGS="$(TARGET_LDFLAGS)" \
 	LDLIBS="-lrt -lm"
 
@@ -22,12 +24,12 @@ define PCI_BUILD_CMDS
 		exit 1 ; \
 	fi
 
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(PCI_SRCDIR) \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(PCI_BUILDDIR) \
 		$(PCI_MAKE_OPTS)
 endef
 
 define PCI_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(PCI_SRCDIR) \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(PCI_BUILDDIR) \
 		$(PCI_MAKE_OPTS) \
 		DESTDIR=$(TARGET_DIR) \
 		INSTALL_PATH=$(TARGET_DIR)/usr/lib/kselftests/pci_endpoint \
diff --git a/package/linux-tools/linux-tool-perf.mk.in b/package/linux-tools/linux-tool-perf.mk.in
index 3271fd5683eb..348eb1a4240f 100644
--- a/package/linux-tools/linux-tool-perf.mk.in
+++ b/package/linux-tools/linux-tool-perf.mk.in
@@ -18,6 +18,11 @@ else
 PERF_ARCH=$(NORMALIZED_ARCH)
 endif
 
+# The python scripts run by the perf build are run through symlinks when
+# building out of tree: do not let python write its bytecode next to the
+# real script, in the kernel sources.
+PERF_MAKE_ENV = PYTHONDONTWRITEBYTECODE=1
+
 PERF_MAKE_FLAGS = \
 	$(LINUX_MAKE_FLAGS) \
 	JOBS=$(PARALLEL_JOBS) \
@@ -147,25 +152,25 @@ endif
 # For a POST_PATCH hook, tools/perf/Documentation/Makefile is not
 # guaranteed to exist yet.
 define PERF_DISABLE_DOCUMENTATION
-	if [ -f $(LINUX_DIR)/tools/perf/Documentation/Makefile ]; then \
-		printf "%%:\n\t@:\n" >$(LINUX_DIR)/tools/perf/Documentation/GNUmakefile; \
+	if [ -f $(LINUX_TOOLS_KDIR)/tools/perf/Documentation/Makefile ]; then \
+		printf "%%:\n\t@:\n" >$(LINUX_TOOLS_KDIR)/tools/perf/Documentation/GNUmakefile; \
 	fi
 endef
 LINUX_TOOLS_PRE_CONFIGURE_HOOKS += PERF_DISABLE_DOCUMENTATION
 
 # O must be redefined here to overwrite the one used by Buildroot for
-# out of tree build. We build perf in $(LINUX_DIR)/tools/perf/ and not just
+# out of tree build. We build perf in $(LINUX_TOOLS_KDIR)/tools/perf/ and not just
 # $(LINUX_DIR) so that it isn't built in the root directory of the kernel
 # sources.
 define PERF_BUILD_CMDS
-	$(Q)if test ! -f $(LINUX_DIR)/tools/perf/Makefile ; then \
+	$(Q)if test ! -f $(LINUX_TOOLS_KSRC)/perf/Makefile ; then \
 		echo "Your kernel version is too old and does not have the perf tool." ; \
 		echo "At least kernel 2.6.31 must be used." ; \
 		exit 1 ; \
 	fi
 	$(Q)if test "$(BR2_PACKAGE_ELFUTILS)" = "" ; then \
-		if ! grep -q NO_LIBELF $(LINUX_DIR)/tools/perf/Makefile* ; then \
-			if ! test -r $(LINUX_DIR)/tools/perf/config/Makefile ; then \
+		if ! grep -q NO_LIBELF $(LINUX_TOOLS_KSRC)/perf/Makefile* ; then \
+			if ! test -r $(LINUX_TOOLS_KSRC)/perf/config/Makefile ; then \
 				echo "The perf tool in your kernel cannot be built without libelf." ; \
 				echo "Either upgrade your kernel to >= 3.7, or enable the elfutils package." ; \
 				exit 1 ; \
@@ -173,14 +178,14 @@ define PERF_BUILD_CMDS
 		fi \
 	fi
 	$(Q)if test "$(BR2_PACKAGE_LINUX_TOOLS_PERF_TUI)" = "y" ; then \
-		if ! grep -q NO_SLANG $(LINUX_DIR)/tools/perf/Makefile* ; then \
+		if ! grep -q NO_SLANG $(LINUX_TOOLS_KSRC)/perf/Makefile* ; then \
 			echo "The perf tool in your kernel cannot be build with the TUI." ; \
 			echo "Either upgrade your kernel to >= 3.10, or disable the TUI." ; \
 			exit 1 ; \
 		fi \
 	fi
-	$(TARGET_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
-		-C $(LINUX_DIR)/tools/perf O=$(LINUX_DIR)/tools/perf/
+	$(TARGET_MAKE_ENV) $(PERF_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
+		-C $(LINUX_TOOLS_KDIR)/tools/perf O=$(LINUX_TOOLS_KDIR)/tools/perf/
 endef
 
 # After installation, we remove the Perl and Python scripts from the
@@ -196,8 +201,8 @@ LINUX_TOOLS_BIN_ARCH_EXCLUDE += \
 endif
 
 define PERF_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
-		-C $(LINUX_DIR)/tools/perf O=$(LINUX_DIR)/tools/perf/ install
+	$(TARGET_MAKE_ENV) $(PERF_MAKE_ENV) $(MAKE1) $(PERF_MAKE_FLAGS) \
+		-C $(LINUX_TOOLS_KDIR)/tools/perf O=$(LINUX_TOOLS_KDIR)/tools/perf/ install
 	$(PERF_INSTALL_REMOVE_SCRIPTS)
 endef
 
diff --git a/package/linux-tools/linux-tool-rtla.mk.in b/package/linux-tools/linux-tool-rtla.mk.in
index d9bdcc3016e7..aef4343010c8 100644
--- a/package/linux-tools/linux-tool-rtla.mk.in
+++ b/package/linux-tools/linux-tool-rtla.mk.in
@@ -16,7 +16,7 @@ RTLA_MAKE_OPTS = $(LINUX_MAKE_FLAGS) \
 
 ifeq ($(BR2_TOOLCHAIN_HAS_SSP),)
 define RTLA_DISABLE_STACK_PROTECTOR
-	$(SED) 's/-fstack-protector.* //' $(LINUX_DIR)/tools/tracing/rtla/Makefile
+	$(SED) 's/-fstack-protector.* //' $(LINUX_TOOLS_KDIR)/tools/tracing/rtla/Makefile
 endef
 endif
 
@@ -27,14 +27,14 @@ define RTLA_LINUX_CONFIG_FIXUPS
 endef
 
 define RTLA_BUILD_CMDS
-	$(Q)if ! grep install $(LINUX_DIR)/tools/tracing/rtla/Makefile >/dev/null 2>&1 ; then \
+	$(Q)if ! grep install $(LINUX_TOOLS_KSRC)/tracing/rtla/Makefile >/dev/null 2>&1 ; then \
 		echo "Your kernel version is too old and does not implement the rtla tool." ; \
 		echo "At least kernel 5.19 must be used." ; \
 		exit 1 ; \
 	fi
 	$(RTLA_DISABLE_STACK_PROTECTOR)
 	$(TARGET_MAKE_ENV) $(MAKE) $(RTLA_MAKE_OPTS) \
-		-C $(LINUX_DIR)/tools/tracing rtla
+		-C $(LINUX_TOOLS_KDIR)/tools/tracing rtla
 endef
 
 # make rtla_install build and install by default documentation using rst2man
@@ -42,12 +42,12 @@ endef
 # folder so let's simply install the resulting rtla binary and create symlinks
 # like Linux does in its tools/tracing/rtla/Makefile
 define RTLA_INSTALL_TARGET_CMDS
-	$(INSTALL) -m 0755 -D $(LINUX_DIR)/tools/tracing/rtla/rtla $(TARGET_DIR)/usr/bin
+	$(INSTALL) -m 0755 -D $(LINUX_TOOLS_KDIR)/tools/tracing/rtla/rtla $(TARGET_DIR)/usr/bin
 	ln -sf rtla $(TARGET_DIR)/usr/bin/osnoise
 	ln -sf rtla $(TARGET_DIR)/usr/bin/timerlat
 
 	# Check if hwnoise is provided or not
-	if grep -q hwnoise $(LINUX_DIR)/tools/tracing/rtla/Makefile; then \
+	if grep -q hwnoise $(LINUX_TOOLS_KSRC)/tracing/rtla/Makefile; then \
 		ln -sf rtla $(TARGET_DIR)/usr/bin/hwnoise ; \
 	fi
 endef
diff --git a/package/linux-tools/linux-tool-selftests.mk.in b/package/linux-tools/linux-tool-selftests.mk.in
index 032a71e32000..4f25c4a922c1 100644
--- a/package/linux-tools/linux-tool-selftests.mk.in
+++ b/package/linux-tools/linux-tool-selftests.mk.in
@@ -27,11 +27,14 @@ SELFTESTS_MAKE_FLAGS = \
 	KHDR_DIR=$(LINUX_DIR)/usr/include \
 	KHDR_INCLUDES="-isystem $(LINUX_DIR)/usr/include"
 
+# The ynl library of the net selftests is built with the host compiler
 LINUX_TOOLS_BIN_ARCH_EXCLUDE += \
-	/usr/lib/kselftests/tc-testing/
+	/usr/lib/kselftests/tc-testing/ \
+	/usr/lib/kselftests/net/lib/ynl/ \
+	/usr/lib/kselftests/drivers/net/
 
 # O must be redefined here to overwrite the one used by Buildroot for
-# out of tree build. We build the selftests in $(LINUX_DIR)/tools/selftests and
+# out of tree build. We build the selftests in $(LINUX_TOOLS_KDIR)/tools/selftests and
 # not just $(LINUX_DIR) so that it isn't built in the root directory of the kernel
 # sources.
 #
@@ -43,12 +46,12 @@ LINUX_TOOLS_BIN_ARCH_EXCLUDE += \
 define SELFTESTS_BUILD_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR) $(SELFTESTS_MAKE_FLAGS) \
 		headers_install
-	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR)/tools/testing/selftests \
-		$(SELFTESTS_MAKE_FLAGS) O=$(LINUX_DIR)/tools/testing/selftests
+	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_TOOLS_KDIR)/tools/testing/selftests \
+		$(SELFTESTS_MAKE_FLAGS) O=$(LINUX_TOOLS_KDIR)/tools/testing/selftests
 endef
 
 define SELFTESTS_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_DIR)/tools/testing/selftests \
-		$(SELFTESTS_MAKE_FLAGS) O=$(LINUX_DIR)/tools/testing/selftests \
+	$(TARGET_MAKE_ENV) $(MAKE1) -C $(LINUX_TOOLS_KDIR)/tools/testing/selftests \
+		$(SELFTESTS_MAKE_FLAGS) O=$(LINUX_TOOLS_KDIR)/tools/testing/selftests \
 		INSTALL_PATH=$(TARGET_DIR)/usr/lib/kselftests install
 endef
diff --git a/package/linux-tools/linux-tool-tmon.mk.in b/package/linux-tools/linux-tool-tmon.mk.in
index 56c328c51fd7..cb071f5fee12 100644
--- a/package/linux-tools/linux-tool-tmon.mk.in
+++ b/package/linux-tools/linux-tool-tmon.mk.in
@@ -14,24 +14,24 @@ TMON_MAKE_OPTS = $(LINUX_MAKE_FLAGS) \
 
 ifeq ($(BR2_TOOLCHAIN_HAS_SSP),)
 define TMON_DISABLE_STACK_PROTECTOR
-	$(SED) 's%-fstack-protector%%' $(LINUX_DIR)/tools/thermal/tmon/Makefile
+	$(SED) 's%-fstack-protector%%' $(LINUX_TOOLS_KDIR)/tools/thermal/tmon/Makefile
 endef
 endif
 
 define TMON_BUILD_CMDS
-	$(Q)if ! grep install $(LINUX_DIR)/tools/thermal/tmon/Makefile >/dev/null 2>&1 ; then \
+	$(Q)if ! grep install $(LINUX_TOOLS_KSRC)/thermal/tmon/Makefile >/dev/null 2>&1 ; then \
 		echo "Your kernel version is too old and does not have the tmon tool." ; \
 		echo "At least kernel 3.13 must be used." ; \
 		exit 1 ; \
 	fi
 	$(TMON_DISABLE_STACK_PROTECTOR)
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(TMON_MAKE_OPTS) \
 		tmon
 endef
 
 define TMON_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools \
 		$(TMON_MAKE_OPTS) \
 		INSTALL_ROOT=$(TARGET_DIR) \
 		tmon_install
diff --git a/package/linux-tools/linux-tool-usbtools.mk.in b/package/linux-tools/linux-tool-usbtools.mk.in
index 797758adce51..6e72fe6de79a 100644
--- a/package/linux-tools/linux-tool-usbtools.mk.in
+++ b/package/linux-tools/linux-tool-usbtools.mk.in
@@ -13,20 +13,20 @@ LINUX_TOOLS_USBTOOLS_LIST = \
 	$(if $(BR2_PACKAGE_LINUX_TOOLS_USBTOOLS_FFSTEST),ffs-test)
 
 define USBTOOLS_BUILD_CMDS
-	$(Q)if ! grep install $(LINUX_DIR)/tools/usb/Makefile >/dev/null 2>&1 ; then \
+	$(Q)if ! grep install $(LINUX_TOOLS_KSRC)/usb/Makefile >/dev/null 2>&1 ; then \
 		echo "Your kernel version is too old to build the USB tools." ; \
 		echo "At least kernel 5.9 must be used." ; \
 		exit 1 ; \
 	fi
 
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools/usb \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools/usb \
 		ALL_TARGETS="$(LINUX_TOOLS_USBTOOLS_LIST)" \
 		$(USBTOOLS_MAKE_OPTS) \
 		all
 endef
 
 define USBTOOLS_INSTALL_TARGET_CMDS
-	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_DIR)/tools/usb \
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(LINUX_TOOLS_KDIR)/tools/usb \
 		ALL_TARGETS="$(LINUX_TOOLS_USBTOOLS_LIST)" \
 		$(USBTOOLS_MAKE_OPTS) \
 		DESTDIR=$(TARGET_DIR) \
diff --git a/package/linux-tools/linux-tools.mk b/package/linux-tools/linux-tools.mk
index 49e73a9ca4ec..c1b13af0dd4c 100644
--- a/package/linux-tools/linux-tools.mk
+++ b/package/linux-tools/linux-tools.mk
@@ -8,7 +8,25 @@
 # Instead, we directly build in the sources of the linux package. We can do
 # that, because we're not building in the same location and the same files.
 #
-# So, all tools refer to $(LINUX_DIR) instead of $(@D).
+# So, all tools refer to $(LINUX_TOOLS_KDIR) to build, instead of $(@D).
+#
+# Which tools can be built, though, is checked against the kernel sources
+# in $(LINUX_SRCDIR), which is not $(LINUX_DIR), the kernel build directory,
+# when the kernel is built out of tree.
+#
+# The tools build in-tree, and we do not want to pollute the kernel sources
+# of an out-of-tree build. So in that case, we build in a shadow of the
+# kernel sources, which is a tree of real directories with symlinks to the
+# files.
+LINUX_TOOLS_KSRC = $(LINUX_SRCDIR)/tools
+LINUX_TOOLS_KDIR = $(if $(LINUX_OUT_OF_TREE),$(LINUX_TOOLS_BUILDDIR)/linux,$(LINUX_DIR))
+
+define LINUX_TOOLS_SHADOW_SOURCES
+	$(if $(LINUX_OUT_OF_TREE),\
+		support/scripts/symlink-tree -f tools $(LINUX_SRCDIR) $(LINUX_TOOLS_KDIR))
+endef
+# Must come first, before the hooks that tweak the kernel sources
+LINUX_TOOLS_PRE_CONFIGURE_HOOKS += LINUX_TOOLS_SHADOW_SOURCES
 
 # Note: we need individual tools makefiles to be included *before* we build
 # the list of build and install hooks below to guarantee that each tool has
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2026-10-28 21:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 21:37 [Buildroot] [PATCH v2 00/23] Support building the Linux kernel out of tree Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 01/23] package: prepare removal of <pkg>_DIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 02/23] infra: introduce a global SRC_DIR variable Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 03/23] package: fix <pkg>_SRCDIR and <pkg>_BUILDDIR values Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 04/23] boot/boot-wrapper-aarch64: needs LINUX_BUILDDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 05/23] boot/mxs-bootlets: needs (BAREBOX, LINUX, UBOOT)_BUILDDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 06/23] linux/extensions: point to proper _SRCDIR and @D Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 07/23] linux/linux: LINUX_VERSION_PROBED should run from build directory Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 08/23] package: use <pkg>_SRCSUBDIR where <pkg>_SRCDIR used to include _SUBDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 09/23] linux: build out of tree Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 10/23] packages: sync host and target patch hooks Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 11/23] omniorb: avoid target-only patch hook Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 12/23] lua: rework post-patch hook usage Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 13/23] infra: host packages inherit the target extra downloads Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 14/23] package/libtool: use post-patch hooks Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 15/23] package/libtool: also apply libtool-patch to host libtool Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 16/23] package/{ffmpeg, libvpx}: use $(@D) instead of $(pkg_SRCDIR) when possible Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 17/23] package/perl: apply the perl-cross even for the host variant Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 18/23] infra/autotools: warn for package that autoreconf without libtool patch Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 19/23] packages: replace $(PKG)_DIR with @D where possible Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 20/23] linux: support custom logo and devicetree files in out-of-tree builds Florian Fainelli via buildroot
2026-10-28 21:37 ` Florian Fainelli via buildroot [this message]
2026-10-28 21:37 ` [Buildroot] [PATCH v2 22/23] package: read kernel headers from LINUX_SRCDIR Florian Fainelli via buildroot
2026-10-28 21:37 ` [Buildroot] [PATCH v2 23/23] docs/manual: document out-of-tree package builds and the new srcdir variables Florian Fainelli via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028213744.511429-22-florian.fainelli@broadcom.com \
    --to=buildroot@buildroot.org \
    --cc=arnout@rnout.be \
    --cc=bernd@kuhls.net \
    --cc=bisson.gary@gmail.com \
    --cc=eric.le.bihan.dev@free.fr \
    --cc=florian.fainelli@broadcom.com \
    --cc=francois.perrad.86@gmail.com \
    --cc=giulio.benetti@benettiengineering.com \
    --cc=jezz@sysmic.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=mahyar.koshkouei@gmail.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=p.debruijn@unilogic.nl \
    --cc=petr.vorel@gmail.com \
    --cc=romain.naour@gmail.com \
    --cc=spenser@gillilanding.com \
    --cc=thomas.perale@mind.be \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tuzakli.refik@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox