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 31# 32# Installation 33# 34quiet_cmd_install = INSTALL $@ 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 55 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) 66sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY) 67quiet_cmd_sign = SIGN $@ 68 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(sig-key) certs/signing_key.x509 $@ \ 69 $(if $(KBUILD_EXTMOD),|| true) 70else 71quiet_cmd_sign := 72 cmd_sign := : 73endif 74 75ifeq ($(modules_sign_only),) 76 77$(dst)/%.ko: $(extmod_prefix)%.ko FORCE 78 $(call cmd,install) 79 $(call cmd,strip) 80 $(call cmd,sign) 81 82else 83 84$(dst)/%.ko: FORCE 85 $(call cmd,sign) 86 87endif 88 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 $< 96quiet_cmd_zstd = ZSTD $@ 97 cmd_zstd = $(ZSTD) -T0 --rm -f -q $< 98 99$(dst)/%.ko.gz: $(dst)/%.ko FORCE 100 $(call cmd,gzip) 101 102$(dst)/%.ko.xz: $(dst)/%.ko FORCE 103 $(call cmd,xz) 104 105$(dst)/%.ko.zst: $(dst)/%.ko FORCE 106 $(call cmd,zstd) 107 108PHONY += FORCE 109FORCE: 110 111.PHONY: $(PHONY) 112