-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·79 lines (66 loc) · 1.97 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
#!/bin/bash
function print_usage() {
echo -e "Build script commands: build.sh cmd [options]\n"
echo "Commands:"
echo -e "\tbuild: build for the current system architecture"
echo -e "\tclean: remove all build artifacts"
echo -e "\thelp: print this message"
echo "Options:"
echo -e "\t-noviz: build without OpenCV support, so no ability to visualize the network"
echo -e "\t-arm: build for ARM architecture"
echo -e "\t-rel: build release version (optimized)"
}
function build_command() {
mkdir -p build
pushd build > /dev/null
rm -rf CMake* cmake* *.so Make* test
echo "Build command: '${1}'"
${1}
local num_cores=$(cat /proc/cpuinfo | grep processor | wc -l)
echo "Building with ${num_cores} threads..."
make -j${num_cores}
popd > /dev/null
}
# Do not echo in this function anything besides the final string
function make_build_string() {
declare -A options=(["-arm"]="-DCMAKE_TOOLCHAIN_FILE=../pi.cmake"
["-noviz"]="-DNO_OPENCV:bool=true"
["-rel"]="-DCMAKE_BUILD_TYPE=Release");
declare -A dups;
local build_string="";
for option in "${@}";do
if ! test "${dups[${option}]+isset}";then
dups[${option}]="isset";
else
continue
fi
dups["${option}"]="already_exists";
if test "${options[${option}]+isset}";then
build_string+=${options[${option}]};
build_string+=" ";
fi
done
echo "${build_string}";
}
function main() {
local cmd=${1};
shift;
case ${cmd} in
build)
local build_str=$(make_build_string $@)
build_str="cmake ${build_str} ..";
build_command "${build_str}"
;;
clean)
echo "Cleaning the build artifacts..."
rm -rf build
;;
help)
print_usage
;;
*)
print_usage
;;
esac
}
main $@