blob: c264da2b9b3083738eb6bb67d513a76634dca572 [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Masahiro Yamadae1cfdc02018-05-28 18:21:59 +09002# 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
Masahiro Yamada902a6892019-05-09 16:35:55 +090022# $(failure,<command>)
23# Return n if <command> exits with 0, y otherwise
24failure = $(if-success,$(1),n,y)
25
Masahiro Yamadae1cfdc02018-05-28 18:21:59 +090026# $(cc-option,<flag>)
27# Return y if the compiler supports <flag>, n otherwise
Masahiro Yamada3bed1b72020-01-18 02:14:35 +090028cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
Masahiro Yamadae1cfdc02018-05-28 18:21:59 +090029
30# $(ld-option,<flag>)
31# Return y if the linker supports <flag>, n otherwise
32ld-option = $(success,$(LD) -v $(1))
Masahiro Yamada59f53852018-05-28 18:22:06 +090033
Vincenzo Frascinoc2d920b2020-03-13 14:35:02 +053034# $(as-option,<flag>)
35# /dev/zero is used as output instead of /dev/null as some assembler cribs when
36# both input and output are same. Also both of them have same write behaviour so
37# can be easily substituted.
38as-option = $(success, $(CC) $(CLANG_FLAGS) $(1) -c -x assembler /dev/null -o /dev/zero)
39
Catalin Marinas42d519e2020-01-15 11:30:07 +000040# $(as-instr,<instr>)
41# Return y if the assembler supports <instr>, n otherwise
42as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
43
Masahiro Yamada902a6892019-05-09 16:35:55 +090044# check if $(CC) and $(LD) exist
45$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
46$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
47
Thomas Gleixner75959d42019-07-16 21:47:27 +020048# Fail if the linker is gold as it's not capable of linking the kernel proper
49$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
50
Masahiro Yamada8cc4fd72020-03-10 19:12:49 +090051# machine bit flags
52# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
53# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
54cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
55m32-flag := $(cc-option-bit,-m32)
56m64-flag := $(cc-option-bit,-m64)