forked from opentibiabr/canary
-
Notifications
You must be signed in to change notification settings - Fork 2
/
recompile.sh
executable file
·118 lines (101 loc) · 2.48 KB
/
recompile.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
#!/bin/bash
set -euo pipefail
# Variáveis
VCPKG_PATH=${1:-"$HOME"}
VCPKG_PATH=$VCPKG_PATH/vcpkg/scripts/buildsystems/vcpkg.cmake
BUILD_TYPE=${2:-"linux-release"}
ARCHITECTURE=$(uname -m)
ARCHITECTUREVALUE=0
# Function to print information messages
info() {
echo -e "\033[1;34m[INFO]\033[0m $1"
}
# Function to check if a command is available
check_command() {
if ! command -v "$1" >/dev/null; then
echo "The command '$1' is not available. Please install it and try again."
exit 1
fi
}
check_architecture() {
if [[ $ARCHITECTURE == "aarch64"* ]]; then
info "its architecture is ARM"
ARCHITECTUREVALUE=1
else
info "its architecture is ARM $ARCHITECTURE"
fi
}
# Function to configure Canary
setup_canary() {
if [ -d "build" ]; then
cd build
else
mkdir -p build && cd build
info "Canary has already been configured, skipping this step..."
fi
}
# Function to build Canary
build_canary() {
info "Configuring Canary..."
if [[ $ARCHITECTUREVALUE == 1 ]]; then
export VCPKG_FORCE_SYSTEM_BINARIES=1
fi
cmake -DCMAKE_TOOLCHAIN_FILE="$VCPKG_PATH" .. --preset "$BUILD_TYPE" >cmake_log.txt 2>&1 || {
cat cmake_log.txt
return 1
}
info "Starting the build process..."
local total_steps=0
local progress=0
local build_status=0
global_beats=0
local temp_file="temp_global_beats.txt"
echo "0" >$temp_file
cmake --build "$BUILD_TYPE" 2>&1 > >(while IFS= read -r line; do
echo "$line" >>build_log.txt
if [[ $line =~ ^\[([0-9]+)/([0-9]+)\].* ]]; then
current_step=${BASH_REMATCH[1]}
total_steps=${BASH_REMATCH[2]}
progress=$((current_step * 100 / total_steps))
printf "\r\033[1;32m[INFO]\033[0m Progress build: [%3d%%]" $progress
echo "1" >$temp_file
fi
done) || build_status=1
global_beats=$(cat $temp_file)
rm $temp_file
if [[ $build_status -eq 0 ]]; then
if [[ $global_beats == 1 ]]; then
echo
fi
return 0
else
echo
cat build_log.txt
return 1
fi
}
# Function to move the generated executable
move_executable() {
local executable_name="canary"
cd ..
if [ -e "$executable_name" ]; then
info "Saving old build"
mv ./"$executable_name" ./"$executable_name".old
fi
info "Moving the generated executable to the canary folder directory..."
cp ./build/linux-release/bin/"$executable_name" ./"$executable_name"
info "Build completed successfully!"
}
# Main function
main() {
check_command "cmake"
check_architecture
setup_canary
if build_canary; then
move_executable
else
echo -e "\033[31m[ERROR]\033[0m Build failed..."
exit 1
fi
}
main