Denys Vlasenko | 084e228 | 2010-05-15 21:08:51 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # bashism: |
| 3 | # "read -r" without variable name reads line into $REPLY |
| 4 | # without stripping whitespace. |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 5 | |
Denys Vlasenko | 572b9a3 | 2010-05-09 16:20:52 +0200 | [diff] [blame] | 6 | test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 7 | |
| 8 | # cd to objtree |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 9 | cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; } |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 10 | |
| 11 | srctree="$1" |
| 12 | |
Denys Vlasenko | 084e228 | 2010-05-15 21:08:51 +0200 | [diff] [blame] | 13 | find -type d | while read -r d; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 14 | src="$srctree/$d/Kbuild.src" |
| 15 | dst="$d/Kbuild" |
| 16 | if test -f "$src"; then |
| 17 | echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 18 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 19 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
| 20 | echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp" |
Denys Vlasenko | c84c85a | 2010-05-14 20:30:44 +0200 | [diff] [blame] | 21 | while read -r; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 22 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 23 | printf "%s\n" "$REPLY" |
| 24 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 25 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 26 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 27 | rm -- "$dst.$$.tmp" |
| 28 | else |
| 29 | echo " GEN $dst" |
| 30 | mv -- "$dst.$$.tmp" "$dst" |
| 31 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 32 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 33 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 34 | src="$srctree/$d/Config.src" |
| 35 | dst="$d/Config.in" |
| 36 | if test -f "$src"; then |
| 37 | echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 38 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 39 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
| 40 | echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp" |
Denys Vlasenko | c84c85a | 2010-05-14 20:30:44 +0200 | [diff] [blame] | 41 | while read -r; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 42 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 43 | printf "%s\n" "$REPLY" |
| 44 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 45 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 46 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 47 | rm -- "$dst.$$.tmp" |
| 48 | else |
| 49 | echo " GEN $dst" |
| 50 | mv -- "$dst.$$.tmp" "$dst" |
| 51 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 52 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 53 | done |
| 54 | |
| 55 | # Last read failed. This is normal. Don't exit with its error code: |
| 56 | exit 0 |