-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·225 lines (186 loc) · 7.06 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·225 lines (186 loc) · 7.06 KB
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
#!/bin/bash
# Function to display usage
usage() {
echo ""
echo " KeeperFX Launcher - Build Script"
echo ""
echo " Usage: $0 <win64s|linux64> <debug|release|console> [--installer] [--verbose]"
echo ""
echo " Commands: "
echo " $0 <win64s|linux64> <debug|release> build a debug or release version"
echo " $0 <win64s|linux64> console open a console in the build container"
echo ""
echo " Options:"
echo " --installer also create an installer for the release build"
echo " --verbose enable cmake verbosity"
echo ""
exit 1
}
# Check if at least 2 arguments are provided
if [ $# -lt 2 ]; then
usage
fi
# Make sure $(pwd) is populated
if [[ -n "$(pwd)" ]]; then
echo "Current directory: $(pwd)"
else
echo "Failed to retrieve the current directory"
exit 1
fi
# Variables
TARGET="$1"
MODE="$2"
VERBOSE=""
BUILD_SHARED_LIBS=ON
BUILD_INSTALLER=OFF
TARGET_CONTAINER=""
# Handle options
shift 2 # Remove first 2 arguments
while (("$#")); do
case "$1" in
--installer)
BUILD_INSTALLER=ON
;;
--verbose)
VERBOSE="--verbose"
;;
*)
usage
;;
esac
shift
done
# Make sure target is valid
if [[ "$TARGET" =~ ^(win64s|linux64)$ ]]; then
echo "Target: $TARGET"
else
echo "Invalid target: $TARGET"
exit 1
fi
# Disallow making installers for debug versions
if [ "$MODE" == "debug" ] && [ "$BUILD_INSTALLER" == "ON" ]; then
echo "Making an installer for a debug version is not possible"
exit 1
fi
# Get current user and group ID
USER_ID=$(id -u)
GROUP_ID=$(id -g)
# Get launcher version
HEADER_FILE="$(pwd)/src/version.h"
VERSION_MAJOR=$(grep -E "#define LAUNCHER_VERSION_MAJOR" "$HEADER_FILE" | awk '{print $3}')
VERSION_MINOR=$(grep -E "#define LAUNCHER_VERSION_MINOR" "$HEADER_FILE" | awk '{print $3}')
VERSION_PATCH=$(grep -E "#define LAUNCHER_VERSION_PATCH" "$HEADER_FILE" | awk '{print $3}')
VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
echo "Launcher Version: $VERSION"
# Docker container names:
# kfx-launcher-qt-build-base
# kfx-launcher-qt-build-win64s
# kfx-launcher-qt-build-linux64
# Build the base build container image if it does not exist
if [[ "$(docker images -q kfx-launcher-qt-build-base 2> /dev/null)" == "" ]]; then
echo "Docker image kfx-launcher-qt-build-base does not exist. Building the image..."
docker build -t kfx-launcher-qt-build-base -f Dockerfile.base .
else
echo "Docker image 'kfx-launcher-qt-build-base' already exists. No need to build again."
fi
# Make sure the base build container image exists after a possible build
if [[ "$(docker images -q kfx-launcher-qt-build-base 2> /dev/null)" == "" ]]; then
echo "Docker image 'kfx-launcher-qt-build-base' does not exist"
exit 1
fi
# Build the required build container image if it does not exist
if [[ "$(docker images -q kfx-launcher-qt-build-$TARGET 2> /dev/null)" == "" ]]; then
echo "Docker image kfx-launcher-qt-build-$TARGET does not exist. Building the image..."
docker build -t kfx-launcher-qt-build-$TARGET -f Dockerfile.$TARGET .
else
echo "Docker image 'kfx-launcher-qt-build-$TARGET' already exists. No need to build again."
fi
# Make sure the required build container image exists after possible build
if [[ "$(docker images -q kfx-launcher-qt-build-$TARGET 2> /dev/null)" == "" ]]; then
echo "Docker image 'kfx-launcher-qt-build-$TARGET' does not exist"
exit 1
fi
# Handle mode
if [ "$MODE" == "console" ]; then
docker run --rm -it -v "$(pwd)":/project -u $USER_ID:$GROUP_ID kfx-launcher-qt-build-$TARGET bash
exit 0
elif [ "$MODE" == "debug" ]; then
CMAKE_BUILD_TYPE="Debug"
elif [ "$MODE" == "release" ]; then
CMAKE_BUILD_TYPE="Release"
BUILD_SHARED_LIBS=OFF
else
usage
fi
# Start compiling
echo "Compiling $TARGET $CMAKE_BUILD_TYPE build..."
if [ "$TARGET" = "win64s" ]; then
docker run --rm -v "$(pwd)":/project -u $USER_ID:$GROUP_ID kfx-launcher-qt-build-win64s bash -c "
cd /project &&
x86_64-w64-mingw32.static-cmake -Bbuild/mingw-win64 -H. -DWINDOWS=TRUE -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -Wno-dev &&
x86_64-w64-mingw32.static-cmake --build build/mingw-win64 --config $CMAKE_BUILD_TYPE $VERBOSE
"
# Make sure executable is built
if ! [ -f "$(pwd)/build/mingw-win64/keeperfx-launcher-qt.exe" ]; then
echo "Executable 'keeperfx-launcher-qt.exe' not built"
exit 1
fi
# Handle release
if [ "$MODE" == "release" ]; then
# Clean up any previous builds
if [ -d "$(pwd)/release/win64" ]; then
rm -rf "$(pwd)/release/win64"
fi
# Make release dir and move files
mkdir -p "$(pwd)/release/win64/"
cp "$(pwd)/build/mingw-win64/keeperfx-launcher-qt.exe" "$(pwd)/release/win64/keeperfx-launcher-qt.exe"
cp "$(pwd)/build/mingw-win64/7za.dll" "$(pwd)/release/win64/7za.dll"
# Make an installer
if [ "$BUILD_INSTALLER" == "ON" ]; then
echo "Building installer..."
docker run --rm -i -v "$(pwd)":/work amake/innosetup windows-installer.iss
# Rename installer to include launcher version
mv "$(pwd)/release/win64/keeperfx-web-installer.exe" "$(pwd)/release/win64/keeperfx-launcher-qt-$VERSION-win64-web-installer.exe"
fi
# Package files
echo "Packaging release"
7z a "$(pwd)/release/win64/keeperfx-launcher-qt-$VERSION-win64.7z" "$(pwd)/release/win64/keeperfx-launcher-qt.exe" "$(pwd)/release/win64/7za.dll"
# Show release directory output
ls -lh "$(pwd)/release/win64/"
fi
fi
if [ "$TARGET" = "linux64" ]; then
docker run --rm -v "$(pwd)":/project -u $USER_ID:$GROUP_ID kfx-launcher-qt-build-linux64 bash -c "
cd /project &&
cmake -Bbuild/linux64 -H. -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -Wno-dev &&
cmake --build build/linux64 --config $CMAKE_BUILD_TYPE $VERBOSE
"
# Make sure executable is built
if ! [ -f "$(pwd)/build/linux64/keeperfx-launcher-qt" ]; then
echo "Binary 'keeperfx-launcher-qt' not built"
exit 1
fi
# Handle release
if [ "$MODE" == "release" ]; then
# Clean up any previous builds
if [ -d "$(pwd)/release/linux64" ]; then
rm -rf "$(pwd)/release/linux64"
fi
# Make release dir and move files
mkdir -p "$(pwd)/release/linux64"
cp "$(pwd)/build/linux64/keeperfx-launcher-qt" "$(pwd)/release/linux64/keeperfx-launcher-qt"
cp "$(pwd)/build/linux64/7z.so" "$(pwd)/release/linux64/7z.so"
# Package files
# echo "Packaging release"
# 7z a "$(pwd)/release/win64/keeperfx-launcher-qt-$VERSION-win64.7z" "$(pwd)/release/win64/keeperfx-launcher-qt.exe" "$(pwd)/release/win64/7za.dll"
# Show release directory output
ls -lh "$(pwd)/release/linux64/"
fi
# TODO:
# MAKE SURE BINARY IS BUILT
# MOVE TO RELEASE DIR
# LINUX DEPLOY
fi
# Done
echo ""
echo "Build complete."