-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·288 lines (249 loc) · 7.09 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
usage()
{
echo "Usage: $0" \
"[-h arm-none-linux]" \
"[-p <PREFIX>]" \
"[-b <BUILD_DIR>]" \
"[-j 4]" \
"[-s build|trim|pack]" 1>&2
exit 1
}
while getopts ":h:p:b:j:s:" o; do
case "${o}" in
h) HOST=$OPTARG ;;
p) PREFIX=$OPTARG ;;
b) BUILD_DIR=$OPTARG ;;
j) JOBS=$OPTARG ;;
s) STAGE=$OPTARG ;;
V) VERSION=$OPTARG ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
SCRIPT_DIR=$(readlink -f $(dirname $0))
[ -z $HOST ] && HOST=arm-none-linux-gnueabi
[ -z $PREFIX ] && PREFIX=$SCRIPT_DIR/_install/$HOST
[ -z $BUILD_DIR ] && BUILD_DIR=$SCRIPT_DIR/build/$HOST
[ -z $JOBS ] && JOBS=4
[ -z $STAGE ] && STAGE=build
[ -z $VERSION ] && VERSION=`git tag |tail -n1`
export MAKE=make
export CC=$HOST-gcc
export CXX=$HOST-g++
export CPP=$HOST-cpp
export AS=$HOST-as
export LD=$HOST-ld
export STRIP=$HOST-strip
export C_INCLUDE_PATH=$PREFIX/include
export CPLUS_INCLUDE_PATH=$PREFIX/include
export LD_LIBRARY_PATH=$PREFIX/lib
RPATH='-Wl,-rpath,$$\ORIGIN:$$\ORIGIN/../lib'
mkdir -p $PREFIX/share/
echo "CPPFLAGS=-I$PREFIX/include LDFLAGS=-L$PREFIX/lib" > $PREFIX/share/config.site
do_build()
{
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Building $1\033[0m"
$*
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Finished $1\033[0m"
}
do_make()
{
local make_dir=$1
local make_jobs=$2
local make_opts=$3
if [ -z "$make_opts" ]; then
$MAKE -C $make_dir -j$make_jobs
else
$MAKE -C $make_dir -j$make_jobs "$make_opts"
fi
if [ ! $? -eq 0 ]; then
rm -rf $make_dir
echo -e "\033[31m($(date '+%Y-%m-%d %H:%M:%S')): Failed to make $1\033[0m"
exit 1
fi
if [[ ! $make_opts =~ 'install' ]]; then
$MAKE -C $make_dir install
fi
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Success to make $1\033[0m"
}
do_build_with_configure()
{
local name=$1
local config_opts=$2
local make_opts=$3
local build=$BUILD_DIR/$name
# Skip or start
if [ -e $build ]; then
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Skip $1\033[0m"
return
fi
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Start building $1\033[0m"
# autogen & configure
if [ ! -e $SCRIPT_DIR/$name/configure ]; then
pushd $SCRIPT_DIR/$name && ./autogen.sh && popd
fi
mkdir -p $build && pushd $build
$SCRIPT_DIR/$name/configure $config_opts
popd
if [ ! $? -eq 0 ]; then
rm -rf $build
echo -e "\033[31m($(date '+%Y-%m-%d %H:%M:%S')): Failed to configure $1\033[0m"
exit 1
fi
# make
do_make $build $JOBS "$make_opts"
}
do_build_with_cmake()
{
local name=$1
local config_opts=$2
local make_opts=$3
local build=$BUILD_DIR/$name
# Skip or start
if [ -e $build ]; then
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Skip $1\033[0m"
return
fi
echo -e "\033[32m($(date '+%Y-%m-%d %H:%M:%S')): Start building $1\033[0m"
# cmake
mkdir -p $build && pushd $build
cmake $SCRIPT_DIR/$name $config_opts
popd
if [ ! $? -eq 0 ]; then
rm -rf $build
echo -e "\033[31m($(date '+%Y-%m-%d %H:%M:%S')): Failed to configure $1\033[0m"
exit 1
fi
# make
do_make $build $JOBS "$make_opts"
}
do_patch()
{
local name=$1
pushd $SCRIPT_DIR/$name
git reset --hard HEAD
for item in $(ls $SCRIPT_DIR/patchs/$name); do
git apply $SCRIPT_DIR/patchs/$name/$item
done
popd
}
stage_build()
{
git submodule init
git submodule update
# zlib
do_build_with_cmake zlib "-DCMAKE_INSTALL_PREFIX=$PREFIX"
rm -f $PREFIX/lib/libz.so*
# elfutils
pushd elfutils && autoreconf -i -f && automake --add-missing && popd
do_patch elfutils
do_build_with_configure elfutils "--prefix=$PREFIX --host=${HOST} \
--enable-maintainer-mode --disable-textrelcheck"
# libunwind
do_build_with_configure libunwind \
"--prefix=$PREFIX --host=${HOST} --enable-shared=yes"
# binutils & gdb
do_patch binutils-gdb
do_build_with_configure binutils-gdb \
"--prefix=$PREFIX --host=$HOST" \
"CFLAGS=-g -O2 -DHAVE_FCNTL_H -DHAVE_LIMITS_H"
# systemtap
do_build_with_configure systemtap "--prefix=$PREFIX --host=${HOST} --without-avahi"
# strace
[ ! -e $BUILD_DIR/strace ] && cd strace && ./bootstrap && cd -
do_build_with_configure strace \
"--prefix=$PREFIX --host=${HOST} --enable-mpers=no"
# ltrace
do_build_with_configure ltrace "--prefix=$PREFIX --host=${HOST}"
# valgrind
do_build_with_configure valgrind \
"--prefix=$PREFIX --host=${HOST/arm/armv7}"
# gperftools
do_build_with_configure gperftools \
"--prefix=$PREFIX --host=${HOST} --enable-libunwind \
--disable-static --disable-debugalloc" \
"install-libLTLIBRARIES"
# heaptrack
pushd boost
echo "using gcc : arm : aarch64-linux-gnu-g++ ;" > boost/user-config.jam
./bootstrap.sh --prefix=$PREFIX
./b2 install -a -q \
--disable-icu \
--with-system \
--with-filesystem \
--with-iostreams \
--user-config=user-config.jam \
-s NO_ZLIB=0 \
-s NO_COMPRESSION=0 \
-s ZLIB_INCLUDE=$PREFIX/include \
-s ZLIB_LIBPATH=$PREFIX/lib \
-s ZLIB_BINARY=z \
-j $JOBS \
abi=aapcs address-model=64 architecture=arm \
binary-format=elf threading=multi toolset=gcc-arm
rm -rf $PREFIX/lib/libboost_*
popd
do_build_with_cmake heaptrack \
"-DCMAKE_INSTALL_PREFIX=$PREFIX -DHEAPTRACK_BUILD_PRINT=off \
-DHEAPTRACK_BUILD_GUI=off -DHEAPTRACK_BUILD_TRACK=on"
# tcpdump
do_build_with_configure libpcap \
"--prefix=$PREFIX --host=${HOST} --with-pcap=linux --enable-shared=no"
do_build_with_cmake tcpdump "-DCMAKE_INSTALL_PREFIX=$PREFIX"
}
stage_trim()
{
pushd $PREFIX
# Strip
find bin -mindepth 1 -type f -exec $STRIP -s {} \; 2>/dev/null
find lib -path lib/valgrind -name '*.so*' -type f -exec $STRIP -s {} \;
# Valgrind
find lib/valgrind/ -perm 0755 \
! -name '*core*' \
! -name '*memcheck*' \
! -name '*.a' \
-exec rm -f {} \;
popd
}
stage_pack()
{
pushd $PREFIX
find lib/ -maxdepth 1 -name '*.so*' -type f -exec chrpath -r '$ORIGIN/../lib' {} \;
tar --transform 'flags=r;s#^#edt/#' -czvf edt-$HOST-$VERSION.tar.gz \
lib/libdw*.so* \
lib/libelf*.so* \
lib/libunwind.so* \
lib/libtcmalloc.so* \
lib/libprofiler.so* \
lib/valgrind/*.so \
lib/valgrind/*-*-linux \
lib/valgrind/*.xml \
lib/heaptrack \
bin/nm \
bin/objdump \
bin/readelf \
bin/strip \
bin/strings \
bin/gdb* \
bin/dtrace\
bin/stap* \
bin/strace \
bin/ltrace \
bin/valgrind \
bin/vgdb \
bin/heaptrack \
sbin/tcpdump
popd
}
if [ "$STAGE" = build ]; then
stage_build
STAGE=trim
fi
if [ "$STAGE" = trim ]; then
stage_trim
STAGE=pack
fi
if [ "$STAGE" = pack ]; then
stage_pack
fi