xref: /openbmc/linux/scripts/Kconfig.include (revision 7e24a55b2122746c2eef192296fc84624354f895)
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
28dd298656SMasahiro Yamadacc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(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
36*c8cae1c1SMasahiro Yamadaas-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) $(2) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
37*c8cae1c1SMasahiro Yamadaas-instr64 = $(as-instr,$(1),$(m64-flag))
3842d519e3SCatalin Marinas
39902a6898SMasahiro Yamada# check if $(CC) and $(LD) exist
402f7ab126SMiguel Ojeda$(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
41902a6898SMasahiro Yamada$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
42902a6898SMasahiro Yamada
432f7ab126SMiguel Ojeda# Get the C compiler name, version, and error out if it is not supported.
44aec6c60aSMasahiro Yamadacc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
452f7ab126SMiguel Ojeda$(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not supported.)
46aec6c60aSMasahiro Yamadacc-name := $(shell,set -- $(cc-info) && echo $1)
47aec6c60aSMasahiro Yamadacc-version := $(shell,set -- $(cc-info) && echo $2)
48aec6c60aSMasahiro Yamada
49ba64beb1SMasahiro Yamada# Get the assembler name, version, and error out if it is not supported.
50ba64beb1SMasahiro Yamadaas-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
51ba64beb1SMasahiro Yamada$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
52ba64beb1SMasahiro Yamadaas-name := $(shell,set -- $(as-info) && echo $1)
53ba64beb1SMasahiro Yamadaas-version := $(shell,set -- $(as-info) && echo $2)
54ba64beb1SMasahiro Yamada
5502aff859SMasahiro Yamada# Get the linker name, version, and error out if it is not supported.
5602aff859SMasahiro Yamadald-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
5702aff859SMasahiro Yamada$(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
5802aff859SMasahiro Yamadald-name := $(shell,set -- $(ld-info) && echo $1)
5902aff859SMasahiro Yamadald-version := $(shell,set -- $(ld-info) && echo $2)
6075959d44SThomas Gleixner
618cc4fd73SMasahiro Yamada# machine bit flags
628cc4fd73SMasahiro Yamada#  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
638cc4fd73SMasahiro Yamada#  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
648cc4fd73SMasahiro Yamadacc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
658cc4fd73SMasahiro Yamadam32-flag := $(cc-option-bit,-m32)
668cc4fd73SMasahiro Yamadam64-flag := $(cc-option-bit,-m64)
67