Skip to contentSkip to conversation

kbuild: deb-pkg: factor out common Make options in debian/rules

PATCH In review Masahiro Yamada 4 participants 13 messages Dec 26, 2023 – Apr 2, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 kbuild: deb-pkg: factor out common Make options in debian/rules

This avoid code duplication between binary-arch and built-arch.

---

 scripts/package/debian/rules | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/package/debian/rules +4 -4
index 3dafa9496c63..26bc6239e200 100755
@@ -10,20 +10,20 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     MAKEFLAGS += -j$(NUMJOBS)
 endif
 
+make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE)
+
 .PHONY: binary binary-indep binary-arch
 binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \
-	KERNELRELEASE=$(KERNELRELEASE) \
+	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
 	run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb
 
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
 build-indep:
 build-arch:
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \
-	KERNELRELEASE=$(KERNELRELEASE) \
+	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
 	$(shell $(srctree)/scripts/package/deb-build-option) \
 	olddefconfig all
 
Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/6 kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules

The binary-arch target needs to use the same CROSS_COMPILE as used in build-arch; otherwise, 'make run-command' may attempt to resync the .config file.

Squash scripts/package/deb-build-option into debian/rules, as it is a small amount of code.

---

 scripts/package/deb-build-option | 14 --------------
 scripts/package/debian/rules     |  5 +++--
 2 files changed, 3 insertions(+), 16 deletions(-)
 delete mode 100755 scripts/package/deb-build-option
scripts/package/deb-build-option deleted +0 -14
deleted file mode 100755
index 7950eff01781..000000000000
@@ -1,14 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-only
-
-# Set up CROSS_COMPILE if not defined yet
-if [ "${CROSS_COMPILE+set}" != "set" -a "${DEB_HOST_ARCH}" != "${DEB_BUILD_ARCH}" ]; then
-	echo CROSS_COMPILE=${DEB_HOST_GNU_TYPE}-
-fi
-
-version=$(dpkg-parsechangelog -S Version)
-debian_revision="${version##*-}"
-
-if [ "${version}" != "${debian_revision}" ]; then
-	echo KBUILD_BUILD_VERSION=${debian_revision}
-fi
scripts/package/debian/rules +3 -2
index 26bc6239e200..529b71b55efa 100755
@@ -10,7 +10,9 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     MAKEFLAGS += -j$(NUMJOBS)
 endif
 
-make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE)
+revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
+CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
+make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
 
 .PHONY: binary binary-indep binary-arch
 binary: binary-arch binary-indep
@@ -24,7 +26,6 @@ build: build-arch build-indep
 build-indep:
 build-arch:
 	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
-	$(shell $(srctree)/scripts/package/deb-build-option) \
 	olddefconfig all
 
 .PHONY: clean
Signature · 1 line
2.40.1
Reviewed-by on v1 2/6
#2 lore raw

Re: [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules

Quoted 9 lines · Masahiro Yamada

The binary-arch target needs to use the same CROSS_COMPILE as used in build-arch; otherwise, 'make run-command' may attempt to resync the .config file.

Squash scripts/package/deb-build-option into debian/rules, as it is a small amount of code.

---

Quoted 52 lines
 scripts/package/deb-build-option | 14 --------------
 scripts/package/debian/rules     |  5 +++--
 2 files changed, 3 insertions(+), 16 deletions(-)
 delete mode 100755 scripts/package/deb-build-option
scripts/package/deb-build-option deleted +0 -14
deleted file mode 100755
index 7950eff01781..000000000000
@@ -1,14 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-only
-
-# Set up CROSS_COMPILE if not defined yet
-if [ "${CROSS_COMPILE+set}" != "set" -a "${DEB_HOST_ARCH}" != "${DEB_BUILD_ARCH}" ]; then
-	echo CROSS_COMPILE=${DEB_HOST_GNU_TYPE}-
-fi
-
-version=$(dpkg-parsechangelog -S Version)
-debian_revision="${version##*-}"
-
-if [ "${version}" != "${debian_revision}" ]; then
-	echo KBUILD_BUILD_VERSION=${debian_revision}
-fi
scripts/package/debian/rules +3 -2
index 26bc6239e200..529b71b55efa 100755
@@ -10,7 +10,9 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     MAKEFLAGS += -j$(NUMJOBS)
 endif
 
-make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE)
+revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
+CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
+make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
 
 .PHONY: binary binary-indep binary-arch
 binary: binary-arch binary-indep
