1This patch is the work of E5ten; Landley doesn't want toybox to be POSIX because
2he's writing his own sh (toysh), and somehow that means the build system
3shouldn't be buildable outside of toybox bootstrapping itself.
4https://github.com/landley/toybox/pull/182
5diff --git a/configure b/configure
6index 0b6501fc..23dd687d 100755
7--- a/configure
8+++ b/configure
9@@ -1,10 +1,10 @@
10-#!/bin/bash
11+#!/bin/sh
12
13 # This sets environment variables used by scripts/make.sh
14
15 # People run ./configure out of habit, so do "defconfig" for them.
16
17-if [ "$(basename "$0")" == configure ]
18+if [ "${0##*/}" = configure ]
19 then
20 echo "Assuming you want 'make defconfig', but you should probably check the README."
21 make defconfig
22diff --git a/scripts/bloatcheck b/scripts/bloatcheck
23index fff4690f..30492c64 100755
24--- a/scripts/bloatcheck
25+++ b/scripts/bloatcheck
26@@ -1,4 +1,4 @@
27-#!/bin/bash
28+#!/bin/sh
29
30 if [ $# -ne 2 ]
31 then
32@@ -40,7 +40,7 @@ do_bloatcheck()
33 fi
34
35 SIZE=$(printf "%d" "0x$b")
36- if [ "$a" == "-" ]
37+ if [ "$a" = "-" ]
38 then
39 OLD=$(($OLD+$SIZE))
40 SIZE=$((-1*$SIZE))
41diff --git a/scripts/change.sh b/scripts/change.sh
42index 99dcfde9..b1fa62a0 100755
43--- a/scripts/change.sh
44+++ b/scripts/change.sh
45@@ -1,4 +1,4 @@
46-#!/bin/bash
47+#!/bin/sh
48
49 # build each command as a standalone executable
50
51@@ -14,8 +14,8 @@ mkdir -p "$PREFIX" || exit 1
52
53 for i in $(generated/instlist | egrep -vw "sh|help")
54 do
55- echo -n " $i" &&
56+ printf ' %s' "$i" &&
57 scripts/single.sh $i > /dev/null 2>$PREFIX/${i}.bad &&
58- rm $PREFIX/${i}.bad || echo -n '*'
59+ rm $PREFIX/${i}.bad || printf '*'
60 done
61 echo
62diff --git a/scripts/findglobals.sh b/scripts/findglobals.sh
63index 2c63164b..9455bc61 100755
64--- a/scripts/findglobals.sh
65+++ b/scripts/findglobals.sh
66@@ -1,4 +1,4 @@
67-#!/bin/bash
68+#!/bin/sh
69
70 # Quick and dirty check to see if anybody's leaked global variables.
71 # We should have this, toy_list, toybuf, and toys.
72diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh
73index 955c82cd..b5cff559 100755
74--- a/scripts/genconfig.sh
75+++ b/scripts/genconfig.sh
76@@ -1,11 +1,11 @@
77-#!/bin/bash
78+#!/bin/sh
79
80 # This has to be a separate file from scripts/make.sh so it can be called
81 # before menuconfig. (It's called again from scripts/make.sh just to be sure.)
82
83 mkdir -p generated
84
85-source scripts/portability.sh
86+. scripts/portability.sh
87
88 probecc()
89 {
90@@ -18,8 +18,8 @@ probesymbol()
91 {
92 probecc $2 2>/dev/null && DEFAULT=y || DEFAULT=n
93 rm a.out 2>/dev/null
94- echo -e "config $1\n\tbool" || exit 1
95- echo -e "\tdefault $DEFAULT\n" || exit 1
96+ printf 'config %s\n\tbool' || exit 1
97+ printf '\tdefault %s\n\n' || exit 1
98 }
99
100 probeconfig()
101@@ -28,7 +28,7 @@ probeconfig()
102 # llvm produces its own really stupid warnings about things that aren't wrong,
103 # and although you can turn the warning off, gcc reacts badly to command line
104 # arguments it doesn't understand. So probe.
105- [ -z "$(probecc -Wno-string-plus-int <<< \#warn warn 2>&1 | grep string-plus-int)" ] &&
106+ [ -z "$(echo '#warn' | probecc -Wno-string-plus-int warn 2>&1 | grep string-plus-int)" ] &&
107 echo -Wno-string-plus-int >> generated/cflags
108
109 # Probe for container support on target
110@@ -92,7 +92,7 @@ EOF
111 #include <unistd.h>
112 int main(int argc, char *argv[]) { return fork(); }
113 EOF
114- echo -e '\tdepends on !TOYBOX_FORCE_NOMMU'
115+ printf '\tdepends on !TOYBOX_FORCE_NOMMU\n'
116
117 probesymbol TOYBOX_PRLIMIT << EOF
118 #include <sys/types.h>
119@@ -155,17 +155,18 @@ PENDING=
120 toys toys/*/*.c | (
121 while IFS=":" read FILE NAME
122 do
123- [ "$NAME" == help ] && continue
124- [ "$NAME" == install ] && continue
125- [ "$NAME" == sh ] && FILE="toys/*/*.c"
126- echo -e "$NAME: $FILE *.[ch] lib/*.[ch]\n\tscripts/single.sh $NAME\n"
127- echo -e "test_$NAME:\n\tscripts/test.sh $NAME\n"
128- [ "${FILE/pending//}" != "$FILE" ] &&
129+ [ "$NAME" = help ] && continue
130+ [ "$NAME" = install ] && continue
131+ [ "$NAME" = sh ] && FILE="toys/*/*.c"
132+ printf '%s: %s *.[ch] lib/*.[ch]\n\tscripts/single.sh %s\n\n' \
133+ "$NAME" "$FILE" "$NAME"
134+ printf 'test_%s:\n\tscripts/test.sh \n\n' "$NAME" "$NAME"
135+ [ "${FILE#*pending}" != "$FILE" ] &&
136 PENDING="$PENDING $NAME" ||
137 WORKING="$WORKING $NAME"
138 done &&
139-echo -e "clean::\n\t@rm -f $WORKING $PENDING" &&
140-echo -e "list:\n\t@echo $(echo $WORKING | tr ' ' '\n' | sort | xargs)" &&
141-echo -e "list_pending:\n\t@echo $(echo $PENDING | tr ' ' '\n' | sort | xargs)" &&
142-echo -e ".PHONY: $WORKING $PENDING" | $SED 's/ \([^ ]\)/ test_\1/g'
143+printf 'clean::\n\t@rm -f %s %s\n' "$WORKING" "$PENDING" &&
144+printf 'list:\n\t@echo %s\n' "$(echo $WORKING | tr ' ' '\n' | sort | xargs)" &&
145+printf 'list_pending:\n\t@echo %s\n' "$(echo $PENDING | tr ' ' '\n' | sort | xargs)" &&
146+echo ".PHONY: $WORKING $PENDING" | $SED 's/ \([^ ]\)/ test_\1/g'
147 ) > .singlemake
148diff --git a/scripts/install.sh b/scripts/install.sh
149index 648a2411..0ee232cd 100755
150--- a/scripts/install.sh
151+++ b/scripts/install.sh
152@@ -1,8 +1,8 @@
153-#!/bin/bash
154+#!/bin/sh
155
156 # Grab default values for $CFLAGS and such.
157
158-source ./configure
159+. ./configure
160
161 [ -z "$PREFIX" ] && PREFIX="/usr/toybox"
162
163@@ -12,19 +12,19 @@ LONG_PATH=""
164 while [ ! -z "$1" ]
165 do
166 # Create symlinks instead of hardlinks?
167- [ "$1" == "--symlink" ] && LINK_TYPE="-s"
168+ [ "$1" = "--symlink" ] && LINK_TYPE="-s"
169
170 # Uninstall?
171- [ "$1" == "--uninstall" ] && UNINSTALL=Uninstall
172+ [ "$1" = "--uninstall" ] && UNINSTALL=Uninstall
173
174 # Delete destination command if it exists?
175- [ "$1" == "--force" ] && DO_FORCE="-f"
176+ [ "$1" = "--force" ] && DO_FORCE="-f"
177
178 # Use {,usr}/{bin,sbin} paths instead of all files in one directory?
179- [ "$1" == "--long" ] && LONG_PATH="bin/"
180+ [ "$1" = "--long" ] && LONG_PATH="bin/"
181
182 # Symlink host toolchain binaries to destination to create cross compile $PATH
183- [ "$1" == "--airlock" ] && AIRLOCK=1
184+ [ "$1" = "--airlock" ] && AIRLOCK=1
185
186 shift
187 done
188@@ -131,7 +131,7 @@ do
189 fi
190
191 X=$[$X+1]
192- FALLBACK="$PREFIX/fallback-$X"
193+ FALLBACK="$PREFIX/fallback-$((X += 1))"
194 done
195
196 if [ ! -f "$PREFIX/$i" ]
197diff --git a/scripts/make.sh b/scripts/make.sh
198index 5b2d5d81..68fcbc2d 100755
199--- a/scripts/make.sh
200+++ b/scripts/make.sh
201@@ -1,4 +1,4 @@
202-#!/bin/bash
203+#!/bin/sh
204
205 # Grab default values for $CFLAGS and such.
206
207@@ -16,8 +16,7 @@ fi
208
209 export LANG=c
210 export LC_ALL=C
211-set -o pipefail
212-source scripts/portability.sh
213+. scripts/portability.sh
214
215 [ -z "$KCONFIG_CONFIG" ] && KCONFIG_CONFIG=.config
216 [ -z "$OUTNAME" ] && OUTNAME=toybox"${TARGET:+-$TARGET}"
217@@ -31,7 +30,7 @@ UNSTRIPPED="generated/unstripped/$(basename "$OUTNAME")"
218 DOTPROG=
219 do_loudly()
220 {
221- [ ! -z "$V" ] && echo "$@" || echo -n "$DOTPROG"
222+ [ ! -z "$V" ] && echo "$@" || printf '%s' "$DOTPROG"
223 "$@"
224 }
225
226@@ -60,7 +59,7 @@ fi
227
228 if isnewer generated/newtoys.h toys
229 then
230- echo -n "generated/newtoys.h "
231+ printf 'generated/newtoys.h '
232
233 echo "USE_TOYBOX(NEWTOY(toybox, NULL, TOYFLAG_STAYROOT))" > generated/newtoys.h
234 $SED -n -e 's/^USE_[A-Z0-9_]*(/&/p' toys/*/*.c \
235@@ -83,9 +82,9 @@ BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE $GITHASH)"
236 LIBFILES="$(ls lib/*.c | grep -v lib/help.c)"
237 TOYFILES="lib/help.c main.c $TOYFILES"
238
239-if [ "${TOYFILES/pending//}" != "$TOYFILES" ]
240+if [ "${TOYFILES#*pending}" != "$TOYFILES" ]
241 then
242- echo -e "\n\033[1;31mwarning: using unfinished code from toys/pending\033[0m"
243+ printf '\n\033[1;31mwarning: using unfinished code from toys/pending\033[0m\n'
244 fi
245
246 genbuildsh()
247@@ -106,10 +105,10 @@ genbuildsh()
248 echo '$BUILD $FILES $LINK'
249 }
250
251-if ! cmp -s <(genbuildsh 2>/dev/null | head -n 6 ; echo LINK="'"$LDOPTIMIZE $LDFLAGS) \
252- <(head -n 7 generated/build.sh 2>/dev/null | $SED '7s/ -o .*//')
253+if [ "$(genbuildsh 2>/dev/null | head -n 6 ; echo LINK="'"$LDOPTIMIZE $LDFLAGS)" != \
254+ "$(head -n 7 generated/build.sh 2>/dev/null | $SED '7s/ -o .*//')" ]
255 then
256- echo -n "Library probe"
257+ printf 'Library probe'
258
259 # We trust --as-needed to remove each library if we don't use any symbols
260 # out of it, this loop is because the compiler has no way to ignore a library
261@@ -122,7 +121,7 @@ then
262 echo "int main(int argc, char *argv[]) {return 0;}" | \
263 ${CROSS_COMPILE}${CC} $CFLAGS $LDFLAGS -xc - -o generated/libprobe $LDASNEEDED -l$i > /dev/null 2>/dev/null &&
264 echo -l$i >> generated/optlibs.dat
265- echo -n .
266+ printf .
267 done
268 rm -f generated/libprobe
269 echo
270@@ -185,7 +184,7 @@ make_flagsh()
271
272 echo "#define NEWTOY(aa,bb,cc) aa $I bb"
273 echo '#define OLDTOY(...)'
274- if [ "$I" == A ]
275+ if [ "$I" = A ]
276 then
277 cat generated/config.h
278 else
279@@ -215,13 +214,13 @@ make_flagsh()
280
281 if isnewer generated/flags.h toys "$KCONFIG_CONFIG"
282 then
283- echo -n "generated/flags.h "
284+ printf 'generated/flags.h '
285 make_flagsh
286 fi
287
288 # Extract global structure definitions and flag definitions from toys/*/*.c
289
290-function getglobals()
291+getglobals()
292 {
293 for i in toys/*/*.c
294 do
295@@ -230,13 +229,13 @@ function getglobals()
296 -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
297 -e 's/^)/};/' -e 'p' $i)"
298
299- [ ! -z "$DATA" ] && echo -e "// $i\n\n$DATA\n"
300+ [ ! -z "$DATA" ] && printf '// %s\n\n%s\n\n' "$i" "$DATA"
301 done
302 }
303
304 if isnewer generated/globals.h toys
305 then
306- echo -n "generated/globals.h "
307+ printf 'generated/globals.h '
308 GLOBSTRUCT="$(getglobals)"
309 (
310 echo "$GLOBSTRUCT"
311@@ -255,7 +254,7 @@ fi
312
313 if isnewer generated/tags.h toys
314 then
315- echo -n "generated/tags.h "
316+ printf 'generated/tags.h '
317
318 $SED -n '/TAGGED_ARRAY(/,/^)/{s/.*TAGGED_ARRAY[(]\([^,]*\),/\1/;p}' \
319 toys/*/*.c lib/*.c | generated/mktags > generated/tags.h
320@@ -273,7 +272,7 @@ fi
321
322 [ ! -z "$NOBUILD" ] && exit 0
323
324-echo -n "Compile $OUTNAME"
325+printf 'Compile $OUTNAME'
326 [ ! -z "$V" ] && echo
327 DOTPROG=.
328
329@@ -286,7 +285,7 @@ if [ ! -e "$X" ] || [ ! -z "$(find toys -name "*.h" -newer "$X")" ]
330 then
331 rm -rf generated/obj && mkdir -p generated/obj || exit 1
332 else
333- rm -f generated/obj/{main,lib_help}.o || exit 1
334+ rm -f generated/obj/main.o generated/obj/lib_help.o || exit 1
335 fi
336
337 # build each generated/obj/*.o file in parallel
338@@ -299,9 +298,10 @@ CLICK=
339
340 for i in $LIBFILES click $TOYFILES
341 do
342- [ "$i" == click ] && CLICK=1 && continue
343+ [ "$i" = click ] && CLICK=1 && continue
344
345- X=${i/lib\//lib_}
346+ X="$i"
347+ [ "${X#*lib/}" = "$X" ] || X="${X%%lib/*}lib_${X#*lib/}"
348 X=${X##*/}
349 OUT="generated/obj/${X%%.c}.o"
350 LNKFILES="$LNKFILES $OUT"
351@@ -309,8 +309,9 @@ do
352 # $LIBFILES doesn't need to be rebuilt if older than .config, $TOYFILES does
353 # ($TOYFILES contents can depend on CONFIG symbols, lib/*.c never should.)
354
355- [ "$OUT" -nt "$i" ] && [ -z "$CLICK" -o "$OUT" -nt "$KCONFIG_CONFIG" ] &&
356- continue
357+ [ -n "$(find "$OUT" -newer "$i" 2>/dev/null)" ] &&
358+ { [ -z "$CLICK" ] || [ -n "$(find "$OUT" -newer "$KCONFIG_CONFIG" 2>/dev/null)" ]; } &&
359+ continue
360
361 do_loudly $BUILD -c $i -o $OUT &
362 PENDING="$PENDING $!"
363diff --git a/scripts/mcm-buildall.sh b/scripts/mcm-buildall.sh
364index cac41372..4075872f 100755
365--- a/scripts/mcm-buildall.sh
366+++ b/scripts/mcm-buildall.sh
367@@ -1,4 +1,4 @@
368-#!/bin/bash
369+#!/bin/sh
370
371 # Script to build all cross and native compilers supported by musl-libc.
372 # This isn't directly used by toybox, but is useful for testing.
373@@ -22,7 +22,7 @@ BOOTSTRAP=i686-linux-musl
374
375 [ -z "$OUTPUT" ] && OUTPUT="$PWD/ccc"
376
377-if [ "$1" == clean ]
378+if [ "$1" = clean ]
379 then
380 rm -rf "$OUTPUT" host-* *.log
381 make clean
382@@ -38,7 +38,7 @@ make_toolchain()
383 OUTPUT="$PWD/host-$TARGET"
384 EXTRASUB=y
385 else
386- if [ "$TYPE" == static ]
387+ if [ "$TYPE" = static ]
388 then
389 HOST=$BOOTSTRAP
390 [ "$TARGET" = "$HOST" ] && LP="$PWD/host-$HOST/bin:$LP"
391@@ -53,7 +53,9 @@ make_toolchain()
392 echo "no $TARGET-cc in $LP" && return
393 fi
394 COMMON_CONFIG="CC=\"$HOST-gcc -static --static\" CXX=\"$HOST-g++ -static --static\""
395- export -n HOST
396+ _HOST="$HOST"
397+ unset HOST
398+ HOST="$_HOST"
399 OUTPUT="$OUTPUT/${RENAME:-$TARGET}-$TYPE"
400 fi
401
402@@ -66,7 +68,7 @@ make_toolchain()
403 # Change title bar to say what we're currently building
404
405 echo === building $TARGET-$TYPE
406- echo -en "\033]2;$TARGET-$TYPE\007"
407+ printf '\033]2;$TARGET-$TYPE\007' "$TARGET" "$TYPE"
408
409 rm -rf build/"$TARGET" "$OUTPUT" &&
410 [ -z "$CPUS" ] && CPUS=$(($(nproc)+1))
411@@ -76,10 +78,10 @@ make_toolchain()
412 COMMON_CONFIG="CFLAGS=\"$CFLAGS -g0 -Os\" CXXFLAGS=\"$CXXFLAGS -g0 -Os\" LDFLAGS=\"$LDFLAGS -s\" $COMMON_CONFIG" \
413 install -j$CPUS || exit 1
414 set +x
415- echo -e '#ifndef __MUSL__\n#define __MUSL__ 1\n#endif' \
416+ printf '#ifndef __MUSL__\n#define __MUSL__ 1\n#endif\n' \
417 >> "$OUTPUT/${EXTRASUB:+$TARGET/}include/features.h"
418
419- if [ ! -z "$RENAME" ] && [ "$TYPE" == cross ]
420+ if [ ! -z "$RENAME" ] && [ "$TYPE" = cross ]
421 then
422 CONTEXT="output/$RENAME-cross/bin"
423 for i in "$CONTEXT/$TARGET-"*
424@@ -93,7 +95,7 @@ make_toolchain()
425 # $BOOTSTRAP arch
426 [ -z "$TYPE" ] && make clean
427
428- if [ "$TYPE" == native ]
429+ if [ "$TYPE" = native ]
430 then
431 # gcc looks in "../usr/include" but not "/bin/../include" (relative to the
432 # executable). That means /usr/bin/gcc looks in /usr/usr/include, so that's
433@@ -108,14 +110,14 @@ make_toolchain()
434 # Expand compressed target into binutils/gcc "tuple" and call make_toolchain
435 make_tuple()
436 {
437- PART1=${1/:*/}
438- PART3=${1/*:/}
439- PART2=${1:$((${#PART1}+1)):$((${#1}-${#PART3}-${#PART1}-2))}
440+ PART1=${1%%:*}
441+ PART3=${1##*:}
442+ PART2=${1#${PART1}:} PART2+${PART2%:${PART3}}
443
444 # Do we need to rename this toolchain after building it?
445- RENAME=${PART1/*@/}
446- [ "$RENAME" == "$PART1" ] && RENAME=
447- PART1=${PART1/@*/}
448+ RENAME=${PART1##*@}
449+ [ "$RENAME" = "$PART1" ] && RENAME=
450+ PART1=${PART1%%@*}
451 TARGET=${PART1}-linux-musl${PART2}
452
453 [ -z "$NOCLEAN" ] && rm -rf build
454diff --git a/scripts/portability.sh b/scripts/portability.sh
455index 618022c7..63dee932 100644
456--- a/scripts/portability.sh
457+++ b/scripts/portability.sh
458@@ -1,6 +1,6 @@
459 # sourced to find alternate names for things
460
461-source configure
462+. ./configure
463
464 if [ -z "$(command -v "${CROSS_COMPILE}${CC}")" ]
465 then
466diff --git a/scripts/record-commands b/scripts/record-commands
467index 8410966b..f49bcff9 100755
468--- a/scripts/record-commands
469+++ b/scripts/record-commands
470@@ -1,4 +1,4 @@
471-#!/bin/bash
472+#!/bin/sh
473
474 # Set up command recording wrapper
475
476diff --git a/scripts/single.sh b/scripts/single.sh
477index c40c6bcf..473bbdd4 100755
478--- a/scripts/single.sh
479+++ b/scripts/single.sh
480@@ -1,4 +1,4 @@
481-#!/bin/bash
482+#!/bin/sh
483
484 # Build a standalone toybox command
485
486@@ -9,7 +9,7 @@ then
487 fi
488
489 # Add trailing / to PREFIX when it's set but hasn't got one
490-[ "$PREFIX" == "${PREFIX%/}" ] && PREFIX="${PREFIX:+$PREFIX/}"
491+[ "$PREFIX" = "${PREFIX%/}" ] && PREFIX="${PREFIX:+$PREFIX/}"
492
493 # Harvest TOYBOX_* symbols from .config
494 if [ ! -e .config ]
495@@ -24,7 +24,7 @@ touch -c .config
496 export KCONFIG_CONFIG=.singleconfig
497 for i in "$@"
498 do
499- echo -n "$i:"
500+ printf '%s:' "$i"
501 TOYFILE="$(egrep -l "TOY[(]($i)[ ,]" toys/*/*.c)"
502
503 if [ -z "$TOYFILE" ]
504@@ -37,7 +37,7 @@ do
505
506 DEPENDS=
507 MPDEL=
508- if [ "$i" == sh ]
509+ if [ "$i" = sh ]
510 then
511 DEPENDS="$(sed -n 's/USE_\([^(]*\)(NEWTOY([^,]*,.*TOYFLAG_MAYFORK.*/\1/p' toys/*/*.c)"
512 else
513--- a/scripts/mkroot.sh
514+++ b/scripts/mkroot.sh
515@@ -6,7 +6,7 @@
516
517 # assign command line NAME=VALUE args to env vars, keeping rest as packages
518 while [ $# -ne 0 ]; do
519- [ "${1/=/}" != "$1" ] && eval "export ${1/=*/}=\"\${1#*=}\"" ||
520+ [ "${1#*=}" != "$1" ] && eval "export ${1%%=*}=\"\${1#*=}\"" ||
521 { [ "$1" != '--' ] && PKG="${PKG:-plumbing} $1"; }
522 shift
523 done
524@@ -13,6 +13,6 @@
525
526 die() { echo "$@" >&2; exit 1; }
527-announce() { echo -e "\033]2;$CROSS $*\007\n=== $*"; }
528+announce() { printf '\033]2;%s %s\007\n=== %s\n' "$CROSS" "$*"; }
529
530 # Create target-independent working directories (cmdline can change locations)
531 TOP="$PWD/root"
532@@ -22,13 +22,13 @@
533 if [ ! -z "$CROSS" ]; then
534 [ ! -d "${CCC:=$PWD/ccc}" ] && die "No ccc symlink to compiler directory."
535 CROSS_COMPILE="$(echo "$CCC/$CROSS"-*cross/bin/"$CROSS"*-cc | sed 's/cc$//')"
536- if [ "${CROSS::3}" == all ]; then
537+ if [ "${CROSS::3}" = all ]; then
538 for i in $(ls "$CCC" | sed -n 's/-.*//p' | sort -u | xargs); do
539- { rm -f "$LOG/$i-log".{failed,success}
540- "$0" "$@" CROSS=$i ; [ $? -eq 0 ] && mv "$LOG/$i".{txt,success}
541- } |& tee "$LOG/$i.txt"
542+ { rm -f "$LOG/$i-logfailed" "$LOG/$i-log.success"
543+ "$0" "$@" CROSS=$i ; [ $? -eq 0 ] && mv "$LOG/$i.txt" "$LOG/$i.success"
544+ } 2>&1 | tee "$LOG/$i.txt"
545 [ ! -e "$LOG/$i.success" ] &&
546- { mv "$LOG/$i".{txt,failed};[ "$CROSS" != allnonstop ] && exit 1; }
547+ { mv "$LOG/$i.txt" "$LOG/$i.failed";[ "$CROSS" != allnonstop ] && exit 1; }
548 done
549 exit
550 elif [ ! -e "${CROSS_COMPILE}cc" ]; then
551@@ -37,8 +37,8 @@
552 fi
553 fi
554
555-${CROSS_COMPILE}cc --static -xc - -o /dev/null <<< "int main(void){return 0;}"||
556- die "${CROSS_COMPILE}cc can't create static binaries"
557+! echo 'int main(void) {return 0;}' | cc --static -cx - -o /dev/null ||
558+ die "Warning: host compiler can't create static binaries." >&2; sleep 3
559
560 # Parse and sanity check $CROSS_COMPILE (if any)
561 if [ ! -z "$CROSS_COMPILE" ]; then
562@@ -45,6 +45,6 @@
563 CROSS_PATH="$(dirname "$(which "${CROSS_COMPILE}cc")")"
564 [ -z "$CROSS_PATH" ] && die "no ${CROSS_COMPILE}cc in path"
565- : ${CROSS_BASE:=$(basename "$CROSS_COMPILE")} ${CROSS:=${CROSS_BASE/-*/}}
566+ : ${CROSS_BASE:=$(basename "$CROSS_COMPILE")} ${CROSS:=${CROSS_BASE/%%-*/}}
567 fi
568 echo "Building for ${CROSS:=host}"
569
570@@ -65,8 +65,10 @@
571 fi
572
573 # Create new root filesystem's directory layout
574-mkdir -p "$ROOT"/{etc,tmp,proc,sys,dev,home,mnt,root,usr/{bin,sbin,lib},var} &&
575-chmod a+rwxt "$ROOT"/tmp && ln -s usr/{bin,sbin,lib} "$ROOT" || exit 1
576+mkdir -p "$ROOT/etc" "$ROOT/tmp" "$ROOT/proc" "$ROOT/sys" "$ROOT/dev" \
577+ "$ROOT/home" "$ROOT/mnt" "$ROOT/root" "$ROOT/usr/bin" "$ROOT/usr/sbin" \
578+ "$ROOT/usr/lib" "$ROOT/var"
579+chmod a+rwxt "$ROOT"/tmp && ln -s usr/bin usr/sbin usr/lib "$ROOT" || exit 1
580
581 # Write init script. Runs as pid 1 from initramfs to set up and hand off system.
582 cat > "$ROOT"/init << 'EOF' &&
583@@ -114,7 +116,7 @@
584 guest:x:500:500:guest:/home/guest:/bin/sh
585 nobody:x:65534:65534:nobody:/proc/self:/dev/null
586 EOF
587-echo -e 'root:x:0:\nguest:x:500:\nnobody:x:65534:' > "$ROOT"/etc/group || exit 1
588+printf 'root:x:0:\nguest:x:500:\nnobody:x:65534:\n' > "$ROOT"/etc/group || exit 1
589
590 # Build static toybox with existing .config if there is one, else defconfig+sh
591 announce toybox
592@@ -133,7 +135,7 @@
593 else
594 # Which architecture are we building a kernel for?
595 LINUX="$(realpath "$LINUX")"
596- [ -z "$TARGET" ] && TARGET="${CROSS_BASE/-*/}"
597+ [ -z "$TARGET" ] && TARGET="${CROSS_BASE%%-*/}"
598 [ -z "$TARGET" ] && TARGET="$(uname -m)"
599
600 # Target-specific info in an (alphabetical order) if/else staircase
601@@ -140,6 +142,6 @@
602 # Each target needs board config, serial console, RTC, ethernet, block device.
603
604- if [ "$TARGET" == armv5l ]; then
605+ if [ "$TARGET" = armv5l ]; then
606 # This could use the same VIRT board as armv7, but let's demonstrate a
607 # different one requiring a separate device tree binary.
608 QEMU="arm -M versatilepb -net nic,model=rtl8139 -net user"
609@@ -147,8 +149,8 @@
610 KCONF=CPU_ARM926T,MMU,VFP,ARM_THUMB,AEABI,ARCH_VERSATILE,ATAGS,DEPRECATED_PARAM_STRUCT,ARM_ATAG_DTB_COMPAT,ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_DRV_PL031,RTC_HCTOSYS,PCI,PCI_VERSATILE,BLK_DEV_SD,SCSI,SCSI_LOWLEVEL,SCSI_SYM53C8XX_2,SCSI_SYM53C8XX_MMIO,NET_VENDOR_REALTEK,8139CP
611 KERNEL_CONFIG="CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0"
612 DTB=arch/arm/boot/dts/versatile-pb.dtb
613- elif [ "$TARGET" == armv7l ] || [ "$TARGET" == aarch64 ]; then
614- if [ "$TARGET" == aarch64 ]; then
615+ elif [ "$TARGET" = armv7l ] || [ "$TARGET" = aarch64 ]; then
616+ if [ "$TARGET" = aarch64 ]; then
617 QEMU="aarch64 -M virt -cpu cortex-a57"
618 KARCH=arm64 VMLINUX=arch/arm64/boot/Image
619 else
620@@ -156,11 +158,11 @@
621 fi
622 KARGS=ttyAMA0
623 KCONF=MMU,ARCH_MULTI_V7,ARCH_VIRT,SOC_DRA7XX,ARCH_OMAP2PLUS_TYPICAL,ARCH_ALPINE,ARM_THUMB,VDSO,CPU_IDLE,ARM_CPUIDLE,KERNEL_MODE_NEON,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_HCTOSYS,RTC_DRV_PL031,NET_CORE,VIRTIO_MENU,VIRTIO_NET,PCI,PCI_HOST_GENERIC,VIRTIO_BLK,VIRTIO_PCI,VIRTIO_MMIO,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,PATA_PLATFORM,PATA_OF_PLATFORM,ATA_GENERIC
624- elif [ "$TARGET" == i486 ] || [ "$TARGET" == i686 ] ||
625- [ "$TARGET" == x86_64 ] || [ "$TARGET" == x32 ]; then
626- if [ "$TARGET" == i486 ]; then
627+ elif [ "$TARGET" = i486 ] || [ "$TARGET" = i686 ] ||
628+ [ "$TARGET" = x86_64 ] || [ "$TARGET" = x32 ]; then
629+ if [ "$TARGET" = i486 ]; then
630 QEMU="i386 -cpu 486 -global fw_cfg.dma_enabled=false" KCONF=M486
631- elif [ "$TARGET" == i686 ]; then
632+ elif [ "$TARGET" = i686 ]; then
633 QEMU="i386 -cpu pentium3" KCONF=MPENTIUMII
634 else
635 QEMU=x86_64 KCONF=64BIT
636@@ -167,4 +169,4 @@
637- [ "$TARGET" == x32 ] && KCONF=X86_X32
638+ [ "$TARGET" = x32 ] && KCONF=X86_X32
639 fi
640 KARCH=x86 KARGS=ttyS0 VMLINUX=arch/x86/boot/bzImage
641 KCONF=$KCONF,UNWINDER_FRAME_POINTER,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_INTEL,E1000,SERIAL_8250,SERIAL_8250_CONSOLE,RTC_CLASS
642@@ -171,15 +173,15 @@
643- elif [ "$TARGET" == m68k ]; then
644+ elif [ "$TARGET" = m68k ]; then
645 QEMU="m68k -M q800" KARCH=m68k KARGS=ttyS0 VMLINUX=vmlinux
646 KCONF=MMU,M68040,M68KFPU_EMU,MAC,SCSI_MAC_ESP,MACINTOSH_DRIVERS,ADB,ADB_MACII,NET_CORE,MACSONIC,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE
647- elif [ "$TARGET" == mips ] || [ "$TARGET" == mipsel ]; then
648+ elif [ "$TARGET" = mips ] || [ "$TARGET" = mipsel ]; then
649 QEMU="mips -M malta" KARCH=mips KARGS=ttyS0 VMLINUX=vmlinux
650 KCONF=MIPS_MALTA,CPU_MIPS32_R2,SERIAL_8250,SERIAL_8250_CONSOLE,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_AMD,PCNET32,POWER_RESET,POWER_RESET_SYSCON
651- [ "$TARGET" == mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
652+ [ "$TARGET" = mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
653 QEMU="mipsel -M malta"
654- elif [ "$TARGET" == powerpc ]; then
655+ elif [ "$TARGET" = powerpc ]; then
656 KARCH=powerpc QEMU="ppc -M g3beige" KARGS=ttyS0 VMLINUX=vmlinux
657 KCONF=ALTIVEC,PPC_PMAC,PPC_OF_BOOT_TRAMPOLINE,IDE,IDE_GD,IDE_GD_ATA,BLK_DEV_IDE_PMAC,BLK_DEV_IDE_PMAC_ATA100FIRST,MACINTOSH_DRIVERS,ADB,ADB_CUDA,NET_VENDOR_NATSEMI,NET_VENDOR_8390,NE2K_PCI,SERIO,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE,BOOTX_TEXT
658- elif [ "$TARGET" == powerpc64le ]; then
659+ elif [ "$TARGET" = powerpc64le ]; then
660 KARCH=powerpc QEMU="ppc64 -M pseries -vga none" KARGS=hvc0
661 VMLINUX=vmlinux
662 KCONF=PPC64,PPC_PSERIES,CPU_LITTLE_ENDIAN,PPC_OF_BOOT_TRAMPOLINE,BLK_DEV_SD,SCSI_LOWLEVEL,SCSI_IBMVSCSI,ATA,NET_VENDOR_IBM,IBMVETH,HVC_CONSOLE,PPC_TRANSACTIONAL_MEM,PPC_DISABLE_WERROR,SECTION_MISMATCH_WARN_ONLY
663@@ -186,7 +188,7 @@
664 elif [ "$TARGET" = s390x ]; then
665 QEMU="s390x" KARCH=s390 VMLINUX=arch/s390/boot/bzImage
666 KCONF=MARCH_Z900,PACK_STACK,NET_CORE,VIRTIO_NET,VIRTIO_BLK,SCLP_TTY,SCLP_CONSOLE,SCLP_VT220_TTY,SCLP_VT220_CONSOLE,S390_GUEST
667- elif [ "$TARGET" == sh2eb ]; then
668+ elif [ "$TARGET" = sh2eb ]; then
669 KARCH=sh VMLINUX=vmlinux KERNEL_CONFIG='CONFIG_MEMORY_START=0x10000000
670 CONFIG_CMDLINE="console=ttyUL0 earlycon"' BUILTIN=1
671 KCONF=CPU_SUBTYPE_J2,CPU_BIG_ENDIAN,SH_JCORE_SOC,SMP,BINFMT_ELF_FDPIC,JCORE_EMAC,SERIAL_UARTLITE,SERIAL_UARTLITE_CONSOLE,HZ_100,CMDLINE_OVERWRITE,SPI,SPI_JCORE,MMC,PWRSEQ_SIMPLE,MMC_BLOCK,MMC_SPI
672@@ -193,4 +195,4 @@
673- elif [ "$TARGET" == sh4 ]; then
674+ elif [ "$TARGET" = sh4 ]; then
675 QEMU="sh4 -M r2d -serial null -serial mon:stdio" KARCH=sh
676 KARGS="ttySC1 noiotrap" VMLINUX=arch/sh/boot/zImage
677 KERNEL_CONFIG="CONFIG_MEMORY_START=0x0c000000"
678@@ -205,7 +207,7 @@
679 echo qemu-system-"$QEMU" '"$@"' $QEMU_MORE -nographic -no-reboot -m 256 \
680 -kernel $(basename $VMLINUX) $INITRD \
681 "-append \"panic=1 HOST=$TARGET console=$KARGS \$KARGS\"" \
682- ${DTB:+-dtb "$(basename "$DTB")"} ";echo -e '\e[?7h'" \
683+ ${DTB:+-dtb "$(basename "$DTB")"} ";printf '\033[?7h\n'" \
684 > "$OUTPUT/qemu-$TARGET.sh" &&
685 chmod +x "$OUTPUT/qemu-$TARGET.sh" || exit 1
686 fi
687@@ -212,7 +214,8 @@
688
689 announce "linux-$KARCH"
690- pushd "$LINUX" && make distclean && popd &&
691- cp -sfR "$LINUX" "$MYBUILD/linux" && pushd "$MYBUILD/linux" &&
692+ dir="$PWD"
693+ cd "$LINUX" && make distclean && cd "$dir" &&
694+ cp -sfR "$LINUX" "$MYBUILD/linux" && cd "$MYBUILD/linux" &&
695
696 # Write miniconfig
697 { echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=$TARGET.miniconf"
698@@ -219,4 +222,4 @@
699- echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n"
700+ printf "# make ARCH=%s -j \$(nproc)\n# boot %s\n\n\n" "$KARCH" "$VMLINUX"
701 echo "# CONFIG_EMBEDDED is not set"
702
703 # Expand list of =y symbols, first generic then architecture-specific
704@@ -223,6 +226,6 @@
705 for i in BINFMT_ELF,BINFMT_SCRIPT,NO_HZ,HIGH_RES_TIMERS,BLK_DEV,BLK_DEV_INITRD,RD_GZIP,BLK_DEV_LOOP,EXT4_FS,EXT4_USE_FOR_EXT2,VFAT_FS,FAT_DEFAULT_UTF8,MISC_FILESYSTEMS,SQUASHFS,SQUASHFS_XATTR,SQUASHFS_ZLIB,DEVTMPFS,DEVTMPFS_MOUNT,TMPFS,TMPFS_POSIX_ACL,NET,PACKET,UNIX,INET,IPV6,NETDEVICES,NET_CORE,NETCONSOLE,ETHERNET,COMPAT_32BIT_TIME,EARLY_PRINTK,IKCONFIG,IKCONFIG_PROC $KCONF ; do
706 echo "# architecture ${X:-independent}"
707- sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1=y\n/g' <<< "$i"
708+ echo "$i" | sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1=y\n/g'
709 X=specific
710 done
711 [ ! -z "$BUILTIN" ] && echo -e CONFIG_INITRAMFS_SOURCE="\"$OUTPUT/fs\""
712@@ -232,9 +235,10 @@
713
714 # Second config pass to remove stupid kernel defaults
715 # See http://lkml.iu.edu/hypermail/linux/kernel/1912.3/03493.html
716- sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(sed -E -e '/^$/d' \
717- -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set/\n@g' \
718- <<< VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU)" -i .config &&
719+ sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(echo \
720+ 'VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU' | sed -E -e '/^$/d' \
721+ -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set/\n@g')" \
722+ -i .config &&
723 yes "" | make ARCH=$KARCH oldconfig > /dev/null &&
724
725 # Build kernel. Copy config, device tree binary, and kernel binary to output
726@@ -241,7 +245,7 @@
727 make ARCH=$KARCH CROSS_COMPILE="$CROSS_COMPILE" -j $(nproc) &&
728 cp .config "$OUTPUT/linux-fullconfig" || exit 1
729 [ ! -z "$DTB" ] && { cp "$DTB" "$OUTPUT" || exit 1 ;}
730- cp "$VMLINUX" "$OUTPUT" && cd .. && rm -rf linux && popd || exit 1
731+ cp "$VMLINUX" "$OUTPUT" && cd .. && rm -rf linux && "$dir" || exit 1
732 fi
733
734 # clean up and package root filesystem for initramfs.