Build Debian packages out-of-tree
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:
dpkg-source --build $dir→
make -f debian/rules
dpkg-deb --build $dir $deb
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 by
dh_builddeb, which has the 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 two reasons at the moment:
The path for the
.chagnesfile is hard-coded in
dpkg-buildpackageand cannot be changed.
DH_OPTIONSalso is not a good idea as the option
--destdiris not unique for
dh_builddeb: It is also used by
dh_auto_installso files get installed in the wrong location.