aboutsummaryrefslogtreecommitdiff
path: root/scripts/embedded_scripts
blob: 7245ba6e084b450cf9c1951140f5152c70c98534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

target="$1"
loc="$2"

test "$target" || exit 1
test "$SED" || SED=sed
test "$DD" || DD=dd

# Some people were bitten by their system lacking a (proper) od
od -v -b </dev/null >/dev/null
if test $? != 0; then
	echo 'od tool is not installed or cannot accept "-v -b" options'
	exit 1
fi

exec >"$target.$$"

scripts=""
if [ -d "$loc" ]
then
	scripts=$(cd $loc; ls * 2>/dev/null)
fi

n=$(echo $scripts | wc -w)

if [ $n -ne 0 ]
then
	printf '#ifdef DEFINE_script_names\n'
	printf 'const char script_names[] ALIGN1 = '
	for i in $scripts
	do
		printf '"%s\\0"' $i
	done
	printf ';\n'
	printf '#else\n'
	printf 'extern const char script_names[] ALIGN1;\n'
	printf '#endif\n'
fi
printf "#define NUM_SCRIPTS $n\n\n"

if [ $n -ne 0 ]
then
	printf '#define UNPACKED_SCRIPTS_LENGTH '
	for i in $scripts
	do
		cat $loc/$i
		printf '\000'
	done | wc -c

	printf '#define PACKED_SCRIPTS \\\n'
	for i in $scripts
	do
		cat $loc/$i
		printf '\000'
	done | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
	| grep -v '^ ' \
	| $SED -e 's/^[^ ]*//' \
		-e 's/ //g' \
		-e '/^$/d' \
		-e 's/\(...\)/0\1,/g' \
		-e 's/$/ \\/'
	printf '\n'
fi

mv -- "$target.$$" "$target"