kbuild: error out if $(KBUILD_EXTMOD) contains % or :
[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
ccae4cfa
MY
12modules := $(sort $(shell cat $(MODORDER)))
13
14ifeq ($(KBUILD_EXTMOD),)
15dst := $(MODLIB)/kernel
16else
17INSTALL_MOD_DIR ?= extra
18dst := $(MODLIB)/$(INSTALL_MOD_DIR)
19endif
20
65ce9c38
MY
21suffix-y :=
22suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
23suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
c3d7ef37 24suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
65ce9c38
MY
25
26modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
1da177e4 27
1da177e4
LT
28__modinst: $(modules)
29 @:
30
65ce9c38
MY
31#
32# Installation
33#
ccae4cfa 34quiet_cmd_install = INSTALL $@
65ce9c38
MY
35 cmd_install = mkdir -p $(dir $@); cp $< $@
36
37# Strip
38#
39# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
40# are installed. If INSTALL_MOD_STRIP is '1', then the default option
41# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
42# as the options to the strip command.
43ifdef INSTALL_MOD_STRIP
44
45ifeq ($(INSTALL_MOD_STRIP),1)
46strip-option := --strip-debug
47else
48strip-option := $(INSTALL_MOD_STRIP)
49endif
50
51quiet_cmd_strip = STRIP $@
52 cmd_strip = $(STRIP) $(strip-option) $@
53
54else
ccae4cfa 55
65ce9c38
MY
56quiet_cmd_strip =
57 cmd_strip = :
58
59endif
60
61#
62# Signing
63# Don't stop modules_install even if we can't sign external modules.
64#
65ifeq ($(CONFIG_MODULE_SIG_ALL),y)
4db9c2e3 66sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
65ce9c38 67quiet_cmd_sign = SIGN $@
4db9c2e3 68 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(sig-key) certs/signing_key.x509 $@ \
65ce9c38
MY
69 $(if $(KBUILD_EXTMOD),|| true)
70else
71quiet_cmd_sign :=
72 cmd_sign := :
73endif
74
961ab4a3
MY
75ifeq ($(modules_sign_only),)
76
65ce9c38 77$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
ccae4cfa 78 $(call cmd,install)
65ce9c38
MY
79 $(call cmd,strip)
80 $(call cmd,sign)
81
961ab4a3
MY
82else
83
84$(dst)/%.ko: FORCE
85 $(call cmd,sign)
86
87endif
88
65ce9c38
MY
89#
90# Compression
91#
92quiet_cmd_gzip = GZIP $@
93 cmd_gzip = $(KGZIP) -n -f $<
94quiet_cmd_xz = XZ $@
95 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
c3d7ef37
PG
96quiet_cmd_zstd = ZSTD $@
97 cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
65ce9c38
MY
98
99$(dst)/%.ko.gz: $(dst)/%.ko FORCE
100 $(call cmd,gzip)
101
102$(dst)/%.ko.xz: $(dst)/%.ko FORCE
103 $(call cmd,xz)
ccae4cfa 104
c3d7ef37
PG
105$(dst)/%.ko.zst: $(dst)/%.ko FORCE
106 $(call cmd,zstd)
107
ccae4cfa
MY
108PHONY += FORCE
109FORCE:
4f193362 110
4f193362 111.PHONY: $(PHONY)