[PATCH v4 4/7] tools: build perf in tools_build
From: Sasha Levin
Date: Thu Nov 12 2026 - 17:12:46 EST
Add CONFIG_TOOLS_BUILD_PERF. perf is built as it is built standalone,
with optional features enabled when their libraries are installed, and
with perf's WERROR setting following CONFIG_WERROR. The feature table is
left out of the kernel build log.
CONFIG_TOOLS_BUILD_PERF_MINIMAL builds it with MINIMAL=1 instead, which
turns every optional feature off, so the result does not depend on the
build machine. Without MINIMAL=1 perf does not build when pkg-config,
libelf or libtraceevent is missing, so the option can only be turned
off when Kconfig finds all three for the target, and never with
CONFIG_COMPILE_TEST. A build test, randconfig included, then does not
fail over a library the machine does not have.
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/Kconfig | 24 ++++++++++++++++++++++++
tools/Makefile.kbuild | 10 ++++++++++
2 files changed, 34 insertions(+)
diff --git a/tools/Kconfig b/tools/Kconfig
index 04896e6b0ca51..ab1e15beb9fe3 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -60,6 +60,30 @@ config TOOLS_BUILD_IIO
help
Build tools/iio (lsiio, iio_event_monitor, iio_generic_buffer).
+config TOOLS_BUILD_PERF
+ bool "perf"
+ help
+ Build tools/perf. As in a standalone perf build, optional
+ features are enabled when the libraries they need are installed.
+
+# What perf does not build without, unless it is built with MINIMAL=1
+config TOOLS_BUILD_PERF_LIBS
+ def_bool $(success,command -v $(CROSS_COMPILE)pkg-config || command -v pkg-config) && \
+ $(success,echo 'int main(void) { return 0; }' | $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag) `$(CROSS_COMPILE)pkg-config --cflags --libs libtraceevent 2>/dev/null || pkg-config --cflags --libs libtraceevent` -include libelf.h -include trace-seq.h -x c - -o /dev/null -lelf)
+
+config TOOLS_BUILD_PERF_MINIMAL
+ bool "Build perf with all optional features disabled" if TOOLS_BUILD_PERF_LIBS && !COMPILE_TEST
+ depends on TOOLS_BUILD_PERF
+ default !TOOLS_BUILD_PERF_LIBS || COMPILE_TEST
+ help
+ Build perf with MINIMAL=1, which turns off every optional
+ feature, so that the result does not depend on which libraries
+ the build machine has installed. This is always on when
+ pkg-config, libelf or libtraceevent is missing for the target,
+ as perf does not build without them otherwise, and with
+ COMPILE_TEST, which keeps build tests such as allmodconfig the
+ same on every machine.
+
config TOOLS_BUILD_SPI
bool "SPI tools"
help
diff --git a/tools/Makefile.kbuild b/tools/Makefile.kbuild
index 7a26e7c3d5769..5cf8441989fac 100644
--- a/tools/Makefile.kbuild
+++ b/tools/Makefile.kbuild
@@ -79,6 +79,16 @@ PHONY += $(tool-targets)
$(tool-targets): tool-%: FORCE
$(call build,$(outdir)/$*,-C $(toolsdir)/$* O=$(outdir)/$* CC='$(call escsq,$(tools-cc))',,TOOLS_BUILD_$(shell echo $* | tr a-z A-Z))
+# perf, without the feature table in the kernel build log
+perf-flags := CC='$(call escsq,$(tools-cc))' FEATURE_DISPLAY= WERROR=$(if $(CONFIG_WERROR),1,0)
+perf-flags-$(CONFIG_TOOLS_BUILD_PERF_MINIMAL) += MINIMAL=1
+
+__tools_build: $(if $(CONFIG_TOOLS_BUILD_PERF),perf)
+
+PHONY += perf
+perf: FORCE
+ $(call build,$(outdir)/perf,-C $(toolsdir)/perf -f Makefile.perf O=$(outdir)/perf $(perf-flags) $(perf-flags-y),,TOOLS_BUILD_PERF)
+
PHONY += FORCE
FORCE:
--
2.53.0