Skip to contentSkip to conversation

kbuild: add srcdeb-pkg target

PATCH In review Masahiro Yamada 3 participants 8 messages Apr 17, 2023 – Apr 22, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kbuild: add srcdeb-pkg target

This new target builds only the debian source package.

Unify the build rules of deb-pkg, srcdeb-pkg, bindeb-pkg to avoid code duplication.

---

 scripts/Makefile.package | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
scripts/Makefile.package +21 -7
index 4d90691505b1..d8a36304b26e 100644
@@ -5,7 +5,6 @@ include $(srctree)/scripts/Kbuild.include
 include $(srctree)/scripts/Makefile.lib
 
 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
-KBUILD_PKG_ROOTCMD ?="fakeroot -u"
 # Include only those top-level files that are needed by make, plus the GPL copy
 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
                include init io_uring ipc kernel lib mm net rust \
@@ -86,6 +85,9 @@ binrpm-pkg:
 	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
 		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
 
+# deb-pkg srcdeb-pkg bindeb-pkg
+# ---------------------------------------------------------------------------
+
 quiet_cmd_debianize = GEN     $@
       cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
 
@@ -104,14 +106,25 @@ debian-orig: linux.tar.gz debian
 		cp $< ../$(orig-name); \
 	fi
 
-PHONY += deb-pkg
-deb-pkg: debian-orig
-	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
-		--build=source,binary -nc -us -uc
+KBUILD_PKG_ROOTCMD ?= 'fakeroot -u'
+
+PHONY += deb-pkg srcdeb-pkg bindeb-pkg
+
+deb-pkg:    private build-type := source,binary
+srcdeb-pkg: private build-type := source
+bindeb-pkg: private build-type := binary
 
-PHONY += bindeb-pkg
+deb-pkg srcdeb-pkg: debian-orig
 bindeb-pkg: debian
-	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
+deb-pkg srcdeb-pkg bindeb-pkg:
+	+$(strip dpkg-buildpackage \
+	--build=$(build-type) --no-pre-clean --unsigned-changes \
+	$(if $(findstring source, $(build-type)), \
+		--unsigned-source) \
+	$(if $(findstring binary, $(build-type)), \
+		-r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
+		--no-check-builddeps) \
+	$(DPKG_FLAGS))
 
 PHONY += intdeb-pkg
 intdeb-pkg:
@@ -208,6 +221,7 @@ help:
 	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
 	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
 	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
+	@echo '  srcdeb-pkg          - Build only the source kernel deb package'
 	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
 	@echo '  snap-pkg            - Build only the binary kernel snap package'
 	@echo '                        (will connect to external hosts)'
Signature · 1 line
2.37.2
#1 lore raw

PATCH 2/2 kbuild: deb-pkg: add KDEB_SOURCE_COMPRESS to specify compression type

Add KDEB_SOURCE_COMPRESS to specify the compression for the orig and debian tarballs. (The existing KDEB_COMPRESS is used to specify the compression for binary packages.)

Supported algorithms are gzip, bzip2, lzma, and xz, all of which are supported by dpkg-source.

---

 scripts/Makefile.package | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
scripts/Makefile.package +23 -8
index d8a36304b26e..ce3d8b4e9cb0 100644
@@ -41,19 +41,25 @@ check-git:
 		false; \
 	fi
 
-git-config-tar.gz  = -c tar.tar.gz.command="$(KGZIP)"
-git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
-git-config-tar.xz  = -c tar.tar.xz.command="$(XZ)"
-git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
+git-config-tar.gz   = -c tar.tar.gz.command="$(KGZIP)"
+git-config-tar.bz2  = -c tar.tar.bz2.command="$(KBZIP2)"
+git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
+git-config-tar.xz   = -c tar.tar.xz.command="$(XZ)"
+git-config-tar.zst  = -c tar.tar.zst.command="$(ZSTD)"
 
 quiet_cmd_archive = ARCHIVE $@
       cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
                     --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
 
+suffix-gzip  := .gz
+suffix-bzip2 := .bz2
+suffix-lzma  := .lzma
+suffix-xz    := .xz
+
 # Linux source tarball
 # ---------------------------------------------------------------------------
 
-linux-tarballs := $(addprefix linux, .tar.gz)
+linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
 
 targets += $(linux-tarballs)
 $(linux-tarballs): archive-args = $$(cat $<)
