single.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # Build a standalone toybox command
  3. [ -z "$1" ] && { echo "usage: single.sh command..." >&2; exit 1; }
  4. # Add trailing / to PREFIX when it's set but hasn't got one
  5. [ "$PREFIX" == "${PREFIX%/}" ] && PREFIX="${PREFIX:+$PREFIX/}"
  6. # Harvest TOYBOX_* symbols from .config, or fresh defconfig if none
  7. export KCONFIG_CONFIG
  8. if [ ! -e ${KCONFIG_CONFIG:=.config} ]
  9. then
  10. KCONFIG_CONFIG=.singleconfig
  11. make defconfig
  12. else
  13. # Force dependencies to rebuild headers if we build multiplexer after this.
  14. touch "$KCONFIG_CONFIG"
  15. fi
  16. GLOBDEP="$(sed -n 's/CONFIG_\(TOYBOX_[^=]*\)=y/\1/p' "$KCONFIG_CONFIG")"
  17. KCONFIG_CONFIG=.singleconfig
  18. for i in "$@"
  19. do
  20. echo -n "$i:"
  21. TOYFILE="$(egrep -l "TOY[(]($i)[ ,]" toys/*/*.c)"
  22. if [ -z "$TOYFILE" ]
  23. then
  24. echo "Unknown command '$i'" >&2
  25. exit 1
  26. fi
  27. make allnoconfig > /dev/null || exit 1
  28. unset DEPENDS MPDEL
  29. if [ "$i" == sh ]
  30. then
  31. DEPENDS="$(sed -n 's/USE_\([^(]*\)(NEWTOY([^,]*,.*TOYFLAG_MAYFORK.*/\1/p' toys/*/*.c)"
  32. else
  33. MPDEL='s/CONFIG_TOYBOX=y/# CONFIG_TOYBOX is not set/;t'
  34. fi
  35. # Enable stuff this command depends on
  36. DEPENDS="$({ echo $DEPENDS $GLOBDEP; sed -n "/^config *$i"'$/,/^$/{s/^[ \t]*depends on //;T;s/[!][A-Z0-9_]*//g;s/ *&& */|/g;p}' $TOYFILE;}| xargs | tr ' ' '|')"
  37. NAME=$(echo $i | tr a-z- A-Z_)
  38. sed -ri -e "$MPDEL" \
  39. -e "s/# (CONFIG_($NAME|${NAME}_.*${DEPENDS:+|$DEPENDS})) is not set/\1=y/" \
  40. "$KCONFIG_CONFIG" || exit 1
  41. export OUTNAME="$PREFIX$i"
  42. rm -f "$OUTNAME" &&
  43. scripts/make.sh || exit 1
  44. done