1 |
#!/bin/bash |
2 |
|
3 |
# this gem of a hack gathers all fiels required by the client for the platform |
4 |
# by deep magic, it works on osx, linux and windows. on MY osx, linux |
5 |
# and windows, that is. |
6 |
|
7 |
STRIP="strip" |
8 |
LIBEXT=so |
9 |
LIB0=so.? |
10 |
SO=so |
11 |
SYSLIB=/usr/lib |
12 |
MAKE=make |
13 |
ARCHNAME=x86 |
14 |
GENPACK_ENVVARS="LD_LIBRARY_PATH=." |
15 |
|
16 |
umask 022 |
17 |
|
18 |
if [ "$(uname -s)" = CYGWIN_NT-5.0 ]; then |
19 |
. ~/.setenv |
20 |
|
21 |
OS=windows |
22 |
URLADER=.exe |
23 |
unset PANGO |
24 |
PERL=/c/perl/bin/perl |
25 |
MAKE=nmake |
26 |
SYSLIB=/c/gtk/bin |
27 |
LIBEXT=dll |
28 |
LIB0=dll |
29 |
SO=dll |
30 |
STRIP=":" # stripping the perl library kills it, and apparently, everythignis always stripped |
31 |
|
32 |
# fontconfig apparently ignores env vars and always looks at ./etc/fonts/fonts.conf, |
33 |
# but only if . isn't actually called bin or lib. hope for the best. |
34 |
GENPACK_ENVVARS="FONTCONFIG_PATH=pm/Deliantra/Client/private/resources/fonts FONTCONFIG_FILE=fonts.conf" |
35 |
|
36 |
pango-querymodules() { |
37 |
/c/gtk/bin/pango-querymodules # empty output usually |
38 |
} |
39 |
|
40 |
elif [ "$(uname -s)" = Darwin ]; then |
41 |
OS=darwin |
42 |
URLADER=-osx105 |
43 |
PANGO=1.6.0 |
44 |
PERL=/opt/local/bin/perl |
45 |
GENPACK_ENVVARS="DYLD_LIBRARY_PATH=." |
46 |
|
47 |
SYSLIB=/opt/local/lib |
48 |
LIB0=dylib |
49 |
SO=bundle |
50 |
STRIP="strip -x" |
51 |
elif [ $(arch) = i686 ]; then |
52 |
OS=linux |
53 |
URLADER=-x86 |
54 |
PANGO=1.5.0 |
55 |
PERL=/usr/bin/perl |
56 |
else |
57 |
OS=linux |
58 |
URLADER=-amd64 |
59 |
PANGO=1.5.0 |
60 |
PERL=/usr/bin/perl |
61 |
ARCHNAME=amd64 |
62 |
fi |
63 |
|
64 |
export DIST="$(pwd)/dist/$OS-$ARCHNAME" |
65 |
|
66 |
rm -rf "$DIST" |
67 |
mkdir -p "$DIST" |
68 |
|
69 |
#PERL=/opt/perl |
70 |
#PANGO=1.6.0 |
71 |
|
72 |
export EV_EVENTFD=0 |
73 |
export EV_INOTIFY=0 |
74 |
export EV_SIGNALFD=0 |
75 |
|
76 |
if true; then |
77 |
for mod in deliantra/Deliantra deliantra/Deliantra-Client; do |
78 |
# for mod in common-sense AnyEvent EV JSON-XS deliantra/Deliantra Compress-LZF BDB Guard deliantra/Deliantra-Client; do |
79 |
# for mod in CFPlus; do |
80 |
( |
81 |
cd /root/src/$mod |
82 |
cvs update -AdP |
83 |
$PERL Makefile.PL </dev/null >/dev/null |
84 |
$MAKE clean >/dev/null |
85 |
$PERL Makefile.PL </dev/null >/dev/null |
86 |
if ! $MAKE install >log 2>&1; then |
87 |
cat log |
88 |
exit |
89 |
fi |
90 |
rm -f log |
91 |
$MAKE clean >/dev/null |
92 |
) || exit |
93 |
done |
94 |
fi |
95 |
|
96 |
cat <<EOF >"$DIST"/pango.rc |
97 |
[Pango] |
98 |
ModuleFiles = pango.modules |
99 |
EOF |
100 |
|
101 |
( |
102 |
exec 5>"$DIST"/pango.modules |
103 |
pango-querymodules | grep ^/ | while read lib rest; do |
104 |
base=$(basename "$lib") |
105 |
[ "$base" = pango-basic-x.$LIBEXT ] && continue |
106 |
cp -p "$lib" "$DIST"/. |
107 |
echo "$base $rest" >&5 |
108 |
done |
109 |
) |
110 |
|
111 |
############################################################################# |
112 |
|
113 |
IFS=" |
114 |
" # space tab nl cr - cr for windows |
115 |
eval $($PERL -V:sitebinexp -V:sitearchexp -V:sitelib -V:vendorarchexp -V:vendorlibexp -V:archlibexp -V:privlibexp) |
116 |
|
117 |
mkdir -p "$DIST"/pm/bin |
118 |
cp "$sitebinexp"/deliantra "$DIST"/pm/bin/ |
119 |
cp -p util/run "$DIST" |
120 |
|
121 |
( |
122 |
exec <util/modules.dep |
123 |
|
124 |
# while read type name; do |
125 |
# if [ "$type" = d ]; then |
126 |
# # not implemented |
127 |
# dir=$(echo "$name" | sed -e s%::%/%g) |
128 |
# for lib in "$sitearchexp" "$sitelib" "$vendorarchexp" "$vendorlibexp" "$archlibexp" "$privlibexp"; do |
129 |
# if [ -e "$lib/auto/$dir/.packlist" ]; then |
130 |
# cat "$lib/auto/$dir/.packlist" |
131 |
# fi |
132 |
# echo "x $lib $dir" |
133 |
# done |
134 |
# elif [ $type = m ]; then |
135 |
# : |
136 |
# else |
137 |
# echo "unknown type $type ($name)" |
138 |
# exit 1 |
139 |
# fi |
140 |
# done |
141 |
mkdir -p "$DIST"/pm |
142 |
|
143 |
export OSDIST="$DIST" |
144 |
[ "$OS" = windows ] && OSDIST=$(cygpath -w "$OSDIST") |
145 |
|
146 |
$PERL -e ' |
147 |
use Config; |
148 |
use File::Glob qw(:glob); |
149 |
use File::Copy; |
150 |
use File::Path; |
151 |
use File::Basename; |
152 |
|
153 |
my @path = do { |
154 |
my %seen; |
155 |
grep !$seen{$_}++, grep length, map $Config{$_}, qw( |
156 |
sitearchexp |
157 |
sitelib |
158 |
vendorarchexp |
159 |
vendorlibexp |
160 |
archlibexp |
161 |
privlibexp |
162 |
) |
163 |
}; |
164 |
|
165 |
while (<>) { |
166 |
s/\015?\012$//; |
167 |
next if /^(#|$)/; |
168 |
s/\.dynob$/.'$SO'/; |
169 |
|
170 |
my $found; |
171 |
for my $lib (@path) { |
172 |
chdir $lib || next; |
173 |
|
174 |
my @glob = File::Glob::bsd_glob $_, 0; # explicit 0 needed |
175 |
|
176 |
if (@glob) { |
177 |
++$found; |
178 |
|
179 |
for (@glob) { |
180 |
if (-d $_) { |
181 |
system "rsync", "-aR", $_, "$ENV{DIST}/pm/."; |
182 |
} else { |
183 |
File::Path::mkpath "$ENV{OSDIST}/pm/" . dirname $_; |
184 |
File::Copy::syscopy "$_", "$ENV{OSDIST}/pm/$_" |
185 |
or die "$ENV{OSDIST}/pm/$_: $!"; |
186 |
|
187 |
if (s/\.pm$//) { |
188 |
$auto = "auto/$_"; |
189 |
|
190 |
for my $glob ("*.'$SO'", "autosplit.ix", "*.al") { |
191 |
for (bsd_glob "$auto/$glob", 0) { |
192 |
File::Path::mkpath "$ENV{OSDIST}/pm/" . dirname $_; |
193 |
File::Copy::syscopy "$_", "$ENV{OSDIST}/pm/$_"; |
194 |
} |
195 |
} |
196 |
} |
197 |
} |
198 |
} |
199 |
|
200 |
last; |
201 |
} |
202 |
} |
203 |
|
204 |
warn "$_: not found\n" |
205 |
unless $found; |
206 |
} |
207 |
' |
208 |
) || exit |
209 |
|
210 |
############################################################################# |
211 |
|
212 |
if [ "$OS" = windows ]; then |
213 |
libdeps() { |
214 |
objdump -p "$1" | awk '/\tDLL Name:/ { print $3 }' | while read lib; do |
215 |
set -- $(type "$lib") |
216 |
case "$3" in |
217 |
/c/WINNT/* | /c/sdk/* ) |
218 |
;; |
219 |
* ) |
220 |
echo "$3" |
221 |
;; |
222 |
esac |
223 |
done |
224 |
} |
225 |
elif [ "$OS" = darwin ]; then |
226 |
libdeps() { |
227 |
otool -L "$1" | perl -ne 'print "$1\n" if m%^\s+(/opt\S+)%' |
228 |
} |
229 |
else |
230 |
libdeps() { |
231 |
ldd "$1" | perl -ne 'print "$1\n" if / => (\S+)/' |
232 |
} |
233 |
fi |
234 |
|
235 |
add_deps() { |
236 |
local so="$1" |
237 |
libdeps "$so" | while read path; do |
238 |
base="$(basename "$path")" |
239 |
if ! [ -e "$base" ]; then |
240 |
cp -p "$path" . |
241 |
chmod 755 "$base" |
242 |
add_deps "$base" |
243 |
fi |
244 |
done |
245 |
} |
246 |
|
247 |
( |
248 |
cd "$DIST" |
249 |
|
250 |
cp -p "$PERL" . |
251 |
|
252 |
if [ "$OS" = windows ]; then |
253 |
cp -p $SYSLIB/libvorbisfile-3.dll $SYSLIB/mikmod.dll $SYSLIB/libpng12-0.dll . |
254 |
cp /root/src/CFPlus/util/splash.bmp . |
255 |
chmod -R u+rwX pm/auto |
256 |
|
257 |
# convert perl to a non-console-app |
258 |
$PERL -MWin32::Exe -e '$e = new Win32::Exe"perl.exe"; $e->set_subsystem_windows; $e->write' |
259 |
|
260 |
else |
261 |
# patch braindamaged pango |
262 |
perl -pe 's{/u(?=sr/lib(32)?/pango)}{/\x00}g; s{\Q'$PANGO'\E\x00}{y.t.u\x00}g' <$SYSLIB/libpango-1.0.$LIB0 >libpango-1.0.$LIB0 |
263 |
chmod 755 libpango-1.0.$LIB0 |
264 |
|
265 |
for lib in mikmod vorbisfile; do |
266 |
cp -p $SYSLIB/lib$lib.$LIB0 . |
267 |
chmod 755 lib$lib.$LIB0 |
268 |
done |
269 |
fi |
270 |
|
271 |
for so in $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl; do |
272 |
add_deps "$so" |
273 |
done |
274 |
|
275 |
rm -f pm/auto/POSIX/*.al |
276 |
|
277 |
for lib in \ |
278 |
dl c m rt pthread nsl crypt \ |
279 |
X11 Xext Xau Xdmcp ICE SM Xrandr Xrender Xxf86vm drm GL \ |
280 |
z |
281 |
do |
282 |
rm -f lib"$lib".$SO0 |
283 |
done |
284 |
|
285 |
if [ "$OS" = darwin ]; then |
286 |
# "dll hell" is most severe on os x, because apple |
287 |
# does not generally give a shit for backwards compatibility, |
288 |
# alwayss ships outdated libraries and often provides libraries |
289 |
# of the same name as well-known libs (such as libjpeg), that |
290 |
# of course do something completely different |
291 |
patchlibs() { |
292 |
<"$1" \ |
293 |
perl -0777 -pe ' |
294 |
s%('"/opt/local/lib[^\x00]*/lib"'([^\x00/]+)\.dylib\x00)% |
295 |
my $s = $1; |
296 |
my $r = "libdeliantra-$2.dylib\x00"; |
297 |
(length $r) <= (length $s) |
298 |
or die "lib replacement <$r> larger than <$s>\n"; |
299 |
substr $s, 0, length $r, $r; |
300 |
$s |
301 |
%ge |
302 |
' \ |
303 |
>"$1~" && mv "$1~" "$1" || exit 67 |
304 |
} |
305 |
|
306 |
# patch bundles and pango modules with external dependencies, |
307 |
# should be few, so hardcode(tm) |
308 |
for so in \ |
309 |
pm/auto/BDB/BDB.bundle \ |
310 |
pm/auto/Deliantra/Client/Client.bundle \ |
311 |
*.$LIBEXT |
312 |
do |
313 |
patchlibs "$so" |
314 |
done |
315 |
|
316 |
# now patch and rename all .dylibs |
317 |
for lib in *.$LIB0; do |
318 |
stem="${lib#lib}" |
319 |
stem="${stem%.$LIB0}" |
320 |
patchlibs "$lib" |
321 |
mv "$lib" "libdeliantra-$stem.dylib" |
322 |
done |
323 |
fi |
324 |
|
325 |
[ "$OS" = linux ] && chrpath -d perl # debian perls have an rpath. really. |
326 |
$STRIP $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl |
327 |
) |
328 |
|
329 |
printf -- urlader$URLADER >"$DIST".urlader |
330 |
|
331 |
echo >"$DIST".genpack genpack deliantra_S-$OS-"$ARCHNAME" '"$EXE_VER"' '"$1"' $GENPACK_ENVVARS ./perl run |
332 |
|
333 |
exit |
334 |
|
335 |
|
336 |
tar cf deliantra-gnu-linux-$ARCHNAME.tar deliantra-gnu-linux-$ARCHNAME |
337 |
gzip -9vf deliantra-gnu-linux-$ARCHNAME.tar |
338 |
todata deliantra-gnu-linux-$ARCHNAME.tar.gz |
339 |
|