blob: a98f509ce334b459b02a4b64129c48662bac972a [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 Vlasenko1d72d432010-06-25 13:30:59 +020014old=`cat "$dst" 2>/dev/null`
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020015# 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.
Denys Vlasenko1d72d432010-06-25 13:30:59 +020019new=`echo "/* DO NOT EDIT. This file is generated from applets.src.h */"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020020while IFS='' read -r REPLY; do
21 test x"$REPLY" = x"INSERT" && REPLY="$s"
22 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020023done <"$src"`
24if test x"$new" != x"$old"; then
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020025 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020026 printf "%s\n" "$new" >"$dst"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020027fi
28
Denys Vlasenkof0f94702010-06-06 01:53:38 +020029# (Re)generate include/usage.h
30src="$srctree/include/usage.src.h"
31dst="include/usage.h"
32# We add line continuation backslash after each line,
33# and insert empty line before each line which doesn't start
34# with space or tab
35# (note: we need to use \\\\ because of ``)
36s=`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 +020037old=`cat "$dst" 2>/dev/null`
38new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020039while IFS='' read -r REPLY; do
40 test x"$REPLY" = x"INSERT" && REPLY="$s"
41 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020042done <"$src"`
43if test x"$new" != x"$old"; then
Denys Vlasenkof0f94702010-06-06 01:53:38 +020044 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020045 printf "%s\n" "$new" >"$dst"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020046fi
47
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020048# (Re)generate */Kbuild and */Config.in
Denys Vlasenko084e2282010-05-15 21:08:51 +020049find -type d | while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020050 d="${d#./}"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020051 src="$srctree/$d/Kbuild.src"
52 dst="$d/Kbuild"
53 if test -f "$src"; then
Denys Vlasenko76c936f2010-05-27 02:33:31 +020054 #echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020055
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020056 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020057
Denys Vlasenko1d72d432010-06-25 13:30:59 +020058 old=`cat "$dst" 2>/dev/null`
59 new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020060 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020061 test x"$REPLY" = x"INSERT" && REPLY="$s"
62 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020063 done <"$src"`
64 if test x"$new" != x"$old"; then
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020065 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020066 printf "%s\n" "$new" >"$dst"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020067 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020068 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020069
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020070 src="$srctree/$d/Config.src"
71 dst="$d/Config.in"
72 if test -f "$src"; then
Denys Vlasenko76c936f2010-05-27 02:33:31 +020073 #echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020074
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020075 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020076
Denys Vlasenko1d72d432010-06-25 13:30:59 +020077 old=`cat "$dst" 2>/dev/null`
78 new=`echo "# DO NOT EDIT. This file is generated from Config.src"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020079 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020080 test x"$REPLY" = x"INSERT" && REPLY="$s"
81 printf "%s\n" "$REPLY"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020082 done <"$src"`
83 if test x"$new" != x"$old"; then
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020084 echo " GEN $dst"
Denys Vlasenko1d72d432010-06-25 13:30:59 +020085 printf "%s\n" "$new" >"$dst"
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020086 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020087 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020088done
89
90# Last read failed. This is normal. Don't exit with its error code:
91exit 0