2023-12-26 13:53:05

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules

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

Signed-off-by: Masahiro Yamada <[email protected]>
---

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



2023-12-26 13:53:15

by Masahiro Yamada

[permalink] [raw]
Subject: [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.

Signed-off-by: Masahiro Yamada <[email protected]>
---

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


2023-12-26 13:53:29

by Masahiro Yamada

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

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 <[email protected]>
---

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


2023-12-26 13:53:55

by Masahiro Yamada

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

'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 <[email protected]>
---

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


2023-12-26 13:53:59

by Masahiro Yamada

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

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 <[email protected]>
---

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


2023-12-26 13:54:13

by Masahiro Yamada

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

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 <[email protected]>
Reviewed-by: Nicolas Schier <[email protected]>
---

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


2023-12-27 07:55:38

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 1/6] kbuild: deb-pkg: factor out common Make options in debian/rules

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 <[email protected]>

>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> 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
>

2023-12-27 07:56:52

by Nicolas Schier

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

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 <[email protected]>
> ---

Reviewed-by: Nicolas Schier <[email protected]>


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

2023-12-27 08:08:38

by Nicolas Schier

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

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 <[email protected]>
> ---
>
> 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 <[email protected]>

2023-12-27 08:10:09

by Nicolas Schier

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

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 <[email protected]>
> ---
>
> 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 <[email protected]>

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

2023-12-27 08:11:17

by Nicolas Schier

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

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 <[email protected]>
> ---

Reviewed-by: Nicolas Schier <[email protected]>

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

2024-04-02 16:01:25

by Robert Nelson

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

On Tue, Dec 26, 2023 at 7:54 AM Masahiro Yamada <[email protected]> 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 <[email protected]>
> Reviewed-by: Nicolas Schier <[email protected]>
> ---
>
> 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 <[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,

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

2024-04-02 20:36:43

by Robert Nelson

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

> > +++ 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 <[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,

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