Skip to content

Build i386 packages on amd64

Here is how I build both amd64 and i386 Debian packages on my amd64 host, using cowbuilder.
The same should be possible using pbuilder, but I prefer cowbuilder which is faster

Creating the chroots

First, let’s create the base images (this step has to be executed as root). By default, the target distribution is unstable (sid).

# cowbuilder --create --architecture amd64 --basepath /var/cache/pbuilder/base-unstable_amd64.cow
# cowbuilder --create --architecture i386 --basepath /var/cache/pbuilder/base-unstable_i386.cow

To update the chroots, you will also have to pass the --basepath option.

pbuilder

Configuring pbuilder

Here is my ~/.pbuilderrc file, which should obviously be adapted to your own needs:

# do not specify variables when running cowbuilder --create or --update
if [ -f debian/changelog ]; then
        [ -z "$ARCH" ] && ARCH=$(dpkg --print-architecture)
        [ -z "$DIST" ] && DIST=$(dpkg-parsechangelog | sed -n 's/^Distribution: //p')
fi
 
PDEBUILD_PBUILDER="cowbuilder --build --basepath /var/cache/pbuilder/base-${DIST}_${ARCH}.cow"
 
DEBBUILDOPTS="-d ${OPTS}"
 
ARCHITECTURE=${ARCH}
 
BUILDRESULT=~/build-area
 
MIRRORSITE=http://ftp.fr.debian.org/debian
EXTRAPACKAGES="$EXTRAPACKAGES lintian"
 
AUTO_DEBSIGN=yes
 
HOOKDIR=${HOME}/.pbuilder/hooks/
 
PKGNAME_LOGFILE_EXTENTION="_${ARCH}.build"

Automatically check built packages with lintian

I use the following hook to automatically check the built packages with lintian within the chroot.
This should be saved as ~/.pbuilder/hooks/B91_lintian:

#!/bin/sh
# run lintian
 
echo "I: running lintian on the package"
echo ""
echo "============================== LINTIAN RESULTS =============================="
echo ""
tput "smso"
lintian --allow-root -I /tmp/buildd/*.changes 
tput "rmso"
echo ""
echo "============================================================================="
echo ""

Building the packages

Standard build

To build packages, I use the following steps:

  1. build i386 binary packages only:
    $ ARCH=i386 pdebuild --debbuildopts -b
  2. build amd64 packages:
    $ pdebuild
  3. merge and sign changelogs:
    $ cd ~/build-area
    $ mergechanges -f package_0.1-1_i386.changes packages_0.1-1_amd64.changes
    $ debsign package_0.1-1_multi.changes

Packages can then be uploaded using the _multi.changes file using your standard tool (dupload or dput).

Building for other distributions

As you might have noticed, I also sometimes build packages for stable (backports). By default, my pbuilder configuration takes the target distribution by reading the changelog. Base images should be built with --distribution < target > (see cowbuilder(8) for more information).

If you want to overwrite this, you can specify the $DIST variable when building the package:

$ DIST=stable pdebuild

I find it comfortable to add symlinks so that I am able to use either the distribution name or its code name:

# ln -s /var/cache/pbuilder/base-unstable_amd64.cow /var/cache/pbuilder/base-sid_amd64.cow
# ln -s /var/cache/pbuilder/base-unstable_i386.cow /var/cache/pbuilder/base-sid_i386.cow

git-buildpackage

You can also use this setup combined with git-buildpackage.

To build a package:

ARCH=i386 git-buildpackage --git-builder="pdebuild --debbuildopts -b"
ARCH=amd64 git-buildpackage --git-builder="pdebuild"

The default builder can also be defined in ~/.gbp.conf, but you will have to change it to pass the correct build options.

Also note that git-buildpackage >= 0.5.6 comes with a git-pbuilder script which eases using git-buildpackage and pbuilder/cowbuilder.
More information on: http://honk.sigxcpu.org/con/Git_buildpackage_0_5_6.html