blob: 77a69ba9cd198a793ac90ae39045e4da7b2386b0 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001# SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002# Kconfig helper macros
3
4# Convenient variables
5comma := ,
6quote := "
7squote := '
8empty :=
9space := $(empty) $(empty)
10dollar := $
11right_paren := )
12left_paren := (
13
14# $(if-success,<command>,<then>,<else>)
15# Return <then> if <command> exits with 0, <else> otherwise.
16if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
17
18# $(success,<command>)
19# Return y if <command> exits with 0, n otherwise
20success = $(if-success,$(1),y,n)
21
David Brazdil0f672f62019-12-10 10:32:29 +000022# $(failure,<command>)
23# Return n if <command> exits with 0, y otherwise
24failure = $(if-success,$(1),n,y)
25
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000026# $(cc-option,<flag>)
27# Return y if the compiler supports <flag>, n otherwise
Olivier Deprez0e641232021-09-23 10:07:05 +020028cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029
30# $(ld-option,<flag>)
31# Return y if the linker supports <flag>, n otherwise
32ld-option = $(success,$(LD) -v $(1))
33
David Brazdil0f672f62019-12-10 10:32:29 +000034# 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)
37
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)
40
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000041# gcc version including patch level
David Brazdil0f672f62019-12-10 10:32:29 +000042gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC))
Olivier Deprez0e641232021-09-23 10:07:05 +020043
44# machine bit flags
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.
47cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
48m32-flag := $(cc-option-bit,-m32)
49m64-flag := $(cc-option-bit,-m64)