3 # Grab default values for $CFLAGS and such.
7 echo "Extract configuration information from toys/*.c files..."
10 echo "Generate headers from toys/*.h..."
12 # Create a list of all the applets toybox can provide. Note that the first
13 # entry is out of order on purpose (the toybox multiplexer applet must be the
14 # first element of the array). The rest must be sorted in alphabetical order
15 # for fast binary search.
21 sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1
24 echo "NEWTOY(toybox, NULL, 0)" > generated/newtoys.h
25 newtoys | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \
26 | sed 's/[^ ]* //' >> generated/newtoys.h
28 # Extract global structure definitions from toys/*.c
34 NAME="$(echo $i | sed 's@toys/\(.*\)\.c@\1@')"
37 sed -n -e '/^DEFINE_GLOBALS(/,/^)/b got;b;:got' \
38 -e 's/^DEFINE_GLOBALS(/struct '"$NAME"'_data {/' \
39 -e 's/^)/};/' -e 'p' $i
43 GLOBSTRUCT="$(getglobals)"
47 echo "extern union global_union {"
48 echo "$GLOBSTRUCT" | sed -n 's/struct \(.*\)_data {/ struct \1_data \1;/p'
50 ) > generated/globals.h
52 # Only recreate generated/help.h if python is installed
53 if [ ! -z "$(which python)" ] && [ ! -z "$(grep 'CONFIG_HELP=y' .config)" ]
55 echo "Extract help text from Config.in."
56 scripts/config2help.py Config.in > generated/help.h || exit 1
59 echo "Make generated/config.h from .config."
61 # This long and roundabout sed invocation is to make old versions of sed happy.
62 # New ones have '\n' so can replace one line with two without all the branches
63 # and tedious mucking about with hold space.
66 -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
68 -e 's/^CONFIG_\(.*\)=y.*/\1/' \
73 -e 's/.*/#define CFG_& 0/p' \
75 -e 's/.*/#define USE_&(...)/p' \
79 -e 's/.*/#define CFG_& 1/p' \
81 -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \
82 .config > generated/config.h || exit 1
84 # Extract a list of toys/*.c files to compile from the data in ".config" with
87 # 1) Grab the XXX part of all CONFIG_XXX entries, removing everything after the
89 # 2) Sort the list, keeping only one of each entry.
90 # 3) Convert to lower case.
91 # 4) Remove toybox itself from the list (as that indicates global symbols).
92 # 5) Add "toys/" prefix and ".c" suffix.
94 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@' )
96 echo "Compile toybox..."
98 $DEBUG $CC $CFLAGS -I . -o toybox_unstripped $OPTIMIZE main.c lib/*.c \
99 $TOYFILES -Wl,--as-needed,-lutil,--no-as-needed || exit 1
100 $DEBUG $STRIP toybox_unstripped -o toybox || exit 1