Newer
Older
#!/bin/bash
output=/dev/stdout
# displays help text
function displayHelp {
cat << HelpText
Usage: compile.sh [OPTION]...
Options:
-d, --dry Do not compile
-g, --git Add hash of HEAD to filename
-h, --help Show this help text
-p, --python Run sanityCheck based on python
-q, --quiet Suppress terminal output
HelpText
}
#display an error message
function echoError {
echo -e "\033[0;31m$@\033[0m"
}
#display message
function echoMessage {
echo "$1" > "${output}"
}
#compile the HTML file
function compile {
mkdir -p bin
export TWEEGO_PATH=devTools/tweeGo/storyFormats
TWEEGO_EXE="tweego"
if hash $TWEEGO_EXE 2>/dev/null; then
echoMessage "system tweego binary"
else
case "$(uname -m)" in
x86_64|amd64)
echoMessage "x64 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx64"
elif [ $OSTYPE = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win64"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix64"
fi
;;
x86|i[3-6]86)
echoMessage "x86 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx86"
elif [ $OSTYPE = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win86"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix86"
fi
;;
*)
echoError "No system tweego binary found, and no precompiled binary for your platform available."
echoError "Please compile tweego and put the executable in PATH."
exit 2
esac
fi
if [[ "$usehash" ]]; then
HASH="$(git rev-list -n 1 --abbrev-commit HEAD)"
COMMIT=$(git rev-parse --short HEAD) # Find and insert current commit
sed -Ei "s/build .releaseID/\0 commit $COMMIT/" src/gui/mainMenu/AlphaDisclaimer.tw
$TWEEGO_EXE -o $file src/ --head devTools/head.html || build_failed="true"
if [ "$build_failed" = "true" ]
then
echoError "Build failed."
exit 1
fi
#Make the output prettier, replacing \t with a tab and \n with a newline
sed -i -e '/^.*<div id="store-area".*$/s/\\t/\t/g' -e '/^.*<div id="store-area".*$/s/\\n/\n/g' $file
if [[ ! "$usehash" ]]; then git checkout -- src/gui/mainMenu/AlphaDisclaimer.tw;fi # Revert AlphaDisclaimer for next compilation
echoMessage "Saved to $file."
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
}
if [[ "$1" == "" ]]; then
#tip if no option
echoMessage "For more options see compile.sh -h."
else
#parse options
while [[ "$1" ]]
do
case $1 in
-d|--dry)
dry="true"
;;
-g|--git)
usehash="true"
;;
-h|--help)
displayHelp
exit 0
;;
-j|--java)
java="true"
;;
-p|--python)
python="true"
;;
-q|--quiet)
output=/dev/null
;;
*)
echoError "Unknown argument $1."
displayHelp
exit 1
esac
shift
done
fi
# Run sanity check.
[ -n "$java" ] && ./sanityCheck.sh java
[ -n "$python" ] && ./sanityCheck.sh
#compile
if [[ "$dry" ]]; then
echoMessage "Dry run finished."
else
compile
echoMessage "Compilation finished."