-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
242 lines (204 loc) · 6.51 KB
/
build.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
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
#!/bin/bash
function check_cmake {
if ! command -v cmake &> /dev/null
then
echo "CMake not found. Please install CMake and make sure it is in the PATH."
exit 1
fi
}
function init_environment {
LOCAL_CONFIG="$PWD/env_cfg.bat"
if [ -f "$LOCAL_CONFIG" ]; then
source "$LOCAL_CONFIG"
else
echo "set \"QTDIR_LINUX=/usr/local/Qt5.15.13\"" >> "$LOCAL_CONFIG"
echo "set \"BOOST_DIR_LINUX=/home/user/devtools/boost_1_81_0\"" >> "$LOCAL_CONFIG"
echo "Please configure dependency paths in \"$LOCAL_CONFIG\" first!"
read -p "Press enter to continue"
exit 1
fi
if [ $? -ne 0 ]; then exit $?; fi
read_env_cfg
export CONFIG="release"
export IPPONBOARD_ROOT_DIR="$PWD"
export QTDIR="$LINUX_QTDIR"
export BOOST_DIR="$LINUX_BOOST_DIR"
export BUILD_DIR="$IPPONBOARD_ROOT_DIR/_build/Ipponboard-Linux"
export BIN_DIR="$IPPONBOARD_ROOT_DIR/_bin/Ipponboard-$CONFIG"
export TEST_BIN_DIR="$IPPONBOARD_ROOT_DIR/_bin/Test-$CONFIG"
export OUTPUT_DIR="$IPPONBOARD_ROOT_DIR/_output"
}
function read_env_cfg {
while IFS='=' read -r key value
do
export $key="$value"
done < <(grep -o 'set ".*=.*"' ./env_cfg.bat | sed 's/set "//g' | sed 's/"//g')
}
function show_menu {
clear
echo "
Current config ($CONFIG):
QTDIR : $QTDIR
BOOST_DIR : $BOOST_DIR
ROOT_DIR : $IPPONBOARD_ROOT_DIR
BUILD_DIR : $BUILD_DIR
BIN_DIR : $BIN_DIR
Select build mode:
(1) clean ALL
(2) create makefiles
(3) tests only
(4) build all
(5) run Ipponboard
(6) build doc
(7) translate resources
(8) make archive
(9) clean build; make archive (release only)
(s) switch debug/release
(q) quit
"
}
function execute_and_measure {
local function=$1
start_time=$(date +%s)
$function
end_time=$(date +%s)
elapsed_time=$(expr $end_time - $start_time)
echo "Elapsed time: $elapsed_time seconds"
read -p "Press enter to continue"
}
function main_loop {
init_environment
while true; do
show_menu
read -n 1 -s choice
case $choice in
'1') execute_and_measure clean_all ;;
'2') execute_and_measure create_makefiles ;;
'3') execute_and_measure build_and_run_tests ;;
'4') execute_and_measure build_all ;;
'5') execute_and_measure run ;;
'6') execute_and_measure build_doc ;;
'7') execute_and_measure translate_resources ;;
'8') execute_and_measure make_archive ;;
'9') execute_and_measure clean_build_with_archive ;;
's') switch_config ;;
'q') break ;;
*) echo "Invalid choice" ;;
esac
done
}
function clean_all {
# remove _bin and _build directories
dirs=("$IPPONBOARD_ROOT_DIR/_bin" "$IPPONBOARD_ROOT_DIR/_build" "$OUTPUT_DIR")
for item in "${dirs[@]}"; do
echo "Removing $item"
if [ -d "$item" ]; then
rm -rf "$item"
fi
done
echo "Removing versioninfo.h"
rm -f "$IPPONBOARD_ROOT_DIR/base/versioninfo.h"
}
function create_makefiles {
./scripts/create-versioninfo.sh "$IPPONBOARD_ROOT_DIR/base" || return 1
cmake -S $PWD -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=$CONFIG -G "Unix Makefiles" --fresh
return $?
}
function run_tests {
exe="$TEST_BIN_DIR/IpponboardTest"
if [ ! -f "$exe" ]; then
echo "Test app not found: $exe"
return 1
fi
pushd "$TEST_BIN_DIR" > /dev/null
"./IpponboardTest"
success=$?
popd > /dev/null
return $success
}
function build_and_run_tests {
NUM_CORES=$(nproc)
cmake --build "$BUILD_DIR" --config $CONFIG --target IpponboardTest -j"$NUM_CORES" || return 1
run_tests
return $?
}
function build_all {
NUM_CORES=$(nproc)
cmake --build "$BUILD_DIR" --config $CONFIG -j"$NUM_CORES" || return 1
run_tests || return $?
build_doc || return $?
return 0
}
function run {
exe="$BIN_DIR/Ipponboard"
if [ ! -f "$exe" ]; then
echo "App not found: $exe"
return 1
fi
pushd "$BIN_DIR" > /dev/null
"./Ipponboard"
success=$?
popd > /dev/null
return $success
}
function build_doc {
if ! command -v pandoc &> /dev/null; then
echo "ERROR: Pandoc not found!"
echo "Pandoc is required to build the html help. Please install pandoc and make sure it is in the PATH."
return 1
fi
echo "Creating Docs..."
BASE_DIR="$IPPONBOARD_ROOT_DIR/doc"
pandoc -s "$BASE_DIR/USER_MANUAL-DE.md" -o "$BIN_DIR/Anleitung.html" --metadata=title:Anleitung --css="$BASE_DIR/Ipponboard.css" --resource-path="$BASE_DIR" --self-contained || return $?
pandoc -s "$BASE_DIR/USER_MANUAL-EN.md" -o "$BIN_DIR/User-Manual.html" --metadata=title:"User Manual" --css="$BASE_DIR/Ipponboard.css" --resource-path="$BASE_DIR" --self-contained || return $?
pandoc -s "CHANGELOG.md" -o "$BIN_DIR/CHANGELOG.html" --css="$BASE_DIR/Ipponboard.css" --self-contained || return $?
echo "Copying license files..."
cp -r "$BASE_DIR/licenses" "$BIN_DIR/licenses" || return $?
echo "done."
return 0
}
function translate_resources {
echo "not iplemented yet"
read -p "Press enter to continue"
mkdir -p "$BIN_DIR/lang"
"$QTDIR/bin/lrelease" -compress "$PWD/i18n/de.ts" -qm "$BIN_DIR/lang/de.qm" || return $?
"$QTDIR/bin/lrelease" -compress "$PWD/i18n/nl.ts" -qm "$BIN_DIR/lang/nl.qm" || return $?
return 0
}
function make_archive {
ARCH=$(uname -m)
SYSTEM=$(uname -s)
RELEASE=$(uname -r)
# Ipponboard-Release-Linux-x86_64-5.15.153.1-microsoft-standard-WSL2
ARCHIVE_NAME="$OUTPUT_DIR/Ipponboard-$SYSTEM-$ARCH-$RELEASE-$CONFIG.7z"
if [ -f "$ARCHIVE_NAME" ]; then
rm "$ARCHIVE_NAME"
fi
echo "Creating archive $ARCHIVE_NAME"
7z a "$ARCHIVE_NAME" "$BIN_DIR/*" -bso0 -bsp1 || return $?
ARCHIVESIZE=$(du -b "$ARCHIVE_NAME" | awk '{print $1}')
echo "Archive created with $ARCHIVESIZE bytes"
return $?
}
function clean_build_with_archive {
if [ "$CONFIG" != "release" ]; then
switch_config
fi
clean_all || return $?
create_makefiles || return $?
build_all || return $?
make_archive || return $?
return 0
}
function switch_config {
if [ "$CONFIG" == "release" ]; then
export CONFIG="debug"
else
export CONFIG="release"
fi
export BIN_DIR="$IPPONBOARD_ROOT_DIR/_bin/Ipponboard-$CONFIG"
export TEST_BIN_DIR="$IPPONBOARD_ROOT_DIR/_bin/Test-$CONFIG"
}
# Main
check_cmake
main_loop