embedded_scripts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/sh
  2. . ./.config || exit 1
  3. target="$1"
  4. custom_loc="$2"
  5. applet_loc="$3"
  6. test "$target" || exit 1
  7. test "$SED" || SED=sed
  8. test "$DD" || DD=dd
  9. if [ x"$CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS" != x"y" ]
  10. then
  11. printf '#define NUM_SCRIPTS 0\n' >"$target"
  12. exit 0
  13. fi
  14. # Some people were bitten by their system lacking a (proper) od
  15. od -v -b </dev/null >/dev/null
  16. if test $? != 0; then
  17. echo 'od tool is not installed or cannot accept "-v -b" options'
  18. exit 1
  19. fi
  20. custom_scripts=""
  21. if [ -d "$custom_loc" ]
  22. then
  23. custom_scripts=$(cd $custom_loc; ls * 2>/dev/null)
  24. fi
  25. all_scripts=$($srctree/applets/busybox.mkscripts)
  26. # all_scripts includes applet scripts and custom scripts, sort them out
  27. applet_scripts=""
  28. for i in $all_scripts
  29. do
  30. found=0
  31. for j in $custom_scripts
  32. do
  33. if [ "$i" = "$j" ]
  34. then
  35. found=1
  36. break;
  37. fi
  38. done
  39. if [ $found -eq 0 ]
  40. then
  41. # anything that isn't a custom script is an applet script
  42. applet_scripts="$applet_scripts $i"
  43. fi
  44. done
  45. # we know the custom scripts are present but applet scripts might have
  46. # become detached from their configuration
  47. for i in $applet_scripts
  48. do
  49. #if [ ! -f "$applet_loc/$i" -a ! -f "$custom_loc/$i" ]
  50. if [ ! -f "$applet_loc/$i" ]
  51. then
  52. echo "missing applet script $i"
  53. exit 1
  54. fi
  55. done
  56. n=$(echo $custom_scripts $applet_scripts | wc -w)
  57. nall=$(echo $all_scripts | wc -w)
  58. if [ $n -ne $nall ]
  59. then
  60. echo "script mismatch $n != $nall"
  61. exit 1
  62. fi
  63. concatenate_scripts() {
  64. for i in $custom_scripts
  65. do
  66. cat $custom_loc/$i
  67. printf '\000'
  68. done
  69. for i in $applet_scripts
  70. do
  71. cat $applet_loc/$i
  72. printf '\000'
  73. done
  74. }
  75. exec >"$target.$$"
  76. if [ $n -ne 0 ]
  77. then
  78. printf '#ifdef DEFINE_SCRIPT_DATA\n'
  79. printf 'const uint16_t applet_numbers[] = {\n'
  80. for i in $custom_scripts $applet_scripts
  81. do
  82. # TODO support applets with names including invalid characters
  83. printf '\tAPPLET_NO_%s,\n' $i
  84. done
  85. printf '};\n'
  86. printf '#else\n'
  87. printf 'extern const uint16_t applet_numbers[];\n'
  88. printf '#endif\n'
  89. fi
  90. printf "\n"
  91. printf '#define NUM_SCRIPTS %d\n' $n
  92. printf "\n"
  93. if [ $n -ne 0 ]
  94. then
  95. printf '#define UNPACKED_SCRIPTS_LENGTH '
  96. concatenate_scripts | wc -c
  97. printf '#define PACKED_SCRIPTS \\\n'
  98. concatenate_scripts | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | \
  99. od -v -b \
  100. | grep -v '^ ' \
  101. | $SED -e 's/^[^ ]*//' \
  102. -e 's/ //g' \
  103. -e '/^$/d' \
  104. -e 's/\(...\)/0\1,/g' \
  105. -e 's/$/ \\/'
  106. printf '\n'
  107. fi
  108. mv -- "$target.$$" "$target"