Friday, February 27, 2015

Cross compiling armhf for Debian distribution (Qt5 and chroot)

This guide covers building Qt5 projects into armhf architecture .deb files for distribution.

Make Emulated Root Enviroment

First we want to make an emulated root environment to do all of our work in [1]. We need to get debootstrap and qemu-user-static to do this.
sudo apt-get install debootstrap qemu-user-static
sudo qemu-debootstrap --no-check-gpg --arch=armhf sid /chroots/sid-armhf ftp://ftp.debian.org/debian/
view raw gistfile1.txt hosted with ❤ by GitHub

This will take a long time as we are building a new root filesystem of archetecture armhf in /chroots/sid-armhf. You may have noticed sid in a few places. This is debians unstable distribution. You could replace it with any other release found in:
ftp://ftp.debian.org/debian/dists/

Next we need to change our apparent root directory and mount the proc directory:
sudo chroot /chroots/sid-armhf
mount -t proc proc /proc
view raw gistfile1.txt hosted with ❤ by GitHub

Create a /usr/sbin/policy-rc.d to prevent daemons from starting up inside the chroot:
echo "************************************" >&2
echo "All rc.d operations denied by policy" >&2
echo "************************************" >&2
exit 101
view raw policy-rc.d hosted with ❤ by GitHub

And change the permissions to 775:
chmod 0755 /usr/sbin/policy-rc.d
view raw gistfile1.txt hosted with ❤ by GitHub

Finally modify the /etc/apt/sources.lst file to a proper repository for the root:
deb http://ftp.debian.org/debian sid main
deb-src http://ftp.debian.org/debian sid main
view raw sources.list hosted with ❤ by GitHub
Then update and install the archive-keyring followed by another update of apt:
apt-get update && apt-get install debian-archive-keyring && apt-get update
view raw gistfile1.txt hosted with ❤ by GitHub

To reduce error messages about locales you may wish to install the locales package in the emulated root environment:
apt-get install locales
view raw gistfile1.txt hosted with ❤ by GitHub

And then configure it selecting (assuming you are using US English):
  en_US.ISO-8859-1
  en_US.ISO-8859-15
  en_US.UTF-8
I chose to use UTF-8 as the default locale.
dpkg-reconfigure locales
view raw gistfile1.txt hosted with ❤ by GitHub

Making a .deb from a Qt Project

This next portion focuses on creating a .deb file from a Qt project, following the steps outlined in [3] is recommended for a better understanding.

I have built a sample project to package which can be found here:
https://bitbucket.org/ablaylock/qtdebianpackage.git

Clone the repo into helloworld-0.0.1 (do this somewhere smart like /home/username):
git clone https://bitbucket.org/ablaylock/qtdebianpackage.git helloworld-0.0.1
view raw gistfile1.txt hosted with ❤ by GitHub

Next we need to install the proper packages for building the Qt project and .deb files:
apt-get install build-essential dh-make qt5-default qttools5-dev-tools
view raw gistfile1.txt hosted with ❤ by GitHub

Now we are ready to rock. To build the package (without source, if you want source follow the steps in [3]) run the dist_gen.sh script.
./helloworld-0.0.1/dist_gen.sh
view raw gistfile1.txt hosted with ❤ by GitHub

No comments:

Post a Comment