diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-11-16 07:29:12 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2010-11-16 09:01:54 -0500 |
commit | f718e3a0dbe47ed7ed0398fe4461d33c8f69c669 (patch) | |
tree | 20bad9f86dabaf6af4fb06c9e7d991f307e12b97 | |
parent | b78d561ec79b6a7c29d14bf49c82b600815b2cc4 (diff) | |
download | busybox-w32-f718e3a0dbe47ed7ed0398fe4461d33c8f69c669.tar.gz busybox-w32-f718e3a0dbe47ed7ed0398fe4461d33c8f69c669.tar.bz2 busybox-w32-f718e3a0dbe47ed7ed0398fe4461d33c8f69c669.zip |
gen_build_files.sh: rewrite with sed
The shell parsing of files is incredibly slow on many systems. With
one report, the process was taking a minute or two which made people
thing the build was hung. So rewrite the craziness with sed and proper
shell functions. On an idle system, this cut the runtime by half.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-x | scripts/gen_build_files.sh | 100 |
1 files changed, 47 insertions, 53 deletions
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index 09a95b507..1c1edcc12 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh | |||
@@ -9,43 +9,54 @@ mkdir include 2>/dev/null | |||
9 | 9 | ||
10 | srctree="$1" | 10 | srctree="$1" |
11 | 11 | ||
12 | status() { printf ' %-8s%s\n' "$1" "$2"; } | ||
13 | gen() { status "GEN" "$@"; } | ||
14 | chk() { status "CHK" "$@"; } | ||
15 | |||
16 | generate() | ||
17 | { | ||
18 | local src="$1" dst="$2" header="$3" insert="$4" | ||
19 | #chk "${dst}" | ||
20 | ( | ||
21 | echo "${header}" | ||
22 | if grep -qs '^INSERT$' "${src}"; then | ||
23 | sed -n '1,/^INSERT$/p' "${src}" | ||
24 | echo "${insert}" | ||
25 | sed -n '/^INSERT$/,$p' "${src}" | ||
26 | else | ||
27 | if [ -n "${insert}" ]; then | ||
28 | echo "ERROR: INSERT line missing in: ${src}" 1>&2 | ||
29 | fi | ||
30 | cat "${src}" | ||
31 | fi | ||
32 | ) | sed '/^INSERT$/d' > "${dst}.tmp" | ||
33 | if ! cmp -s "${dst}" "${dst}.tmp"; then | ||
34 | gen "${dst}" | ||
35 | mv "${dst}.tmp" "${dst}" | ||
36 | else | ||
37 | rm -f "${dst}.tmp" | ||
38 | fi | ||
39 | } | ||
40 | |||
12 | # (Re)generate include/applets.h | 41 | # (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` | 42 | s=`sed -n 's@^//applet:@@p' -- "$srctree"/*/*.c "$srctree"/*/*/*.c` |
16 | old=`cat "$dst" 2>/dev/null` | 43 | generate \ |
17 | # Why "IFS='' read -r REPLY"?? | 44 | "$srctree/include/applets.src.h" \ |
18 | # This atrocity is needed to read lines without mangling. | 45 | "include/applets.h" \ |
19 | # IFS='' prevents whitespace trimming, | 46 | "/* DO NOT EDIT. This file is generated from applets.src.h */" \ |
20 | # -r suppresses backslash handling. | 47 | "${s}" |
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 | 48 | ||
31 | # (Re)generate include/usage.h | 49 | # (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, | 50 | # We add line continuation backslash after each line, |
35 | # and insert empty line before each line which doesn't start | 51 | # and insert empty line before each line which doesn't start |
36 | # with space or tab | 52 | # with space or tab |
37 | # (note: we need to use \\\\ because of ``) | 53 | # (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` | 54 | 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` | 55 | generate \ |
40 | new=`echo "/* DO NOT EDIT. This file is generated from usage.src.h */" | 56 | "$srctree/include/usage.src.h" \ |
41 | while IFS='' read -r REPLY; do | 57 | "include/usage.h" \ |
42 | test x"$REPLY" = x"INSERT" && REPLY="$s" | 58 | "/* DO NOT EDIT. This file is generated from usage.src.h */" \ |
43 | printf "%s\n" "$REPLY" | 59 | "${s}" |
44 | done <"$src"` | ||
45 | if test x"$new" != x"$old"; then | ||
46 | echo " GEN $dst" | ||
47 | printf "%s\n" "$new" >"$dst" | ||
48 | fi | ||
49 | 60 | ||
50 | # (Re)generate */Kbuild and */Config.in | 61 | # (Re)generate */Kbuild and */Config.in |
51 | { cd -- "$srctree" && find . -type d; } | while read -r d; do | 62 | { cd -- "$srctree" && find . -type d; } | while read -r d; do |
@@ -55,42 +66,25 @@ fi | |||
55 | dst="$d/Kbuild" | 66 | dst="$d/Kbuild" |
56 | if test -f "$src"; then | 67 | if test -f "$src"; then |
57 | mkdir -p -- "$d" 2>/dev/null | 68 | mkdir -p -- "$d" 2>/dev/null |
58 | #echo " CHK $dst" | ||
59 | 69 | ||
60 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` | 70 | s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` |
61 | 71 | generate \ | |
62 | old=`cat "$dst" 2>/dev/null` | 72 | "${src}" "${dst}" \ |
63 | new=`echo "# DO NOT EDIT. This file is generated from Kbuild.src" | 73 | "# DO NOT EDIT. This file is generated from Kbuild.src" \ |
64 | while IFS='' read -r REPLY; do | 74 | "${s}" |
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 | 75 | fi |
73 | 76 | ||
74 | src="$srctree/$d/Config.src" | 77 | src="$srctree/$d/Config.src" |
75 | dst="$d/Config.in" | 78 | dst="$d/Config.in" |
76 | if test -f "$src"; then | 79 | if test -f "$src"; then |
77 | mkdir -p -- "$d" 2>/dev/null | 80 | mkdir -p -- "$d" 2>/dev/null |
78 | #echo " CHK $dst" | ||
79 | 81 | ||
80 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` | 82 | s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` |
81 | 83 | generate \ | |
82 | old=`cat "$dst" 2>/dev/null` | 84 | "${src}" "${dst}" \ |
83 | new=`echo "# DO NOT EDIT. This file is generated from Config.src" | 85 | "# DO NOT EDIT. This file is generated from Config.src" \ |
84 | while IFS='' read -r REPLY; do | 86 | "${s}" |
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 | 87 | fi |
93 | done | 88 | done |
94 | 89 | ||
95 | # Last read failed. This is normal. Don't exit with its error code: | ||
96 | exit 0 | 90 | exit 0 |