-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·219 lines (191 loc) · 5.66 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
set -x -e
########################################
# download & build depend software
########################################
WORK_DIR=`pwd`
DEPS_SOURCE=`pwd`/thirdsrc
DEPS_PREFIX=`pwd`/thirdparty
DEPS_CONFIG="--prefix=${DEPS_PREFIX} --disable-shared --with-pic"
FLAG_DIR=`pwd`/.build
export PATH=${DEPS_PREFIX}/bin:$PATH
mkdir -p ${DEPS_SOURCE} ${DEPS_PREFIX} ${FLAG_DIR}
if [ ! -f "${FLAG_DIR}/dl_third" ] || [ ! -d "${DEPS_SOURCE}/.git" ]; then
rm -rf ${DEPS_SOURCE}
mkdir ${DEPS_SOURCE}
git clone https://github.com/yvxiang/thirdparty.git thirdsrc
touch "${FLAG_DIR}/dl_third"
fi
cd ${DEPS_SOURCE}
# boost
if [ ! -f "${FLAG_DIR}/boost_1_57_0" ] \
|| [ ! -d "${DEPS_PREFIX}/boost_1_57_0/boost" ]; then
if [ -e boost_1_57_0.tar.gz ]; then
rm boost_1_57_0.tar.gz
fi
wget --no-check-certificate https://raw.githubusercontent.com/lylei9/boost_1_57_0/master/boost_1_57_0.tar.gz
tar zxf boost_1_57_0.tar.gz
rm -rf ${DEPS_PREFIX}/boost_1_57_0
mv boost_1_57_0 ${DEPS_PREFIX}/boost_1_57_0
touch "${FLAG_DIR}/boost_1_57_0"
fi
# protobuf
if [ ! -f "${FLAG_DIR}/protobuf_2_6_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libprotobuf.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/google/protobuf" ]; then
cd protobuf-2.6.1
autoreconf -ivf
./configure ${DEPS_CONFIG}
make -j4
make install
cd -
touch "${FLAG_DIR}/protobuf_2_6_1"
fi
#leveldb
if [ ! -f "${FLAG_DIR}/leveldb" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libleveldb.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/leveldb" ]; then
rm -rf leveldb
git clone https://github.com/lylei/leveldb.git leveldb
cd leveldb
echo "PREFIX=${DEPS_PREFIX}" > config.mk
make -j4
make install
cd -
touch "${FLAG_DIR}/leveldb"
fi
# snappy
if [ ! -f "${FLAG_DIR}/snappy_1_1_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libsnappy.a" ] \
|| [ ! -f "${DEPS_PREFIX}/include/snappy.h" ]; then
cd snappy-1.1.1
autoreconf -ivf
./configure ${DEPS_CONFIG}
make -j4
make install
cd -
touch "${FLAG_DIR}/snappy_1_1_1"
fi
# sofa-pbrpc
if [ ! -f "${FLAG_DIR}/sofa-pbrpc" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libsofa-pbrpc.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/sofa/pbrpc" ]; then
rm -rf sofa-pbrpc
git clone --depth=1 https://github.com/baidu/sofa-pbrpc.git sofa-pbrpc
cd sofa-pbrpc
sed -i '/BOOST_HEADER_DIR=/ d' depends.mk
sed -i '/PROTOBUF_DIR=/ d' depends.mk
sed -i '/SNAPPY_DIR=/ d' depends.mk
echo "BOOST_HEADER_DIR=${DEPS_PREFIX}/boost_1_57_0" >> depends.mk
echo "PROTOBUF_DIR=${DEPS_PREFIX}" >> depends.mk
echo "SNAPPY_DIR=${DEPS_PREFIX}" >> depends.mk
echo "PREFIX=${DEPS_PREFIX}" >> depends.mk
make -j4
make install
cd -
touch "${FLAG_DIR}/sofa-pbrpc"
fi
# cmake for gflags
if ! which cmake ; then
cd CMake-3.2.1
./configure --prefix=${DEPS_PREFIX}
make -j4
make install
cd -
fi
# gflags
if [ ! -f "${FLAG_DIR}/gflags_2_1_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libgflags.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/gflags" ]; then
cd gflags-2.1.1
cmake -DCMAKE_INSTALL_PREFIX=${DEPS_PREFIX} -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC
make -j4
make install
cd -
touch "${FLAG_DIR}/gflags_2_1_1"
fi
# gtest
if [ ! -f "${FLAG_DIR}/gtest_1_7_0" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libgtest.a" ] \
|| [ ! -d "${DEPS_PREFIX}/include/gtest" ]; then
cd gtest-1.7.0
./configure ${DEPS_CONFIG}
make
cp -a lib/.libs/* ${DEPS_PREFIX}/lib
cp -a include/gtest ${DEPS_PREFIX}/include
cd -
touch "${FLAG_DIR}/gtest_1_7_0"
fi
# libunwind for gperftools
if [ ! -f "${FLAG_DIR}/libunwind_0_99" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libunwind.a" ] \
|| [ ! -f "${DEPS_PREFIX}/include/libunwind.h" ]; then
cd libunwind-0.99
./configure ${DEPS_CONFIG}
make CFLAGS=-fPIC -j4
make CFLAGS=-fPIC install
cd -
touch "${FLAG_DIR}/libunwind_0_99"
fi
# gperftools (tcmalloc)
if [ ! -f "${FLAG_DIR}/gperftools_2_2_1" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libtcmalloc_minimal.a" ]; then
cd gperftools-2.2.1
./configure ${DEPS_CONFIG} CPPFLAGS=-I${DEPS_PREFIX}/include LDFLAGS=-L${DEPS_PREFIX}/lib
make -j4
make install
cd -
touch "${FLAG_DIR}/gperftools_2_2_1"
fi
# test c++11
set +e
if test -z "$CXX"; then
CXX=g++
fi
$CXX --std=c++11 -x c++ - -o teststd.out 2>/dev/null <<EOF
int main() {}
EOF
if [ "$?" = 0 ]; then
STD_FLAG=c++11
fi
rm -rf teststd.out
set -e
# common
if [ ! -f "${FLAG_DIR}/common" ] \
|| [ ! -f "${DEPS_PREFIX}/lib/libcommon.a" ]; then
rm -rf common
git clone -b cpp11 https://github.com/baidu/common
cd common
sed -i 's/^PREFIX=.*/PREFIX=..\/..\/thirdparty/' config.mk
if test -z "$STD_FLAG"; then
sed -i 's/-std=c++11/-std=c++0x/g' Makefile
fi
make -j4
make install
cd -
touch "${FLAG_DIR}/common"
fi
cd ${WORK_DIR}
########################################
# config depengs.mk
########################################
echo "PBRPC_PATH=./thirdparty" > depends.mk
echo "PROTOBUF_PATH=./thirdparty" >> depends.mk
echo "PROTOC_PATH=./thirdparty/bin/" >> depends.mk
echo 'PROTOC=$(PROTOC_PATH)protoc' >> depends.mk
echo "PBRPC_PATH=./thirdparty" >> depends.mk
echo "BOOST_PATH=./thirdparty/boost_1_57_0" >> depends.mk
echo "GFLAG_PATH=./thirdparty" >> depends.mk
echo "GTEST_PATH=./thirdparty" >> depends.mk
echo "COMMON_PATH=./thirdparty" >> depends.mk
echo "TCMALLOC_PATH=./thirdparty" >> depends.mk
if test -z "$STD_FLAG"; then
echo "STD_FLAG=c++0x" >> depends.mk
else
echo "STD_FLAG=c++11" >> depends.mk
fi
########################################
# build tera
########################################
make clean
make -j4