]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - scripts/Makefile.modinst
Merge tag 'kvm-x86-misc-6.7' of https://github.com/kvm-x86/linux into HEAD
[thirdparty/kernel/stable.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
2dfec887
MY
12install-y :=
13
151aeca2 14ifeq ($(KBUILD_EXTMOD)$(sign-only),)
5e02797b
MY
15
16# remove the old directory and symlink
17$(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build)
18
19install-$(CONFIG_MODULES) += $(addprefix $(MODLIB)/, build modules.order)
20
21$(MODLIB)/build: FORCE
22 $(call cmd,symlink)
23
24quiet_cmd_symlink = SYMLINK $@
25 cmd_symlink = ln -s $(CURDIR) $@
26
27$(MODLIB)/modules.order: modules.order FORCE
28 $(call cmd,install_modorder)
29
30quiet_cmd_install_modorder = INSTALL $@
31 cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@
32
33# Install modules.builtin(.modinfo) even when CONFIG_MODULES is disabled.
34install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo)
35
36$(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo): $(MODLIB)/%: % FORCE
37 $(call cmd,install)
38
39endif
40
6768fa4b 41modules := $(call read-file, $(MODORDER))
ccae4cfa
MY
42
43ifeq ($(KBUILD_EXTMOD),)
44dst := $(MODLIB)/kernel
45else
b74d7bb7 46INSTALL_MOD_DIR ?= updates
ccae4cfa
MY
47dst := $(MODLIB)/$(INSTALL_MOD_DIR)
48endif
49
84850dbb
MY
50$(foreach x, % :, $(if $(findstring $x, $(dst)), \
51 $(error module installation path cannot contain '$x')))
52
65ce9c38
MY
53suffix-y :=
54suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
55suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
c3d7ef37 56suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
65ce9c38 57
f65a4868 58modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
2dfec887 59install-$(CONFIG_MODULES) += $(modules)
1da177e4 60
5e02797b 61__modinst: $(install-y)
1da177e4
LT
62 @:
63
65ce9c38
MY
64#
65# Installation
66#
ccae4cfa 67quiet_cmd_install = INSTALL $@
2dfec887 68 cmd_install = cp $< $@
65ce9c38
MY
69
70# Strip
71#
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.
76ifdef INSTALL_MOD_STRIP
77
78ifeq ($(INSTALL_MOD_STRIP),1)
79strip-option := --strip-debug
80else
81strip-option := $(INSTALL_MOD_STRIP)
82endif
83
84quiet_cmd_strip = STRIP $@
85 cmd_strip = $(STRIP) $(strip-option) $@
86
87else
ccae4cfa 88
65ce9c38
MY
89quiet_cmd_strip =
90 cmd_strip = :
91
92endif
93
94#
95# Signing
96# Don't stop modules_install even if we can't sign external modules.
97#
22e46f64 98ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
4db9c2e3 99sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
22e46f64
JL
100else
101sig-key := $(CONFIG_MODULE_SIG_KEY)
102endif
65ce9c38 103quiet_cmd_sign = SIGN $@
22e46f64 104 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
65ce9c38 105 $(if $(KBUILD_EXTMOD),|| true)
02e8487b 106
151aeca2 107ifeq ($(sign-only),)
02e8487b
MY
108
109# During modules_install, modules are signed only when CONFIG_MODULE_SIG_ALL=y.
110ifndef CONFIG_MODULE_SIG_ALL
65ce9c38
MY
111quiet_cmd_sign :=
112 cmd_sign := :
113endif
114
2dfec887 115# Create necessary directories
552c5013 116$(foreach dir, $(sort $(dir $(install-y))), $(shell mkdir -p $(dir)))
2dfec887 117
65ce9c38 118$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
ccae4cfa 119 $(call cmd,install)
65ce9c38
MY
120 $(call cmd,strip)
121 $(call cmd,sign)
122
5e02797b 123ifdef CONFIG_MODULES
79b96c33
MY
124__modinst: depmod
125
126PHONY += depmod
5e02797b 127depmod: $(install-y)
79b96c33
MY
128 $(call cmd,depmod)
129
130quiet_cmd_depmod = DEPMOD $(MODLIB)
131 cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE)
5e02797b 132endif
79b96c33 133
961ab4a3
MY
134else
135
136$(dst)/%.ko: FORCE
137 $(call cmd,sign)
138
139endif
140
65ce9c38
MY
141#
142# Compression
143#
144quiet_cmd_gzip = GZIP $@
145 cmd_gzip = $(KGZIP) -n -f $<
146quiet_cmd_xz = XZ $@
fbf5892d 147 cmd_xz = $(XZ) --check=crc32 --lzma2=dict=1MiB -f $<
c3d7ef37
PG
148quiet_cmd_zstd = ZSTD $@
149 cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
65ce9c38
MY
150
151$(dst)/%.ko.gz: $(dst)/%.ko FORCE
152 $(call cmd,gzip)
153
154$(dst)/%.ko.xz: $(dst)/%.ko FORCE
155 $(call cmd,xz)
ccae4cfa 156
c3d7ef37
PG
157$(dst)/%.ko.zst: $(dst)/%.ko FORCE
158 $(call cmd,zstd)
159
ccae4cfa
MY
160PHONY += FORCE
161FORCE:
4f193362 162
4f193362 163.PHONY: $(PHONY)