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 | 572b9a3 | 2010-05-09 16:20:52 +0200 | [diff] [blame] | 3 | test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 4 | |
| 5 | # cd to objtree |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 6 | cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 7 | |
| 8 | srctree="$1" |
| 9 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 10 | # (Re)generate include/applets.h |
| 11 | src="$srctree/include/applets.src.h" |
| 12 | dst="include/applets.h" |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 13 | s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 14 | echo "/* DO NOT EDIT. This file is generated from applets.src.h */" >"$dst.$$.tmp" |
| 15 | # 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. |
| 19 | while IFS='' read -r REPLY; do |
| 20 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 21 | printf "%s\n" "$REPLY" |
| 22 | done <"$src" >>"$dst.$$.tmp" |
| 23 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 24 | rm -- "$dst.$$.tmp" |
| 25 | else |
| 26 | echo " GEN $dst" |
| 27 | mv -- "$dst.$$.tmp" "$dst" |
| 28 | fi |
| 29 | |
Denys Vlasenko | f0f9470 | 2010-06-06 01:53:38 +0200 | [diff] [blame] | 30 | # (Re)generate include/usage.h |
| 31 | src="$srctree/include/usage.src.h" |
| 32 | dst="include/usage.h" |
| 33 | # We add line continuation backslash after each line, |
| 34 | # and insert empty line before each line which doesn't start |
| 35 | # with space or tab |
| 36 | # (note: we need to use \\\\ because of ``) |
| 37 | s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
| 38 | echo "/* DO NOT EDIT. This file is generated from usage.src.h */" >"$dst.$$.tmp" |
| 39 | # Why "IFS='' read -r REPLY"?? |
| 40 | # This atrocity is needed to read lines without mangling. |
| 41 | # IFS='' prevents whitespace trimming, |
| 42 | # -r suppresses backslash handling. |
| 43 | while IFS='' read -r REPLY; do |
| 44 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 45 | printf "%s\n" "$REPLY" |
| 46 | done <"$src" >>"$dst.$$.tmp" |
| 47 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 48 | rm -- "$dst.$$.tmp" |
| 49 | else |
| 50 | echo " GEN $dst" |
| 51 | mv -- "$dst.$$.tmp" "$dst" |
| 52 | fi |
| 53 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 54 | # (Re)generate */Kbuild and */Config.in |
Denys Vlasenko | 084e228 | 2010-05-15 21:08:51 +0200 | [diff] [blame] | 55 | find -type d | while read -r d; do |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 56 | d="${d#./}" |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 57 | src="$srctree/$d/Kbuild.src" |
| 58 | dst="$d/Kbuild" |
| 59 | if test -f "$src"; then |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 60 | #echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 61 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 62 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
Denys Vlasenko | a1db8b8 | 2010-05-18 00:24:17 +0200 | [diff] [blame] | 63 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 64 | echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp" |
Denys Vlasenko | a1db8b8 | 2010-05-18 00:24:17 +0200 | [diff] [blame] | 65 | while IFS='' read -r REPLY; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 66 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 67 | printf "%s\n" "$REPLY" |
| 68 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 69 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 70 | rm -- "$dst.$$.tmp" |
| 71 | else |
| 72 | echo " GEN $dst" |
| 73 | mv -- "$dst.$$.tmp" "$dst" |
| 74 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 75 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 76 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 77 | src="$srctree/$d/Config.src" |
| 78 | dst="$d/Config.in" |
| 79 | if test -f "$src"; then |
Denys Vlasenko | 76c936f | 2010-05-27 02:33:31 +0200 | [diff] [blame] | 80 | #echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 81 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 82 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
Denys Vlasenko | a1db8b8 | 2010-05-18 00:24:17 +0200 | [diff] [blame] | 83 | |
Denys Vlasenko | 6c5bf0d | 2010-06-06 00:53:45 +0200 | [diff] [blame] | 84 | echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp" |
Denys Vlasenko | a1db8b8 | 2010-05-18 00:24:17 +0200 | [diff] [blame] | 85 | while IFS='' read -r REPLY; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 86 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 87 | printf "%s\n" "$REPLY" |
| 88 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 89 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 90 | rm -- "$dst.$$.tmp" |
| 91 | else |
| 92 | echo " GEN $dst" |
| 93 | mv -- "$dst.$$.tmp" "$dst" |
| 94 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 95 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 96 | done |
| 97 | |
| 98 | # Last read failed. This is normal. Don't exit with its error code: |
| 99 | exit 0 |