gen_build_files.sh uses bashism, document it
[oweals/busybox.git] / scripts / gen_build_files.sh
1 #!/bin/bash
2 # bashism:
3 # "read -r" without variable name reads line into $REPLY
4 # without stripping whitespace.
5
6 test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
7
8 # cd to objtree
9 cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
10
11 srctree="$1"
12
13 find -type d | while read -r d; do
14         src="$srctree/$d/Kbuild.src"
15         dst="$d/Kbuild"
16         if test -f "$src"; then
17                 echo "  CHK     $dst"
18
19                 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
20                 echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp"
21                 while read -r; do
22                         test x"$REPLY" = x"INSERT" && REPLY="$s"
23                         printf "%s\n" "$REPLY"
24                 done <"$src" >>"$dst.$$.tmp"
25
26                 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
32         fi
33
34         src="$srctree/$d/Config.src"
35         dst="$d/Config.in"
36         if test -f "$src"; then
37                 echo "  CHK     $dst"
38
39                 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
40                 echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp"
41                 while read -r; do
42                         test x"$REPLY" = x"INSERT" && REPLY="$s"
43                         printf "%s\n" "$REPLY"
44                 done <"$src" >>"$dst.$$.tmp"
45
46                 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
52         fi
53 done
54
55 # Last read failed. This is normal. Don't exit with its error code:
56 exit 0