Skip to content

Instantly share code, notes, and snippets.

@guimondmm
Last active October 25, 2019 06:59
Show Gist options
  • Save guimondmm/a859fc11f945377afadb04f6f410ab16 to your computer and use it in GitHub Desktop.
Save guimondmm/a859fc11f945377afadb04f6f410ab16 to your computer and use it in GitHub Desktop.
Build ScummVM for Nintendo 3DS on macOS
#!/usr/bin/env bash
# Build ScummVM for Nintendo 3DS on macOS
set -e # exit on errors
sudo -K # reset sudo credentials
SCUMMVM_VERSION='v2.1.0' # tagged version of ScummVM (tested with v2.1.0)
FORMAT='cia' # 3dsx or cia
# (Un)comment the lines below to (de)select engines as needed
ENGINES=$(echo $(echo -e '
# access Access engine
# adl ADL engine
agi AGI engine
# agos AGOS engine
# agos2 AGOS 2 games in AGOS engine
# avalanche Lord Avalot d’Argent engine
# bbvs Beavis and Butthead in Virtual Stupidity engine
bladerunner Blade Runner engine
# cge CGE engine
# cge2 CGE2 engine
# chewy Chewy: Esc from F5 engine
# cine Cinematique evo 1 engine
# composer Magic Composer engine
# cruise Cinematique evo 2 engine
# cryo Lost Eden engine
# cryomni3d Cryo Omni3D games engine
# cstime Where in Time is Carmen Sandiego? in Mohawk engine
# director Macromedia Director engine
# dm Dungeon Master engine
# draci Dragon History engine
# drascula Drascula: The Vampire Strikes Back engine
# dreamweb Dreamweb engine
# eob Eye of the Beholder in Kyra engine
# fullpipe Full Pipe engine
# glk ScummGlk Interactive Fiction games engine
# gnap UFOs engine
# gob Gobli*ns engine
# groovie Groovie engine
# groovie2 Groovie 2 games in Groovie engine
# hdb Hyperspace Delivery Boy! engine
# he HE71+ games in SCUMM engine
# hopkins Hopkins FBI engine
# hugo Hugo Trilogy engine
# ihnm IHNM in SAGA engine
# illusions Illusions Engine engine
# kyra Kyra engine
# lab Labyrinth of Time engine
# lastexpress The Last Express engine
# lilliput Lilliput engine
# lol Lands of Lore in Kyra engine
# lure Lure of the Temptress engine
# macventure MacVenture engine
# made MADE engine
# mads MADS engine
# mohawk Mohawk engine
# mortevielle Mortevielle engine
# mutationofjb Mutation of JB engine
# myst Myst in Mohawk engine
# neverhood Neverhood engine
# parallaction Parallaction engine
# pegasus The Journeyman Project: Pegasus Prime engine
# pink Pink Panther engine
# plumbers Plumbers Don’t Wear Ties engine
# prince The Prince and The Coward engine
queen Flight of the Amazon Queen engine
# riven Riven: The Sequel to Myst in Mohawk engine
# saga SAGA engine
# saga2 SAGA 2 games in SAGA engine
sci SCI engine
# sci32 SCI32 games in SCI engine
scumm SCUMM engine
scumm-7-8 v7 & v8 games in SCUMM engine
# sherlock The Lost Files of Sherlock Holmes engine
sky Beneath a Steel Sky engine
# sludge Sludge engine
# startrek Star Trek 25th Anniversary/Judgment Rites engine
# supernova Mission Supernova engine
sword1 Broken Sword engine
sword2 Broken Sword II engine
sword25 Broken Sword 2.5 engine
# teenagent Teen Agent engine
# testbed TestBed: the Testing framework engine
# tinsel Tinsel engine
# titanic Starship Titanic engine
# toltecs 3 Skulls of the Toltecs engine
# tony Tony Tough and the Night of Roasted Moths engine
# toon Toonstruck engine
# touche Touche: The Adventures of the Fifth Musketeer engine
# tsage TsAGE engine
# tucker Bud Tucker in Double Trouble engine
# versailles Versailles 1685 in Cryo Omni3D games engine
# voyeur Voyeur engine
# wage WAGE engine
# wintermute Wintermute engine
# xeen World of Xeen engine
# zvision Z-Vision engine' |
sed -n 's/ *\([^# ]*\) *.*/\1/p') | sed 's/ /,/g')
# Checking for Xcode command line tools
if ! [ -d "$(xcode-select -p 2> /dev/null)" ]; then
echo -e '\e[1m\e[97mInstalling the Command Line Tools for Xcode…\e[0m'
DEMAND_TOOLS='/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress'
touch $DEMAND_TOOLS
softwareupdate -i "$(softwareupdate -l | grep -B 1 -E 'Command Line Tools' |
awk -F'*' '/^ *\\*/ {print $2}' | sed -e 's/^ *Label: //' -e 's/^ *//' |
sort -V | tail -n1)"
rm $DEMAND_TOOLS
until [ -d "$(xcode-select -p 2> /dev/null)" ]; do
xcode-select --install &> /dev/null
read -r -s -n 1 -p \
'Wait for the installation to complete, then press any key to continue…'
echo
done
fi
# Check for devkitPro pacman (installing requires sudo)
# https://devkitpro.org/wiki/devkitPro_pacman
if ! dkp-pacman -V &> /dev/null; then
echo -e '\e[1m\e[97mDownloading devkitPro pacman…\e[0m'
curl $(curl -s https://api.github.com/repos/devkitPro/pacman/releases/latest |
sed -n 's/.*browser.*\(https.*pkg\).*/\1/p') -L -o /tmp/dkp-pacman.pkg
echo -e '\e[1m\e[97mInstalling devkitPro pacman…\e[0m'
sudo installer -pkg /tmp/dkp-pacman.pkg -target /
rm /tmp/dkp-pacman.pkg
fi
# Find missing devkitPro packages (installing requires sudo)
echo -e '\e[1m\e[97mChecking for required devkitPro packages…\e[0m'
MISSING=""
DEPS='3ds-dev devkitpro-pkgbuild-helpers 3ds-portlibs 3ds-libmad'
for D in $DEPS; do
dkp-pacman -Qq $(dkp-pacman -Ssq ^$D\$) || MISSING="$D ${MISSING}"
done
if [ "$MISSING" ]; then
echo -e '\e[1m\e[97mInstalling missing devkitPro packages…\e[0m'
sudo dkp-pacman -Sy --noconfirm --needed $MISSING
fi
# Clone or reset tagged version of ScummVM repo
if [ -d "scummvm-${SCUMMVM_VERSION}" ]; then
echo -e "\e[1m\e[97mCleaning up scummvm-${SCUMMVM_VERSION} directory…\e[0m"
cd scummvm-$SCUMMVM_VERSION
git reset --hard "${SCUMMVM_VERSION}"
git clean -fdx
else
echo -e "\e[1m\e[97mDownloading scummvm-${SCUMMVM_VERSION}…\e[0m"
git clone --branch "${SCUMMVM_VERSION}" \
--depth 1 git@github.com:scummvm/scummvm.git scummvm-$SCUMMVM_VERSION
cd scummvm-$SCUMMVM_VERSION
fi
# Set up the build environment (requires bash)
# https://doxygen.scummvm.org/d0/dce/md_backends_platform_3ds_README.html
echo -e "\e[1m\e[97mSetting up the build environment…\e[0m"
source /opt/devkitpro/devkitarm.sh
source /opt/devkitpro/3dsvars.sh
export PKG_CONFIG_PATH=$PORTLIBS_PREFIX/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PORTLIBS_PREFIX/lib/pkgconfig
export CFLAGS="-g -march=armv6k -mtune=mpcore -mfloat-abi=hard -O2
-mword-relocations -ffunction-sections -fdata-sections"
export CPPFLAGS="-I${PORTLIBS_PREFIX}/include -I${DEVKITPRO}/libctru/include"
./configure --prefix=$PORTLIBS_PREFIX --host=arm-none-eabi --enable-static
# The command below will include all engines and will likely be
# too massive to be stable using either the 3DSX or the CIA format:
# ./configure --host=3ds
# Instead, enable the desired engines selectively:
./configure --host=3ds --disable-all-engines --enable-engine=$ENGINES
echo -e "\e[1m\e[97mBuilding ScummVM ${FORMAT^^}…\e[0m"
make && make scummvm.$FORMAT
# Verify the size of the binary
if [ -f *.elf ]; then
SIZE=$(size -A *.elf | sed -n 's/.text *\([0-9]*\).*/\1/p')
[ $SIZE -le 10000000 ] ||
>&2 echo -e "\e[33mWarning: ELF .text segment is too large\! (${SIZE} Bytes)
Cull some engines or you may experience crashes in memory-intensive games.\e[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment