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