Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·184 lines (162 loc) · 4.56 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·184 lines (162 loc) · 4.56 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
#!/bin/bash
# save original home directory path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Clone dependencies
mkdir -p thirdparty
cd thirdparty
# Clone or update ASIO
if [ -d "asio" ]; then
echo "ASIO already exists, updating..."
cd asio && git pull && cd ..
else
git clone https://github.com/chriskohlhoff/asio.git
fi
if [ ! -d "asio/asio/include" ]; then
echo "ASIO directory structure incorrect, checking..."
if [ -f "asio/asio.hpp" ]; then
echo "Found ASIO headers at root"
else
echo "Warning: ASIO structure may be unexpected"
fi
fi
# Clone or update JSON
if [ -d "json" ]; then
echo "JSON already exists, updating..."
cd json && git pull && cd ..
else
git clone https://github.com/nlohmann/json.git
fi
# Clone or update spdlog
if [ -d "spdlog" ]; then
echo "spdlog already exists, updating..."
cd spdlog && git pull && cd ..
else
git clone https://github.com/gabime/spdlog.git
fi
# Clone or update GLM
if [ -d "glm" ]; then
echo "GLM already exists, updating..."
cd glm && git pull && cd ..
else
git clone https://github.com/g-truc/glm.git
fi
cd ..
# Parse command line arguments
USE_CITUS=OFF
USE_SQLITE=OFF
ENABLE_ASAN=OFF
CLEAR_PREVIOUS=OFF
APT_UPDATE=OFF
for arg in "$@"; do
case $arg in
--with-citus)
echo "Installing Citus extension..."
USE_CITUS=ON
;;
--with-sqlite)
echo "Installing SQLite3 development libraries..."
USE_SQLITE=ON
;;
--with-asan)
echo "Enabling AddressSanitizer and UndefinedBehaviorSanitizer"
ENABLE_ASAN=ON
;;
--apt-update)
echo "Enabling linux apt update"
APT_UPDATE=ON
;;
--clear)
echo "Enabling clear previous compilations"
CLEAR_PREVIOUS=ON
;;
*)
;;
esac
done
# Build configuration
echo "Building with Citus: $USE_CITUS, SQLite: $USE_SQLITE, ASan: $ENABLE_ASAN, apt update: $APT_UPDATE"
# Install system dependencies
if [ $APT_UPDATE == ON ]; then
sudo apt update
sudo apt install -y \
build-essential \
cmake \
libpq-dev \
python3-dev \
libssl-dev \
zlib1g-dev \
postgresql \
libglm-dev \
libasio-dev \
libspdlog-dev \
nlohmann-json3-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
libx11-dev \
libxi-dev \
libxrandr-dev \
mesa-common-dev \
uuid-dev \
libcrypt-dev \
libfmt-dev
if [ $USE_CITUS == ON ]; then
sudo apt install -y postgresql-citus
fi
if [ $USE_SQLITE == ON ]; then
sudo apt install -y libsqlite3-dev
fi
fi
# Clean previous build artifacts
rm -f CMakeCache.txt Makefile cmake_install.cmake
rm -rf CMakeFiles
# Create build directory and copy related folders
mkdir -p build
cd build
if [ "$CLEAR_PREVIOUS" == ON ]; then
echo "Clearing previous compilations..."
find . -mindepth 1 -maxdepth 1 ! -name "certs" -exec rm -rf {} +
fi
# Run CMake
cmake .. -B . \
-DUSE_CITUS=${USE_CITUS} \
-DUSE_SQLITE=${USE_SQLITE} \
-DENABLE_ASAN=${ENABLE_ASAN} \
-DCMAKE_BUILD_TYPE=Debug
# Build
make -j$(nproc)
# ========== SSL Certificate Generation ==========
if command -v openssl &> /dev/null; then
mkdir -p certs
if [ ! -f "certs/server.crt" ] || [ ! -f "certs/server.key" ]; then
echo "Generating self-signed SSL certificate..."
openssl req -x509 -newkey rsa:4096 \
-keyout certs/server.key \
-out certs/server.crt \
-days 365 -nodes \
-subj "/CN=localhost"
echo "SSL certificate and key created in certs/"
fi
if [ ! -f "certs/dhparam.pem" ]; then
echo "Generating DH parameters (this may take a moment)..."
openssl dhparam -out certs/dhparam.pem 2048
echo "DH parameters generated."
fi
else
echo "openssl not found, skipping SSL certificate generation"
fi
# ================================================
if [ -f "gameserver" ]; then
echo "Build successful! Executable: $(pwd)/gameserver"
else
echo "Build failed - no executable created"
echo "Check cmake output above for errors"
fi
# create default database user (commented out by default)
#sudo -u postgres psql -c "DROP USER IF EXISTS gameuser;"
#sudo -u postgres psql -c "CREATE USER gameuser WITH PASSWORD 'password' SUPERUSER;"
echo "Go to $SCRIPT_DIR"
cd "$SCRIPT_DIR" || exit
echo "Copy config to build folder ..."
rsync -a --delete config/ build/config/
echo "Copy dbschema to build folder ..."
rsync -a --delete dbschema/ build/dbschema/