@@ -24,7 +26,6 @@ build: build-arch build-indep
 build-indep:
 build-arch:
 	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
-	$(shell $(srctree)/scripts/package/deb-build-option) \
 	olddefconfig all
 
 .PHONY: clean
Signature · 1 line
2.40.1
#3 lore raw

PATCH 3/6 kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed

In reply to Masahiro Yamada

Since commit 491b146d4c13 ("kbuild: builddeb: Eliminate debian/arch use"), direct execution of debian/rules results in the following error:

dpkg-architecture: error: unknown option 'DEB_HOST_MULTIARCH'

The current code:

dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH

... does not look sensible because:

- For this code to work correctly, DEB_HOST_ARCH must be pre-defined, which is true when the packages are built via dpkg-buildpackage. In this case, DEB_HOST_MULTIARCH is also likely defined, hence there is no need to query DEB_HOST_MULTIARCH in the first place.

- If DEB_HOST_MULTIARCH is undefined, DEB_HOST_ARCH is likely undefined too. So, you cannot query DEB_HOST_MULTIARCH in this way. This is mostly the case where debian/rules is directly executed.

When debian/rules is directly executed, querying DEB_HOST_MUCHARCH is not enough because we need to know DEB_{BUILD,HOST}_GNU_TYPE as well.

All DEB_* variables are defined when the package build is initiated by dpkg-buildpackage, but otherwise, let's call dpkg-architecture to set all DEB_* environment variables.

This implementation relies on dpkg commit 7c54fa2b232e ("dpkg-architecture: Add a --print-format option").

---

 scripts/package/builddeb     |  5 ++---
 scripts/package/debian/rules | 12 +++++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)
scripts/package/builddeb +2 -3
index 2fe51e6919da..2eb4910f0ef3 100755
@@ -171,9 +171,8 @@ install_libc_headers () {
 
 	# move asm headers to /usr/include/<libc-machine>/asm to match the structure
 	# used by Debian-based distros (to support multi-arch)
-	host_arch=$(dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH)
-	mkdir $pdir/usr/include/$host_arch
-	mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
+	mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
+	mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
 }
 
 rm -f debian/files
scripts/package/debian/rules +11 -1
index 529b71b55efa..8f24a8e84bf2 100755
@@ -30,5 +30,15 @@ build-arch:
 
 .PHONY: clean
 clean:
-	rm -rf debian/files debian/linux-*
+	rm -rf debian/files debian/linux-* debian/deb-env.vars
 	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean
+
+# If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
+# directly. Run 'dpkg-architecture --print-set --print-format=make' to
+# generate a makefile construct that exports all DEB_* variables.
+ifndef DEB_HOST_ARCH
+-include debian/deb-env.vars
+
+debian/deb-env.vars:
+	dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@
+endif
Signature · 1 line
2.40.1
Reviewed-by on v1 3/6
#4 lore raw

Re: [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed

Quoted 76 lines · Masahiro Yamada

Since commit 491b146d4c13 ("kbuild: builddeb: Eliminate debian/arch use"), direct execution of debian/rules results in the following error:

dpkg-architecture: error: unknown option 'DEB_HOST_MULTIARCH'

The current code:

dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH

... does not look sensible because:

- For this code to work correctly, DEB_HOST_ARCH must be pre-defined, which is true when the packages are built via dpkg-buildpackage. In this case, DEB_HOST_MULTIARCH is also likely defined, hence there is no need to query DEB_HOST_MULTIARCH in the first place.

- If DEB_HOST_MULTIARCH is undefined, DEB_HOST_ARCH is likely undefined too. So, you cannot query DEB_HOST_MULTIARCH in this way. This is mostly the case where debian/rules is directly executed.

When debian/rules is directly executed, querying DEB_HOST_MUCHARCH is not enough because we need to know DEB_{BUILD,HOST}_GNU_TYPE as well.

All DEB_* variables are defined when the package build is initiated by dpkg-buildpackage, but otherwise, let's call dpkg-architecture to set all DEB_* environment variables.

This implementation relies on dpkg commit 7c54fa2b232e ("dpkg-architecture: Add a --print-format option").

---

 scripts/package/builddeb     |  5 ++---
 scripts/package/debian/rules | 12 +++++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)
