forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarm.sh
executable file
·307 lines (268 loc) · 6.54 KB
/
farm.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/sh
# Build script for radare2 - pancake<nopcode.org>
[ -z "${MAKEFLAGS}" ] && MAKEFLAGS="-j4"
[ -z "${MAKE}" ] && MAKE=make
[ -z "${NAME}" ] && NAME=radare2
[ -z "${DIR}" ] && DIR=radare2.build
[ -z "${URL}" ] && URL=http://github.com/radare/${NAME}
PYTHON=python2
WD=${PWD}/${DIR}
NOW=$(date +%Y%m%d-%H%M%S)
if [ -z "$1" ]; then
LOGFILE=${WD}/build.log.${NOW}
else
LOGFILE="$1"
fi
PREFIX=/usr
DESTDIR=${WD}/prefix
DONTFIND=""
CONFIGUREFLAGS="--prefix=${PREFIX}"
DOLOG="2>&1 | tee -a ${LOGFILE}" # verbose build
DOLOG="2>&1 | tee -a ${LOGFILE} > /dev/null"
testcc() {
eval type $1 > /dev/null 2>&1
if [ $? = 0 ]; then
log "[==] Found $1"
cc=$1
else
log "[==] Cannot find $1"
fi
}
log() {
echo $* ; echo $* >> ${LOGFILE}
}
logchk() {
if [ $1 = 0 ]; then
log "[==] RESULT: ok"
else
log "[==] RESULT: Shit happens"
fi
}
logcmd() {
eval "( $* ; logchk $? ) ${DOLOG}"
}
r2uninstall() {
cd radare2
make uninstall DESTDIR=${DESTDIR}
}
installdeps() {
VALA=vala-0.18.0
echo "I am going to install ${VALA} and valabind..."
sleep 2
wget -c http://download.gnome.org/sources/vala/0.9/${VALA}.tar.bz2
tar xjvf ${VALA}.tar.bz2
cd ${VALA}
./configure --prefix=/usr
make
make install
cd ..
echo ${VALA} > ${WD}/version.vala
type swig > /dev/null 2>&1
if [ $? = 1 ]; then
# TODO: install swig from svn!
echo "Cannot find 'swig'. apt-get install swig or get it from svn"
echo "svn co https://swig.svn.sourceforge.net/svnroot/swig/trunk swig"
else
if [ -d valabind ]; then
cd valabind
git reset --hard
git clean -xdf
git pull
else
git clone http://github.com/radare/valabind
cd valabind
fi
chmod +x configure
./configure --prefix=/usr
${MAKE} ${MAKEFLAGS}
${MAKE} install DESTDIR=${DESTDIR}
cd ..
fi
}
uninstalldeps() {
VALA=`cat ${WD}/version.vala`
cd ${VALA}
${MAKE} uninstall DESTDIR=${DESTDIR}
cd ..
rm -rf ${VALA} ${VALA}.tar.bz2
cd valabind
${MAKE} uninstall DESTDIR=${DESTDIR}
}
mkdir -p ${DIR}
cd ${DIR}
# TODO: clean spaguettis
case "$1" in
"-i")
if [ -z "$2" ]; then
echo "Usage: build.sh -i [path]"
exit 1
fi
DONTFIND=1
DESTDIR="$2"
;;
"-I")
if [ -z "$2" ]; then
echo "Usage: build.sh -I [path]"
exit 1
fi
DESTDIR="$2"
r2uninstall
exit 0
;;
"-d")
if [ -z "$2" ]; then
echo "Usage: build.sh -d [path]"
exit 1
fi
DESTDIR="$2"
installdeps
exit 0
;;
"-D")
if [ -z "$2" ]; then
echo "Usage: build.sh -D [path]"
exit 1
fi
DESTDIR="$2"
uninstalldeps
exit 0
;;
"-c")
rm -f ${WD}/build.*
rm -rf ${WD}/prefix
rm -rf ${WD}/vala*
;;
"-h")
cat<<EOF
Usage: build.sh [logfile|-option]
-i [destdir] install r2
-I [destdir] uninstall r2
-c clean build directory
-d [destdir] compile and install dependencies
-D [destdir] uninstall dependencies
-h show this help
Dependencies:
vala http://live.gnome.org/Vala
swig http://www.swig.org/
valabind http://github.com/radare/valabind
Examples:
sys/farm.sh do the build and generate log
sudo sys/farm.sh -i / install system-wide (/+/usr)
sudo sys/farm.sh -I uninstall
sudo sys/farm.sh -d / install dependencies system-wide
sys/farm.sh -d ~/prefix install dependencies in home
sudo sys/farm.sh -c clean build directory
rm -rf radare2.build remove build directory
EOF
exit 0
;;
esac
log "[==] Logging ${LOGFILE}"
:> ${LOGFILE}
ln -fs ${LOGFILE} ${WD}/build.log
log "[==] Retrieving system information"
date >> ${LOGFILE}
uname -a >> ${LOGFILE}
cat /proc/cpuinfo >> ${LOGFILE}
type git > /dev/null 2>&1
if [ ! $? = 0 ]; then
cat <<EOF
Cannot find 'git'.
EOF
exit 1
fi
log "[==] Working directory: $WD/$DIR"
if [ -d "${NAME}" ]; then
log "[==] Cleaning up old build directory..."
cd ${NAME}
git clean -xdf
git reset --hard
log "[==] Updating repository to HEAD..."
logcmd hg revert -a
logcmd hg pull -u
else
log "[==] Checking out from ${URL}..."
git clone ${URL} 2>&1 | tee -a ${LOGFILE}
cd ${NAME}
fi
if [ -e "config-user.mk" ]; then
log "[==] Running clean and mrproper..."
${MAKE} clean > /dev/null 2>&1
${MAKE} mrproper > /dev/null 2>&1
fi
log "[==] Running configure..."
logcmd time ./configure ${CONFIGUREFLAGS}
log "[==] Running make ${MAKEFLAGS}"
logcmd time ${MAKE} ${MAKEFLAGS}
log "[==] Symbolic installation... "
${MAKE} symstall DESTDIR="${DESTDIR}" > /dev/null 2>&1
if [ -z "${DONTFIND}" ]; then
log "[==] List of symbollically installed files"
logcmd "(cd ${DESTDIR} && find *)"
fi
log "[==] Running some tests..."
export PATH=${DESTDIR}/${PREFIX}/bin:$PATH
export PKG_CONFIG_PATH=${DESTDIR}/${PREFIX}/lib/pkgconfig
export LD_LIBRARY_PATH=${DESTDIR}/${PREFIX}/lib
logcmd type r2
logcmd type rasm2
logcmd type rabin2
logcmd radare2 -V
if [ -z "${DONTFIND}" ]; then
log "[==] List of installed files"
logcmd "(cd ${DESTDIR} && find *)"
log "[==] Uninstalling.."
logcmd time ${MAKE} uninstall DESTDIR="${DESTDIR}"
log "[==] List of residual files"
logcmd "(cd ${DESTDIR} && find *)"
fi
log "[==] Installing in ${PREFIX}"
logcmd time ${MAKE} install DESTDIR="${DESTDIR}"
log "[==] Configuring valabind bindings..."
cd swig
logcmd time ./configure --prefix=${PREFIX}
log "[==] Compiling swig/..."
logcmd time ${MAKE} ${MAKEFLAGS}
log "[==] Installing valabind bindings..."
logcmd time ${MAKE} install DESTDIR=${DESTDIR}
log "[==] Testing bindings.."
export PYTHONPATH=${DESTDIR}/${PREFIX}/lib/python2.5/site-packages/
logcmd ${PYTHON} -c "'from r2.r_util import *;b=RBuffer()'"
logcmd ${PYTHON} -c "'from r2.r_asm import *;a=RAsm()'"
logcmd ${PYTHON} -c "'from r2.r_core import *;c=RCore()'"
# TODO. add more tests here
# back to root dir
cd ..
log "[==] Looking for mingw32 crosscompilers.."
cc=""
for a in i486-mingw32-gcc i586-mingw32msvc-gcc ; do
testcc $a
[ -n "$cc" ] && break
done
if [ -n "$cc" ]; then
log "[==] mingw32 build using $cc"
if [ -e "config-user.mk" ]; then
${MAKE} clean > /dev/null 2>&1
${MAKE} mrproper >/dev/null 2>&1
fi
rm -f *.zip
log "[==] mingw32 configure"
logcmd ./configure --without-gmp --with-ostype=windows --with-compiler=$cc --host=i586-unknown-windows
log "[==] mingw32 make"
logcmd ${MAKE} ${MAKEFLAGS}
log "[==] mingw32 w32dist"
logcmd ${MAKE} w32dist
cp radare2-w32*.zip ${WD}
# build bindings
cd swig
log "[==] mingw32 swig: configure"
logcmd ./configure --without-gmp --with-ostype=windows --with-compiler=$cc --host=i586-unknown-windows
log "[==] mingw32 swig: make"
logcmd ${MAKE} ${MAKEFLAGS} w32
log "[==] mingw32 swig: w32dist"
logcmd ${MAKE} w32dist
cd ..
else
log "[==] Cannot find any compatible w32 crosscompiler. Report if not true"
fi
echo "[==] Please report ${LOGFILE}"