<p>ⓒ Richard Levitte</p>
http://journal.richard.levitte.org/tags/debian/Richard Levitte's journalikiwiki2011-07-23T14:24:45ZHacking the Debian build system from within...http://journal.richard.levitte.org/entries/hacking-debian-build-system/2011-07-23T14:24:45Z2011-02-26T08:38:52Z
<p><a class="FlattrButton" href=
"http://journal.richard.levitte.org/entries/hacking-debian-build-system/"
title="Hacking the Debian build system from within..." rev=
"flattr;uid:levitte;button:compact;category:text;tags:hacking,debian,dpkg-buildpackage;">
It seems there's an annoying fault in dpkg-buildpackage, it doesn't
support build-arch and build-indep in the file debian/rules. This
blog entry talks about an easy way to solve this.</a></p>
<p>It seems there's an annoying fault in <a href=
"http://www.debian.org/doc/maint-guide/ch-build.en.html">dpkg-buildpackage</a>,
it doesn't support <tt>build-arch</tt> and <tt>build-indep</tt> in
the file <tt>debian/rules</tt>. Even when given the options to
create architecture dependent binary packages only (-B) or
architecture independent packages only (-A), it still insists on
using the <tt>build</tt> target.</p>
<p>People have been annoyed at this for quite a while, considering
there are a number of bug reports that have still not been resolved
although this has been around for years (See bugs <a href=
"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=218893">#218893</a>
and <a href=
"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=229357">#229357</a>,
but also more recently, <a href=
"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=604397">#604397</a>).</p>
<p><a href=
"http://www.debian.org/doc/debian-policy/ch-source.html#s-debianrules">
Debian Policy Manual, section 4.9 (debian/rules)</a> seems to say,
however, that it's perfectly acceptable to have the package built
via <tt>binary</tt> / <tt>binary-indep</tt> /
<tt>binary-arch</tt>:</p>
<blockquote>
<p>For some packages, notably ones where the same source tree is
compiled in different ways to produce two binary packages, the
build target does not make much sense. For these packages it is
good enough to provide two (or more) targets (build-a and build-b
or whatever) for each of the ways of building the package, and a
build target that does nothing. The binary target will have to
build the package in each of the possible ways and make the binary
package out of each.</p>
</blockquote>
<p>Unfortunately, those targets are run via <tt>fakeroot</tt>,
which is not recommended for <tt>configure</tt>, and sometimes not
build building or testing.</p>
<p>So, how to solve that? There are some convoluted half ass ways
to resolve this, but can it be made cleaner? Here's my attempt,
entirely based on using <tt>debhelper</tt> and the script
<tt>dh</tt>.</p>
<p>In <tt>debian/rules</tt>, disable the build target entirely, by
having this as early as possible (and most definitely before the
<tt>%</tt> target that's usually seen in a <tt>debian/rules</tt>
that uses the command <tt>dh</tt>):</p>
<pre>
build:
@echo 'The build target is disabled, please use the appropriate binary target.'
</pre>
<p>Add the script <tt>nofakeroot</tt> in the <tt>debian/</tt>
directory, and don't forget to make it executable. Here's what the
script looks like:</p>
<pre>
#! /bin/sh
# Usage:
# nofakeroot [command ...]
#
# Runs command after removing any trace of fakeroot from the environment it
# receives.
my_PRELOAD=
for l in $LD_PRELOAD; do
if ! echo $l | grep "libfakeroot[-a-z]*\\.so" > /dev/null; then
if [ -n "$my_PRELOAD" ]; then
my_PRELOAD="$my_PRELOAD $l"
else
my_PRELOAD="$l"
fi
fi
done
was_IFS="$IFS" IFS=:
my_LIBRARY_PATH=
for p in $LD_LIBRARY_PATH; do
if ! echo $p | grep "/libfakeroot\$" > /dev/null; then
if [ -n "$my_LIBRARY_PATH" ]; then
my_LIBRARY_PATH="${my_LIBRARY_PATH}:$p"
else
my_LIBRARY_PATH="$p"
fi
fi
done
IFS="$was_IFS"
LD_PRELOAD="$my_PRELOAD" LD_LIBRARY_PATH="$my_LIBRARY_PATH" eval "$@"
</pre>
<p>Finally, add a few overrides in <tt>debian/rules</tt>:</p>
<pre>
override_dh_auto_configure:
debian/nofakeroot dh_auto_configure
override_dh_auto_build:
debian/nofakeroot dh_auto_build
override_dh_auto_test:
debian/nofakeroot dh_auto_test
</pre>
<p>The entire <tt>debian/rules</tt> looks like this:</p>
<pre>
build:
@echo 'The build target is disabled, please use the appropriate binary target.'
%:
dh $@
override_dh_auto_configure:
debian/nofakeroot dh_auto_configure
override_dh_auto_build:
debian/nofakeroot dh_auto_build
override_dh_auto_test:
debian/nofakeroot dh_auto_test
</pre>