scripts/package/builddeb +2 -3
index 2fe51e6919da..2eb4910f0ef3 100755
@@ -171,9 +171,8 @@ install_libc_headers () {
 
 	# move asm headers to /usr/include/<libc-machine>/asm to match the structure
 	# used by Debian-based distros (to support multi-arch)
-	host_arch=$(dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH)
-	mkdir $pdir/usr/include/$host_arch
-	mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
+	mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
+	mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
 }
 
 rm -f debian/files
scripts/package/debian/rules +11 -1
index 529b71b55efa..8f24a8e84bf2 100755
@@ -30,5 +30,15 @@ build-arch:
 
 .PHONY: clean
 clean:
-	rm -rf debian/files debian/linux-*
+	rm -rf debian/files debian/linux-* debian/deb-env.vars
 	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean
+
+# If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
+# directly. Run 'dpkg-architecture --print-set --print-format=make' to
+# generate a makefile construct that exports all DEB_* variables.
+ifndef DEB_HOST_ARCH
+-include debian/deb-env.vars
+
+debian/deb-env.vars:
+	dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@
+endif
Signature · 1 line
2.40.1

Thanks!

#5 lore raw

PATCH 4/6 kbuild: deb-pkg: allow to run debian/rules from output directory

In reply to Masahiro Yamada

'make O=... deb-pkg' creates the debian directory in the output directory. However, currently it is impossible to run debian/rules created in the separate output directory.

This commit delays the $(srctree) expansion by escaping '$' and by quating the entire command, making it possible to run debian/rules in the output directory.

---

 scripts/package/debian/rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/debian/rules +1 -1
index 8f24a8e84bf2..6b2333e3cf96 100755
@@ -19,7 +19,7 @@ binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
 	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
-	run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb
+	run-command KBUILD_RUN_COMMAND='+$${srctree}/scripts/package/builddeb'
 
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
Signature · 1 line
2.40.1
Reviewed-by on v1 4/6
#6 lore raw

