Skip to content

Instantly share code, notes, and snippets.

@JohnnyonFlame
Last active April 20, 2023 12:16
Show Gist options
  • Save JohnnyonFlame/df7ba61a5559de293680789e7f01fbdc to your computer and use it in GitHub Desktop.
Save JohnnyonFlame/df7ba61a5559de293680789e7f01fbdc to your computer and use it in GitHub Desktop.
Configuring a cross-build chroot, building and Installing SDL2 for Rockchips (As seen on 351ELEC!)

Your dependencies

dpkg --add-architecture arm64
apt update
apt install -yy crossbuild-essential-arm64 autoconf cmake meson git wget nano curl unzip pkg-config libasound2-dev:arm64 libsndio-dev:arm64 libudev-dev:arm64 libdbus-1-dev:arm64 libsamplerate0-dev:arm64 libibus-1.0-dev:arm64 libfreetype6-dev:arm64 libgl1-mesa-dev:arm64

Meson and Cmake build files

cd /opt/
wget https://gist.githubusercontent.com/JohnnyonFlame/8d6d0562345cbfed35746ac2ffd08aa1/raw/aarch64.meson
wget https://gist.githubusercontent.com/JohnnyonFlame/bf2e0756c1bf185d9f1e9d51f7ff4e80/raw/aarch64.cmake
ln -sf /usr/share/pkg-config-crosswrapper /usr/bin/aarch64-linux-gnu-pkg-config

libdrm

wget http://dri.freedesktop.org/libdrm/libdrm-2.4.108.tar.xz
tar xvf libdrm-2.4.108.tar.xz 
mv libdrm-2.4.108 libdrm
cd libdrm
meson build/ --cross-file=/opt/aarch64.meson -D{intel,radeon,amdgpu,vmwgfx,vc4,freedreno,nouveau,etnaviv}=false --prefix=/usr/aarch64-linux-gnu/
ninja -C build install
cd ..

libmali

wget https://github.com/351ELEC/libmali/archive/9b1375cfb1e54f89f4f5ae574d809cca486970f5.zip
unzip 9b1375cfb1e54f89f4f5ae574d809cca486970f5.zip 
mv libmali-9b1375cfb1e54f89f4f5ae574d809cca486970f5/ libmali
cd libmali
meson build/ --cross-file=/opt/aarch64.meson --prefix=/usr/aarch64-linux-gnu/
ninja -C build install
cd ..

librga

wget https://github.com/351ELEC/linux-rga/archive/1fc02d56d97041c86f01bc1284b7971c6098c5fb.tar.gz
tar xvf 1fc02d56d97041c86f01bc1284b7971c6098c5fb.tar.gz 
mv linux-rga-1fc02d56d97041c86f01bc1284b7971c6098c5fb/ linux-rga
cd linux-rga
meson build/ --cross-file=/opt/aarch64.meson --prefix=/usr/aarch64-linux-gnu/
ninja -C build install
cd ..

libsdl2

git clone https://github.com/libsdl-org/SDL --branch release-2.0.20 --depth 1
cd SDL
wget https://raw.githubusercontent.com/351ELEC/351ELEC/main/packages/games/tools/SDL2/patches/0001-kmsdrm-Workaround-missing-gbm_bo_get_offset-and-SDL_.patch
wget https://raw.githubusercontent.com/351ELEC/351ELEC/main/packages/games/tools/SDL2/patches/rotation/0005-SDL-2.0.20.odroidgoa-support.patch
wget https://raw.githubusercontent.com/351ELEC/351ELEC/main/packages/games/tools/SDL2/patches/rotation/0006-KMSDRM-Also-rotate-the-cursor.patch
patch -p1 < 0001-kmsdrm-Workaround-missing-gbm_bo_get_offset-and-SDL_.patch
patch -p1 < 0005-SDL-2.0.20.odroidgoa-support.patch
patch -p1 < 0006-KMSDRM-Also-rotate-the-cursor.patch
./autogen.sh
./configure --prefix=/usr/aarch64-linux-gnu/ --host=aarch64-linux-gnu --enable-video-kmsdrm --disable-video-x11 --disable-video-rpi --disable-video-wayland --disable-video-vulkan
make install -j16
cd ..

