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