Mercurial > hg > toybox
annotate scripts/make.sh @ 1613:96aa7ec74936 draft
Fix yet another sed bug.
The s/// command would copy the \ of substitutions before deciding what to
do with them (generally overwriting the \ with the new data). When the
substitution was A) at the very end of the new string, B) resolved to nothing,
it could leave a trailing \ that didn't belong there and didn't get overwritten
because the "copy trailing data" part that copies the original string's null
terminator already happened before the \ overwrote it.
The ghostwheel() function restarts regexes after embedded NUL bytes, but
if the string it's passed is _longer_ than the length it's told then it
gets confused (and it means we're off the end of our allocation so segfaults
are likely).
Fix: test for \ first and move the "copy byte" logic into an else case.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 15 Dec 2014 03:34:55 -0600 |
parents | e5d81c69729b |
children | ae9d3ffeecbe |
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 |
890
c7e7b159568d
The host sort on many distros behaves stupidly, and sorts stuff in non-ascii order by default. Make it stop.
Rob Landley <rob@landley.net>
parents:
720
diff
changeset
|
5 export LANG=c |
1450
0089cd84afea
Another fix from Johan Bergstr?m, using the gnu/dammit version of sort on the host can be screwed up by more than one environment variable.
Rob Landley <rob@landley.net>
parents:
1446
diff
changeset
|
6 export LC_ALL=C |
1466
aa0ae038e275
Make tweaks: collate generated/*.o files into their own subdirectory, add PIPEFAIL for better error reporting, and simpler regex to select toys/*/*.c list based on NEWTOY/OLDTOY macros.
Rob Landley <rob@landley.net>
parents:
1458
diff
changeset
|
7 set -o pipefail |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 source ./configure |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 |
1032
40d0c96a8e89
Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents:
999
diff
changeset
|
10 [ -z "$KCONFIG_CONFIG" ] && KCONFIG_CONFIG=".config" |
40d0c96a8e89
Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents:
999
diff
changeset
|
11 |
1484
19435f12ec63
Give library probe a progress indicator, and use 150% of detected CPUs to try to keep large SMP machines busy (each compiler invocation is short so they exit almost as fast as we launch them).
Rob Landley <rob@landley.net>
parents:
1470
diff
changeset
|
12 # Since each cc invocation is short, launch half again as many processes |
19435f12ec63
Give library probe a progress indicator, and use 150% of detected CPUs to try to keep large SMP machines busy (each compiler invocation is short so they exit almost as fast as we launch them).
Rob Landley <rob@landley.net>
parents:
1470
diff
changeset
|
13 # as we have processors so they don't exit faster than we can start them. |
19435f12ec63
Give library probe a progress indicator, and use 150% of detected CPUs to try to keep large SMP machines busy (each compiler invocation is short so they exit almost as fast as we launch them).
Rob Landley <rob@landley.net>
parents:
1470
diff
changeset
|
14 [ -z "$CPUS" ] && |
19435f12ec63
Give library probe a progress indicator, and use 150% of detected CPUs to try to keep large SMP machines busy (each compiler invocation is short so they exit almost as fast as we launch them).
Rob Landley <rob@landley.net>
parents:
1470
diff
changeset
|
15 CPUS=$((($(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)*3)/2)) |
19435f12ec63
Give library probe a progress indicator, and use 150% of detected CPUs to try to keep large SMP machines busy (each compiler invocation is short so they exit almost as fast as we launch them).
Rob Landley <rob@landley.net>
parents:
1470
diff
changeset
|
16 |
1179
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
17 # Respond to V= by echoing command lines as well as running them |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
18 DOTPROG= |
1179
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
19 do_loudly() |
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
20 { |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
21 [ ! -z "$V" ] && echo "$@" || echo -n "$DOTPROG" |
1179
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
22 "$@" |
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
23 } |
260cce6c3e35
Replace python help converter with C implementation.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
24 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
25 # Is anything under directory $2 newer than file $1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
26 isnewer() |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
27 { |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
28 [ ! -z "$(find "$2" -newer "$1" 2>/dev/null || echo yes)" ] |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
29 } |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
30 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
31 echo "Generate headers from toys/*/*.c..." |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
32 |
1492
8bf5f528d352
Delete generated/README.txt (the contents are in code.html now) so clean can just remove the "generated" directory entirely.
Rob Landley <rob@landley.net>
parents:
1489
diff
changeset
|
33 mkdir -p generated |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
34 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
35 if isnewer generated/Config.in toys |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
36 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
37 echo "Extract configuration information from toys/*.c files..." |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
38 scripts/genconfig.sh |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
39 fi |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
40 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
41 # Create a list of all the commands toybox can provide. Note that the first |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
42 # entry is out of order on purpose (the toybox multiplexer command must be the |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
43 # first element of the array). The rest must be sorted in alphabetical order |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
44 # for fast binary search. |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
45 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
46 if isnewer generated/newtoys.h toys |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
47 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
48 echo -n "generated/newtoys.h " |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
49 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
50 echo "USE_TOYBOX(NEWTOY(toybox, NULL, TOYFLAG_STAYROOT))" > generated/newtoys.h |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
51 sed -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
52 | sed 's/\(.*TOY(\)\([^,]*\),\(.*\)/\2 \1\2,\3/' | sort -k 1,1 \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
53 | sed 's/[^ ]* //' >> generated/newtoys.h && |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
54 sed -n -e 's/.*(NEWTOY(\([^,]*\), *\(\("[^"]*"[^,]*\)*\),.*/#define OPTSTR_\1\t\2/p' \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
55 generated/newtoys.h > generated/oldtoys.h || exit 1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
56 fi |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
57 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
58 [ ! -z "$V" ] && echo "Which C files to build..." |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
59 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
60 # Extract a list of toys/*/*.c files to compile from the data in $KCONFIG_CONFIG |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
61 TOYFILES="$(egrep -l "TOY[(]($(sed -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr ' [A-Z]' '|[a-z]'))[ ,]" toys/*/*.c)" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
62 BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE)" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
63 FILES="$(echo lib/*.c main.c $TOYFILES)" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
64 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
65 genbuildsh() |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
66 { |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
67 # Write a canned build line for use on crippled build machines. |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
68 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
69 echo "#!/bin/sh" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
70 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
71 echo "BUILD=\"$BUILD\"" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
72 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
73 echo "FILES=\"$FILES\"" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
74 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
75 echo "LINK=\"$LINK\"" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
76 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
77 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
78 echo '$BUILD $FILES $LINK' |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
79 } |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
80 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
81 if ! cmp -s <(genbuildsh | head -n 3) \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
82 <(head -n 3 generated/build.sh 2>/dev/null) |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
83 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
84 echo -n "Library probe" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
85 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
86 # We trust --as-needed to remove each library if we don't use any symbols |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
87 # out of it, this loop is because the compiler has no way to ignore a library |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
88 # that doesn't exist, so we have to detect and skip nonexistent libraries |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
89 # for it. |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
90 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
91 > generated/optlibs.dat |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
1584
diff
changeset
|
92 for i in util crypt m resolv selinux |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
93 do |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
94 echo "int main(int argc, char *argv[]) {return 0;}" | \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
95 ${CROSS_COMPILE}${CC} $CFLAGS -xc - -o /dev/null -Wl,--as-needed -l$i > /dev/null 2>/dev/null && |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
96 echo -l$i >> generated/optlibs.dat |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
97 echo -n . |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
98 done |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
99 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
100 fi |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
101 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
102 # LINK needs optlibs.dat, above |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
103 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
104 LINK="$(echo $LDOPTIMIZE -o toybox_unstripped -Wl,--as-needed $(cat generated/optlibs.dat))" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
105 genbuildsh > generated/build.sh && chmod +x generated/build.sh || exit 1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
106 |
1032
40d0c96a8e89
Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents:
999
diff
changeset
|
107 echo "Make generated/config.h from $KCONFIG_CONFIG." |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 # 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
|
110 # 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
|
111 # 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
|
112 |
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
|
113 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
|
114 -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
|
115 -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
|
116 -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
|
117 -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
|
118 -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
|
119 -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
|
120 -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
|
121 -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
|
122 -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
|
123 -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
|
124 -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
|
125 -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
|
126 -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
|
127 -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
|
128 -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
|
129 -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
|
130 -e 's/.*/#define USE_&(...) __VA_ARGS__/p' \ |
1032
40d0c96a8e89
Add scripts/single.sh to build individual non-multiplexed standalone commands.
Rob Landley <rob@landley.net>
parents:
999
diff
changeset
|
131 $KCONFIG_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
|
132 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
133 if [ generated/mkflags -ot scripts/mkflags.c ] |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
134 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
135 do_loudly $HOSTCC scripts/mkflags.c -o generated/mkflags || exit 1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
136 fi |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
137 |
1172 | 138 echo -n "generated/flags.h " |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
139 |
1208
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
140 # Process config.h and newtoys.h to generate FLAG_x macros. Note we must |
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
141 # always #define the relevant macro, even when it's disabled, because we |
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
142 # allow multiple NEWTOY() in the same C file. (When disabled the FLAG is 0, |
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
143 # so flags&0 becomes a constant 0 allowing dead code elimination.) |
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
144 |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
145 # Parse files through C preprocessor twice, once to get flags for current |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
146 # .config and once to get flags for allyesconfig |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
147 for I in A B |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
148 do |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
149 ( |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
150 # define macros and select header files with option string data |
712
a950dd960593
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents:
705
diff
changeset
|
151 |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
152 echo "#define NEWTOY(aa,bb,cc) aa $I bb" |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
153 echo '#define OLDTOY(...)' |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
154 if [ "$I" == A ] |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
155 then |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
156 cat generated/config.h |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
157 else |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
158 sed '/USE_.*([^)]*)$/s/$/ __VA_ARGS__/' generated/config.h |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
159 fi |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
160 cat generated/newtoys.h |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
161 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
162 # Run result through preprocessor, glue together " " gaps leftover from USE |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
163 # macros, delete comment lines, print any line with a quoted optstring, |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
164 # turn any non-quoted opstring (NULL or 0) into " " (because fscanf can't |
1210
1c4c893d4e72
Fix header file generation to not be confused by empty (but non-NULL) option string.
Rob Landley <rob@landley.net>
parents:
1208
diff
changeset
|
165 # handle "" with nothing in it, and mkflags uses that). |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
166 |
1094
370f15d1ece1
Don't use $CC without $CROSS_COMPILE because $HOSTCC could be something else entirely.
Rob Landley <rob@landley.net>
parents:
1076
diff
changeset
|
167 ) | ${CROSS_COMPILE}${CC} -E - | \ |
1210
1c4c893d4e72
Fix header file generation to not be confused by empty (but non-NULL) option string.
Rob Landley <rob@landley.net>
parents:
1208
diff
changeset
|
168 sed -n -e 's/" *"//g;/^#/d;t clear;:clear;s/"/"/p;t;s/\( [AB] \).*/\1 " "/p' |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
169 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
170 # Sort resulting line pairs and glue them together into triplets of |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
171 # command "flags" "allflags" |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
172 # to feed into mkflags C program that outputs actual flag macros |
1208
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
173 # If no pair (because command's disabled in config), use " " for flags |
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
174 # so allflags can define the appropriate zero macros. |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
175 |
1208
c86b1579c383
CLEANUP transitions require all the generated/flags.h stanzas always be present (even for commands disabled in the config) to avoid undefined symbol errors referencing FLAG_ macros.
Rob Landley <rob@landley.net>
parents:
1194
diff
changeset
|
176 done | sort | sed -n 's/ A / /;t pair;h;s/\([^ ]*\).*/\1 " "/;x;b single;:pair;h;n;:single;s/[^ ]* B //;H;g;s/\n/ /;p' |\ |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
177 generated/mkflags > generated/flags.h || exit 1 |
712
a950dd960593
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents:
705
diff
changeset
|
178 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
179 # Extract global structure definitions and flag definitions from toys/*/*.c |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
180 |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
181 function getglobals() |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
182 { |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
183 for i in toys/*/*.c |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
184 do |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
185 NAME="$(echo $i | sed 's@.*/\(.*\)\.c@\1@')" |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
186 DATA="$(sed -n -e '/^GLOBALS(/,/^)/b got;b;:got' \ |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
187 -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \ |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
188 -e 's/^)/};/' -e 'p' $i)" |
712
a950dd960593
Cleanup i18n support (#ifdefectomy, move global init to process launch). Teach make.sh to emit "#define FLAG_x 0" for options inside disabled USE macros so we can unconditionally refer to them.
Rob Landley <rob@landley.net>
parents:
705
diff
changeset
|
189 |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
1074
diff
changeset
|
190 [ ! -z "$DATA" ] && echo -e "// $i\n\n$DATA\n" |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
191 done |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
192 } |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
193 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
194 if isnewer generated/globals.h toys |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
195 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
196 echo -n "generated/globals.h " |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
197 GLOBSTRUCT="$(getglobals)" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
198 ( |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
199 echo "$GLOBSTRUCT" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
200 echo |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
201 echo "extern union global_union {" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
202 echo "$GLOBSTRUCT" | \ |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
203 sed -n 's/struct \(.*\)_data {/ struct \1_data \1;/p' |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
204 echo "} this;" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
205 ) > generated/globals.h |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
206 fi |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
207 |
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
208 echo "generated/help.h" |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
209 if [ generated/config2help -ot scripts/config2help.c ] |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
210 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
211 do_loudly $HOSTCC scripts/config2help.c -I . lib/xwrap.c lib/llist.c \ |
1608
e5d81c69729b
Oops. xfork() moved to portability.c and the config2help.c build wasn't including that. (Worked until I did a "make clean".)
Rob Landley <rob@landley.net>
parents:
1603
diff
changeset
|
212 lib/lib.c lib/portability.c -o generated/config2help || exit 1 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
213 fi |
1194
855b706d10dc
Use right config for single builds.
Rob Landley <rob@landley.net>
parents:
1179
diff
changeset
|
214 generated/config2help Config.in $KCONFIG_CONFIG > generated/help.h || exit 1 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
664
diff
changeset
|
215 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
216 [ ! -z "$NOBUILD" ] && exit 0 |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
217 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
218 echo -n "Compile toybox" |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
219 [ ! -z "$V" ] && echo |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
220 DOTPROG=. |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
221 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
222 # This is a parallel version of: do_loudly $BUILD $FILES $LINK || exit 1 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
223 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
224 X="$(ls -1t generated/obj/* 2>/dev/null | tail -n 1)" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
225 if [ ! -e "$X" ] || [ ! -z "$(find toys -name "*.h" -newer "$X")" ] |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
226 then |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
227 rm -rf generated/obj && mkdir -p generated/obj || exit 1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
228 else |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
229 rm -f generated/obj/{main,lib_help}.o || exit 1 |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
230 fi |
1446
f46ccbcf3f13
Fix parallel make not always catching errors before link time.
Rob Landley <rob@landley.net>
parents:
1428
diff
changeset
|
231 PENDING= |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
232 LFILES= |
1584
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
233 DONE=0 |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
234 for i in $FILES |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
235 do |
1466
aa0ae038e275
Make tweaks: collate generated/*.o files into their own subdirectory, add PIPEFAIL for better error reporting, and simpler regex to select toys/*/*.c list based on NEWTOY/OLDTOY macros.
Rob Landley <rob@landley.net>
parents:
1458
diff
changeset
|
236 # build each generated/obj/*.o file in parallel |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
237 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
238 X=${i/lib\//lib_} |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
239 X=${X##*/} |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
240 OUT="generated/obj/${X%%.c}.o" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
241 LFILES="$LFILES $OUT" |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
242 [ "$OUT" -nt "$i" ] && continue |
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
243 do_loudly $BUILD -c $i -o $OUT & |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
244 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
245 # ratelimit to $CPUS many parallel jobs, detecting errors |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
246 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
247 while true |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
248 do |
1446
f46ccbcf3f13
Fix parallel make not always catching errors before link time.
Rob Landley <rob@landley.net>
parents:
1428
diff
changeset
|
249 PENDING="$(echo $PENDING $(jobs -rp) | tr ' ' '\n' | sort -u)" |
1458 | 250 [ $(echo -n "$PENDING" | wc -l) -lt "$CPUS" ] && break; |
1446
f46ccbcf3f13
Fix parallel make not always catching errors before link time.
Rob Landley <rob@landley.net>
parents:
1428
diff
changeset
|
251 |
1584
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
252 wait $(echo "$PENDING" | head -n 1) |
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
253 DONE=$(($DONE+$?)) |
1446
f46ccbcf3f13
Fix parallel make not always catching errors before link time.
Rob Landley <rob@landley.net>
parents:
1428
diff
changeset
|
254 PENDING="$(echo "$PENDING" | tail -n +2)" |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
255 done |
1584
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
256 [ $DONE -ne 0 ] && break |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
257 done |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
258 |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
259 # wait for all background jobs, detecting errors |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
260 |
1446
f46ccbcf3f13
Fix parallel make not always catching errors before link time.
Rob Landley <rob@landley.net>
parents:
1428
diff
changeset
|
261 for i in $PENDING |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
262 do |
1584
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
263 wait $i |
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
264 DONE=$(($DONE+$?)) |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
265 done |
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
266 |
1584
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
267 [ $DONE -ne 0 ] && exit 1 |
1250bc526316
Improve error reporting in parallel build. (On error, wait for all children to finish before exiting.)
Rob Landley <rob@landley.net>
parents:
1578
diff
changeset
|
268 |
1578
a34104fc7544
Add "make change" target to build the big toybox binary as a bunch of little ones (in the "change" subdirectory), and tweak scripts/make.sh to avoid redundant work when rebuilding.
Rob Landley <rob@landley.net>
parents:
1492
diff
changeset
|
269 do_loudly $BUILD $LFILES $LINK || exit 1 |
512
9bcc288a1c54
Fix from Georgi Chorbadzhiyski to make cross compiling more robust.
Rob Landley <rob@landley.net>
parents:
472
diff
changeset
|
270 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
|
271 # 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
|
272 # its output the way SUSv4 suggests it do so. |
472 | 273 do_loudly chmod +x toybox || exit 1 |
1428
e66fb422b78a
Parallelize the build. (set CPUS=1 to force single processor build, or another number to override processor count autodetect.)
Rob Landley <rob@landley.net>
parents:
1343
diff
changeset
|
274 echo |