-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·95 lines (82 loc) · 2.52 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
#!/bin/bash
workdir=`pwd`
x86_64_build_dir="${workdir}/build/x86-64"
aarch64_build_dir="${workdir}/build/aarch64"
if [[ `uname` == "Linux" ]]; then
processor_num=`cat /proc/cpuinfo | grep processor | grep -v grep | wc -l`
elif [[ `uname` == "Darwin" ]]; then
processor_num=`sysctl machdep.cpu | grep machdep.cpu.core_count | cut -d " " -f 2`
else
processor_num=1
fi
build_type='Release'
options="-DCMAKE_BUILD_TYPE=${build_type}"
# --------------------------------------------------------------------------- #
function BuildX86_64() {
mkdir -p ${x86_64_build_dir}
cd ${x86_64_build_dir}
cmd="cmake $options -DTINYCV_USE_X86_64=ON -DCMAKE_INSTALL_PREFIX=${x86_64_build_dir}/install ../.. && cmake --build . -j ${processor_num} --config ${build_type} && cmake --build . --target install -j ${processor_num} --config ${build_type}"
echo "cmd -> $cmd"
eval "$cmd"
}
function BuildAarch64() {
arch=$(uname -m)
case "$arch" in
"x86_64")
extra_options="-DCMAKE_TOOLCHAIN_FILE=${workdir}/cmake/toolchains/aarch64-linux-gnu.cmake"
;;
"aarch64")
;;
*)
echo "unsupported arch -> $arch"
exit 1
;;
esac
mkdir ${aarch64_build_dir}
cd ${aarch64_build_dir}
cmd="cmake $options ${extra_options} -DTINYCV_USE_AARCH64=ON -DCMAKE_INSTALL_PREFIX=${aarch64_build_dir}/install .. && cmake --build . -j ${processor_num} --config ${build_type} && cmake --build . --target install -j ${processor_num} --config ${build_type}"
echo "cmd -> $cmd"
eval "$cmd"
}
declare -A engine2func=(
["x86_64"]=BuildX86_64
["aarch64"]=BuildAarch64
)
# --------------------------------------------------------------------------- #
function Usage() {
echo -n "[INFO] usage: $0 [ all"
for engine in ${!engine2func[@]}; do
echo -n " | $engine"
done
echo "] [cmake options]"
}
if [ $# -lt 1 ]; then
Usage
exit 1
fi
engine="$1"
shift
options="$options $*"
if [ "$engine" == "all" ]; then
for engine in "${!engine2func[@]}"; do
func=${engine2func[$engine]}
eval $func
if [ $? -ne 0 ]; then
echo "[ERROR] build [$engine] failed." >&2
exit 1
fi
done
else
func=${engine2func["$engine"]}
if ! [ -z "$func" ]; then
eval $func
if [ $? -ne 0 ]; then
echo "[ERROR] build [$engine] failed." >&2
exit 1
fi
else
echo "[ERROR] unknown engine name [$engine]" >&2
Usage
exit 1
fi
fi