single.sh 1.5 KB

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