blob: ff9b09e4cfca0c989bad14ca3002c352277a48b6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002# ==========================================================================
3# Installing modules
4# ==========================================================================
5
Paul Smith4f193362006-03-05 17:14:10 -05006PHONY := __modinst
Linus Torvalds1da177e2005-04-16 15:20:36 -07007__modinst:
8
Masahiro Yamada65ce9c32021-03-31 22:38:08 +09009include include/config/auto.conf
Masahiro Yamada3204a7f2021-02-28 15:10:26 +090010include $(srctree)/scripts/Kbuild.include
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +090012modules := $(sort $(shell cat $(MODORDER)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +090014ifeq ($(KBUILD_EXTMOD),)
15dst := $(MODLIB)/kernel
16else
17INSTALL_MOD_DIR ?= extra
18dst := $(MODLIB)/$(INSTALL_MOD_DIR)
19endif
20
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090021suffix-y :=
22suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
23suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
Piotr Gorskic3d7ef32021-04-07 18:09:27 +020024suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090025
26modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +090027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028__modinst: $(modules)
29 @:
30
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090031quiet_cmd_none =
32 cmd_none = :
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090034#
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)
69quiet_cmd_sign = SIGN $@
70$(eval $(call config_filename,MODULE_SIG_KEY))
71 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 $@ \
72 $(if $(KBUILD_EXTMOD),|| true)
73else
74quiet_cmd_sign :=
75 cmd_sign := :
76endif
77
Masahiro Yamada961ab4a2021-03-31 22:38:09 +090078ifeq ($(modules_sign_only),)
79
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090080$(dst)/%.ko: $(extmod_prefix)%.ko FORCE
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +090081 $(call cmd,install)
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090082 $(call cmd,strip)
83 $(call cmd,sign)
84
Masahiro Yamada961ab4a2021-03-31 22:38:09 +090085else
86
87$(dst)/%.ko: FORCE
88 $(call cmd,sign)
89
90endif
91
Masahiro Yamada65ce9c32021-03-31 22:38:08 +090092#
93# Compression
94#
95quiet_cmd_gzip = GZIP $@
96 cmd_gzip = $(KGZIP) -n -f $<
97quiet_cmd_xz = XZ $@
98 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
Piotr Gorskic3d7ef32021-04-07 18:09:27 +020099quiet_cmd_zstd = ZSTD $@
100 cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
Masahiro Yamada65ce9c32021-03-31 22:38:08 +0900101
102$(dst)/%.ko.gz: $(dst)/%.ko FORCE
103 $(call cmd,gzip)
104
105$(dst)/%.ko.xz: $(dst)/%.ko FORCE
106 $(call cmd,xz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Piotr Gorskic3d7ef32021-04-07 18:09:27 +0200108$(dst)/%.ko.zst: $(dst)/%.ko FORCE
109 $(call cmd,zstd)
110
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +0900111PHONY += FORCE
112FORCE:
Paul Smith4f193362006-03-05 17:14:10 -0500113
Paul Smith4f193362006-03-05 17:14:10 -0500114.PHONY: $(PHONY)