blob: 898e5b367cf282edaad97f60b949d82d4395bbc2 (
plain)
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
|
#!/bin/bash
# dodeps: find dependencies in busybox applets.
# v0.1
# Comments/ideas are welcome: wmertens@gentoo.org
[ ! -f Config.h ] && echo you need to run this from the main source && exit
if [ ! -f deps ]; then
cat <<EOF
This program will compile all applets with the BB_FEATURE definitions you gave.
Then, it will find the dependencies in them, and save them in the file "deps".
Then, it will calculate the applets you can activate with the same set of
function dependencies. It will also give an estimate of the added code size.
This can then be used to make more informed decisions about what you want in
the busybox.
If you don't like this, press ctrl-c now, otherwise press enter.
EOF
read a
# Compile everything
mv Config.h Config.h.orig
awk '{if ($0~/^\/\/#define BB_/ && $0!~/FEATURE/){print substr($0,3)}else{print}}' Config.h.orig > Config.h
make -j2
# Get dependencies and sizes
export CC=gcc
for i in `./busybox.sh Config.h|sed 's/\.c/.o/g'`; do echo -n ${i%%.o} \(`size $i|awk /$i'/{print $(NF-2)}'`\):\ ; nm -p $i|awk '$1=="U"{a[i++]=$2}END{n=asort(a);for(i=1;i<=n;i++){printf a[i] " "}}'; echo; done > deps
mv Config.h.orig Config.h
fi
# Calculate suggestions
my_apps=`gcc -E -dM Config.h | awk '{if ($0~/^#define BB_/ && $0!~/FEATURE/){if(t==1){printf "|"}; printf "^" tolower(substr($2,4)) " "; t=1}}'`
egrep "$my_apps" deps | awk '{for(i=3;i<=NF;i++){print $i}}'|sort -u > used_funcs
egrep -v "$my_apps" deps | awk '{for(i=3;i<=NF;i++){print $i}}'|sort -u > used_funcs_other
join -v2 used_funcs used_funcs_other > new_funcs
rm used_funcs used_funcs_other
# Show results
echo "These applets share the same functions (code sizes are estimates)"
egrep -v "$my_apps" deps | egrep -v -f new_funcs | sed 's/^\([^ ]*\) (\([0-9]*\)).*/\2\t\1/' | sort -n
echo
echo You can find the temporary results in:
echo deps: all dependencies, new_funcs: unused functions
echo If you run this script again, it will use the previous calculations,
echo instead of compiling all applets again.
|