Rob Landley | 7e21d5f | 2006-04-27 23:34:46 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 3 | target="$1" |
| 4 | loc="$2" |
Rob Landley | 7e21d5f | 2006-04-27 23:34:46 +0000 | [diff] [blame] | 5 | |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 6 | test "$target" || exit 1 |
Rob Landley | 7e21d5f | 2006-04-27 23:34:46 +0000 | [diff] [blame] | 7 | test "$loc" || loc=. |
Bernhard Reutner-Fischer | a1e130f | 2006-05-21 10:45:01 +0000 | [diff] [blame] | 8 | test -x "$loc/usage" || exit 1 |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 9 | test "$SED" || SED=sed |
Bernhard Reutner-Fischer | b35e3a8 | 2009-10-27 17:05:31 +0100 | [diff] [blame] | 10 | test "$DD" || DD=dd |
Denis Vlasenko | 7d219aa | 2006-10-05 10:17:08 +0000 | [diff] [blame] | 11 | |
Denys Vlasenko | 0fdf2e1 | 2010-09-16 15:46:20 +0200 | [diff] [blame] | 12 | # Some people were bitten by their system lacking a (proper) od |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 13 | od -v -b </dev/null >/dev/null |
Denys Vlasenko | 06a80bd | 2010-09-16 13:23:15 +0200 | [diff] [blame] | 14 | if test $? != 0; then |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 15 | echo 'od tool is not installed or cannot accept "-v -b" options' |
Denys Vlasenko | 06a80bd | 2010-09-16 13:23:15 +0200 | [diff] [blame] | 16 | exit 1 |
| 17 | fi |
| 18 | |
Denys Vlasenko | 08f0b78 | 2010-07-04 23:34:02 +0200 | [diff] [blame] | 19 | exec >"$target.$$" |
Rob Landley | 7e21d5f | 2006-04-27 23:34:46 +0000 | [diff] [blame] | 20 | |
Denys Vlasenko | 2f32bf8 | 2010-06-06 04:14:28 +0200 | [diff] [blame] | 21 | echo '#define UNPACKED_USAGE "" \' |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 22 | "$loc/usage" | od -v -b \ |
Denys Vlasenko | 5fa6d1a | 2015-10-05 11:15:43 +0200 | [diff] [blame] | 23 | | grep -v '^ ' \ |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 24 | | $SED -e 's/^[^ ]*//' \ |
| 25 | -e 's/ //g' \ |
| 26 | -e '/^$/d' \ |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 27 | -e 's/\(...\)/\\\1/g' \ |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 28 | -e 's/^/"/' \ |
| 29 | -e 's/$/" \\/' |
| 30 | echo '' |
Denys Vlasenko | 5fa6d1a | 2015-10-05 11:15:43 +0200 | [diff] [blame] | 31 | # "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines: |
| 32 | #0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117 |
| 33 | # 000010 000010 026533 063144 020135 026533 020143 047503 |
| 34 | #0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111 |
| 35 | # 043116 044504 056522 055440 066055 046040 043517 044506 |
| 36 | #0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111 |
| 37 | # 042514 020135 026533 020141 041501 044524 047117 044506 |
Denis Vlasenko | 937b10f | 2008-02-09 09:26:43 +0000 | [diff] [blame] | 38 | |
Denys Vlasenko | fe93624 | 2017-01-06 19:16:36 +0100 | [diff] [blame] | 39 | echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`" |
| 40 | echo |
| 41 | |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 42 | echo '#define PACKED_USAGE \' |
Denis Vlasenko | 63e49fa | 2008-08-09 20:31:57 +0000 | [diff] [blame] | 43 | ## Breaks on big-endian systems! |
| 44 | ## # Extra effort to avoid using "od -t x1": -t is not available |
| 45 | ## # in non-CONFIG_DESKTOPed busybox od |
Denis Vlasenko | ea7c9b3 | 2008-09-25 10:39:10 +0000 | [diff] [blame] | 46 | ## |
Denis Vlasenko | 63e49fa | 2008-08-09 20:31:57 +0000 | [diff] [blame] | 47 | ## "$loc/usage" | bzip2 -1 | od -v -x \ |
| 48 | ## | $SED -e 's/^[^ ]*//' \ |
Denys Vlasenko | 3581c62 | 2010-01-25 13:39:24 +0100 | [diff] [blame] | 49 | ## -e 's/ //g' \ |
| 50 | ## -e '/^$/d' \ |
| 51 | ## -e 's/\(..\)\(..\)/0x\2,0x\1,/g' |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 52 | ## -e 's/$/ \\/' |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 53 | "$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \ |
Denys Vlasenko | 5fa6d1a | 2015-10-05 11:15:43 +0200 | [diff] [blame] | 54 | | grep -v '^ ' \ |
Denis Vlasenko | 937b10f | 2008-02-09 09:26:43 +0000 | [diff] [blame] | 55 | | $SED -e 's/^[^ ]*//' \ |
Bernhard Reutner-Fischer | b35e3a8 | 2009-10-27 17:05:31 +0100 | [diff] [blame] | 56 | -e 's/ //g' \ |
| 57 | -e '/^$/d' \ |
Denys Vlasenko | 195c436 | 2013-11-26 14:56:29 +0100 | [diff] [blame] | 58 | -e 's/\(...\)/0\1,/g' \ |
Denys Vlasenko | 0e5ba08 | 2010-06-05 23:11:07 +0200 | [diff] [blame] | 59 | -e 's/$/ \\/' |
| 60 | echo '' |
Denys Vlasenko | 08f0b78 | 2010-07-04 23:34:02 +0200 | [diff] [blame] | 61 | |
Denys Vlasenko | 1d36f24 | 2010-07-08 02:29:47 +0200 | [diff] [blame] | 62 | mv -- "$target.$$" "$target" |