Kconfig.include 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. # Fail if the linker is gold as it's not capable of linking the kernel proper
  34. $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
  35. # machine bit flags
  36. # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
  37. # $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
  38. cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
  39. m32-flag := $(cc-option-bit,-m32)
  40. m64-flag := $(cc-option-bit,-m64)