1 # SPDX-License-Identifier: GPL-2.0-only
2 # Kconfig helper macros
9 space := $(empty) $(empty)
14 # $(if-success,<command>,<then>,<else>)
15 # Return <then> if <command> exits with 0, <else> otherwise.
16 if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
18 # $(success,<command>)
19 # Return y if <command> exits with 0, n otherwise
20 success = $(if-success,$(1),y,n)
22 # $(failure,<command>)
23 # Return n if <command> exits with 0, y otherwise
24 failure = $(if-success,$(1),n,y)
27 # Return y if the compiler supports <flag>, n otherwise
28 cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
31 # Return y if the linker supports <flag>, n otherwise
32 ld-option = $(success,$(LD) -v $(1))
34 # check if $(CC) and $(LD) exist
35 $(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
36 $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
38 # Fail if the linker is gold as it's not capable of linking the kernel proper
39 $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
41 # gcc version including patch level
42 gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC))
45 # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
46 # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
47 cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
48 m32-flag := $(cc-option-bit,-m32)
49 m64-flag := $(cc-option-bit,-m64)