-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·134 lines (118 loc) · 3.62 KB
/
build.sh
File metadata and controls
executable file
·134 lines (118 loc) · 3.62 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
#!/bin/bash
# save original home directory path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Clone dependencies
mkdir -p thirdparty
cd thirdparty
git clone https://github.com/chriskohlhoff/asio.git
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
git clone https://github.com/nlohmann/json.git
git clone https://github.com/gabime/spdlog.git
git clone https://github.com/g-truc/glm.git
cd ..
# Install system dependencies
#sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
libpq-dev \
python3-dev \
libssl-dev \
zlib1g-dev \
postgresql-15 \
libglm-dev \
libasio-dev \
libspdlog-dev \
nlohmann-json3-dev
# Parse command line arguments
USE_CITUS=OFF
USE_SQLITE=OFF
ENABLE_ASAN=OFF
CLEAR_PREVIOUS=OFF
for arg in "$@"; do
case $arg in
--with-citus)
echo "Installing Citus extension..."
sudo apt-get install -y postgresql-15-citus-12
USE_CITUS=ON
;;
--with-sqlite)
echo "Installing SQLite3 development libraries..."
sudo apt-get install -y libsqlite3-dev
USE_SQLITE=ON
;;
--with-asan)
echo "Enabling AddressSanitizer and UndefinedBehaviorSanitizer"
ENABLE_ASAN=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"
# 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; 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/