Re: [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory

Quoted 6 lines · Masahiro Yamada

'make O=... deb-pkg' creates the debian directory in the output directory. However, currently it is impossible to run debian/rules created in the separate output directory.

This commit delays the $(srctree) expansion by escaping '$' and by quating the entire command, making it possible to run debian/rules in

quating -> quoting

Quoted 13 lines

the output directory.

---

 scripts/package/debian/rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/debian/rules +0 -0
index 8f24a8e84bf2..6b2333e3cf96 100755

scripts/package/debian/rules binary: binary-arch binary-indep · line 22

Quoted 5 lines
scripts/package/debian/rules +1 -1
@@ -19,7 +19,7 @@ binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
 	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
-	run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb
+	run-command KBUILD_RUN_COMMAND='+$${srctree}/scripts/package/builddeb'

That's a nice trick.

Quoted 6 lines
scripts/package/debian/rules +0 -0
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
Signature · 1 line
2.40.1
#7 lore raw

PATCH 5/6 kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules

In reply to Masahiro Yamada

This is unneeded because the Makefile in the output directory wraps the top-level Makefile in the srctree.

Just run $(MAKE) irrespective of the build location.

---

 scripts/package/debian/rules | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/package/debian/rules +3 -5
index 6b2333e3cf96..36d51f60f98d 100755
@@ -3,8 +3,6 @@
 
 include debian/rules.vars
 
-srctree ?= .
-
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
     MAKEFLAGS += -j$(NUMJOBS)
@@ -18,20 +16,20 @@ make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(r
 binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
-	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
+	$(MAKE) $(make-opts) \
 	run-command KBUILD_RUN_COMMAND='+$${srctree}/scripts/package/builddeb'
 
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
 build-indep:
 build-arch:
-	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
+	$(MAKE) $(make-opts) \
 	olddefconfig all
 
 .PHONY: clean
 clean:
 	rm -rf debian/files debian/linux-* debian/deb-env.vars
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean
+	$(MAKE) ARCH=$(ARCH) clean
 
 # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
 # directly. Run 'dpkg-architecture --print-set --print-format=make' to
Signature · 1 line
2.40.1
Reviewed-by on v1 5/6
#8 lore raw

Re: [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules

Quoted 7 lines · Masahiro Yamada

This is unneeded because the Makefile in the output directory wraps the top-level Makefile in the srctree.

Just run $(MAKE) irrespective of the build location.

---

Quoted 44 lines
 scripts/package/debian/rules | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/package/debian/rules +3 -5
index 6b2333e3cf96..36d51f60f98d 100755
@@ -3,8 +3,6 @@
 
 include debian/rules.vars
 
-srctree ?= .
-
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
     MAKEFLAGS += -j$(NUMJOBS)
@@ -18,20 +16,20 @@ make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(r
 binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
-	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
+	$(MAKE) $(make-opts) \
 	run-command KBUILD_RUN_COMMAND='+$${srctree}/scripts/package/builddeb'
 
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
 build-indep:
 build-arch:
-	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
+	$(MAKE) $(make-opts) \
 	olddefconfig all
 
 .PHONY: clean
 clean:
 	rm -rf debian/files debian/linux-* debian/deb-env.vars
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean
+	$(MAKE) ARCH=$(ARCH) clean
 
 # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
 # directly. Run 'dpkg-architecture --print-set --print-format=make' to
Signature · 1 line
2.40.1
#9 lore raw

PATCH 6/6 kbuild: deb-pkg: use more debhelper commands in builddeb

In reply to Masahiro Yamada

Commit 36862e14e316 ("kbuild: deb-pkg: use dh_listpackages to know enabled packages") started to require the debhelper tool suite.

Use more dh_* commands in create_package():

- dh_installdocs to install copyright
- dh_installchangelogs to install changelog
- dh_compress to compress changelog
- dh_fixperms to replace the raw chmod command
- dh_gencontrol to replace the raw dpkg-gencontrol command
- dh_md5sums to record the md5sum of included files
- dh_builddeb to replace the raw dpkg-deb command

Set DEB_RULES_REQUIRES_ROOT to 'no' in case debian/rules is executed directly.

---

 scripts/package/builddeb     | 23 ++++++++---------------
 scripts/package/debian/rules |  2 ++
 scripts/package/mkdebian     |  2 +-
 3 files changed, 11 insertions(+), 16 deletions(-)
scripts/package/builddeb +8 -15
index 2eb4910f0ef3..436d55a83ab0 100755
@@ -26,23 +26,16 @@ if_enabled_echo() {
 
 create_package() {
 	local pname="$1" pdir="$2"
-	local dpkg_deb_opts
 
-	mkdir -m 755 -p "$pdir/DEBIAN"
-	mkdir -p "$pdir/usr/share/doc/$pname"
-	cp debian/copyright "$pdir/usr/share/doc/$pname/"
-	cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
-	gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
-	sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
-		| xargs -r0 md5sum > DEBIAN/md5sums"
+	export DH_OPTIONS="-p${pname} -P${pdir}"
 
-	# a+rX in case we are in a restrictive umask environment like 0077
-	# ug-s in case we build in a setuid/setgid directory
-	chmod -R go-w,a+rX,ug-s "$pdir"
-
-	# Create the package
-	dpkg-gencontrol -p$pname -P"$pdir"
-	dpkg-deb --root-owner-group ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
+	dh_installdocs
+	dh_installchangelogs
+	dh_compress
+	dh_fixperms
+	dh_gencontrol
+	dh_md5sums
+	dh_builddeb -- ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS}
 }
 
 install_linux_image () {
scripts/package/debian/rules +2 -0
index 36d51f60f98d..1f56938ea5d4 100755
@@ -1,6 +1,8 @@
 #!/usr/bin/make -f
 # SPDX-License-Identifier: GPL-2.0-only
 
+export DEB_RULES_REQUIRES_ROOT := no
+
 include debian/rules.vars
 
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
scripts/package/mkdebian +1 -1
index 93a24712b9a1..070149c985fe 100755
@@ -193,7 +193,7 @@ Section: kernel
 Priority: optional
 Maintainer: $maintainer
 Rules-Requires-Root: no
-Build-Depends: debhelper
+Build-Depends: debhelper-compat (= 12)
 Build-Depends-Arch: bc, bison, cpio, flex, kmod, libelf-dev:native, libssl-dev:native, rsync
 Homepage: https://www.kernel.org/
 
Signature · 1 line
2.40.1
#10 lore raw

Re: [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb

Quoted 80 lines · Masahiro Yamada

Commit 36862e14e316 ("kbuild: deb-pkg: use dh_listpackages to know enabled packages") started to require the debhelper tool suite.

Use more dh_* commands in create_package():

- dh_installdocs to install copyright
- dh_installchangelogs to install changelog
- dh_compress to compress changelog
- dh_fixperms to replace the raw chmod command
- dh_gencontrol to replace the raw dpkg-gencontrol command
- dh_md5sums to record the md5sum of included files
- dh_builddeb to replace the raw dpkg-deb command

Set DEB_RULES_REQUIRES_ROOT to 'no' in case debian/rules is executed directly.

---

 scripts/package/builddeb     | 23 ++++++++---------------
 scripts/package/debian/rules |  2 ++
 scripts/package/mkdebian     |  2 +-
 3 files changed, 11 insertions(+), 16 deletions(-)
scripts/package/builddeb +8 -15
index 2eb4910f0ef3..436d55a83ab0 100755
@@ -26,23 +26,16 @@ if_enabled_echo() {
 
 create_package() {
        local pname="$1" pdir="$2"
-       local dpkg_deb_opts
 
-       mkdir -m 755 -p "$pdir/DEBIAN"
-       mkdir -p "$pdir/usr/share/doc/$pname"
-       cp debian/copyright "$pdir/usr/share/doc/$pname/"
-       cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
-       gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
-       sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
-               | xargs -r0 md5sum > DEBIAN/md5sums"
+       export DH_OPTIONS="-p${pname} -P${pdir}"
 
-       # a+rX in case we are in a restrictive umask environment like 0077
-       # ug-s in case we build in a setuid/setgid directory
-       chmod -R go-w,a+rX,ug-s "$pdir"
-
-       # Create the package
-       dpkg-gencontrol -p$pname -P"$pdir"
-       dpkg-deb --root-owner-group ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
+       dh_installdocs
+       dh_installchangelogs
+       dh_compress
+       dh_fixperms
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb -- ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS}
 }
 
 install_linux_image () {
scripts/package/debian/rules +2 -0
index 36d51f60f98d..1f56938ea5d4 100755
@@ -1,6 +1,8 @@
 #!/usr/bin/make -f
 # SPDX-License-Identifier: GPL-2.0-only
 
+export DEB_RULES_REQUIRES_ROOT := no
+
 include debian/rules.vars
 
 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
scripts/package/mkdebian +0 -0
index 93a24712b9a1..070149c985fe 100755

scripts/package/mkdebian Section: kernel · line 196

Quoted 5 lines
scripts/package/mkdebian +1 -1
@@ -193,7 +193,7 @@ Section: kernel
 Priority: optional
 Maintainer: $maintainer
 Rules-Requires-Root: no
-Build-Depends: debhelper
+Build-Depends: debhelper-compat (= 12)

make ARCH=arm CROSS_COMPILE= bindeb-pkg

I'm seeing a fun issue with Ubuntu 24.04 (Noble)... 13.14.1ubuntu5:
https://launchpad.net/ubuntu/+source/debhelper

dpkg-buildpackage --build=binary --no-pre-clean --unsigned-changes -R'make -f debian/rules' -j1 -a$(cat debian/arch)
dpkg-buildpackage: info: source package linux-upstream
dpkg-buildpackage: info: source version 1noble
dpkg-buildpackage: info: source distribution noble
dpkg-buildpackage: info: source changed by rcn-ee <[email protected]>
dpkg-source --before-build .
dpkg-buildpackage: info: host architecture armhf
dpkg-checkbuilddeps: error: Unmet build dependencies: debhelper-compat (= 12)
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
dpkg-buildpackage: warning: (Use -d flag to override.)

Where as Debian (testing) Trixie and Sid: 13.15.3
https://packages.debian.org/source/trixie/debhelper

dpkg-buildpackage --build=binary --no-pre-clean --unsigned-changes -R'make -f debian/rules' -j1 -a$(cat debian/arch)
dpkg-buildpackage: info: source package linux-upstream
dpkg-buildpackage: info: source version 1trixie
dpkg-buildpackage: info: source distribution trixie
dpkg-buildpackage: info: source changed by rcn-ee <[email protected]>
dpkg-source --before-build .
dpkg-buildpackage: info: host architecture armhf
make -f debian/rules binary

dpkg-buildpackage --build=binary --no-pre-clean --unsigned-changes -R'make -f debian/rules' -j1 -a$(cat debian/arch)
dpkg-buildpackage: info: source package linux-upstream
dpkg-buildpackage: info: source version 1sid
dpkg-buildpackage: info: source distribution trixie
dpkg-buildpackage: info: source changed by rcn-ee <[email protected]>
dpkg-source --before-build .
dpkg-buildpackage: info: host architecture armhf
make -f debian/rules binary

Not really sure why Noble is failing, but wonder if, would fix it..
Build-Depends: debhelper-compat (>= 12)

Regards,

Signature · 2 lines
Robert Nelson
https://rcn-ee.com/
#11 lore raw

Re: [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb

Quoted 13 lines

scripts/package/mkdebian Section: kernel · line 196

Quoted 7 lines

+++ b/scripts/package/mkdebian

scripts/package/mkdebian +1 -1
@@ -193,7 +193,7 @@ Section: kernel
 Priority: optional
 Maintainer: $maintainer
 Rules-Requires-Root: no
-Build-Depends: debhelper
+Build-Depends: debhelper-compat (= 12)

make ARCH=arm CROSS_COMPILE= bindeb-pkg

I'm seeing a fun issue with Ubuntu 24.04 (Noble)... 13.14.1ubuntu5:
https://launchpad.net/ubuntu/+source/debhelper

Quoted 11 lines

dpkg-buildpackage --build=binary --no-pre-clean --unsigned-changes -R'make -f debian/rules' -j1 -a$(cat debian/arch)
dpkg-buildpackage: info: source package linux-upstream
dpkg-buildpackage: info: source version 1noble
dpkg-buildpackage: info: source distribution noble
dpkg-buildpackage: info: source changed by rcn-ee <[email protected]>
dpkg-source --before-build .
dpkg-buildpackage: info: host architecture armhf
dpkg-checkbuilddeps: error: Unmet build dependencies: debhelper-compat (= 12)
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
dpkg-buildpackage: warning: (Use -d flag to override.)

Sorry for the noise, this looks to be a time32 related issue in Ubuntu's armhf Vs, arm64... As my arm64 Noble schroot just finished it's version of v6.9.0-rc2 package with no issues..

Regards,

Signature · 2 lines
Robert Nelson
https://rcn-ee.com/
Reviewed-by on v1 1/6
#12 lore raw
In reply to Masahiro Yamada
Quoted 1 line · Masahiro Yamada

This avoid code duplication between binary-arch and built-arch.

avoids ?

Quoted 39 lines

---

 scripts/package/debian/rules | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/package/debian/rules +4 -4
index 3dafa9496c63..26bc6239e200 100755
@@ -10,20 +10,20 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
     MAKEFLAGS += -j$(NUMJOBS)
 endif
 
+make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE)
+
 .PHONY: binary binary-indep binary-arch
 binary: binary-arch binary-indep
 binary-indep: build-indep
 binary-arch: build-arch
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \
-	KERNELRELEASE=$(KERNELRELEASE) \
+	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
 	run-command KBUILD_RUN_COMMAND=+$(srctree)/scripts/package/builddeb
 
 .PHONY: build build-indep build-arch
 build: build-arch build-indep
 build-indep:
 build-arch:
-	$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) \
-	KERNELRELEASE=$(KERNELRELEASE) \
+	$(MAKE) -f $(srctree)/Makefile $(make-opts) \
 	$(shell $(srctree)/scripts/package/deb-build-option) \
 	olddefconfig all
 
Signature · 1 line
2.40.1