Skip to content

Instantly share code, notes, and snippets.

@Sanaki
Last active February 5, 2022 07:57
Show Gist options
  • Save Sanaki/44200de635032c21d5d9a11aba75b23b to your computer and use it in GitHub Desktop.
Save Sanaki/44200de635032c21d5d9a11aba75b23b to your computer and use it in GitHub Desktop.
Script for building retroarch and select cores
#!/usr/bin/env bash
# Known non-working (YMMV): Dosbox SVN CE (Dosbox Pure is now preferred anyway), Emux (requires a special build recipe), easyrpg (relies on a rather specific server setup and scripts now)
# Partial Reference: https://libretro.readthedocs.io/en/latest/development/retroarch/compilation/linux-and-bsd/
# FORCE when set to YES will build regardless of changes
# NOCLEAN when set to 1 will prevent make clean before each build. Do not use NOCLEAN on core recipes or cores won't pull changes. Due to this situation I recommend against building MAME as part of this script.
# EXIT_ON_ERROR determines if the build stops on errors
# SINGLE_CORE can be set to a core name to bypass building the entire recipe (core set)
# Load variables from file named "rabuildvars" in same directory as script, if present. File is simply executed in the shell via the "source" command, so more advanced environment prep can be done in here as well if desired.
[[ -f ${BASH_SOURCE%/*}/rabuildvars ]] && . "${BASH_SOURCE%/*}/rabuildvars" && echo 'Local build variables loaded' || echo 'No "rabuildvars" file found, skipping local variable loading'
# Cores to be built, exporting the libretro_cores env var will use that list instead. For ease of use, ~/.bashrc or the "rabuildvars" file will suffice for this. This default list is intended to cover all common bases, but it is not by any means a complete core set. Creating your own list is recommended.
echo "Building RetroArch and the following cores:" ${libretro_cores:="2048 atari800 bluemsx citra dolphin fbneo ffmpeg flycast genesis_plus_gx gw hatari mednafen_lynx mednafen_ngp mednafen_psx_hw mednafen_saturn mednafen_supergrafx mednafen_vb mednafen_wswan melonds mesen mgba mupen64plus_next neocd opera picodrive pokemini ppsspp prosystem quasi88 sameboy snes9x stella vice_x128 virtualjaguar"}
# Force rebuild of retroarch and all listed cores if command is "updatera force"
[[ $1 = "force" ]] && _force=YES || _force=NO
# Support users with modified XDG_CONFIG_HOME location
[[ -z "$XDG_CONFIG_HOME" ]] && XDG_CONFIG_HOME="$HOME/.config"
# Clone or update the libretro-super repo
mkdir -p ~/src
cd ~/src
git clone https://github.com/libretro/libretro-super.git --depth 1 2> >(grep -v 'already exists and is not an empty directory' >&2) || (cd libretro-super ; git pull)
cd libretro-super
# Build retroarch, use ra_recipe env var to specify a custom recipe if needed
FORCE=$_force EXIT_ON_ERROR=1 ./libretro-buildbot-recipe.sh ${ra_recipe:-recipes/linux/retroarch-linux-x64}
mkdir -p ~/bin
ln -fT ~/src/libretro-super/retroarch/retroarch ~/bin/retroarch
# Generate custom recipe for cores
truncate -s 0 recipes/linux/custom-cores-x64
for core in $libretro_cores; do
# Check if libretro_recipe exists and is a file, pull core recipe overrides from it if present
if [[ -e $libretro_recipe ]] && [[ ! -z $(grep "^$core " "$libretro_recipe") ]]
then
sed -n "/^$core\s/p" "$libretro_recipe" >> recipes/linux/custom-cores-x64
else
sed -n "/^$core\s/p" recipes/linux/cores-linux-x64-generic >> recipes/linux/custom-cores-x64
fi
done
ln -f recipes/linux/cores-linux-x64-generic.conf recipes/linux/custom-cores-x64.conf
# Build cores
FORCE=$_force EXIT_ON_ERROR=0 ./libretro-buildbot-recipe.sh recipes/linux/custom-cores-x64
# Hardlink cores into default core directory used by retroarch (generating directories if needed, overwriting existing cores)
mkdir -p "$XDG_CONFIG_HOME"/retroarch/cores
ln -f ~/src/libretro-super/dist/unix/*.so "$XDG_CONFIG_HOME"/retroarch/cores/
# Symlink PPSSPP assets to system if included in core list.
if [[ $libretro_cores == *"ppsspp"* ]]; then
mkdir -p "$XDG_CONFIG_HOME"/retroarch/system
ln -sfT ~/src/libretro-super/libretro-ppsspp/assets "$XDG_CONFIG_HOME"/retroarch/system/PPSSPP
fi
# Clone/pull and symlink dolphin assets if requested. Clone size is ~40MiB.
if [[ "$libretro_dolphin_assets" -eq 1 ]]; then
cd ~/src
git clone https://github.com/dolphin-emu/dolphin.git --depth 1 2> >(grep -v 'already exists and is not an empty directory' >&2) || (cd dolphin ; git pull)
mkdir -p "$XDG_CONFIG_HOME"/retroarch/system/dolphin-emu
ln -sfT ~/src/dolphin/Data/Sys "$XDG_CONFIG_HOME"/retroarch/system/dolphin-emu/Sys
fi
# Symlink assets and other files into the default config directory
ln -sfT ~/src/libretro-super/retroarch/media/assets "$XDG_CONFIG_HOME"/retroarch/assets
ln -sfT ~/src/libretro-super/retroarch/media/autoconfig "$XDG_CONFIG_HOME"/retroarch/autoconfig
mkdir -p "$XDG_CONFIG_HOME"/retroarch/database
#ln -sfT ~/src/libretro-super/retroarch/media/libretrodb/cursors "$XDG_CONFIG_HOME"/retroarch/database/cursors
ln -sfT ~/src/libretro-super/retroarch/media/libretrodb/rdb "$XDG_CONFIG_HOME"/retroarch/database/rdb
ln -sfT ~/src/libretro-super/retroarch/media/overlays "$XDG_CONFIG_HOME"/retroarch/overlay
mkdir -p "$XDG_CONFIG_HOME"/retroarch/shaders
ln -sfT ~/src/libretro-super/retroarch/media/shaders_cg "$XDG_CONFIG_HOME"/retroarch/shaders/shaders_cg
ln -sfT ~/src/libretro-super/retroarch/media/shaders_glsl "$XDG_CONFIG_HOME"/retroarch/shaders/shaders_glsl
ln -sfT ~/src/libretro-super/retroarch/media/shaders_slang "$XDG_CONFIG_HOME"/retroarch/shaders/shaders_slang
# Symlink cheats without touching core-specific cheat files
mkdir -p "$XDG_CONFIG_HOME"/retroarch/cheats
for i in ~/src/libretro-super/retroarch/media/libretrodb/cht/*; do
ln -sfT "$i" "$XDG_CONFIG_HOME"/retroarch/cheats/"${i##*/}"
done
# Lock all cores added via this script (allows using online updater to "update all cores" without overwrite)
for i in ~/src/libretro-super/dist/unix/*.so; do
touch "$XDG_CONFIG_HOME"/retroarch/cores/"${i##*/}".lck
done
# Replace core info in default config with git core info
rm "$XDG_CONFIG_HOME"/retroarch/cores/*.info
cp ~/src/libretro-super/dist/info/*.info "$XDG_CONFIG_HOME"/retroarch/cores/
@Pysis868
Copy link

Pysis868 commented Jan 1, 2020

[[ -z "$cores" ]] && cores="..."; style and maybe for those other env vars too.

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