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