@@ -88,6 +94,15 @@ binrpm-pkg:
 # deb-pkg srcdeb-pkg bindeb-pkg
 # ---------------------------------------------------------------------------
 
+KDEB_SOURCE_COMPRESS ?= gzip
+
+PHONY += linux.tar.unsupported_deb_compress
+linux.tar.unsupported_deb_compress:
+	@echo "error: $(KDEB_SOURCE_COMPRESS): unsupported debian source compression" >&2
+	@false
+
+debian-orig-suffix := $(if $(filter gzip bzip2 lzma xz, $(KDEB_SOURCE_COMPRESS)),$(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported_deb_compress)
+
 quiet_cmd_debianize = GEN     $@
       cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
 
@@ -97,9 +112,9 @@ debian: FORCE
 PHONY += debian-orig
 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
-debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
+debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
 debian-orig: mkdebian-opts = --need-source
-debian-orig: linux.tar.gz debian
+debian-orig: linux.tar$(debian-orig-suffix) debian
 	$(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
 		ln -f $< ../$(orig-name); \
 	else \
@@ -120,7 +135,7 @@ deb-pkg srcdeb-pkg bindeb-pkg:
 	+$(strip dpkg-buildpackage \
 	--build=$(build-type) --no-pre-clean --unsigned-changes \
 	$(if $(findstring source, $(build-type)), \
-		--unsigned-source) \
+		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
 	$(if $(findstring binary, $(build-type)), \
 		-r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
 		--no-check-builddeps) \
Signature · 1 line
2.37.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] kbuild: deb-pkg: add KDEB_SOURCE_COMPRESS to specify compression type

Quoted 3 lines · Masahiro Yamada

Add KDEB_SOURCE_COMPRESS to specify the compression for the orig and debian tarballs. (The existing KDEB_COMPRESS is used to specify the compression for binary packages.)

Sounds to me, that it would make sense to sum-up some documentation for kbuild Debian package configuration.

Quoted 45 lines

Supported algorithms are gzip, bzip2, lzma, and xz, all of which are supported by dpkg-source.

---

 scripts/Makefile.package | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
scripts/Makefile.package +11 -5
index d8a36304b26e..ce3d8b4e9cb0 100644
@@ -41,19 +41,25 @@ check-git:
 		false; \
 	fi
 
-git-config-tar.gz  = -c tar.tar.gz.command="$(KGZIP)"
-git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
-git-config-tar.xz  = -c tar.tar.xz.command="$(XZ)"
-git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
+git-config-tar.gz   = -c tar.tar.gz.command="$(KGZIP)"
+git-config-tar.bz2  = -c tar.tar.bz2.command="$(KBZIP2)"
+git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
+git-config-tar.xz   = -c tar.tar.xz.command="$(XZ)"
+git-config-tar.zst  = -c tar.tar.zst.command="$(ZSTD)"
 
 quiet_cmd_archive = ARCHIVE $@
       cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
                     --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
 
+suffix-gzip  := .gz
+suffix-bzip2 := .bz2
+suffix-lzma  := .lzma
+suffix-xz    := .xz
+
 # Linux source tarball
 # ---------------------------------------------------------------------------
 
-linux-tarballs := $(addprefix linux, .tar.gz)
+linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
 
 targets += $(linux-tarballs)
 $(linux-tarballs): archive-args = $$(cat $<)

scripts/Makefile.package binrpm-pkg: · line 97

Quoted 4 lines
scripts/Makefile.package +1 -0
@@ -88,6 +94,15 @@ binrpm-pkg:
 # deb-pkg srcdeb-pkg bindeb-pkg
 # ---------------------------------------------------------------------------
 
+KDEB_SOURCE_COMPRESS ?= gzip

According to dpkg-source(1), xz is the default compression for deb source format >= 2. Shouldn't we use xz here by default as well?

Thanks and kind regards,
Nicolas

Quoted 34 lines
scripts/Makefile.package +11 -3
+
+PHONY += linux.tar.unsupported_deb_compress
+linux.tar.unsupported_deb_compress:
+	@echo "error: $(KDEB_SOURCE_COMPRESS): unsupported debian source compression" >&2
+	@false
+
+debian-orig-suffix := $(if $(filter gzip bzip2 lzma xz, $(KDEB_SOURCE_COMPRESS)),$(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported_deb_compress)
+
 quiet_cmd_debianize = GEN     $@
       cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
 
@@ -97,9 +112,9 @@ debian: FORCE
 PHONY += debian-orig
 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
-debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
+debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
 debian-orig: mkdebian-opts = --need-source
-debian-orig: linux.tar.gz debian
+debian-orig: linux.tar$(debian-orig-suffix) debian
 	$(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
 		ln -f $< ../$(orig-name); \
 	else \
@@ -120,7 +135,7 @@ deb-pkg srcdeb-pkg bindeb-pkg:
 	+$(strip dpkg-buildpackage \
 	--build=$(build-type) --no-pre-clean --unsigned-changes \
 	$(if $(findstring source, $(build-type)), \
-		--unsigned-source) \
+		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
 	$(if $(findstring binary, $(build-type)), \
 		-r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
 		--no-check-builddeps) \
Signature · 1 line
2.37.2
#3 lore raw

Re: [PATCH 2/2] kbuild: deb-pkg: add KDEB_SOURCE_COMPRESS to specify compression type

Quoted 57 lines · Nicolas Schier
Quoted 3 lines · Masahiro Yamada

Add KDEB_SOURCE_COMPRESS to specify the compression for the orig and debian tarballs. (The existing KDEB_COMPRESS is used to specify the compression for binary packages.)

Sounds to me, that it would make sense to sum-up some documentation for kbuild Debian package configuration.

Quoted 48 lines

Supported algorithms are gzip, bzip2, lzma, and xz, all of which are supported by dpkg-source.

---

 scripts/Makefile.package | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
scripts/Makefile.package +11 -5
index d8a36304b26e..ce3d8b4e9cb0 100644
@@ -41,19 +41,25 @@ check-git:
              false; \
      fi
 
-git-config-tar.gz  = -c tar.tar.gz.command="$(KGZIP)"
-git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
-git-config-tar.xz  = -c tar.tar.xz.command="$(XZ)"
-git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
+git-config-tar.gz   = -c tar.tar.gz.command="$(KGZIP)"
+git-config-tar.bz2  = -c tar.tar.bz2.command="$(KBZIP2)"
+git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
+git-config-tar.xz   = -c tar.tar.xz.command="$(XZ)"
+git-config-tar.zst  = -c tar.tar.zst.command="$(ZSTD)"
 
 quiet_cmd_archive = ARCHIVE $@
       cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
                     --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
 
+suffix-gzip  := .gz
+suffix-bzip2 := .bz2
+suffix-lzma  := .lzma
+suffix-xz    := .xz
+
 # Linux source tarball
 # ---------------------------------------------------------------------------
 
-linux-tarballs := $(addprefix linux, .tar.gz)
+linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
 
 targets += $(linux-tarballs)
 $(linux-tarballs): archive-args = $$(cat $<)
@@ -88,6 +94,15 @@ binrpm-pkg:
 # deb-pkg srcdeb-pkg bindeb-pkg
 # ---------------------------------------------------------------------------
 
Quoted 4 lines

scripts/Makefile.package binrpm-pkg: · line 97

Quoted 1 line
scripts/Makefile.package +1 -0
+KDEB_SOURCE_COMPRESS ?= gzip

According to dpkg-source(1), xz is the default compression for deb source format >= 2. Shouldn't we use xz here by default as well?

Yes.
xz is the default because we switched to format 3.0 (quilt).

But, we used gzip for a long time, so I did not change it in this commit.

I do not have a strong opinion.

Ben (debian kernel maintainer) is in the CC list,
perhaps he has some preference.

--
Best Regards
Masahiro Yamada

#4 lore raw

Re: [PATCH 2/2] kbuild: deb-pkg: add KDEB_SOURCE_COMPRESS to specify compression type

Quoted 1 line · Masahiro Yamada

On Thu, Apr 20, 2023 at 5:34 AM Nicolas Schier <[email protected]> wrote:

[...]

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+KDEB_SOURCE_COMPRESS ?= gzip

According to dpkg-source(1), xz is the default compression for deb source format >= 2. Shouldn't we use xz here by default as well?

Yes.
xz is the default because we switched to format 3.0 (quilt).

Quoted 8 lines

But, we used gzip for a long time, so I did not change it in this commit.

I do not have a strong opinion.

Ben (debian kernel maintainer) is in the CC list,
perhaps he has some preference.

I think it makes sense to keep source compression unchanged in this commit, but you could add another commit to change the default.

Ben.

Signature · 2 lines
Ben Hutchings
Theory and practice are closer in theory than in practice - John Levine
#5 lore raw
In reply to Masahiro Yamada
Quoted 8 lines · Masahiro Yamada

This new target builds only the debian source package.

Unify the build rules of deb-pkg, srcdeb-pkg, bindeb-pkg to avoid code duplication.

---

[...]

scripts/Makefile.package debian-orig: linux.tar.gz debian · line 126

Quoted 10 lines

bindeb-pkg: debian

scripts/Makefile.package +8 -1
-	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
+deb-pkg srcdeb-pkg bindeb-pkg:
+	+$(strip dpkg-buildpackage \
+	--build=$(build-type) --no-pre-clean --unsigned-changes \
+	$(if $(findstring source, $(build-type)), \
+		--unsigned-source) \
+	$(if $(findstring binary, $(build-type)), \
+		-r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
+		--no-check-builddeps) \

[...]

There is no need to make the use of --unsigned-source (-us) or -r conditional on the build type. They will be ignored if not applicable.

This is also adding --no-check-builddeps (-d), which is not explained in the commit message. It might be valid to add this for srcdeb-pkg, but the build dependency check is valuable for bindeb-pkg and deb-pkg.

Ben.

Signature · 2 lines
Ben Hutchings
Sturgeon's Law: Ninety percent of everything is crap.
#6 lore raw
Quoted 21 lines · Ben Hutchings
Quoted 8 lines · Masahiro Yamada

This new target builds only the debian source package.

Unify the build rules of deb-pkg, srcdeb-pkg, bindeb-pkg to avoid code duplication.

---

[...]

scripts/Makefile.package debian-orig: linux.tar.gz debian · line 126

Quoted 10 lines

bindeb-pkg: debian

scripts/Makefile.package +8 -1
-     +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
+deb-pkg srcdeb-pkg bindeb-pkg:
+     +$(strip dpkg-buildpackage \
+     --build=$(build-type) --no-pre-clean --unsigned-changes \
+     $(if $(findstring source, $(build-type)), \
+             --unsigned-source) \
+     $(if $(findstring binary, $(build-type)), \
+             -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
+             --no-check-builddeps) \
Quoted 4 lines

[...]

There is no need to make the use of --unsigned-source (-us) or -r conditional on the build type. They will be ignored if not applicable.

True, but you can also say there is no need
to pass options that we know are unnecessary.

My motivation is to make unneeded options
really don't-care.

2/2 will add KDEB_SOURCE_COMPRESS.

If I do not make it optional,
"KDEB_SOURCE_COMPRESS=foo make bindeb-pkg"
would fail.

dpkg-buildpackage --build=binary --no-pre-clean --unsigned-changes --unsigned-source --compression=foo -r'fakeroot -u' -a$(cat debian/arch)
dpkg-buildpackage: info: source package linux-upstream
dpkg-buildpackage: info: source version 6.3.0-rc7-00003-geb58366b57fe-33
dpkg-buildpackage: info: source distribution kinetic
dpkg-buildpackage: info: source changed by Masahiro Yamada <[email protected]>
dpkg-buildpackage: info: host architecture amd64
dpkg-source --compression=foo --before-build .
dpkg-source: error: foo is not a supported compression

Use --help for program usage information.

"dpkg-buildpackage --build=binary" does not
generate a source package, but still checks
if --compression=foo is correct.

Quoted 3 lines

This is also adding --no-check-builddeps (-d), which is not explained in the commit message. It might be valid to add this for srcdeb-pkg, but the build dependency check is valuable for bindeb-pkg and deb-pkg.

Yes.
So, I added --no-check-builddeps to the else arm.

I will add the following commit description:

--no-check-builddeps is added to srcbin-pkg
so that build dependencies will not be checked.

Quoted 6 lines

Ben.

--
Ben Hutchings
Sturgeon's Law: Ninety percent of everything is crap.

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw
Quoted 1 line · Masahiro Yamada

On Mon, Apr 17, 2023 at 11:52 PM Ben Hutchings <[email protected]> wrote:

[...]

Quoted 7 lines
Quoted 3 lines

This is also adding --no-check-builddeps (-d), which is not explained in the commit message. It might be valid to add this for srcdeb-pkg, but the build dependency check is valuable for bindeb-pkg and deb-pkg.

Yes.
So, I added --no-check-builddeps to the else arm.

[...]

Sorry, I read that wrongly.

Ben.

Signature · 2 lines
Ben Hutchings
Theory and practice are closer in theory than in practice - John Levine