162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci# Kconfig helper macros
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci# Convenient variables
562306a36Sopenharmony_cicomma       := ,
662306a36Sopenharmony_ciquote       := "
762306a36Sopenharmony_cisquote      := '
862306a36Sopenharmony_ciempty       :=
962306a36Sopenharmony_cispace       := $(empty) $(empty)
1062306a36Sopenharmony_cidollar      := $
1162306a36Sopenharmony_ciright_paren := )
1262306a36Sopenharmony_cileft_paren  := (
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci# $(if-success,<command>,<then>,<else>)
1562306a36Sopenharmony_ci# Return <then> if <command> exits with 0, <else> otherwise.
1662306a36Sopenharmony_ciif-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci# $(success,<command>)
1962306a36Sopenharmony_ci# Return y if <command> exits with 0, n otherwise
2062306a36Sopenharmony_cisuccess = $(if-success,$(1),y,n)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci# $(failure,<command>)
2362306a36Sopenharmony_ci# Return n if <command> exits with 0, y otherwise
2462306a36Sopenharmony_cifailure = $(if-success,$(1),n,y)
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci# $(cc-option,<flag>)
2762306a36Sopenharmony_ci# Return y if the compiler supports <flag>, n otherwise
2862306a36Sopenharmony_cicc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci# $(ld-option,<flag>)
3162306a36Sopenharmony_ci# Return y if the linker supports <flag>, n otherwise
3262306a36Sopenharmony_cild-option = $(success,$(LD) -v $(1))
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci# $(as-instr,<instr>)
3562306a36Sopenharmony_ci# Return y if the assembler supports <instr>, n otherwise
3662306a36Sopenharmony_cias-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# check if $(CC) and $(LD) exist
3962306a36Sopenharmony_ci$(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
4062306a36Sopenharmony_ci$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci# Get the C compiler name, version, and error out if it is not supported.
4362306a36Sopenharmony_cicc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
4462306a36Sopenharmony_ci$(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not supported.)
4562306a36Sopenharmony_cicc-name := $(shell,set -- $(cc-info) && echo $1)
4662306a36Sopenharmony_cicc-version := $(shell,set -- $(cc-info) && echo $2)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci# Get the assembler name, version, and error out if it is not supported.
4962306a36Sopenharmony_cias-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
5062306a36Sopenharmony_ci$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
5162306a36Sopenharmony_cias-name := $(shell,set -- $(as-info) && echo $1)
5262306a36Sopenharmony_cias-version := $(shell,set -- $(as-info) && echo $2)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci# Get the linker name, version, and error out if it is not supported.
5562306a36Sopenharmony_cild-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
5662306a36Sopenharmony_ci$(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
5762306a36Sopenharmony_cild-name := $(shell,set -- $(ld-info) && echo $1)
5862306a36Sopenharmony_cild-version := $(shell,set -- $(ld-info) && echo $2)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci# machine bit flags
6162306a36Sopenharmony_ci#  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
6262306a36Sopenharmony_ci#  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
6362306a36Sopenharmony_cicc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
6462306a36Sopenharmony_cim32-flag := $(cc-option-bit,-m32)
6562306a36Sopenharmony_cim64-flag := $(cc-option-bit,-m64)
66