blob: f79fa2f83c60a45cc77950e73e97201e22eb6209 [file] [log] [blame]
Denys Vlasenko3015a132010-05-17 01:59:16 +02001#!/bin/sh
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02002
Denys Vlasenkoc3dadba2011-04-16 17:59:34 +02003# Note: was using sed OPTS CMD -- FILES
4# but users complain that many sed implementations
5# are misinterpreting --.
6
Denys Vlasenko572b9a32010-05-09 16:20:52 +02007test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02008
9# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020010cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko1883cb12010-07-09 01:25:36 +020011# In separate objtree build, include/ might not exist yet
12mkdir include 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020013
14srctree="$1"
15
Mike Frysingerf718e3a2010-11-16 07:29:12 -050016status() { printf ' %-8s%s\n' "$1" "$2"; }
17gen() { status "GEN" "$@"; }
18chk() { status "CHK" "$@"; }
19
20generate()
21{
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020022 # NB: data to be inserted at INSERT line is coming on stdin
Denys Vlasenkobca4ea82017-01-24 20:52:42 +010023 src="$1"
24 dst="$2"
25 header="$3"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050026 #chk "${dst}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020027 {
Denys Vlasenko7a3f8e22010-11-25 06:55:18 +010028 # Need to use printf: different shells have inconsistent
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020029 # rules re handling of "\n" in echo params.
Denys Vlasenko749e3052010-11-24 15:06:49 +010030 printf "%s\n" "${header}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020031 # print everything up to INSERT line
Denys Vlasenko4ea37d62011-10-19 21:17:20 +020032 sed -n '/^INSERT$/ q; p' "${src}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020033 # copy stdin to stdout
34 cat
35 # print everything after INSERT line
Matthias Andree9b76f892014-01-10 11:54:37 +010036 sed -n '/^INSERT$/ {
37 :l
38 n
39 p
40 bl
41 }' "${src}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020042 } >"${dst}.tmp"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050043 if ! cmp -s "${dst}" "${dst}.tmp"; then
44 gen "${dst}"
45 mv "${dst}.tmp" "${dst}"
46 else
47 rm -f "${dst}.tmp"
48 fi
49}
50
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020051# (Re)generate include/applets.h
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020052sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
53| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050054 "$srctree/include/applets.src.h" \
55 "include/applets.h" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020056 "/* DO NOT EDIT. This file is generated from applets.src.h */"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020057
Denys Vlasenkof0f94702010-06-06 01:53:38 +020058# (Re)generate include/usage.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020059# We add line continuation backslash after each line,
60# and insert empty line before each line which doesn't start
61# with space or tab
Matthias Andree9b76f892014-01-10 11:54:37 +010062TAB="$(printf '\tX')"
63TAB="${TAB%X}"
64LF="$(printf '\nX')"
65LF="${LF%X}"
66sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \
67 -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010068 "$srctree"/*/*.c "$srctree"/*/*/*.c \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020069| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050070 "$srctree/include/usage.src.h" \
71 "include/usage.h" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020072 "/* DO NOT EDIT. This file is generated from usage.src.h */"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020073
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020074# (Re)generate */Kbuild and */Config.in
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010075# We skip .dotdirs - makes git/svn/etc users happier
Denys Vlasenko29f35262014-03-16 12:05:58 +010076{ cd -- "$srctree" && find . -type d ! '(' -name '.?*' -prune ')'; } \
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010077| while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020078 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +020079
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020080 src="$srctree/$d/Kbuild.src"
81 dst="$d/Kbuild"
82 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030083 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020084
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020085 sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
86 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050087 "${src}" "${dst}" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020088 "# DO NOT EDIT. This file is generated from Kbuild.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020089 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020090
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020091 src="$srctree/$d/Config.src"
92 dst="$d/Config.in"
93 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +030094 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020095
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020096 sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
97 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050098 "${src}" "${dst}" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020099 "# DO NOT EDIT. This file is generated from Config.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200100 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200101done
102
Denys Vlasenkof9d09132010-11-21 22:10:07 +0100103# Last read failed. This is normal. Don't exit with its error code:
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200104exit 0