package/upmpcli: bump to version 0.13.1
[buildroot-gz.git] / package / pkg-kernel-module.mk
blob200c91dfef01f21ff2d0e50e4db5fb4f9932fffb
1 ################################################################################
2 # kernel module infrastructure for building Linux kernel modules
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.
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).
15 # As such, it is to be used in conjunction with another *-package infra,
16 # like so:
18 # $(eval $(kernel-module))
19 # $(eval $(generic-package))
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:
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))
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 ################################################################################
37 ################################################################################
38 # inner-kernel-module -- generates the make targets needed to support building
39 # a kernel module
41 # argument 1 is the lowercase package name
42 # argument 2 is the uppercase package name
43 ################################################################################
45 define inner-kernel-module
47 # If the package is enabled, ensure the kernel will support modules
48 ifeq ($$(BR2_PACKAGE_$(2)),y)
49 LINUX_NEEDS_MODULES = y
50 endif
52 # The kernel must be built first.
53 $(2)_DEPENDENCIES += linux
55 # This is only defined in some infrastructures (e.g. autotools, cmake),
56 # but not in others (e.g. generic). So define it here as well.
57 $(2)_MAKE ?= $$(MAKE)
59 # If not specified, consider the source of the kernel module to be at
60 # the root of the package.
61 $(2)_MODULE_SUBDIRS ?= .
63 # Build the kernel module(s)
64 # Force PWD for those packages that want to use it to find their
65 # includes and other support files (Booo!)
66 define $(2)_KERNEL_MODULES_BUILD
67 @$$(call MESSAGE,"Building kernel module(s)")
68 $$(foreach d,$$($(2)_MODULE_SUBDIRS), \
69 $$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
70 -C $$(LINUX_DIR) \
71 $$(LINUX_MAKE_FLAGS) \
72 $$($(2)_MODULE_MAKE_OPTS) \
73 PWD=$$(@D)/$$(d) \
74 M=$$(@D)/$$(d) \
75 modules$$(sep))
76 endef
77 $(2)_POST_BUILD_HOOKS += $(2)_KERNEL_MODULES_BUILD
79 # Install the kernel module(s)
80 # Force PWD for those packages that want to use it to find their
81 # includes and other support files (Booo!)
82 define $(2)_KERNEL_MODULES_INSTALL
83 @$$(call MESSAGE,"Installing kernel module(s)")
84 $$(foreach d,$$($(2)_MODULE_SUBDIRS), \
85 $$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
86 -C $$(LINUX_DIR) \
87 $$(LINUX_MAKE_FLAGS) \
88 $$($(2)_MODULE_MAKE_OPTS) \
89 PWD=$$(@D)/$$(d) \
90 M=$$(@D)/$$(d) \
91 modules_install$$(sep))
92 endef
93 $(2)_POST_INSTALL_TARGET_HOOKS += $(2)_KERNEL_MODULES_INSTALL
95 endef
97 ################################################################################
98 # kernel-module -- the target generator macro for kernel module packages
99 ################################################################################
101 kernel-module = $(call inner-kernel-module,$(pkgname),$(call UPPERCASE,$(pkgname)))