18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci# Kconfig helper macros
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci# Convenient variables
58c2ecf20Sopenharmony_cicomma       := ,
68c2ecf20Sopenharmony_ciquote       := "
78c2ecf20Sopenharmony_cisquote      := '
88c2ecf20Sopenharmony_ciempty       :=
98c2ecf20Sopenharmony_cispace       := $(empty) $(empty)
108c2ecf20Sopenharmony_cidollar      := $
118c2ecf20Sopenharmony_ciright_paren := )
128c2ecf20Sopenharmony_cileft_paren  := (
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci# $(if-success,<command>,<then>,<else>)
158c2ecf20Sopenharmony_ci# Return <then> if <command> exits with 0, <else> otherwise.
168c2ecf20Sopenharmony_ciif-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci# $(success,<command>)
198c2ecf20Sopenharmony_ci# Return y if <command> exits with 0, n otherwise
208c2ecf20Sopenharmony_cisuccess = $(if-success,$(1),y,n)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci# $(failure,<command>)
238c2ecf20Sopenharmony_ci# Return n if <command> exits with 0, y otherwise
248c2ecf20Sopenharmony_cifailure = $(if-success,$(1),n,y)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci# $(cc-option,<flag>)
278c2ecf20Sopenharmony_ci# Return y if the compiler supports <flag>, n otherwise
288c2ecf20Sopenharmony_cicc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci# $(ld-option,<flag>)
318c2ecf20Sopenharmony_ci# Return y if the linker supports <flag>, n otherwise
328c2ecf20Sopenharmony_cild-option = $(success,$(LD) -v $(1))
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci# $(as-instr,<instr>)
358c2ecf20Sopenharmony_ci# Return y if the assembler supports <instr>, n otherwise
368c2ecf20Sopenharmony_cias-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci# check if $(CC) and $(LD) exist
398c2ecf20Sopenharmony_ci$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
408c2ecf20Sopenharmony_ci$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci# Fail if the linker is gold as it's not capable of linking the kernel proper
438c2ecf20Sopenharmony_ci$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci# Get the assembler name, version, and error out if it is not supported.
468c2ecf20Sopenharmony_cias-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
478c2ecf20Sopenharmony_ci$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
488c2ecf20Sopenharmony_cias-name := $(shell,set -- $(as-info) && echo $1)
498c2ecf20Sopenharmony_cias-version := $(shell,set -- $(as-info) && echo $2)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci# machine bit flags
528c2ecf20Sopenharmony_ci#  $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
538c2ecf20Sopenharmony_ci#  $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
548c2ecf20Sopenharmony_cicc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
558c2ecf20Sopenharmony_cim32-flag := $(cc-option-bit,-m32)
568c2ecf20Sopenharmony_cim64-flag := $(cc-option-bit,-m64)
57