123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- PHONY := _modpost
- _modpost: __modpost
- include include/config/auto.conf
- include scripts/Kbuild.include
- ifneq ($(KBUILD_EXTMOD),)
- obj := $(KBUILD_EXTMOD)
- src := $(obj)
- include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
- $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
- endif
- include scripts/Makefile.lib
- kernelsymfile := $(objtree)/Module.symvers
- modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
- MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort -u
- __modules := $(shell $(MODLISTCMD))
- modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
- _modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
- modpost = scripts/mod/modpost \
- $(if $(CONFIG_MODVERSIONS),-m) \
- $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \
- $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
- $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
- $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
- $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
- $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
- $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
- $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
- MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))
- modpost-ext = $(if $(CONFIG_LTO_CLANG),.lto,)
- ifdef CONFIG_LTO_CLANG
- quiet_cmd_cc_lto_link_modules = LD [M] $@
- bad_ld_flags = -plugin-opt=-function-sections -plugin-opt=-data-sections
- filtered_ld_flags = $(filter-out $(bad_ld_flags),$(ld_flags))
- cmd_cc_lto_link_modules = \
- $(LD) $(filtered_ld_flags) -r -o $(@) \
- $(shell [ -s $(@:$(modpost-ext).o=.o.symversions) ] && \
- echo -T $(@:$(modpost-ext).o=.o.symversions)) \
- --whole-archive $(filter-out FORCE,$^)
- $(modules:.ko=$(modpost-ext).o): %$(modpost-ext).o: %.o FORCE
- $(call if_changed,cc_lto_link_modules)
- endif
- quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
- cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/$(modpost-ext)\.o/' | $(modpost) $(MODPOST_OPT) -s -T -
- PHONY += __modpost
- __modpost: $(modules:.ko=$(modpost-ext).o) FORCE
- $(call cmd,modpost) $(wildcard vmlinux)
- quiet_cmd_kernel-mod = MODPOST $@
- cmd_kernel-mod = $(modpost) $@
- vmlinux.o: FORCE
- $(call cmd,kernel-mod)
- $(symverfile): __modpost ;
- $(modules:.ko=$(modpost-ext).mod.c): __modpost ;
- modname = $(notdir $(@:.mod.o=))
- quiet_cmd_cc_o_c = CC $@
- cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \
- -c -o $@ $<
- $(modules:.ko=.mod.o): %.mod.o: %$(modpost-ext).mod.c FORCE
- $(call if_changed_dep,cc_o_c)
- targets += $(modules:.ko=$(modpost-ext).mod.o)
- ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
- quiet_cmd_ld_ko_o = LD [M] $@
- ifdef CONFIG_LTO_CLANG
- bad_ld_flags = -plugin-opt=-function-sections -plugin-opt=-data-sections
- filtered_ldflags = $(filter-out $(bad_ld_flags),$(LDFLAGS))
- cmd_ld_ko_o = \
- $(LD) -r $(filtered_ld_flags) \
- $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
- $(shell [ -s $(@:.ko=.o.symversions) ] && \
- echo -T $(@:.ko=.o.symversions)) \
- -o $@ --whole-archive \
- $(filter-out FORCE,$(^:$(modpost-ext).o=.o))
- ifdef CONFIG_FTRACE_MCOUNT_RECORD
- cmd_ld_ko_o += ; $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) $@
- endif
- else
- cmd_ld_ko_o = \
- $(LD) -r $(LDFLAGS) \
- $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
- -o $@ $(filter-out FORCE,$^) ; \
- $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
- endif
- $(modules): %.ko: %$(modpost-ext).o %.mod.o FORCE
- +$(call if_changed,ld_ko_o)
- targets += $(modules)
- PHONY += FORCE
- FORCE:
- targets := $(wildcard $(sort $(targets)))
- cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
- ifneq ($(cmd_files),)
- include $(cmd_files)
- endif
- .PHONY: $(PHONY)
|