The sbuild way

See SimpleSbuild for more sbuild details

One-time setup

$ sudo apt-get install ubuntu-dev-tools
$ mk-sbuild --skip-proposed --target armhf vivid
$ sbuild-update --keygen # if this is the first time you have used sbuild on this machine

Replace "vivid" by appropriate target distribution. If you are missing packages, mk-sbuild on first invocation will install them and add your user account to the right group. If that happens, you may need to relogin & rerun above command. Run mk-sbuild for each distribution series you want to target.

Building the package

Build the package:

$ sbuild -A -d vivid --host armhf package*.dsc

Note - you may want to use -n to disable sbuild's automatic build log email feature which is enabled by default, but usually not properly configured. See man sbuild for more information.

Tips & Tricks

In ~/.sbuildrc one can set a few options:

# Mail address where logs are sent to (mandatory, no default!)
$mailto = '';
# We develop $dev
$distribution = "utopic";
# Build arch all packages
$build_arch_all = 1;
# Build arch any packages
$build_arch_any = 1;
# Resolve | Other packages
$resolve_alternatives = 1;
$build_environment = { 'NO_PKG_MANGLE' => '1', 'DEB_BUILD_OPTIONS' => 'parallel=12', 'HOME' => '/build/' };
$run_lintian = 1;
# don't remove this, Perl needs it:
  1. mailto setting makes sure no emails are sent-out by sbuild, which is typically what one wants on a dev machine. (thus no need to pass -n option)

  2. setting distribution makes that distribution the default, thus no need to pass -d utopic all the time

  3. build_arch_all / build_arch_any makes sure that _all.deb and _arch.deb packages are build, thus no need to pass -A option

  4. resolve_alternatives makes sure that alternative build-dependencies are resolved, instead of always taking just the first one
  5. build_environment settings allow doing fancy things:
    • NO_PKG_MANGLE -> do not generate -dbgsym packages, do not run PNG/SVG optimisations, do not strip translations (these are typically done in launchpad for main packages, but are time consuming and not needed on local builds)

    • DEB_BUILD_OPTIONS -> set various DEB_BUILD_OPTIONS see Debian Policy for available flags, but e.g. parallel=X makes builds parallelized, "nocheck" skips running unit tests, "nostrip" keeps debug symbols on all binaries

    • HOME -> by default mk-sbuild sets $HOME to a non-existing directory, but on launchpad, $HOME is set to /build/ which does exist and is writable. So this makes local sbuild match launchpad's one more closely.

  6. run_lintian -> executes lintian against generated packages at the end of the build, using that distribution's lintian (e.g. utopic's lintian when building in utopic chroot)

With above tricks, one can build packages with simply:

$ sbuild --host armhf *.dsc


bzr branch lp:camera-app
cd camera-app
bzr bd -S
cd ../build-area/
sbuild --host armhf camera-app_*.dsc

Common resolutions

  1. If you need python3 interpreter -> Build-Depend on "python3:any"

  2. Use cmake, not qmake
  3. Multi-arch all of your libraries
  4. Make sure that your builds pass without building/running test-suite (as during cross-compilation it will not be possible to execute e.g. compiled test binaries)
  5. At the moment, it's not possible to cross-compile and generate gobject bindings (gir-* packages)

If you have questions

  • Ping Saviq, xnox, or just ask on #ubuntu-devel

The LXC way

If you want to cross-compilation you can also do this with an LXC container.

First create one

$ sudo lxc-create -n vivid-armhf -t ubuntu -- -b $USER -a armhf -r vivid

This creates an armhf container (which will use qemu-arm-static internally, so will be a bit slow as it emulates armhf).

echo "lxc.init_cmd = /sbin/upstart" | sudo tee -a /var/lib/lxc/vivid-armhf/config

This configures the container to use upstart rather than systemd which is quite essential as with systemd the container would start up as qemu is missing support (see Once we get qemu 2.6 in Ubuntu this wouldn't be needed anymore as this then includes support for the missing ioctls. But until then we have to use this and it shouldn't make any difference.

After the container is created you can start the container with

$ sudo lxc-start -n vivid-armhf

The container is now running in the background and is ready to be used. You can get a terminal session with

$ sudo lxc-console -n vivid-armhf

You can login with your regular user and password. Also your /home directory is mounted within the container.

As next steps you want to install the phone overlay ppa so you can properly build everything with the correct build deps available.

container$ sudo add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay

Afterwards you can start to build as normal.

Touch/CrossCompile (last edited 2016-03-22 06:51:23 by morphis)