Kconfig.include 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # Kconfig helper macros
  3. # Convenient variables
  4. comma := ,
  5. quote := "
  6. squote := '
  7. empty :=
  8. space := $(empty) $(empty)
  9. dollar := $
  10. right_paren := )
  11. left_paren := (
  12. # $(if-success,<command>,<then>,<else>)
  13. # Return <then> if <command> exits with 0, <else> otherwise.
  14. if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
  15. # $(success,<command>)
  16. # Return y if <command> exits with 0, n otherwise
  17. success = $(if-success,$(1),y,n)
  18. # $(failure,<command>)
  19. # Return n if <command> exits with 0, y otherwise
  20. failure = $(if-success,$(1),n,y)
  21. # $(cc-option,<flag>)
  22. # Return y if the compiler supports <flag>, n otherwise
  23. 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. # $(ld-option,<flag>)
  25. # Return y if the linker supports <flag>, n otherwise
  26. ld-option = $(success,$(LD) -v $(1))
  27. # $(as-instr,<instr>)
  28. # Return y if the assembler supports <instr>, n otherwise
  29. as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
  30. # check if $(CC) and $(LD) exist
  31. $(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
  32. $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
  33. # Get the compiler name, version, and error out if it is not supported.
  34. cc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
  35. $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not supported.)
  36. cc-name := $(shell,set -- $(cc-info) && echo $1)
  37. cc-version := $(shell,set -- $(cc-info) && echo $2)
  38. # Get the linker name, version, and error out if it is not supported.
  39. ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
  40. $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
  41. ld-name := $(shell,set -- $(ld-info) && echo $1)
  42. ld-version := $(shell,set -- $(ld-info) && echo $2)
  43. # Get the assembler name, version, and error out if it is not supported.
  44. # cc-wrapper may not yet be compiled, use NO_WRAPPER_CC.
  45. as-info := $(shell,$(srctree)/scripts/as-version.sh $(NO_WRAPPER_CC) $(CLANG_FLAGS))
  46. $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
  47. as-name := $(shell,set -- $(as-info) && echo $1)
  48. as-version := $(shell,set -- $(as-info) && echo $2)
  49. # machine bit flags
  50. # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
  51. # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
  52. cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
  53. m32-flag := $(cc-option-bit,-m32)
  54. m64-flag := $(cc-option-bit,-m64)