-
Notifications
You must be signed in to change notification settings - Fork 0
/
CREATE
executable file
·433 lines (382 loc) · 17.9 KB
/
CREATE
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# Set to fail script if any command fails
set -e
# Color and style settings for enhanced output readability
if [[ "$OSTYPE" != "msys" && "$OSTYPE" != "win32" ]]; then
Esc=$(printf "\033")
ColourReset="${Esc}[m"
ColourBold="${Esc}[1m"
Red="${Esc}[31m"
Green="${Esc}[32m"
Yellow="${Esc}[33m"
Blue="${Esc}[34m"
Magenta="${Esc}[35m"
Cyan="${Esc}[36m"
White="${Esc}[37m"
BoldRed="${Esc}[1;31m"
BoldBlue="${Esc}[1;90m"
BoldGreen="${Esc}[1;32m"
Reset="${Esc}[0m" # ANSI code for reset
fi
# Function to display help information
function display_help() {
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}Usage: $(basename $0) [options]"
echo ""
echo "Options:"
echo " -r, --run Run the AIMM executable after building."
echo " --clean Clean the build directory before building."
echo " -v, --verbose Enable verbose output during the build."
echo " --install-dependencies Install required dependencies based on the OS."
echo " --debug Build the project in debug mode."
echo " --release Build the project in release mode."
echo " --compiler Specify the compiler (e.g., gcc or clang)."
echo " --force Force a full rebuild of the project."
echo " --flatbuffers-only Install the flatbuffer headers."
echo " --build-project Build only the project, no other executable."
echo " -h, --help Display this help message and exit."
echo ""
echo "This script configures and builds the project with optional configurations.${Reset}"
echo "${Yellow}================================================================================${Reset}"
exit 0
}
# Function to install dependencies on Linux
install_linux() {
# Update package list and upgrade packages
sudo apt-get update -y
sudo apt-get upgrade -y
# Install build-essential, cmake, git, and other dependencies
sudo apt-get install -y \
build-essential \
cmake \
git \
libopencv-dev \
gcc \
g++ \
clang \
lcov \
doxygen \
graphviz \
expect-dev \
libwayland-dev \
wayland-protocols \
libwayland-egl-backend-dev \
libxkbcommon-dev \
libegl1-mesa-dev \
xorg \
openbox \
libxrandr-dev \
libxinerama-dev \
libxcursor-dev \
libxi-dev \
python3.10 \
python3.10-dev \
# Install unbuffer (comes with expect-dev package)
sudo apt-get install -y expect-dev
# Install OpenCV (libopencv-dev)
sudo apt-get install -y libopencv-dev
# Install Doxygen and Graphviz for generating documentation
sudo apt-get install -y doxygen graphviz
# Install FlatBuffers (flatc)
FLATBUFFERS_VERSION=2.0.0
wget https://github.com/google/flatbuffers/archive/v${FLATBUFFERS_VERSION}.tar.gz
tar -xzf v${FLATBUFFERS_VERSION}.tar.gz
cd flatbuffers-${FLATBUFFERS_VERSION}
cmake -G "Unix Makefiles"
make
sudo make install
cd ..
rm -rf flatbuffers-${FLATBUFFERS_VERSION} v${FLATBUFFERS_VERSION}.tar.gz
# Verify installations
echo "${Yellow}================================================================================${Reset}"
# Verify installations
echo "${BoldBlue}[Install] Verifying installations...${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Unbuffer: $(which unbuffer)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} CMake: $(cmake --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Git: $(git --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} OpenCV: $(pkg-config --modversion opencv4)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} GCC: $(gcc --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} G++: $(g++ --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Clang: $(clang --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} LCOV: $(lcov --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Doxygen: $(doxygen --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Flatc: $(flatc --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Earthly: $(earthly --version)${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} All dependencies installed successfully on Linux!${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Remember to source ~/.zshrc and install the Docker Daemon!${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} https://docs.docker.com/get-docker/${Reset}"
echo "${Yellow}================================================================================${Reset}"
}
# Function to install dependencies on macOS
install_macos() {
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install] Installing...${Reset}"
echo "${Yellow}================================================================================${Reset}"
# Install Homebrew if not already installed
if ! command -v brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Install dependencies using Homebrew
brew install \
cmake \
git \
opencv \
gcc \
llvm \
lcov \
doxygen \
graphviz \
expect \
flatbuffers \
earthly
# Set up environment for clang-tidy
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib -L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"' >> ~/.zshrc
echo 'export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv/lib/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.zshrc
echo "export PKG_CONFIG_PATH=$OPENCV_PATH/lib/pkgconfig:\$PKG_CONFIG_PATH" >> ~/.zshrc
echo "${Yellow}================================================================================${Reset}"
# Verify installations
echo "${BoldBlue}[Install] Verifying installations...${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Unbuffer: $(which unbuffer)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} CMake: $(cmake --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Git: $(git --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} OpenCV: $(pkg-config --modversion opencv4)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} GCC: $(gcc --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} G++: $(g++ --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Clang: $(clang --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} LCOV: $(lcov --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Doxygen: $(doxygen --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Flatc: $(flatc --version)${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Earthly: $(earthly --version)${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} All dependencies installed successfully on macOS!${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} Remember to source ~/.zshrc and install the Docker Daemon!${Reset}"
echo "${BoldBlue}[Install]${Reset}${Green} https://docs.docker.com/get-docker/${Reset}"
echo "${Yellow}================================================================================${Reset}"
}
# Function to detect the operating system
detect_os_for_install() {
OS="$(uname)"
case "$OS" in
Linux*) install_linux ;;
Darwin*) install_macos ;;
*) echo "Unsupported OS: $OS" ; exit 1 ;;
esac
}
# Function to compile FlatBuffers
compile_flatbuffers() {
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[FlatBuffers]${Reset} ${Green}Compiling serialization schemas...${Reset}"
flatc -c --gen-object-api --gen-mutable --reflect-names -o src/serialization/fbs_gen/ src/serialization/fbs/*.fbs
echo "${BoldBlue}[FlatBuffers]${Reset} ${Green}Compilation complete.${Reset}"
}
# Function to move compiled FlatBuffers to include directory
move_flatbuffers() {
echo "${BoldBlue}[FlatBuffers]${Reset} ${Green}Injecting compiled headers to include directory...${Reset}"
mv src/serialization/fbs_gen/* include/serialization/
echo "${BoldBlue}[FlatBuffers]${Reset} ${Green}Successfully injected headers!${Reset}"
}
# Function to clean generated FlatBuffer headers
clean_generated_flatbuffers() {
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Clean]${Reset} ${Green}Cleaning generated FlatBuffer headers from include directory...${Reset}"
local directory="include"
local pattern="*_generated.h"
# Check if the directory exists
if [ -d "$directory" ]; then
# Find and remove files matching the pattern
find "$directory" -name "$pattern" -type f -exec echo "${BoldBlue}[Clean] Removing: {}" \; -exec rm {} +
echo "${BoldBlue}[Clean]${Reset} ${Green}Generated headers cleaned successfully.${Reset}"
else
echo "${Red}================================================================================${Reset}"
echo "${Red}[Clean] Error: Directory $directory does not exist.${Reset}"
echo "${Red}================================================================================${Reset}"
fi
}
# Initial flag settings
VERBOSE=false
BUILD_TYPE="Release" # Default to Release unless specified otherwise
COMPILER=""
FORCE_REBUILD=false
INSTALL_AFTER_BUILD=false
FLATBUFFER_ONLY=falsed
FLATBUFFER=true
COMPILE_PROJECT=false
BUILD_PROJECT_EARTHLY=true
FLATBUFFER_CLEAN=false
HEADLESS=OFF
# Enhanced option parsing
while [[ "$#" -gt 0 ]]; do
case "$1" in
-r|--run) RUN_AIMM=true; shift ;;
--clean) CLEAN_BUILD=true; shift ;;
-v|--verbose) VERBOSE=true; shift ;;
--debug) BUILD_TYPE="Debug"; shift ;;
--release) BUILD_TYPE="Release"; shift ;;
--compiler) COMPILER=$2; shift 2 ;;
--force) FORCE_REBUILD=true; shift ;;
--install) INSTALL_AFTER_BUILD=true; shift ;;
--flatbuffers-only)
FLATBUFFER_ONLY=true
COMPILE_PROJECT=false
shift ;;
--flatbuffers-clean)
FLATBUFFER_CLEAN=true
shift ;;
--install-dependencies)
detect_os_for_install
exit 0
;;
--build-project)
COMPILE_PROJECT=true
BUILD_PROJECT_EARTHLY=false
shift ;;
-h|--help) display_help ;;
--headless) HEADLESS=ON; shift ;;
*) echo "${Yellow}================================================================================${Reset}\n${Red}Unknown option: $1${Reset}"; display_help; exit 1 ;;
esac
done
``
message="
${Yellow}================================================================================
${BoldBlue} ____ _____ ______ _ _____ ____ ____ ____ ____
${BoldBlue}|_ \\|_ _||_ _ \`. / \\ |_ _||_ \\ / _||_ \\ / _|
${BoldBlue} | \\ | | | | \`. \ ______ / _ \\ | | | \\/ | | \\/ |
${BoldBlue} | |\\ \\| | | | | ||______|/ ___ \\ | | | |\\ /| | | |\\ /| |
${BoldBlue} _| |_\\ |_ _| |_.' / _/ / \\ \\_ _| |_ _| |_\\/_| |_ _| |_\\/_| |_
${BoldBlue}|_____|\\____||______.' |____| |____||_____||_____||_____||_____||_____|
"
echo "$message"
echo "${Reset}${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Build] Running pre-build checks...${Reset}"
# Check for essential tools
essential_tools=("cmake" "gcc" "g++" "make" "flatc")
for tool in "${essential_tools[@]}"; do
if ! command -v $tool &> /dev/null; then
echo "${Red} [Check] Error: $tool is required but not installed.${Reset}"
# exit 1
fi
done
# Check for JAVA_HOME if needed
if [ -z "$JAVA_HOME" ]; then
echo "${Red}[Check] Error: JAVA_HOME is not set.${Reset}"
# exit 1
fi
# Ensure write permission in the build directory
if [ ! -w "build" ]; then
echo "${Red}[Check] Error: No write permission in the build directory.${Reset}"
# exit 1
fi
# Verify enough disk space (e.g., 1GB) in /tmp or build directory
required_space_mb=1000
available_space=$(df "/tmp" | tail -1 | awk '{print $4}')
if (( available_space < required_space_mb * 1024 )); then
echo "${Red}[Check] Error: Insufficient disk space in /tmp.${Reset}"
# exit 1
fi
# Network availability check (simple ping to a reliable host)
if ! ping -c 1 8.8.8.8 >/dev/null 2>&1; then
echo "${Red}[Check] Error: Network check failed. Please check your internet connection.${Reset}"
# exit 1
fi
# Check specific configuration file is present
# if [ ! -f "config/settings.yaml" ]; then
# echo "${Red}Error: Missing required configuration file: config/settings.yaml.${Reset}"
# exit 1
# fi
echo "${BoldBlue}[Build] Pre-build checks passed successfully.${Reset}"
# Clean build directory if requested
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Clean] Checking if build directory needs cleaning...${Reset}"
if [[ "$CLEAN_BUILD" == true ]]; then
read -p "${BoldBlue}Are you sure you want to remove the build directory? [y/N] ${Reset}" confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}Removing the build directory...${Reset}"
rm -rf build
else
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Clean] Clean build skipped by user input.${Reset}"
fi
else
echo "${BoldBlue}[Clean] No project clean requested. Skipping...${Reset}"
fi
# Build flatbuffers as requested
if [[ "$FLATBUFFER_CLEAN" == true ]]; then
clean_generated_flatbuffers
fi
# Build flatbuffers as requested
if [[ "$FLATBUFFER_ONLY" == true ]]; then
compile_flatbuffers
move_flatbuffers
else
compile_flatbuffers
move_flatbuffers
fi
# Determine the maximum number of CPU cores
NUM_CORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu)
# Conditionally configure and build the full project
if [[ "$COMPILE_PROJECT" == true ]]; then
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Build]${Reset} ${Green}Configuring with CMake...${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}********************************************************************************${Reset}"
cmake -S . -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DHEADLESS=$HEADLESS ${COMPILER:+-DCMAKE_CXX_COMPILER=$COMPILER} || { echo "CMake configuration failed"; exit 1; }
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Build]${Reset} ${Green}Building with CMake...${Reset}"
echo "${Yellow}================================================================================${Reset}"
if [[ "$FORCE_REBUILD" == true ]]; then
cmake --build build --clean-first --parallel $NUM_CORES "$@"
else
cmake --build build --parallel $NUM_CORES "$@"
fi
fi
if [[ "$BUILD_PROJECT_EARTHLY" == true ]]; then
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}[Build]${Reset} ${Green}Building with Earthly...${Reset}"
echo "${Yellow}================================================================================${Reset}"
echo "${BoldBlue}********************************************************************************${Reset}"
unbuffer earthly +build 2>&1 | while IFS= read -r line
do
# Direct substitution for targeted emojis
line=${line//🚀/} # Remove rocket emojis
line=${line//🔧/} # Remove wrench emojis
line=${line//⏫/} # Remove upgrade emojis
line=${line//🎁/} # Remove gift emojis
line=${line//🌍/} # Remove gift emojis
line=${line//✅/- } # Replace checkmark emoji with a dash
# Exclude specific lines by not echoing them
# Use regex matching or more inclusive patterns
if [[ "$line" =~ "Push Summary" ]] || \
[[ "$line" =~ "To enable pushing use earthly" ]]; then
continue # Skip the rest of the loop and do not echo this line
fi
# Filter out unwanted promotional message
if [[ "$line" != *"Reuse cache between CI runs with Earthly Satellites!"* ]]; then
echo "$line"
fi
done
fi
# Install if requested
if [[ "$INSTALL_AFTER_BUILD" == true ]]; then
echo "${Yellow}================================================================================${Reset}"
echo "${BlueBold}[Install] ${Green}Installing the project...${Reset}"
echo "${Yellow}================================================================================${Reset}"
cmake --install build
fi
# Run AIMM if requested
if [[ "$RUN_AIMM" == true ]]; then
if [[ -f "AIMM" ]]; then
./AIMM
else
echo "${Red}================================================================================${Reset}"
echo "${Red}[Run] Error: Executable AIMM not found in the current directory${Reset}"
echo "${Red}================================================================================${Reset}"
exit 1
fi
fi