#!/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 < 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.