tweak scripts/gen_build_files.sh
[oweals/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; do
11     d="$REPLY"
12
13     src="$srctree/$d/Kbuild.src"
14     dst="$d/Kbuild"
15     if test -f "$src"; then
16         echo "  CHK     $dst"
17
18         s=`sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c`
19         echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
20         while read; do
21             test x"$REPLY" = x"INSERT" && REPLY="$s"
22             printf "%s\n" "$REPLY"
23         done <"$src" >>"$dst.$$.tmp"
24
25         if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
26             rm "$dst.$$.tmp"
27         else
28             echo "  GEN     $dst"
29             mv "$dst.$$.tmp" "$dst"
30         fi
31     fi
32
33     src="$srctree/$d/Config.src"
34     dst="$d/Config.in"
35     if test -f "$src"; then
36         echo "  CHK     $dst"
37
38         s=`sed -n 's@^//config:@@p' "$srctree/$d"/*.c`
39         echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
40         while read; do
41             test x"$REPLY" = x"INSERT" && REPLY="$s"
42             printf "%s\n" "$REPLY"
43         done <"$src" >>"$dst.$$.tmp"
44
45         if test -f "$dst" && cmp -s "$dst.$$.tmp" "$dst"; then
46             rm "$dst.$$.tmp"
47         else
48             echo "  GEN     $dst"
49             mv "$dst.$$.tmp" "$dst"
50         fi
51     fi
52
53 done
54
55 # Last read failed. This is normal. Don't exit with its error code:
56 exit 0