1 # SPDX-License-Identifier: GPL-2.0-only 1 # SPDX-License-Identifier: GPL-2.0-only 2 # Kconfig helper macros 2 # Kconfig helper macros 3 3 4 # Convenient variables 4 # Convenient variables 5 comma := , 5 comma := , 6 quote := " 6 quote := " 7 squote := ' 7 squote := ' 8 empty := 8 empty := 9 space := $(empty) $(empty) 9 space := $(empty) $(empty) 10 dollar := $ 10 dollar := $ 11 right_paren := ) 11 right_paren := ) 12 left_paren := ( 12 left_paren := ( 13 13 14 # $(if-success,<command>,<then>,<else>) 14 # $(if-success,<command>,<then>,<else>) 15 # Return <then> if <command> exits with 0, <el 15 # Return <then> if <command> exits with 0, <else> otherwise. 16 if-success = $(shell,{ $(1); } >/dev/null 2>&1 16 if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") 17 17 18 # $(success,<command>) 18 # $(success,<command>) 19 # Return y if <command> exits with 0, n otherw 19 # Return y if <command> exits with 0, n otherwise 20 success = $(if-success,$(1),y,n) 20 success = $(if-success,$(1),y,n) 21 21 22 # $(failure,<command>) 22 # $(failure,<command>) 23 # Return n if <command> exits with 0, y otherw 23 # Return n if <command> exits with 0, y otherwise 24 failure = $(if-success,$(1),n,y) 24 failure = $(if-success,$(1),n,y) 25 25 26 # $(cc-option,<flag>) 26 # $(cc-option,<flag>) 27 # Return y if the compiler supports <flag>, n 27 # Return y if the compiler supports <flag>, n otherwise 28 cc-option = $(success,trap "rm -rf .tmp_$$" EX !! 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) 29 29 30 # $(ld-option,<flag>) 30 # $(ld-option,<flag>) 31 # Return y if the linker supports <flag>, n ot 31 # Return y if the linker supports <flag>, n otherwise 32 ld-option = $(success,$(LD) -v $(1)) 32 ld-option = $(success,$(LD) -v $(1)) 33 33 34 # $(as-instr,<instr>) 34 # $(as-instr,<instr>) 35 # Return y if the assembler supports <instr>, 35 # Return y if the assembler supports <instr>, n otherwise 36 as-instr = $(success,printf "%b\n" "$(1)" | $( !! 36 as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -) 37 as-instr64 = $(as-instr,$(1),$(m64-flag)) << 38 37 39 # check if $(CC) and $(LD) exist 38 # check if $(CC) and $(LD) exist 40 $(error-if,$(failure,command -v $(CC)),C compi !! 39 $(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found) 41 $(error-if,$(failure,command -v $(LD)),linker 40 $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) 42 41 43 # Get the C compiler name, version, and error !! 42 # Fail if the linker is gold as it's not capable of linking the kernel proper 44 cc-info := $(shell,$(srctree)/scripts/cc-versi !! 43 $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported) 45 $(error-if,$(success,test -z "$(cc-info)"),Sor << 46 cc-name := $(shell,set -- $(cc-info) && echo $ << 47 cc-version := $(shell,set -- $(cc-info) && ech << 48 << 49 # Get the assembler name, version, and error o << 50 as-info := $(shell,$(srctree)/scripts/as-versi << 51 $(error-if,$(success,test -z "$(as-info)"),Sor << 52 as-name := $(shell,set -- $(as-info) && echo $ << 53 as-version := $(shell,set -- $(as-info) && ech << 54 << 55 # Get the linker name, version, and error out << 56 ld-info := $(shell,$(srctree)/scripts/ld-versi << 57 $(error-if,$(success,test -z "$(ld-info)"),Sor << 58 ld-name := $(shell,set -- $(ld-info) && echo $ << 59 ld-version := $(shell,set -- $(ld-info) && ech << 60 44 61 # machine bit flags 45 # machine bit flags 62 # $(m32-flag): -m32 if the compiler supports 46 # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. 63 # $(m64-flag): -m64 if the compiler supports 47 # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. 64 cc-option-bit = $(if-success,$(CC) -Werror $(1 48 cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) 65 m32-flag := $(cc-option-bit,-m32) 49 m32-flag := $(cc-option-bit,-m32) 66 m64-flag := $(cc-option-bit,-m64) 50 m64-flag := $(cc-option-bit,-m64)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.