18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci$(obj)/randomize_layout_plugin.so: $(objtree)/$(obj)/randomize_layout_seed.h
48c2ecf20Sopenharmony_ciquiet_cmd_create_randomize_layout_seed = GENSEED $@
58c2ecf20Sopenharmony_cicmd_create_randomize_layout_seed = \
68c2ecf20Sopenharmony_ci  $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
78c2ecf20Sopenharmony_ci$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
88c2ecf20Sopenharmony_ci	$(call if_changed,create_randomize_layout_seed)
98c2ecf20Sopenharmony_citargets += randomize_layout_seed.h randomize_layout_hash.h
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# Build rules for plugins
128c2ecf20Sopenharmony_ci#
138c2ecf20Sopenharmony_ci# No extra code is needed for single-file plugins.
148c2ecf20Sopenharmony_ci# For multi-file plugins, use *-objs syntax to list the objects.
158c2ecf20Sopenharmony_ci#
168c2ecf20Sopenharmony_ci# If the plugin foo.so is compiled from foo.c and foo2.c, you can do:
178c2ecf20Sopenharmony_ci#
188c2ecf20Sopenharmony_ci# foo-objs := foo.o foo2.o
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cialways-y += $(GCC_PLUGIN)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciGCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciplugin_cxxflags	= -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \
258c2ecf20Sopenharmony_ci		   -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \
268c2ecf20Sopenharmony_ci		   -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
278c2ecf20Sopenharmony_ci		   -ggdb -Wno-narrowing -Wno-unused-variable \
288c2ecf20Sopenharmony_ci		   -Wno-format-diag
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciplugin_ldflags	= -shared
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciplugin-single	:= $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m)))
338c2ecf20Sopenharmony_ciplugin-multi	:= $(filter-out $(plugin-single), $(GCC_PLUGIN))
348c2ecf20Sopenharmony_ciplugin-objs	:= $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs))))
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_citargets += $(plugin-single) $(plugin-multi) $(plugin-objs)
378c2ecf20Sopenharmony_ciclean-files += *.so
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciplugin-single	:= $(addprefix $(obj)/, $(plugin-single))
408c2ecf20Sopenharmony_ciplugin-multi	:= $(addprefix $(obj)/, $(plugin-multi))
418c2ecf20Sopenharmony_ciplugin-objs	:= $(addprefix $(obj)/, $(plugin-objs))
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciquiet_cmd_plugin_cxx_so_c = HOSTCXX $@
448c2ecf20Sopenharmony_ci      cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $<
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci$(plugin-single): $(obj)/%.so: $(src)/%.c FORCE
478c2ecf20Sopenharmony_ci	$(call if_changed_dep,plugin_cxx_so_c)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciquiet_cmd_plugin_ld_so_o = HOSTLD  $@
508c2ecf20Sopenharmony_ci      cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \
518c2ecf20Sopenharmony_ci			   $(addprefix $(obj)/, $($(target-stem)-objs))
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci$(plugin-multi): FORCE
548c2ecf20Sopenharmony_ci	$(call if_changed,plugin_ld_so_o)
558c2ecf20Sopenharmony_ci$(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs)))))
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciquiet_cmd_plugin_cxx_o_c = HOSTCXX $@
588c2ecf20Sopenharmony_ci      cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $<
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci$(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
618c2ecf20Sopenharmony_ci	$(call if_changed_dep,plugin_cxx_o_c)
62