xref: /linux/scripts/Makefile.gcc-plugins (revision ed58c0e9eefef517aa5a547b78658e2ab4422232)
16b90bd4bSEmese Revfyifdef CONFIG_GCC_PLUGINS
26b90bd4bSEmese Revfy  __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC))
36b90bd4bSEmese Revfy  PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)")
46b90bd4bSEmese Revfy
5543c37cbSEmese Revfy  SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
6543c37cbSEmese Revfy
70dae776cSEmese Revfy  gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY)	+= cyc_complexity_plugin.so
8543c37cbSEmese Revfy
9543c37cbSEmese Revfy  ifdef CONFIG_GCC_PLUGIN_SANCOV
10543c37cbSEmese Revfy    ifeq ($(CFLAGS_KCOV),)
11543c37cbSEmese Revfy      # It is needed because of the gcc-plugin.sh and gcc version checks.
12543c37cbSEmese Revfy      gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV)           += sancov_plugin.so
13543c37cbSEmese Revfy
14543c37cbSEmese Revfy      ifneq ($(PLUGINCC),)
15543c37cbSEmese Revfy        CFLAGS_KCOV := $(SANCOV_PLUGIN)
16543c37cbSEmese Revfy      else
17543c37cbSEmese Revfy        $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler)
18543c37cbSEmese Revfy      endif
19543c37cbSEmese Revfy    endif
20543c37cbSEmese Revfy  endif
21543c37cbSEmese Revfy
226b90bd4bSEmese Revfy  GCC_PLUGINS_CFLAGS := $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y))
236b90bd4bSEmese Revfy
24543c37cbSEmese Revfy  export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN SANCOV_PLUGIN
256b90bd4bSEmese Revfy
26*ed58c0e9SKees Cook  ifneq ($(PLUGINCC),)
27543c37cbSEmese Revfy    # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication.
28543c37cbSEmese Revfy    GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS))
296b90bd4bSEmese Revfy  endif
306b90bd4bSEmese Revfy
316b90bd4bSEmese Revfy  KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
326b90bd4bSEmese Revfy  GCC_PLUGIN := $(gcc-plugin-y)
336b90bd4bSEmese Revfyendif
34*ed58c0e9SKees Cook
35*ed58c0e9SKees Cook# If plugins aren't supported, abort the build before hard-to-read compiler
36*ed58c0e9SKees Cook# errors start getting spewed by the main build.
37*ed58c0e9SKees CookPHONY += gcc-plugins-check
38*ed58c0e9SKees Cookgcc-plugins-check: FORCE
39*ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS
40*ed58c0e9SKees Cook  ifeq ($(PLUGINCC),)
41*ed58c0e9SKees Cook    ifneq ($(GCC_PLUGINS_CFLAGS),)
42*ed58c0e9SKees Cook      ifeq ($(call cc-ifversion, -ge, 0405, y), y)
43*ed58c0e9SKees Cook	$(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true
44*ed58c0e9SKees Cook	@echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1
45*ed58c0e9SKees Cook      else
46*ed58c0e9SKees Cook	@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
47*ed58c0e9SKees Cook      endif
48*ed58c0e9SKees Cook    endif
49*ed58c0e9SKees Cook  endif
50*ed58c0e9SKees Cookendif
51*ed58c0e9SKees Cook	@:
52*ed58c0e9SKees Cook
53*ed58c0e9SKees Cook# Actually do the build, if requested.
54*ed58c0e9SKees CookPHONY += gcc-plugins
55*ed58c0e9SKees Cookgcc-plugins: scripts_basic gcc-plugins-check
56*ed58c0e9SKees Cookifdef CONFIG_GCC_PLUGINS
57*ed58c0e9SKees Cook	$(Q)$(MAKE) $(build)=scripts/gcc-plugins
58*ed58c0e9SKees Cookendif
59*ed58c0e9SKees Cook	@:
60