source: branches/3.2/mindi-busybox/scripts/gen_build_files.sh @ 3232

Last change on this file since 3232 was 3232, checked in by bruno, 5 years ago
  • Update mindi-busybox to 1.21.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/bin/sh
2
3# Note: was using sed OPTS CMD -- FILES
4# but users complain that many sed implementations
5# are misinterpreting --.
6
7test $# -ge 2 || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
8
9# cd to objtree
10cd -- "$2" || { echo "Syntax: $0 SRCTREE OBJTREE"; exit 1; }
11# In separate objtree build, include/ might not exist yet
12mkdir include 2>/dev/null
13
14srctree="$1"
15
16status() { printf '  %-8s%s\n' "$1" "$2"; }
17gen() { status "GEN" "$@"; }
18chk() { status "CHK" "$@"; }
19
20generate()
21{
22    # NB: data to be inserted at INSERT line is coming on stdin
23    local src="$1" dst="$2" header="$3"
24    #chk "${dst}"
25    {
26        # Need to use printf: different shells have inconsistent
27        # rules re handling of "\n" in echo params.
28        printf "%s\n" "${header}"
29        # print everything up to INSERT line
30        sed -n '/^INSERT$/ q; p' "${src}"
31        # copy stdin to stdout
32        cat
33        # print everything after INSERT line
34        sed -n '/^INSERT$/ { :l; n; p; bl }' "${src}"
35    } >"${dst}.tmp"
36    if ! cmp -s "${dst}" "${dst}.tmp"; then
37        gen "${dst}"
38        mv "${dst}.tmp" "${dst}"
39    else
40        rm -f "${dst}.tmp"
41    fi
42}
43
44# (Re)generate include/applets.h
45sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \
46| generate \
47    "$srctree/include/applets.src.h" \
48    "include/applets.h" \
49    "/* DO NOT EDIT. This file is generated from applets.src.h */"
50
51# (Re)generate include/usage.h
52# We add line continuation backslash after each line,
53# and insert empty line before each line which doesn't start
54# with space or tab
55sed -n -e 's@^//usage:\([ \t].*\)$@\1 \\@p' -e 's@^//usage:\([^ \t].*\)$@\n\1 \\@p' \
56    "$srctree"/*/*.c "$srctree"/*/*/*.c \
57| generate \
58    "$srctree/include/usage.src.h" \
59    "include/usage.h" \
60    "/* DO NOT EDIT. This file is generated from usage.src.h */"
61
62# (Re)generate */Kbuild and */Config.in
63# We skip .dotdirs - makes git/svn/etc users happier
64{ cd -- "$srctree" && find . -type d -not '(' -name '.?*' -prune ')'; } \
65| while read -r d; do
66    d="${d#./}"
67
68    src="$srctree/$d/Kbuild.src"
69    dst="$d/Kbuild"
70    if test -f "$src"; then
71        mkdir -p -- "$d" 2>/dev/null
72
73        sed -n 's@^//kbuild:@@p' "$srctree/$d"/*.c \
74        | generate \
75            "${src}" "${dst}" \
76            "# DO NOT EDIT. This file is generated from Kbuild.src"
77    fi
78
79    src="$srctree/$d/Config.src"
80    dst="$d/Config.in"
81    if test -f "$src"; then
82        mkdir -p -- "$d" 2>/dev/null
83
84        sed -n 's@^//config:@@p' "$srctree/$d"/*.c \
85        | generate \
86            "${src}" "${dst}" \
87            "# DO NOT EDIT. This file is generated from Config.src"
88    fi
89done
90
91# Last read failed. This is normal. Don't exit with its error code:
92exit 0
Note: See TracBrowser for help on using the repository browser.