1#!/bin/bash 2 3# Build a standalone toybox command 4 5if [ -z "$1" ] 6then 7 echo "usage: single.sh command..." >&2 8 exit 1 9fi 10 11# Add trailing / to PREFIX when it's set but hasn't got one 12[ "$PREFIX" == "${PREFIX%/}" ] && PREFIX="${PREFIX:+$PREFIX/}" 13 14# Harvest TOYBOX_* symbols from .config 15if [ ! -e .config ] 16then 17 echo "Need .config for toybox global settings. Run defconfig/menuconfig." >&2 18 exit 1 19fi 20 21# Force dependencies to rebuild headers if we build multiplexer after this. 22touch -c .config 23 24export KCONFIG_CONFIG=.singleconfig 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 DEPENDS= 39 MPDEL= 40 if [ "$i" == sh ] 41 then 42 DEPENDS="$(sed -n 's/USE_\([^(]*\)(NEWTOY([^,]*,.*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; sed -n "/^config *$i"'$/,/^$/{s/^[ \t]*depends on //;T;s/[!][A-Z0-9_]*//g;s/ *&& */|/g;p}' $TOYFILE; sed -n 's/CONFIG_\(TOYBOX_[^=]*\)=y/\1/p' .config;}| 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 #&& grep "CONFIG_TOYBOX_" .config >> "$KCONFIG_CONFIG" || exit 1 53 54 export OUTNAME="$PREFIX$i" 55 rm -f "$OUTNAME" && 56 scripts/make.sh || exit 1 57done 58