busybox/size_single_applets.sh
<<
>>
Prefs
   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"
   9
  10# The list of all applet config symbols
  11test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
  12apps="`
  13grep ^IF_ include/applets.h \
  14| grep -v ^IF_FEATURE_ \
  15| sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
  16| sort | uniq
  17`"
  18
  19test $# = 0 && set -- $apps
  20
  21mintext=999999999
  22for 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
  33                echo "# New mintext from $app: $mintext"
  34        }
  35        eval "text_${app}=$text"
  36done
  37
  38for app; do
  39        b="busybox_${app}"
  40        test -f "$b" || continue
  41        eval "text=\$text_${app}"
  42        echo "# $app adds $((text-mintext))"
  43done
  44
  45grep ^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
  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'"
  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
  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)\""
  82        fi
  83        echo "/' -i $file"
  84done
  85