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
15 # As such, it is to be used in conjunction with another *-package infra,
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
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
41 # argument 1 is the lowercase package name
42 # argument 2 is the uppercase package name
43 ################################################################################
45 define inner-kernel-module
47 # The kernel must be built first.
48 $(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.
54 # If not specified, consider the source of the kernel module to be at
55 # the root of the package.
56 $(2)_MODULE_SUBDIRS ?
= .
58 # Build the kernel module(s)
59 # Force PWD for those packages that want to use it to find their
60 # includes and other support files (Booo!)
61 define $(2)_KERNEL_MODULES_BUILD
62 @
$$(call MESSAGE
,"Building kernel module(s)")
63 $$(foreach d
,$$($(2)_MODULE_SUBDIRS
), \
64 $$(LINUX_MAKE_ENV
) $$($$(PKG
)_MAKE
) \
66 $$(LINUX_MAKE_FLAGS
) \
67 $$($(2)_MODULE_MAKE_OPTS
) \
72 $(2)_POST_BUILD_HOOKS
+= $(2)_KERNEL_MODULES_BUILD
74 # Install the kernel module(s)
75 # Force PWD for those packages that want to use it to find their
76 # includes and other support files (Booo!)
77 define $(2)_KERNEL_MODULES_INSTALL
78 @
$$(call MESSAGE
,"Installing kernel module(s)")
79 $$(foreach d
,$$($(2)_MODULE_SUBDIRS
), \
80 $$(LINUX_MAKE_ENV
) $$($$(PKG
)_MAKE
) \
82 $$(LINUX_MAKE_FLAGS
) \
83 $$($(2)_MODULE_MAKE_OPTS
) \
86 modules_install
$$(sep
))
88 $(2)_POST_INSTALL_TARGET_HOOKS
+= $(2)_KERNEL_MODULES_INSTALL
92 ################################################################################
93 # kernel-module -- the target generator macro for kernel module packages
94 ################################################################################
96 kernel-module
= $(call inner-kernel-module
,$(pkgname
),$(call UPPERCASE
,$(pkgname
)))