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 # For the shell pull in MAYFORK commands from other source files as builtins. 39 unset DEPENDS MPDEL 40 if [ "$i" == sh ] 41 then 42 DEPENDS="$($SED -n 's/USE_\([^(]*\)(...TOY([^,]*,.*TOYFLAG_MAYFORK.*/\1/p' toys/*/*.c)" 43 else 44 MPDEL='s/CONFIG_TOYBOX=y/# CONFIG_TOYBOX is not set/;t' 45 fi 46 47 # Enable stuff this command depends on 48 DEPENDS="$({ echo $DEPENDS $GLOBDEP; $SED -n "/^config *$i"'$/,/^$/{s/^[ \t]*depends on //;T;s/[!][A-Z0-9_]*//g;s/ *&& */|/g;p}' $TOYFILE;}| xargs | tr ' ' '|')" 49 NAME=$(echo $i | tr a-z- A-Z_) 50 $SED -ri -e "$MPDEL" \ 51 -e "s/# (CONFIG_($NAME|${NAME}_.*${DEPENDS:+|$DEPENDS})) is not set/\1=y/" \ 52 "$KCONFIG_CONFIG" || exit 1 53 54 export OUTNAME="$PREFIX$i" 55 rm -f "$OUTNAME" && 56 scripts/make.sh || exit 1 57done 58