[PATCH v4 01/14] tools build: Fix feature checks to touch target files on success

From: Ian Rogers

Date: Fri May 15 2026 - 13:41:47 EST


In tools/build/feature/Makefile, test-clang-bpf-co-re.bin and
test-bpftool-skeletons.bin redirected grep output but never touched or
created the $@ target file upon success.

Because the target file was never created on disk, Kbuild could never cache
the result of the check. Consequently, Make treated the prerequisite as
missing and continuously re-executed the Clang BPF backend and bpftool
feature checks on every single sub-make evaluation during build startup.

Refactor both feature check recipes to redirect grep output to .make.output
and touch $@ upon success (> $(@:.bin=.make.output) 2>&1 && touch $@). This
perfectly matches standard Kbuild feature check conventions and ensures the
target file is touched on disk purely upon success, allowing Kbuild to
perfectly cache positive detections and avoid redundant sub-make forks. For
test-clang-bpf-co-re.bin, add the explicit source file prerequisite
test-clang-bpf-co-re.c and simplify the Clang recipe using $<.

Tested-by: James Clark <james.clark@xxxxxxxxxx>
Assisted-by: Gemini:gemini-3.1-pro-preview
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/build/feature/Makefile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 704c687ed3ad..ea278becee2f 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -383,9 +383,9 @@ $(OUTPUT)test-libaio.bin:
$(OUTPUT)test-libzstd.bin:
$(BUILD) -lzstd

-$(OUTPUT)test-clang-bpf-co-re.bin:
- $(CLANG) -S -g --target=bpf -o - $(patsubst %.bin,%.c,$(@F)) | \
- grep BTF_KIND_VAR
+$(OUTPUT)test-clang-bpf-co-re.bin: test-clang-bpf-co-re.c
+ $(CLANG) -S -g --target=bpf -o - $< | \
+ grep BTF_KIND_VAR > $(@:.bin=.make.output) 2>&1 && touch $@

$(OUTPUT)test-file-handle.bin:
$(BUILD)
@@ -398,7 +398,7 @@ $(OUTPUT)test-libopenssl.bin:

$(OUTPUT)test-bpftool-skeletons.bin:
$(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \
- > $(@:.bin=.make.output) 2>&1
+ > $(@:.bin=.make.output) 2>&1 && touch $@

# Testing Rust is special: we don't compile anything, it's enough to check the
# compiler presence. Compiling a test code for this purposes is problematic,
--
2.54.0.563.g4f69b47b94-goog