forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-plugins
executable file
·265 lines (227 loc) · 5.79 KB
/
configure-plugins
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
#!/bin/sh
#
# Script to configure "staticability" of plugins
# author: pancake // nopcode
# update: 2010-01-14
#
LANG=C
LC_ALL=C
LOADLIBS=1
export LANG
export LC_ALL
list () {
for a in $STATIC ; do echo "static $a" ; done
for a in $SHARED ; do echo "shared $a" ; done
exit 0
}
help () {
echo "Usage: ./configure-plugins [options]"
echo " -n do nothing.. do not generate any file"
echo " --list list all static and shared plugins"
echo " --rm-static [dir] remove plugins that are already in core from dir"
echo " --static [name ..] define named plugin as static"
echo " --shared [name ..] define named plugin as shared"
echo " --help, -h display this helpful message"
echo "NOTE: static plugins are compiled inside the owner library"
exit 0
}
cfg=./plugins.cfg
if [ ! -f "$cfg" ]; then
cp -f dist/plugins-cfg/plugins.def.cfg plugins.cfg
fi
load () {
if [ -e $cfg ]; then
echo "configure-plugins: Loading $cfg .."
. $cfg
else
echo "configure-plugins: Loading $1 .."
. "$1"
fi
}
save () {
cp $cfg plugins.cfg
# echo "STATIC=\"$STATIC\"" > $cfg
# echo "SHARED=\"$SHARED\"" >>$cfg
}
generate_configh () {
plugins=""
oldlib=""
for a in ${STATIC} ; do
lib=$(echo $a | cut -d . -f 1) # library
plg=$(echo $a | cut -d . -f 2) # plugin name
if [ ! "$oldlib" = "$lib" ]; then
[ -n "$oldlib" ] && echo " 0"
oldlib=$lib
if type perl > /dev/null 2>&1 ; then
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
else
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
fi
echo
echo "#define R_${uclib}_STATIC_PLUGINS \\"
plugins="${plugins} __${uclib}"
fi
echo " &r_${lib}_plugin_${plg}, \\"
done
[ -n "$oldlib" ] && echo " 0"
# FILL EMPTY PLUGIN ARRAYS WITH LOVE
for a in ${SHARED} ; do
lib=$(echo $a | cut -d . -f 1) # library
plg=$(echo $a | cut -d . -f 2) # plugin name
if [ ! "$oldlib" = "$lib" ]; then
oldlib=$lib
if type perl > /dev/null 2>&1; then
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
else
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
fi
if [ -z "`echo ${plugins} | grep __${uclib}`" ]; then
plugins="${plugins} __${uclib}"
echo
echo "#define R_${uclib}_STATIC_PLUGINS 0"
fi
fi
done
}
generate_asmdinc() {
plugins=""
oldlib=""
for a in ${STATIC} ; do
lib=$(echo $a | cut -d . -f 1) # library
plg=$(echo $a | cut -d . -f 2) # plugin name
echo "(SdbGperf*)&gperf_${plg},"
done
}
generate_configmk () {
plugins=""
oldlib=""
for a in ${STATIC} ; do
lib=$(echo $a | cut -d . -f 1) # library
plg=$(echo $a | cut -d . -f 2) # plugin name
if [ ! "$oldlib" = "$lib" ]; then
[ -n "$oldlib" ] && printf "\n"
oldlib=$lib
if type perl > /dev/null 2>&1 ; then
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
else
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
fi
printf "STATIC_${uclib}_PLUGINS= "
plugins="${plugins} __${uclib}"
fi
printf "p/${plg}.mk "
done
echo
# fill the holes with love
for a in ${SHARED} ; do
lib=$(echo $a | cut -d . -f 1) # library
if type perl > /dev/null 2>&1 ; then
uclib=$(echo $lib | perl -pe 'tr/[a-z]/[A-Z]/')
else
uclib=$(echo $lib | tr '[a-z]' '[A-Z]')
fi
if [ -z "`echo ${plugins} | grep __${uclib}`" ]; then
plugins="${plugins} __${uclib}"
echo "STATIC_${uclib}_PLUGINS="
fi
done
}
generate () {
echo "configure-plugins: Generating libr/config.h"
cat libr/config.h.head > libr/config.h
echo "#define R2_LOADLIBS ${LOADLIBS}" >> libr/config.h
generate_configh >> libr/config.h
cat libr/config.h.tail >> libr/config.h
echo "configure-plugins: Generating libr/asm/d/config.inc"
generate_asmdinc >> libr/asm/d/config.inc
echo "configure-plugins: Generating libr/config.mk"
cat libr/config.mk.head > libr/config.mk
generate_configmk >> libr/config.mk
cat libr/config.mk.tail >> libr/config.mk
return
}
add () {
for a in $1 ; do [ $a = $2 ] && return ; done ; echo $1 $2
}
sub () {
n="" ; for a in $1 ; do [ $a = $2 ] && continue ; n="$n $a" ; done ; echo $n
}
echo | sort -t. > /dev/null 2>&1
if [ $? = 0 ]; then
SORT="sort -t."
else
SORT="sort"
fi
dosort () {
( for a in $1 ; do echo $a ; done ) | tr _ Z | ${SORT} | tr Z _
#( for a in $1 ; do echo $a ; done ) | sort -t. --key=1,1d
}
sort_vars () {
STATIC=$(dosort "$STATIC")
SHARED=$(dosort "$SHARED")
}
make_static () {
STATIC=$(add "$STATIC" $1)
SHARED=$(sub "$SHARED" $1)
}
make_shared () {
SHARED=$(add "$SHARED" $1)
STATIC=$(sub "$STATIC" $1)
}
make_ () { : ; }
MODE=""
DONOTHING=0
DEFCFG=dist/plugins-cfg/plugins.def.cfg
rmstatic() {
C=0
if [ -z "$1" ]; then
echo "Missing argument"
exit 1
fi
for a in ${STATIC} ; do
b="`echo $a | tr . _`"
for ext in dll dylib so ; do
f="$b.$ext"
if [ -f "$f" ]; then
C=$(($C+1))
printf " $C found\r"
#echo "rm -f $f"
rm -f "$f"
fi
done
done
echo "Removed $C shared plugins that are already static"
}
RMSTATIC=-
while : ; do
[ -z "$1" ] && break
case "$1" in
"--static") MODE=static ; ;;
"--shared") MODE=shared ; ;;
"--without-gpl") DEFCFG=./plugins.nogpl.cfg ;;
"--disable-loadlibs") LOADLIBS=0 ;;
"--rm-static") RMSTATIC="$2" ; ;;
"--list") sort_vars ; list ; ;;
"-n") DONOTHING=1 ; ;;
"-h"|"--help") help ; ;;
*) eval make_$MODE $1 ; ;;
esac
shift
done
load ${DEFCFG}
sort_vars
if [ - != "${RMSTATIC}" ]; then
if [ -z "${RMSTATIC}" ]; then
echo "Missing argument" >&2
exit
fi
if [ -d "${RMSTATIC}" ]; then
cd "${RMSTATIC}" && rmstatic "${RMSTATIC}"
fi
exit 0
fi
[ ${DONOTHING} = 0 ] && generate
echo SHARED: ${SHARED}
echo STATIC: ${STATIC}
save
exit 0