hblock: bump to 3.4.0
[kiss-trunc88.git] / toybox.mine / patches / POSIX.patch
blob7269a7cb2027040e3cea8aa9c7d0b4f6abecdd43
1 This patch is the work of E5ten; Landley doesn't want toybox to be POSIX because
2 he's writing his own sh (toysh), and somehow that means the build system
3 shouldn't be buildable outside of toybox bootstrapping itself.
4 https://github.com/landley/toybox/pull/182
5 diff --git a/configure b/configure
6 index 0b6501fc..23dd687d 100755
7 --- a/configure
8 +++ b/configure
9 @@ -1,10 +1,10 @@
10 -#!/bin/bash
11 +#!/bin/sh
13 # This sets environment variables used by scripts/make.sh
15 # People run ./configure out of habit, so do "defconfig" for them.
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
22 diff --git a/scripts/bloatcheck b/scripts/bloatcheck
23 index fff4690f..30492c64 100755
24 --- a/scripts/bloatcheck
25 +++ b/scripts/bloatcheck
26 @@ -1,4 +1,4 @@
27 -#!/bin/bash
28 +#!/bin/sh
30 if [ $# -ne 2 ]
31 then
32 @@ -40,7 +40,7 @@ do_bloatcheck()
35 SIZE=$(printf "%d" "0x$b")
36 - if [ "$a" == "-" ]
37 + if [ "$a" = "-" ]
38 then
39 OLD=$(($OLD+$SIZE))
40 SIZE=$((-1*$SIZE))
41 diff --git a/scripts/change.sh b/scripts/change.sh
42 index 99dcfde9..b1fa62a0 100755
43 --- a/scripts/change.sh
44 +++ b/scripts/change.sh
45 @@ -1,4 +1,4 @@
46 -#!/bin/bash
47 +#!/bin/sh
49 # build each command as a standalone executable
51 @@ -14,8 +14,8 @@ mkdir -p "$PREFIX" || exit 1
53 for i in $(generated/instlist | egrep -vw "sh|help")
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
62 diff --git a/scripts/findglobals.sh b/scripts/findglobals.sh
63 index 2c63164b..9455bc61 100755
64 --- a/scripts/findglobals.sh
65 +++ b/scripts/findglobals.sh
66 @@ -1,4 +1,4 @@
67 -#!/bin/bash
68 +#!/bin/sh
70 # Quick and dirty check to see if anybody's leaked global variables.
71 # We should have this, toy_list, toybuf, and toys.
72 diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh
73 index 955c82cd..b5cff559 100755
74 --- a/scripts/genconfig.sh
75 +++ b/scripts/genconfig.sh
76 @@ -1,11 +1,11 @@
77 -#!/bin/bash
78 +#!/bin/sh
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.)
83 mkdir -p generated
85 -source scripts/portability.sh
86 +. scripts/portability.sh
88 probecc()
90 @@ -18,8 +18,8 @@ probesymbol()
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
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
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(); }
114 - echo -e '\tdepends on !TOYBOX_FORCE_NOMMU'
115 + printf '\tdepends on !TOYBOX_FORCE_NOMMU\n'
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
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
148 diff --git a/scripts/install.sh b/scripts/install.sh
149 index 648a2411..0ee232cd 100755
150 --- a/scripts/install.sh
151 +++ b/scripts/install.sh
152 @@ -1,8 +1,8 @@
153 -#!/bin/bash
154 +#!/bin/sh
156 # Grab default values for $CFLAGS and such.
158 -source ./configure
159 +. ./configure
161 [ -z "$PREFIX" ] && PREFIX="/usr/toybox"
163 @@ -12,19 +12,19 @@ LONG_PATH=""
164 while [ ! -z "$1" ]
166 # Create symlinks instead of hardlinks?
167 - [ "$1" == "--symlink" ] && LINK_TYPE="-s"
168 + [ "$1" = "--symlink" ] && LINK_TYPE="-s"
170 # Uninstall?
171 - [ "$1" == "--uninstall" ] && UNINSTALL=Uninstall
172 + [ "$1" = "--uninstall" ] && UNINSTALL=Uninstall
174 # Delete destination command if it exists?
175 - [ "$1" == "--force" ] && DO_FORCE="-f"
176 + [ "$1" = "--force" ] && DO_FORCE="-f"
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/"
182 # Symlink host toolchain binaries to destination to create cross compile $PATH
183 - [ "$1" == "--airlock" ] && AIRLOCK=1
184 + [ "$1" = "--airlock" ] && AIRLOCK=1
186 shift
187 done
188 @@ -131,7 +131,7 @@ do
191 X=$[$X+1]
192 - FALLBACK="$PREFIX/fallback-$X"
193 + FALLBACK="$PREFIX/fallback-$((X += 1))"
194 done
196 if [ ! -f "$PREFIX/$i" ]
197 diff --git a/scripts/make.sh b/scripts/make.sh
198 index 5b2d5d81..68fcbc2d 100755
199 --- a/scripts/make.sh
200 +++ b/scripts/make.sh
201 @@ -1,4 +1,4 @@
202 -#!/bin/bash
203 +#!/bin/sh
205 # Grab default values for $CFLAGS and such.
207 @@ -16,8 +16,7 @@ fi
209 export LANG=c
210 export LC_ALL=C
211 -set -o pipefail
212 -source scripts/portability.sh
213 +. scripts/portability.sh
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()
221 - [ ! -z "$V" ] && echo "$@" || echo -n "$DOTPROG"
222 + [ ! -z "$V" ] && echo "$@" || printf '%s' "$DOTPROG"
223 "$@"
226 @@ -60,7 +59,7 @@ fi
228 if isnewer generated/newtoys.h toys
229 then
230 - echo -n "generated/newtoys.h "
231 + printf 'generated/newtoys.h '
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"
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'
246 genbuildsh()
247 @@ -106,10 +105,10 @@ genbuildsh()
248 echo -e "FILES='$LIBFILES $TOYFILES'\n\n\$BUILD \$FILES \$LINK"
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'
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()
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()
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
288 # Extract global structure definitions and flag definitions from toys/*/*.c
290 -function getglobals()
291 +getglobals()
293 for i in toys/*/*.c
295 @@ -230,13 +229,13 @@ function getglobals()
296 -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
297 -e 's/^)/};/' -e 'p' $i)"
299 - [ ! -z "$DATA" ] && echo -e "// $i\n\n$DATA\n"
300 + [ ! -z "$DATA" ] && printf '// %s\n\n%s\n\n' "$i" "$DATA"
301 done
304 if isnewer generated/globals.h toys
305 then
306 - echo -n "generated/globals.h "
307 + printf 'generated/globals.h '
308 GLOBSTRUCT="$(getglobals)"
310 echo "$GLOBSTRUCT"
311 @@ -255,7 +254,7 @@ fi
313 if isnewer generated/tags.h toys
314 then
315 - echo -n "generated/tags.h "
316 + printf 'generated/tags.h '
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
322 [ ! -z "$NOBUILD" ] && exit 0
324 -echo -n "Compile $OUTNAME"
325 +printf 'Compile $OUTNAME'
326 [ ! -z "$V" ] && echo
327 DOTPROG=.
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
337 # build each generated/obj/*.o file in parallel
338 @@ -299,9 +298,10 @@ CLICK=
340 for i in $LIBFILES click $TOYFILES
342 - [ "$i" == click ] && CLICK=1 && continue
343 + [ "$i" = click ] && CLICK=1 && continue
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.)
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
361 do_loudly $BUILD -c $i -o $OUT &
362 PENDING="$PENDING $!"
363 diff --git a/scripts/mcm-buildall.sh b/scripts/mcm-buildall.sh
364 index 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
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
375 [ -z "$OUTPUT" ] && OUTPUT="$PWD/ccc"
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
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"
402 @@ -66,7 +68,7 @@ make_toolchain()
403 # Change title bar to say what we're currently building
405 echo === building $TARGET-$TYPE
406 - echo -en "\033]2;$TARGET-$TYPE\007"
407 + printf '\033]2;$TARGET-$TYPE\007' "$TARGET" "$TYPE"
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"
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
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()
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}}
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}
453 [ -z "$NOCLEAN" ] && rm -rf build
454 diff --git a/scripts/portability.sh b/scripts/portability.sh
455 index 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
461 -source ./configure
462 +. ./configure
464 if [ -z "$(command -v "${CROSS_COMPILE}${CC}")" ]
465 then
466 diff --git a/scripts/record-commands b/scripts/record-commands
467 index 8410966b..f49bcff9 100755
468 --- a/scripts/record-commands
469 +++ b/scripts/record-commands
470 @@ -1,4 +1,4 @@
471 -#!/bin/bash
472 +#!/bin/sh
474 # Set up command recording wrapper
476 diff --git a/scripts/single.sh b/scripts/single.sh
477 index c40c6bcf..473bbdd4 100755
478 --- a/scripts/single.sh
479 +++ b/scripts/single.sh
480 @@ -1,4 +1,4 @@
481 -#!/bin/bash
482 +#!/bin/sh
484 # Build a standalone toybox command
486 @@ -9,7 +9,7 @@ then
487 [ -z "$1" ] && { echo "usage: single.sh command..." >&2; exit 1; }
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/}"
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 "$@"
499 - echo -n "$i:"
500 + printf '%s:' "$i"
501 TOYFILE="$(egrep -l "TOY[(]($i)[ ,]" toys/*/*.c)"
503 if [ -z "$TOYFILE" ]
504 @@ -37,7 +37,7 @@ do
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 @@
517 # assign command line NAME=VALUE args to env vars, the rest are packages
518 for i in "$@"; do
519 - [ "${i/=/}" != "$i" ] && export "$i" || { [ "$i" != -- ] && PKG="$PKG $i"; }
520 + [ "${1#*=}" != "$1" ] && export "$i" || { [ "$i" != -- ] && PKG="$PKG $i"; }
521 done
522 @@ -13,6 +13,6 @@
524 die() { echo "$@" >&2; exit 1; }
525 -announce() { echo -e "\033]2;$CROSS $*\007\n=== $*"; }
526 +announce() { printf '\033]2;%s %s\007\n=== %s\n' "$CROSS" "$*"; }
528 # Create target-independent working directories (cmdline can change locations)
529 TOP="$PWD/root"
530 @@ -22,13 +22,13 @@
531 if [ ! -z "$CROSS" ]; then
532 [ ! -d "${CCC:=$PWD/ccc}" ] && die "No ccc symlink to compiler directory."
533 CROSS_COMPILE="$(echo "$CCC/$CROSS"-*cross/bin/"$CROSS"*-cc | sed 's/cc$//')"
534 - if [ "${CROSS::3}" == all ]; then
535 + if [ "${CROSS::3}" = all ]; then
536 for i in $(ls "$CCC" | sed -n 's/-.*//p' | sort -u | xargs); do
537 - { rm -f "$LOG/$i-log".{failed,success}
538 - "$0" "$@" CROSS=$i ; [ $? -eq 0 ] && mv "$LOG/$i".{txt,success}
539 - } |& tee "$LOG/$i.txt"
540 + { rm -f "$LOG/$i-logfailed" "$LOG/$i-log.success"
541 + "$0" "$@" CROSS=$i ; [ $? -eq 0 ] && mv "$LOG/$i.txt" "$LOG/$i.success"
542 + } 2>&1 | tee "$LOG/$i.txt"
543 [ ! -e "$LOG/$i.success" ] &&
544 - { mv "$LOG/$i".{txt,failed};[ "$CROSS" != allnonstop ] && exit 1; }
545 + { mv "$LOG/$i.txt" "$LOG/$i.failed";[ "$CROSS" != allnonstop ] && exit 1; }
546 done
547 exit
548 elif [ ! -e "${CROSS_COMPILE}cc" ]; then
549 @@ -37,8 +37,8 @@
553 -${CROSS_COMPILE}cc --static -xc - -o /dev/null <<< "int main(void){return 0;}"||
554 - die "${CROSS_COMPILE}cc can't create static binaries"
555 +! echo 'int main(void) {return 0;}' | cc --static -cx - -o /dev/null ||
556 + die "Warning: host compiler can't create static binaries." >&2; sleep 3
558 # Parse and sanity check $CROSS_COMPILE (if any)
559 if [ ! -z "$CROSS_COMPILE" ]; then
560 @@ -45,6 +45,6 @@
561 CROSS_PATH="$(dirname "$(which "${CROSS_COMPILE}cc")")"
562 [ -z "$CROSS_PATH" ] && die "no ${CROSS_COMPILE}cc in path"
563 - : ${CROSS_BASE:=$(basename "$CROSS_COMPILE")} ${CROSS:=${CROSS_BASE/-*/}}
564 + : ${CROSS_BASE:=$(basename "$CROSS_COMPILE")} ${CROSS:=${CROSS_BASE/%%-*/}}
566 echo "Building for ${CROSS:=host}"
568 @@ -65,8 +65,10 @@
571 # Create new root filesystem's directory layout
572 -mkdir -p "$ROOT"/{etc,tmp,proc,sys,dev,home,mnt,root,usr/{bin,sbin,lib},var} &&
573 -chmod a+rwxt "$ROOT"/tmp && ln -s usr/{bin,sbin,lib} "$ROOT" || exit 1
574 +mkdir -p "$ROOT/etc" "$ROOT/tmp" "$ROOT/proc" "$ROOT/sys" "$ROOT/dev" \
575 + "$ROOT/home" "$ROOT/mnt" "$ROOT/root" "$ROOT/usr/bin" "$ROOT/usr/sbin" \
576 + "$ROOT/usr/lib" "$ROOT/var"
577 +chmod a+rwxt "$ROOT"/tmp && ln -s usr/bin usr/sbin usr/lib "$ROOT" || exit 1
579 # Write init script. Runs as pid 1 from initramfs to set up and hand off system.
580 cat > "$ROOT"/init << 'EOF' &&
581 @@ -114,7 +116,7 @@
582 guest:x:500:500:guest:/home/guest:/bin/sh
583 nobody:x:65534:65534:nobody:/proc/self:/dev/null
585 -echo -e 'root:x:0:\nguest:x:500:\nnobody:x:65534:' > "$ROOT"/etc/group || exit 1
586 +printf 'root:x:0:\nguest:x:500:\nnobody:x:65534:\n' > "$ROOT"/etc/group || exit 1
588 # Build static toybox with existing .config if there is one, else defconfig+sh
589 announce toybox
590 @@ -133,7 +135,7 @@
591 else
592 # Which architecture are we building a kernel for?
593 LINUX="$(realpath "$LINUX")"
594 - [ -z "$TARGET" ] && TARGET="${CROSS_BASE/-*/}"
595 + [ -z "$TARGET" ] && TARGET="${CROSS_BASE%%-*/}"
596 [ -z "$TARGET" ] && TARGET="$(uname -m)"
598 # Target-specific info in an (alphabetical order) if/else staircase
599 @@ -140,6 +142,6 @@
600 # Each target needs board config, serial console, RTC, ethernet, block device.
602 - if [ "$TARGET" == armv5l ]; then
603 + if [ "$TARGET" = armv5l ]; then
604 # This could use the same VIRT board as armv7, but let's demonstrate a
605 # different one requiring a separate device tree binary.
606 QEMU="arm -M versatilepb -net nic,model=rtl8139 -net user"
607 @@ -147,8 +149,8 @@
608 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
609 KERNEL_CONFIG="CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0"
610 DTB=arch/arm/boot/dts/versatile-pb.dtb
611 - elif [ "$TARGET" == armv7l ] || [ "$TARGET" == aarch64 ]; then
612 - if [ "$TARGET" == aarch64 ]; then
613 + elif [ "$TARGET" = armv7l ] || [ "$TARGET" = aarch64 ]; then
614 + if [ "$TARGET" = aarch64 ]; then
615 QEMU="aarch64 -M virt -cpu cortex-a57"
616 KARCH=arm64 VMLINUX=arch/arm64/boot/Image
617 else
618 @@ -156,11 +158,11 @@
620 KARGS=ttyAMA0
621 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
622 - elif [ "$TARGET" == i486 ] || [ "$TARGET" == i686 ] ||
623 - [ "$TARGET" == x86_64 ] || [ "$TARGET" == x32 ]; then
624 - if [ "$TARGET" == i486 ]; then
625 + elif [ "$TARGET" = i486 ] || [ "$TARGET" = i686 ] ||
626 + [ "$TARGET" = x86_64 ] || [ "$TARGET" = x32 ]; then
627 + if [ "$TARGET" = i486 ]; then
628 QEMU="i386 -cpu 486 -global fw_cfg.dma_enabled=false" KCONF=M486
629 - elif [ "$TARGET" == i686 ]; then
630 + elif [ "$TARGET" = i686 ]; then
631 QEMU="i386 -cpu pentium3" KCONF=MPENTIUMII
632 else
633 QEMU=x86_64 KCONF=64BIT
634 @@ -167,4 +169,4 @@
635 - [ "$TARGET" == x32 ] && KCONF=X86_X32
636 + [ "$TARGET" = x32 ] && KCONF=X86_X32
638 KARCH=x86 KARGS=ttyS0 VMLINUX=arch/x86/boot/bzImage
639 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
640 @@ -171,15 +173,15 @@
641 - elif [ "$TARGET" == m68k ]; then
642 + elif [ "$TARGET" = m68k ]; then
643 QEMU="m68k -M q800" KARCH=m68k KARGS=ttyS0 VMLINUX=vmlinux
644 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
645 - elif [ "$TARGET" == mips ] || [ "$TARGET" == mipsel ]; then
646 + elif [ "$TARGET" = mips ] || [ "$TARGET" = mipsel ]; then
647 QEMU="mips -M malta" KARCH=mips KARGS=ttyS0 VMLINUX=vmlinux
648 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
649 - [ "$TARGET" == mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
650 + [ "$TARGET" = mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
651 QEMU="mipsel -M malta"
652 - elif [ "$TARGET" == powerpc ]; then
653 + elif [ "$TARGET" = powerpc ]; then
654 KARCH=powerpc QEMU="ppc -M g3beige" KARGS=ttyS0 VMLINUX=vmlinux
655 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
656 - elif [ "$TARGET" == powerpc64le ]; then
657 + elif [ "$TARGET" = powerpc64le ]; then
658 KARCH=powerpc QEMU="ppc64 -M pseries -vga none" KARGS=hvc0
659 VMLINUX=vmlinux
660 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
661 @@ -186,7 +188,7 @@
662 elif [ "$TARGET" = s390x ]; then
663 QEMU="s390x" KARCH=s390 VMLINUX=arch/s390/boot/bzImage
664 KCONF=MARCH_Z900,PACK_STACK,NET_CORE,VIRTIO_NET,VIRTIO_BLK,SCLP_TTY,SCLP_CONSOLE,SCLP_VT220_TTY,SCLP_VT220_CONSOLE,S390_GUEST
665 - elif [ "$TARGET" == sh2eb ]; then
666 + elif [ "$TARGET" = sh2eb ]; then
667 KARCH=sh VMLINUX=vmlinux KERNEL_CONFIG='CONFIG_MEMORY_START=0x10000000
668 CONFIG_CMDLINE="console=ttyUL0 earlycon"' BUILTIN=1
669 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
670 @@ -193,4 +195,4 @@
671 - elif [ "$TARGET" == sh4 ]; then
672 + elif [ "$TARGET" = sh4 ]; then
673 QEMU="sh4 -M r2d -serial null -serial mon:stdio" KARCH=sh
674 KARGS="ttySC1 noiotrap" VMLINUX=arch/sh/boot/zImage
675 KERNEL_CONFIG="CONFIG_MEMORY_START=0x0c000000"
676 @@ -205,7 +207,7 @@
677 echo qemu-system-"$QEMU" '"$@"' $QEMU_MORE -nographic -no-reboot -m 256 \
678 -kernel $(basename $VMLINUX) $INITRD \
679 "-append \"panic=1 HOST=$TARGET console=$KARGS \$KARGS\"" \
680 - ${DTB:+-dtb "$(basename "$DTB")"} ";echo -e '\e[?7h'" \
681 + ${DTB:+-dtb "$(basename "$DTB")"} ";printf '\033[?7h\n'" \
682 > "$OUTPUT/qemu-$TARGET.sh" &&
683 chmod +x "$OUTPUT/qemu-$TARGET.sh" || exit 1
685 @@ -212,7 +214,8 @@
687 announce "linux-$KARCH"
688 - pushd "$LINUX" && make distclean && popd &&
689 - cp -sfR "$LINUX" "$MYBUILD/linux" && pushd "$MYBUILD/linux" &&
690 + dir="$PWD"
691 + cd "$LINUX" && make distclean && cd "$dir" &&
692 + cp -sfR "$LINUX" "$MYBUILD/linux" && cd "$MYBUILD/linux" &&
694 # Write miniconfig
695 { echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=$TARGET.miniconf"
696 @@ -219,4 +222,4 @@
697 - echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n"
698 + printf "# make ARCH=%s -j \$(nproc)\n# boot %s\n\n\n" "$KARCH" "$VMLINUX"
699 echo "# CONFIG_EMBEDDED is not set"
701 # Expand list of =y symbols, first generic then architecture-specific
702 @@ -223,6 +226,6 @@
703 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
704 echo "# architecture ${X:-independent}"
705 - sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1=y\n/g' <<< "$i"
706 + echo "$i" | sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1=y\n/g'
707 X=specific
708 done
709 [ ! -z "$BUILTIN" ] && echo -e CONFIG_INITRAMFS_SOURCE="\"$OUTPUT/fs\""
710 @@ -232,9 +235,10 @@
712 # Second config pass to remove stupid kernel defaults
713 # See http://lkml.iu.edu/hypermail/linux/kernel/1912.3/03493.html
714 - sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(sed -E -e '/^$/d' \
715 - -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set/\n@g' \
716 - <<< VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU)" -i .config &&
717 + sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(echo \
718 + 'VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU' | sed -E -e '/^$/d' \
719 + -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set/\n@g')" \
720 + -i .config &&
721 yes "" | make ARCH=$KARCH oldconfig > /dev/null &&
723 # Build kernel. Copy config, device tree binary, and kernel binary to output
724 @@ -241,7 +245,7 @@
725 make ARCH=$KARCH CROSS_COMPILE="$CROSS_COMPILE" -j $(nproc) &&
726 cp .config "$OUTPUT/linux-fullconfig" || exit 1
727 [ ! -z "$DTB" ] && { cp "$DTB" "$OUTPUT" || exit 1 ;}
728 - cp "$VMLINUX" "$OUTPUT" && cd .. && rm -rf linux && popd || exit 1
729 + cp "$VMLINUX" "$OUTPUT" && cd .. && rm -rf linux && "$dir" || exit 1
732 # clean up and package root filesystem for initramfs.