.. | .. |
---|
| 1 | +# SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | # Kconfig helper macros |
---|
2 | 3 | |
---|
3 | 4 | # Convenient variables |
---|
.. | .. |
---|
18 | 19 | # Return y if <command> exits with 0, n otherwise |
---|
19 | 20 | success = $(if-success,$(1),y,n) |
---|
20 | 21 | |
---|
| 22 | +# $(failure,<command>) |
---|
| 23 | +# Return n if <command> exits with 0, y otherwise |
---|
| 24 | +failure = $(if-success,$(1),n,y) |
---|
| 25 | + |
---|
21 | 26 | # $(cc-option,<flag>) |
---|
22 | 27 | # Return y if the compiler supports <flag>, n otherwise |
---|
23 | | -cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null) |
---|
| 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) |
---|
24 | 29 | |
---|
25 | 30 | # $(ld-option,<flag>) |
---|
26 | 31 | # Return y if the linker supports <flag>, n otherwise |
---|
27 | 32 | ld-option = $(success,$(LD) -v $(1)) |
---|
28 | 33 | |
---|
29 | | -# gcc version including patch level |
---|
30 | | -gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') |
---|
| 34 | +# $(as-instr,<instr>) |
---|
| 35 | +# Return y if the assembler supports <instr>, n otherwise |
---|
| 36 | +as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -) |
---|
| 37 | + |
---|
| 38 | +# check if $(CC) and $(LD) exist |
---|
| 39 | +$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found) |
---|
| 40 | +$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) |
---|
| 41 | + |
---|
| 42 | +# Fail if the linker is gold as it's not capable of linking the kernel proper |
---|
| 43 | +$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported) |
---|
| 44 | + |
---|
| 45 | +# Get the assembler name, version, and error out if it is not supported. |
---|
| 46 | +as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS)) |
---|
| 47 | +$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.) |
---|
| 48 | +as-name := $(shell,set -- $(as-info) && echo $1) |
---|
| 49 | +as-version := $(shell,set -- $(as-info) && echo $2) |
---|
| 50 | + |
---|
| 51 | +# machine bit flags |
---|
| 52 | +# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. |
---|
| 53 | +# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. |
---|
| 54 | +cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) |
---|
| 55 | +m32-flag := $(cc-option-bit,-m32) |
---|
| 56 | +m64-flag := $(cc-option-bit,-m64) |
---|