Compiling Individual Packages

You may know me from former titles such as “Batocera Linux Buildroot Modifications” and “How to work on Batocera (and not recompile everything)”.

RPi3, the “per platform” example used here, was formerly known internally as rpi3 in Batocera v35 and lower. This is now bcm2837 in v36 and higher.

If you'd instead like to only test certain config files (like es_features.cfg), you can edit them directly in the live system and save them via overlays.

Compiling the entirety of Batocera is optional, but recommended as it automatically sets up your enviroment for compiling individual packages. batocera.linux is based on Buildroot, manual available here.

For each package (ie. kodi, emulationstation), Buildroot does the following:

  1. do prerequisites
  2. download
  3. extract
  4. patch
  5. configure
  6. build
  7. install staging
  8. install target

More exactly:

  1. do the prerequisite packages recursively if not yet done (ie sdl2 if you want to build emulationstation)
  2. download the package in the dl directory according to information from package/package-name/ or package/batocera/package-name/
  3. extract the package in output/build/package-name-version
  4. patch the package from *.patch files (files next to the .mk file or board/batocera/patches/ or board/batocera/bcm2837/patches/)
  5. configure the package according to the .mk file
  6. build the package according to the .mk file
  7. install in the output/bcm2837/host/ staging directory, in case of libraries
  8. install in the output/bcm2837/target/ directory

For each step, Buildroot creates an empty flag file. For example: .stamp_downloaded in output/bcm2837/build/package-name-version.

In case a step failed, just run make or make package-name again to restart/continue the build where you left.

To completely rebuild a package (for example an RPi 3 package):

rm -rf output/bcm2837/build/package-name-version
make package-name

For example, to build EmulationStation again from the latest master git version:

rm -rf output/bcm2837/build/batocera-emulationstation-master
make batocera-emulationstation

Individual packages can also be compiled using the container using:

make x86_64-pkg PKG=batocera-splash

replacing the components as necessary.

Although this will build package itself, it does not do so in the same way that the regular make x86_64-build does. Using a package build cannot be used for testing a package's successful build, always use -build or -cleanbuild to confirm before making a pull request.

When you clone the batocera.linux git repository, you mainly get the following directories:

  • .config: the list of all packages, stating if you are going to build it or not.
  • dl: the directory where all files are downloaded, for example, batocera-emulationstation-master.tar.gz
  • output: the directory where everything is built.

In other words, in order to reinitialize your build, you can type:

rm -rf .config dl output

I personally use the following command to confirm I have no other remaining files:

git status --ignored

My dl directory is a link on ../DL in order to use the same download directory for all my builds, to avoid to download the source archives each time again and again. Note that you may have to remove some packages like batocera-emulationstation-master.tar.gz or batocera-configgen-master.tar.gz while the contains is the master branch of their respective git repositories. In other words, whenever the content is dynamic (master) and not a precise GitHub version. If you commit something on configgen, while the file is in the dl directory, buildroot will not download it again as it is seen as the same filename.

EmulationStation is a separate git repository from Batocera system. To work on EmulationStation, the simplest way is to directly get it on your computer and compile it without buildroot.

This is for generic packages that aren't necessarily emulators.

