A simple cross-compiler for the Raspberry Pi
I've recently found some use for a first-generation Raspberry Pi (Pi 1 model B) which had been lying in a drawer since many years. A few days ago I've installed the Raspbian distribution in it, and was about to installmotion
on it, but I stopped as soon as I noticed that
was suggesting to bring in 1 GB worth of dependencies. Adding
reduced the proposal a bit, but it was still around 700 MB -- a bit too much for my taste. I figured out that the
package for Debian (and Raspbian) depends on MySQL, PostgreSQL, FFmpeg and what not; so, I decided that I could probably just recompile it and disable all the stuff I didn't need at
But I didn't want to install all the build dependencies and the cross-compiler in my machine; containers exist for a reason, after all. So I had a look at thecrossbuilder
tool that we use in UBports: this is a nice little shell program that uses an Ubuntu-based LXD image to cross-compile a package after automatically fetching all its dependencies, and installs it into an UBports device. It does some magic with
and stuff, but I thought that the basic functionality should work with minor modifications on any Debian-based distribution.
And indeed, some hours later, I got a branch
where I can use
to build packages for the Raspberry Pi. Assuming that you have LXD properly setup, the command
crossbuilder --raspbian source motion
will cause crossbuilder to create a container and download the Debian source package for
; at this point you can modify the source code as you see fit, and rebuild it. I only changed the
file to add a few flags such as
, etc. And
is the command to run in order to perform the build. This will first download all the dependencies (according to the
file), build the package, and create a
archive containing all the generated
files. This archive can then be copied into the target device and unpacked there.
Now, there's a small problem in that Raspbian claims to be
, while in fact its floating-point processor is somehow not compliant with the armhf architecture. So, you generally cannot use an
package from Debian or Ubuntu on the Raspberry Pi. Given that I didn't have the time to prepare a proper Raspbian image for LXD, I used the Debian distribution as a base instead, and I chose to target the
architecture: this might impose some penalties on the performance (at least for floating-point code), but it seems to work fine on the Raspberry Pi. Unfortunately, this means that you cannot just install the generated packages o the Pi, as
will complain about the architecture mismatch (your package is
, while the distro claims to be
). But unpacking the debian package with
dpkg -x motion_<...>.deb tmp
will indeed give you package that you can use.
I will eventually get back to this and make the script work better with Raspbian, but this is a quick start.