1 # SPDX-License-Identifier: GPL-2.0
2 # ==========================================================================
4 # ==========================================================================
9 include include/config/auto.conf
10 include $(srctree)/scripts/Kbuild.include
14 ifeq ($(KBUILD_EXTMOD)$(sign-only),)
16 # remove the old directory and symlink
17 $(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build)
19 install-$(CONFIG_MODULES) += $(addprefix $(MODLIB)/, build modules.order)
21 $(MODLIB)/build: FORCE
24 quiet_cmd_symlink = SYMLINK $@
25 cmd_symlink = ln -s $(CURDIR) $@
27 $(MODLIB)/modules.order: modules.order FORCE
28 $(call cmd,install_modorder)
30 quiet_cmd_install_modorder = INSTALL $@
31 cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@
33 # Install modules.builtin(.modinfo) even when CONFIG_MODULES is disabled.
34 install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo)
36 $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo): $(MODLIB)/%: % FORCE
41 modules := $(call read-file, $(MODORDER))
43 ifeq ($(KBUILD_EXTMOD),)
44 dst := $(MODLIB)/kernel
46 INSTALL_MOD_DIR ?= updates
47 dst := $(MODLIB)/$(INSTALL_MOD_DIR)
50 $(foreach x, % :, $(if $(findstring $x, $(dst)), \
51 $(error module installation path cannot contain '$x')))
54 suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
55 suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
56 suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
58 modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
59 install-$(CONFIG_MODULES) += $(modules)
61 __modinst: $(install-y)
67 quiet_cmd_install = INSTALL $@
68 cmd_install = cp $< $@
72 # INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
73 # are installed. If INSTALL_MOD_STRIP is '1', then the default option
74 # --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
75 # as the options to the strip command.
76 ifdef INSTALL_MOD_STRIP
78 ifeq ($(INSTALL_MOD_STRIP),1)
79 strip-option := --strip-debug
81 strip-option := $(INSTALL_MOD_STRIP)
84 quiet_cmd_strip = STRIP $@
85 cmd_strip = $(STRIP) $(strip-option) $@
96 # Don't stop modules_install even if we can't sign external modules.
98 ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
99 sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
101 sig-key := $(CONFIG_MODULE_SIG_KEY)
103 quiet_cmd_sign = SIGN $@
104 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
105 $(if $(KBUILD_EXTMOD),|| true)
109 # During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y.
110 ifndef CONFIG_MODULE_SIG_ALL
115 # Create necessary directories
116 $(shell mkdir -p $(sort $(dir $(install-y))))
118 $(dst)/%.ko: $(extmod_prefix)%.ko FORCE
130 quiet_cmd_depmod = DEPMOD $(MODLIB)
131 cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE)
144 quiet_cmd_gzip = GZIP $@
145 cmd_gzip = $(KGZIP) -n -f $<
147 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
148 quiet_cmd_zstd = ZSTD $@
149 cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
151 $(dst)/%.ko.gz: $(dst)/%.ko FORCE
154 $(dst)/%.ko.xz: $(dst)/%.ko FORCE
157 $(dst)/%.ko.zst: $(dst)/%.ko FORCE