Makefile.gcc-plugins 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ifdef CONFIG_GCC_PLUGINS
  2. __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
  3. PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
  4. SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
  5. gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
  6. ifdef CONFIG_GCC_PLUGIN_SANCOV
  7. ifeq ($(CFLAGS_KCOV),)
  8. # It is needed because of the gcc-plugin.sh and gcc version checks.
  9. gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
  10. ifneq ($(PLUGINCC),)
  11. CFLAGS_KCOV := $(SANCOV_PLUGIN)
  12. else
  13. $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler)
  14. endif
  15. endif
  16. endif
  17. GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
  18. export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR SANCOV_PLUGIN
  19. ifneq ($(PLUGINCC),)
  20. # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
  21. GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
  22. endif
  23. KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
  24. GCC_PLUGIN := $(gcc-plugin-y)
  25. GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y)
  26. endif
  27. # If plugins aren't supported, abort the build before hard-to-read compiler
  28. # errors start getting spewed by the main build.
  29. PHONY += gcc-plugins-check
  30. gcc-plugins-check: FORCE
  31. ifdef CONFIG_GCC_PLUGINS
  32. ifeq ($(PLUGINCC),)
  33. ifneq ($(GCC_PLUGINS_CFLAGS),)
  34. ifeq ($(call cc-ifversion, -ge, 0405, y), y)
  35. $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true
  36. @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
  37. else
  38. @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc version does not support plugins, you should upgrade it to at least gcc 4.5" >&2 && exit 1
  39. endif
  40. endif
  41. endif
  42. endif
  43. @:
  44. # Actually do the build, if requested.
  45. PHONY += gcc-plugins
  46. gcc-plugins: scripts_basic gcc-plugins-check
  47. ifdef CONFIG_GCC_PLUGINS
  48. $(Q)$(MAKE) $(build)=scripts/gcc-plugins
  49. endif
  50. @: