Cross-compiling TVHeadend for Raspberry Pi

This guide details how to set up a chroot environment to enable you to build TVHeadend for Raspberry Pi (which uses the arm architecture) on an x86_64 Debian distribution.

Setting up the chroot

A chroot is essentially an installation of the linux operating system that exists within the host version but is (or can be) completely isolated from the outside host. This means that it’s possible to build packages for completely different versions of linux than the one running the chroot and indeed even different architectures. This guide specifically details setting up a chroot which runs the armhf version of Debian (as used by the Raspberry Pi) to enable you to build and optionally package a version of TVHeadend for distribution and use on the Raspberry Pi.

Installing the required tools

sudo apt-get install qemu-user-static dchroot schroot debootstrap wget

or

sudo aptitude install qemu-user-static dchroot schroot debootstrap wget
cd /tmp
wget https://archive.raspbian.org/raspbian/pool/main/r/raspbian-archive-keyring/raspbian-archive-keyring_20120528.2_all.deb
sudo dpkg -i raspbian-archive-keyring_20120528.2_all.deb

Creating your chroot

sudo mkdir -p /var/chroot/raspbian-armhf/
sudo qemu-debootstrap --keyring /usr/share/keyrings/raspbian-archive-keyring.gpg --arch armhf jessie /var/chroot/raspbian-armhf http://archive.raspbian.org/raspbian

If you want to use a different version of Debian other than jessie – substitute jessie for your preferred version (i.e. wheezy) in the command above

sudo echo raspbian-armhf | sudo tee /var/chroot/raspbian-armhf/etc/debian_chroot
sudo ln -s ../proc/mounts /var/chroot/raspbian-armhf/etc/mtab
sudo cp /etc/passwd /etc/group /etc/shadow /var/chroot/raspbian-armhf/etc
sudo nano /etc/dchroot.conf

Enter the following in the newly created file;

raspbian-armhf /var/chroot/raspbian-armhf
sudo nano /etc/schroot/schroot.conf

Enter (or add to the end of the file) the following. Again substitute jessie for your preferred debian variant (i.e. wheezy)

[raspbian-armhf]
description=raspbian jessie armhf
location=/var/chroot/raspbian-armhf
users=pd
groups=sbuild-security
root-groups=root
personality=linux32

Entering the chroot

sudo dchroot -d -c raspbian-armhf

The following commands all happen inside of the chroot – ensure that your bash prompt says ‘raspbian-armhf’ before continuing as this confirms you are inside of your chroot environment.

Installing the required tools

sudo apt-get install git build-essential pkg-config libssl-dev bzip2 wget libavahi-client-dev zlib1g-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavresample-dev python gettext cmake libdvbcsa-dev liburiparser-dev debhelper libcurl4-gnutls-dev curl

If you get an error whilst trying to install these packages, check your sources.list to ensure it has not been replaced by another mirror other than the raspbian one;

sudo nano /etc/apt/sources.list

It should look like this;

deb http://archive.raspbian.org/raspbian jessie main
deb-src http://archive.raspbian.org/raspbian jessie main

If it doesn’t, delete any lines in the file (CTRL+K) then replace them with the above lines and try installing the packages again.

Downloading the TVHeadend source code

Change to the root directory;

cd /root

To download the latest stable (4.0) source code then running

git clone -b release/4.0 https://github.com/tvheadend/tvheadend.git

If you want to get the very latest (4.1) source code (which is considered unstable) then running

git clone https://github.com/tvheadend/tvheadend.git

Packaging the source code into a redistributable .deb package

As the intention of this guide is to install the package on a different machine, we have skipped the ‘build’ step as it is incorporated into the packaging instructions below.

From the TVHeadend source directory, run;

AUTOBUILD_CONFIGURE_EXTRA='--prefix=/usr --includedir=${prefix}/include --mandir=${prefix}/share/man --infodir=${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libexecdir=${prefix}/lib/tvheadend --disable-maintainer-mode --disable-dependency-tracking --enable-libffmpeg_static --enable-hdhomerun_static --enable-dvbcsa --enable-bundle' ./Autobuild.sh -t debian

Installing packaged version of TVHeadend

The autobuild command will produce a .deb file (named something like tvheadend_v4.1-2141~g01c26fc_amd64.deb) in the directory above the source directory. Copy the debian package (either by using a USB disk or using scp to copy it to your target host) and run the following to install it;

sudo dpkg -i YourPackageName.deb

You will more than likely hit failed dependencies here so after running the above, run the following to fix the missing dependencies;

sudo apt-get install -f

That’s it! You should be able to view the TVHeadend web interface at http://RaspberryPiIPAddress:9981/

Tagged with: , , , , ,