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 | 084e228 | 2010-05-15 21:08:51 +0200 | [diff] [blame] | 10 | find -type d | while read -r d; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 11 | src="$srctree/$d/Kbuild.src" |
| 12 | dst="$d/Kbuild" |
| 13 | if test -f "$src"; then |
| 14 | echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 15 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 16 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
| 17 | 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^] | 18 | |
| 19 | # Why "IFS='' read -r REPLY"?? |
| 20 | # This atrocity is needed to read lines without mangling. |
| 21 | # IFS='' prevents whitespace trimming, |
| 22 | # -r suppresses backslash handling. |
| 23 | while IFS='' read -r REPLY; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 24 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 25 | printf "%s\n" "$REPLY" |
| 26 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 27 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 28 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 29 | rm -- "$dst.$$.tmp" |
| 30 | else |
| 31 | echo " GEN $dst" |
| 32 | mv -- "$dst.$$.tmp" "$dst" |
| 33 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 34 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 35 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 36 | src="$srctree/$d/Config.src" |
| 37 | dst="$d/Config.in" |
| 38 | if test -f "$src"; then |
| 39 | echo " CHK $dst" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 40 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 41 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
| 42 | 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^] | 43 | |
| 44 | while IFS='' read -r REPLY; do |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 45 | test x"$REPLY" = x"INSERT" && REPLY="$s" |
| 46 | printf "%s\n" "$REPLY" |
| 47 | done <"$src" >>"$dst.$$.tmp" |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 48 | |
Denys Vlasenko | 8e3aff0 | 2010-05-10 11:00:11 +0200 | [diff] [blame] | 49 | if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then |
| 50 | rm -- "$dst.$$.tmp" |
| 51 | else |
| 52 | echo " GEN $dst" |
| 53 | mv -- "$dst.$$.tmp" "$dst" |
| 54 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 55 | fi |
Denys Vlasenko | 7fb68f1 | 2010-05-09 04:22:48 +0200 | [diff] [blame] | 56 | done |
| 57 | |
| 58 | # Last read failed. This is normal. Don't exit with its error code: |
| 59 | exit 0 |