3 # Note: was using sed OPTS CMD -- FILES
4 # but users complain that many sed implementations
5 # are misinterpreting --.
7 test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
10 cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
11 # In separate objtree build, include/ might not exist yet
12 mkdir include 2>/dev/null
16 status() { printf ' %-8s%s\n' "$1" "$2"; }
17 gen() { status "GEN" "$@"; }
18 chk() { status "CHK" "$@"; }
22 # NB: data to be inserted at INSERT line is coming on stdin
23 local src="$1" dst="$2" header="$3"
26 # Need to use printf: different shells have inconsistent
27 # rules re handling of "\n" in echo params.
28 printf "%s\n" "${header}"
29 # print everything up to INSERT line
30 sed -n '/^INSERT$/ q; p' "${src}"
31 # copy stdin to stdout
33 # print everything after INSERT line
34 sed -n '/^INSERT$/ { :l; n; p; bl }' "${src}"
36 if ! cmp -s "${dst}" "${dst}.tmp"; then
38 mv "${dst}.tmp" "${dst}"
44 # (Re)generate include/applets.h
45 sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
47 "$srctree/include/applets.src.h" \
49 "/* DO NOT EDIT. This file is generated from applets.src.h */"
51 # (Re)generate include/usage.h
52 # We add line continuation backslash after each line,
53 # and insert empty line before each line which doesn't start
55 sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
57 "$srctree/include/usage.src.h" \
59 "/* DO NOT EDIT. This file is generated from usage.src.h */"
61 # (Re)generate */Kbuild and */Config.in
62 { cd -- "$srctree" && find . -type d; } | while read -r d; do
65 src="$srctree/$d/Kbuild.src"
67 if test -f "$src"; then
68 mkdir -p -- "$d" 2>/dev/null
70 sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
73 "# DO NOT EDIT. This file is generated from Kbuild.src"
76 src="$srctree/$d/Config.src"
78 if test -f "$src"; then
79 mkdir -p -- "$d" 2>/dev/null
81 sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
84 "# DO NOT EDIT. This file is generated from Config.src"
88 # Last read failed. This is normal. Don't exit with its error code: