make_single_applets.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if grep -q 'use larger COMMON_BUFSIZE' busybox_make_${app}.log; then
  66. # FEATURE_USE_BSS_TAIL=y is selected, and build system
  67. # recommends rebuilding. Do so, and print some
  68. # debug info to see whether it works right:
  69. tail -n1 busybox_make_${app}.log
  70. nm busybox_unstripped | grep ' _end'
  71. make >/dev/null 2>&1
  72. nm busybox_unstripped | grep ' _end'
  73. grep ^bb_common_bufsiz1 busybox_unstripped.map
  74. fi
  75. grep -i -e error: -e warning: busybox_make_${app}.log \
  76. || rm busybox_make_${app}.log
  77. mv busybox busybox_${app}
  78. #mv .config busybox_config_${app}
  79. fi
  80. mv .config.SV .config
  81. #exit
  82. done
  83. touch .config # or else next "make" can be confused
  84. echo "Failures: $fail"
  85. test $fail = 0 # set exitcode