Build Debian packages out-of-tree
Debians dpkg-buildpackage has the annoying feature, that the build artifacts are placed in the parent directory.
Bug 657491 requested that feature in 2012, but there still is no such option.
While working on speeding up the build process I investigated, how that could be fixed or at least be worked around.
Building a package by default involves the following programs calling each other:
debuilddpkg-buildpackagedpkg-source --build $dir→../$pkg_$ver.dscmake -f debian/rulesdpkg-deb --build $dir $deb
dpkg-genbuildinfo→../$pkg_$ver_$arch.buildinfodpkg-genchanges→../$pkg_$ver_$arch.changes
Several of them already have an option to overwrite the directory and/or an be invoked from paths outside the normal build directory:
dpkg-sourceplaces the files in the current working directory by default, but you can give it an absolute path.dpkg-debcan use an absolute path for its output file. It is invoked bydh_builddeb, which has the option--destdir=Verzeichnis.dpkg-genbuildinfohas the-u$diroption.dpkg-genchangeshas the-u$diroption.
So for a first try for an out-of-tree build we can do it like this:
#/bin/sh
set -e -u
src="$PWD"
out="$HOME/my-repo"
# Manually build source with absolute path
dpkg-source --before-build .
(cd "$out" && dpkg-source --build "$src")
# For the rest use dpkg-buildpackage
DH_OPTIONS="--destdir=$out" \
dpkg-buildpackage \
--buildinfo-option=-u"$out" \
--changes-option=-u"$out" \
-b --no-sign
# More work like
dpkg-source --aftere-build .
(cd "$out" && debsign *.changes) # FIXME
This mostly works but fails for the following reasons at the moment:
-
The path for the
.changesfile is hard-coded indpkg-buildpackageand cannot be changed. -
Using
DH_OPTIONSalso is not a good idea as the option--destdiris not unique fordh_builddeb: It is also used bydh_auto_installso files get installed in the wrong location. -
Debian policy only recommends the use of
debhelper, but packages are free to use other strategies in their filedebian/rules. Instead of using the wrapperdh_builddebpackages may usedpkg-debdirectly and pass arbitrary paths. Therefore there is no way fordpkg-buildpackageto force an--output-directorytodpkg-debwithout the risk of breaking some obscure package.
TBC…