1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only 2*4882a593Smuzhiyun# Kconfig helper macros 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun# Convenient variables 5*4882a593Smuzhiyuncomma := , 6*4882a593Smuzhiyunquote := " 7*4882a593Smuzhiyunsquote := ' 8*4882a593Smuzhiyunempty := 9*4882a593Smuzhiyunspace := $(empty) $(empty) 10*4882a593Smuzhiyundollar := $ 11*4882a593Smuzhiyunright_paren := ) 12*4882a593Smuzhiyunleft_paren := ( 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun# $(if-success,<command>,<then>,<else>) 15*4882a593Smuzhiyun# Return <then> if <command> exits with 0, <else> otherwise. 16*4882a593Smuzhiyunif-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun# $(success,<command>) 19*4882a593Smuzhiyun# Return y if <command> exits with 0, n otherwise 20*4882a593Smuzhiyunsuccess = $(if-success,$(1),y,n) 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun# $(failure,<command>) 23*4882a593Smuzhiyun# Return n if <command> exits with 0, y otherwise 24*4882a593Smuzhiyunfailure = $(if-success,$(1),n,y) 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun# $(cc-option,<flag>) 27*4882a593Smuzhiyun# Return y if the compiler supports <flag>, n otherwise 28*4882a593Smuzhiyuncc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o) 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun# $(ld-option,<flag>) 31*4882a593Smuzhiyun# Return y if the linker supports <flag>, n otherwise 32*4882a593Smuzhiyunld-option = $(success,$(LD) -v $(1)) 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun# $(as-instr,<instr>) 35*4882a593Smuzhiyun# Return y if the assembler supports <instr>, n otherwise 36*4882a593Smuzhiyunas-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -) 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun# check if $(CC) and $(LD) exist 39*4882a593Smuzhiyun$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found) 40*4882a593Smuzhiyun$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun# Fail if the linker is gold as it's not capable of linking the kernel proper 43*4882a593Smuzhiyun$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported) 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun# machine bit flags 46*4882a593Smuzhiyun# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. 47*4882a593Smuzhiyun# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. 48*4882a593Smuzhiyuncc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) 49*4882a593Smuzhiyunm32-flag := $(cc-option-bit,-m32) 50*4882a593Smuzhiyunm64-flag := $(cc-option-bit,-m64) 51