-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild Stratagus.sh
executable file
·239 lines (215 loc) · 7.26 KB
/
Build Stratagus.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env zsh
# ANSI colour codes
PURPLE='\033[0;35m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Colour
# This just gets the location of the folder where the script is run from.
SCRIPT_DIR=${0:a:h}
cd "$SCRIPT_DIR"
# Detect CPU architecture and number of cores
ARCH_NAME="$(uname -m)"
CORES=$(sysctl -n hw.ncpu)
# Introduction
echo "\n${PURPLE}This script is for compiling a native macOS build of:"
echo "${GREEN}War1gus - ${PURPLE}Warcraft: Orcs and Humans${NC}"
echo "${GREEN}Wargus - ${PURPLE}Warcraft II${NC}"
echo "${GREEN}Stargus - ${PURPLE}Starcraft${RED} Starcraft is currently not playable${NC}"
echo "\n${PURPLE}The app can extract the original game data from an official GoG or BNE game installer${NC}"
echo "\n${PURPLE}Note that due to a bug in the source code, the source folder is required when using the data extraction tool${NC}"
echo "${PURPLE}The source code folder can be safely deleted after you have extracted the game data\n${NC}"
echo "${GREEN}Homebrew${PURPLE} and the ${GREEN}Xcode command-line tools${PURPLE} are required to build${NC}"
echo "${PURPLE}If they are not present you will be prompted to install them${NC}\n"
# Check for homebrew installation
homebrew_check() {
echo "${PURPLE}Checking for Homebrew...${NC}"
if ! command -v brew &> /dev/null; then
echo -e "${PURPLE}Homebrew not found. Installing Homebrew...${NC}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ "${ARCH_NAME}" == "arm64" ]]; then
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> $HOME/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
else
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> $HOME/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
fi
# Check for errors
if [ $? -ne 0 ]; then
echo "${RED}There was an issue installing Homebrew${NC}"
echo "${PURPLE}Quitting script...${NC}"
exit 1
fi
else
echo -e "${PURPLE}Homebrew found. Updating Homebrew...${NC}"
brew update
fi
}
# Function for checking for an individual dependency
single_dependency_check() {
if [ -d "$(brew --prefix)/opt/$1" ]; then
echo -e "${GREEN}Found $1. Checking for updates...${NC}"
brew upgrade $1
else
echo -e "${PURPLE}Did not find $1. Installing...${NC}"
brew install $1
fi
}
# Install required dependencies
check_all_dependencies() {
echo -e "${PURPLE}Checking for Homebrew dependencies...${NC}"
# Required Homebrew packages
deps=( cmake dylibbundler sdl2 sdl2_mixer sdl2_image lua libpng ffmpeg meson ninja )
for dep in $deps[@]
do
single_dependency_check $dep
done
}
# Build Stratagus
build_stratagus() {
echo "${PURPLE}Building Stratagus...${NC}"
git clone --recurse-submodules https://github.com/Wargus/stratagus
cd stratagus
cmake . -B build -DBUILD_VENDORED_LUA=ON -DWITH_OPENMP=OFF
# If there is an issue with libs: -DBUILD_VENDORED_MEDIA_LIBS=ON
make -C build -j$CORES
cd ..
export STRATAGUS_INCLUDE_DIR=${PWD}/stratagus/gameheaders
export STRATAGUS=${PWD}/stratagus/build/stratagus
# Check for errors
if [ $? -ne 0 ]; then
echo "${RED}There was an issue building Stratagus${NC}"
echo "${PURPLE}Quitting script...${NC}"
exit 1
fi
}
build_war1gus() {
echo "${PURPLE}Building War1gus...${NC}"
git clone --recurse-submodules https://github.com/Wargus/war1gus
cd war1gus
cmake . -B build \
-DSTRATAGUS_INCLUDE_DIR=$STRATAGUS_INCLUDE_DIR \
-DSTRATAGUS=$STRATAGUS \
-DCMAKE_FIND_FRAMEWORK=LAST
make -C build -j$CORES
./mac/bundle.sh
rm -rf ../Warcraft.app
mv ./mac/War1gus.app ../Warcraft.app && cd ..
# Optional: Get a Warcraft icon
curl -o Warcraft.app/Contents/Resources/war1gus.icns https://parsefiles.back4app.com/JPaQcFfEEQ1ePBxbf6wvzkPMEqKYHhPYv8boI1Rc/b219394bc1718b8d2858b5977a1f4b8b_Warcraft.icns
# Bundle libs & Codesign
dylibbundler -of -cd -b -x ./Warcraft.app/Contents/MacOS/stratagus -d ./Warcraft.app/Contents/libs/
dylibbundler -of -cd -b -x ./Warcraft.app/Contents/MacOS/war1tool -d ./Warcraft.app/Contents/libs/
# Check for errors
if [ $? -ne 0 ]; then
echo "${RED}There was an issue building War1gus${NC}"
echo "${PURPLE}Quitting script...${NC}"
exit 1
fi
}
build_wargus() {
echo "${PURPLE}Building Wargus...${NC}"
git clone --recurse-submodules https://github.com/Wargus/wargus
cd wargus
cmake . -B build \
-DSTRATAGUS_INCLUDE_DIR=$STRATAGUS_INCLUDE_DIR \
-DSTRATAGUS=$STRATAGUS \
-DCMAKE_FIND_FRAMEWORK=LAST
make -C build -j$CORES
./mac/bundle.sh
rm -rf ../Warcraft\ II.app
mv ./mac/Wargus.app ../Warcraft\ II.app && cd ..
# Optional: Get a Warcraft II icon
curl -o Warcraft\ II.app/Contents/Resources/wargus.icns https://parsefiles.back4app.com/JPaQcFfEEQ1ePBxbf6wvzkPMEqKYHhPYv8boI1Rc/f333e393cb0e0d7dffe4c63401aa9abb_Warcraft_2.icns
# Bundle libs & Codesign
dylibbundler -of -cd -b -x ./Warcraft\ II.app/Contents/MacOS/stratagus -d ./Warcraft\ II.app/Contents/libs/
dylibbundler -of -cd -b -x ./Warcraft\ II.app/Contents/MacOS/wartool -d ./Warcraft\ II.app/Contents/libs/
# Check for errors
if [ $? -ne 0 ]; then
echo "${RED}There was an issue building Wargus${NC}"
echo "${PURPLE}Quitting script...${NC}"
exit 1
fi
}
build_stargus() {
echo "${PURPLE}Building Stargus...${NC}"
git clone --recurse-submodules https://github.com/Wargus/stargus
cd stargus
meson setup -DSTRATAGUS_INCLUDE_DIR=$STRATAGUS_INCLUDE_DIR -DSTRATAGUS_BIN=$STRATAGUS build
ninja -C build
./mac/bundle.sh
rm -rf ../Starcraft.app
mv ./mac/Stargus.app ../Starcraft.app && cd ..
# Optional: Get a Starcraft icon
curl -o Starcraft.app/Contents/Resources/stargus.icns https://parsefiles.back4app.com/JPaQcFfEEQ1ePBxbf6wvzkPMEqKYHhPYv8boI1Rc/19a774b8baa4ad3dd3e9e097d30d6cd9_Starcraft.icns
# Bundle libs & Codesign
dylibbundler -of -cd -b -x ./Starcraft.app/Contents/MacOS/stratagus -d ./Starcraft.app/Contents/libs/
dylibbundler -of -cd -b -x ./Starcraft.app/Contents/MacOS/startool -d ./Starcraft.app/Contents/libs/
# Check for errors
if [ $? -ne 0 ]; then
echo "${RED}There was an issue building Stargus${NC}"
echo "${PURPLE}Quitting script...${NC}"
exit 1
fi
}
PS3='Which game would you like to build? '
OPTIONS=(
"War1gus"
"Wargus"
"War1gus & Wargus"
"Stargus"
"All"
"Quit")
select opt in $OPTIONS[@]
do
case $opt in
"War1gus")
homebrew_check
check_all_dependencies
build_stratagus
build_war1gus
break
;;
"Wargus")
homebrew_check
check_all_dependencies
build_stratagus
build_wargus
break
;;
"War1gus & Wargus")
homebrew_check
check_all_dependencies
build_stratagus
build_war1gus
build_wargus
break
;;
"Stargus")
homebrew_check
check_all_dependencies
build_stratagus
build_stargus
break
;;
"All")
homebrew_check
check_all_dependencies
build_stratagus
build_war1gus
build_wargus
build_stargus
break
;;
"Quit")
echo -e "${RED}Quitting${NC}"
exit 0
;;
*) echo "\"$REPLY\" is not one of the options...";;
esac
done
# Cleanup
# Note: Not removing the source dir because it is required in order for the extractor tool to work due to a bug.
echo "${PURPLE}Cleaning up...${NC}"
echo "${PURPLE}Not removing the source directories because they are required in order for the extractor tool to work${NC}"
echo "${PURPLE}After you have extracted the game data it is safe to delete the source directories${NC}"
rm -rf stratagus