libsdl2_image

wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.zip
unzip SDL2_image-2.0.5.zip
mv SDL2_image-2.0.5 SDL2_image
cd SDL2_image
./configure --prefix=/usr/aarch64-linux-gnu/ --host=aarch64-linux-gnu
make install -j16
cd ..

libsdl2_ttf

wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz
tar xvf SDL2_ttf-2.0.14.tar.gz
mv SDL2_ttf-2.0.14 SDL2_ttf
cd SDL2_ttf
freetypeconf_args="freetype2 " FREETYPE_CONFIG="/usr/bin/aarch64-linux-gnu-pkg-config" ./configure --prefix=/usr/aarch64-linux-gnu/ --host=aarch64-linux-gnu --with-freetype-prefix=/usr/aarch64-linux-gnu --without-x
make install -j16
cd ..

Bonus Round, FNA

apt install -yy mono-complete

git clone https://github.com/FNA-XNA/FNA --recursive

cd FNA/lib/FAudio
cmake -B build . -DCMAKE_TOOLCHAIN_FILE=/opt/aarch64.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -C build -j16

cd ../FNA3D
cmake -B build . -DCMAKE_TOOLCHAIN_FILE=/opt/aarch64.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -C build -j16

cd ../SDL2-CS
make release

cd ../Theorafile
make TRIPLET=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc

cd ../../
make release

mkdir -p rel/dlls rel/libs
cp $(find . -name \*.dll\*) rel/dlls
cp $(find . -name \*.so\*) rel/libs
cd rel
tar zcvf FNA_$(git rev-parse --short HEAD)-aarch64.tar.gz *

Bonus 2: Mono (can't crossbuild - use something like an N2+ or suffer.)

wget https://download.mono-project.com/sources/mono/mono-6.12.0.122.tar.xz
tar xf mono-6.12.0.122.tar.xz
cd mono-6.12.0.122
./autogen.sh --with-ikvm-native=no --with-csc=mcs --enable-llvm --disable-dependency-tracking --with-mcs-build --prefix=$(pwd)/built
make -j7
make install
wget https://gist.githubusercontent.com/JohnnyonFlame/df7ba61a5559de293680789e7f01fbdc/raw/Makefile.optm
cd built
PATH=$(pwd)/bin:$(pwd)/../llvm/usr/bin:$PATH MONO_PATH=$(pwd)/lib/mono make -f ../Makefile.optm -j7
DLLS=$(wildcard lib/mono/gac/*/*/*.dll) lib/mono/4.5/mscorlib.dll
SO=$(patsubst %.dll,%.so,$(DLLS))
FLAGS=--aot=llvm -O=all
VERSION=6.12.0.122
ARCH=aarch64
%.so: %.dll
mono ${FLAGS} $<
all: $(SO)
rm -rf mono_aot_*
cp -r ../llvm/usr/* .
cp /usr/lib/aarch64-linux-gnu/libopcodes-*-system.so lib/
cp /usr/lib/aarch64-linux-gnu/libbfd-*-system.so lib/
cp /usr/lib/aarch64-linux-gnu/libctf.so* lib/
cp /lib/aarch64-linux-gnu/libz.so.1 lib/
cp /usr/bin/aarch64-linux-gnu-as bin/as
cp /usr/bin/aarch64-linux-gnu-ld bin/ld
cp /usr/bin/aarch64-linux-gnu-ld* bin/
mksquashfs * mono-${VVERSION}-${ARCH}.squashfs
@JohnnyonFlame
Copy link
Author

JohnnyonFlame commented Feb 16, 2022

Run Me on a chroot! (or don't, not really that secure... no hash checks etc)

cd /opt
apt install -yy wget sed
wget https://gist.github.com/JohnnyonFlame/df7ba61a5559de293680789e7f01fbdc/raw/readme.md -O runme.sh
sed -i '1 i\\#\!\/bin\/bash -e' runme.sh
sed -i "s/\`\`\`\(bash\)\?//g" runme.sh
chmod +x runme.sh
./runme.sh

Fair warning: This is a fairly insecure script with zero checks for the validity of many of the moving parts. No liability or guarantees, implied or otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment