xref: /linux/scripts/Kconfig.include (revision 02aff85922043cf175ebbe5fc3430acfeaeb8393)
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
284d0831e8SMasahiro Yamadacc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
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
42aec6c60aSMasahiro Yamada# Get the compiler name, version, and error out if it is not supported.
43aec6c60aSMasahiro Yamadacc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
44aec6c60aSMasahiro Yamada$(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not supported.)
45aec6c60aSMasahiro Yamadacc-name := $(shell,set -- $(cc-info) && echo $1)
46aec6c60aSMasahiro Yamadacc-version := $(shell,set -- $(cc-info) && echo $2)
47aec6c60aSMasahiro Yamada
48*02aff859SMasahiro Yamada# Get the linker name, version, and error out if it is not supported.
49*02aff859SMasahiro Yamadald-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
50*02aff859SMasahiro Yamada$(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
51*02aff859SMasahiro Yamadald-name := $(shell,set -- $(ld-info) && echo $1)
52*02aff859SMasahiro Yamadald-version := $(shell,set -- $(ld-info) && echo $2)
5375959d44SThomas Gleixner
548cc4fd73SMasahiro Yamada# machine bit flags
558cc4fd73SMasahiro Yamada#  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
568cc4fd73SMasahiro Yamada#  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
578cc4fd73SMasahiro Yamadacc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
588cc4fd73SMasahiro Yamadam32-flag := $(cc-option-bit,-m32)
598cc4fd73SMasahiro Yamadam64-flag := $(cc-option-bit,-m64)
60