Denys Vlasenko | 3015a13 | 2010-05-17 01:59:16 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 2 | |
Denys Vlasenko | 572b9a3 | 2010-05-09 16:20:52 +0200 | [diff] [blame] | 3 | test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 4 | |
| 5 | # cd to objtree |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 6 | cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 1883cb1 | 2010-07-09 01:25:36 +0200 | [diff] [blame] | 7 | # In separate objtree build, include/ might not exist yet |
| 8 | mkdir include 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 9 | |
| 10 | srctree="$1" |
| 11 | |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 12 | status() { printf ' %-8s%s\n' "$1" "$2"; } |
| 13 | gen() { status "GEN" "$@"; } |
| 14 | chk() { status "CHK" "$@"; } |
| 15 | |
| 16 | generate() |
| 17 | { |
| 18 | local src="$1" dst="$2" header="$3" insert="$4" |
| 19 | #chk "${dst}" |
| 20 | ( |
Denys Vlasenko | 7a3f8e2 | 2010-11-25 06:55:18 +0100 | [diff] [blame] | 21 | # Need to use printf: different shells have inconsistent |
| 22 | # rules re handling of "\n" in echo params, |
| 23 | # and ${insert} definitely contains "\n". |
| 24 | # Therefore, echo "${header}" would not work: |
Denys Vlasenko | 749e305 | 2010-11-24 15:06:49 +0100 | [diff] [blame] | 25 | printf "%s\n" "${header}" |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 26 | if grep -qs '^INSERT$' "${src}"; then |
| 27 | sed -n '1,/^INSERT$/p' "${src}" |
Denys Vlasenko | 749e305 | 2010-11-24 15:06:49 +0100 | [diff] [blame] | 28 | printf "%s\n" "${insert}" |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 29 | sed -n '/^INSERT$/,$p' "${src}" |
| 30 | else |
| 31 | if [ -n "${insert}" ]; then |
Denys Vlasenko | 749e305 | 2010-11-24 15:06:49 +0100 | [diff] [blame] | 32 | printf "%s\n" "ERROR: INSERT line missing in: ${src}" 1>&2 |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 33 | fi |
| 34 | cat "${src}" |
| 35 | fi |
| 36 | ) | sed '/^INSERT$/d' > "${dst}.tmp" |
| 37 | if ! cmp -s "${dst}" "${dst}.tmp"; then |
| 38 | gen "${dst}" |
| 39 | mv "${dst}.tmp" "${dst}" |
| 40 | else |
| 41 | rm -f "${dst}.tmp" |
| 42 | fi |
| 43 | } |
| 44 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 45 | # (Re)generate include/applets.h |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 46 | s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 47 | generate \ |
| 48 | "$srctree/include/applets.src.h" \ |
| 49 | "include/applets.h" \ |
| 50 | "/* DO NOT EDIT. This file is generated from applets.src.h */" \ |
| 51 | "${s}" |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 52 | |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 53 | # (Re)generate include/usage.h |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 54 | # We add line continuation backslash after each line, |
| 55 | # and insert empty line before each line which doesn't start |
| 56 | # with space or tab |
| 57 | # (note: we need to use \\\\ because of ``) |
| 58 | s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 59 | generate \ |
| 60 | "$srctree/include/usage.src.h" \ |
| 61 | "include/usage.h" \ |
| 62 | "/* DO NOT EDIT. This file is generated from usage.src.h */" \ |
| 63 | "${s}" |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 64 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 65 | # (Re)generate */Kbuild and */Config.in |
Waldemar Brodkorb | 95b83ba | 2010-08-06 09:17:26 +0200 | [diff] [blame] | 66 | { cd -- "$srctree" && find . -type d; } | while read -r d; do |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 67 | d="${d#./}" |
Denys Vlasenko | 1883cb1 | 2010-07-09 01:25:36 +0200 | [diff] [blame] | 68 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 69 | src="$srctree/$d/Kbuild.src" |
| 70 | dst="$d/Kbuild" |
| 71 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 72 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 73 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 74 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 75 | generate \ |
| 76 | "${src}" "${dst}" \ |
| 77 | "# DO NOT EDIT. This file is generated from Kbuild.src" \ |
| 78 | "${s}" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 79 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 80 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 81 | src="$srctree/$d/Config.src" |
| 82 | dst="$d/Config.in" |
| 83 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 84 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 85 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 86 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 87 | generate \ |
| 88 | "${src}" "${dst}" \ |
| 89 | "# DO NOT EDIT. This file is generated from Config.src" \ |
| 90 | "${s}" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 91 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 92 | done |
| 93 | |
Denys Vlasenko | f9d0913 | 2010-11-21 22:10:07 +0100 | [diff] [blame] | 94 | # Last read failed. This is normal. Don't exit with its error code: |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 95 | exit 0 |