blob: ea14de5e243aeaa2caf3aa2976237923fa37c8e3 [file] [log] [blame]
Denys Vlasenko084e2282010-05-15 21:08:51 +02001#!/bin/bash
2# bashism:
3# "read -r" without variable name reads line into $REPLY
4# without stripping whitespace.
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02005
Denys Vlasenko572b9a32010-05-09 16:20:52 +02006test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02007
8# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +02009cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020010
11srctree="$1"
12
Denys Vlasenko084e2282010-05-15 21:08:51 +020013find -type d | while read -r d; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020014 src="$srctree/$d/Kbuild.src"
15 dst="$d/Kbuild"
16 if test -f "$src"; then
17 echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020018
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020019 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
20 echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
Denys Vlasenkoc84c85a2010-05-14 20:30:44 +020021 while read -r; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020022 test x"$REPLY" = x"INSERT" && REPLY="$s"
23 printf "%s\n" "$REPLY"
24 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020025
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020026 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 Vlasenko7fb68f12010-05-09 04:22:48 +020032 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020033
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020034 src="$srctree/$d/Config.src"
35 dst="$d/Config.in"
36 if test -f "$src"; then
37 echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020038
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020039 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
40 echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
Denys Vlasenkoc84c85a2010-05-14 20:30:44 +020041 while read -r; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020042 test x"$REPLY" = x"INSERT" && REPLY="$s"
43 printf "%s\n" "$REPLY"
44 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020045
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020046 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 Vlasenko7fb68f12010-05-09 04:22:48 +020052 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020053done
54
55# Last read failed. This is normal. Don't exit with its error code:
56exit 0