-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
build.sh
executable file
·169 lines (139 loc) · 3.6 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
#!/bin/bash
set -x
#color code
C_RED="\033[31m"
C_GREEN="\033[32m"
C_END="\033[0m"
CMAKE_MIN_VERSION="3.18"
TAR_MIN_VERSION="1.26"
BUILD_DIR=output
CLEAN_BUILD="false"
ARGS=()
for i in "$@"; do
case $i in
-c*|--clean*)
CLEAN_BUILD="true"
;;
-*|--*)
echo "Unknown option $i"
exit 1
;;
*)
ARGS=("${ARGS[@]}" $i)
;;
esac
done
if [ ! -f "/proc/cpuinfo" ];then
CPU_CORE=$(sysctl -n hw.ncpu)
else
CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l)
fi
if [ ${CPU_CORE} -eq 0 ]; then
CPU_CORE=1
fi
echo "cpu core ${CPU_CORE}"
if [[ "${CLEAN_BUILD}" = "true" ]]; then
rm -rf "${BUILD_DIR}" buildtrees deps pkg
fi
if [[ "${ARGS[0]}" = "clean" ]]; then
rm -rf "${BUILD_DIR}" buildtrees deps pkg
exit 0
fi
if [[ "${ARGS[0]}" = "codis" ]]; then
export GOPATH=${PWD}
export CGO_ENABLED=1
pushd codis
if [[ "${CLEAN_BUILD}" = "true" ]]; then
make -j ${CPU_CORE} clean
fi
make -j ${CPU_CORE} "${ARGS[@]:1}"
popd
exit 0
fi
source ./utils/Get_OS_Version.sh
function version_compare() {
if [[ "$1" == "$2" ]]; then
return 0
fi
if [[ "$(printf '%s\n' "$1" "$2" | sort -rV | head -n1)" == "$1" ]]; then
#local version less min version
echo -e "local ${C_GREEN} $3 ${C_END} version ${C_GREEN} $2 ${C_END} less min version ${C_GREEN} $1 ${C_END}"
exit 1
fi
}
function check_program() {
if ! type $1 >/dev/null 2>&1; then
# not find
echo -e "not find ${C_GREEN} $1 ${C_END} on localhost"
return 1
fi
return 0
}
function install_package() {
if [ $PM == "unknow" ]; then
echo -e "${C_RED} unknow package manager, please install $1 ${C_END}"
exit 1
fi
if [ ${PM} == "apt" ]; then
sudo ${PM} -y install $1
elif [ ${PM} == "brew" ]; then
${PM} install -d $1
else
sudo ${PM} install -y $1
fi
if [ $? -ne 0 ]; then
echo -e "${C_RED} install $1 fail, install autoconf before compiling ${C_END}"
exit 1;
fi
}
if ! check_program autoconf; then
# not find autoconf,do install
echo -e "not find ${C_GREEN} autoconf ${C_END} on localhost, now do install"
install_package autoconf
fi
if ! check_program tar; then
echo -e "not find ${C_GREEN} tar ${C_END} on localhost, please install and min version ${C_GREEN} ${TAR_MIN_VERSION} ${C_END}"
exit 1;
fi
if ! check_program cmake; then
if ! check_program cmake3; then
echo -e "not find ${C_GREEN} cmake ${C_END}, please install cmake and min version ${C_GREEN} ${CMAKE_MIN_VERSION} ${C_END}"
exit 1
else
CMAKE=cmake3
fi
else
CMAKE=cmake
fi
# get local cmake version
LOCAL_CMAKE_VERSION=`${CMAKE} --version |grep version |grep -o '[0-9.]\+'`
#compare cmake version
version_compare ${CMAKE_MIN_VERSION} ${LOCAL_CMAKE_VERSION} 'cmake'
# get local tar version
LOCAL_TAR_VERSION=`tar --version |head -n 1 |grep -o '[0-9.]\+'`
#compare tar version
version_compare ${TAR_MIN_VERSION} ${LOCAL_TAR_VERSION} 'tar'
if [ ! -d ${BUILD_DIR} ]; then
mkdir ${BUILD_DIR}
fi
cd ${BUILD_DIR}
use_pika_tools=""
if [[ "${ARGS[0]}" = "tools" ]]; then
use_pika_tools="-DUSE_PIKA_TOOLS=ON"
fi
with_command_docs=""
if [ "${WITH_COMMAND_DOCS}" = "ON" ]; then
with_command_docs="-DWITH_COMMAND_DOCS=ON"
fi
${CMAKE} ${use_pika_tools} ${with_command_docs} .. .
if [ $? -ne 0 ]; then
echo -e "${C_RED} cmake execution error ${C_END}"
exit 1
fi
make -j ${CPU_CORE}
if [ $? -eq 0 ]; then
echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}"
else
echo -e "${C_RED} pika compile fail ${C_END}"
exit 1
fi