-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmkbundle
executable file
·136 lines (111 loc) · 3.05 KB
/
mkbundle
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# Filebundle generator
# Copyright (C) 2009 Andreas Öman
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -u # Fail on undefined vars
READER="cat"
SOURCE=
DEPFILE=
OUTPUT=
PREFIX=
COMPRESS=false
usage()
{
cat << EOF
usage: $0 options
Generate a filebundle .c-file from a directory
OPTIONS:
-h Show this message
-s Source path
-d Dependency file (for use with make)
-o Output file (.c file)
-z Compress individual files using gzip
-p Filebundle prefix
EOF
}
while getopts "s:d:o:zhp:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
z)
READER="gzip -9"
COMPRESS=true
;;
d)
DEPFILE="$OPTARG"
;;
s)
SOURCE="$OPTARG"
;;
o)
OUTPUT="$OPTARG"
;;
p)
PREFIX="$OPTARG"
;;
esac
done
if [[ -z $SOURCE ]] || [[ -z $OUTPUT ]] || [[ -z $PREFIX ]]; then
usage
exit 1
fi
FILES=`find "${SOURCE}" -mindepth 1 -and \( \( -name .svn -or -name "*~" -or -name .DS_Store \) -and -prune \) -or -print | sed "s%^$SOURCE/%%" | xargs echo`
echo >${OUTPUT} "// auto-generated by $0"
for file in $FILES; do
if [ -f ${SOURCE}/$file ]; then
name=`echo $file | sed -e s#[/.-]#_#g`
echo >>${OUTPUT} "// ${SOURCE}/$file"
echo >>${OUTPUT} "static const unsigned char embedded_$name[]={"
$READER <${SOURCE}/$file | od -v -An -b | awk '/[^\s]+/ { print $0 }' | sed s/^\ */0/ | sed s/\ *$/,/| sed s/\ /,\ 0/g >>${OUTPUT}
echo >>${OUTPUT} "};"
fi
done
echo >>${OUTPUT} "#include \"libsvc/filebundle.h\""
echo >>${OUTPUT} "static const struct filebundle_entry filebundle_entries[] = {"
[[ -z $DEPFILE ]] || echo >${DEPFILE} -n "${OUTPUT}: ${SOURCE} "
for file in $FILES; do
[[ -z $DEPFILE ]] || echo >>${DEPFILE} -n "${SOURCE}/$file "
if [ -f ${SOURCE}/$file ]; then
if $COMPRESS; then
ORIGINAL_SIZE=`stat -c "%s" ${SOURCE}/$file`
else
ORIGINAL_SIZE="-1"
fi
N=`echo $file | sed -e s#[/.-]#_#g`
echo >>${OUTPUT} "{\"$file\", embedded_$N, sizeof(embedded_$N),${ORIGINAL_SIZE}},"
fi
done
echo >>${OUTPUT} "{(void *)0, 0, 0, 0}};"
[[ -z $DEPFILE ]] || echo >>${DEPFILE} ""
for file in $FILES; do
[[ -z $DEPFILE ]] || echo >>${DEPFILE} "${SOURCE}/$file: "
done
cat >>${OUTPUT} <<EOF
static struct filebundle fb = {
.entries = &filebundle_entries[0],
.prefix = "${PREFIX}"
};
static void __attribute__((constructor)) filebundle_init (void)
{
extern struct filebundle *filebundles;
fb.next = filebundles;
filebundles = &fb;
}
EOF