blob: 36fc2a007218e7684657e7d68042bef41bc9c686 [file] [log] [blame]
Rob Landley7e21d5f2006-04-27 23:34:46 +00001#!/bin/sh
2
Denis Vlasenko7d219aa2006-10-05 10:17:08 +00003target="$1"
4loc="$2"
Rob Landley7e21d5f2006-04-27 23:34:46 +00005
Denis Vlasenko7d219aa2006-10-05 10:17:08 +00006test "$target" || exit 1
Rob Landley7e21d5f2006-04-27 23:34:46 +00007test "$loc" || loc=.
Bernhard Reutner-Fischera1e130f2006-05-21 10:45:01 +00008test -x "$loc/usage" || exit 1
Denis Vlasenko7d219aa2006-10-05 10:17:08 +00009test "$SED" || SED=sed
Bernhard Reutner-Fischerb35e3a82009-10-27 17:05:31 +010010test "$DD" || DD=dd
Denis Vlasenko7d219aa2006-10-05 10:17:08 +000011
Denys Vlasenko0fdf2e12010-09-16 15:46:20 +020012# Some people were bitten by their system lacking a (proper) od
Denys Vlasenko195c4362013-11-26 14:56:29 +010013od -v -b </dev/null >/dev/null
Denys Vlasenko06a80bd2010-09-16 13:23:15 +020014if test $? != 0; then
Denys Vlasenko195c4362013-11-26 14:56:29 +010015 echo 'od tool is not installed or cannot accept "-v -b" options'
Denys Vlasenko06a80bd2010-09-16 13:23:15 +020016 exit 1
17fi
18
Denys Vlasenko08f0b782010-07-04 23:34:02 +020019exec >"$target.$$"
Rob Landley7e21d5f2006-04-27 23:34:46 +000020
Denys Vlasenko2f32bf82010-06-06 04:14:28 +020021echo '#define UNPACKED_USAGE "" \'
Denys Vlasenko195c4362013-11-26 14:56:29 +010022"$loc/usage" | od -v -b \
Denys Vlasenko5fa6d1a2015-10-05 11:15:43 +020023| grep -v '^ ' \
Denys Vlasenko0e5ba082010-06-05 23:11:07 +020024| $SED -e 's/^[^ ]*//' \
25 -e 's/ //g' \
26 -e '/^$/d' \
Denys Vlasenko195c4362013-11-26 14:56:29 +010027 -e 's/\(...\)/\\\1/g' \
Denys Vlasenko0e5ba082010-06-05 23:11:07 +020028 -e 's/^/"/' \
29 -e 's/$/" \\/'
30echo ''
Denys Vlasenko5fa6d1a2015-10-05 11:15:43 +020031# "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 Vlasenko937b10f2008-02-09 09:26:43 +000038
Denys Vlasenkofe936242017-01-06 19:16:36 +010039echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`"
40echo
41
Denys Vlasenko0e5ba082010-06-05 23:11:07 +020042echo '#define PACKED_USAGE \'
Denis Vlasenko63e49fa2008-08-09 20:31:57 +000043## 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 Vlasenkoea7c9b32008-09-25 10:39:10 +000046##
Denis Vlasenko63e49fa2008-08-09 20:31:57 +000047## "$loc/usage" | bzip2 -1 | od -v -x \
48## | $SED -e 's/^[^ ]*//' \
Denys Vlasenko3581c622010-01-25 13:39:24 +010049## -e 's/ //g' \
50## -e '/^$/d' \
51## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
Denys Vlasenko0e5ba082010-06-05 23:11:07 +020052## -e 's/$/ \\/'
Denys Vlasenko195c4362013-11-26 14:56:29 +010053"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
Denys Vlasenko5fa6d1a2015-10-05 11:15:43 +020054| grep -v '^ ' \
Denis Vlasenko937b10f2008-02-09 09:26:43 +000055| $SED -e 's/^[^ ]*//' \
Bernhard Reutner-Fischerb35e3a82009-10-27 17:05:31 +010056 -e 's/ //g' \
57 -e '/^$/d' \
Denys Vlasenko195c4362013-11-26 14:56:29 +010058 -e 's/\(...\)/0\1,/g' \
Denys Vlasenko0e5ba082010-06-05 23:11:07 +020059 -e 's/$/ \\/'
60echo ''
Denys Vlasenko08f0b782010-07-04 23:34:02 +020061
Denys Vlasenko1d36f242010-07-08 02:29:47 +020062mv -- "$target.$$" "$target"