Skip to content

Instantly share code, notes, and snippets.

@towerofnix
Last active October 10, 2016 17:38
Show Gist options
  • Save towerofnix/fccc72ffb23bc522fd9e44444a946657 to your computer and use it in GitHub Desktop.
Save towerofnix/fccc72ffb23bc522fd9e44444a946657 to your computer and use it in GitHub Desktop.
Makes Nintendo DS devkitPro development less hard, so you can finally Do Stuff!
read -r -d '' DOCS <<EndDocs
# -- DS Util --
# Only the most helpful utility on the whole file system!
#
# Basics and Config Structure
# DS Util is a project I made so that it's easier to Do Stuff related to the
# Nintendo DS. Read on to learn about the various functions this publishes.
#
# All this stuff almost definitely only works on Mac OS X (or macOS, or
# whatever they call it now).
#
# Also you'll need to get jq, which is used for parsing the project JSON
# config stuff: https://stedolan.github.io/jq/
#
# And this is all designed for people using devkitPro for DS development.
#
# Configuration is stored in ./proj_config.json. You're expected to run
# ds-utils in the working directory of your project, that is, the folder that
# contains NDS files built by make, the "source" folder, and so on.
#
# {
# publish_nds: Location to copy the built NDS file when publishing. See
# ds-publish.
# mounted_publish: {
# volume: Volume to mount before publishing. See ds-publish.
# unmount: Boolean specifying whether or not to unmount the volume. Also
# see ds-publish.
# }
# }
#
# ds-help
# This, duh.
#
# ds-build
# Used to build the DS file. For now it just runs make. Used as a dependency
# for various other ds-utils.
#
# ds-test
# Used to test run a DS file. Can use a specified application to open the NDS
# file by specifying .test_app in the configuration file, but defaults to
# DeSmuME.
#
# ds-publish
# Used to publish a DS file to a separate location. Runs ds-build as a
# dependency.
#
# If mounted_publish.volume is specified, ds-publish will mount this volume
# using diskutil before copying the file over. Additionally,
# mounted_publish.unmount can be set to true to unmount the volume after
# copying the file over. It's handy for exporting to a microSD slot, for
# example.
#
# - end of docs -
EndDocs
ds() {
echo "ds ---------"
echo " ds-help"
echo " ds-build"
echo " ds-publish"
echo " ds-test"
}
ds-help() {
echo "$DOCS" | less
}
ds-build() {
echo -e "\x1b[33mBuilding..\x1b[0m"
if make; then
echo -e "\x1b[33mBuilding done!\x1b[0m"
return 0
else
echo -e "\x1b[31mFailed to build :(\x1b[0m"
return $?
fi
}
ds-publish() {
ds-build
echo -e "\x1b[33mPublishing..\x1b[0m"
VOLUME="$(cat proj_config.json | jq -r .mounted_publish.volume)"
if [ "$VOLUME" != "null" ]; then
diskutil mount "$VOLUME"
fi
SRC_NDS="$(basename $(pwd)).nds"
PUB_NDS="$(cat proj_config.json | jq -r '.publish_nds')"
echo "$SRC_NDS -> $PUB_NDS..."
cp "$SRC_NDS" "$PUB_NDS"
UNMOUNT="$(cat proj_config.json | jq -r .mounted_publish.unmount)"
if [ "$UNMOUNT" == "true" ]; then
diskutil unmount "$VOLUME"
fi
echo -e "\x1b[33mPublishing done!\x1b[0m"
}
ds-test() {
if ds-build; then
SRC_NDS="$(basename $(pwd)).nds"
TEST_APP="$(cat proj_config.json | jq -r .test_app)"
if [ "$TEST_APP" == "null" ]; then
TEST_APP="DeSmuME"
fi
open -a "$TEST_APP" "$SRC_NDS"
fi
}
export -f ds-build
export -f ds-test
export -f ds-publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment