Skip to content

Compiling Opensource Games for PortMaster

Since PortMaster is platform-independent and delivers its own dependencies, we don't rely on the build mechanism of the CFWs out there. To compile games for the AARCH64 architecture, you can do so in various ways. We build on Ubuntu 22.04 LTS.

Info

Many porting methods do not require you to set up a build environment. This is only necessary when you need to build games and/or libraries from source!

Which Ubuntu version?

A program only runs on a device whose glibc is at least as new as the one it was built against. So the version of Ubuntu you build on decides which firmware your port can run on.

  • Ubuntu 22.04 (glibc 2.35) is what we build on. Use it unless you have a reason not to.
  • Ubuntu 20.04 (glibc 2.31) is the one to use if you want your port to also run on older CFWs like ArkOS. A device can run anything built against an older glibc than its own, so a port built on 20.04 runs everywhere a 22.04 build does, and on the older firmware as well.

The WSL steps below use 22.04, and say what to change to build on 20.04 instead.

The min_glibc field in a port's port.json makes PortMaster hide the port on devices whose glibc is older, so people don't install something that won't run. Only fill it in if your port supplies its own binaries. The Port JSON Generator has a field for it and suggests 2.35 to match 22.04. If you built on 20.04 to support older CFWs like ArkOS, leave it empty.

Build environment options

Below you will find several options for build environments suited for PortMaster.


1. WSL2 Chroot (Change root)

For more information, visit the GitHub Repository.

Instructions

Install required packages on Ubuntu 22.04 LTS WSL 2:

sudo apt install build-essential binfmt-support daemonize libarchive-tools qemu-system qemu-user qemu-user-static gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
  • Download ubuntu-22.04-server-cloudimg-arm64-root.tar.xz from Ubuntu Cloud Images.

    To build on 20.04 instead, for older CFWs like ArkOS, download 20.04 Focal server-cloudimg-arm64-wsl.rootfs.tar.gz from the Ubuntu Cloud Image archive and use its file name in the next step.

  • Extract the tarball in a folder:

    mkdir folder
    sudo bsdtar -xpf ubuntu-22.04-server-cloudimg-arm64-root.tar.xz -C folder
    
  • Copy qemu static binary into that folder:

    sudo cp /usr/bin/qemu-aarch64-static folder/usr/bin
    
  • Start systemd with daemonize:

    sudo daemonize /usr/bin/unshare -fp --mount-proc /lib/systemd/systemd --system-unit=basic.target
    
  • Check if AARCH64 binfmt entry is present:

    ls /proc/sys/fs/binfmt_misc/
    
  • Mount and chroot into the environment:

    sudo mount -o bind /proc folder/proc
    sudo mount -o bind /dev folder/dev
    sudo chroot folder qemu-aarch64-static /bin/bash
    
  • In the chroot, delete /etc/resolv.conf file and write a name server to it.

    rm /etc/resolv.conf
    echo "nameserver 8.8.8.8" > /etc/resolv.conf
    
  • Exit chroot

    ```bash
    mkdir -p folder/tmp/.X11-unix
    ```
    
  • Create chroot.sh:

    #!/bin/bash
    
    sudo daemonize /usr/bin/unshare -fp --mount-proc /lib/systemd/systemd --system-unit=basic.target
    
    sudo mount -o bind /proc folder/proc
    sudo mount -o bind /dev folder/dev
    sudo mount -o bind /tmp/.X11-unix folder/tmp/.X11-unix
    xhost + local:
    sudo chroot folder qemu-aarch64-static /bin/bash
    
  • Make the chroot.sh executable:

    chmod +x chroot.sh
    
  • Chroot into the new environment:

    sudo ./chroot.sh
    
  • Update & Upgrade the chroot:

    apt-get update && apt-get upgrade 
    
  • Helpful development tools & libraries to have in the chroot:

    apt-get install --no-install-recommends build-essential git wget libdrm-dev python3 python3-pip python3-setuptools python3-wheel ninja-build libopenal-dev premake4 autoconf      libevdev-dev ffmpeg libboost-tools-dev magics++ libboost-thread-dev libboost-all-dev pkg-config zlib1g-dev libsdl-mixer1.2-dev libsdl1.2-dev libsdl-gfx1.2-dev libsdl2-mixer-dev clang cmake cmake-data libarchive13 libcurl4 libfreetype6-dev librhash0 libuv1 mercurial mercurial-common libgbm-dev libsdl-image1.2-dev
    
  • Install custom SDL2 Libraries for better compatibility:

    rm /usr/lib/aarch64-linux-gnu/libSDL2.* 
    rm -rf /usr/lib/aarch64-linux-gnu/libSDL2-2.0.so*
    
    wget https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.26.2.tar.gz
    ./configure --prefix=/usr
    make -j8
    make install
    
    /sbin/ldconfig
    

2. Docker

Multi Arch compilation with this Docker Guide


3. AARCH64 chroot development VM by Christian

This is a Virtual Box VM with two chroot instances (AARCH64 & ARMHF).

For More Info: Forum Post

Getting Into Chroots:

  • For 32-bit Arm environment:

    sudo chroot /mnt/data/armhf/
    
    or create an Arm32 shortcut on the desktop GUI and click on it.

  • For 64-bit Arm environment:

    sudo chroot /mnt/data/arm64/
    
    or create an Arm64 shortcut on the desktop GUI and click on it.

Helpful Tools to Install:

apt -y install build-essential git wget libdrm-dev python3 python3-pip python3-setuptools python3-wheel ninja-build libopenal-dev premake4 autoconf libevdev-dev ffmpeg libsnappy-dev libboost-tools-dev magics++ libboost-thread-dev libboost-all-dev pkg-config zlib1g-dev libpng-dev libsdl2-dev clang cmake cmake-data libarchive13 libcurl4 libfreetype6-dev libjsoncpp1 librhash0 libuv1 mercurial mercurial-common libgbm-dev libsdl2-ttf-2.0-0 libsdl2-ttf-dev 

4. Create Your Own chroot

As per this guide.


5. Cross-Compiling Tools for AARCH64

With the arm64 SDL2 library, etc.