diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/embedded_scripts | 107 | ||||
-rwxr-xr-x | scripts/gen_build_files.sh | 21 |
2 files changed, 102 insertions, 26 deletions
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts index 7245ba6e0..b7a023ce0 100755 --- a/scripts/embedded_scripts +++ b/scripts/embedded_scripts | |||
@@ -1,7 +1,8 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | target="$1" | 3 | target="$1" |
4 | loc="$2" | 4 | custom_loc="$2" |
5 | applet_loc="$3" | ||
5 | 6 | ||
6 | test "$target" || exit 1 | 7 | test "$target" || exit 1 |
7 | test "$SED" || SED=sed | 8 | test "$SED" || SED=sed |
@@ -14,46 +15,102 @@ if test $? != 0; then | |||
14 | exit 1 | 15 | exit 1 |
15 | fi | 16 | fi |
16 | 17 | ||
17 | exec >"$target.$$" | 18 | custom_scripts="" |
18 | 19 | if [ -d "$custom_loc" ] | |
19 | scripts="" | ||
20 | if [ -d "$loc" ] | ||
21 | then | 20 | then |
22 | scripts=$(cd $loc; ls * 2>/dev/null) | 21 | custom_scripts=$(cd $custom_loc; ls * 2>/dev/null) |
23 | fi | 22 | fi |
23 | all_scripts=$(applets/busybox.mkscripts) | ||
24 | |||
25 | # all_scripts includes applet scripts and custom scripts, sort them out | ||
26 | applet_scripts="" | ||
27 | for i in $all_scripts | ||
28 | do | ||
29 | found=0 | ||
30 | for j in $custom_scripts | ||
31 | do | ||
32 | if [ "$i" = "$j" ] | ||
33 | then | ||
34 | found=1 | ||
35 | break; | ||
36 | fi | ||
37 | done | ||
38 | if [ $found -eq 0 ] | ||
39 | then | ||
40 | # anything that isn't a custom script is an applet script | ||
41 | applet_scripts="$applet_scripts $i" | ||
42 | fi | ||
43 | done | ||
24 | 44 | ||
25 | n=$(echo $scripts | wc -w) | 45 | # we know the custom scripts are present but applet scripts might have |
46 | # become detached from their configuration | ||
47 | for i in $applet_scripts | ||
48 | do | ||
49 | #if [ ! -f "$applet_loc/$i" -a ! -f "$custom_loc/$i" ] | ||
50 | if [ ! -f "$applet_loc/$i" ] | ||
51 | then | ||
52 | echo "missing applet script $i" | ||
53 | exit 1 | ||
54 | fi | ||
55 | done | ||
26 | 56 | ||
27 | if [ $n -ne 0 ] | 57 | n=$(echo $custom_scripts $applet_scripts | wc -w) |
58 | nall=$(echo $all_scripts | wc -w) | ||
59 | |||
60 | if [ $n -ne $nall ] | ||
28 | then | 61 | then |
29 | printf '#ifdef DEFINE_script_names\n' | 62 | echo "script mismatch $n != $nall" |
30 | printf 'const char script_names[] ALIGN1 = ' | 63 | exit 1 |
31 | for i in $scripts | 64 | fi |
65 | |||
66 | concatenate_scripts() { | ||
67 | for i in $custom_scripts | ||
68 | do | ||
69 | cat $custom_loc/$i | ||
70 | printf '\000' | ||
71 | done | ||
72 | for i in $applet_scripts | ||
32 | do | 73 | do |
33 | printf '"%s\\0"' $i | 74 | cat $applet_loc/$i |
75 | printf '\000' | ||
34 | done | 76 | done |
35 | printf ';\n' | 77 | } |
78 | |||
79 | exec >"$target.$$" | ||
80 | |||
81 | if [ $n -ne 0 ] | ||
82 | then | ||
83 | printf '#ifdef DEFINE_SCRIPT_DATA\n' | ||
84 | if [ $n -ne 0 ] | ||
85 | then | ||
86 | printf 'const uint16_t applet_numbers[] = {\n' | ||
87 | for i in $custom_scripts $applet_scripts | ||
88 | do | ||
89 | # TODO support applets with names including invalid characters | ||
90 | printf '\tAPPLET_NO_%s,\n' $i | ||
91 | done | ||
92 | printf '};\n' | ||
93 | fi | ||
36 | printf '#else\n' | 94 | printf '#else\n' |
37 | printf 'extern const char script_names[] ALIGN1;\n' | 95 | if [ $n -ne 0 ] |
96 | then | ||
97 | printf 'extern const uint16_t applet_numbers[];\n' | ||
98 | fi | ||
38 | printf '#endif\n' | 99 | printf '#endif\n' |
39 | fi | 100 | fi |
40 | printf "#define NUM_SCRIPTS $n\n\n" | 101 | |
102 | printf "\n" | ||
103 | printf '#define NUM_SCRIPTS %d\n' $n | ||
104 | printf "\n" | ||
41 | 105 | ||
42 | if [ $n -ne 0 ] | 106 | if [ $n -ne 0 ] |
43 | then | 107 | then |
44 | printf '#define UNPACKED_SCRIPTS_LENGTH ' | 108 | printf '#define UNPACKED_SCRIPTS_LENGTH ' |
45 | for i in $scripts | 109 | concatenate_scripts | wc -c |
46 | do | ||
47 | cat $loc/$i | ||
48 | printf '\000' | ||
49 | done | wc -c | ||
50 | 110 | ||
51 | printf '#define PACKED_SCRIPTS \\\n' | 111 | printf '#define PACKED_SCRIPTS \\\n' |
52 | for i in $scripts | 112 | concatenate_scripts | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | \ |
53 | do | 113 | od -v -b \ |
54 | cat $loc/$i | ||
55 | printf '\000' | ||
56 | done | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \ | ||
57 | | grep -v '^ ' \ | 114 | | grep -v '^ ' \ |
58 | | $SED -e 's/^[^ ]*//' \ | 115 | | $SED -e 's/^[^ ]*//' \ |
59 | -e 's/ //g' \ | 116 | -e 's/ //g' \ |
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index f79fa2f83..64e4bffa9 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh | |||
@@ -17,12 +17,26 @@ status() { printf ' %-8s%s\n' "$1" "$2"; } | |||
17 | gen() { status "GEN" "$@"; } | 17 | gen() { status "GEN" "$@"; } |
18 | chk() { status "CHK" "$@"; } | 18 | chk() { status "CHK" "$@"; } |
19 | 19 | ||
20 | # scripts in the 'embed' directory are treated as fake applets | ||
21 | custom_scripts() | ||
22 | { | ||
23 | custom_loc="$1" | ||
24 | if [ -d "$custom_loc" ] | ||
25 | then | ||
26 | for i in $(cd "$custom_loc"; ls *) | ||
27 | do | ||
28 | printf "APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, dummy)\n" $i; | ||
29 | done | ||
30 | fi | ||
31 | } | ||
32 | |||
20 | generate() | 33 | generate() |
21 | { | 34 | { |
22 | # NB: data to be inserted at INSERT line is coming on stdin | 35 | # NB: data to be inserted at INSERT line is coming on stdin |
23 | src="$1" | 36 | src="$1" |
24 | dst="$2" | 37 | dst="$2" |
25 | header="$3" | 38 | header="$3" |
39 | loc="$4" | ||
26 | #chk "${dst}" | 40 | #chk "${dst}" |
27 | { | 41 | { |
28 | # Need to use printf: different shells have inconsistent | 42 | # Need to use printf: different shells have inconsistent |
@@ -32,6 +46,10 @@ generate() | |||
32 | sed -n '/^INSERT$/ q; p' "${src}" | 46 | sed -n '/^INSERT$/ q; p' "${src}" |
33 | # copy stdin to stdout | 47 | # copy stdin to stdout |
34 | cat | 48 | cat |
49 | if [ -n "$loc" ] | ||
50 | then | ||
51 | custom_scripts "$loc" | ||
52 | fi | ||
35 | # print everything after INSERT line | 53 | # print everything after INSERT line |
36 | sed -n '/^INSERT$/ { | 54 | sed -n '/^INSERT$/ { |
37 | :l | 55 | :l |
@@ -53,7 +71,8 @@ sed -n 's@^//applet:@@p' "$srctree"/*/*.c "$srctree"/*/*/*.c \ | |||
53 | | generate \ | 71 | | generate \ |
54 | "$srctree/include/applets.src.h" \ | 72 | "$srctree/include/applets.src.h" \ |
55 | "include/applets.h" \ | 73 | "include/applets.h" \ |
56 | "/* DO NOT EDIT. This file is generated from applets.src.h */" | 74 | "/* DO NOT EDIT. This file is generated from applets.src.h */" \ |
75 | "$srctree/embed" | ||
57 | 76 | ||
58 | # (Re)generate include/usage.h | 77 | # (Re)generate include/usage.h |
59 | # We add line continuation backslash after each line, | 78 | # We add line continuation backslash after each line, |