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 24 25modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules)) 26 27__modinst: $(modules) 28 @: 29 30quiet_cmd_none = 31 cmd_none = : 32 33# 34# Installation 35# 36quiet_cmd_install = INSTALL $@ 37 cmd_install = mkdir -p $(dir $@); cp $< $@ 38 39# Strip 40# 41# INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they 42# are installed. If INSTALL_MOD_STRIP is '1', then the default option 43# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used 44# as the options to the strip command. 45ifdef INSTALL_MOD_STRIP 46 47ifeq ($(INSTALL_MOD_STRIP),1) 48strip-option := --strip-debug 49else 50strip-option := $(INSTALL_MOD_STRIP) 51endif 52 53quiet_cmd_strip = STRIP $@ 54 cmd_strip = $(STRIP) $(strip-option) $@ 55 56else 57 58quiet_cmd_strip = 59 cmd_strip = : 60 61endif 62 63# 64# Signing 65# Don't stop modules_install even if we can't sign external modules. 66# 67ifeq ($(CONFIG_MODULE_SIG_ALL),y) 68quiet_cmd_sign = SIGN $@ 69$(eval $(call config_filename,MODULE_SIG_KEY)) 70 cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 $@ \ 71 $(if $(KBUILD_EXTMOD),|| true) 72else 73quiet_cmd_sign := 74 cmd_sign := : 75endif 76 77$(dst)/%.ko: $(extmod_prefix)%.ko FORCE 78 $(call cmd,install) 79 $(call cmd,strip) 80 $(call cmd,sign) 81 82# 83# Compression 84# 85quiet_cmd_gzip = GZIP $@ 86 cmd_gzip = $(KGZIP) -n -f $< 87quiet_cmd_xz = XZ $@ 88 cmd_xz = $(XZ) --lzma2=dict=2MiB -f $< 89 90$(dst)/%.ko.gz: $(dst)/%.ko FORCE 91 $(call cmd,gzip) 92 93$(dst)/%.ko.xz: $(dst)/%.ko FORCE 94 $(call cmd,xz) 95 96PHONY += FORCE 97FORCE: 98 99.PHONY: $(PHONY) 100