Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0-only
0002 # ===========================================================================
0003 # Module final link
0004 # ===========================================================================
0005 
0006 PHONY := __modfinal
0007 __modfinal:
0008 
0009 include include/config/auto.conf
0010 include $(srctree)/scripts/Kbuild.include
0011 
0012 # for c_flags
0013 include $(srctree)/scripts/Makefile.lib
0014 
0015 # find all modules listed in modules.order
0016 modules := $(sort $(shell cat $(MODORDER)))
0017 
0018 __modfinal: $(modules)
0019         @:
0020 
0021 # modname and part-of-module are set to make c_flags define proper module flags
0022 modname = $(notdir $(@:.mod.o=))
0023 part-of-module = y
0024 
0025 quiet_cmd_cc_o_c = CC [M]  $@
0026       cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI), $(c_flags)) -c -o $@ $<
0027 
0028 %.mod.o: %.mod.c FORCE
0029         $(call if_changed_dep,cc_o_c)
0030 
0031 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
0032 
0033 quiet_cmd_ld_ko_o = LD [M]  $@
0034       cmd_ld_ko_o +=                                                    \
0035         $(LD) -r $(KBUILD_LDFLAGS)                                      \
0036                 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)              \
0037                 -T scripts/module.lds -o $@ $(filter %.o, $^);          \
0038         $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
0039 
0040 quiet_cmd_btf_ko = BTF [M] $@
0041       cmd_btf_ko =                                                      \
0042         if [ -f vmlinux ]; then                                         \
0043                 LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
0044                 $(RESOLVE_BTFIDS) -b vmlinux $@;                        \
0045         else                                                            \
0046                 printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
0047         fi;
0048 
0049 # Same as newer-prereqs, but allows to exclude specified extra dependencies
0050 newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
0051 
0052 # Same as if_changed, but allows to exclude specified extra dependencies
0053 if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check),      \
0054         $(cmd);                                                              \
0055         printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
0056 
0057 # Re-generate module BTFs if either module's .ko or vmlinux changed
0058 $(modules): %.ko: %.o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE
0059         +$(call if_changed_except,ld_ko_o,vmlinux)
0060 ifdef CONFIG_DEBUG_INFO_BTF_MODULES
0061         +$(if $(newer-prereqs),$(call cmd,btf_ko))
0062 endif
0063 
0064 targets += $(modules) $(modules:.ko=.mod.o)
0065 
0066 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
0067 # ---------------------------------------------------------------------------
0068 
0069 PHONY += FORCE
0070 FORCE:
0071 
0072 # Read all saved command lines and dependencies for the $(targets) we
0073 # may be building above, using $(if_changed{,_dep}). As an
0074 # optimization, we don't need to read them if the target does not
0075 # exist, we will rebuild anyway in that case.
0076 
0077 existing-targets := $(wildcard $(sort $(targets)))
0078 
0079 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 
0080 
0081 .PHONY: $(PHONY)