162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci# =========================================================================== 362306a36Sopenharmony_ci# Module final link 462306a36Sopenharmony_ci# =========================================================================== 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciPHONY := __modfinal 762306a36Sopenharmony_ci__modfinal: 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciinclude include/config/auto.conf 1062306a36Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci# for c_flags 1362306a36Sopenharmony_ciinclude $(srctree)/scripts/Makefile.lib 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci# find all modules listed in modules.order 1662306a36Sopenharmony_cimodules := $(call read-file, $(MODORDER)) 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci__modfinal: $(modules:%.o=%.ko) 1962306a36Sopenharmony_ci @: 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci# modname and part-of-module are set to make c_flags define proper module flags 2262306a36Sopenharmony_cimodname = $(notdir $(@:.mod.o=)) 2362306a36Sopenharmony_cipart-of-module = y 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciquiet_cmd_cc_o_c = CC [M] $@ 2662306a36Sopenharmony_ci cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI) $(CFLAGS_GCOV), $(c_flags)) -c -o $@ $< 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci%.mod.o: %.mod.c FORCE 2962306a36Sopenharmony_ci $(call if_changed_dep,cc_o_c) 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciquiet_cmd_ld_ko_o = LD [M] $@ 3462306a36Sopenharmony_ci cmd_ld_ko_o += \ 3562306a36Sopenharmony_ci $(LD) -r $(KBUILD_LDFLAGS) \ 3662306a36Sopenharmony_ci $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 3762306a36Sopenharmony_ci -T scripts/module.lds -o $@ $(filter %.o, $^); \ 3862306a36Sopenharmony_ci $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciquiet_cmd_btf_ko = BTF [M] $@ 4162306a36Sopenharmony_ci cmd_btf_ko = \ 4262306a36Sopenharmony_ci if [ ! -f vmlinux ]; then \ 4362306a36Sopenharmony_ci printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ 4462306a36Sopenharmony_ci else \ 4562306a36Sopenharmony_ci LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ 4662306a36Sopenharmony_ci $(RESOLVE_BTFIDS) -b vmlinux $@; \ 4762306a36Sopenharmony_ci fi; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci# Same as newer-prereqs, but allows to exclude specified extra dependencies 5062306a36Sopenharmony_cinewer_prereqs_except = $(filter-out $(PHONY) $(1),$?) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci# Same as if_changed, but allows to exclude specified extra dependencies 5362306a36Sopenharmony_ciif_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ 5462306a36Sopenharmony_ci $(cmd); \ 5562306a36Sopenharmony_ci printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci# Re-generate module BTFs if either module's .ko or vmlinux changed 5862306a36Sopenharmony_ci%.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE 5962306a36Sopenharmony_ci +$(call if_changed_except,ld_ko_o,vmlinux) 6062306a36Sopenharmony_ciifdef CONFIG_DEBUG_INFO_BTF_MODULES 6162306a36Sopenharmony_ci +$(if $(newer-prereqs),$(call cmd,btf_ko)) 6262306a36Sopenharmony_ciendif 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_citargets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci# Add FORCE to the prequisites of a target to force it to be always rebuilt. 6762306a36Sopenharmony_ci# --------------------------------------------------------------------------- 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciPHONY += FORCE 7062306a36Sopenharmony_ciFORCE: 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci# Read all saved command lines and dependencies for the $(targets) we 7362306a36Sopenharmony_ci# may be building above, using $(if_changed{,_dep}). As an 7462306a36Sopenharmony_ci# optimization, we don't need to read them if the target does not 7562306a36Sopenharmony_ci# exist, we will rebuild anyway in that case. 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciexisting-targets := $(wildcard $(sort $(targets))) 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci.PHONY: $(PHONY) 82