linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules
@ 2023-12-26 13:52 Masahiro Yamada
  2023-12-26 13:52 ` [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules Masahiro Yamada
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

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

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/package/debian/rules | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 3dafa9496c63..26bc6239e200 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
@ 2023-12-26 13:52 ` Masahiro Yamada
  2023-12-27  7:56   ` Nicolas Schier
  2023-12-26 13:52 ` [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed Masahiro Yamada
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 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

diff --git a/scripts/package/deb-build-option b/scripts/package/deb-build-option
deleted file mode 100755
index 7950eff01781..000000000000
--- a/scripts/package/deb-build-option
+++ /dev/null
@@ -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
diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 26bc6239e200..529b71b55efa 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
  2023-12-26 13:52 ` [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules Masahiro Yamada
@ 2023-12-26 13:52 ` Masahiro Yamada
  2023-12-27  8:08   ` Nicolas Schier
  2023-12-26 13:52 ` [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory Masahiro Yamada
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

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").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/package/builddeb     |  5 ++---
 scripts/package/debian/rules | 12 +++++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 2fe51e6919da..2eb4910f0ef3 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -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
diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 529b71b55efa..8f24a8e84bf2 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
  2023-12-26 13:52 ` [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules Masahiro Yamada
  2023-12-26 13:52 ` [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed Masahiro Yamada
@ 2023-12-26 13:52 ` Masahiro Yamada
  2023-12-27  8:09   ` Nicolas Schier
  2023-12-26 13:52 ` [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules Masahiro Yamada
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

'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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/package/debian/rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 8f24a8e84bf2..6b2333e3cf96 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
                   ` (2 preceding siblings ...)
  2023-12-26 13:52 ` [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory Masahiro Yamada
@ 2023-12-26 13:52 ` Masahiro Yamada
  2023-12-27  8:11   ` Nicolas Schier
  2023-12-26 13:52 ` [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb Masahiro Yamada
  2023-12-27  7:55 ` [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Nicolas Schier
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/package/debian/rules | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 6b2333e3cf96..36d51f60f98d 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
                   ` (3 preceding siblings ...)
  2023-12-26 13:52 ` [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules Masahiro Yamada
@ 2023-12-26 13:52 ` Masahiro Yamada
  2024-04-02 15:59   ` Robert Nelson
  2023-12-27  7:55 ` [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Nicolas Schier
  5 siblings, 1 reply; 13+ messages in thread
From: Masahiro Yamada @ 2023-12-26 13:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Ben Hutchings, Masahiro Yamada, Nicolas Schier, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

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.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
---

 scripts/package/builddeb     | 23 ++++++++---------------
 scripts/package/debian/rules |  2 ++
 scripts/package/mkdebian     |  2 +-
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 2eb4910f0ef3..436d55a83ab0 100755
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -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 () {
diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
index 36d51f60f98d..1f56938ea5d4 100755
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -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))))
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
index 93a24712b9a1..070149c985fe 100755
--- a/scripts/package/mkdebian
+++ b/scripts/package/mkdebian
@@ -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/
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules
  2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
                   ` (4 preceding siblings ...)
  2023-12-26 13:52 ` [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb Masahiro Yamada
@ 2023-12-27  7:55 ` Nicolas Schier
  5 siblings, 0 replies; 13+ messages in thread
From: Nicolas Schier @ 2023-12-27  7:55 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nathan Chancellor, Nick Desaulniers,
	linux-kernel

On Tue, Dec 26, 2023 at 10:52:38PM +0900, Masahiro Yamada wrote:
> This avoid code duplication between binary-arch and built-arch.

avoids ?

Reviewed-by: Nicolas Schier <n.schier@avm.de>

> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/package/debian/rules | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 3dafa9496c63..26bc6239e200 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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
>  
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules
  2023-12-26 13:52 ` [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules Masahiro Yamada
@ 2023-12-27  7:56   ` Nicolas Schier
  0 siblings, 0 replies; 13+ messages in thread
From: Nicolas Schier @ 2023-12-27  7:56 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-kernel

On Tue, Dec 26, 2023 at 10:52:39PM +0900, Masahiro Yamada wrote:
> 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.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Reviewed-by: Nicolas Schier <n.schier@avm.de>


> 
>  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
> 
> diff --git a/scripts/package/deb-build-option b/scripts/package/deb-build-option
> deleted file mode 100755
> index 7950eff01781..000000000000
> --- a/scripts/package/deb-build-option
> +++ /dev/null
> @@ -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
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 26bc6239e200..529b71b55efa 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed
  2023-12-26 13:52 ` [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed Masahiro Yamada
@ 2023-12-27  8:08   ` Nicolas Schier
  0 siblings, 0 replies; 13+ messages in thread
From: Nicolas Schier @ 2023-12-27  8:08 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-kernel

On Tue, Dec 26, 2023 at 10:52:40PM +0900, Masahiro Yamada wrote:
> 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").
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/package/builddeb     |  5 ++---
>  scripts/package/debian/rules | 12 +++++++++++-
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/scripts/package/builddeb b/scripts/package/builddeb
> index 2fe51e6919da..2eb4910f0ef3 100755
> --- a/scripts/package/builddeb
> +++ b/scripts/package/builddeb
> @@ -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
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 529b71b55efa..8f24a8e84bf2 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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
> -- 
> 2.40.1

Thanks!

Reviewed-by: Nicolas Schier <n.schier@avm.de>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory
  2023-12-26 13:52 ` [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory Masahiro Yamada
@ 2023-12-27  8:09   ` Nicolas Schier
  0 siblings, 0 replies; 13+ messages in thread
From: Nicolas Schier @ 2023-12-27  8:09 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nathan Chancellor, Nick Desaulniers,
	linux-kernel

On Tue, Dec 26, 2023 at 10:52:41PM +0900, Masahiro Yamada wrote:
> '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

> the output directory.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/package/debian/rules | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 8f24a8e84bf2..6b2333e3cf96 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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.

Reviewed-by: Nicolas Schier <n.schier@avm.de>

>  
>  .PHONY: build build-indep build-arch
>  build: build-arch build-indep
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules
  2023-12-26 13:52 ` [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules Masahiro Yamada
@ 2023-12-27  8:11   ` Nicolas Schier
  0 siblings, 0 replies; 13+ messages in thread
From: Nicolas Schier @ 2023-12-27  8:11 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-kernel

On Tue, Dec 26, 2023 at 10:52:42PM +0900, Masahiro Yamada wrote:
> 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.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---

Reviewed-by: Nicolas Schier <n.schier@avm.de>

> 
>  scripts/package/debian/rules | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 6b2333e3cf96..36d51f60f98d 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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
> -- 
> 2.40.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb
  2023-12-26 13:52 ` [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb Masahiro Yamada
@ 2024-04-02 15:59   ` Robert Nelson
  2024-04-02 20:35     ` Robert Nelson
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Nelson @ 2024-04-02 15:59 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nicolas Schier, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

On Tue, Dec 26, 2023 at 7:54 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> 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.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-by: Nicolas Schier <n.schier@avm.de>
> ---
>
>  scripts/package/builddeb     | 23 ++++++++---------------
>  scripts/package/debian/rules |  2 ++
>  scripts/package/mkdebian     |  2 +-
>  3 files changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/scripts/package/builddeb b/scripts/package/builddeb
> index 2eb4910f0ef3..436d55a83ab0 100755
> --- a/scripts/package/builddeb
> +++ b/scripts/package/builddeb
> @@ -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 () {
> diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
> index 36d51f60f98d..1f56938ea5d4 100755
> --- a/scripts/package/debian/rules
> +++ b/scripts/package/debian/rules
> @@ -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))))
> diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
> index 93a24712b9a1..070149c985fe 100755
> --- a/scripts/package/mkdebian
> +++ b/scripts/package/mkdebian
> @@ -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 <robertcnelson@gmail.com>
 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 <robertcnelson@gmail.com>
 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 <robertcnelson@gmail.com>
 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,

-- 
Robert Nelson
https://rcn-ee.com/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb
  2024-04-02 15:59   ` Robert Nelson
@ 2024-04-02 20:35     ` Robert Nelson
  0 siblings, 0 replies; 13+ messages in thread
From: Robert Nelson @ 2024-04-02 20:35 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, Ben Hutchings, Nicolas Schier, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kernel

> > +++ b/scripts/package/mkdebian
> > @@ -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 <robertcnelson@gmail.com>
>  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,

-- 
Robert Nelson
https://rcn-ee.com/

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-04-02 20:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-26 13:52 [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Masahiro Yamada
2023-12-26 13:52 ` [PATCH 2/6] kbuild: deb-pkg: squash scripts/package/deb-build-option to debian/rules Masahiro Yamada
2023-12-27  7:56   ` Nicolas Schier
2023-12-26 13:52 ` [PATCH 3/6] kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed Masahiro Yamada
2023-12-27  8:08   ` Nicolas Schier
2023-12-26 13:52 ` [PATCH 4/6] kbuild: deb-pkg: allow to run debian/rules from output directory Masahiro Yamada
2023-12-27  8:09   ` Nicolas Schier
2023-12-26 13:52 ` [PATCH 5/6] kbuild: deb-pkg: remove unneeded '-f $srctree/Makefile' in debian/rules Masahiro Yamada
2023-12-27  8:11   ` Nicolas Schier
2023-12-26 13:52 ` [PATCH 6/6] kbuild: deb-pkg: use more debhelper commands in builddeb Masahiro Yamada
2024-04-02 15:59   ` Robert Nelson
2024-04-02 20:35     ` Robert Nelson
2023-12-27  7:55 ` [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules Nicolas Schier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).