[BusyBox] Dependencies script
Wout Mertens
wmertens at gentoo.org
Tue May 21 10:43:04 UTC 2002
Hi,
I made a silly little script that can help you decide on what to put in
your busybox executable. Just thought I'd share it with you.
The way it works is: You run it from within an unpacked source directory,
after tweaking Config.h to set the BB_FEATUREs that you want. Then it will
compile all applets and save the dependencies and codesizes.
Then, every time you run it, it will check the Config.h and tell you what
applets you can add that use the same functions as the one you are already
using, so the only addition would be the codesize of the applet.
It helped /me/ in choosing what to add, so it might help you :)
Maybe something for the scripts/ directory? I know it's not the world's
cleanest code, but it works :*)
Cheers,
Wout.
-------------- next part --------------
#!/bin/bash
# dodeps: find dependencies in busybox applets.
# v0.1
# Comments/ideas are welcome: wmertens at 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.
More information about the busybox
mailing list