Kconfig.include 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(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) $(2) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
  30. as-instr64 = $(as-instr,$(1),$(m64-flag))
  31. # check if $(CC) and $(LD) exist
  32. $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
  33. $(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
  34. # Get the C compiler name, version, and error out if it is not supported.
  35. cc-info := $(shell,$(srctree)/scripts/cc-version.sh $(CC))
  36. $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this C compiler is not supported.)
  37. cc-name := $(shell,set -- $(cc-info) && echo $1)
  38. cc-version := $(shell,set -- $(cc-info) && echo $2)
  39. # Get the assembler name, version, and error out if it is not supported.
  40. as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
  41. $(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
  42. as-name := $(shell,set -- $(as-info) && echo $1)
  43. as-version := $(shell,set -- $(as-info) && echo $2)
  44. # Get the linker name, version, and error out if it is not supported.
  45. ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD))
  46. $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.)
  47. ld-name := $(shell,set -- $(ld-info) && echo $1)
  48. ld-version := $(shell,set -- $(ld-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)
  55. # Test whether the compiler can link userspace applications
  56. cc_can_link_user = $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(1))
  57. rustc-version := $(shell,$(srctree)/scripts/rustc-version.sh $(RUSTC))
  58. rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
  59. # $(rustc-option,<flag>)
  60. # Return y if the Rust compiler supports <flag>, n otherwise
  61. # If you are testing for unstable features, consider testing RUSTC_VERSION
  62. # instead, as features may have different completeness while available.
  63. rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null --out-dir=.tmp_$$ -o .tmp_$$/tmp.rlib)