From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH v3 2/8] linux-module: Do not use shell environment
Date: Tue, 1 Feb 2022 17:52:58 +0100 [thread overview]
Message-ID: <20220201165304.21976-3-ubely@ilbers.de> (raw)
In-Reply-To: <20220201165304.21976-1-ubely@ilbers.de>
From: Anton Mikanovich <amikan@ilbers.de>
To make package build process independent of the shell environment we
should remove KDIR and PN passing through export call.
KDIR can be prepared during package build. This also will allow not to
rely on previous builddeps install task.
To pass PN variable we can just migrate to template-based debian/rules
file.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
.../linux-module/files/debian/rules | 37 ----------
.../linux-module/files/debian/rules.tmpl | 67 +++++++++++++++++++
meta/recipes-kernel/linux-module/module.inc | 34 +---------
3 files changed, 70 insertions(+), 68 deletions(-)
delete mode 100755 meta/recipes-kernel/linux-module/files/debian/rules
create mode 100755 meta/recipes-kernel/linux-module/files/debian/rules.tmpl
diff --git a/meta/recipes-kernel/linux-module/files/debian/rules b/meta/recipes-kernel/linux-module/files/debian/rules
deleted file mode 100755
index 59720b37..00000000
--- a/meta/recipes-kernel/linux-module/files/debian/rules
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/make -f
-
-# Debian rules for custom kernel module build
-#
-# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
-#
-# SPDX-License-Identifier: MIT
-
-export DEB_BUILD_OPTIONS=parallel=$(shell nproc)
-
-export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
-
-ifeq ($(DEB_HOST_GNU_CPU), arm)
-export ARCH=arm
-endif
-ifeq ($(DEB_HOST_GNU_CPU), aarch64)
-export ARCH=arm64
-endif
-ifeq ($(DEB_HOST_GNU_CPU), riscv64)
-export ARCH=riscv
-endif
-ifneq (,$(findstring 86,$(DEB_HOST_GNU_CPU)))
-export ARCH=x86
-endif
-
-override_dh_auto_clean:
- $(MAKE) -C $(KDIR) M=$(PWD) clean
-
-override_dh_auto_build:
- $(MAKE) -C $(KDIR) M=$(PWD) modules
-
-override_dh_auto_install:
- $(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(PWD)/debian/$(PN) modules_install
-
-%:
- CFLAGS= LDFLAGS= dh $@ --parallel
diff --git a/meta/recipes-kernel/linux-module/files/debian/rules.tmpl b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
new file mode 100755
index 00000000..054a7b83
--- /dev/null
+++ b/meta/recipes-kernel/linux-module/files/debian/rules.tmpl
@@ -0,0 +1,67 @@
+#!/usr/bin/make -f
+
+# Debian rules for custom kernel module build
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+#
+# SPDX-License-Identifier: MIT
+
+export DEB_BUILD_OPTIONS=parallel=$(shell nproc)
+
+export CROSS_COMPILE=$(DEB_HOST_GNU_TYPE)-
+
+ifeq ($(DEB_HOST_GNU_CPU), arm)
+export ARCH=arm
+endif
+ifeq ($(DEB_HOST_GNU_CPU), aarch64)
+export ARCH=arm64
+endif
+ifeq ($(DEB_HOST_GNU_CPU), riscv64)
+export ARCH=riscv
+endif
+ifneq (,$(findstring 86,$(DEB_HOST_GNU_CPU)))
+export ARCH=x86
+endif
+
+ifeq (${KERNEL_TYPE}, raspios)
+# In RaspiOS one package provides several headers
+KERNEL_SUFFIX := "+"
+ifeq (${KERNEL_NAME}, kernel8)
+KERNEL_SUFFIX := "-v8+"
+else ifeq (${KERNEL_NAME}, kernel7l)
+KERNEL_SUFFIX := "-v7l+"
+else ifeq (${KERNEL_NAME}, kernel7)
+KERNEL_SUFFIX := "-v7+"
+endif
+KDIR := $(shell dpkg -L ${KERNEL_HEADERS_PKG} | grep "/lib/modules/.*${KERNEL_SUFFIX}/build" | head -n1)
+endif
+
+ifeq ($(KDIR),)
+# Custom kernels contain the build folder directly.
+KDIR := $(shell dpkg -L ${KERNEL_HEADERS_PKG} | grep "/lib/modules/.*/build")
+endif
+ifeq ($(KDIR),)
+# Debian kernels install that folder indirectly via a dependency.
+KERNEL_DEP := $(shell dpkg-query -W -f '$${Depends}' ${KERNEL_HEADERS_PKG} | sed 's/.*\(linux-headers-[[:graph:]]*\).*/\1/')
+KDIR := $(shell dpkg -L $(KERNEL_DEP) | grep "/lib/modules/.*/build")
+endif
+
+# With some build systems like sbuild `dh clean` can be called twice:
+# first, by build system itself before chroot's apt database updated,
+# second, by dpkg-buildpackage during build. So, KDIR may be empty
+# in first case (while no dependencies are yet installed), and a broken
+# 'make ... clean' command is produced. Just skip override in this case.
+ifneq ($(KDIR),)
+override_dh_auto_clean:
+ $(MAKE) -C $(KDIR) M=$(PWD) clean
+endif
+
+override_dh_auto_build:
+ $(MAKE) -C $(KDIR) M=$(PWD) modules
+
+override_dh_auto_install:
+ $(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(PWD)/debian/${PN} modules_install
+
+%:
+ CFLAGS= LDFLAGS= dh $@ --parallel
diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc
index 968ac4c7..75dc4374 100644
--- a/meta/recipes-kernel/linux-module/module.inc
+++ b/meta/recipes-kernel/linux-module/module.inc
@@ -24,8 +24,9 @@ AUTOLOAD ?= ""
inherit dpkg
TEMPLATE_FILES = "debian/control.tmpl \
- debian/changelog.tmpl"
-TEMPLATE_VARS += "KERNEL_IMAGE_PKG KERNEL_HEADERS_PKG"
+ debian/changelog.tmpl \
+ debian/rules.tmpl"
+TEMPLATE_VARS += "KERNEL_NAME KERNEL_TYPE KERNEL_IMAGE_PKG KERNEL_HEADERS_PKG PN"
do_prepare_build() {
cp -r ${WORKDIR}/debian ${S}/
@@ -34,32 +35,3 @@ do_prepare_build() {
echo "echo $module >> /etc/modules" >> ${S}/debian/postinst
done
}
-
-dpkg_runbuild_prepend() {
- if [ "${KERNEL_TYPE}" = "raspios" ]; then
- # In RaspiOS one package provides several headers
- KERNEL_SUFFIX="+"
- if [ "${KERNEL_NAME}" = "kernel8" ]; then
- KERNEL_SUFFIX="-v8+"
- elif [ "${KERNEL_NAME}" = "kernel7l" ]; then
- KERNEL_SUFFIX="-v7l+"
- elif [ "${KERNEL_NAME}" = "kernel7" ]; then
- KERNEL_SUFFIX="-v7+"
- fi
- export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_HEADERS_PKG} | \
- grep "/lib/modules/.*${KERNEL_SUFFIX}/build" | head -n1)
- fi
- if [ -z "$KDIR" ]; then
- # Custom kernels contain the build folder directly.
- export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_HEADERS_PKG} | \
- grep "/lib/modules/.*/build")
- fi
- if [ -z "$KDIR" ]; then
- # Debian kernels install that folder indirectly via a dependency.
- KERNEL_DEP=$(dpkg-query -W -f '${Depends}' --admindir=${BUILDCHROOT_DIR}/var/lib/dpkg \
- ${KERNEL_HEADERS_PKG} | sed 's/.*\(linux-headers-[[:graph:]]*\).*/\1/')
- export KDIR=$(dpkg -L --root=${BUILDCHROOT_DIR} ${KERNEL_DEP} | \
- grep "/lib/modules/.*/build")
- fi
- export PN=${PN}
-}
--
2.20.1
next prev parent reply other threads:[~2022-02-01 16:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 16:52 [PATCH v3 0/8] Avoid using shell environment during the build Uladzimir Bely
2022-02-01 16:52 ` [PATCH v3 1/8] template: Copy template attributes on transform Uladzimir Bely
2022-02-01 16:52 ` Uladzimir Bely [this message]
2022-02-01 16:52 ` [PATCH v3 3/8] u-boot: Do not use shell environment Uladzimir Bely
2022-02-01 16:53 ` [PATCH v3 4/8] trusted-firmware: " Uladzimir Bely
2022-02-01 16:53 ` [PATCH v3 5/8] optee-os: " Uladzimir Bely
2022-02-01 16:53 ` [PATCH v3 6/8] kselftest: " Uladzimir Bely
2022-02-01 16:53 ` [PATCH v3 7/8] linux-mainline: Move cfg fragment test to debian/rules Uladzimir Bely
2022-02-01 16:53 ` [PATCH v3 8/8] linux-custom: Move cfg fragments applying " Uladzimir Bely
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=20220201165304.21976-3-ubely@ilbers.de \
--to=ubely@ilbers.de \
--cc=isar-users@googlegroups.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox