blob: 1c1edcc12953f3975ffe5ebea77a9d38d3e45ba0 [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 (
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 Vlasenko6c5bf0d2010-06-06 00:53:45 +020041# (Re)generate include/applets.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020042s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050043generate \
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 Vlasenko6c5bf0d2010-06-06 00:53:45 +020048
Denys Vlasenkof0f94702010-06-06 01:53:38 +020049# (Re)generate include/usage.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020050# 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 ``)
54s=`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 -050055generate \
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 Vlasenkof0f94702010-06-06 01:53:38 +020060
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020061# (Re)generate */Kbuild and */Config.in
Waldemar Brodkorb95b83ba2010-08-06 09:17:26 +020062{ cd -- "$srctree" && find . -type d; } | while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020063 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +020064
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020065 src="$srctree/$d/Kbuild.src"
66 dst="$d/Kbuild"
67 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030068 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020069
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020070 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050071 generate \
72 "${src}" "${dst}" \
73 "# DO NOT EDIT. This file is generated from Kbuild.src" \
74 "${s}"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020075 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020076
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020077 src="$srctree/$d/Config.src"
78 dst="$d/Config.in"
79 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030080 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020081
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020082 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
Mike Frysingerf718e3a2010-11-16 07:29:12 -050083 generate \
84 "${src}" "${dst}" \
85 "# DO NOT EDIT. This file is generated from Config.src" \
86 "${s}"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020087 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020088done
89
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020090exit 0