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 := $(sort $(shell cat $(MODORDER))) 13 14ifeq ($(KBUILD_EXTMOD),) 15dst := $(MODLIB)/kernel 16else 17INSTALL_MOD_DIR ?= extra 18dst := $(MODLIB)/$(INSTALL_MOD_DIR) 19endif 20 21suffix-y := 22suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz 23suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz 24suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst 25 26modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules)) 27 28__modinst: $(modules) 29 @: 30 31quiet_cmd_none = 32 cmd_none = : 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) 69CONFIG_MODULE_SIG_KEY := $(CONFIG_MODULE_SIG_KEY:"%"=%) 70sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) 71quiet_cmd_sign = SIGN $@ 72 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(sig-key) certs/signing_key.x509 $@ \ 73 $(if $(KBUILD_EXTMOD),|| true) 74else 75quiet_cmd_sign := 76 cmd_sign := : 77endif 78 79ifeq ($(modules_sign_only),) 80 81$(dst)/%.ko: $(extmod_prefix)%.ko FORCE 82 $(call cmd,install) 83 $(call cmd,strip) 84 $(call cmd,sign) 85 86else 87 88$(dst)/%.ko: FORCE 89 $(call cmd,sign) 90 91endif 92 93# 94# Compression 95# 96quiet_cmd_gzip = GZIP $@ 97 cmd_gzip = $(KGZIP) -n -f $< 98quiet_cmd_xz = XZ $@ 99 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $< 100quiet_cmd_zstd = ZSTD $@ 101 cmd_zstd = $(ZSTD) -T0 --rm -f -q $< 102 103$(dst)/%.ko.gz: $(dst)/%.ko FORCE 104 $(call cmd,gzip) 105 106$(dst)/%.ko.xz: $(dst)/%.ko FORCE 107 $(call cmd,xz) 108 109$(dst)/%.ko.zst: $(dst)/%.ko FORCE 110 $(call cmd,zstd) 111 112PHONY += FORCE 113FORCE: 114 115.PHONY: $(PHONY) 116