diff options
| author | Ron Yorston <rmy@pobox.com> | 2018-11-28 10:28:18 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2018-11-28 10:28:18 +0000 |
| commit | 2a69a2200a141c1504b662eca64b802cdab71b12 (patch) | |
| tree | eab0cc01852db237a26052a83c8f582ed92b7cd9 /scripts | |
| parent | 97ca1f4b955f486cd26461cb09185335483d2921 (diff) | |
| parent | 572dfb8e78323b9837f7c5e3369ee233a440b8f2 (diff) | |
| download | busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.gz busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.tar.bz2 busybox-w32-2a69a2200a141c1504b662eca64b802cdab71b12.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/embedded_scripts | 125 | ||||
| -rwxr-xr-x | scripts/gen_build_files.sh | 21 | ||||
| -rwxr-xr-x | scripts/trylink | 21 |
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 | |||
| 5 | target="$1" | ||
| 6 | custom_loc="$2" | ||
| 7 | applet_loc="$3" | ||
| 8 | |||
| 9 | test "$target" || exit 1 | ||
| 10 | test "$SED" || SED=sed | ||
| 11 | test "$DD" || DD=dd | ||
| 12 | |||
| 13 | if [ x"$CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS" != x"y" ] | ||
| 14 | then | ||
| 15 | printf '#define NUM_SCRIPTS 0\n' >"$target" | ||
| 16 | exit 0 | ||
| 17 | fi | ||
| 18 | |||
| 19 | # Some people were bitten by their system lacking a (proper) od | ||
| 20 | od -v -b </dev/null >/dev/null | ||
| 21 | if test $? != 0; then | ||
| 22 | echo 'od tool is not installed or cannot accept "-v -b" options' | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | custom_scripts="" | ||
| 27 | if [ -d "$custom_loc" ] | ||
| 28 | then | ||
| 29 | custom_scripts=$(cd $custom_loc; ls * 2>/dev/null) | ||
| 30 | fi | ||
| 31 | all_scripts=$($srctree/applets/busybox.mkscripts) | ||
| 32 | |||
| 33 | # all_scripts includes applet scripts and custom scripts, sort them out | ||
| 34 | applet_scripts="" | ||
| 35 | for i in $all_scripts | ||
| 36 | do | ||
| 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 | ||
| 51 | done | ||
| 52 | |||
| 53 | # we know the custom scripts are present but applet scripts might have | ||
| 54 | # become detached from their configuration | ||
| 55 | for i in $applet_scripts | ||
| 56 | do | ||
| 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 | ||
| 63 | done | ||
| 64 | |||
| 65 | n=$(echo $custom_scripts $applet_scripts | wc -w) | ||
| 66 | nall=$(echo $all_scripts | wc -w) | ||
| 67 | |||
| 68 | if [ $n -ne $nall ] | ||
| 69 | then | ||
| 70 | echo "script mismatch $n != $nall" | ||
| 71 | exit 1 | ||
| 72 | fi | ||
| 73 | |||
| 74 | concatenate_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 | |||
| 87 | exec >"$target.$$" | ||
| 88 | |||
| 89 | if [ $n -ne 0 ] | ||
| 90 | then | ||
| 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' | ||
| 102 | fi | ||
| 103 | |||
| 104 | printf "\n" | ||
| 105 | printf '#define NUM_SCRIPTS %d\n' $n | ||
| 106 | printf "\n" | ||
| 107 | |||
| 108 | if [ $n -ne 0 ] | ||
| 109 | then | ||
| 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' | ||
| 123 | fi | ||
| 124 | |||
| 125 | mv -- "$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"; } | |||
| 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 * 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 | |||
| 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, |
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. |
| 150 | while test "$LDLIBS"; do | 150 | while 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 | ||
| 184 | done | 181 | done |
| 185 | 182 | ||
| 186 | # Make the binary with final, minimal list of libs | 183 | # Make the binary with final, minimal list of libs |
