pkg-kernel-module.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ################################################################################
  2. # kernel module infrastructure for building Linux kernel modules
  3. #
  4. # This file implements an infrastructure that eases development of package
  5. # .mk files for out-of-tree Linux kernel modules. It should be used for all
  6. # packages that build a Linux kernel module using the kernel's out-of-tree
  7. # buildsystem, unless they use a complex custom buildsystem.
  8. #
  9. # The kernel-module infrastructure requires the packages that use it to also
  10. # use another package infrastructure. kernel-module only defines post-build
  11. # and post-install hooks. This allows the package to build both kernel
  12. # modules and/or user-space components (with any of the other *-package
  13. # infra).
  14. #
  15. # As such, it is to be used in conjunction with another *-package infra,
  16. # like so:
  17. #
  18. # $(eval $(kernel-module))
  19. # $(eval $(generic-package))
  20. #
  21. # Note: if the caller needs access to the kernel modules (either after they
  22. # are built or after they are installed), it will have to define its own
  23. # post-build/install hooks *after* calling kernel-module, but *before*
  24. # calling the other *-package infra, like so:
  25. #
  26. # $(eval $(kernel-module))
  27. # define FOO_MOD_TWEAK
  28. # # do something
  29. # endef
  30. # FOO_POST_BUILD_HOOKS += FOO_MOD_TWEAK
  31. # $(eval $(generic-package))
  32. #
  33. # Note: this infra does not check that the kernel is enabled; it is expected
  34. # to be enforced at the Kconfig level with proper 'depends on'.
  35. ################################################################################
  36. ################################################################################
  37. # inner-kernel-module -- generates the make targets needed to support building
  38. # a kernel module
  39. #
  40. # argument 1 is the lowercase package name
  41. # argument 2 is the uppercase package name
  42. ################################################################################
  43. define inner-kernel-module
  44. # If the package is enabled, ensure the kernel will support modules
  45. ifeq ($$(BR2_PACKAGE_$(2)),y)
  46. LINUX_NEEDS_MODULES = y
  47. endif
  48. # The kernel must be built first.
  49. $(2)_DEPENDENCIES += linux
  50. # This is only defined in some infrastructures (e.g. autotools, cmake),
  51. # but not in others (e.g. generic). So define it here as well.
  52. $(2)_MAKE ?= $$(MAKE)
  53. # If not specified, consider the source of the kernel module to be at
  54. # the root of the package.
  55. $(2)_MODULE_SUBDIRS ?= .
  56. # Build the kernel module(s)
  57. # Force PWD for those packages that want to use it to find their
  58. # includes and other support files (Booo!)
  59. define $(2)_KERNEL_MODULES_BUILD
  60. @$$(call MESSAGE,"Building kernel module(s)")
  61. $$(foreach d,$$($(2)_MODULE_SUBDIRS), \
  62. $$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
  63. -C $$(LINUX_DIR) \
  64. $$(LINUX_MAKE_FLAGS) \
  65. $$($(2)_MODULE_MAKE_OPTS) \
  66. PWD=$$(@D)/$$(d) \
  67. M=$$(@D)/$$(d) \
  68. modules$$(sep))
  69. endef
  70. $(2)_POST_BUILD_HOOKS += $(2)_KERNEL_MODULES_BUILD
  71. # Install the kernel module(s)
  72. # Force PWD for those packages that want to use it to find their
  73. # includes and other support files (Booo!)
  74. define $(2)_KERNEL_MODULES_INSTALL
  75. @$$(call MESSAGE,"Installing kernel module(s)")
  76. $$(foreach d,$$($(2)_MODULE_SUBDIRS), \
  77. $$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
  78. -C $$(LINUX_DIR) \
  79. $$(LINUX_MAKE_FLAGS) \
  80. $$($(2)_MODULE_MAKE_OPTS) \
  81. PWD=$$(@D)/$$(d) \
  82. M=$$(@D)/$$(d) \
  83. modules_install$$(sep))
  84. endef
  85. $(2)_POST_INSTALL_TARGET_HOOKS += $(2)_KERNEL_MODULES_INSTALL
  86. endef
  87. ################################################################################
  88. # kernel-module -- the target generator macro for kernel module packages
  89. ################################################################################
  90. kernel-module = $(call inner-kernel-module,$(pkgname),$(call UPPERCASE,$(pkgname)))