blob: d2db907f3541ad29355daecae840368bd08e1c76 [file] [log] [blame]
Denys Vlasenko3015a132010-05-17 01:59:16 +02001#!/bin/sh
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02002
Denys Vlasenko572b9a32010-05-09 16:20:52 +02003test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02004
5# cd to objtree
Denys Vlasenko8e3aff02010-05-10 11:00:11 +02006cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
Denys Vlasenko7fb68f12010-05-09 04:22:48 +02007
8srctree="$1"
9
Denys Vlasenko084e2282010-05-15 21:08:51 +020010find -type d | while read -r d; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020011 src="$srctree/$d/Kbuild.src"
12 dst="$d/Kbuild"
13 if test -f "$src"; then
14 echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020015
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020016 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
17 echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020018
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 Vlasenko8e3aff02010-05-10 11:00:11 +020024 test x"$REPLY" = x"INSERT" && REPLY="$s"
25 printf "%s\n" "$REPLY"
26 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020027
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020028 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 Vlasenko7fb68f12010-05-09 04:22:48 +020034 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020035
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020036 src="$srctree/$d/Config.src"
37 dst="$d/Config.in"
38 if test -f "$src"; then
39 echo " CHK $dst"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020040
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020041 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
42 echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
Denys Vlasenkoa1db8b82010-05-18 00:24:17 +020043
44 while IFS='' read -r REPLY; do
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020045 test x"$REPLY" = x"INSERT" && REPLY="$s"
46 printf "%s\n" "$REPLY"
47 done <"$src" >>"$dst.$$.tmp"
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020048
Denys Vlasenko8e3aff02010-05-10 11:00:11 +020049 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 Vlasenko7fb68f12010-05-09 04:22:48 +020055 fi
Denys Vlasenko7fb68f12010-05-09 04:22:48 +020056done
57
58# Last read failed. This is normal. Don't exit with its error code:
59exit 0