sed: check errors writing file with sed -i
[busybox-git.git] / size_single_applets.sh
blob4b70e761fc24357cdbf8dca30cc870d649a9d6c0
1 #!/bin/bash
2 # Which config to use when updating the sizes in "official"
3 # source tree? I am using x86 glibc toolchain of some typical distro,
4 # not-static build, 32-bit defconfig build:
5 # # CONFIG_STATIC is not set
6 # CONFIG_CROSS_COMPILER_PREFIX=""
7 # CONFIG_EXTRA_CFLAGS="-m32"
8 # CONFIG_EXTRA_LDFLAGS="-m32"
10 # The list of all applet config symbols
11 test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
12 apps="`
13 grep ^IF_ include/applets.h \
14 | grep -v ^IF_FEATURE_ \
15 | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
16 | sort | uniq
19 test $# = 0 && set -- $apps
21 mintext=999999999
22 for app; do
23 b="busybox_${app}"
24 test -f "$b" || continue
25 text=`size "$b" | tail -1 | sed -e's/\t/ /g' -e's/^ *//' -e's/ .*//'`
26 #echo "text from $app: $text"
27 test x"${text//[0123456789]/}" = x"" || {
28 echo "Can't get: size $b"
29 exit 1
31 test $mintext -gt $text && {
32 mintext=$text
33 echo "# New mintext from $app: $mintext"
35 eval "text_${app}=$text"
36 done
38 for app; do
39 b="busybox_${app}"
40 test -f "$b" || continue
41 eval "text=\$text_${app}"
42 echo "# $app adds $((text-mintext))"
43 done
45 grep ^IF_ include/applets.h \
46 | grep -v ^IF_FEATURE_ \
47 | sed 's/, .*//' \
48 | sed 's/\t//g' \
49 | sed 's/ //g' \
50 | sed 's/(APPLET(/(/' \
51 | sed 's/(APPLET_[A-Z]*(/(/' \
52 | sed 's/(IF_[A-Z_]*(/(/' \
53 | sed 's/IF_\([A-Z0-9._-]*\)(\(.*\)/\1 \2/' \
54 | sort | uniq \
55 | while read app name; do
56 b="busybox_${app}"
57 test -f "$b" || continue
59 file=`grep -l "bool \"$name[\" ]" $(find -name '*.c') | xargs`
60 # A few applets have their CONFIG items in Config.* files, not .c files:
61 test "$file" || file=`grep -l "bool \"$name[\" ]" $(find -name 'Config.*') | xargs`
62 test "$file" || continue
63 #echo "FILE:'$file'"
65 eval "text=\$text_${app}"
66 sz=$((text-mintext))
67 sz_kb=$((sz/1000))
68 sz_frac=$(( (sz - sz_kb*1000) ))
69 sz_f=$((sz_frac / 100))
71 echo -n "sed 's/bool \"$name"'[" ](*[0-9tinykbytes .]*)*"*$/'
72 if test "$sz_kb" -ge 10; then
73 echo -n "bool \"$name (${sz_kb} kb)\""
74 elif test "$sz_kb" -gt 0 -a "$sz_f" = 0; then
75 echo -n "bool \"$name (${sz_kb} kb)\""
76 elif test "$sz_kb" -gt 0; then
77 echo -n "bool \"$name ($sz_kb.${sz_f} kb)\""
78 elif test "$sz" -ge 200; then
79 echo -n "bool \"$name ($sz bytes)\""
80 else
81 echo -n "bool \"$name (tiny)\""
83 echo "/' -i $file"
84 done