Skip to contentSkip to conversation

core: new infra to ease building kernel modules (branch yem/kernel-modules)

PATCH New Yann E. MORIN 2 participants 13 messages Jul 12, 2015 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

v3 cover core: new infra to ease building kernel modules (branch yem/kernel-modules)

Hello All!

This series introduces a new infrastructure to help writing packages that build kernel modules.

Unlike other package infrastrucutre, this new kernel-module infrastructure is not stand-alone, but is made as a complement to existing infrastructures, so that packages can build both userland and kernel modules.

A few packages (9) are converted to use that new infrastructure, and it greatly simplifies most of them (even allowing us to drop some of our patches).

Furthermore, as a side effect of converting it to this new inra, it also fixes the sysdig package, which is cirrently broken because it tries to build with the host kernel.

Unfortunately, not all packages that build kernel headers were converted, becasue they use very custom (aka convoluted) Makefiles to reinvent out-of-tree module building, and it is too much work to fix them.

Changes v2 -> v3:
- better documentation (Arnout, Jeremy)
- better commit logs (Arnout, Doug)
- drop more variables (Arnout)
- override PWD in the infra, not per-package

Changes v1 -> v2:
- drop third and fourth args to inner macros (unneeded), fix comments about inner macros (Arnout, Baruch)
- add LINU_MAKE_ENV (Arnout)
- be less verbose, print a single MESSAGE (Thomas, Arnout)
- rephrase parts of the manual (Arnout)
- explain now-missing variable in ktap (Thomas)
- fix crypto-dev (Doug)
- fix owl-linux

Regards,
Yann E. MORIN.

The following changes since commit 98573709465cd0cf27f31e219cc51f8e5535ff11:

package/x11r7/xdriver_xf86-input-libinput: bump version to 0.11.0 (2015-07-12 00:52:28 +0200)

are available in the git repository at:

git://git.busybox.net/~ymorin/git/buildroot yem/kernel-modules

for you to fetch changes up to 643b9f65eee71f7f842fcb640af562a9c11d80d8:

package/sysdig: use kernel-module helper (2015-07-12 02:14:34 +0200)

----------------------------------------------------------------
Yann E. MORIN (11):
package-infra: add helper to build kernel modules docs/manual: add kernel-module package/lttng-modules: use kernel-module helper package/igh-ethercat: use kernel-module helper package/ktap: use kernel-module helper package/cryptodev-linux: use the kernel-module helper package/ocf-linux: use kernel-module helper package/on2-8170-modules: use kernel-module helper package/owl-linux: use kernel-module helper package/simicsfs: use kernel-module helper package/sysdig: use kernel-module helper

 docs/manual/adding-packages-kernel-module.txt      | 142 +++++++++++++++++++++
 docs/manual/adding-packages.txt                    |   2 +
 package/Makefile.in                                |   1 +
 package/cryptodev-linux/cryptodev-linux.mk         |  12 +-
 package/igh-ethercat/igh-ethercat.mk               |  14 +-
 package/ktap/ktap.mk                               |   7 +-
 package/lttng-modules/lttng-modules.mk             |  11 +-
 package/ocf-linux/0001-modules-cross.patch         |  42 ------
 package/ocf-linux/ocf-linux.mk                     |  17 +--
 package/on2-8170-modules/on2-8170-modules.mk       |  11 +-
 .../0001-fix-CROSS_COMPILE-usage-in-Makefile.patch |  16 ---
 ...-3.3.x.patch => 0001-fix-for-linux-3.3.x.patch} |   0
 package/owl-linux/owl-linux.mk                     |  11 +-
 package/pkg-kernel-module.mk                       |  96 ++++++++++++++
 package/simicsfs/simicsfs.mk                       |  10 +-
 package/sysdig/sysdig.mk                           |  22 +++-
 16 files changed, 278 insertions(+), 136 deletions(-)
 create mode 100644 docs/manual/adding-packages-kernel-module.txt
 delete mode 100644 package/ocf-linux/0001-modules-cross.patch
 delete mode 100644 package/owl-linux/0001-fix-CROSS_COMPILE-usage-in-Makefile.patch
 rename package/owl-linux/{0002-fix-for-linux-3.3.x.patch => 0001-fix-for-linux-3.3.x.patch} (100%)
 create mode 100644 package/pkg-kernel-module.mk
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH v3 1/11 package-infra: add helper to build kernel modules

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.

