build system: make gen_build_files.sh messages more inline with the rest
[platform/upstream/busybox.git] / scripts / gen_build_files.sh
1 #!/bin/sh
2
3 test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
4
5 # cd to objtree
6 cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
7
8 srctree="$1"
9
10 find -type d | while read -r d; do
11         d="${d#./}"
12         src="$srctree/$d/Kbuild.src"
13         dst="$d/Kbuild"
14         if test -f "$src"; then
15                 #echo "  CHK     $dst"
16
17                 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
18                 echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
19
20                 # Why "IFS='' read -r REPLY"??
21                 # This atrocity is needed to read lines without mangling.
22                 # IFS='' prevents whitespace trimming,
23                 # -r suppresses backslash handling.
24                 while IFS='' read -r REPLY; do
25                         test x"$REPLY" = x"INSERT" && REPLY="$s"
26                         printf "%s\n" "$REPLY"
27                 done <"$src" >>"$dst.$$.tmp"
28
29                 if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
30                         rm -- "$dst.$$.tmp"
31                 else
32                         echo "  GEN     $dst"
33                         mv -- "$dst.$$.tmp" "$dst"
34                 fi
35         fi
36
37         src="$srctree/$d/Config.src"
38         dst="$d/Config.in"
39         if test -f "$src"; then
40                 #echo "  CHK     $dst"
41
42                 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
43                 echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
44
45                 while IFS='' read -r REPLY; do
46                         test x"$REPLY" = x"INSERT" && REPLY="$s"
47                         printf "%s\n" "$REPLY"
48                 done <"$src" >>"$dst.$$.tmp"
49
50                 if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
51                         rm -- "$dst.$$.tmp"
52                 else
53                         echo "  GEN     $dst"
54                         mv -- "$dst.$$.tmp" "$dst"
55                 fi
56         fi
57 done
58
59 # Last read failed. This is normal. Don't exit with its error code:
60 exit 0