Skip to content

Commit b61442d

Browse files
committed
tools: do not include scripts/Kbuild.include
Since commit 57fd251 ("kbuild: split cc-option and friends to scripts/Makefile.compiler"), some kselftests fail to build. The tools/ directory opted out Kbuild, and went in a different direction. People copied scripts and Makefiles to the tools/ directory to create their own build system. tools/build/Build.include mimics scripts/Kbuild.include, but some tool Makefiles include the Kbuild one to import a feature that is missing in tools/build/Build.include: - Commit ec04aa3 ("tools/thermal: tmon: use "-fstack-protector" only if supported") included scripts/Kbuild.include from tools/thermal/tmon/Makefile to import the cc-option macro. - Commit c2390f1 ("selftests: kvm: fix for compilers that do not support -no-pie") included scripts/Kbuild.include from tools/testing/selftests/kvm/Makefile to import the try-run macro. - Commit 9cae4ac ("selftests/bpf: do not ignore clang failures") included scripts/Kbuild.include from tools/testing/selftests/bpf/Makefile to import the .DELETE_ON_ERROR target. - Commit 0695f8b ("selftests/powerpc: Handle Makefile for unrecognized option") included scripts/Kbuild.include from tools/testing/selftests/powerpc/pmu/ebb/Makefile to import the try-run macro. Copy what they need into tools/build/Build.include, and make them include it instead of scripts/Kbuild.include. Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: 57fd251 ("kbuild: split cc-option and friends to scripts/Makefile.compiler") Reported-by: Janosch Frank <[email protected]> Reported-by: Christian Borntraeger <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Tested-by: Christian Borntraeger <[email protected]> Acked-by: Yonghong Song <[email protected]>
1 parent 0e0345b commit b61442d

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

tools/build/Build.include

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,27 @@ cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXX
100100
## HOSTCC C flags
101101

102102
host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(KBUILD_HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj))
103+
104+
# output directory for tests below
105+
TMPOUT = .tmp_$$$$
106+
107+
# try-run
108+
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
109+
# Exit code chooses option. "$$TMP" serves as a temporary file and is
110+
# automatically cleaned up.
111+
try-run = $(shell set -e; \
112+
TMP=$(TMPOUT)/tmp; \
113+
mkdir -p $(TMPOUT); \
114+
trap "rm -rf $(TMPOUT)" EXIT; \
115+
if ($(1)) >/dev/null 2>&1; \
116+
then echo "$(2)"; \
117+
else echo "$(3)"; \
118+
fi)
119+
120+
# cc-option
121+
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
122+
cc-option = $(call try-run, \
123+
$(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
124+
125+
# delete partially updated (i.e. corrupted) files on error
126+
.DELETE_ON_ERROR:

tools/testing/selftests/bpf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
include ../../../../scripts/Kbuild.include
2+
include ../../../build/Build.include
33
include ../../../scripts/Makefile.arch
44
include ../../../scripts/Makefile.include
55

tools/testing/selftests/kvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
include ../../../../scripts/Kbuild.include
2+
include ../../../build/Build.include
33

44
all:
55

tools/testing/selftests/powerpc/pmu/ebb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
include ../../../../../../scripts/Kbuild.include
2+
include ../../../../../build/Build.include
33

44
noarg:
55
$(MAKE) -C ../../

tools/thermal/tmon/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# We need this for the "cc-option" macro.
3-
include ../../../scripts/Kbuild.include
3+
include ../../build/Build.include
44

55
VERSION = 1.0
66

0 commit comments

Comments
 (0)