Denys Vlasenko | 483405a | 2017-07-18 20:17:51 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 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" |
| 9 | |
Denys Vlasenko | 483405a | 2017-07-18 20:17:51 +0200 | [diff] [blame] | 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 |
| 17 | `" |
| 18 | |
Denys Vlasenko | 483405a | 2017-07-18 20:17:51 +0200 | [diff] [blame] | 19 | test $# = 0 && set -- $apps |
| 20 | |
| 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 |
| 30 | } |
| 31 | test $mintext -gt $text && { |
| 32 | mintext=$text |
Denys Vlasenko | 36495af | 2018-01-14 12:13:16 +0100 | [diff] [blame] | 33 | echo "# New mintext from $app: $mintext" |
Denys Vlasenko | 483405a | 2017-07-18 20:17:51 +0200 | [diff] [blame] | 34 | } |
| 35 | eval "text_${app}=$text" |
| 36 | done |
| 37 | |
| 38 | for app; do |
| 39 | b="busybox_${app}" |
| 40 | test -f "$b" || continue |
| 41 | eval "text=\$text_${app}" |
Denys Vlasenko | 36495af | 2018-01-14 12:13:16 +0100 | [diff] [blame] | 42 | echo "# $app adds $((text-mintext))" |
Denys Vlasenko | 483405a | 2017-07-18 20:17:51 +0200 | [diff] [blame] | 43 | done |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 44 | |
| 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 |
| 58 | |
Denys Vlasenko | df1ff10 | 2018-12-28 13:37:44 +0100 | [diff] [blame] | 59 | file=`grep -l "bool \"$name[\" ]" $(find -name '*.c') | xargs` |
Denys Vlasenko | 83e7e13 | 2018-12-28 13:03:48 +0100 | [diff] [blame] | 60 | # A few applets have their CONFIG items in Config.* files, not .c files: |
Denys Vlasenko | df1ff10 | 2018-12-28 13:37:44 +0100 | [diff] [blame] | 61 | test "$file" || file=`grep -l "bool \"$name[\" ]" $(find -name 'Config.*') | xargs` |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 62 | test "$file" || continue |
| 63 | #echo "FILE:'$file'" |
| 64 | |
| 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)) |
| 70 | |
Denys Vlasenko | 36495af | 2018-01-14 12:13:16 +0100 | [diff] [blame] | 71 | echo -n "sed 's/bool \"$name"'[" ](*[0-9tinykbytes .]*)*"*$/' |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 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)\"" |
| 82 | fi |
| 83 | echo "/' -i $file" |
| 84 | done |