Merge tag 'nfs-for-6.4-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[linux-block.git] / scripts / Makefile.modinst
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2# ==========================================================================
3# Installing modules
4# ==========================================================================
5
4f193362 6PHONY := __modinst
1da177e4
LT
7__modinst:
8
65ce9c38 9include include/config/auto.conf
3204a7fb 10include $(srctree)/scripts/Kbuild.include
1da177e4 11
6768fa4b 12modules := $(call read-file, $(MODORDER))
ccae4cfa
MY
13
14ifeq ($(KBUILD_EXTMOD),)
15dst := $(MODLIB)/kernel
16else
b74d7bb7 17INSTALL_MOD_DIR ?= updates
ccae4cfa
MY
18dst := $(MODLIB)/$(INSTALL_MOD_DIR)
19endif
20
84850dbb
MY
21$(foreach x, % :, $(if $(findstring $x, $(dst)), \
22 $(error module installation path cannot contain '$x')))
23
65ce9c38
MY
24suffix-y :=
25suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
26suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
c3d7ef37 27suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
65ce9c38 28
f65a4868 29modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
1da177e4 30
1da177e4
LT
31__modinst: $(modules)
32 @:
33
65ce9c38
MY
34#
35# Installation
36#
ccae4cfa 37quiet_cmd_install = INSTALL $@
65ce9c38
MY
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
ccae4cfa 58
65ce9c38
MY
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)
22e46f64 69ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
4db9c2e3 70sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
22e46f64
JL
71else
72sig-key := $(CONFIG_MODULE_SIG_KEY)
73endif
65ce9c38 74quiet_cmd_sign = SIGN $@
22e46f64 75 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
65ce9c38
MY
76 $(if $(KBUILD_EXTMOD),|| true)
77else
78quiet_cmd_sign :=
79 cmd_sign := :
80endif
81
961ab4a3
MY
82ifeq ($(modules_sign_only),)
83
65ce9c38 84$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
ccae4cfa 85 $(call cmd,install)
65ce9c38
MY
86 $(call cmd,strip)
87 $(call cmd,sign)
88
961ab4a3
MY
89else
90
91$(dst)/%.ko: FORCE
92 $(call cmd,sign)
93
94endif
95
65ce9c38
MY
96#
97# Compression
98#
99quiet_cmd_gzip = GZIP $@
100 cmd_gzip = $(KGZIP) -n -f $<
101quiet_cmd_xz = XZ $@
102 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
c3d7ef37
PG
103quiet_cmd_zstd = ZSTD $@
104 cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
65ce9c38
MY
105
106$(dst)/%.ko.gz: $(dst)/%.ko FORCE
107 $(call cmd,gzip)
108
109$(dst)/%.ko.xz: $(dst)/%.ko FORCE
110 $(call cmd,xz)
ccae4cfa 111
c3d7ef37
PG
112$(dst)/%.ko.zst: $(dst)/%.ko FORCE
113 $(call cmd,zstd)
114
ccae4cfa
MY
115PHONY += FORCE
116FORCE:
4f193362 117
4f193362 118.PHONY: $(PHONY)