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 09/23] linux: build out of tree when LINUX_OVERRIDE_SRCDIR is set
Date: Fri, 23 Oct 2026 14:51:24 -0700 [thread overview]
Message-ID: <20261023215138.2301146-3-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261023215138.2301146-1-florian.fainelli@broadcom.com>
Introduce <pkg>_SUPPORTS_OUT_OF_TREE. For a package that sets it and
has <pkg>_OVERRIDE_SRCDIR defined:
- <pkg>_SRCDIR is the overridden directory, used in place: nothing is
rsynced into $(BUILD_DIR), only the pre/post rsync hooks still run;
- the source-related stamp files (rsynced, patched, ...) live in the
build directory so that nothing is created in the user's tree;
- kconfig packages start from the source directory with O=<builddir>,
which makes kbuild generate its wrapper Makefile in the build
directory, so that all the existing -C $(LINUX_DIR) invocations keep
working unmodified.
Enable it for the Linux kernel. The source tree must be clean (no
in-tree .config, include/config, arch/*/include/generated).
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
linux/linux.mk | 4 ++++
package/pkg-generic.mk | 30 ++++++++++++++++++++++--------
package/pkg-kconfig.mk | 6 +++++-
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/linux/linux.mk b/linux/linux.mk
index a90e09afe906..ffec32154222 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -6,6 +6,10 @@
LINUX_VERSION = $(call qstrip,$(BR2_LINUX_KERNEL_VERSION))
LINUX_LICENSE = GPL-2.0
+
+# When LINUX_OVERRIDE_SRCDIR is set, build out of tree: no rsync of the
+# sources, the kernel is built in $(BUILD_DIR)/linux-custom with O=.
+LINUX_SUPPORTS_OUT_OF_TREE = YES
LINUX_LICENSE_FILES = $(call qstrip,$(BR2_LINUX_KERNEL_LICENSE_FILES))
LINUX_CPE_ID_VENDOR = linux
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 138fe9ccef4f..c8f532e1c3e6 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -221,11 +221,11 @@ $(SRC_DIR)/%/.stamp_extracted:
# used.
$(SRC_DIR)/%/.stamp_rsynced:
@$(call step_start,rsync)
- @$(call MESSAGE,"Syncing from source dir $(SRCDIR)")
+ @$(call MESSAGE,"$(if $($(PKG)_OUT_OF_TREE),Using out-of-tree source dir,Syncing from source dir) $(SRCDIR)")
@mkdir -p $(@D)
$(foreach hook,$($(PKG)_PRE_RSYNC_HOOKS),$(call $(hook))$(sep))
@test -d $(SRCDIR) || (echo "ERROR: $(SRCDIR) does not exist" ; exit 1)
- rsync -au --chmod=u=rwX,go=rX $($(PKG)_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS) $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D)
+ $(if $($(PKG)_OUT_OF_TREE),,rsync -au --chmod=u=rwX,go=rX $($(PKG)_OVERRIDE_SRCDIR_RSYNC_EXCLUSIONS) $(RSYNC_VCS_EXCLUSIONS) $(call qstrip,$(SRCDIR))/ $(@D))
$(foreach hook,$($(PKG)_POST_RSYNC_HOOKS),$(call $(hook))$(sep))
@$(call step_end,rsync)
$(Q)touch $@
@@ -559,13 +559,27 @@ ifndef $(2)_STRIP_COMPONENTS
endif
$(2)_SRCDIR = $$($(2)_DIR)
-$(2)_BUILDDIR = $$($(2)_DIR)
+$(2)_BUILDDIR ?= $$($(2)_DIR)
$(2)_SRCSUBDIR = $$($(2)_SRCDIR)/$$($(2)_SUBDIR)
ifneq ($$($(2)_OVERRIDE_SRCDIR),)
$(2)_VERSION = custom
endif
+# Packages that set <pkg>_SUPPORTS_OUT_OF_TREE = YES can be built out of
+# tree when their source directory is overridden: the sources are used
+# where they are (no rsync), and only the build directory lives in
+# $(BUILD_DIR). The source-related stamp files must then not be created
+# in the (user-owned) source directory, so they live in the build directory.
+$(2)_STAMP_SRCDIR = $$($(2)_SRCDIR)
+ifneq ($$($(2)_OVERRIDE_SRCDIR),)
+ifeq ($$($(3)_SUPPORTS_OUT_OF_TREE),YES)
+$(2)_OUT_OF_TREE = YES
+$(2)_SRCDIR = $$(abspath $$(call qstrip,$$($(2)_OVERRIDE_SRCDIR)))
+$(2)_STAMP_SRCDIR = $$($(2)_BUILDDIR)
+endif
+endif
+
ifndef $(2)_SOURCE
ifdef $(3)_SOURCE
$(2)_SOURCE = $$($(3)_SOURCE)
@@ -844,11 +858,11 @@ $(2)_TARGET_INSTALL_IMAGES = $$($(2)_BUILDDIR)/.stamp_images_installed
$(2)_TARGET_INSTALL_HOST = $$($(2)_BUILDDIR)/.stamp_host_installed
$(2)_TARGET_BUILD = $$($(2)_BUILDDIR)/.stamp_built
$(2)_TARGET_CONFIGURE = $$($(2)_BUILDDIR)/.stamp_configured
-$(2)_TARGET_RSYNC = $$($(2)_SRCDIR)/.stamp_rsynced
-$(2)_TARGET_PATCH = $$($(2)_SRCDIR)/.stamp_patched
-$(2)_TARGET_EXTRACT = $$($(2)_SRCDIR)/.stamp_extracted
-$(2)_TARGET_SOURCE = $$($(2)_SRCDIR)/.stamp_downloaded
-$(2)_TARGET_ACTUAL_SOURCE = $$($(2)_SRCDIR)/.stamp_actual_downloaded
+$(2)_TARGET_RSYNC = $$($(2)_STAMP_SRCDIR)/.stamp_rsynced
+$(2)_TARGET_PATCH = $$($(2)_STAMP_SRCDIR)/.stamp_patched
+$(2)_TARGET_EXTRACT = $$($(2)_STAMP_SRCDIR)/.stamp_extracted
+$(2)_TARGET_SOURCE = $$($(2)_STAMP_SRCDIR)/.stamp_downloaded
+$(2)_TARGET_ACTUAL_SOURCE = $$($(2)_STAMP_SRCDIR)/.stamp_actual_downloaded
$(2)_TARGET_DIRCLEAN = $$($(2)_BUILDDIR)/.stamp_dircleaned
# default extract command
diff --git a/package/pkg-kconfig.mk b/package/pkg-kconfig.mk
index 8a63d55be033..5e46c62c58e6 100644
--- a/package/pkg-kconfig.mk
+++ b/package/pkg-kconfig.mk
@@ -147,8 +147,12 @@ $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES): | $(1)-patch
fi; \
done
+# For an out-of-tree build, the first kconfig run is what creates the
+# wrapper Makefile in the build directory, so it must be started from
+# the source directory.
$(2)_KCONFIG_MAKE = \
- $$($(2)_MAKE_ENV) $$($(2)_MAKE) -C $$($(2)_BUILDDIR) \
+ $$($(2)_MAKE_ENV) $$($(2)_MAKE) \
+ $$(if $$($(2)_OUT_OF_TREE),-C $$($(2)_SRCDIR) O=$$($(2)_BUILDDIR),-C $$($(2)_BUILDDIR)) \
$$(PKG_KCONFIG_COMMON_OPTS) $$($(2)_KCONFIG_OPTS)
# The specified source configuration file and any additional configuration file
--
2.34.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2026-10-23 21:52 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 21:47 [Buildroot] [PATCH 00/23] Support building the Linux kernel out of tree with LINUX_OVERRIDE_SRCDIR Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 01/23] package: prepare removal of <pkg>_DIR Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 02/23] infra: introduce a global SRC_DIR variable Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 03/23] package: fix <pkg>_SRCDIR and <pkg>_BUILDDIR values Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 04/23] boot/boot-wrapper-aarch64: needs LINUX_BUILDDIR Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 05/23] boot/mxs-bootlets: needs (BAREBOX, LINUX, UBOOT)_BUILDDIR Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 06/23] linux/extensions: point to proper _SRCDIR and @D Florian Fainelli via buildroot
2026-10-23 21:47 ` [Buildroot] [PATCH 07/23] linux/linux: LINUX_VERSION_PROBED should run from build directory Florian Fainelli via buildroot
2026-10-23 21:51 ` Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 08/23] package: use <pkg>_SRCSUBDIR where <pkg>_SRCDIR used to include _SUBDIR Florian Fainelli via buildroot
2026-10-23 21:51 ` Florian Fainelli via buildroot [this message]
2026-10-23 21:51 ` [Buildroot] [PATCH 10/23] packages: sync host and target patch hooks Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 11/23] omniorb: avoid target-only patch hook Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 12/23] lua: rework post-patch hook usage Florian Fainelli via buildroot
2026-10-24 10:46 ` François PERRAD
2026-10-27 16:43 ` Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 13/23] infra: host packages inherit the target extra downloads Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 14/23] package/libtool: use post-patch hooks Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 15/23] package/libtool: also apply libtool-patch to host libtool Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 16/23] package/{ffmpeg, libvpx}: use $(@D) instead of $(pkg_SRCDIR) when possible Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 17/23] package/perl: apply the perl-cross even for the host variant Florian Fainelli via buildroot
2026-10-24 10:20 ` François PERRAD
2026-10-27 16:44 ` Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 18/23] infra/autotools: warn for package that autoreconf without libtool patch Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 19/23] packages: replace $(PKG)_DIR with @D where possible Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 20/23] linux: support custom logo and devicetree files in out-of-tree builds Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 21/23] package/linux-tools: support an out-of-tree kernel build Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 22/23] package: read kernel headers from LINUX_SRCDIR Florian Fainelli via buildroot
2026-10-23 21:51 ` [Buildroot] [PATCH 23/23] docs/manual: document out-of-tree package builds and the new srcdir variables Florian Fainelli via buildroot
2026-10-24 20:44 ` [Buildroot] [PATCH 00/23] Support building the Linux kernel out of tree with LINUX_OVERRIDE_SRCDIR Thomas Petazzoni via buildroot
2026-10-26 21:49 ` Florian Fainelli via buildroot
2026-10-27 8:14 ` Arnout Vandecappelle via buildroot
2026-10-27 8:26 ` Thomas Petazzoni via buildroot
2026-10-27 8:43 ` Arnout Vandecappelle via buildroot
2026-10-27 12:41 ` Thomas Petazzoni via buildroot
2026-10-27 12:44 ` Thomas Petazzoni via buildroot
2026-10-27 13:53 ` Arnout Vandecappelle via buildroot
2026-10-27 16:53 ` Florian Fainelli via buildroot
2026-10-27 19:22 ` Thomas Petazzoni via buildroot
2026-10-27 19:56 ` Florian Fainelli via buildroot
2026-10-28 18:16 ` Thomas Petazzoni via buildroot
2026-10-28 18:35 ` Florian Fainelli via buildroot
2026-10-28 19:26 ` Thomas Petazzoni via buildroot
2026-10-27 20:32 ` Fiona Klute via buildroot
2026-10-28 18:18 ` Thomas Petazzoni via buildroot
2026-10-28 18:34 ` Florian Fainelli via buildroot
2026-10-28 19:26 ` Thomas Petazzoni 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=20261023215138.2301146-3-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