0001 # SPDX-License-Identifier: GPL-2.0-only
0002 # Kconfig helper macros
0003
0004 # Convenient variables
0005 comma := ,
0006 quote := "
0007 squote := '
0008 empty :=
0009 space := $(empty) $(empty)
0010 dollar := $
0011 right_paren := )
0012 left_paren := (
0013
0014 # $(if-success,<command>,<then>,<else>)
0015 # Return <then> if <command> exits with 0, <else> otherwise.
0016 if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
0017
0018 # $(success,<command>)
0019 # Return y if <command> exits with 0, n otherwise
0020 success = $(if-success,$(1),y,n)
0021
0022 # $(failure,<command>)
0023 # Return n if <command> exits with 0, y otherwise
0024 failure = $(if-success,$(1),n,y)
0025
0026 # $(cc-option,<flag>)
0027 # Return y if the compiler supports <flag>, n otherwise
0028 cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
0029
0030 # $(ld-option,<flag>)
0031 # Return y if the linker supports <flag>, n otherwise
0032 ld-option = $(success,$(LD) -v $(1))
0033
0034 # $(as-instr,<instr>)
0035 # Return y if the assembler supports <instr>, n otherwise
0036 as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
0037
0038 # check if $(CC) and $(LD) exist
0039 $(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
0040 $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
0041
0042 # Get the compiler name, version, and error out if it is not supported.
0043 cc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
0044 $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not supported.)
0045 cc-name := $(shell,set -- $(cc-info) && echo $1)
0046 cc-version := $(shell,set -- $(cc-info) && echo $2)
0047
0048 # Get the assembler name, version, and error out if it is not supported.
0049 as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
0050 $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
0051 as-name := $(shell,set -- $(as-info) && echo $1)
0052 as-version := $(shell,set -- $(as-info) && echo $2)
0053
0054 # Get the linker name, version, and error out if it is not supported.
0055 ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
0056 $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
0057 ld-name := $(shell,set -- $(ld-info) && echo $1)
0058 ld-version := $(shell,set -- $(ld-info) && echo $2)
0059
0060 # machine bit flags
0061 # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
0062 # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
0063 cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
0064 m32-flag := $(cc-option-bit,-m32)
0065 m64-flag := $(cc-option-bit,-m64)