Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | # ========================================================================== |
| 3 | # Installing modules |
| 4 | # ========================================================================== |
| 5 | |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 6 | PHONY := __modinst |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | __modinst: |
| 8 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 9 | include include/config/auto.conf |
Masahiro Yamada | 3204a7f | 2021-02-28 15:10:26 +0900 | [diff] [blame] | 10 | include $(srctree)/scripts/Kbuild.include |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Masahiro Yamada | ccae4cf | 2021-03-31 22:38:07 +0900 | [diff] [blame] | 12 | modules := $(sort $(shell cat $(MODORDER))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Masahiro Yamada | ccae4cf | 2021-03-31 22:38:07 +0900 | [diff] [blame] | 14 | ifeq ($(KBUILD_EXTMOD),) |
| 15 | dst := $(MODLIB)/kernel |
| 16 | else |
| 17 | INSTALL_MOD_DIR ?= extra |
| 18 | dst := $(MODLIB)/$(INSTALL_MOD_DIR) |
| 19 | endif |
| 20 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 21 | suffix-y := |
| 22 | suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz |
| 23 | suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz |
Piotr Gorski | c3d7ef3 | 2021-04-07 18:09:27 +0200 | [diff] [blame] | 24 | suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 25 | |
| 26 | modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules)) |
Masahiro Yamada | ccae4cf | 2021-03-31 22:38:07 +0900 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | __modinst: $(modules) |
| 29 | @: |
| 30 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 31 | quiet_cmd_none = |
| 32 | cmd_none = : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 34 | # |
| 35 | # Installation |
| 36 | # |
| 37 | quiet_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. |
| 46 | ifdef INSTALL_MOD_STRIP |
| 47 | |
| 48 | ifeq ($(INSTALL_MOD_STRIP),1) |
| 49 | strip-option := --strip-debug |
| 50 | else |
| 51 | strip-option := $(INSTALL_MOD_STRIP) |
| 52 | endif |
| 53 | |
| 54 | quiet_cmd_strip = STRIP $@ |
| 55 | cmd_strip = $(STRIP) $(strip-option) $@ |
| 56 | |
| 57 | else |
| 58 | |
| 59 | quiet_cmd_strip = |
| 60 | cmd_strip = : |
| 61 | |
| 62 | endif |
| 63 | |
| 64 | # |
| 65 | # Signing |
| 66 | # Don't stop modules_install even if we can't sign external modules. |
| 67 | # |
| 68 | ifeq ($(CONFIG_MODULE_SIG_ALL),y) |
| 69 | quiet_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) |
| 73 | else |
| 74 | quiet_cmd_sign := |
| 75 | cmd_sign := : |
| 76 | endif |
| 77 | |
Masahiro Yamada | 961ab4a | 2021-03-31 22:38:09 +0900 | [diff] [blame] | 78 | ifeq ($(modules_sign_only),) |
| 79 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 80 | $(dst)/%.ko: $(extmod_prefix)%.ko FORCE |
Masahiro Yamada | ccae4cf | 2021-03-31 22:38:07 +0900 | [diff] [blame] | 81 | $(call cmd,install) |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 82 | $(call cmd,strip) |
| 83 | $(call cmd,sign) |
| 84 | |
Masahiro Yamada | 961ab4a | 2021-03-31 22:38:09 +0900 | [diff] [blame] | 85 | else |
| 86 | |
| 87 | $(dst)/%.ko: FORCE |
| 88 | $(call cmd,sign) |
| 89 | |
| 90 | endif |
| 91 | |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 92 | # |
| 93 | # Compression |
| 94 | # |
| 95 | quiet_cmd_gzip = GZIP $@ |
| 96 | cmd_gzip = $(KGZIP) -n -f $< |
| 97 | quiet_cmd_xz = XZ $@ |
| 98 | cmd_xz = $(XZ) --lzma2=dict=2MiB -f $< |
Piotr Gorski | c3d7ef3 | 2021-04-07 18:09:27 +0200 | [diff] [blame] | 99 | quiet_cmd_zstd = ZSTD $@ |
| 100 | cmd_zstd = $(ZSTD) -T0 --rm -f -q $< |
Masahiro Yamada | 65ce9c3 | 2021-03-31 22:38:08 +0900 | [diff] [blame] | 101 | |
| 102 | $(dst)/%.ko.gz: $(dst)/%.ko FORCE |
| 103 | $(call cmd,gzip) |
| 104 | |
| 105 | $(dst)/%.ko.xz: $(dst)/%.ko FORCE |
| 106 | $(call cmd,xz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Piotr Gorski | c3d7ef3 | 2021-04-07 18:09:27 +0200 | [diff] [blame] | 108 | $(dst)/%.ko.zst: $(dst)/%.ko FORCE |
| 109 | $(call cmd,zstd) |
| 110 | |
Masahiro Yamada | ccae4cf | 2021-03-31 22:38:07 +0900 | [diff] [blame] | 111 | PHONY += FORCE |
| 112 | FORCE: |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 113 | |
Paul Smith | 4f19336 | 2006-03-05 17:14:10 -0500 | [diff] [blame] | 114 | .PHONY: $(PHONY) |