blob: 03831f501a7b50be4f468633520c2ac60f7fd9fb [file] [log] [blame]
Denys Vlasenko3015a132010-05-17 01:59:16 +02001#!/bin/sh
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02002
Denys Vlasenko572b9a32010-05-09 16:20:52 +02003test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02004
5# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +02006cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko1883cb12010-07-09 01:25:36 +02007# In separate objtree build, include/ might not exist yet
8mkdir include 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02009
10srctree="$1"
11
Mike Frysingerf718e3a2010-11-16 07:29:12 -050012status() { printf ' %-8s%s\n' "$1" "$2"; }
13gen() { status "GEN" "$@"; }
14chk() { status "CHK" "$@"; }
15
16generate()
17{
18 local src="$1" dst="$2" header="$3" insert="$4"
19 #chk "${dst}"
20 (
Denys Vlasenko7a3f8e22010-11-25 06:55:18 +010021 # 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 Vlasenko749e3052010-11-24 15:06:49 +010025 printf "%s\n" "${header}"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050026 if grep -qs '^INSERT$' "${src}"; then
27 sed -n '1,/^INSERT$/p' "${src}"
Denys Vlasenko749e3052010-11-24 15:06:49 +010028 printf "%s\n" "${insert}"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050029 sed -n '/^INSERT$/,$p' "${src}"
30 else
31 if [ -n "${insert}" ]; then
Denys Vlasenko749e3052010-11-24 15:06:49 +010032 printf "%s\n" "ERROR: INSERT line missing in: ${src}" 1>&2
Mike Frysingerf718e3a2010-11-16 07:29:12 -050033 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 Vlasenko6c5bf0d2010-06-06 00:53:45 +020045# (Re)generate include/applets.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020046s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050047generate \
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 Vlasenko6c5bf0d2010-06-06 00:53:45 +020052
Denys Vlasenkof0f94702010-06-06 01:53:38 +020053# (Re)generate include/usage.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020054# 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 ``)
58s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050059generate \
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 Vlasenkof0f94702010-06-06 01:53:38 +020064
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020065# (Re)generate */Kbuild and */Config.in
Waldemar Brodkorb95b83ba2010-08-06 09:17:26 +020066{ cd -- "$srctree" && find . -type d; } | while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020067 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +020068
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020069 src="$srctree/$d/Kbuild.src"
70 dst="$d/Kbuild"
71 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030072 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020073
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020074 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050075 generate \
76 "${src}" "${dst}" \
77 "# DO NOT EDIT. This file is generated from Kbuild.src" \
78 "${s}"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020079 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020080
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020081 src="$srctree/$d/Config.src"
82 dst="$d/Config.in"
83 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030084 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020085
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020086 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050087 generate \
88 "${src}" "${dst}" \
89 "# DO NOT EDIT. This file is generated from Config.src" \
90 "${s}"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020091 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020092done
93
Denys Vlasenkof9d09132010-11-21 22:10:07 +010094# Last read failed. This is normal. Don't exit with its error code:
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020095exit 0