From: Sasha Levin <sashal@kernel.org>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>,
linux-kbuild@vger.kernel.org, Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RFC PATCH 2/6] kbuild: add "make tools_build" to build userspace tools from tools/
Date: Thu, 15 Oct 2026 14:52:40 -0400 [thread overview]
Message-ID: <atEg-E51MHBHL8Ju@laps> (raw)
In-Reply-To: <b0fa30a6-9f41-4c9a-a3fb-2634322e2bd1@t-8ch.de>
On Tue, Oct 13, 2026 at 10:38:37PM +0200, Thomas Weißschuh wrote:
>On 2026-10-11 19:36:41-0400, Sasha Levin wrote:
>(...)
>
>> Assisted-by: LLM
>> Signed-off-by: Sasha Levin <sashal@kernel.org>
>> ---
>> .gitignore | 5 +++
>> Makefile | 8 ++++-
>> lib/Kconfig.debug | 2 ++
>> tools/Kconfig | 72 +++++++++++++++++++++++++++++++++++++++
>> tools/Makefile.kbuild | 79 +++++++++++++++++++++++++++++++++++++++++++
>> 5 files changed, 165 insertions(+), 1 deletion(-)
>> create mode 100644 tools/Kconfig
>> create mode 100644 tools/Makefile.kbuild
>
>(...)
>
>> diff --git a/tools/Kconfig b/tools/Kconfig
>> new file mode 100644
>> index 0000000000000..bf0643b39b86e
>> --- /dev/null
>> +++ b/tools/Kconfig
>> @@ -0,0 +1,72 @@
>> +# SPDX-License-Identifier: GPL-2.0-only
>> +
>> +config TOOLS_BUILD_ABI
>> + def_bool X86_64 || ARM64
>> +
>> +config TOOLS_BUILD_GLIBC
>> + def_bool $(success,echo '#include <features.h>' | $(CC) $(CLANG_FLAGS) $(USERCFLAGS) -E -dM -x c - | grep -q __GLIBC__)
>> +
>> +menuconfig TOOLS_BUILD
>> + bool "Build userspace tools from tools/"
>> + depends on CC_CAN_LINK && !UML
>
>Why !UML?
Building with ARCH=um was reaching the tools, which then set "-I
tools/arch/um/include" but that dir doesn't exist.
I worked around this for the RFC, but I think I can address it when I resent
the patches.
>> + depends on TOOLS_BUILD_ABI && TOOLS_BUILD_GLIBC
>
>These dependencies could be on separate lines, it will reduce churn when
>they get modified.
ack
>> + help
>> + Build the selected programs under tools/ for the target together
>> + with the kernel, as part of "make all", or alone with
>> + "make tools_build". Each program is built by its own build system
>> + into tools-build/ in the object tree. The tools then always match
>> + the kernel they were built with, and a change that breaks one of
>> + them shows up in the same build that compiles the kernel.
>> +
>> + This needs a compiler that can link glibc programs for the target,
>> + and is currently limited to x86_64 and arm64.
>> +
>> + If unsure, say N.
>
>(...)
>
>> diff --git a/tools/Makefile.kbuild b/tools/Makefile.kbuild
>> new file mode 100644
>> index 0000000000000..820a2d9a3893b
>> --- /dev/null
>> +++ b/tools/Makefile.kbuild
>> @@ -0,0 +1,79 @@
>> +# SPDX-License-Identifier: GPL-2.0-only
>> +#
>> +# Builds the userspace programs selected in tools/Kconfig for the target.
>> +# Invoked by "make tools_build", which "make all" runs when CONFIG_TOOLS_BUILD
>> +# is set. Each program is built by its own build system, the way it is built
>> +# standalone, into $(objtree)/tools-build/.
>> +
>> +PHONY := __tools_build
>> +__tools_build:
>> +
>> +include include/config/auto.conf
>> +
>> +abs_srctree := $(realpath $(srctree))
>> +toolsdir := $(abs_srctree)/tools
>> +outdir := $(CURDIR)/tools-build
>> +
>> +# kbuild's state and the user's compiler flags, from the environment or the
>> +# command line, would change how these build
>> +unexport srctree objtree srcroot VPATH building_out_of_srctree sub_make_done
>> +unexport CLANG_FLAGS INSTALL_HDR_PATH O
>> +unexport CFLAGS CPPFLAGS LDFLAGS EXTRA_CFLAGS EXTRA_LDFLAGS USERCFLAGS USERLDFLAGS
>> +space := $(subst ,, )
>> +overrides := $(subst \$(space),\@space@,$(MAKEOVERRIDES))
>> +MAKEOVERRIDES := $(subst \@space@,\$(space),$(filter-out O=% CFLAGS=% CPPFLAGS=% \
>> + LDFLAGS=% EXTRA_CFLAGS=% EXTRA_LDFLAGS=% USERCFLAGS=% USERLDFLAGS=%,$(overrides)))
>> +
>> +# Keep Python's bytecode caches out of the source tree
>> +export PYTHONDONTWRITEBYTECODE := 1
>
>This should just be done in the toplevel Makefile IMO.
I originally added this because perf was silly, but apparently that was a bug
instead of intended behavior, which was fixed in 5479e1a13b759 ("perf tools:
Put Python bytecode in output directory"), so I think I can just drop this
altogether.
--
Thanks,
Sasha
next prev parent reply other threads:[~2026-10-15 18:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 23:36 [RFC PATCH 0/6] kbuild: build the userspace tools in tools/ with the kernel Sasha Levin
2026-10-11 23:36 ` [RFC PATCH 1/6] kbuild: factor the userspace ABI flags out into KBUILD_USERABI Sasha Levin
2026-10-13 20:31 ` Thomas Weißschuh
2026-10-11 23:36 ` [RFC PATCH 2/6] kbuild: add "make tools_build" to build userspace tools from tools/ Sasha Levin
2026-10-13 20:38 ` Thomas Weißschuh
2026-10-15 18:52 ` Sasha Levin [this message]
2026-10-11 23:36 ` [RFC PATCH 3/6] tools: build perf in tools_build Sasha Levin
2026-10-12 22:07 ` Ian Rogers
2026-10-13 17:08 ` Sasha Levin
2026-10-13 20:21 ` Arnaldo Carvalho de Melo
2026-10-15 19:26 ` Sasha Levin
2026-10-15 21:26 ` Ian Rogers
2026-10-15 22:35 ` Arnaldo Melo
2026-10-11 23:36 ` [RFC PATCH 4/6] tools: build kernel selftests " Sasha Levin
2026-10-13 19:29 ` Shuah Khan
2026-10-13 20:41 ` Thomas Weißschuh
2026-10-11 23:36 ` [RFC PATCH 5/6] kbuild: build the tools selected in tools/Kconfig as part of "make all" Sasha Levin
2026-10-11 23:36 ` [RFC PATCH 6/6] Documentation: describe building tools with the kernel Sasha Levin
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=atEg-E51MHBHL8Ju@laps \
--to=sashal@kernel.org \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=irogers@google.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=shuah@kernel.org \
--cc=thomas@t-8ch.de \
/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;
as well as URLs for NNTP newsgroup(s).