xref: /linux/scripts/Kconfig.include (revision 8cc4fd73501d9f1370c3eebb70cfe8cc9e24062b)
1ec8f24b7SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
2e1cfdc0eSMasahiro Yamada# Kconfig helper macros
3e1cfdc0eSMasahiro Yamada
4e1cfdc0eSMasahiro Yamada# Convenient variables
5e1cfdc0eSMasahiro Yamadacomma       := ,
6e1cfdc0eSMasahiro Yamadaquote       := "
7e1cfdc0eSMasahiro Yamadasquote      := '
8e1cfdc0eSMasahiro Yamadaempty       :=
9e1cfdc0eSMasahiro Yamadaspace       := $(empty) $(empty)
10e1cfdc0eSMasahiro Yamadadollar      := $
11e1cfdc0eSMasahiro Yamadaright_paren := )
12e1cfdc0eSMasahiro Yamadaleft_paren  := (
13e1cfdc0eSMasahiro Yamada
14e1cfdc0eSMasahiro Yamada# $(if-success,<command>,<then>,<else>)
15e1cfdc0eSMasahiro Yamada# Return <then> if <command> exits with 0, <else> otherwise.
16e1cfdc0eSMasahiro Yamadaif-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
17e1cfdc0eSMasahiro Yamada
18e1cfdc0eSMasahiro Yamada# $(success,<command>)
19e1cfdc0eSMasahiro Yamada# Return y if <command> exits with 0, n otherwise
20e1cfdc0eSMasahiro Yamadasuccess = $(if-success,$(1),y,n)
21e1cfdc0eSMasahiro Yamada
22902a6898SMasahiro Yamada# $(failure,<command>)
23902a6898SMasahiro Yamada# Return n if <command> exits with 0, y otherwise
24902a6898SMasahiro Yamadafailure = $(if-success,$(1),n,y)
25902a6898SMasahiro Yamada
26e1cfdc0eSMasahiro Yamada# $(cc-option,<flag>)
27e1cfdc0eSMasahiro Yamada# Return y if the compiler supports <flag>, n otherwise
283bed1b7bSMasahiro Yamadacc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
29e1cfdc0eSMasahiro Yamada
30e1cfdc0eSMasahiro Yamada# $(ld-option,<flag>)
31e1cfdc0eSMasahiro Yamada# Return y if the linker supports <flag>, n otherwise
32e1cfdc0eSMasahiro Yamadald-option = $(success,$(LD) -v $(1))
3359f53855SMasahiro Yamada
3442d519e3SCatalin Marinas# $(as-instr,<instr>)
3542d519e3SCatalin Marinas# Return y if the assembler supports <instr>, n otherwise
3642d519e3SCatalin Marinasas-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
3742d519e3SCatalin Marinas
38902a6898SMasahiro Yamada# check if $(CC) and $(LD) exist
39902a6898SMasahiro Yamada$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
40902a6898SMasahiro Yamada$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
41902a6898SMasahiro Yamada
4275959d44SThomas Gleixner# Fail if the linker is gold as it's not capable of linking the kernel proper
4375959d44SThomas Gleixner$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
4475959d44SThomas Gleixner
4559f53855SMasahiro Yamada# gcc version including patch level
46fa7295abSMasahiro Yamadagcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC))
47*8cc4fd73SMasahiro Yamada
48*8cc4fd73SMasahiro Yamada# machine bit flags
49*8cc4fd73SMasahiro Yamada#  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
50*8cc4fd73SMasahiro Yamada#  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
51*8cc4fd73SMasahiro Yamadacc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
52*8cc4fd73SMasahiro Yamadam32-flag := $(cc-option-bit,-m32)
53*8cc4fd73SMasahiro Yamadam64-flag := $(cc-option-bit,-m64)
54