Commit | Line | Data |
---|---|---|
ec8f24b7 | 1 | # SPDX-License-Identifier: GPL-2.0-only |
e1cfdc0e MY |
2 | # Kconfig helper macros |
3 | ||
4 | # Convenient variables | |
5 | comma := , | |
6 | quote := " | |
7 | squote := ' | |
8 | empty := | |
9 | space := $(empty) $(empty) | |
10 | dollar := $ | |
11 | right_paren := ) | |
12 | left_paren := ( | |
13 | ||
14 | # $(if-success,<command>,<then>,<else>) | |
15 | # Return <then> if <command> exits with 0, <else> otherwise. | |
16 | if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") | |
17 | ||
18 | # $(success,<command>) | |
19 | # Return y if <command> exits with 0, n otherwise | |
20 | success = $(if-success,$(1),y,n) | |
21 | ||
902a6898 MY |
22 | # $(failure,<command>) |
23 | # Return n if <command> exits with 0, y otherwise | |
24 | failure = $(if-success,$(1),n,y) | |
25 | ||
e1cfdc0e MY |
26 | # $(cc-option,<flag>) |
27 | # Return y if the compiler supports <flag>, n otherwise | |
dd298656 | 28 | cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o) |
e1cfdc0e MY |
29 | |
30 | # $(ld-option,<flag>) | |
31 | # Return y if the linker supports <flag>, n otherwise | |
32 | ld-option = $(success,$(LD) -v $(1)) | |
59f53855 | 33 | |
42d519e3 CM |
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 | ||
902a6898 | 38 | # check if $(CC) and $(LD) exist |
2f7ab126 | 39 | $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found) |
902a6898 MY |
40 | $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) |
41 | ||
2f7ab126 | 42 | # Get the C compiler name, version, and error out if it is not supported. |
aec6c60a | 43 | cc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC)) |
2f7ab126 | 44 | $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not supported.) |
aec6c60a MY |
45 | cc-name := $(shell,set -- $(cc-info) && echo $1) |
46 | cc-version := $(shell,set -- $(cc-info) && echo $2) | |
47 | ||
ba64beb1 MY |
48 | # Get the assembler name, version, and error out if it is not supported. |
49 | as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS)) | |
50 | $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.) | |
51 | as-name := $(shell,set -- $(as-info) && echo $1) | |
52 | as-version := $(shell,set -- $(as-info) && echo $2) | |
53 | ||
02aff859 MY |
54 | # Get the linker name, version, and error out if it is not supported. |
55 | ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD)) | |
56 | $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.) | |
57 | ld-name := $(shell,set -- $(ld-info) && echo $1) | |
58 | ld-version := $(shell,set -- $(ld-info) && echo $2) | |
75959d44 | 59 | |
8cc4fd73 MY |
60 | # machine bit flags |
61 | # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. | |
62 | # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. | |
63 | cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) | |
64 | m32-flag := $(cc-option-bit,-m32) | |
65 | m64-flag := $(cc-option-bit,-m64) |