Skip to content

Commit 902a689

Browse files
committed
kbuild: terminate Kconfig when $(CC) or $(LD) is missing
If the compiler specified by $(CC) is not present, the Kconfig stage sprinkles 'not found' messages, then succeeds. $ make CROSS_COMPILE=foo defconfig /bin/sh: 1: foogcc: not found /bin/sh: 1: foogcc: not found *** Default configuration is based on 'x86_64_defconfig' ./scripts/gcc-version.sh: 17: ./scripts/gcc-version.sh: foogcc: not found ./scripts/gcc-version.sh: 18: ./scripts/gcc-version.sh: foogcc: not found ./scripts/gcc-version.sh: 19: ./scripts/gcc-version.sh: foogcc: not found ./scripts/gcc-version.sh: 17: ./scripts/gcc-version.sh: foogcc: not found ./scripts/gcc-version.sh: 18: ./scripts/gcc-version.sh: foogcc: not found ./scripts/gcc-version.sh: 19: ./scripts/gcc-version.sh: foogcc: not found ./scripts/clang-version.sh: 11: ./scripts/clang-version.sh: foogcc: not found ./scripts/gcc-plugin.sh: 11: ./scripts/gcc-plugin.sh: foogcc: not found init/Kconfig:16:warning: 'GCC_VERSION': number is invalid # # configuration written to .config # Terminate parsing files immediately if $(CC) or $(LD) is not found. "make *config" will fail more nicely. $ make CROSS_COMPILE=foo defconfig *** Default configuration is based on 'x86_64_defconfig' scripts/Kconfig.include:34: compiler 'foogcc' not found make[1]: *** [scripts/kconfig/Makefile;82: defconfig] Error 1 make: *** [Makefile;557: defconfig] Error 2 Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d2f8ae0 commit 902a689

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ endif
537537
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
538538
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
539539
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
540-
CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
540+
CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1)
541541

542542
ifeq ($(config-targets),1)
543543
# ===========================================================================

scripts/Kconfig.include

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
1818
# Return y if <command> exits with 0, n otherwise
1919
success = $(if-success,$(1),y,n)
2020

21+
# $(failure,<command>)
22+
# Return n if <command> exits with 0, y otherwise
23+
failure = $(if-success,$(1),n,y)
24+
2125
# $(cc-option,<flag>)
2226
# Return y if the compiler supports <flag>, n otherwise
2327
cc-option = $(success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null)
@@ -26,5 +30,9 @@ cc-option = $(success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null)
2630
# Return y if the linker supports <flag>, n otherwise
2731
ld-option = $(success,$(LD) -v $(1))
2832

33+
# check if $(CC) and $(LD) exist
34+
$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
35+
$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
36+
2937
# gcc version including patch level
3038
gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC))

0 commit comments

Comments
 (0)