diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/embedded_scripts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts new file mode 100755 index 000000000..986e85160 --- /dev/null +++ b/scripts/embedded_scripts | |||
@@ -0,0 +1,66 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | target="$1" | ||
4 | loc="$2" | ||
5 | |||
6 | test "$target" || exit 1 | ||
7 | test "$SED" || SED=sed | ||
8 | test "$DD" || DD=dd | ||
9 | |||
10 | # Some people were bitten by their system lacking a (proper) od | ||
11 | od -v -b </dev/null >/dev/null | ||
12 | if test $? != 0; then | ||
13 | echo 'od tool is not installed or cannot accept "-v -b" options' | ||
14 | exit 1 | ||
15 | fi | ||
16 | |||
17 | exec >"$target.$$" | ||
18 | |||
19 | scripts="" | ||
20 | if [ -d "$loc" ] | ||
21 | then | ||
22 | scripts=$(cd $loc; ls * 2>/dev/null) | ||
23 | fi | ||
24 | |||
25 | n=$(echo $scripts | wc -w) | ||
26 | |||
27 | if [ $n -ne 0 ] | ||
28 | then | ||
29 | printf '#ifdef DEFINE_script_names\n' | ||
30 | printf 'const char script_names[] ALIGN1 = ' | ||
31 | for i in $scripts | ||
32 | do | ||
33 | printf '"%s\\0"' $i | ||
34 | done | ||
35 | printf '"\\0";\n' | ||
36 | printf '#else\n' | ||
37 | printf 'extern const char script_names[] ALIGN1;\n' | ||
38 | printf '#endif\n' | ||
39 | fi | ||
40 | printf "#define NUM_SCRIPTS $n\n\n" | ||
41 | |||
42 | if [ $n -ne 0 ] | ||
43 | then | ||
44 | printf '#define UNPACKED_SCRIPTS_LENGTH ' | ||
45 | for i in $scripts | ||
46 | do | ||
47 | cat $loc/$i | ||
48 | printf '\000' | ||
49 | done | wc -c | ||
50 | |||
51 | printf '#define PACKED_SCRIPTS \\\n' | ||
52 | for i in $scripts | ||
53 | do | ||
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 '^ ' \ | ||
58 | | $SED -e 's/^[^ ]*//' \ | ||
59 | -e 's/ //g' \ | ||
60 | -e '/^$/d' \ | ||
61 | -e 's/\(...\)/0\1,/g' \ | ||
62 | -e 's/$/ \\/' | ||
63 | printf '\n' | ||
64 | fi | ||
65 | |||
66 | mv -- "$target.$$" "$target" | ||