From patchwork Wed Jun 10 19:22:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 482840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id 7BA0F140293 for ; Thu, 11 Jun 2015 05:22:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ufTiFd/f; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B79DD3228F; Wed, 10 Jun 2015 19:22:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2onNA5YtJydL; Wed, 10 Jun 2015 19:22:27 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 3D80332E1B; Wed, 10 Jun 2015 19:22:27 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id E417C1C0A5C for ; Wed, 10 Jun 2015 19:22:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id CB2B390F82 for ; Wed, 10 Jun 2015 19:22:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K7qAszhxMzh5 for ; Wed, 10 Jun 2015 19:22:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wg0-f67.google.com (mail-wg0-f67.google.com [74.125.82.67]) by whitealder.osuosl.org (Postfix) with ESMTPS id D8CF590E4E for ; Wed, 10 Jun 2015 19:22:23 +0000 (UTC) Received: by wggy19 with SMTP id y19so8391556wgg.2 for ; Wed, 10 Jun 2015 12:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6IaAvY/TtnHhnJBYSw28cF48Sv28luL2mCOSdj1E8Rs=; b=ufTiFd/fJpWgcGGdikJYtua4lB0ELdCPdP1NZXQ8GE/5Sk318zmnmEpzAmMu5CCeF4 5kwbNkdJOD3LqwMOuiFv5Tf2py7ar5rrvT2mMZToEuHcETFvQfeKFfJL/ttI2J+0JJ1U 7WMhtr3KwbJuT6Pa9FUg4Xk/5k+BxZqzae4oOLDxwFa3xoucVY6vg76GCVJWMhmmotb2 8jUFC8NN1358R/L4FIpRvsfX8a1dpGAC6lNe2gPX3jMQjwPi8KCB2y4liUC3sXTrfOCZ A11w/RrbI/e4/HFt8zuLVgf4on5x1su0jZr0HwutnqwZa6rY7IPAF1TceUpUjt3UeDek pjeg== X-Received: by 10.180.109.136 with SMTP id hs8mr11292960wib.73.1433964142433; Wed, 10 Jun 2015 12:22:22 -0700 (PDT) Received: from localhost.localdomain (ns304657.ip-46-105-103.eu. [46.105.103.66]) by mx.google.com with ESMTPSA id u9sm15937311wju.44.2015.06.10.12.22.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Jun 2015 12:22:21 -0700 (PDT) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Wed, 10 Jun 2015 21:22:05 +0200 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Cc: Thomas Petazzoni , "Yann E. MORIN" Subject: [Buildroot] [PATCH 01/11 v2] package-infra: add helper to build kernel modules X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" 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" Cc: Thomas Petazzoni Cc: Baruch Siach Cc: Arnout Vandecappelle Tested-by: Doug Kehn Reviewed-by: Arnout Vandecappelle (Essensium/Mind) --- 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)))