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