All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 01/11 v2] package-infra: add helper to build kernel modules
Date: Wed, 10 Jun 2015 21:22:05 +0200	[thread overview]
Message-ID: <a9355834b4604ad9989556affbddeb9926343abd.1433964001.git.yann.morin.1998@free.fr> (raw)
In-Reply-To: <cover.1433964001.git.yann.morin.1998@free.fr>

The Linux kernel offers a nice and easy-to-use infra to build
out-of-tree kernel modules.

Currently, we have quite a few packages that build kernel modules, and
most duplicate (or rewrite) the same code over-and-over again.

Introduce a new infrastructure that provides helpers to build kernel
modules, so packages do not have to duplicate/rewrite that.

The infrastructure, unlike any other package infra, is not standalone.
It needs another package infra to be used. This is so that packages that
provide both userland and kernel modules can be built easily. So, this
infra only defines post-build and post-install hooks, that will build
the kernel modules after the rest of the package.

Also, no host version is provided, since it does not make sense to build
kernel modules for the host.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Baruch Siach <baruch@tkos.co.il>
Cc: Arnout Vandecappelle <arnout@mind.be>

---
Changes v1 -> v2:
  - drop third and fourth args to inner macro: we're never going to
    build kernel modules for the host  (Baruch, Arnout)
  - add missing LINUX_MAKE_ENV  (Arnout)
  - use $$(@D), not $$($(2)_DIR)  (Arnout)
  - print a single MESSAGE  (Arnout, Thomas)
  - typoes  (Arnout)
---
 package/Makefile.in          |  1 +
 package/pkg-kernel-module.mk | 89 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 package/pkg-kernel-module.mk

diff --git a/package/Makefile.in b/package/Makefile.in
index c02d31f..180fd46 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -398,3 +398,4 @@ include package/pkg-virtual.mk
 include package/pkg-generic.mk
 include package/pkg-kconfig.mk
 include package/pkg-rebar.mk
