[2725] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
[3232] | 3 | # Note: was using sed OPTS CMD -- FILES
|
---|
| 4 | # but users complain that many sed implementations
|
---|
| 5 | # are misinterpreting --.
|
---|
| 6 |
|
---|
[2725] | 7 | test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
|
---|
| 8 |
|
---|
| 9 | # cd to objtree
|
---|
| 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
|
---|
| 13 |
|
---|
| 14 | srctree="$1"
|
---|
| 15 |
|
---|
| 16 | status() { printf ' %-8s%s\n' "$1" "$2"; }
|
---|
| 17 | gen() { status "GEN" "$@"; }
|
---|
| 18 | chk() { status "CHK" "$@"; }
|
---|
| 19 |
|
---|
| 20 | generate()
|
---|
| 21 | {
|
---|
[3232] | 22 | # NB: data to be inserted at INSERT line is coming on stdin
|
---|
| 23 | local src="$1" dst="$2" header="$3"
|
---|
[2725] | 24 | #chk "${dst}"
|
---|
[3232] | 25 | {
|
---|
| 26 | # Need to use printf: different shells have inconsistent
|
---|
| 27 | # rules re handling of "\n" in echo params.
|
---|
[2725] | 28 | printf "%s\n" "${header}"
|
---|
[3232] | 29 | # print everything up to INSERT line
|
---|
| 30 | sed -n '/^INSERT$/ q; p' "${src}"
|
---|
| 31 | # copy stdin to stdout
|
---|
| 32 | cat
|
---|
| 33 | # print everything after INSERT line
|
---|
[3621] | 34 | sed -n '/^INSERT$/ {
|
---|
| 35 | :l
|
---|
| 36 | n
|
---|
| 37 | p
|
---|
| 38 | bl
|
---|
| 39 | }' "${src}"
|
---|
[3232] | 40 | } >"${dst}.tmp"
|
---|
[2725] | 41 | if ! cmp -s "${dst}" "${dst}.tmp"; then
|
---|
| 42 | gen "${dst}"
|
---|
| 43 | mv "${dst}.tmp" "${dst}"
|
---|
| 44 | else
|
---|
| 45 | rm -f "${dst}.tmp"
|
---|
| 46 | fi
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | # (Re)generate include/applets.h
|
---|
[3232] | 50 | sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
|
---|
| 51 | | generate \
|
---|
[2725] | 52 | "$srctree/include/applets.src.h" \
|
---|
| 53 | "include/applets.h" \
|
---|
[3232] | 54 | "/* DO NOT EDIT. This file is generated from applets.src.h */"
|
---|
[2725] | 55 |
|
---|
| 56 | # (Re)generate include/usage.h
|
---|
| 57 | # We add line continuation backslash after each line,
|
---|
| 58 | # and insert empty line before each line which doesn't start
|
---|
| 59 | # with space or tab
|
---|
[3621] | 60 | TAB="$(printf '\tX')"
|
---|
| 61 | TAB="${TAB%X}"
|
---|
| 62 | LF="$(printf '\nX')"
|
---|
| 63 | LF="${LF%X}"
|
---|
| 64 | sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \
|
---|
| 65 | -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \
|
---|
[3232] | 66 | "$srctree"/*/*.c "$srctree"/*/*/*.c \
|
---|
| 67 | | generate \
|
---|
[2725] | 68 | "$srctree/include/usage.src.h" \
|
---|
| 69 | "include/usage.h" \
|
---|
[3232] | 70 | "/* DO NOT EDIT. This file is generated from usage.src.h */"
|
---|
[2725] | 71 |
|
---|
| 72 | # (Re)generate */Kbuild and */Config.in
|
---|
[3232] | 73 | # We skip .dotdirs - makes git/svn/etc users happier
|
---|
[3621] | 74 | { cd -- "$srctree" && find . -type d ! '(' -name '.?*' -prune ')'; } \
|
---|
[3232] | 75 | | while read -r d; do
|
---|
[2725] | 76 | d="${d#./}"
|
---|
| 77 |
|
---|
| 78 | src="$srctree/$d/Kbuild.src"
|
---|
| 79 | dst="$d/Kbuild"
|
---|
| 80 | if test -f "$src"; then
|
---|
| 81 | mkdir -p -- "$d" 2>/dev/null
|
---|
| 82 |
|
---|
[3232] | 83 | sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
|
---|
| 84 | | generate \
|
---|
[2725] | 85 | "${src}" "${dst}" \
|
---|
[3232] | 86 | "# DO NOT EDIT. This file is generated from Kbuild.src"
|
---|
[2725] | 87 | fi
|
---|
| 88 |
|
---|
| 89 | src="$srctree/$d/Config.src"
|
---|
| 90 | dst="$d/Config.in"
|
---|
| 91 | if test -f "$src"; then
|
---|
| 92 | mkdir -p -- "$d" 2>/dev/null
|
---|
| 93 |
|
---|
[3232] | 94 | sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
|
---|
| 95 | | generate \
|
---|
[2725] | 96 | "${src}" "${dst}" \
|
---|
[3232] | 97 | "# DO NOT EDIT. This file is generated from Config.src"
|
---|
[2725] | 98 | fi
|
---|
| 99 | done
|
---|
| 100 |
|
---|
| 101 | # Last read failed. This is normal. Don't exit with its error code:
|
---|
| 102 | exit 0
|
---|