Compile batocera.linux

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.

If you are not familiar with git, you should first take a look at this page explaining the basics for contributing to Batocera Linux with git.

Choose either Docker or Direct Compilation.

Make sure you have a reasonably fast CPU, and at least 8GB of RAM (even 12GB+ if you need to compile MAME). 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 between 80GB and 130GB of free disk space to download and compile the whole system.

The x86_64 version is the largest, downloading packages and building them takes up to 130GB. When you build another architecture on the same system, you will need less, as many packages are common across architectures and already downloaded.

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 or Arch Linux for example, you would start it up with sudo systemctl start docker.service and make sure that your user is in the docker group).

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

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 gcc-multilib g++-multilib
 sudo dpkg --add-architecture i386
 sudo apt-get update
 sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

pip3 install conan

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 (or is empty) after cloning, execute the following commands:

 git submodule init
 git submodule update

You only need to do this once.

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.

To make things easier, there is makefile described here that makes the compilation process smoother.

1. Install build environment

 make batocera-docker-image

2. Customize directories

You can check the default directories with the following command:

 make vars

You can change directories in batocera.mk. I recommend you disable tracking of changes in that file with:

 git update-index --assume-unchanged batocera.mk

3. Build an image

Command is different for each target architecture, but share the same suffix like make rockpro64-build or:

 make x86_64-build

You can check valid targets architectures with make vars.

4. Shell

It's also possible to get a shell to the desired build environment. Similar to -build, with make rockpro64-shell or:

 make x86_64-shell

5. Build a single package

To build a single package, you can open a shell or use the -pkg target. Examples:

 make rockpro64-pkg PKG=batocera-splash
 make x86_64-shell PKG=libretro-mame

6. ccache

To enable ccache for all builds, add the necessary options to batocera.mk. An example is provided there. See EXTRA_OPTS. No need to edit defconfig.

7. Compile clean builds

 make x86_64-cleanbuild
 

8. Build a webserver to upgrade your Batocera

You can easily upgrade your Batocera test machine with the build you have just compiled. Let's imagine your build box's IP address is 10.0.0.2. If your build machine has Python3 installed, you can run a webserver with:

 make x86_64-webserver

Then, you can launch an upgrade from your Batocera test box. If your build box hosting the web server is on 10.0.0.10, you can simply upgrade to your freshly brewed build by entering from your Batocera SSH:

 batocera-upgrade http://10.0.0.10:8000

Of course you can still use out of tree builds to compile Batocera. 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 between 50GB and 90GB of free space 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

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.

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

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

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
docker run -it --rm -v $PWD:/build -v $HOME/dev/batocera/DL:/build/dl batocera-docker
docker image ls
docker rmi <image_name> or docker image rm <image_name>
docker ps
docker kill [container name]

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

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 weeks ago
  • by lbrpdx