diff options
Diffstat (limited to 'scripts/gen_build_files.sh')
-rwxr-xr-x | scripts/gen_build_files.sh | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh new file mode 100755 index 000000000..d2db907f3 --- /dev/null +++ b/scripts/gen_build_files.sh | |||
@@ -0,0 +1,59 @@ | |||
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 | src="$srctree/$d/Kbuild.src" | ||
12 | dst="$d/Kbuild" | ||
13 | if test -f "$src"; then | ||
14 | echo " CHK $dst" | ||
15 | |||
16 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` | ||
17 | echo "# DO NOT EDIT. This file is generated from Kbuild.src" >"$dst.$$.tmp" | ||
18 | |||
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 | ||
24 | test x"$REPLY" = x"INSERT" && REPLY="$s" | ||
25 | printf "%s\n" "$REPLY" | ||
26 | done <"$src" >>"$dst.$$.tmp" | ||
27 | |||
28 | 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 | ||
34 | fi | ||
35 | |||
36 | src="$srctree/$d/Config.src" | ||
37 | dst="$d/Config.in" | ||
38 | if test -f "$src"; then | ||
39 | echo " CHK $dst" | ||
40 | |||
41 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` | ||
42 | echo "# DO NOT EDIT. This file is generated from Config.src" >"$dst.$$.tmp" | ||
43 | |||
44 | while IFS='' read -r REPLY; do | ||
45 | test x"$REPLY" = x"INSERT" && REPLY="$s" | ||
46 | printf "%s\n" "$REPLY" | ||
47 | done <"$src" >>"$dst.$$.tmp" | ||
48 | |||
49 | 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 | ||
55 | fi | ||
56 | done | ||
57 | |||
58 | # Last read failed. This is normal. Don't exit with its error code: | ||
59 | exit 0 | ||