1 # SPDX-License-Identifier: GPL-2.0
2 # ==========================================================================
4 # ==========================================================================
9 include $(objtree)/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,.ranges) even when CONFIG_MODULES is disabled.
34 install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo)
36 install-$(CONFIG_BUILTIN_MODULE_RANGES) += $(MODLIB)/modules.builtin.ranges
38 $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin.ranges): $(MODLIB)/%: % FORCE
43 modules := $(call read-file, modules.order)
45 ifeq ($(KBUILD_EXTMOD),)
46 dst := $(MODLIB)/kernel
48 INSTALL_MOD_DIR ?= updates
49 dst := $(MODLIB)/$(INSTALL_MOD_DIR)
52 $(foreach x, % :, $(if $(findstring $x, $(dst)), \
53 $(error module installation path cannot contain '$x')))
56 ifdef CONFIG_MODULE_COMPRESS_ALL
57 suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
58 suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
59 suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
62 modules := $(patsubst %.o, $(dst)/%.ko$(suffix-y), $(modules))
63 install-$(CONFIG_MODULES) += $(modules)
65 __modinst: $(install-y)
71 quiet_cmd_install = INSTALL $@
72 cmd_install = cp $< $@
76 # INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
77 # are installed. If INSTALL_MOD_STRIP is '1', then the default option
78 # --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
79 # as the options to the strip command.
80 ifdef INSTALL_MOD_STRIP
82 ifeq ($(INSTALL_MOD_STRIP),1)
83 strip-option := --strip-debug
85 strip-option := $(INSTALL_MOD_STRIP)
88 quiet_cmd_strip = STRIP $@
89 cmd_strip = $(STRIP) $(strip-option) $@
100 # Don't stop modules_install even if we can't sign external modules.
102 ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
103 sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
105 sig-key := $(CONFIG_MODULE_SIG_KEY)
107 quiet_cmd_sign = SIGN $@
108 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
109 $(if $(KBUILD_EXTMOD),|| true)
113 # During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y.
114 ifndef CONFIG_MODULE_SIG_ALL
119 # Create necessary directories
120 $(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir)))
122 $(dst)/%.ko: %.ko FORCE
134 quiet_cmd_depmod = DEPMOD $(MODLIB)
135 cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE)
148 quiet_cmd_gzip = GZIP $@
149 cmd_gzip = $(KGZIP) -n -f $<
151 cmd_xz = $(XZ) --check=crc32 --lzma2=dict=1MiB -f $<
152 quiet_cmd_zstd = ZSTD $@
153 cmd_zstd = $(ZSTD) --rm -f -q $<
155 $(dst)/%.ko.gz: $(dst)/%.ko FORCE
158 $(dst)/%.ko.xz: $(dst)/%.ko FORCE
161 $(dst)/%.ko.zst: $(dst)/%.ko FORCE