xref: /linux-6.15/scripts/Makefile.modinst (revision 2dfec887)
1# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================
3# Installing modules
4# ==========================================================================
5
6PHONY := __modinst
7__modinst:
8
9include include/config/auto.conf
10include $(srctree)/scripts/Kbuild.include
11
12install-y :=
13
14modules := $(call read-file, $(MODORDER))
15
16ifeq ($(KBUILD_EXTMOD),)
17dst := $(MODLIB)/kernel
18else
19INSTALL_MOD_DIR ?= updates
20dst := $(MODLIB)/$(INSTALL_MOD_DIR)
21endif
22
23$(foreach x, % :, $(if $(findstring $x, $(dst)), \
24	$(error module installation path cannot contain '$x')))
25
26suffix-y				:=
27suffix-$(CONFIG_MODULE_COMPRESS_GZIP)	:= .gz
28suffix-$(CONFIG_MODULE_COMPRESS_XZ)	:= .xz
29suffix-$(CONFIG_MODULE_COMPRESS_ZSTD)	:= .zst
30
31modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
32install-$(CONFIG_MODULES) += $(modules)
33
34__modinst: $(modules)
35	@:
36
37#
38# Installation
39#
40quiet_cmd_install = INSTALL $@
41      cmd_install = cp $< $@
42
43# Strip
44#
45# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
46# are installed. If INSTALL_MOD_STRIP is '1', then the default option
47# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
48# as the options to the strip command.
49ifdef INSTALL_MOD_STRIP
50
51ifeq ($(INSTALL_MOD_STRIP),1)
52strip-option := --strip-debug
53else
54strip-option := $(INSTALL_MOD_STRIP)
55endif
56
57quiet_cmd_strip = STRIP   $@
58      cmd_strip = $(STRIP) $(strip-option) $@
59
60else
61
62quiet_cmd_strip =
63      cmd_strip = :
64
65endif
66
67#
68# Signing
69# Don't stop modules_install even if we can't sign external modules.
70#
71ifeq ($(CONFIG_MODULE_SIG_ALL),y)
72ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
73sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
74else
75sig-key := $(CONFIG_MODULE_SIG_KEY)
76endif
77quiet_cmd_sign = SIGN    $@
78      cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
79                 $(if $(KBUILD_EXTMOD),|| true)
80else
81quiet_cmd_sign :=
82      cmd_sign := :
83endif
84
85ifeq ($(modules_sign_only),)
86
87# Create necessary directories
88$(shell mkdir -p $(sort $(dir $(install-y))))
89
90$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
91	$(call cmd,install)
92	$(call cmd,strip)
93	$(call cmd,sign)
94
95__modinst: depmod
96
97PHONY += depmod
98depmod: $(modules)
99	$(call cmd,depmod)
100
101quiet_cmd_depmod = DEPMOD  $(MODLIB)
102      cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE)
103
104else
105
106$(dst)/%.ko: FORCE
107	$(call cmd,sign)
108
109endif
110
111#
112# Compression
113#
114quiet_cmd_gzip = GZIP    $@
115      cmd_gzip = $(KGZIP) -n -f $<
116quiet_cmd_xz = XZ      $@
117      cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
118quiet_cmd_zstd = ZSTD    $@
119      cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
120
121$(dst)/%.ko.gz: $(dst)/%.ko FORCE
122	$(call cmd,gzip)
123
124$(dst)/%.ko.xz: $(dst)/%.ko FORCE
125	$(call cmd,xz)
126
127$(dst)/%.ko.zst: $(dst)/%.ko FORCE
128	$(call cmd,zstd)
129
130PHONY += FORCE
131FORCE:
132
133.PHONY: $(PHONY)
134