Makefile.modfinal 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # ===========================================================================
  3. # Module final link
  4. # ===========================================================================
  5. PHONY := __modfinal
  6. __modfinal:
  7. include include/config/auto.conf
  8. include $(srctree)/scripts/Kbuild.include
  9. # for c_flags
  10. include $(srctree)/scripts/Makefile.lib
  11. # find all modules listed in modules.order
  12. modules := $(call read-file, $(MODORDER))
  13. __modfinal: $(modules:%.o=%.ko)
  14. @:
  15. # modname and part-of-module are set to make c_flags define proper module flags
  16. modname = $(notdir $(@:.mod.o=))
  17. part-of-module = y
  18. GCOV_PROFILE := n
  19. KCSAN_SANITIZE := n
  20. quiet_cmd_cc_o_c = CC [M] $@
  21. cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI), $(c_flags)) -c -o $@ $<
  22. %.mod.o: %.mod.c FORCE
  23. $(call if_changed_dep,cc_o_c)
  24. $(extmod_prefix).module-common.o: $(srctree)/scripts/module-common.c FORCE
  25. $(call if_changed_dep,cc_o_c)
  26. quiet_cmd_ld_ko_o = LD [M] $@
  27. cmd_ld_ko_o = \
  28. $(LD) -r $(KBUILD_LDFLAGS) \
  29. $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
  30. -T scripts/module.lds -o $@ $(filter %.o, $^)
  31. quiet_cmd_btf_ko = BTF [M] $@
  32. cmd_btf_ko = \
  33. if [ ! -f vmlinux ]; then \
  34. printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
  35. else \
  36. LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base vmlinux $@; \
  37. $(RESOLVE_BTFIDS) -b vmlinux $@; \
  38. fi;
  39. # Same as newer-prereqs, but allows to exclude specified extra dependencies
  40. newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
  41. # Same as if_changed, but allows to exclude specified extra dependencies
  42. if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
  43. $(cmd); \
  44. printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
  45. # Re-generate module BTFs if either module's .ko or vmlinux changed
  46. %.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE
  47. +$(call if_changed_except,ld_ko_o,vmlinux)
  48. ifdef CONFIG_DEBUG_INFO_BTF_MODULES
  49. +$(if $(newer-prereqs),$(call cmd,btf_ko))
  50. endif
  51. targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) $(extmod_prefix).module-common.o
  52. # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
  53. # ---------------------------------------------------------------------------
  54. PHONY += FORCE
  55. FORCE:
  56. # Read all saved command lines and dependencies for the $(targets) we
  57. # may be building above, using $(if_changed{,_dep}). As an
  58. # optimization, we don't need to read them if the target does not
  59. # exist, we will rebuild anyway in that case.
  60. existing-targets := $(wildcard $(sort $(targets)))
  61. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  62. .PHONY: $(PHONY)