Skip to content

Commit 159956f

Browse files
committed
kbuild: deb-pkg: set DEB_* variables if debian/rules is directly executed
Since commit 491b146 ("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 <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 7d4f07d commit 159956f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

scripts/package/builddeb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ install_libc_headers () {
171171

172172
# move asm headers to /usr/include/<libc-machine>/asm to match the structure
173173
# used by Debian-based distros (to support multi-arch)
174-
host_arch=$(dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH)
175-
mkdir $pdir/usr/include/$host_arch
176-
mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
174+
mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
175+
mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
177176
}
178177

179178
rm -f debian/files

scripts/package/debian/rules

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,16 @@ build-arch:
3030

3131
.PHONY: clean
3232
clean:
33-
rm -rf debian/files debian/linux-*
33+
rm -rf debian/files debian/linux-* debian/deb-env.vars*
3434
$(MAKE) -f $(srctree)/Makefile ARCH=$(ARCH) clean
35+
36+
# If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
37+
# directly. Run 'dpkg-architecture --print-set --print-format=make' to
38+
# generate a makefile construct that exports all DEB_* variables.
39+
ifndef DEB_HOST_ARCH
40+
include debian/deb-env.vars
41+
42+
debian/deb-env.vars:
43+
dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
44+
mv $@.tmp $@
45+
endif

0 commit comments

Comments
 (0)