blob: 647c7daf7f1122a24392ba0b45b470ab63239e21 [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 Vlasenko7fb68f12010-05-09 04:22:48 +02007
8srctree="$1"
9
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020010# (Re)generate include/applets.h
11src="$srctree/include/applets.src.h"
12dst="include/applets.h"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020013s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020014echo "/* DO NOT EDIT. This file is generated from applets.src.h */" >"$dst.$$.tmp"
15# Why "IFS='' read -r REPLY"??
16# This atrocity is needed to read lines without mangling.
17# IFS='' prevents whitespace trimming,
18# -r suppresses backslash handling.
19while IFS='' read -r REPLY; do
20 test x"$REPLY" = x"INSERT" && REPLY="$s"
21 printf "%s\n" "$REPLY"
22done <"$src" >>"$dst.$$.tmp"
23if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
24 rm -- "$dst.$$.tmp"
25else
26 echo " GEN $dst"
27 mv -- "$dst.$$.tmp" "$dst"
28fi
29
Denys Vlasenkof0f94702010-06-06 01:53:38 +020030# (Re)generate include/usage.h
31src="$srctree/include/usage.src.h"
32dst="include/usage.h"
33# We add line continuation backslash after each line,
34# and insert empty line before each line which doesn't start
35# with space or tab
36# (note: we need to use \\\\ because of ``)
37s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
38echo "/* DO NOT EDIT. This file is generated from usage.src.h */" >"$dst.$$.tmp"
39# Why "IFS='' read -r REPLY"??
40# This atrocity is needed to read lines without mangling.
41# IFS='' prevents whitespace trimming,
42# -r suppresses backslash handling.
43while IFS='' read -r REPLY; do
44 test x"$REPLY" = x"INSERT" && REPLY="$s"
45 printf "%s\n" "$REPLY"
46done <"$src" >>"$dst.$$.tmp"
47if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
48 rm -- "$dst.$$.tmp"
49else
50 echo " GEN $dst"
51 mv -- "$dst.$$.tmp" "$dst"
52fi
53
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020054# (Re)generate */Kbuild and */Config.in
Denys Vlasenko084e2282010-05-15 21:08:51 +020055find -type d | while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020056 d="${d#./}"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020057 src="$srctree/$d/Kbuild.src"
58 dst="$d/Kbuild"
59 if test -f "$src"; then
Denys Vlasenko76c936f2010-05-27 02:33:31 +020060 #echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020061
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020062 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020063
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020064 echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020065 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020066 test x"$REPLY" = x"INSERT" && REPLY="$s"
67 printf "%s\n" "$REPLY"
68 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020069 if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
70 rm -- "$dst.$$.tmp"
71 else
72 echo " GEN $dst"
73 mv -- "$dst.$$.tmp" "$dst"
74 fi
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
Denys Vlasenko76c936f2010-05-27 02:33:31 +020080 #echo " CHK $dst"
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`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020083
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020084 echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020085 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020086 test x"$REPLY" = x"INSERT" && REPLY="$s"
87 printf "%s\n" "$REPLY"
88 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020089 if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
90 rm -- "$dst.$$.tmp"
91 else
92 echo " GEN $dst"
93 mv -- "$dst.$$.tmp" "$dst"
94 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020095 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020096done
97
98# Last read failed. This is normal. Don't exit with its error code:
99exit 0