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:
debuild
dpkg-buildpackage
dpkg-source --build $dir
→../$pkg_$ver.dsc
make -f debian/rules
dpkg-deb --build $dir $deb
dpkg-genbuildinfo
→../$pkg_$ver_$arch.buildinfo
dpkg-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-source
places the files in the current working directory by default, but you can give it an absolute path.dpkg-deb
can use an absolute path for its output file. It is invoked bydh_builddeb
, which has the option--destdir=Verzeichnis
.dpkg-genbuildinfo
has the-u$dir
option.dpkg-genchanges
has the-u$dir
option.
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
.changes
file is hard-coded indpkg-buildpackage
and cannot be changed. -
Using
DH_OPTIONS
also is not a good idea as the option--destdir
is not unique fordh_builddeb
: It is also used bydh_auto_install
so 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_builddeb
packages may usedpkg-deb
directly and pass arbitrary paths. Therefore there is no way fordpkg-buildpackage
to force an--output-directory
todpkg-deb
without the risk of breaking some obscure package.
TBC…