-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcthupdate
executable file
·76 lines (63 loc) · 3.55 KB
/
cthupdate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
[ "$CTH_VERBOSE" ] || [ "$CI" ] && set -x
# shellcheck disable=SC2039
set -eo pipefail
# Pull the latest changes, if any CMake/C++ then run CMake and make, else the Lua files are copied into the latest app.
# Copyright 2016- tobylane. Licensed under the MIT licence found in LICENSE.txt or online
# Usage: cthupdate [ clean | build | cmake | make | animview [ xz | zip | folder | dmg ] [ release | upload ] ]
lua=5.4 # 5.1 5.3 5.4 for lua5.1 lua5.3 lua
gitlog=2 # Length of git log, 0 is acceptable
dir="$(brew --prefix)"
#ver=MACOSX_DEPLOYMENT_TARGET= # Target sdk version, or blank for latest, list with xcodebuild -showsdks
#lib=build_files/libs
if [ "$(basename "$PWD")" = "build_files" ]; then cd ..; fi
cd "$(git rev-parse --show-toplevel)"
# If the git repository is a fork and you want to build the latest upstream version
# git fetch upstream && git switch upstream/master > /dev/null 2>&1
if [ "$1" = "clean" ]
then rm -rf build && mkdir -p build/CorsixTH && echo "Cleaned" && exit 0
fi
if [ "$1" != "build" ] && [ "$1" != "cmake" ] && [ "$1" != "make" ] && [ "$1" != "animview" ] &&
[ "$(curl -sS -H "If-None-Match: $(git rev-parse HEAD)" -H 'Accept: application/vnd.github.v3.sha' \
'http://api.github.com/repos/CorsixTH/CorsixTH/commits/master' -o /dev/null -m 3 -w '%{http_code}')" != "304" ] &&
git pull --rebase --autostash 2>&1 | grep -qie 'up to date' >/dev/null # Alternatively 'git pull --ff-only'
then
echo "No new changes."; exit 0
elif git status | grep -qie 'HEAD detached'; then echo "Building detached head state"
elif git status | grep -qie 'Unmerged paths'; then echo "Git couldn't pull cleanly."; exit 128
fi
diff=$(git diff --name-only 'HEAD@{5.seconds.ago}' HEAD || git diff --name-only HEAD^ HEAD | tr ' ' '\n')
if [ "$1" = "build" ] || [ "$1" = "cmake" ] || echo "$diff" | grep -qie cmake
then
#CXXFLAGS="-march=nehalem -isysroot $(xcrun --show-sdk-path) -O2 -pipe" $ver \
#CMAKE_INCLUDE_PATH="$lib/include" CMAKE_LIBRARY_PATH="$lib/lib" \
cmake . -G"Unix Makefiles" -Bbuild -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="/Applications" \
-DWITH_AUDIO=ON -DWITH_MOVIES=ON -DLUA_LIBRARY="$dir/lib/liblua.$lua.dylib" #-DWITH_LUAROCKS=on
fi
if [ "$1" = "build" ] || [ "$1" = "make" ] || echo "$diff" | grep -qie cmake -e Src
then
cmake --build build/CorsixTH/ --target -- install #--always-make install 2>/dev/null
elif echo "$diff" | grep -qi -e CorsixTH/CorsixTH -e .txt
then
cd CorsixTH
rsync -a CorsixTH.lua Lua Levels Campaigns Graphics /Applications/CorsixTH.app/Contents/Resources/
rsync -a Bitmap/aux_ui.* Bitmap/tree_ctrl.* Bitmap/mainmenu1080.dat Bitmap/mainmenu1080.pal \
/Applications/CorsixTH.app/Contents/Resources/Bitmap/
elif [ -z "$1" ]; then echo "Nothing to do."
fi
if [ "$1" = "animview" ] #|| echo "$diff" | grep -qie AnimView -e AnimationViewer
then
cmake . -G"Unix Makefiles" -Bbuild -DBUILD_ANIMVIEWER=ON -DCMAKE_INSTALL_PREFIX="/Applications"
cmake --build build/AnimView/ --target -- --always-make install #2>/dev/null
fi
rsync -a README.txt LICENSE.txt CONTRIBUTING.txt changelog.txt /Applications/CorsixTH.app/ || true
if git describe --tags --contains 'HEAD@{1}' > /dev/null 2>&1 # Release or release candidate
then open -gt changelog.txt
fi
# Remove the single quoted section if you want to see changes pulled before today
git --no-pager log --no-merges -${gitlog:-1} --oneline --decorate --graph 'HEAD@{yesterday}..HEAD' \
|| git log --oneline -1 --no-merges
# git switch - # To return to the previous branch, to be used with line 19
if [ "$2" ]
then shift; build_files/cthpackage "$@"
fi