-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathbuild_app.sh
113 lines (99 loc) · 2.97 KB
/
build_app.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
#!/bin/bash
source ./xbuild/sh/base_func.sh
declare -a CMD_LIST=("g++" "cmake" "make")
declare -a LIB_LIST=(uv net pcap) # be modified in function install_cmd_and_libs
declare -a INSTALLED_LIB_LIST=(libuv libnet libpcap) # be modified in function install_cmd_and_libs
OS=1 #linux by default
function install_cmd_and_libs {
local CMD="apt-get"
if which apt-get; then
INSTALLED_LIB_LIST=(libuv1-dev libnet-dev libpcap-dev)
CMD="apt-get"
elif which yum; then
INSTALLED_LIB_LIST=(libuv1-devel libnet-devel libpcap-devel)
CMD="yum"
elif which brew; then
INSTALLED_LIB_LIST=(libuv libnet libpcap) # macos
CMD="brew"
else
echo "You have to install ${CMD_LIST[@]} and libuv libnet libpcap manualy."
exit 1
fi
for i in "${CMD_LIST[@]}"
do
which ${i}
if [ $? -ne 0 ]; then
echo "install command $i"
eval "${CMD} install ${i}"
if [ $? -ne 0 ]; then
echo "failed to install $i"
exit
fi
else
echo "skip to install $i. already installed"
fi
done
for i in "${!INSTALLED_LIB_LIST[@]}"
do
local name4ck=${LIB_LIST[$i]}
local name4ins=${INSTALLED_LIB_LIST[$i]}
local ok=1
if [ ${OS} -eq 2 ]; then # linux library check
ldconfig -p |grep ${name4ck}
if [ $? -ne 0 ]; then
ok=0
fi
elif [ ${OS} -eq 1 ]; then # mac library check
ld "-l${name4ck}" > err.log 2>&1
local ret=$(cat err.log)
rm err.log
if [[ ${ret} == *"library not found for"* ]]; then
# if [[ *"library not found for"* == ${ret} ]]; then # wrong!!! cannot change order
echo "no library!!!"
ok=0
fi
else
echo "unsupported platform. You should build it manually."
exit 1
fi
if [ ${ok} -eq 0 ]; then
echo "install library ${name4ins}"
eval "${CMD} install ${name4ins}"
if [ $? -ne 0 ]; then
echo "failed to install $i"
exit $3
fi
else
echo "skip to install ${name4ins}. already installed"
fi
done
}
function run_build {
local TOP_DIR=$(pwd)
local DIR="${TOP_DIR}/build"
[[ -d ${DIR} ]] || mkdir ${DIR}
if [ $? -ne 0 ]; then
echo "failed to create directory ${DIR}"
exit 1
fi
cd ${DIR}
make clean
get_num_core
local num_core=$?
cmake ${TOP_DIR} -DRSOCK_RELEASE=1 && make "-j$num_core"
if [ $? -eq 0 ]; then
echo "build successful."
else
echo "build failed."
fi
}
function check_os {
get_os
OS=$?
if [ ${OS} -eq 0 ]; then
echo "Don't know what system you are using. You have to install ${CMD_LIST} ${INSTALLED_LIB_LIST} by your self"
fi
}
check_os
install_cmd_and_libs
run_build