blob: 09a95b5073335d7a0a1a87ac3eb7c79d2ea67dfa [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
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020012# (Re)generate include/applets.h
13src="$srctree/include/applets.src.h"
14dst="include/applets.h"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020015s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Denys Vlasenko1d72d432010-06-25 13:30:59 +020016old=`cat "$dst" 2>/dev/null`
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020017# Why "IFS='' read -r REPLY"??
18# This atrocity is needed to read lines without mangling.
19# IFS='' prevents whitespace trimming,
20# -r suppresses backslash handling.
Denys Vlasenko1d72d432010-06-25 13:30:59 +020021new=`echo "/* DO NOT EDIT. This file is generated from applets.src.h */"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020022while IFS='' read -r REPLY; do
23 test x"$REPLY" = x"INSERT" && REPLY="$s"
24 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020025done <"$src"`
26if test x"$new" != x"$old"; then
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020027 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020028 printf "%s\n" "$new" >"$dst"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020029fi
30
Denys Vlasenkof0f94702010-06-06 01:53:38 +020031# (Re)generate include/usage.h
32src="$srctree/include/usage.src.h"
33dst="include/usage.h"
34# We add line continuation backslash after each line,
35# and insert empty line before each line which doesn't start
36# with space or tab
37# (note: we need to use \\\\ because of ``)
38s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
Denys Vlasenko1d72d432010-06-25 13:30:59 +020039old=`cat "$dst" 2>/dev/null`
40new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020041while IFS='' read -r REPLY; do
42 test x"$REPLY" = x"INSERT" && REPLY="$s"
43 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020044done <"$src"`
45if test x"$new" != x"$old"; then
Denys Vlasenkof0f94702010-06-06 01:53:38 +020046 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020047 printf "%s\n" "$new" >"$dst"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020048fi
49
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020050# (Re)generate */Kbuild and */Config.in
Waldemar Brodkorb95b83ba2010-08-06 09:17:26 +020051{ cd -- "$srctree" && find . -type d; } | while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020052 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +020053
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020054 src="$srctree/$d/Kbuild.src"
55 dst="$d/Kbuild"
56 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030057 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko76c936f2010-05-27 02:33:31 +020058 #echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020059
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020060 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020061
Denys Vlasenko1d72d432010-06-25 13:30:59 +020062 old=`cat "$dst" 2>/dev/null`
63 new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020064 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020065 test x"$REPLY" = x"INSERT" && REPLY="$s"
66 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020067 done <"$src"`
68 if test x"$new" != x"$old"; then
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020069 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020070 printf "%s\n" "$new" >"$dst"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020071 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020072 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020073
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020074 src="$srctree/$d/Config.src"
75 dst="$d/Config.in"
76 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030077 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko76c936f2010-05-27 02:33:31 +020078 #echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020079
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020080 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020081
Denys Vlasenko1d72d432010-06-25 13:30:59 +020082 old=`cat "$dst" 2>/dev/null`
83 new=`echo "# DO NOT EDIT. This file is generated from Config.src"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020084 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020085 test x"$REPLY" = x"INSERT" && REPLY="$s"
86 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020087 done <"$src"`
88 if test x"$new" != x"$old"; then
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020089 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020090 printf "%s\n" "$new" >"$dst"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020091 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020092 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020093done
94
95# Last read failed. This is normal. Don't exit with its error code:
96exit 0