Thomas Gleixner | ec8f24b | 2019-05-19 13:07:45 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Masahiro Yamada | e1cfdc0 | 2018-05-28 18:21:59 +0900 | [diff] [blame] | 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 | |
Masahiro Yamada | 902a689 | 2019-05-09 16:35:55 +0900 | [diff] [blame] | 22 | # $(failure,<command>) |
| 23 | # Return n if <command> exits with 0, y otherwise |
| 24 | failure = $(if-success,$(1),n,y) |
| 25 | |
Masahiro Yamada | e1cfdc0 | 2018-05-28 18:21:59 +0900 | [diff] [blame] | 26 | # $(cc-option,<flag>) |
| 27 | # Return y if the compiler supports <flag>, n otherwise |
Masahiro Yamada | 4d0831e | 2020-06-14 23:43:41 +0900 | [diff] [blame] | 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) |
Masahiro Yamada | e1cfdc0 | 2018-05-28 18:21:59 +0900 | [diff] [blame] | 29 | |
| 30 | # $(ld-option,<flag>) |
| 31 | # Return y if the linker supports <flag>, n otherwise |
| 32 | ld-option = $(success,$(LD) -v $(1)) |
Masahiro Yamada | 59f5385 | 2018-05-28 18:22:06 +0900 | [diff] [blame] | 33 | |
Catalin Marinas | 42d519e | 2020-01-15 11:30:07 +0000 | [diff] [blame] | 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 | |
Masahiro Yamada | 902a689 | 2019-05-09 16:35:55 +0900 | [diff] [blame] | 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 | |
Thomas Gleixner | 75959d4 | 2019-07-16 21:47:27 +0200 | [diff] [blame] | 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 | |
Masahiro Yamada | 8cc4fd7 | 2020-03-10 19:12:49 +0900 | [diff] [blame] | 45 | # machine bit flags |
| 46 | # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. |
| 47 | # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise. |
| 48 | cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) |
| 49 | m32-flag := $(cc-option-bit,-m32) |
| 50 | m64-flag := $(cc-option-bit,-m64) |