view scripts/ @ 247:085395c1471d

Die on compilation or stripping failure
author Charlie Shepherd <>
date Fri, 25 Jan 2008 14:44:01 +0000
parents c3659856f120
children 4b4a6979d228
line wrap: on
line source


# Grab default values for $CFLAGS and such.

source ./configure

echo "Extract configuration information from toys/*.c files..."

echo "Generate headers from toys/*.h..."

# Create a list of all the applets toybox can provide.  Note that the first
# entry is out of order on purpose (the toybox multiplexer applet must be the
# first element of the array).  The rest must be sorted in alphabetical order
# for fast binary search.

function newtoys()
  for i in toys/*.c
    sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1
echo "NEWTOY(toybox, NULL, 0)" > generated/newtoys.h
newtoys | sort -t '(' -k3,3  >> generated/newtoys.h

# Extract global structure definitions from toys/*.c

function getglobals()
  for i in toys/*.c
    NAME="$(echo $i | sed 's@toys/\(.*\)\.c@\1@')"

    echo -e "// $i\n"
    sed -n -e '/^DEFINE_GLOBALS(/,/^)/b got;b;:got' \
        -e 's/^DEFINE_GLOBALS(/struct '"$NAME"'_data {/' \
        -e 's/^)/};/' -e 'p' $i

  echo "$GLOBSTRUCT"
  echo "extern union global_union {"
  echo "$GLOBSTRUCT" | sed -n 's/struct \(.*\)_data {/	struct \1_data \1;/p'
  echo "} this;"
) > generated/globals.h

# Only recreate generated/help.h if python is installed
if [ ! -z "$(which python)" ] && [ ! -z "$(grep 'CONFIG_HELP=y' .config)" ]
  echo "Extract help text from"
  scripts/ > generated/help.h || exit 1

echo "Make generated/config.h from .config."

# This long and roundabout sed invocation is to make old versions of sed happy.
# New ones have '\n' so can replace one line with two without all the branches
# and tedious mucking about with hold space.

sed -n -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
  -e 't notset' -e 'b tryisset' -e ':notset' \
  -e 'h' -e 's/.*/#define CFG_& 0/p' \
  -e 'g' -e 's/.*/#define USE_&(...)/p' -e 'd' -e ':tryisset' \
  -e 's/^CONFIG_\(.*\)=y.*/\1/' -e 't isset' -e 'd' -e ':isset' \
  -e 'h' -e 's/.*/#define CFG_& 1/p' \
  -e 'g' -e 's/.*/#define USE_&(...) __VA_ARGS__/p' .config > \
  generated/config.h || exit 1

#for i in $(echo toys/*.c | sort)
  # Grab the function command names
  # NAME=$(echo $i | sed -e 's@toys/@@' -e 's@\.c@@')
  #sed -n '/struct '$NAME'_command {/,/};/p' $i \
  #	>> generated/globals_big.h
  #  echo "struct ${NAME}_command;" >> generated/globals.h

# Extract a list of toys/*.c files to compile from the data in ".config" with
# sed, sort, and tr:

# 1) Grab the XXX part of all CONFIG_XXX entries, removing everything after the
# second underline
# 2) Sort the list, keeping only one of each entry.
# 3) Convert to lower case.
# 4) Remove toybox itself from the list (as that indicates global symbols).
# 5) Add "toys/" prefix and ".c" suffix.

TOYFILES=$(cat .config | sed -nre 's/^CONFIG_(.*)=y/\1/;t skip;b;:skip;s/_.*//;p' | sort -u | tr A-Z a-z | grep -v '^toybox$' | sed 's@\(.*\)@toys/\1.c@' )

echo "Compile toybox..."

$DEBUG $CC $CFLAGS -I . -o toybox_unstripped $OPTIMIZE \
  main.c lib/*.c $TOYFILES || exit 1
$DEBUG $STRIP toybox_unstripped -o toybox || exit 1