make_single_applets.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # disable any CONFIG_script_DEPENDENCIES as well
  29. allno="`echo "$allno" | sed "s/^\(CONFIG_.*_DEPENDENCIES\)=y\$/# \1 is not set/"`"
  30. #echo "$allno" >.config_allno
  31. trap 'test -f .config.SV && mv .config.SV .config && touch .config' EXIT
  32. # Turn on each applet individually and build single-applet executable
  33. # (give config names on command line to build only those)
  34. test $# = 0 && set -- $apps
  35. fail=0
  36. for app; do
  37. # Only if it was indeed originally enabled...
  38. { echo "$cfg" | grep -q "^CONFIG_${app}=y\$"; } || continue
  39. echo "Making ${app}..."
  40. mv .config .config.SV
  41. echo "CONFIG_${app}=y" >.config
  42. echo "$allno" | sed "/^# CONFIG_${app} is not set\$/d" >>.config
  43. if test x"${app}" != x"SH_IS_ASH" && test x"${app}" != x"SH_IS_HUSH"; then
  44. # $allno has all choices for "sh" aliasing set to off.
  45. # "sh" aliasing defaults to "ash", not none.
  46. # without this fix, "make oldconfig" sets it wrong,
  47. # resulting in NUM_APPLETS = 2 (the second applet is "sh")
  48. sed '/CONFIG_SH_IS_NONE/d' -i .config
  49. echo "CONFIG_SH_IS_NONE=y" >>.config
  50. fi
  51. if ! yes '' | make oldconfig >busybox_make_${app}.log 2>&1; then
  52. fail=$((fail+1))
  53. echo "Config error for ${app}"
  54. mv .config busybox_config_${app}
  55. elif ! make $makeopts >>busybox_make_${app}.log 2>&1; then
  56. fail=$((fail+1))
  57. grep -i -e error: -e warning: busybox_make_${app}.log
  58. echo "Build error for ${app}"
  59. mv .config busybox_config_${app}
  60. elif ! grep -q '^#define NUM_APPLETS 1$' include/NUM_APPLETS.h; then
  61. grep -i -e error: -e warning: busybox_make_${app}.log
  62. mv busybox busybox_${app}
  63. fail=$((fail+1))
  64. echo "NUM_APPLETS != 1 for ${app}: `cat include/NUM_APPLETS.h`"
  65. mv .config busybox_config_${app}
  66. else
  67. if grep -q 'use larger COMMON_BUFSIZE' busybox_make_${app}.log; then
  68. # FEATURE_USE_BSS_TAIL=y is selected, and build system
  69. # recommends rebuilding. Do so, and print some
  70. # debug info to see whether it works right:
  71. tail -n1 busybox_make_${app}.log
  72. nm busybox_unstripped | grep ' _end'
  73. make >/dev/null 2>&1
  74. nm busybox_unstripped | grep ' _end'
  75. grep ^bb_common_bufsiz1 busybox_unstripped.map
  76. fi
  77. grep -i -e error: -e warning: busybox_make_${app}.log \
  78. || rm busybox_make_${app}.log
  79. mv busybox busybox_${app}
  80. #mv .config busybox_config_${app}
  81. fi
  82. mv .config.SV .config
  83. #exit
  84. done
  85. touch .config # or else next "make" can be confused
  86. echo "Failures: $fail"
  87. test $fail = 0 # set exitcode