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