-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·275 lines (242 loc) · 7 KB
/
build.sh
File metadata and controls
executable file
·275 lines (242 loc) · 7 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
# Media Deduplication Server Build Script
# This script automates the build process for the server
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check dependencies
check_dependencies() {
print_status "Checking build dependencies..."
local missing_deps=()
if ! command_exists cmake; then
missing_deps+=("cmake")
fi
if ! command_exists make; then
missing_deps+=("make")
fi
if ! command_exists pkg-config; then
missing_deps+=("pkg-config")
fi
# Check for Poco libraries
if ! pkg-config --exists Poco; then
# On macOS, check if Poco is installed via Homebrew
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -d "/opt/homebrew/include/Poco" ] || [ -d "/usr/local/include/Poco" ]; then
print_status "Poco libraries found via Homebrew (macOS)"
else
missing_deps+=("poco")
fi
else
missing_deps+=("libpoco-dev")
fi
fi
# Check for SQLite3
if ! pkg-config --exists sqlite3; then
missing_deps+=("libsqlite3-dev")
fi
# Check for yaml-cpp
if ! pkg-config --exists yaml-cpp; then
missing_deps+=("libyaml-cpp-dev")
fi
if [ ${#missing_deps[@]} -ne 0 ]; then
print_error "Missing dependencies: ${missing_deps[*]}"
print_status "Please install the missing dependencies:"
echo "Ubuntu/Debian: sudo apt install ${missing_deps[*]}"
echo "macOS: brew install ${missing_deps[*]}"
echo "CentOS/RHEL: sudo yum install ${missing_deps[*]}"
exit 1
fi
print_success "All dependencies are available"
}
# Function to clean build artifacts
clean_build() {
if [ "$CLEAN" = "true" ]; then
print_status "Cleaning old build artifacts..."
if [ -d "build" ]; then
# Remove only specific artifacts to avoid deleting external dependencies
rm -rf build/CMakeFiles
rm -rf build/bin
rm -rf build/lib
rm -rf build/src
rm -rf build/tests
rm -f build/CMakeCache.txt
rm -f build/cmake_install.cmake
rm -f build/Makefile
rm -f build/compile_commands.json
print_success "Build artifacts cleaned"
else
print_status "No build directory to clean"
fi
fi
}
# Function to create build directory
create_build_dir() {
print_status "Ensuring build directory exists..."
mkdir -p build
print_success "Build directory ready"
}
# Function to configure with CMake
configure_project() {
print_status "Configuring project with CMake..."
local cmake_args=(
"-DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Release}"
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
)
if [ "$BUILD_TYPE" = "Debug" ]; then
cmake_args+=("-DCMAKE_BUILD_TYPE=Debug")
cmake_args+=("-DCMAKE_CXX_FLAGS_DEBUG=-g -O0 -Wall -Wextra")
fi
if [ -n "$INSTALL_PREFIX" ]; then
cmake_args+=("-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX")
fi
cmake -S . -B build "${cmake_args[@]}"
print_success "CMake configuration completed"
}
# Function to build the project
build_project() {
print_status "Building project..."
local cores=1
if command_exists nproc; then
cores=$(nproc)
elif [[ "$OSTYPE" == "darwin"* ]]; then
cores=$(sysctl -n hw.ncpu)
fi
cmake --build build -j"$cores"
print_success "Build completed successfully"
}
# Function to run tests
run_tests() {
if [ "$RUN_TESTS" = "true" ]; then
print_status "Running tests..."
cd build
./bin/all_unit_tests
cd ..
print_success "Tests completed"
fi
}
# Function to install the project
install_project() {
if [ "$INSTALL" = "true" ]; then
print_status "Installing project..."
cd build
sudo make install
cd ..
print_success "Installation completed"
fi
}
# Function to show help
show_help() {
echo "Media Deduplication Server Build Script"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -d, --debug Build in debug mode"
echo " -t, --test Run tests after building"
echo " -i, --install Install after building"
echo " -p, --prefix PATH Set install prefix"
echo " -c, --clean Clean build directory before building"
echo " -v, --verbose Enable verbose output"
echo ""
echo "Examples:"
echo " $0 # Build in release mode"
echo " $0 --debug # Build in debug mode"
echo " $0 --test # Build and run tests"
echo ""
echo "Other scripts:"
echo " ./scripts/stopall # Stop all running server instances"
echo " ./scripts/show_endpoints # Show all available API endpoints"
echo " $0 --install # Build and install"
echo " $0 --debug --test # Build in debug mode and run tests"
}
# Parse command line arguments
BUILD_TYPE="Release"
RUN_TESTS="false"
INSTALL="false"
INSTALL_PREFIX=""
CLEAN="false"
VERBOSE="false"
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
exit 0
;;
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-t|--test)
RUN_TESTS="true"
shift
;;
-i|--install)
INSTALL="true"
shift
;;
-p|--prefix)
INSTALL_PREFIX="$2"
shift 2
;;
-c|--clean)
CLEAN="true"
shift
;;
-v|--verbose)
VERBOSE="true"
shift
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Enable verbose output if requested
if [ "$VERBOSE" = "true" ]; then
set -x
fi
# Main build process
main() {
print_status "Starting Media Deduplication Server build process..."
print_status "Build type: $BUILD_TYPE"
print_status "Clean build: $CLEAN"
print_status "Run tests: $RUN_TESTS"
print_status "Install: $INSTALL"
check_dependencies
clean_build
create_build_dir
configure_project
build_project
run_tests
install_project
print_success "Build process completed successfully!"
if [ -f "build/bin/media_dedup_server" ]; then
print_status "Executable location: build/bin/media_dedup_server"
fi
}
# Run main function
main "$@"