OSDN Git Service

Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just...
[android-x86/external-toybox.git] / scripts / make.sh
1 #!/bin/bash
2
3 # Grab default values for $CFLAGS and such.
4
5 source ./configure
6
7 echo "Extract configuration information from toys/*.c files..."
8 scripts/genconfig.sh
9
10 echo "Generate headers from toys/*.h..."
11
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.
16
17 function newtoys()
18 {
19   for i in toys/*.c
20   do
21     sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1
22   done
23 }
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
27
28 # Extract global structure definitions from toys/*.c
29
30 function getglobals()
31 {
32   for i in toys/*.c
33   do
34     NAME="$(echo $i | sed 's@toys/\(.*\)\.c@\1@')"
35
36     echo -e "// $i\n"
37     sed -n -e '/^DEFINE_GLOBALS(/,/^)/b got;b;:got' \
38         -e 's/^DEFINE_GLOBALS(/struct '"$NAME"'_data {/' \
39         -e 's/^)/};/' -e 'p' $i
40   done
41 }
42
43 GLOBSTRUCT="$(getglobals)"
44 (
45   echo "$GLOBSTRUCT"
46   echo
47   echo "extern union global_union {"
48   echo "$GLOBSTRUCT" | sed -n 's/struct \(.*\)_data {/  struct \1_data \1;/p'
49   echo "} this;"
50 ) > generated/globals.h
51
52 # Only recreate generated/help.h if python is installed
53 if [ ! -z "$(which python)" ] && [ ! -z "$(grep 'CONFIG_HELP=y' .config)" ]
54 then
55   echo "Extract help text from Config.in."
56   scripts/config2help.py Config.in > generated/help.h || exit 1
57 fi
58
59 echo "Make generated/config.h from .config."
60
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.
64
65 sed -n \
66   -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \
67   -e 't notset' \
68   -e 's/^CONFIG_\(.*\)=y.*/\1/' \
69   -e 't isset' \
70   -e 'd' \
71   -e ':notset' \
72   -e 'h' \
73   -e 's/.*/#define CFG_& 0/p' \
74   -e 'g' \
75   -e 's/.*/#define USE_&(...)/p' \
76   -e 'd' \
77   -e ':isset' \
78   -e 'h' \
79   -e 's/.*/#define CFG_& 1/p' \
80   -e 'g' \
81   -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \
82   .config > generated/config.h || exit 1
83
84 # Extract a list of toys/*.c files to compile from the data in ".config" with
85 # sed, sort, and tr:
86
87 # 1) Grab the XXX part of all CONFIG_XXX entries, removing everything after the
88 # second underline
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.
93
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@' )
95
96 echo "Compile toybox..."
97
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