make_single_applets.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # This script expects that the tree was built with the desired .config:
  3. # in particular, it expects that include/applets.h is generated already.
  4. #
  5. # The script will try to rebuild each enabled applet in isolation.
  6. # All other options which chose general bbox config, applet features, etc,
  7. # are not modified for the builds.
  8. makeopts="-j9"
  9. # The list of all applet config symbols
  10. test -f include/applets.h || { echo "No include/applets.h file"; exit 1; }
  11. apps="`
  12. grep ^IF_ include/applets.h \
  13. | grep -v '^IF_FEATURE_' \
  14. | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
  15. | grep -v '^BUSYBOX$' \
  16. | sort | uniq
  17. `"
  18. # Take existing config
  19. test -f .config || { echo "No .config file"; exit 1; }
  20. cfg="`cat .config`"
  21. # Make a config with all applet symbols off
  22. allno="$cfg"
  23. for app in $apps; do
  24. allno="`echo "$allno" | sed "s/^CONFIG_${app}=y\$/# CONFIG_${app} is not set/"`"
  25. done
  26. # remove "busybox" as well
  27. allno="`echo "$allno" | sed "s/^CONFIG_BUSYBOX=y\$/# CONFIG_BUSYBOX is not set/"`"
  28. #echo "$allno" >.config_allno
  29. trap 'test -f .config.SV && mv .config.SV .config && touch .config' EXIT
  30. # Turn on each applet individually and build single-applet executable
  31. # (give config names on command line to build only those)
  32. test $# = 0 && set -- $apps
  33. fail=0
  34. for app; do
  35. # Only if it was indeed originally enabled...
  36. { echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
  37. echo "Making ${app}..."
  38. mv .config .config.SV
  39. echo "CONFIG_${app}=y" >.config
  40. echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
  41. if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
  42. # $allno has all choices for "sh" aliasing set to off.
  43. # "sh" aliasing defaults to "ash", not none.
  44. # without this fix, "make oldconfig" sets it wrong,
  45. # resulting in NUM_APPLETS = 2 (the second applet is "sh")
  46. sed '/CONFIG_SH_IS_NONE/d' -i .config
  47. echo "CONFIG_SH_IS_NONE=y" >>.config
  48. fi
  49. if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
  50. fail=$((fail+1))
  51. echo "Config error for ${app}"
  52. mv .config busybox_config_${app}
  53. elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
  54. fail=$((fail+1))
  55. grep -i -e error: -e warning: busybox_make_${app}.log
  56. echo "Build error for ${app}"
  57. mv .config busybox_config_${app}
  58. elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
  59. grep -i -e error: -e warning: busybox_make_${app}.log
  60. mv busybox busybox_${app}
  61. fail=$((fail+1))
  62. echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
  63. mv .config busybox_config_${app}
  64. else
  65. grep -i -e error: -e warning: busybox_make_${app}.log \
  66. || rm busybox_make_${app}.log
  67. mv busybox busybox_${app}
  68. #mv .config busybox_config_${app}
  69. fi
  70. mv .config.SV .config
  71. #exit
  72. done
  73. touch .config # or else next "make" can be confused
  74. echo "Failures: $fail"
  75. test $fail = 0 # set exitcode