]> git.itanic.dy.fi Git - linux-stable/commitdiff
kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed
authorMasahiro Yamada <masahiroy@kernel.org>
Tue, 26 Dec 2023 13:52:40 +0000 (22:52 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Fri, 5 Jan 2024 10:35:30 +0000 (19:35 +0900)
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 requires dpkg 1.20.6 or newer because --print-format option
was added in dpkg commit 7c54fa2b232e ("dpkg-architecture: Add a
--print-format option").

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
scripts/package/builddeb
scripts/package/debian/rules

index 2fe51e6919da300f500cc6c1f4873ddf6372fbaf..2eb4910f0ef3425eed6af208b297c572b526713d 100755 (executable)
@@ -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
index 529b71b55efa55fae9dcf9f254734960a776d67e..3268340386decf7f679351f34c94015ea89078a6 100755 (executable)
@@ -30,5 +30,16 @@ 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 > $@.tmp
+       mv $@.tmp $@
+endif