The following is a (very) brief summarization of chapter 19 of the Buildroot manual. It is recommended to read that in full in case of any questions.


  • Explain the differences between each different kind of package container (generic, cmake, autotools, etc.).
  • Provide rough syntax for each one.
  • Cover all stages.
  • Define when certain steps aren't absolutely necessary.
  1. Add the package's folder to the appropriate location. For generic packages like this, it will most likely be package/batocera/utils/package-name/.

    It's worth checking if the package you want is already included in buildroot, just check in the buildroot/package/ file. If so, skip steps 2 and 3.

  2. In that folder, create the file. This should contain the package's “metadata” for compilation purposes. Add into this file its:
    1. Buildroot package header: config BR2_PACKAGE_<package>
    2. Its bool shortname used for compilation and other packages it may depend on: bool "<package shortname>"
    3. Specify other packages depends on: depends on BR2_PACKAGE_<other package>
    4. A help section describing the package in more detail.

      For more information on Buildroot's syntax, refer to chapter 16.1 in Buildroot's manual.

  3. Create the makefile. Its filename should be the same as the package's bool shortname, followed by the .mk extension: <package-shortname>.mk
    1. If pulling from a Github source, use the following syntax:
      <package>_VERSION = <commit hash>
      <package>_SITE = $(call github,<author>,<repository>,$(<package>_VERSION))
    2. Each step of package compilation needs to be put into its appropriate function.
      1. If needing to set particular config options while building, place them in <package>_CONF += <options>. For example:
      2. If needing to set particular environmental variables before building, place them in <package>_CONF_ENV += <environment variables>. For example:
        GZDOOM_CONF_ENV += ZMUSIC_LIBRARIES="/x86_64/target/usr/lib/" ZMUSIC_INCLUDE_DIR="/x86_64/target/usr/lib/cmake/ZMusic/"
      3. If compiling from the package's downloaded build folder (such as when downloading a Github repo), put this in define <package>_BUILD_CMDS. Inside of that function, be sure to use the appropriate flag to set the correct working directory: $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) The “make” compiler uses its own instance, which may not be sharing the same current working directory. A generic compilation script would be as follows:
        define <package>_BUILD_CMDS
            $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D)
      4. When compilation is finished, if not compiled as a part of a large over-arching package, copy over the resulting files/binaries to the appropriate locations in the install step (if the compilation process itself doesn't already do so). For example, when compiling an ordinary binary:
        define <package>_INSTALL_TARGET_CMDS
            mkdir -p $(TARGET_DIR)/usr/bin
            cp $(@D)/output_executable $(TARGET_DIR)/usr/bin
    3. When done defining actions to perform for each step, end the makefile with one file line defining which package container to use. For “generic” packages: $(eval $(generic-package)).

      For more information on Buildroot's makefile syntax, refer to chapter 16.2 in Buildroot's manual.

  4. Add the package to the list of compiled packages at package/batocera/core/batocera-system/ This is where you would refer to its Buildroot package header, not its shortname.
  5. Add the package to the list of sources in the appropriate section in That's right, the file in the root directory of the repo.

An example of a recent pull request that adds a simple package:

  1. Add the initial scripts for successful compilation. Ensure that there are no valid build errors with it. Refer to buildroot's documentation for further info.
    1. Create its initial configuration script:<new emulator>/
    2. Create its makefile for package compilation:<new emulator>/<new emulator>.mk
    3. If the emulator requires certain files in certain locations in userdata, copy them to /usr/share/batocera/data/.
    4. If the emulator cannot bind functions to the gamepad's buttons and needs to use a virtual keyboard, add the appropriate evmapy .keys file to <shortname>.<emulator>.keys.
    5. If building from source, add the git repository check to the update script:
  2. Add your BR2 package to the compilation process (and limit your emulator to particular archs (typically, complex standalone emulators are x86/x86_64 only)) in
    • If making a new category of systems, be sure to add it to the included config BR2_PACKAGE_BATOCERA_ALL_SYSTEMS under the #### systems #### section.
  3. Add your system/emulator to the EmulationStation system configuration at (there needs to be at least one default core for the system, described later).
  4. Add your system/emulator to the features list ( and any advanced system settings if necessary.
  5. If the emulator has a desktop configuration application, add it to the Applications menu in the file manager:
    1. Define the generator with its system shortname here: (you can test this locally with /usr/lib/python#.#/site-packages/configgen/Generator
    2. Include it in the packages list (syntax: configgen.generators.<shortname>) here:
    3. Create the “main” configuration generator Python script here: followed by <shortname>/<shortname>
    4. If appropriate, split the file into multiple Python scripts called by <shortname> in the generators/<shortname>/ folder.
  6. Configure the default emulator (if you've added a whole new system) with (if you're merely adding an emulator to an already existing system and you don't want to make it the default, no need to touch this file).
  7. Configure the default settings for particular architectures (such as if your emulator requires certain settings to function on a particular architecture) at
  8. Add the system's shortname and a link to a page explaining the system (Wikipedia tends to be a good “default” but there are better sources out there) to the appropriate section in the systems page of this wiki.
  9. (Optional) If you need to add an explanation for the emulator's exclusion from a particular platform for the compatibility chart, add it to

If you'd like an example of a recent pull request that adds a whole new emulator:

Buildroot features the ability to patch the source code of a package before compiling it, read section 19.2 in the buildroot user manual for more info. Here we will do a quick rundown.

Let's say you want to work on the package “retroarch” to make it evolve via a patch.

First, compile a complete version of Batocera for the architecture you will test. In this example, we will do so for RPi3.

cd batocera.linux
make bcm2837-build

Once this is done, you don't need to build the entirety of it again for your tests. You can just rename/remove the output's target folder for that architecture, like so:

mv output/bcm2837/target output/bcm2837/target_

Now for our patch. First change the working directory to that of the build folder for the respective package:

cd output/bcm2837/build/retroarch-version

Establish the package state using git:

git init

Then add the file(s) you want to modify to the current commit:

git add <the file(s) you modified>

Add all files with git add -A.

Make the modifications to the files you want now.

Then compare the differences and save them to a “patch” file:

git diff > ../../package/batocera/retroarch/001-mymodification.patch

Now clear out the package's respective build folder to make way for testing a new build with it:

cd ../../..
rm -rf ouput/bcm2837/build/batocera/retroarch-version

Then build the package (replacing make if using a different make tool):

make retroarch-patch # to confirm the patch is applied
make retroarch # to finish other steps

It's possible to compile just the package you've modified and then transfer it over to your live Batocera installation using rsync. First, compile the individual package as explained above with make bcm2837-pkg PKG=<package name> and then run:

rsync -av output/bcm2837/target/ root@batocera.local:/

This will sync up the contents of the target directory on your build machine with the Batocera machine. Feel free to immediately test your changes. If the changes are bad and you need to restore, simply reboot and the changes will not persist. To have them persist instead, run batocera-save-overlay from the machine itself.

  • batocera.linux_buildroot_modifications.txt
  • Last modified: 22 months ago
  • by atari