We need to override PWD, because some packages will use it to find their own includes (and other helper files). PWD is inherited from the environment, so it gets whatever value it had when make was launched, which happens to be Buildroot's own top source tree. So, we just force PWD to the proper value, rather than cd-ing first.

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

Cc Thomas Petazzoni <[email protected]>
Cc Baruch Siach <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---
Changes v2 -> v3:
- override PWD

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 | 96 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 package/pkg-kernel-module.mk
package/Makefile.in +1 -0
index 2ed7cf7..545694f 100644
@@ -399,3 +399,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
package/pkg-kernel-module.mk new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/11 docs/manual: add kernel-module

In reply to Yann E. MORIN
Cc Thomas Petazzoni <[email protected]>
Cc Samuel Martin <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Cc Jeremy Rosen <[email protected]>

---
Changes v2 -> v3;
- document a few usefull variables (Arnout, Jeremy)

Changes v1 -> v2:
- some rephrasing and refactoring (Arnout)

---
 docs/manual/adding-packages-kernel-module.txt | 142 ++++++++++++++++++++++++++
 docs/manual/adding-packages.txt               |   2 +
 2 files changed, 144 insertions(+)
 create mode 100644 docs/manual/adding-packages-kernel-module.txt
docs/manual/adding-packages-kernel-module.txt new file +142 -0
new file mode 100644
index 0000000..39575f7
@@ -0,0 +1,142 @@
+// -*- mode:doc; -*-
+// vim: set syntax=asciidoc:
+
+=== Infrastructure for packages building kernel modules
+
+Buildroot offers a helper infrastructure to make it easy to write packages that
+build and install Linux kernel modules. Some packages only contain a kernel
+module, other packages contain programs and libraries in addition to kernel
+modules. Buildroot's helper infrastructure supports either case.
+
+[[kernel-module-tutorial]]
+==== +kernel-module+ tutorial
+
+Let's start with an example on how to prepare a simple package that only
+builds a kernel module, and no other component:
+
+----
+01: ################################################################################
+02: #
+03: # foo
+04: #
+05: ################################################################################
+06: 
+07: FOO_VERSION = 1.2.3
+08: FOO_SOURCE = foo-$(FOO_VERSION).tar.xz
+09: FOO_SITE = http://www.foosoftware.org/download
+10: FOO_LICENSE = GPLv2
+11: FOO_LICENSE_FILES = COPYING
+12: 
+13: $(eval $(kernel-module))
+14: $(eval $(generic-package))
+----
+
+Lines 7-11 define the usual meta-data to specify the version, archive name,
+remote URI where to find the package source, licensing information.
+
+On line 13, we invoke the +kernel-module+ helper infrastructure, that
+generates all the appropriate Makefile rules and variables to build
+that kernel module.
+
+Finally, on line 14, we invoke the
+xref:generic-package-tutorial[+generic-package+ infrastructure].
+
+The dependency on +linux+ is automatically added, so it is not needed to
+specify it in +FOO_DEPENDENCIES+.
+
+What you may have noticed is that, unlike other package infrastructures,
+we explicitly invoke a second infrastructure. This allows a package to
+build a kernel module, but also, if needed, use any one of other package
+infrastructures to build normal userland components (libraries,
+executables...). Using the +kernel-module+ infrastructure on its own is
+not sufficient; another package infrastructure *must* be used.
+
+Let's look at a more complex example:
+
+----
+01: ################################################################################
+02: #
+03: # foo
+04: #
+05: ################################################################################
+06: 
+07: FOO_VERSION = 1.2.3
+08: FOO_SOURCE = foo-$(FOO_VERSION).tar.xz
+09: FOO_SITE = http://www.foosoftware.org/download
+10: FOO_LICENSE = GPLv2
+11: FOO_LICENSE_FILES = COPYING
+12: 
+13: FOO_MODULE_SUBDIRS = driver/base
+14: FOO_MODULE_MAKE_OPTS = KVERSION=$(LINUX_VERSION_PROBED)
+15: 
+16: ifeq ($(BR2_PACKAGE_LIBBAR),y)
+17: FOO_DEPENDENCIES = libbar
+18: FOO_CONF_OPTS = --enable-bar
+19: FOO_MODULE_SUBDIRS += driver/bar
+20: else
+21: FOO_CONF_OPTS = --disable-bar
+22: endif
+23: 
+24: $(eval $(kernel-module))
+26: $(eval $(autotools-package))
+----
+
+Here, we see that we have an autotools-based package, that also builds
+the kernel module located in sub-directory +driver/base+ and, if libbar
+is enabled, the kernel module located in sub-directory +driver/bar+, and
+defines the variable +KVERSION+ to be passed to the Linux buildsystem
+when building the module(s).
+
+
+[[kernel-module-reference]]
+==== +kernel-module+ reference
+
+The main macro for the  kernel module infrastructure is +kernel-module+.
+Unlike other package infrastructures, it is not stand-alone, and requires
+any of the other +*-package+ macros be called after it.
+
+The +kernel-module+ macro defines post-build and post-target-install
+hooks to build the kernel modules. If the package's +.mk+ needs access
+to the built kernel modules, it should do so in a post-build hook,
+*registered after* the call to +kernel-module+. Similarly, if the
+package's +.mk+ needs access to the kernel module after it has been
+installed, it should do so in a post-install hook, *registered after*
+the call to +kernel-module+. Here's an example:
+
+----
+$(eval $(kernel-module))
+
+define FOO_DO_STUFF_WITH_KERNEL_MODULE
+    # Do something with it...
+endef
+FOO_POST_BUILD_HOOKS += FOO_DO_STUFF_WITH_KERNEL_MODULE
+
+$(eval $(generic-package))
+----
+
+Finally, unlike the other package infrastructures, there is no
++host-kernel-module+ variant to build a host kernel module.
+
+The following additional variables can optionally be defined to further
+configure the build of the kernel module:
+
+* +FOO_MODULE_SUBDIRS+ may be set to one or more sub-directories (relative
+  to the package source top-directory) where the kernel module sources are.
+  If empty or not set, the sources for the kernel module(s) are considered
+  to be located at the top of the package source tree.
+
+* +FOO_MODULE_MAKE_OPTS+ may be set to contain extra variable definitions
+  to pass to the Linux buildsystem.
+
+Yo may also reference (but you may *not* set!) those variables:
+
+ * +LINUX_DIR+ contains the path to where the Linux kernel has been
+   extracted and built.
+
+ * +LINUX_VERSION+ contains the version string as configured by the user.
+
+ * +LINUX_VERSION_PROBED+ contains the real version string of the kernel,
+   retrieved with running `make -C $(LINUX_DIR) kernelrelease`
+
+ * +KERNEL_ARCH+ contains the name of the current architecture, like `arm`,
+   `mips`...
docs/manual/adding-packages.txt +2 -0
index b8674f8..721fe39 100644
@@ -29,6 +29,8 @@ include::adding-packages-kconfig.txt[]
 
 include::adding-packages-rebar.txt[]
 
