Make build check for dependencies

This commit is contained in:
Andrew Miner
2017-06-03 11:00:18 -07:00
parent 5a1f4d244c
commit ebbbfffca1
+30 -6
View File
@@ -3,22 +3,40 @@
# Constants ############################################################################################################ # Constants ############################################################################################################
read -d  USAGE <<-END read -d  USAGE <<-END
USAGE: $0 <clean|compile|watch|help> (--view) USAGE: $0 <clean|compile|help|watch> (--view)
END END
FSWATCH="fswatch"
LILYPOND_APP="/Applications/LilyPond.app"
LILYPOND="$LILYPOND_APP/Contents/Resources/bin/lilypond"
# Helper Functions ##################################################################################################### # Helper Functions #####################################################################################################
function cancel { function cancel {
usage; echo; echo $@ echo "$USAGE"; echo; echo $@
exit 1 exit 1
} }
function check-dependencies {
if ! which -s "$FSWATCH"; then
echo "Could not find \"fswatch\"! Try installing using: brew install fswatch"
echo
exit 1
fi
if [[ ! -d "$LILYPOND_APP" ]]; then
echo "Could not find LilyPond! Please install it from http://lilypond.org/download.html."
echo
exit 1
fi
}
function compile-ly { function compile-ly {
BASE_NAME=$(basename -s .ly $1) BASE_NAME=$(basename -s .ly $1)
DIR_NAME=$(dirname $1 | sed "s@./src/scores/@@") DIR_NAME=$(dirname $1 | sed "s@./src/scores/@@")
mkdir -p "dist/$DIR_NAME" mkdir -p "dist/$DIR_NAME"
lilypond -I "$PWD/src/includes" -I "$PWD/src/pieces" -o "dist/$DIR_NAME/$BASE_NAME" $1 $LILYPOND -I "$PWD/src/includes" -I "$PWD/src/pieces" -o "dist/$DIR_NAME/$BASE_NAME" $1
if [[ "$VIEW" == "YES" ]]; then if [[ "$VIEW" == "YES" ]]; then
open -a "/Applications/Google Chrome.app" -g "dist/$DIR_NAME/$BASE_NAME.pdf" open -a "/Applications/Google Chrome.app" -g "dist/$DIR_NAME/$BASE_NAME.pdf"
@@ -45,13 +63,13 @@ function command-compile {
PATTERNS=(${PATTERNS[@]:1}) PATTERNS=(${PATTERNS[@]:1})
find src/scores -name "*.ly" | grep -v includes | grep "$PATTERN" | while read FILE; do find src/scores -name "*.ly" | grep -v includes | grep "$PATTERN" | while read FILE; do
compile-ly $FILE compile-ly "./$FILE"
done done
done done
} }
function command-watch { function command-watch {
fswatch -r src/scores -i '*.ly$' -e "includes" | while read FILE; do $FSWATCH -r src/scores -i '*.ly$' -e "includes" | while read FILE; do
FILE=$(echo $FILE | sed "s@$PWD@.@") FILE=$(echo $FILE | sed "s@$PWD@.@")
compile-ly $FILE compile-ly $FILE
done done
@@ -59,26 +77,32 @@ function command-watch {
# Initialization ####################################################################################################### # Initialization #######################################################################################################
check-dependencies
COMMAND="$1" COMMAND="$1"
shift shift
[[ "$COMMAND" == "" ]] && COMMAND="help" [[ "$COMMAND" == "" ]] && COMMAND="help"
PATTERNS=() PATTERNS=()
HELP="NO"
VIEW="NO" VIEW="NO"
while [[ "$1" != "" ]]; do while [[ "$1" != "" ]]; do
case "$1" in case "$1" in
-h|-?|--help) HELP="YES";;
-v|--view) VIEW="YES";; -v|--view) VIEW="YES";;
*) PATTERNS+=($1);; *) PATTERNS+=($1);;
esac esac
shift shift
done done
[[ "$HELP" == "YES" ]] && usage
case "$COMMAND" in case "$COMMAND" in
-h|--help|help) usage;;
clean) command-clean;; clean) command-clean;;
compile) command-compile;; compile) command-compile;;
help|-h|-?|--help) usage;;
watch) command-watch;; watch) command-watch;;
*) cancel "Unrecognized command: $COMMAND" *) cancel "Unrecognized command: $COMMAND"
esac esac