Mercurial > hg > toybox
annotate scripts/make.sh @ 664:c60ac785784f
Add switch_root and fix infrastructure to understand name "switch_root".
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 08 Sep 2012 01:27:54 -0500 |
parents | 04feab07416c |
children | 7e846e281e38 |
rev | line source |
---|---|
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 # Grab default values for $CFLAGS and such. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 source ./configure |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
7 if [ -z ".config" ] |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
8 then |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
9 echo "No .config (see "make help" for configuration options)." |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
10 exit 1 |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
11 fi |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
12 |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
13 echo "Extract configuration information from toys/*.c files..." |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 scripts/genconfig.sh |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
16 echo "Generate headers from toys/*/*.c..." |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
17 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
18 # Create a list of all the applets toybox can provide. Note that the first |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
19 # entry is out of order on purpose (the toybox multiplexer applet must be the |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
20 # first element of the array). The rest must be sorted in alphabetical order |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
21 # for fast binary search. |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
22 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
23 echo "generated/newtoys.h" |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
24 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
25 function newtoys() |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
26 { |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
27 for i in toys/*/*.c |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
28 do |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
29 sed -n -e '1,/^config [A-Z]/s/^USE_/&/p' $i || exit 1 |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
30 done |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
31 } |
595
d8566c3321f0
Multiplexer needs stayroot flag for suid handling.
Rob Landley <rob@landley.net>
parents:
581
diff
changeset
|
32 echo "NEWTOY(toybox, NULL, TOYFLAG_STAYROOT)" > generated/newtoys.h |
293
6baa13382880
Sort was including the trailing comma and getting the order wrong.
Rob Landley <rob@landley.net>
parents:
264
diff
changeset
|
33 newtoys | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \ |
6baa13382880
Sort was including the trailing comma and getting the order wrong.
Rob Landley <rob@landley.net>
parents:
264
diff
changeset
|
34 | sed 's/[^ ]* //' >> generated/newtoys.h |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
35 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
36 # Extract global structure definitions and flag definitions from toys/*/*.c |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
37 |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
38 function getglobals() |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
39 { |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
40 for i in toys/*/*.c |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
41 do |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
42 NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')" |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
43 |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
44 echo -e "// $i\n" |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
45 sed -n -e '/^DEFINE_GLOBALS(/,/^)/b got;b;:got' \ |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
46 -e 's/^DEFINE_GLOBALS(/struct '"$NAME"'_data {/' \ |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
47 -e 's/^)/};/' -e 'p' $i |
566
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
48 |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
49 # And get flag definitions |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
50 FLAGS="$(sed -n \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
51 -e "s/.*TOY($NAME"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
52 -e 't keep;d;:keep' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
53 -e 's/[><=][0-9][0-9]*//g' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
54 -e 's/+.//g' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
55 -e 's/([^)]*)//g' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
56 -e 's/[-?^:&#|@*]//g' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
57 -e 'p' \ |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
58 generated/newtoys.h)" |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
59 X=0 |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
60 while [ $X -lt ${#FLAGS} ] |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
61 do |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
62 echo -ne "#define OPTFLAG_${NAME}_${FLAGS:$X:1}\t" |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
63 X=$(($X+1)) |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
64 echo "(1<<$((${#FLAGS}-$X)))" |
05617db1a337
Teach make.sh to create flag macros, but with the wrong names. Dunno how to make a translation macro or #ifdef guard to get the names right so they actually be _used_ yet...
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
65 done |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
66 done |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
67 } |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
68 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
69 echo "generated/globals.h" |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
70 |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
71 GLOBSTRUCT="$(getglobals)" |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
72 ( |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
73 echo "$GLOBSTRUCT" |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
74 echo |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
75 echo "extern union global_union {" |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
76 echo "$GLOBSTRUCT" | sed -n 's/struct \(.*\)_data {/ struct \1_data \1;/p' |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
77 echo "} this;" |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
78 ) > generated/globals.h |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
79 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
80 echo "generated/help.h" |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 # Only recreate generated/help.h if python is installed |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 if [ ! -z "$(which python)" ] && [ ! -z "$(grep 'CONFIG_HELP=y' .config)" ] |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 then |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 echo "Extract help text from Config.in." |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 scripts/config2help.py Config.in > generated/help.h || exit 1 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 fi |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 echo "Make generated/config.h from .config." |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 # This long and roundabout sed invocation is to make old versions of sed happy. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 # New ones have '\n' so can replace one line with two without all the branches |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 # and tedious mucking about with hold space. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 |
346
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
94 sed -n \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
95 -e 's/^# CONFIG_\(.*\) is not set.*/\1/' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
96 -e 't notset' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
97 -e 's/^CONFIG_\(.*\)=y.*/\1/' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
98 -e 't isset' \ |
347
52e980b216d3
Convert non-bool config values (such as int) into config.h entries.
Rob Landley <rob@landley.net>
parents:
346
diff
changeset
|
99 -e 's/^CONFIG_\([^=]*\)=\(.*\)/#define CFG_\1 \2/p' \ |
346
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
100 -e 'd' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
101 -e ':notset' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
102 -e 'h' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
103 -e 's/.*/#define CFG_& 0/p' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
104 -e 'g' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
105 -e 's/.*/#define USE_&(...)/p' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
106 -e 'd' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
107 -e ':isset' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
108 -e 'h' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
109 -e 's/.*/#define CFG_& 1/p' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
110 -e 'g' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
111 -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \ |
d0bf1df83c04
Re-wordwrap and reorder the .config->config.h sed script. (No real changes, just one command/line in a clearer order.)
Rob Landley <rob@landley.net>
parents:
321
diff
changeset
|
112 .config > generated/config.h || exit 1 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
114 # Extract a list of toys/*/*.c files to compile from the data in ".config": |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 |
654
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
116 # 1) Get a list of C files in toys/* and glue them together into a regex we can |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
117 # feed to grep that will match any one of them (whole word, not substring). |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
118 TOYFILES="^$(ls toys/*/*.c | sed -n 's@^.*/\(.*\)\.c$@\1@;s/-/_/g;H;${g;s/\n//;s/\n/$|^/gp}')\$" |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
119 |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
120 # 2) Grab the XXX part of all CONFIG_XXX entries, removing everything after the |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 # second underline |
654
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
122 # 3) Sort the list, keeping only one of each entry. |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
123 # 4) Convert to lower case. |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
124 # 5) Remove any config symbol not recognized as a filename from step 1. |
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
125 # 6) Add "toys/*/" prefix and ".c" suffix. |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 |
664
c60ac785784f
Add switch_root and fix infrastructure to understand name "switch_root".
Rob Landley <rob@landley.net>
parents:
654
diff
changeset
|
127 TOYFILES=$(sed -nre 's/^CONFIG_(.*)=y/\1/p' < .config \ |
654
04feab07416c
Teach build to compare toys/*/*.c against .config symbol names instead of stopping at first _ when assembling list of files to build, and convert - to _. This lets us have commands like switch_root or nbd-client.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
128 | sort -u | tr A-Z a-z | grep -E "$TOYFILES" | sed 's@\(.*\)@toys/\*/\1.c@') |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 |
581
1e07220fd3b6
Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
130 echo "Library probe..." |
1e07220fd3b6
Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
131 |
653
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
132 # We trust --as-needed to remove each library if we don't use any symbols |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
133 # out of it, this loop is because the compiler has no way to ignore a library |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
134 # that doesn't exist, so we have to detect and skip nonexistent libraries |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
135 # for it. |
2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
Rob Landley <rob@landley.net>
parents:
595
diff
changeset
|
136 |
581
1e07220fd3b6
Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
137 OPTLIBS="$(for i in util crypt m; do echo "int main(int argc, char *argv[]) {return 0;}" | ${CROSS_COMPILE}${CC} -xc - -o /dev/null -Wl,--as-needed -l$i > /dev/null 2>/dev/null && echo -l$i; done)" |
1e07220fd3b6
Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
138 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 echo "Compile toybox..." |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 |
472 | 141 do_loudly() |
142 { | |
143 [ ! -z "$V" ] && echo "$@" | |
144 "$@" | |
145 } | |
146 | |
512
9bcc288a1c54
Fix from Georgi Chorbadzhiyski to make cross compiling more robust.
Rob Landley <rob@landley.net>
parents:
472
diff
changeset
|
147 do_loudly ${CROSS_COMPILE}${CC} $CFLAGS -I . -o toybox_unstripped $OPTIMIZE \ |
581
1e07220fd3b6
Probe available libraries to link --as-needed, avoiding "unknown libarary" errors.
Rob Landley <rob@landley.net>
parents:
572
diff
changeset
|
148 main.c lib/*.c $TOYFILES -Wl,--as-needed $OPTLIBS || exit 1 |
512
9bcc288a1c54
Fix from Georgi Chorbadzhiyski to make cross compiling more robust.
Rob Landley <rob@landley.net>
parents:
472
diff
changeset
|
149 do_loudly ${CROSS_COMPILE}${STRIP} toybox_unstripped -o toybox || exit 1 |
364
6df3ac5165fa
The "strip" in gcc 4.4 doesn't set the executable bit on its output, despite what SUSv4 says it should do, so cope with buggy FSF tools.
Rob Landley <rob@landley.net>
parents:
347
diff
changeset
|
150 # gcc 4.4's strip command is buggy, and doesn't set the executable bit on |
6df3ac5165fa
The "strip" in gcc 4.4 doesn't set the executable bit on its output, despite what SUSv4 says it should do, so cope with buggy FSF tools.
Rob Landley <rob@landley.net>
parents:
347
diff
changeset
|
151 # its output the way SUSv4 suggests it do so. |
472 | 152 do_loudly chmod +x toybox || exit 1 |