blob: 986e851604c39d2d9b22d6376d4846e9c8d493b9 [file] [log] [blame]
Denys Vlasenko4f2ef4a2018-11-01 09:53:25 +01001#!/bin/sh
2
3target="$1"
4loc="$2"
5
6test "$target" || exit 1
7test "$SED" || SED=sed
8test "$DD" || DD=dd
9
10# Some people were bitten by their system lacking a (proper) od
11od -v -b </dev/null >/dev/null
12if test $? != 0; then
13 echo 'od tool is not installed or cannot accept "-v -b" options'
14 exit 1
15fi
16
17exec >"$target.$$"
18
19scripts=""
20if [ -d "$loc" ]
21then
22 scripts=$(cd $loc; ls * 2>/dev/null)
23fi
24
25n=$(echo $scripts | wc -w)
26
27if [ $n -ne 0 ]
28then
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'
39fi
40printf "#define NUM_SCRIPTS $n\n\n"
41
42if [ $n -ne 0 ]
43then
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'
64fi
65
66mv -- "$target.$$" "$target"