The official, and recommended, way to compile batocera.linux is by using a development container made on purpose with Docker. Although you can do it directly on your Linux machine, if it's a supported Ubuntu Linux.

Choose either Docker or Direct Compilation.

Make sure you have a reasonably fast CPU, and at least 8GB of RAM. If you have a CPU with 8 cores or more (lucky you!), you might need more than 8GB RAM to compile batocera.linux with all threads in parallel. You also need at least 50GB of free disk space to download and compile the whole system.

Docker

If you already have a working Docker installation on your Linux system, you just need to install git (if you don't have that already as well), and skip to the preparations section.

Otherwise, the first step is to install Docker on your machine. Each OS and Linux distribution has a particular way to install Docker.

Please note that most developers use Ubuntu Linux to compile batocera.linux. In October 2018, Docker on Windows is not stable enough to compile Batocera.
In March 2020, with the Docker container running as non-root (regular user), you can compile Batocera on MacOS Mojave 10.14 (Darwin 18.0.0).

Once Docker is installed, you have to get it up and running (depending on your OS, for Linux Solus for example, you would start it up with sudo systemctl start docker.service).

Git is used to download the batocera.linux sources, outside of the docker container.

Direct Compilation

The way to install the necessary packages vary for each Linux distribution. You can find the necessary packages for Ubuntu below.

* Ubuntu 18.04 (might still work with 16.04 too)

 sudo apt-get install build-essential git libncurses5-dev libssl-dev mercurial texinfo zip default-jre imagemagick subversion hgsubversion autoconf automake bison scons libglib2.0-dev bc mtools u-boot-tools flex wget cpio dosfstools libtool
 sudo dpkg --add-architecture i386
 sudo apt-get update
 sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

* Ubuntu 20.04 (Includes requirements for some experimental packages)

 sudo apt-get install build-essential git libncurses5-dev libssl-dev mercurial texinfo zip default-jre imagemagick subversion autoconf automake bison scons libglib2.0-dev bc mtools u-boot-tools flex wget cpio dosfstools libtool
 sudo dpkg --add-architecture i386
 sudo apt-get update
 sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

pip3 install conan

Download the batocera.linux sources

Choose a work directory (your $HOME?) and clone the batocera.linux source code:

git clone https://github.com/batocera-linux/batocera.linux.git

Enter the newly created directory.

 cd batocera.linux

If the buildroot submodule is not created on pull, execute the following commands:

 git submodule init
 git submodule update

You only need to do this once.

If you use Docker, create the image of the container:

 docker build -t batocera-docker https://raw.githubusercontent.com/batocera-linux/batocera.linux/master/Dockerfile

Then start it by using the repository you just cloned as the /build folder of the container itself, with:

 docker container run --user $(id -u) -it --rm -v $PWD/.:/build batocera-docker

If you run the docker container as non-root, you'll be in a I have no name!@xxx:/build container.

Choose the target you want to build

Depending on the target you want to build Batocera for, you need to select one of the batocera-XXXXX_defconfig files, where XXXX has to be replaced with the architecture you are building to. Available ones are:

  • rpi1
  • rpi2
  • rpi3
  • odroidc2
  • odroidn2
  • odroidxu4
  • odroidgoa
  • x86_64
  • x86 (32 bits, old PCs)
  • tinkerboard
  • miqi
  • s905
  • s912
  • rockpro64
  • rock960

You can find them all listed in the configs directory.

Compilation

To make things easier, I recommend using a prepared make script like described here.

Of course you can still use out of tree builds. So, for x86_64, you can do the following:

make O=$PWD/output/x86_64 BR2_EXTERNAL=$PWD -C $PWD/buildroot batocera-x86_64_defconfig
cd output/x86_64
make

Source tree will stay pristine and we be reused for other builds following the same procedure with a different output directory. For example:

make O=$PWD/output/rpi3 BR2_EXTERNAL=$PWD -C $PWD/buildroot batocera-rpi3_defconfig
cd output/rpi3
make

Then, you can take some time for a coffee (or two, or two hundreds actually). Depending on how powerful your CPU is, how much RAM you have, and how fast your SSD/HDD is, compiling a whole Batocera system can take many hours. Don't forget, it's the full OS with all the emulators that we are compiling here, it's not a small task.

Please also mind that the process will take a significant amount of space, so ensure to have at least 50GB free on that partition.

Exit the container if you ran the build inside of it.

The output will be under output/images/batocera and will be gzipped. Its name contains the release version, the platform, and the build date. For instance: output/images/batocera/batocera-5.25-x86_64-20200221.img.gz

You can then flash it with Etcher by following the instructions https://batocera.org/how_to_install or by using dd if you don't want to leave the command line:

gunzip output/images/batocera/batocera-XXXX.img.gz
dd if=output/images/batocera/batocera-XXXX.img of=/dev/**yourtargetdevice** status=progress

Download sources

You can download sources from Internet before compiling by running the following command, assuming you started with x86_64:

cd output/x86_64
make source

Personally, I even run it during 10 minutes and then run make in parallel.

Follow the current compilations

If you want to check on the current status for your x86_64 build:

tail -f output/x84_64/build/build-time.log

What isn't compiled yet?

If you ran make source, you can easily find what's remaining to compile by running :

for i in output/x86_64/build/*; do test -d "$i" && test -e "$i"/.stamp_built || echo "$i"; done; for i in output/x86_64/build/*; do test -d "$i" && test -e "$i"/.stamp_built || echo "$i"; done | wc -l

Sharing a single download folder among all builds

  docker run -it --rm -v $PWD:/build -v $HOME/dev/batocera/DL:/build/dl batocera-docker

List docker images

docker image ls

Remove docker images

docker rmi [image]

List docker containers

docker ps

Remove docker containers

docker kill [container name]

Folder structure and other tips

Follow this page to know more about the structure of the Batocera source code and where your modifications need to be made.

qt5base compilation error in ubuntu docker

Add –security-opt seccomp:unconfined to your docker command line or update the libseccomp2 package

As of February 2020, it looks like this step is not required any longer.

  • compile_batocera.linux.txt
  • Last modified: 4 months ago
  • by ordovice