ec8f24b7faaf3 (Thomas Gleixner 2019-05-19 13:07:45 +0100 1) # SPDX-License-Identifier: GPL-2.0-only
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 2) # Kconfig helper macros
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 3)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 4) # Convenient variables
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 5) comma := ,
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 6) quote := "
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 7) squote := '
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 8) empty :=
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 9) space := $(empty) $(empty)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 10) dollar := $
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 11) right_paren := )
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 12) left_paren := (
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 13)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 14) # $(if-success,<command>,<then>,<else>)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 15) # Return <then> if <command> exits with 0, <else> otherwise.
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 16) if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 17)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 18) # $(success,<command>)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 19) # Return y if <command> exits with 0, n otherwise
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 20) success = $(if-success,$(1),y,n)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 21)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 22) # $(failure,<command>)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 23) # Return n if <command> exits with 0, y otherwise
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 24) failure = $(if-success,$(1),n,y)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 25)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 26) # $(cc-option,<flag>)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 27) # Return y if the compiler supports <flag>, n otherwise
4d0831e8a029c (Masahiro Yamada 2020-06-14 23:43:41 +0900 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)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 29)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 30) # $(ld-option,<flag>)
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 31) # Return y if the linker supports <flag>, n otherwise
e1cfdc0e72fc9 (Masahiro Yamada 2018-05-28 18:21:59 +0900 32) ld-option = $(success,$(LD) -v $(1))
59f53855babf7 (Masahiro Yamada 2018-05-28 18:22:06 +0900 33)
42d519e3d0c07 (Catalin Marinas 2020-01-15 11:30:07 +0000 34) # $(as-instr,<instr>)
42d519e3d0c07 (Catalin Marinas 2020-01-15 11:30:07 +0000 35) # Return y if the assembler supports <instr>, n otherwise
42d519e3d0c07 (Catalin Marinas 2020-01-15 11:30:07 +0000 36) as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
42d519e3d0c07 (Catalin Marinas 2020-01-15 11:30:07 +0000 37)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 38) # check if $(CC) and $(LD) exist
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 39) $(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 40) $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
902a6898bfb48 (Masahiro Yamada 2019-05-09 16:35:55 +0900 41)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 42) # Get the compiler name, version, and error out if it is not supported.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 43) cc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 44) $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not supported.)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 45) cc-name := $(shell,set -- $(cc-info) && echo $1)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 46) cc-version := $(shell,set -- $(cc-info) && echo $2)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 47)
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 48) # Get the assembler name, version, and error out if it is not supported.
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 49) as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 50) $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 51) as-name := $(shell,set -- $(as-info) && echo $1)
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 52) as-version := $(shell,set -- $(as-info) && echo $2)
ba64beb17493a (Masahiro Yamada 2021-03-16 01:12:56 +0900 53)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 54) # Get the linker name, version, and error out if it is not supported.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 55) ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 56) $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 57) ld-name := $(shell,set -- $(ld-info) && echo $1)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 58) ld-version := $(shell,set -- $(ld-info) && echo $2)
75959d44f9dc8 (Thomas Gleixner 2019-07-16 21:47:27 +0200 59)
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 60) # machine bit flags
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 61) # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 62) # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 63) cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 64) m32-flag := $(cc-option-bit,-m32)
8cc4fd73501d9 (Masahiro Yamada 2020-03-10 19:12:49 +0900 65) m64-flag := $(cc-option-bit,-m64)