18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci# ===========================================================================
38c2ecf20Sopenharmony_ci# Module final link
48c2ecf20Sopenharmony_ci# ===========================================================================
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciPHONY := __modfinal
78c2ecf20Sopenharmony_ci__modfinal:
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci# for c_flags
128c2ecf20Sopenharmony_ciinclude $(srctree)/scripts/Makefile.lib
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci# find all modules listed in modules.order
158c2ecf20Sopenharmony_cimodules := $(sort $(shell cat $(MODORDER)))
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci__modfinal: $(modules)
188c2ecf20Sopenharmony_ci	@:
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci# modname and part-of-module are set to make c_flags define proper module flags
218c2ecf20Sopenharmony_cimodname = $(notdir $(@:.mod.o=))
228c2ecf20Sopenharmony_cipart-of-module = y
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciquiet_cmd_cc_o_c = CC [M]  $@
258c2ecf20Sopenharmony_ci      cmd_cc_o_c = $(CC) $(filter-out $(CC_FLAGS_CFI), $(c_flags)) -c -o $@ $<
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci%.mod.o: %.mod.c FORCE
288c2ecf20Sopenharmony_ci	$(call if_changed_dep,cc_o_c)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciifdef CONFIG_LTO_CLANG
338c2ecf20Sopenharmony_ci# With CONFIG_LTO_CLANG, reuse the object file we compiled for modpost to
348c2ecf20Sopenharmony_ci# avoid a second slow LTO link
358c2ecf20Sopenharmony_ciprelink-ext := .lto
368c2ecf20Sopenharmony_ciendif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciquiet_cmd_ld_ko_o = LD [M]  $@
398c2ecf20Sopenharmony_ci      cmd_ld_ko_o =                                                     \
408c2ecf20Sopenharmony_ci	$(LD) -r $(KBUILD_LDFLAGS)					\
418c2ecf20Sopenharmony_ci		$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)		\
428c2ecf20Sopenharmony_ci		-T scripts/module.lds -o $@ $(filter %.o, $^);		\
438c2ecf20Sopenharmony_ci	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci$(modules): %.ko: %$(prelink-ext).o %.mod.o scripts/module.lds FORCE
468c2ecf20Sopenharmony_ci	+$(call if_changed,ld_ko_o)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_citargets += $(modules) $(modules:.ko=.mod.o)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci# Add FORCE to the prequisites of a target to force it to be always rebuilt.
518c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciPHONY += FORCE
548c2ecf20Sopenharmony_ciFORCE:
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci# Read all saved command lines and dependencies for the $(targets) we
578c2ecf20Sopenharmony_ci# may be building above, using $(if_changed{,_dep}). As an
588c2ecf20Sopenharmony_ci# optimization, we don't need to read them if the target does not
598c2ecf20Sopenharmony_ci# exist, we will rebuild anyway in that case.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciexisting-targets := $(wildcard $(sort $(targets)))
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci.PHONY: $(PHONY)
66