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 | ( |
| 21 | echo "${header}" |
| 22 | if grep -qs '^INSERT$' "${src}"; then |
| 23 | sed -n '1,/^INSERT$/p' "${src}" |
| 24 | echo "${insert}" |
| 25 | sed -n '/^INSERT$/,$p' "${src}" |
| 26 | else |
| 27 | if [ -n "${insert}" ]; then |
| 28 | echo "ERROR: INSERT line missing in: ${src}" 1>&2 |
| 29 | fi |
| 30 | cat "${src}" |
| 31 | fi |
| 32 | ) | sed '/^INSERT$/d' > "${dst}.tmp" |
| 33 | if ! cmp -s "${dst}" "${dst}.tmp"; then |
| 34 | gen "${dst}" |
| 35 | mv "${dst}.tmp" "${dst}" |
| 36 | else |
| 37 | rm -f "${dst}.tmp" |
| 38 | fi |
| 39 | } |
| 40 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 41 | # (Re)generate include/applets.h |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 42 | s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame^] | 43 | generate \ |
| 44 | "$srctree/include/applets.src.h" \ |
| 45 | "include/applets.h" \ |
| 46 | "/* DO NOT EDIT. This file is generated from applets.src.h */" \ |
| 47 | "${s}" |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 48 | |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 49 | # (Re)generate include/usage.h |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 50 | # We add line continuation backslash after each line, |
| 51 | # and insert empty line before each line which doesn't start |
| 52 | # with space or tab |
| 53 | # (note: we need to use \\\\ because of ``) |
| 54 | 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^] | 55 | generate \ |
| 56 | "$srctree/include/usage.src.h" \ |
| 57 | "include/usage.h" \ |
| 58 | "/* DO NOT EDIT. This file is generated from usage.src.h */" \ |
| 59 | "${s}" |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 60 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 61 | # (Re)generate */Kbuild and */Config.in |
Waldemar Brodkorb | 95b83ba | 2010-08-06 09:17:26 +0200 | [diff] [blame] | 62 | { cd -- "$srctree" && find . -type d; } | while read -r d; do |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 63 | d="${d#./}" |
Denys Vlasenko | 1883cb1 | 2010-07-09 01:25:36 +0200 | [diff] [blame] | 64 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 65 | src="$srctree/$d/Kbuild.src" |
| 66 | dst="$d/Kbuild" |
| 67 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 68 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 69 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 70 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame^] | 71 | generate \ |
| 72 | "${src}" "${dst}" \ |
| 73 | "# DO NOT EDIT. This file is generated from Kbuild.src" \ |
| 74 | "${s}" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 75 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 76 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 77 | src="$srctree/$d/Config.src" |
| 78 | dst="$d/Config.in" |
| 79 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 80 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 81 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 82 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame^] | 83 | generate \ |
| 84 | "${src}" "${dst}" \ |
| 85 | "# DO NOT EDIT. This file is generated from Config.src" \ |
| 86 | "${s}" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 87 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 88 | done |
| 89 | |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 90 | exit 0 |