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