typo fix
[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 # In separate objtree build, include/ might not exist yet
8 mkdir include 2>/dev/null
9
10 srctree="$1"
11
12 # (Re)generate include/applets.h
13 src="$srctree/include/applets.src.h"
14 dst="include/applets.h"
15 s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
16 old=`cat "$dst" 2>/dev/null`
17 # Why "IFS='' read -r REPLY"??
18 # This atrocity is needed to read lines without mangling.
19 # IFS='' prevents whitespace trimming,
20 # -r suppresses backslash handling.
21 new=`echo "/* DO NOT EDIT. This file is generated from applets.src.h */"
22 while IFS='' read -r REPLY; do
23         test x"$REPLY" = x"INSERT" && REPLY="$s"
24         printf "%s\n" "$REPLY"
25 done <"$src"`
26 if test x"$new" != x"$old"; then
27         echo "  GEN     $dst"
28         printf "%s\n" "$new" >"$dst"
29 fi
30
31 # (Re)generate include/usage.h
32 src="$srctree/include/usage.src.h"
33 dst="include/usage.h"
34 # We add line continuation backslash after each line,
35 # and insert empty line before each line which doesn't start
36 # with space or tab
37 # (note: we need to use \\\\ because of ``)
38 s=`sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\\\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\\\@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c`
39 old=`cat "$dst" 2>/dev/null`
40 new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */"
41 while IFS='' read -r REPLY; do
42         test x"$REPLY" = x"INSERT" && REPLY="$s"
43         printf "%s\n" "$REPLY"
44 done <"$src"`
45 if test x"$new" != x"$old"; then
46         echo "  GEN     $dst"
47         printf "%s\n" "$new" >"$dst"
48 fi
49
50 # (Re)generate */Kbuild and */Config.in
51 { cd -- "$srctree" && find . -type d; } | while read -r d; do
52         d="${d#./}"
53
54         src="$srctree/$d/Kbuild.src"
55         dst="$d/Kbuild"
56         if test -f "$src"; then
57                 mkdir -p -- "$d" 2>/dev/null
58                 #echo "  CHK     $dst"
59
60                 s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c`
61
62                 old=`cat "$dst" 2>/dev/null`
63                 new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src"
64                 while IFS='' read -r REPLY; do
65                         test x"$REPLY" = x"INSERT" && REPLY="$s"
66                         printf "%s\n" "$REPLY"
67                 done <"$src"`
68                 if test x"$new" != x"$old"; then
69                         echo "  GEN     $dst"
70                         printf "%s\n" "$new" >"$dst"
71                 fi
72         fi
73
74         src="$srctree/$d/Config.src"
75         dst="$d/Config.in"
76         if test -f "$src"; then
77                 mkdir -p -- "$d" 2>/dev/null
78                 #echo "  CHK     $dst"
79
80                 s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c`
81
82                 old=`cat "$dst" 2>/dev/null`
83                 new=`echo "# DO NOT EDIT. This file is generated from Config.src"
84                 while IFS='' read -r REPLY; do
85                         test x"$REPLY" = x"INSERT" && REPLY="$s"
86                         printf "%s\n" "$REPLY"
87                 done <"$src"`
88                 if test x"$new" != x"$old"; then
89                         echo "  GEN     $dst"
90                         printf "%s\n" "$new" >"$dst"
91                 fi
92         fi
93 done
94
95 # Last read failed. This is normal. Don't exit with its error code:
96 exit 0