+include package/pkg-kernel-module.mk
diff --git a/package/pkg-kernel-module.mk b/package/pkg-kernel-module.mk
new file mode 100644
index 0000000..608c9e6
--- /dev/null
+++ b/package/pkg-kernel-module.mk
@@ -0,0 +1,89 @@
+################################################################################
+# kernel module infrastructure for building Linux kernel modules
+#
+# This file implements an infrastructure that eases development of package
+# .mk files for out-of-tree Linux kernel modules. It should be used for all
+# packages that build a Linux kernel module using the kernel's out-of-tree
+# buildsystem, unless they use a complex custom build-system.
+#
+# In terms of implementation, this infrastructure relies on another package
+# infrastructure, and only defines post-build and post-install hooks, so that
+# packages can both build user-space (with any of the other *-package infra)
+# and/or build kernel modules.
+#
+# As such, it is to be used in conjunction with another *-package infra,
+# like so:
+#
+#   $(eval $(kernel-module))
+#   $(eval $(generic-package))
+#
+# Note: if the caller needs access to the kernel modules (either after they
+# are built or after they are installed), it will have to define its own
+# post-build/install hooks after calling kernel-module, but before calling
+# the other *-package infra, like so:
+#
+#   $(eval $(kernel-module))
+#   define FOO_MOD_TWEAK
+#   	# do something
+#   endef
+#   FOO_POST_BUILD_HOOKS += FOO_MOD_TWEAK
+#   $(eval $(generic-package))
+#
+# Note: this infra does not check that the kernel is enabled; it is expected
+# to be enforced at the Kconfig level with proper 'depends on'.
+################################################################################
+
+################################################################################
+# inner-kernel-module -- generates the make targets needed to support building
+# a kernel module
+#
+#  argument 1 is the lowercase package name
+#  argument 2 is the uppercase package name
+################################################################################
+
+define inner-kernel-module
+
+# The kernel must be built first.
+$(2)_DEPENDENCIES += linux
+
+# This is only defined in some infrastructures (e.g. autotools, cmake), but
+# not in others (generic). So define it if not already defined.
+$(2)_MAKE ?= $$(MAKE)
+
+# If not specified, consider the source of the kernel module to be at
+# the root of the package.
+$(2)_MODULE_SUBDIRS ?= .
+
+# Build the kernel module(s)
+define $(2)_KERNEL_MODULES_BUILD
+	@$$(call MESSAGE,"Building kernel module(s)")
+	$$(foreach d,$$($(2)_MODULE_SUBDIRS), \
+		$$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
+			-C $$(LINUX_DIR) \
+			$$(LINUX_MAKE_FLAGS) \
+			$$($(2)_MODULE_MAKE_OPTS) \
+			M=$$(@D)/$$(d) \
+			modules$$(sep))
+endef
+$(2)_POST_BUILD_HOOKS += $(2)_KERNEL_MODULES_BUILD
+
+# Install the kernel module(s)
+define $(2)_KERNEL_MODULES_INSTALL
+	@$$(call MESSAGE,"Installing kernel module(s)")
+	$$(foreach d,$$($(2)_MODULE_SUBDIRS), \
+		$$(LINUX_MAKE_ENV) $$($$(PKG)_MAKE) \
+			-C $$(LINUX_DIR) \
+			$$(LINUX_MAKE_FLAGS) \
+			$$($(2)_MODULE_MAKE_OPTS) \
+			M=$$(@D)/$$(d) \
+			modules_install$$(sep))
+endef
+$(2)_POST_INSTALL_TARGET_HOOKS += $(2)_KERNEL_MODULES_INSTALL
+
+endef
+
+################################################################################
+# kernel-module -- the target generator macro for kernel module packages
+################################################################################
+
+kernel-module = $(call inner-kernel-module,$(pkgname),$(call UPPERCASE,$(pkgname)))
-- 
1.9.1

  reply	other threads:[~2015-06-10 19:22 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 19:22 [Buildroot] [PATCH 0/11 v2] pkg-kernel-module: new infra to ease building kernel modules (branch yem/kernel-modules) Yann E. MORIN
2015-06-10 19:22 ` Yann E. MORIN [this message]
2015-06-10 21:08   ` [Buildroot] [PATCH 01/11 v2] package-infra: add helper to build kernel modules rdkehn at yahoo.com
2015-06-11 18:05     ` Yann E. MORIN
2015-06-11 22:44   ` Arnout Vandecappelle
2015-06-12 17:46     ` Yann E. MORIN
2015-06-12 22:52       ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 02/11 v2] docs/manual: add kernel-module Yann E. MORIN
2015-06-11  7:32   ` Jeremy Rosen
2015-06-11 18:06     ` Yann E. MORIN
2015-06-12  6:54       ` Jeremy Rosen
2015-06-10 19:22 ` [Buildroot] [PATCH 03/11 v2] package/lttng-modules: use kernel-module helper Yann E. MORIN
2015-06-11 22:44   ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 04/11 v2] package/igh-ethercat: " Yann E. MORIN
2015-06-11 22:51   ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 05/11 v2] package/ktap: " Yann E. MORIN
2015-06-11 22:53   ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 06/11 v2] package/cryptodev-linux: use the " Yann E. MORIN
2015-06-11 23:02   ` Arnout Vandecappelle
2015-06-12 20:48     ` Yann E. MORIN
2015-06-10 19:22 ` [Buildroot] [PATCH 07/11 v2] package/ocf-linux: use " Yann E. MORIN
2015-06-10 19:22 ` [Buildroot] [PATCH 08/11 v2] package/on2-8170-modules: " Yann E. MORIN
2015-06-11 23:04   ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 09/11 v2] package/owl-linux: " Yann E. MORIN
2015-06-11 23:13   ` Arnout Vandecappelle
2015-06-12 17:55     ` Yann E. MORIN
2015-06-12 23:19       ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 10/11 v2] package/simicsfs: " Yann E. MORIN
2015-06-11 23:13   ` Arnout Vandecappelle
2015-06-10 19:22 ` [Buildroot] [PATCH 11/11 v2] package/sysdig: " Yann E. MORIN
2015-06-11 18:03 ` [Buildroot] [PATCH 0/11 v2] pkg-kernel-module: new infra to ease building kernel modules (branch yem/kernel-modules) Yann E. MORIN
2015-06-11 23:18   ` Arnout Vandecappelle
2015-06-12 17:47     ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a9355834b4604ad9989556affbddeb9926343abd.1433964001.git.yann.morin.1998@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.