-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_build.sh
executable file
·110 lines (99 loc) · 2.67 KB
/
run_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
#!/bin/bash
set -e
###############################################################################
# Usage:
# - when -i is present, build and install into $install_dir
# - when -t is present, tar the intall dir into $tar_dir
# - when -e is present, extract from $tar_dir, and install to $install_dir
###############################################################################
usage()
{
echo ""
echo "Usage: $0 -n name [-e] [-t tar_dir] [-i install_dir] [-s 64bit|32bit]"
echo -e "\t-n project name to build"
echo -e "\t-s arch version, 64bit or 32bit, default 64bit"
echo -e "\t-t dir store/load tar file to/from"
echo -e "\t-r sysroot dir"
echo -e "\t-i dir to install"
exit 1
}
extract=false
sdk_arch=64bit
while getopts "n:t:i:s:r:eh" opt
do
case "$opt" in
n ) name="$OPTARG" ;;
t ) tar_dir="$OPTARG" ;;
i ) install_dir="$OPTARG" ;;
s ) sdk_arch="$OPTARG" ;;
r ) sysroot_dir="$OPTARG" ;;
e ) extract=true ;;
h ) usage ;;
esac
done
#
# check project name
#
if [ -z $name ] ; then
echo "name not present"
exit 1
fi
#
# if extract, extract and then finish
#
if [ "$extract" = true ] ; then
echo 'Extract'
if [ -z $install_dir ] || [ -z $tar_dir ] ; then
echo "$install_dir or $tar_dir not present"
exit 1
fi
mkdir -p ${install_dir}
tar -xhzf ${tar_dir}/${name}.tar.gz -C ${install_dir}
exit 0
fi
if [ "$sdk_arch" == "glibc_riscv64" ]; then
CFLAGS="${CFLAGS} -mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d"
elif [ "$sdk_arch" == "musl_riscv64" ]; then
CFLAGS="${CFLAGS} -mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d"
fi
#
# clean and create build dir and temp install_dir if needed
#
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
rm -rf $SCRIPT_DIR/build/${name}
mkdir -p $SCRIPT_DIR/build/${name}
BUILD_DIR=$SCRIPT_DIR/build/${name}
INSTALL_DIR=$install_dir
if [ -z $install_dir ] ; then
rm -rf $SCRIPT_DIR/install/${name}
mkdir -p $SCRIPT_DIR/install/${name}
INSTALL_DIR=$SCRIPT_DIR/install/${name}
fi
# build
BUILD_DIR=$BUILD_DIR \
INSTALL_DIR=$INSTALL_DIR \
SYSROOT_PATH=$sysroot_dir \
CFLAGS=${CFLAGS} \
SDK_ARCH=$sdk_arch \
$SCRIPT_DIR/build_${name}.sh
if [ "$name" = "opencv4.5" ] ; then
if [ -d $INSTALL_DIR/include/opencv4 ]; then
pushd $INSTALL_DIR
if [ -d include/opencv2 ]; then
rm -rf include/opencv2
fi
mv include/opencv4/opencv2/ include/
rmdir include/opencv4
popd
fi
fi
# tar install dir if $tar_dir is present
if [ ! -z "$tar_dir" ] ; then
if [ ! -e $tar_dir ] ; then
echo "$tar_dir not exist"
exit 1
fi
pushd $INSTALL_DIR
tar -czf $tar_dir/${name}.tar.gz *
popd
fi