+include::adding-packages-kernel-module.txt[]
+
 include::adding-packages-asciidoc.txt[]
 
 include::adding-packages-hooks.txt[]
Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 3/11 package/lttng-modules: use kernel-module helper

In reply to Yann E. MORIN

lttng-modules' Makefile already uses the Linux buildsystem to build its modules, so just switch to using the new kernel-module infra.

To be noted: lttng-modules' Makefile uses $(shell pwd) that expects the PWD to be the Linux' top build directory, which is not the case for us. However, it uses to detect a conflict between a stale static version.h and a generated version.h (due to the switch to uapi). This is of no consequence to us, because we can't have a Linux build directory with such stale files.

---
 package/lttng-modules/lttng-modules.mk | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
package/lttng-modules/lttng-modules.mk +1 -10
index 6833ad2..30c581e 100644
@@ -10,14 +10,5 @@ LTTNG_MODULES_SOURCE = lttng-modules-$(LTTNG_MODULES_VERSION).tar.bz2
 LTTNG_MODULES_LICENSE = LGPLv2.1/GPLv2 for kernel modules; MIT for lib/bitfield.h and lib/prio_heap/*
 LTTNG_MODULES_LICENSE_FILES = lgpl-2.1.txt gpl-2.0.txt mit-license.txt LICENSE
 
-LTTNG_MODULES_DEPENDENCIES = linux
-
-define LTTNG_MODULES_BUILD_CMDS
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNELDIR=$(LINUX_DIR)
-endef
-
-define LTTNG_MODULES_INSTALL_TARGET_CMDS
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNELDIR=$(LINUX_DIR) modules_install
-endef
-
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#4 lore raw

PATCH v3 4/11 package/igh-ethercat: use kernel-module helper

In reply to Yann E. MORIN

igh-ethercat's Makefile just contains calls to the Linux buildsystem, that do exactly what we now do with our kernel-module infra.

---
 package/igh-ethercat/igh-ethercat.mk | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
package/igh-ethercat/igh-ethercat.mk +1 -13
index b5221f8..32c49a3 100644
@@ -10,7 +10,6 @@ IGH_ETHERCAT_SOURCE = ethercat-$(IGH_ETHERCAT_VERSION).tar.bz2
 IGH_ETHERCAT_LICENSE = GPLv2 (IgH EtherCAT master), LGPLv2.1 (libraries)
 IGH_ETHERCAT_LICENSE_FILES = COPYING COPYING.LESSER
 
-IGH_ETHERCAT_DEPENDENCIES = linux
 IGH_ETHERCAT_INSTALL_STAGING = YES
 
 IGH_ETHERCAT_CONF_OPTS = \
@@ -22,16 +21,5 @@ IGH_ETHERCAT_CONF_OPTS += $(if $(BR2_PACKAGE_IGH_ETHERCAT_E1000),--enable-e1000,
 IGH_ETHERCAT_CONF_OPTS += $(if $(BR2_PACKAGE_IGH_ETHERCAT_E1000E),--enable-e1000e,--disable-e1000e)
 IGH_ETHERCAT_CONF_OPTS += $(if $(BR2_PACKAGE_IGH_ETHERCAT_R8169),--enable-r8169,--disable-r8169)
 
-define IGH_ETHERCAT_BUILD_MODULES
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) modules
-endef
-
-IGH_ETHERCAT_POST_BUILD_HOOKS += IGH_ETHERCAT_BUILD_MODULES
-
-define IGH_ETHERCAT_INSTALL_MODULES
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) modules_install
-endef
-
-IGH_ETHERCAT_POST_INSTALL_TARGET_HOOKS += IGH_ETHERCAT_INSTALL_MODULES
-
+$(eval $(kernel-module))
 $(eval $(autotools-package))
Signature · 1 line
1.9.1
#5 lore raw

PATCH v3 5/11 package/ktap: use kernel-module helper

In reply to Yann E. MORIN

Passing the KERNEL_SRC variable is no longer needed, since it was only used to run commands like:

    $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules

which is basically what the new kernel-module infra is now doing.

---
Changes v1 -> v2;
- explain why we get rid of a variable (Thomas)

---
 package/ktap/ktap.mk | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
package/ktap/ktap.mk +3 -4
index 4a0e51c..966b51c 100644
@@ -9,8 +9,6 @@ KTAP_SITE = $(call github,ktap,ktap,$(KTAP_VERSION))
 KTAP_LICENSE = GPLv2
 KTAP_LICENSE_FILES = LICENSE-GPL
 
-KTAP_DEPENDENCIES = linux
-
 ifeq ($(BR2_PACKAGE_ELFUTILS),y)
 KTAP_DEPENDENCIES += elfutils
 else
@@ -19,12 +17,13 @@ endif
 
 define KTAP_BUILD_CMDS
 	$(MAKE) -C $(@D) $(TARGET_CONFIGURE_OPTS) $(KTAP_FLAGS) ktap
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNEL_SRC=$(LINUX_DIR) KVERSION=$(LINUX_VERSION_PROBED) mod
 endef
 
 define KTAP_INSTALL_TARGET_CMDS
 	$(INSTALL) -D -m755 $(@D)/ktap  $(TARGET_DIR)/usr/bin/ktap
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNEL_SRC=$(LINUX_DIR) KVERSION=$(LINUX_VERSION_PROBED) modules_install
 endef
 
+KTAP_MODULE_MAKE_OPTS = KVERSION=$(LINUX_VERSION_PROBED)
+
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#6 lore raw

PATCH v3 6/11 package/cryptodev-linux: use the kernel-module helper

In reply to Yann E. MORIN

The kernel module needs the version.h headers at build-time, but the Makefile only generates it when the module is built with that Makefile, because it has this rule:

    build: version.h
        make ${KERNEL_MAKE_OPTS} modules

So, we must explicitly build this header, which we do in a pre-build hook to ensure it comes before the kernel-module's own hooks. This header needs not be installed in staging.

However, the cryptodev.h header still needs to be installed in staging, which we still do in a staging-install command.

The KERNEL_DIR and PREFIX variables are no longer needed, because we're no longer calling the rules that needed them (build, above, and modules_install, both now handled by the kernel-module infra).

[Doug: add pre-build hook to build version.h]

---
Changes v2 -> v3;
- expand commit log (Arnout, Doug)
- PREFIX and KERNEL_DIR are not needed (Arnout)
- rename hook

Changes v1 -> v2:
- fix missing version.h (Doug)

---
 package/cryptodev-linux/cryptodev-linux.mk | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
package/cryptodev-linux/cryptodev-linux.mk +4 -8
index 6f41930..6001c71 100644
@@ -6,23 +6,19 @@
 
 CRYPTODEV_LINUX_VERSION = 1.7
 CRYPTODEV_LINUX_SITE = http://download.gna.org/cryptodev-linux
-CRYPTODEV_LINUX_DEPENDENCIES = linux
 CRYPTODEV_LINUX_INSTALL_STAGING = YES
 CRYPTODEV_LINUX_LICENSE = GPLv2+
 CRYPTODEV_LINUX_LICENSE_FILES = COPYING
 
-define CRYPTODEV_LINUX_BUILD_CMDS
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNEL_DIR=$(LINUX_DIR)
-endef
-
-define CRYPTODEV_LINUX_INSTALL_TARGET_CMDS
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNEL_DIR=$(LINUX_DIR) \
-		PREFIX=$(TARGET_DIR) modules_install
+define CRYPTODEV_LINUX_MODULE_GEN_VERSION_H
+	$(MAKE) -C $(@D) version.h
 endef
+CRYPTODEV_LINUX_PRE_BUILD_HOOKS += CRYPTODEV_LINUX_MODULE_GEN_VERSION_H
 
 define CRYPTODEV_LINUX_INSTALL_STAGING_CMDS
 	$(INSTALL) -D -m 644 $(@D)/crypto/cryptodev.h \
 		$(STAGING_DIR)/usr/include/crypto/cryptodev.h
 endef
 
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#7 lore raw

PATCH v3 7/11 package/ocf-linux: use kernel-module helper

In reply to Yann E. MORIN

We have a patch that makes ocf-linux' Makefile basically only call to the Linux buildsystem, with commands basically like:

    make -C $(LINUX_DIR) M=$(pwd) modules

which is basically what our new kernel-module infra basically does.

Remove our patch since it is basically no longer needed.

Basically-Signed-off-by "Yann E. MORIN" <[email protected]>

---
Changs v1 -> v2:
- fix spelling of the SUBDIRS variable

---
 package/ocf-linux/0001-modules-cross.patch | 42 ------------------------------
 package/ocf-linux/ocf-linux.mk             | 17 +++++-------
 2 files changed, 7 insertions(+), 52 deletions(-)
 delete mode 100644 package/ocf-linux/0001-modules-cross.patch
package/ocf-linux/0001-modules-cross.patch deleted +0 -42
deleted file mode 100644
index f80ef06..0000000
@@ -1,42 +0,0 @@
-Remove the OCF linux kernel extension instead opting to build ocf-linux
-modules out of tree.
-This is easier for users since no kernel config tweaking is required.
-On the downside the OCF drivers can't be used, but then all of the
-kernel crypto drivers are available to users via cryptosoft which is
-preferred.
-
-Signed-off-by: Gustavo Zacarias <[email protected]>
-
-diff -Nura ocf-linux-20120127.orig/ocf/Makefile ocf-linux-20120127/ocf/Makefile
---- ocf-linux-20120127.orig/ocf/Makefile	2013-04-27 09:27:04.413911866 -0300
-+++ ocf-linux-20120127/ocf/Makefile	2013-04-27 09:27:31.131775576 -0300
-@@ -2,6 +2,7 @@
- -include $(ROOTDIR)/modules/.config
-
- OCF_OBJS = crypto.o criov.o
-+KDIR ?= /lib/modules/$(shell uname -r)/build
-
- ifdef CONFIG_OCF_RANDOMHARVEST
- 	OCF_OBJS += random.o
-@@ -78,20 +79,13 @@
- #
-
- ocf_make:
--	make -C /lib/modules/$(shell uname -r)/build M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m
--	make -C /lib/modules/$(shell uname -r)/build M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m CONFIG_OCF_CRYPTOSOFT=m
--	-make -C /lib/modules/$(shell uname -r)/build M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m CONFIG_OCF_BENCH=m
--	-make -C /lib/modules/$(shell uname -r)/build M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m CONFIG_OCF_OCFNULL=m
--	-make -C /lib/modules/$(shell uname -r)/build M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m CONFIG_OCF_HIFN=m
-+	make -C $(KDIR) M=`pwd` $(OCF_TARGET) CONFIG_OCF_OCF=m CONFIG_OCF_CRYPTOSOFT=m CONFIG_OCF_BENCH=m CONFIG_OCF_OCFNULL=m
-
- ocf_modules:
- 	$(MAKE) ocf_make OCF_TARGET=modules
-
- ocf_install:
- 	$(MAKE) ocf_make OCF_TARGET="modules modules_install"
--	depmod
--	mkdir -p /usr/include/crypto
--	cp cryptodev.h /usr/include/crypto/.
-
- #
- # generate full kernel patches for 2.4 and 2.6 kernels to make patching
package/ocf-linux/ocf-linux.mk +7 -10
index 8ca5578..35968d5 100644
@@ -6,22 +6,19 @@
 
 OCF_LINUX_VERSION = 20120127
 OCF_LINUX_SITE = http://downloads.sourceforge.net/project/ocf-linux/ocf-linux/$(OCF_LINUX_VERSION)
-OCF_LINUX_DEPENDENCIES = linux
 OCF_LINUX_INSTALL_STAGING = YES
 
-define OCF_LINUX_BUILD_CMDS
-	$(MAKE) -C $(@D)/ocf $(LINUX_MAKE_FLAGS) KDIR=$(LINUX_DIR) \
-		ocf_modules
-endef
-
-define OCF_LINUX_INSTALL_TARGET_CMDS
-	$(MAKE) -C $(@D)/ocf $(LINUX_MAKE_FLAGS) KDIR=$(LINUX_DIR) \
-		ocf_install
-endef
+OCF_LINUX_MODULE_SUBDIRS = ocf
+OCF_LINUX_MODULE_MAKE_OPTS = \
+	CONFIG_OCF_OCF=m \
+	CONFIG_OCF_CRYPTOSOFT=m \
+	CONFIG_OCF_BENCH=m \
+	CONFIG_OCF_OCFNULL=m
 
 define OCF_LINUX_INSTALL_STAGING_CMDS
 	$(INSTALL) -D -m 644 $(@D)/ocf/cryptodev.h \
 		$(STAGING_DIR)/usr/include/crypto/cryptodev.h
 endef
 
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#8 lore raw

PATCH v3 8/11 package/on2-8170-modules: use kernel-module helper

In reply to Yann E. MORIN

We were already using the Linux buildsystem to build on2-8170-modules, so just switch to the new kernel-module infra.

---
 package/on2-8170-modules/on2-8170-modules.mk | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
package/on2-8170-modules/on2-8170-modules.mk +1 -10
index 209bcb5..b40ed86 100644
@@ -7,17 +7,8 @@
 ON2_8170_MODULES_VERSION = 73b08061d30789178e692bc332b73d1d9922bf39
 ON2_8170_MODULES_SITE = $(call github,alexandrebelloni,on2-8170-modules,$(ON2_8170_MODULES_VERSION))
 
-ON2_8170_MODULES_DEPENDENCIES = linux
-
 ON2_8170_MODULES_LICENSE = GPLv2+
 #There is no license file
 
-define ON2_8170_MODULES_BUILD_CMDS
-	$(MAKE) -C $(LINUX_DIR) $(LINUX_MAKE_FLAGS) M=$(@D)
-endef
-
-define ON2_8170_MODULES_INSTALL_TARGET_CMDS
-	$(MAKE) -C $(LINUX_DIR) $(LINUX_MAKE_FLAGS) M=$(@D) modules_install
-endef
-
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#9 lore raw

PATCH v3 9/11 package/owl-linux: use kernel-module helper

In reply to Yann E. MORIN

The owl-linux' Makefile is only calling the Linux buildsystem, so switch do using the new kernel-module infra.

Get rid of first patch, no longer needed; rename remaining patch.

---
Changes v2 -> v3;
- do not override PWD, done in the infra

Changes v1 -> v2:
- override $(PWD)

---
 .../0001-fix-CROSS_COMPILE-usage-in-Makefile.patch       | 16 ----------------
 ...-linux-3.3.x.patch => 0001-fix-for-linux-3.3.x.patch} |  0
 package/owl-linux/owl-linux.mk                           | 11 +----------
 3 files changed, 1 insertion(+), 26 deletions(-)
 delete mode 100644 package/owl-linux/0001-fix-CROSS_COMPILE-usage-in-Makefile.patch
 rename package/owl-linux/{0002-fix-for-linux-3.3.x.patch => 0001-fix-for-linux-3.3.x.patch} (100%)
package/owl-linux/0001-fix-CROSS_COMPILE-usage-in-Makefile.patch deleted +0 -16
deleted file mode 100644
index 14b4631..0000000
@@ -1,16 +0,0 @@
-Fix the owl-linux Makefile so that it protects spaces in the CROSS_COMPILE
-variable. For example, this variable will contain spaces if ccache is used.
-
-Signed-off-by: Simon Dawson <[email protected]>
-diff -Nurp a/Makefile b/Makefile
---- a/Makefile	2012-06-14 10:51:45.000000000 +0100
-+++ b/Makefile	2012-07-20 10:46:41.636752148 +0100
-@@ -35,7 +35,7 @@ else
- 	PWD := $(shell pwd)
- 
- default:
--	$(MAKE) -C $(KERNELDIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) MODE=$(MODE) modules
-+	$(MAKE) -C $(KERNELDIR) ARCH=$(ARCH) CROSS_COMPILE="$(CROSS_COMPILE)" M=$(PWD) MODE=$(MODE) modules
- 
- clean: 
- 	-rm -f *.o *.mod.c *.ko modules.order Module.symvers
package/owl-linux/0001-fix-for-linux-3.3.x.patch renamed from package/owl-linux/0002-fix-for-linux-3.3.x.patch +0 -0
similarity index 100%
rename from package/owl-linux/0002-fix-for-linux-3.3.x.patch
rename to package/owl-linux/0001-fix-for-linux-3.3.x.patch
package/owl-linux/owl-linux.mk +1 -10
index 371cc02..1262425 100644
@@ -10,14 +10,5 @@ OWL_LINUX_LICENSE = PROPRIETARY
 OWL_LINUX_LICENSE_FILES = LICENSE
 OWL_LINUX_REDISTRIBUTE = NO
 
-OWL_LINUX_DEPENDENCIES = linux
-
-define OWL_LINUX_BUILD_CMDS
-	$(MAKE) -C $(@D) $(LINUX_MAKE_FLAGS) KERNELDIR=$(LINUX_DIR)
-endef
-
-define OWL_LINUX_INSTALL_TARGET_CMDS
-	$(MAKE) -C $(LINUX_DIR) $(LINUX_MAKE_FLAGS) M="$(@D)" modules_install
-endef
-
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#10 lore raw

PATCH v3 10/11 package/simicsfs: use kernel-module helper

In reply to Yann E. MORIN

We were already using the Linux buildsystem to build simicsfs' modules, so switch to using the kernel-module infra instead.

---
 package/simicsfs/simicsfs.mk | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
package/simicsfs/simicsfs.mk +1 -9
index 51987c5..91ed413 100644
@@ -8,14 +8,6 @@ SIMICSFS_VERSION = 1.18
 SIMICSFS_SITE = http://download.simics.net/pub
 SIMICSFS_LICENSE = GPLv2+
 SIMICSFS_LICENSE_FILES = hostfs.h
-SIMICSFS_DEPENDENCIES = linux
-
-define SIMICSFS_BUILD_CMDS
-	$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) M=$(@D) modules
-endef
-
-define SIMICSFS_INSTALL_TARGET_CMDS
-	$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) M=$(@D) INSTALL_MOD_PATH=$(TARGET_DIR) modules_install
-endef
 
+$(eval $(kernel-module))
 $(eval $(generic-package))
Signature · 1 line
1.9.1
#11 lore raw

PATCH v3 11/11 package/sysdig: use kernel-module helper

In reply to Yann E. MORIN

sysdig's Makefile was already calling the Linux buildsystem to build its modules, so switch to using the new kernel-module infra.

This has the benefit of making sysdig actually buildable, otherwise it fails because it tries to use the kernel headers from the host:

    make: *** /lib/modules/3.13.0-53-generic/build: No such file or directory.  Stop.
    make[5]: *** [all] Error 2
    make[4]: *** [driver/CMakeFiles/driver] Error 2
    make[3]: *** [driver/CMakeFiles/driver.dir/all] Error 2
Cc Angelo Compagnucci <[email protected]>
Cc Thomas Petazzoni <[email protected]>
---
 package/sysdig/sysdig.mk | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
package/sysdig/sysdig.mk +18 -4
index d07d467..85d16a4 100644
@@ -10,13 +10,27 @@ SYSDIG_LICENSE = GPLv2
 SYSDIG_LICENSE_FILES = COPYING
 SYSDIG_CONF_OPTS = -DUSE_BUNDLED_LUAJIT=OFF -DUSE_BUNDLED_ZLIB=OFF \
 	-DUSE_BUNDLED_JSONCPP=OFF -DENABLE_DKMS=OFF
-SYSDIG_DEPENDENCIES = zlib luajit jsoncpp linux
+SYSDIG_DEPENDENCIES = zlib luajit jsoncpp
 SYSDIG_SUPPORTS_IN_SOURCE_BUILD = NO
 
-define SYSDIG_INSTALL_DRIVER
-	$(MAKE) -C $(SYSDIG_BUILDDIR) $(LINUX_MAKE_FLAGS) KERNELDIR="$(LINUX_DIR)" install_driver
+# sysdig creates the module Makefile from a template, which contains a
+# single place-holder, KBUILD_FLAGS, wich is only replaced with two
+# things:
+#   - debug flags, which we don't care about here,
+#   - 'sysdig-feature' flags, which are never set, so always empty
+# So, just replace the place-holder with the only meaningful value: nothing.
+define SYSDIG_MODULE_GEN_MAKEFILE
+	$(INSTALL) -m 0644 $(@D)/driver/Makefile.in $(@D)/driver/Makefile
+	$(SED) 's/@KBUILD_FLAGS@//;' $(@D)/driver/Makefile
 endef
+SYSDIG_POST_PATCH_HOOKS += SYSDIG_MODULE_GEN_MAKEFILE
 
-SYSDIG_POST_INSTALL_TARGET_HOOKS += SYSDIG_INSTALL_DRIVER
+# Don't build the driver as part of the 'standard' procedure, we'll
+# build it on our own with the kernel-module infra.
+SYSDIG_CONF_OPTS += -DBUILD_DRIVER=OFF
 
+SYSDIG_MODULE_SUBDIRS = driver
+SYSDIG_MODULE_MAKE_OPTS = KERNELDIR=$(LINUX_DIR)
+
+$(eval $(kernel-module))
 $(eval $(cmake-package))
Signature · 1 line
1.9.1
#12 lore raw

v3 cover core: new infra to ease building kernel modules (branch yem/kernel-modules)

In reply to Yann E. MORIN

Dear Yann E. MORIN,

Quoted 4 lines · Yann E. MORIN

Yann E. MORIN (11):
package-infra: add helper to build kernel modules docs/manual: add kernel-module package/lttng-modules: use kernel-module helper

Quoted 8 lines

package/igh-ethercat: use kernel-module helper package/ktap: use kernel-module helper package/cryptodev-linux: use the kernel-module helper package/ocf-linux: use kernel-module helper package/on2-8170-modules: use kernel-module helper package/owl-linux: use kernel-module helper package/simicsfs: use kernel-module helper package/sysdig: use kernel-module helper

All applied, thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com