aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/embedded_scripts125
-rwxr-xr-xscripts/gen_build_files.sh21
-rwxr-xr-xscripts/trylink21
3 files changed, 154 insertions, 13 deletions
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
new file mode 100755
index 000000000..aa7bf3e8a
--- /dev/null
+++ b/scripts/embedded_scripts
@@ -0,0 +1,125 @@
1#!/bin/sh
2
3. ./.config || exit 1
4
5target="$1"
6custom_loc="$2"
7applet_loc="$3"
8
9test "$target" || exit 1
10test "$SED" || SED=sed
11test "$DD" || DD=dd
12
13if [ x"$CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS" != x"y" ]
14then
15 printf '#define NUM_SCRIPTS 0\n' >"$target"
16 exit 0
17fi
18
19# Some people were bitten by their system lacking a (proper) od
20od -v -b </dev/null >/dev/null
21if test $? != 0; then
22 echo 'od tool is not installed or cannot accept "-v -b" options'
23 exit 1
24fi
25
26custom_scripts=""
27if [ -d "$custom_loc" ]
28then
29 custom_scripts=$(cd $custom_loc; ls * 2>/dev/null)
30fi
31all_scripts=$($srctree/applets/busybox.mkscripts)
32
33# all_scripts includes applet scripts and custom scripts, sort them out
34applet_scripts=""
35for i in $all_scripts
36do
37 found=0
38 for j in $custom_scripts
39 do
40 if [ "$i" = "$j" ]
41 then
42 found=1
43 break;
44 fi
45 done
46 if [ $found -eq 0 ]
47 then
48 # anything that isn't a custom script is an applet script
49 applet_scripts="$applet_scripts $i"
50 fi
51done
52
53# we know the custom scripts are present but applet scripts might have
54# become detached from their configuration
55for i in $applet_scripts
56do
57 #if [ ! -f "$applet_loc/$i" -a ! -f "$custom_loc/$i" ]
58 if [ ! -f "$applet_loc/$i" ]
59 then
60 echo "missing applet script $i"
61 exit 1
62 fi
63done
64
65n=$(echo $custom_scripts $applet_scripts | wc -w)
66nall=$(echo $all_scripts | wc -w)
67
68if [ $n -ne $nall ]
69then
70 echo "script mismatch $n != $nall"
71 exit 1
72fi
73
74concatenate_scripts() {
75 for i in $custom_scripts
76 do
77 cat $custom_loc/$i
78 printf '\000'
79 done
80 for i in $applet_scripts
81 do
82 cat $applet_loc/$i
83 printf '\000'
84 done
85}
86
87exec >"$target.$$"
88
89if [ $n -ne 0 ]
90then
91 printf '#ifdef DEFINE_SCRIPT_DATA\n'
92 printf 'const uint16_t applet_numbers[] = {\n'
93 for i in $custom_scripts $applet_scripts
94 do
95 # TODO support applets with names including invalid characters
96 printf '\tAPPLET_NO_%s,\n' $i
97 done
98 printf '};\n'
99 printf '#else\n'
100 printf 'extern const uint16_t applet_numbers[];\n'
101 printf '#endif\n'
102fi
103
104printf "\n"
105printf '#define NUM_SCRIPTS %d\n' $n
106printf "\n"
107
108if [ $n -ne 0 ]
109then
110 printf '#define UNPACKED_SCRIPTS_LENGTH '
111 concatenate_scripts | wc -c
112
113 printf '#define PACKED_SCRIPTS \\\n'
114 concatenate_scripts | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | \
115 od -v -b \
116 | grep -v '^ ' \
117 | $SED -e 's/^[^ ]*//' \
118 -e 's/ //g' \
119 -e '/^$/d' \
120 -e 's/\(...\)/0\1,/g' \
121 -e 's/$/ \\/'
122 printf '\n'
123fi
124
125mv -- "$target.$$" "$target"
diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh
index f79fa2f83..92de681ac 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 * 2>/dev/null)
27 do
28 printf "IF_FEATURE_SH_EMBEDDED_SCRIPTS(APPLET_SCRIPTED(%s, scripted, BB_DIR_USR_BIN, BB_SUID_DROP, scripted))\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,
diff --git a/scripts/trylink b/scripts/trylink
index ba2d265bc..bb6b2de2f 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -149,8 +149,8 @@ try $CC $CFLAGS $LDFLAGS \
149# Stop when no lib can be removed. 149# Stop when no lib can be removed.
150while test "$LDLIBS"; do 150while test "$LDLIBS"; do
151 $debug && echo "Trying libraries: $LDLIBS" 151 $debug && echo "Trying libraries: $LDLIBS"
152 all_needed=true 152 dropped_non_first_lib=false
153 last_needed=false 153 first_lib=true
154 for one in $LDLIBS; do 154 for one in $LDLIBS; do
155 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` 155 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
156 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" 156 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
@@ -167,20 +167,17 @@ while test "$LDLIBS"; do
167 if test $? = 0; then 167 if test $? = 0; then
168 echo " Library $one is not needed, excluding it" 168 echo " Library $one is not needed, excluding it"
169 LDLIBS="$without_one" 169 LDLIBS="$without_one"
170 all_needed=false 170 $first_lib || dropped_non_first_lib=true
171 last_needed=false
172 else 171 else
173 echo " Library $one is needed, can't exclude it (yet)" 172 echo " Library $one is needed, can't exclude it (yet)"
174 last_needed=true 173 first_lib=false
175 fi 174 fi
176 done 175 done
177 # All libs were needed, can't remove any 176 # We can stop trying to drop libs if either all libs were needed,
178 $all_needed && break 177 # or we excluded only the _first_ few.
179 # Optimization: was the last tried lib needed? 178 # (else: we dropped some intermediate lib(s), maybe now we can succeed
180 if $last_needed; then 179 # in dropping some of the preceding ones)
181 # Was it the only one lib left? Don't test again then. 180 $dropped_non_first_lib || break
182 { echo "$LDLIBS" | grep -q ' '; } || break
183 fi
184done 181done
185 182
186# Make the binary with final, minimal list of libs 183# Make the binary with final, minimal list of libs