Makefile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # SPDX-License-Identifier: GPL-2.0
  2. $(obj)/randomize_layout_plugin.so: $(obj)/randomize_layout_seed.h
  3. quiet_cmd_create_randomize_layout_seed = SEEDHDR $@
  4. cmd_create_randomize_layout_seed = \
  5. SEED=$$(cat $(filter-out FORCE,$^) </dev/null); \
  6. echo '/*' > $@; \
  7. echo ' * This file is automatically generated. Keep it private.' >> $@; \
  8. echo ' * Exposing this value will expose the layout of randomized structures.' >> $@; \
  9. echo ' */' >> $@; \
  10. echo "const char *randstruct_seed = \"$$SEED\";" >> $@
  11. $(obj)/randomize_layout_seed.h: $(objtree)/scripts/basic/randstruct.seed FORCE
  12. $(call if_changed,create_randomize_layout_seed)
  13. targets += randomize_layout_seed.h
  14. # Build rules for plugins
  15. #
  16. # No extra code is needed for single-file plugins.
  17. # For multi-file plugins, use *-objs syntax to list the objects.
  18. #
  19. # If the plugin foo.so is compiled from foo.c and foo2.c, you can do:
  20. #
  21. # foo-objs := foo.o foo2.o
  22. always-y += $(GCC_PLUGIN)
  23. GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin)
  24. plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \
  25. -include $(srctree)/include/linux/compiler-version.h \
  26. -DPLUGIN_VERSION=$(call stringify,$(KERNELVERSION)) \
  27. -I $(GCC_PLUGINS_DIR)/include -I $(obj) \
  28. -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \
  29. -ggdb -Wno-narrowing -Wno-unused-variable \
  30. -Wno-format-diag
  31. plugin_ldflags = -shared
  32. plugin-single := $(foreach m, $(GCC_PLUGIN), $(if $($(m:%.so=%-objs)),,$(m)))
  33. plugin-multi := $(filter-out $(plugin-single), $(GCC_PLUGIN))
  34. plugin-objs := $(sort $(foreach m, $(plugin-multi), $($(m:%.so=%-objs))))
  35. targets += $(plugin-single) $(plugin-multi) $(plugin-objs)
  36. clean-files += *.so
  37. plugin-single := $(addprefix $(obj)/, $(plugin-single))
  38. plugin-multi := $(addprefix $(obj)/, $(plugin-multi))
  39. plugin-objs := $(addprefix $(obj)/, $(plugin-objs))
  40. quiet_cmd_plugin_cxx_so_c = HOSTCXX $@
  41. cmd_plugin_cxx_so_c = $(HOSTCXX) $(plugin_cxxflags) $(plugin_ldflags) -o $@ $<
  42. $(plugin-single): $(obj)/%.so: $(src)/%.c FORCE
  43. $(call if_changed_dep,plugin_cxx_so_c)
  44. quiet_cmd_plugin_ld_so_o = HOSTLD $@
  45. cmd_plugin_ld_so_o = $(HOSTCXX) $(plugin_ldflags) -o $@ \
  46. $(addprefix $(obj)/, $($(target-stem)-objs))
  47. $(plugin-multi): FORCE
  48. $(call if_changed,plugin_ld_so_o)
  49. $(foreach m, $(notdir $(plugin-multi)), $(eval $(obj)/$m: $(addprefix $(obj)/, $($(m:%.so=%-objs)))))
  50. quiet_cmd_plugin_cxx_o_c = HOSTCXX $@
  51. cmd_plugin_cxx_o_c = $(HOSTCXX) $(plugin_cxxflags) -c -o $@ $<
  52. $(plugin-objs): $(obj)/%.o: $(src)/%.c FORCE
  53. $(call if_changed_dep,plugin_cxx_o_c)