Last active
April 24, 2025 21:32
-
-
Save theAkito/cb23060ff70e235406caf810246d1c1d to your computer and use it in GitHub Desktop.
Compile RetroArch using DietPi v9.12.1 on Raspberry Pi Zero W. Use a microSD of at the very least 8GB. https://github.com/libretro/RetroArch/issues/7606#issuecomment-2825605112
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Compile RetroArch using DietPi v9.12.1 on Raspberry Pi Zero W. | |
# Use a microSD of at the very least 8GB. | |
# | |
# Workflow | |
# 1. Enable strict error handling (errexit, nounset, pipefail). | |
# 2. Declare readonly variables for RetroArch user, home directory, and groups. | |
# 3. Create `retro` user (with home directory and locked password) if it doesn't exist. | |
# 4. Define and install all required build dependencies via apt. | |
# 5. Clone RetroArch repository at the specified tag if not already present, and measure clone time. | |
# 6. Change ownership of RetroArch source directory to `retro` user. | |
# 7. As `retro` user, configure and compile RetroArch as `retro` user, then record build end time. | |
# 8. Calculate apt, clone, build, and total durations and output a formatted build summary. | |
# | |
# https://gist.github.com/theAkito/cb23060ff70e235406caf810246d1c1d | |
# | |
# https://github.com/libretro/RetroArch/issues/7606 | |
# https://docs.libretro.com/guides/rpi/ | |
# Strict Mode | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
declare -r RETRO_USER="retro" | |
declare -r RETRO_HOME_DIR="/home/${RETRO_USER}" | |
declare -r RETRO_GROUPS="audio,video" | |
# Create retro user | |
function useradd_retro { | |
if ! id "${RETRO_USER}" &>/dev/null; then | |
useradd \ | |
--create-home \ | |
--home-dir "${RETRO_HOME_DIR}" \ | |
--shell /bin/bash \ | |
--groups "${RETRO_GROUPS}" \ | |
"${RETRO_USER}" | |
passwd -l "${RETRO_USER}" | |
fi | |
} | |
useradd_retro | |
declare -r DEPS=( | |
git | |
build-essential libudev-dev libegl-dev libgles-dev libx11-xcb-dev | |
libpulse-dev libasound2-dev | |
libavcodec-dev libavdevice-dev libavformat-dev libdrm-common libdrm-dev libdrm2 libegl1-mesa-dev libfreetype6-dev libgbm-dev | |
libgles2 libgles2-mesa libgles2-mesa-dev | |
libsdl-image1.2-dev libsdl2-dev libswresample-dev libswscale-dev | |
libv4l-dev libxkbcommon-dev libxml2-dev yasm zlib1g-dev | |
# Debian >= 12 | |
libswresample-dev | |
) | |
declare -r APT_START=$(date +%s) | |
apt update | |
apt install -y "${DEPS[@]}" | |
declare -r APT_END=$(date +%s) | |
declare -r REPO_URL="https://github.com/libretro/RetroArch" | |
declare -r REPO_TAG="v1.15.0" | |
declare -r CLONE_START=$(date +%s) | |
if [ ! -d "${RETRO_HOME_DIR}/RetroArch" ]; then | |
git clone "${REPO_URL}" -b "${REPO_TAG}" "${RETRO_HOME_DIR}/RetroArch" | |
else | |
echo "RetroArch source already exists at ${RETRO_HOME_DIR}/RetroArch, skipping clone." | |
fi | |
declare -r CLONE_END=$(date +%s) | |
chown -R "${RETRO_USER}":"${RETRO_USER}" "${RETRO_HOME_DIR}/RetroArch" | |
# Build as retro user | |
declare -r BUILD_START=$(date +%s) | |
echo "[INFO] Clone completed and compilation starting at $(date --iso-8601=seconds)" | |
su - "${RETRO_USER}" -c \ | |
"cd ~/RetroArch \ | |
&& ./configure --disable-videocore --disable-opengl1 --enable-opengles --enable-floathard \ | |
&& make -j\"$(nproc)\"" | |
declare -r BUILD_END=$(date +%s) | |
echo "[INFO] Compilation finished at $(date --iso-8601=seconds)" | |
declare -r APT_DURATION=$((APT_END - APT_START)) | |
declare -r CLONE_DURATION=$((CLONE_END - CLONE_START)) | |
declare -r BUILD_DURATION=$((BUILD_END - BUILD_START)) | |
declare -r TOTAL_DURATION=$((BUILD_END - APT_START)) | |
declare -r HOURS=$((BUILD_DURATION/3600)) | |
declare -r MINUTES=$(((BUILD_DURATION%3600)/60)) | |
declare -r SECONDS=$((BUILD_DURATION%60)) | |
declare -r CLONE_HOURS=$((CLONE_DURATION/3600)) | |
declare -r CLONE_MINUTES=$(((CLONE_DURATION%3600)/60)) | |
declare -r CLONE_SECONDS=$((CLONE_DURATION%60)) | |
declare -r APT_HOURS=$((APT_DURATION/3600)) | |
declare -r APT_MINUTES=$(((APT_DURATION%3600)/60)) | |
declare -r APT_SECONDS=$((APT_DURATION%60)) | |
echo "==========================================" | |
echo "RetroArch build summary:" | |
echo " • Clone start: $(date --iso-8601=seconds -d @"${CLONE_START}")" | |
echo " • Clone end: $(date --iso-8601=seconds -d @"${BUILD_START}")" | |
echo " • Compilation start: $(date --iso-8601=seconds -d @"${BUILD_START}")" | |
echo " • Compilation end: $(date --iso-8601=seconds -d @"${BUILD_END}")" | |
printf " • APT time: %02d:%02d:%02d (HH:MM:SS)\n" "${APT_HOURS}" "${APT_MINUTES}" "${APT_SECONDS}" | |
printf " • Clone time: %02d:%02d:%02d (HH:MM:SS)\n" "${CLONE_HOURS}" "${CLONE_MINUTES}" "${CLONE_SECONDS}" | |
printf " • Build time: %02d:%02d:%02d (HH:MM:SS)\n" "${HOURS}" "${MINUTES}" "${SECONDS}" | |
printf " • Total time: %02d:%02d:%02d (HH:MM:SS)\n" "$((TOTAL_DURATION/3600))" "$(((TOTAL_DURATION%3600)/60))" "$((TOTAL_DURATION%60))" | |
echo "==========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment