-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamesman_install.sh
140 lines (118 loc) · 4.4 KB
/
gamesman_install.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
#!/bin/bash
# This script was modified from its original version generated by ChatGPT.
# Always run this script from the root project directory.
# Function to print an error and exit
error_exit() {
echo "Error: $1" 1>&2
exit 1
}
mkdir_if_not_exist() {
local dir_name="$1"
if [ -d "$dir_name" ]; then
echo "Directory '$dir_name' already exists."
else
mkdir "$dir_name" || error_exit "Failed to create directory '$dir_name'."
echo "Directory '$dir_name' created successfully."
fi
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to install dependencies on Debian/Ubuntu
install_debian() {
sudo apt update && sudo apt install -y git cmake zlib1g zlib1g-dev
}
# Function to install dependencies on RHEL/CentOS
install_rhel() {
sudo dnf update && sudo dnf install -y git cmake zlib zlib-devel
}
# Function to install dependencies on MacOS
install_macos() {
# Assuming Homebrew is installed
xcode-select --install
brew install git cmake zlib || error_exit "brew install failed"
}
# Check if running as root, abort if yes.
if [ "$(id -u)" -eq 0 ]; then
error_exit "Running the script as root is dangerous. Please rerun the script as normal user."
fi
# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
# Prompt the user for dependency installation.
read -p "Install dependencies (may require password for sudo on Linux) y/[N]? " response
# Default to 'N' if no response is given
response=${response:-N}
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
INSTALL_DEPENDENCIES=true
else
INSTALL_DEPENDENCIES=false
fi
# Install dependencies based on OS.
if [ "$INSTALL_DEPENDENCIES" = true ]; then
case "$OS" in
Linux*)
# Detect if using Debian/Ubuntu or RHEL/CentOS
if [ -f /etc/debian_version ]; then
install_debian || error_exit "Failed to install dependencies on Debian/Ubuntu."
elif [ -f /etc/redhat-release ]; then
install_rhel || error_exit "Failed to install dependencies on RHEL/CentOS."
else
error_exit "Unsupported Linux distribution."
fi
;;
Darwin*)
install_macos || error_exit "Failed to install dependencies on MacOS."
;;
*)
error_exit "Unsupported operating system."
;;
esac
else
echo "Skipping installation of dependencies."
fi
# Check for required commands
for cmd in git autoconf automake autoreconf cmake; do
command_exists "$cmd" || error_exit "command $cmd not found."
done
#################
# Library Setup #
#################
# Initialize submodules
git submodule update --init || error_exit "Failed to update git submodules"
# Prepare library build directory
mkdir_if_not_exist "lib-build"
cd lib-build || error_exit "Failed to change directory to lib-build"
# Build json-c
mkdir_if_not_exist "json-c"
cd json-c || error_exit "Failed to change directory to lib-build/json-c"
CMAKE_FLAGS="-DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=../../res -DCMAKE_BUILD_TYPE=Release"
cmake ../../lib/json-c/ $CMAKE_FLAGS || error_exit "CMake failed to configure json-c"
make -j || error_exit "json-c make failed"
make install -j || error_exit "json-c make install failed"
cd ../ || error_exit "Failed to change directory back to lib-build"
# Build xz
mkdir_if_not_exist "xz"
cd xz || error_exit "Failed to change directory to lib-build/xz"
cmake ../../lib/xz/ $CMAKE_FLAGS || error_exit "CMake failed to configure xz"
make -j || error_exit "xz make failed"
make install -j || error_exit "xz make install failed"
cd ../ || error_exit "Failed to change directory back to lib-build"
# Build lz4
mkdir_if_not_exist "lz4"
cd lz4 || error_exit "Failed to change directory to lib-build/lz4"
cmake ../../lib/lz4/build/cmake/ $CMAKE_FLAGS || error_exit "CMake failed to configure lz4"
make -j || error_exit "lz4 make failed"
make install -j || error_exit "lz4 make failed"
cd ../ || error_exit "Failed to change directory back to lib-build"
# Finalize library setup
cd ..
############################
# Build GamesmanOne Binary #
############################
mkdir_if_not_exist "build"
cd build || error_exit "Failed to change directory to build"
cmake -DCMAKE_BUILD_TYPE=Release .. || error_exit "CMake failed to configure GamesmanOne."
cd .. || error_exit "Failed to change directory back to the project root."
cmake --build build -- -j || error_exit "CMake failed to build GamesmanOne."