Makefile.modinst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # SPDX-License-Identifier: GPL-2.0
  2. # ==========================================================================
  3. # Installing modules
  4. # ==========================================================================
  5. PHONY := __modinst
  6. __modinst:
  7. include include/config/auto.conf
  8. include $(srctree)/scripts/Kbuild.include
  9. modules := $(sort $(shell cat $(MODORDER)))
  10. ifeq ($(KBUILD_EXTMOD),)
  11. dst := $(MODLIB)/kernel
  12. else
  13. INSTALL_MOD_DIR ?= extra
  14. dst := $(MODLIB)/$(INSTALL_MOD_DIR)
  15. endif
  16. $(foreach x, % :, $(if $(findstring $x, $(dst)), \
  17. $(error module installation path cannot contain '$x')))
  18. suffix-y :=
  19. suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz
  20. suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz
  21. suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
  22. modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules))
  23. ifneq ($(KBUILD_EXTMOD),)
  24. extmod_suffix := $(shell echo "${KBUILD_EXTMOD}" | md5sum | cut -d " " -f 1)
  25. modules += $(dst)/modules.order.$(extmod_suffix)
  26. endif
  27. __modinst: $(modules)
  28. @:
  29. #
  30. # Installation
  31. #
  32. quiet_cmd_install = INSTALL $@
  33. cmd_install = mkdir -p $(dir $@); cp $< $@
  34. # Strip
  35. #
  36. # INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
  37. # are installed. If INSTALL_MOD_STRIP is '1', then the default option
  38. # --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
  39. # as the options to the strip command.
  40. ifdef INSTALL_MOD_STRIP
  41. ifeq ($(INSTALL_MOD_STRIP),1)
  42. strip-option := --strip-debug
  43. else
  44. strip-option := $(INSTALL_MOD_STRIP)
  45. endif
  46. quiet_cmd_strip = STRIP $@
  47. cmd_strip = $(STRIP) $(strip-option) $@
  48. else
  49. quiet_cmd_strip =
  50. cmd_strip = :
  51. endif
  52. #
  53. # Signing
  54. # Don't stop modules_install even if we can't sign external modules.
  55. #
  56. ifeq ($(CONFIG_MODULE_SIG_ALL),y)
  57. ifeq ($(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),)
  58. sig-key := $(if $(wildcard $(CONFIG_MODULE_SIG_KEY)),,$(srctree)/)$(CONFIG_MODULE_SIG_KEY)
  59. else
  60. sig-key := $(CONFIG_MODULE_SIG_KEY)
  61. endif
  62. quiet_cmd_sign = SIGN $@
  63. cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ \
  64. $(if $(KBUILD_EXTMOD),|| true)
  65. else
  66. quiet_cmd_sign :=
  67. cmd_sign := :
  68. endif
  69. ifeq ($(modules_sign_only),)
  70. $(dst)/%.ko: $(extmod_prefix)%.ko FORCE
  71. $(call cmd,install)
  72. $(call cmd,strip)
  73. $(call cmd,sign)
  74. ifneq ($(KBUILD_EXTMOD),)
  75. $(dst)/modules.order.$(extmod_suffix): $(MODORDER) FORCE
  76. $(call cmd,install)
  77. @sed -i "s:^$(KBUILD_EXTMOD):$(INSTALL_MOD_DIR):g" $@
  78. endif
  79. else
  80. $(dst)/%.ko: FORCE
  81. $(call cmd,sign)
  82. endif
  83. #
  84. # Compression
  85. #
  86. quiet_cmd_gzip = GZIP $@
  87. cmd_gzip = $(KGZIP) -n -f $<
  88. quiet_cmd_xz = XZ $@
  89. cmd_xz = $(XZ) --lzma2=dict=2MiB -f $<
  90. quiet_cmd_zstd = ZSTD $@
  91. cmd_zstd = $(ZSTD) -T0 --rm -f -q $<
  92. $(dst)/%.ko.gz: $(dst)/%.ko FORCE
  93. $(call cmd,gzip)
  94. $(dst)/%.ko.xz: $(dst)/%.ko FORCE
  95. $(call cmd,xz)
  96. $(dst)/%.ko.zst: $(dst)/%.ko FORCE
  97. $(call cmd,zstd)
  98. PHONY += FORCE
  99. FORCE:
  100. .PHONY: $(PHONY)