xref: /linux/scripts/gcc-plugins/Makefile (revision ce6ed1c4c9876c2880f52f18c41ef2a30d070bc5)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
26b90bd4bSEmese Revfy
342640b13SMasahiro Yamada$(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h
4313dd1b6SKees Cookquiet_cmd_create_randomize_layout_seed = GENSEED $@
5313dd1b6SKees Cookcmd_create_randomize_layout_seed = \
6313dd1b6SKees Cook  $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
7313dd1b6SKees Cook$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
8313dd1b6SKees Cook	$(call if_changed,create_randomize_layout_seed)
942640b13SMasahiro Yamadatargets += randomize_layout_seed.h randomize_layout_hash.h
10313dd1b6SKees Cook
1142640b13SMasahiro Yamada# Build rules for plugins
1242640b13SMasahiro Yamada#
1342640b13SMasahiro Yamada# No extra code is needed for single-file plugins.
1442640b13SMasahiro Yamada# For multi-file plugins, use *-objs syntax to list the objects.
1542640b13SMasahiro Yamada#
1642640b13SMasahiro Yamada# If the plugin foo.so is compiled from foo.c and foo2.c, you can do:
1742640b13SMasahiro Yamada#
1842640b13SMasahiro Yamada# foo-objs := foo.o foo2.o
196b90bd4bSEmese Revfy
2042640b13SMasahiro Yamadaalways-y += $(GCC_PLUGIN)
21543c37cbSEmese Revfy
2242640b13SMasahiro YamadaGCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin)
2342640b13SMasahiro Yamada
2442640b13SMasahiro Yamadaplugin_cxxflags	= -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \
25*ce6ed1c4SMasahiro Yamada		  -include $(srctree)/include/linux/compiler-version.h \
2667a5a680SValdis Klētnieks		   -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \
2742640b13SMasahiro Yamada		   -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
2867a5a680SValdis Klētnieks		   -ggdb -Wno-narrowing -Wno-unused-variable \
2942640b13SMasahiro Yamada		   -Wno-format-diag
3042640b13SMasahiro Yamada
3142640b13SMasahiro Yamadaplugin_ldflags	= -shared
3242640b13SMasahiro Yamada
3342640b13SMasahiro Yamadaplugin-single	:= $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m)))
3442640b13SMasahiro Yamadaplugin-multi	:= $(filter-out $(plugin-single), $(GCC_PLUGIN))
3542640b13SMasahiro Yamadaplugin-objs	:= $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs))))
3642640b13SMasahiro Yamada
3742640b13SMasahiro Yamadatargets += $(plugin-single) $(plugin-multi) $(plugin-objs)
386b90bd4bSEmese Revfyclean-files += *.so
3942640b13SMasahiro Yamada
4042640b13SMasahiro Yamadaplugin-single	:= $(addprefix $(obj)/, $(plugin-single))
4142640b13SMasahiro Yamadaplugin-multi	:= $(addprefix $(obj)/, $(plugin-multi))
4242640b13SMasahiro Yamadaplugin-objs	:= $(addprefix $(obj)/, $(plugin-objs))
4342640b13SMasahiro Yamada
4442640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_so_c = HOSTCXX $@
4542640b13SMasahiro Yamada      cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $<
4642640b13SMasahiro Yamada
4742640b13SMasahiro Yamada$(plugin-single): $(obj)/%.so: $(src)/%.c FORCE
4842640b13SMasahiro Yamada	$(call if_changed_dep,plugin_cxx_so_c)
4942640b13SMasahiro Yamada
5042640b13SMasahiro Yamadaquiet_cmd_plugin_ld_so_o = HOSTLD  $@
5142640b13SMasahiro Yamada      cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \
5242640b13SMasahiro Yamada			   $(addprefix $(obj)/, $($(target-stem)-objs))
5342640b13SMasahiro Yamada
5442640b13SMasahiro Yamada$(plugin-multi): FORCE
5542640b13SMasahiro Yamada	$(call if_changed,plugin_ld_so_o)
5642640b13SMasahiro Yamada$(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs)))))
5742640b13SMasahiro Yamada
5842640b13SMasahiro Yamadaquiet_cmd_plugin_cxx_o_c = HOSTCXX $@
5942640b13SMasahiro Yamada      cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $<
6042640b13SMasahiro Yamada
6142640b13SMasahiro Yamada$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
6242640b13SMasahiro Yamada	$(call if_changed_dep,plugin_cxx_o_c)
63