Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: do not include scripts/Kbuild.include

Since commit 57fd251c7896 ("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 ec04aa3ae87b ("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 c2390f16fc5b ("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 9cae4ace80ef ("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 0695f8bca93e ("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/86dadf33-70f7-a5ac-cb8c-64966d2f45a1@linux.ibm.com/
Fixes: 57fd251c7896 ("kbuild: split cc-option and friends to scripts/Makefile.compiler")
Reported-by: Janosch Frank <frankja@linux.ibm.com>
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Yonghong Song <yhs@fb.com>

+28 -4
+24
tools/build/Build.include
··· 100 100 ## HOSTCC C flags 101 101 102 102 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:
+1 -1
tools/testing/selftests/bpf/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - include ../../../../scripts/Kbuild.include 2 + include ../../../build/Build.include 3 3 include ../../../scripts/Makefile.arch 4 4 include ../../../scripts/Makefile.include 5 5
+1 -1
tools/testing/selftests/kvm/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - include ../../../../scripts/Kbuild.include 2 + include ../../../build/Build.include 3 3 4 4 all: 5 5
+1 -1
tools/testing/selftests/powerpc/pmu/ebb/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - include ../../../../../../scripts/Kbuild.include 2 + include ../../../../../build/Build.include 3 3 4 4 noarg: 5 5 $(MAKE) -C ../../
+1 -1
tools/thermal/tmon/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # We need this for the "cc-option" macro. 3 - include ../../../scripts/Kbuild.include 3 + include ../../build/Build.include 4 4 5 5 VERSION = 1.0 6 6