aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/embedded_scripts107
-rwxr-xr-xscripts/gen_build_files.sh21
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
3target="$1" 3target="$1"
4loc="$2" 4custom_loc="$2"
5applet_loc="$3"
5 6
6test "$target" || exit 1 7test "$target" || exit 1
7test "$SED" || SED=sed 8test "$SED" || SED=sed
@@ -14,46 +15,102 @@ if test $? != 0; then
14 exit 1 15 exit 1
15fi 16fi
16 17
17exec >"$target.$$" 18custom_scripts=""
18 19if [ -d "$custom_loc" ]
19scripts=""
20if [ -d "$loc" ]
21then 20then
22 scripts=$(cd $loc; ls * 2>/dev/null) 21 custom_scripts=$(cd $custom_loc; ls * 2>/dev/null)
23fi 22fi
23all_scripts=$(applets/busybox.mkscripts)
24
25# all_scripts includes applet scripts and custom scripts, sort them out
26applet_scripts=""
27for i in $all_scripts
28do
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
43done
24 44
25n=$(echo $scripts | wc -w) 45# we know the custom scripts are present but applet scripts might have
46# become detached from their configuration
47for i in $applet_scripts
48do
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
55done
26 56
27if [ $n -ne 0 ] 57n=$(echo $custom_scripts $applet_scripts | wc -w)
58nall=$(echo $all_scripts | wc -w)
59
60if [ $n -ne $nall ]
28then 61then
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 64fi
65
66concatenate_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
79exec >"$target.$$"
80
81if [ $n -ne 0 ]
82then
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'
39fi 100fi
40printf "#define NUM_SCRIPTS $n\n\n" 101
102printf "\n"
103printf '#define NUM_SCRIPTS %d\n' $n
104printf "\n"
41 105
42if [ $n -ne 0 ] 106if [ $n -ne 0 ]
43then 107then
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"; }
17gen() { status "GEN" "$@"; } 17gen() { status "GEN" "$@"; }
18chk() { status "CHK" "$@"; } 18chk() { status "CHK" "$@"; }
19 19
20# scripts in the 'embed' directory are treated as fake applets
21custom_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
20generate() 33generate()
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,