blob: 8b5b15a1b25977f3cf425ee1229fe62a04661a71 [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
Khem Rajc0f81132021-05-12 13:01:35 -07007export LC_ALL=C
8
Denys Vlasenko572b9a32010-05-09 16:20:52 +02009test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020010
11# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020012cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko1883cb12010-07-09 01:25:36 +020013# In separate objtree build, include/ might not exist yet
14mkdir include 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020015
16srctree="$1"
17
Mike Frysingerf718e3a2010-11-16 07:29:12 -050018status() { printf ' %-8s%s\n' "$1" "$2"; }
19gen() { status "GEN" "$@"; }
20chk() { status "CHK" "$@"; }
21
Ron Yorston37788982018-11-17 17:48:14 +000022# scripts in the 'embed' directory are treated as fake applets
23custom_scripts()
24{
25 custom_loc="$1"
26 if [ -d "$custom_loc" ]
27 then
Ron Yorston7b42f8f2018-11-21 10:11:01 +000028 for i in $(cd "$custom_loc"; ls * 2>/dev/null)
Ron Yorston37788982018-11-17 17:48:14 +000029 do
Ron Yorston71df2d32018-11-27 14:34:25 +000030 printf "IF_FEATURE_SH_EMBEDDED_SCRIPTS(APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, scripted))\n" $i;
Ron Yorston37788982018-11-17 17:48:14 +000031 done
32 fi
33}
34
Mike Frysingerf718e3a2010-11-16 07:29:12 -050035generate()
36{
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020037 # NB: data to be inserted at INSERT line is coming on stdin
Denys Vlasenkobca4ea82017-01-24 20:52:42 +010038 src="$1"
39 dst="$2"
40 header="$3"
Ron Yorston37788982018-11-17 17:48:14 +000041 loc="$4"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050042 #chk "${dst}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020043 {
Denys Vlasenko7a3f8e22010-11-25 06:55:18 +010044 # Need to use printf: different shells have inconsistent
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020045 # rules re handling of "\n" in echo params.
Denys Vlasenko749e3052010-11-24 15:06:49 +010046 printf "%s\n" "${header}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020047 # print everything up to INSERT line
Denys Vlasenko4ea37d62011-10-19 21:17:20 +020048 sed -n '/^INSERT$/ q; p' "${src}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020049 # copy stdin to stdout
50 cat
Ron Yorston37788982018-11-17 17:48:14 +000051 if [ -n "$loc" ]
52 then
53 custom_scripts "$loc"
54 fi
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020055 # print everything after INSERT line
Matthias Andree9b76f892014-01-10 11:54:37 +010056 sed -n '/^INSERT$/ {
57 :l
58 n
59 p
60 bl
61 }' "${src}"
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020062 } >"${dst}.tmp"
Mike Frysingerf718e3a2010-11-16 07:29:12 -050063 if ! cmp -s "${dst}" "${dst}.tmp"; then
64 gen "${dst}"
65 mv "${dst}.tmp" "${dst}"
66 else
67 rm -f "${dst}.tmp"
68 fi
69}
70
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020071# (Re)generate include/applets.h
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020072sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
73| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050074 "$srctree/include/applets.src.h" \
75 "include/applets.h" \
Ron Yorston37788982018-11-17 17:48:14 +000076 "/* DO NOT EDIT. This file is generated from applets.src.h */" \
77 "$srctree/embed"
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020078
Denys Vlasenkof0f94702010-06-06 01:53:38 +020079# (Re)generate include/usage.h
Denys Vlasenkof0f94702010-06-06 01:53:38 +020080# We add line continuation backslash after each line,
81# and insert empty line before each line which doesn't start
82# with space or tab
Matthias Andree9b76f892014-01-10 11:54:37 +010083TAB="$(printf '\tX')"
84TAB="${TAB%X}"
85LF="$(printf '\nX')"
86LF="${LF%X}"
87sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \
88 -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010089 "$srctree"/*/*.c "$srctree"/*/*/*.c \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020090| generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -050091 "$srctree/include/usage.src.h" \
92 "include/usage.h" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +020093 "/* DO NOT EDIT. This file is generated from usage.src.h */"
Denys Vlasenkof0f94702010-06-06 01:53:38 +020094
Denys Vlasenko6c5bf0d2010-06-06 00:53:45 +020095# (Re)generate */Kbuild and */Config.in
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010096# We skip .dotdirs - makes git/svn/etc users happier
Denys Vlasenko29f35262014-03-16 12:05:58 +010097{ cd -- "$srctree" && find . -type d ! '(' -name '.?*' -prune ')'; } \
Paulius Zaleckas1c7724b2012-01-30 02:34:56 +010098| while read -r d; do
Denys Vlasenko76c936f2010-05-27 02:33:31 +020099 d="${d#./}"
Denys Vlasenko1883cb12010-07-09 01:25:36 +0200100
Denys Vlasenko8e3aff02010-05-10 11:00:11 +0200101 src="$srctree/$d/Kbuild.src"
102 dst="$d/Kbuild"
103 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +0300104 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200105
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +0200106 sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
107 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -0500108 "${src}" "${dst}" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +0200109 "# DO NOT EDIT. This file is generated from Kbuild.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200110 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200111
Denys Vlasenko8e3aff02010-05-10 11:00:11 +0200112 src="$srctree/$d/Config.src"
113 dst="$d/Config.in"
114 if test -f "$src"; then
Alexander Shishkindaf286c2010-07-15 17:39:24 +0300115 mkdir -p -- "$d" 2>/dev/null
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200116
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +0200117 sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
118 | generate \
Mike Frysingerf718e3a2010-11-16 07:29:12 -0500119 "${src}" "${dst}" \
Denys Vlasenkoefd08bf2011-10-19 17:54:42 +0200120 "# DO NOT EDIT. This file is generated from Config.src"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200121 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200122done
123
Denys Vlasenkof9d09132010-11-21 22:10:07 +0100124# Last read failed. This is normal. Don't exit with its error code:
Denys Vlasenko7fb68f12010-05-09 04:22:48 +0200125exit 0