Denys Vlasenko | 3015a13 | 2010-05-17 01:59:16 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 2 | |
Denys Vlasenko | c3dadba | 2011-04-16 17:59:34 +0200 | [diff] [blame] | 3 | # Note: was using sed OPTS CMD -- FILES |
| 4 | # but users complain that many sed implementations |
| 5 | # are misinterpreting --. |
| 6 | |
Denys Vlasenko | 572b9a3 | 2010-05-09 16:20:52 +0200 | [diff] [blame] | 7 | test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 8 | |
| 9 | # cd to objtree |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 10 | cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 1883cb1 | 2010-07-09 01:25:36 +0200 | [diff] [blame] | 11 | # In separate objtree build, include/ might not exist yet |
| 12 | mkdir include 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 13 | |
| 14 | srctree="$1" |
| 15 | |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 16 | status() { printf ' %-8s%s\n' "$1" "$2"; } |
| 17 | gen() { status "GEN" "$@"; } |
| 18 | chk() { status "CHK" "$@"; } |
| 19 | |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 20 | # scripts in the 'embed' directory are treated as fake applets |
| 21 | custom_scripts() |
| 22 | { |
| 23 | custom_loc="$1" |
| 24 | if [ -d "$custom_loc" ] |
| 25 | then |
Ron Yorston | 7b42f8f | 2018-11-21 10:11:01 +0000 | [diff] [blame] | 26 | for i in $(cd "$custom_loc"; ls * 2>/dev/null) |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 27 | do |
Ron Yorston | 71df2d3 | 2018-11-27 14:34:25 +0000 | [diff] [blame] | 28 | printf "IF_FEATURE_SH_EMBEDDED_SCRIPTS(APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, scripted))\n" $i; |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 29 | done |
| 30 | fi |
| 31 | } |
| 32 | |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 33 | generate() |
| 34 | { |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 35 | # NB: data to be inserted at INSERT line is coming on stdin |
Denys Vlasenko | bca4ea8 | 2017-01-24 20:52:42 +0100 | [diff] [blame] | 36 | src="$1" |
| 37 | dst="$2" |
| 38 | header="$3" |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 39 | loc="$4" |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 40 | #chk "${dst}" |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 41 | { |
Denys Vlasenko | 7a3f8e2 | 2010-11-25 06:55:18 +0100 | [diff] [blame] | 42 | # Need to use printf: different shells have inconsistent |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 43 | # rules re handling of "\n" in echo params. |
Denys Vlasenko | 749e305 | 2010-11-24 15:06:49 +0100 | [diff] [blame] | 44 | printf "%s\n" "${header}" |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 45 | # print everything up to INSERT line |
Denys Vlasenko | 4ea37d6 | 2011-10-19 21:17:20 +0200 | [diff] [blame] | 46 | sed -n '/^INSERT$/ q; p' "${src}" |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 47 | # copy stdin to stdout |
| 48 | cat |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 49 | if [ -n "$loc" ] |
| 50 | then |
| 51 | custom_scripts "$loc" |
| 52 | fi |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 53 | # print everything after INSERT line |
Matthias Andree | 9b76f89 | 2014-01-10 11:54:37 +0100 | [diff] [blame] | 54 | sed -n '/^INSERT$/ { |
| 55 | :l |
| 56 | n |
| 57 | p |
| 58 | bl |
| 59 | }' "${src}" |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 60 | } >"${dst}.tmp" |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 61 | if ! cmp -s "${dst}" "${dst}.tmp"; then |
| 62 | gen "${dst}" |
| 63 | mv "${dst}.tmp" "${dst}" |
| 64 | else |
| 65 | rm -f "${dst}.tmp" |
| 66 | fi |
| 67 | } |
| 68 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 69 | # (Re)generate include/applets.h |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 70 | sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \ |
| 71 | | generate \ |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 72 | "$srctree/include/applets.src.h" \ |
| 73 | "include/applets.h" \ |
Ron Yorston | 3778898 | 2018-11-17 17:48:14 +0000 | [diff] [blame] | 74 | "/* DO NOT EDIT. This file is generated from applets.src.h */" \ |
| 75 | "$srctree/embed" |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 76 | |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 77 | # (Re)generate include/usage.h |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 78 | # We add line continuation backslash after each line, |
| 79 | # and insert empty line before each line which doesn't start |
| 80 | # with space or tab |
Matthias Andree | 9b76f89 | 2014-01-10 11:54:37 +0100 | [diff] [blame] | 81 | TAB="$(printf '\tX')" |
| 82 | TAB="${TAB%X}" |
| 83 | LF="$(printf '\nX')" |
| 84 | LF="${LF%X}" |
| 85 | sed -n -e 's@^//usage:\([ '"$TAB"'].*\)$@\1 \\@p' \ |
| 86 | -e 's@^//usage:\([^ '"$TAB"'].*\)$@\'"$LF"'\1 \\@p' \ |
Paulius Zaleckas | 1c7724b | 2012-01-30 02:34:56 +0100 | [diff] [blame] | 87 | "$srctree"/*/*.c "$srctree"/*/*/*.c \ |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 88 | | generate \ |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 89 | "$srctree/include/usage.src.h" \ |
| 90 | "include/usage.h" \ |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 91 | "/* DO NOT EDIT. This file is generated from usage.src.h */" |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 92 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 93 | # (Re)generate */Kbuild and */Config.in |
Paulius Zaleckas | 1c7724b | 2012-01-30 02:34:56 +0100 | [diff] [blame] | 94 | # We skip .dotdirs - makes git/svn/etc users happier |
Denys Vlasenko | 29f3526 | 2014-03-16 12:05:58 +0100 | [diff] [blame] | 95 | { cd -- "$srctree" && find . -type d ! '(' -name '.?*' -prune ')'; } \ |
Paulius Zaleckas | 1c7724b | 2012-01-30 02:34:56 +0100 | [diff] [blame] | 96 | | while read -r d; do |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 97 | d="${d#./}" |
Denys Vlasenko | 1883cb1 | 2010-07-09 01:25:36 +0200 | [diff] [blame] | 98 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 99 | src="$srctree/$d/Kbuild.src" |
| 100 | dst="$d/Kbuild" |
| 101 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 102 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 103 | |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 104 | sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \ |
| 105 | | generate \ |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 106 | "${src}" "${dst}" \ |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 107 | "# DO NOT EDIT. This file is generated from Kbuild.src" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 108 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 109 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 110 | src="$srctree/$d/Config.src" |
| 111 | dst="$d/Config.in" |
| 112 | if test -f "$src"; then |
Alexander Shishkin | daf286c | 2010-07-15 17:39:24 +0300 | [diff] [blame] | 113 | mkdir -p -- "$d" 2>/dev/null |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 114 | |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 115 | sed -n 's@^//config:@@p' "$srctree/$d"/*.c \ |
| 116 | | generate \ |
Mike Frysinger | f718e3a | 2010-11-16 07:29:12 -0500 | [diff] [blame] | 117 | "${src}" "${dst}" \ |
Denys Vlasenko | efd08bf | 2011-10-19 17:54:42 +0200 | [diff] [blame] | 118 | "# DO NOT EDIT. This file is generated from Config.src" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 119 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 120 | done |
| 121 | |
Denys Vlasenko | f9d0913 | 2010-11-21 22:10:07 +0100 | [diff] [blame] | 122 | # Last read failed. This is normal. Don't exit with its error code: |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 123 | exit 0 |