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=windowx-x86 |
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=darwin-x86 |
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=linux-x86 |
54 |
PANGO=1.5.0 |
55 |
PERL=/usr/bin/perl |
56 |
else |
57 |
OS=linux |
58 |
URLADER=linux-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 || exit |
82 |
cvs update -AdP |
83 |
rm -rf blib |
84 |
$PERL Makefile.PL </dev/null >/dev/null |
85 |
$MAKE clean >/dev/null |
86 |
$PERL Makefile.PL </dev/null >/dev/null |
87 |
if ! $MAKE install >log 2>&1; then |
88 |
echo |
89 |
echo error while building $mod |
90 |
cat log |
91 |
exit |
92 |
fi |
93 |
rm -f log |
94 |
$MAKE clean >/dev/null |
95 |
) || exit |
96 |
done |
97 |
fi |
98 |
|
99 |
cat <<EOF >"$DIST"/pango.rc |
100 |
[Pango] |
101 |
ModuleFiles = pango.modules |
102 |
EOF |
103 |
|
104 |
( |
105 |
exec 5>"$DIST"/pango.modules |
106 |
pango-querymodules | grep ^/ | while read lib rest; do |
107 |
base=$(basename "$lib") |
108 |
[ "$base" = pango-basic-x.$LIBEXT ] && continue |
109 |
cp -p "$lib" "$DIST"/. |
110 |
echo "$base $rest" >&5 |
111 |
done |
112 |
) |
113 |
|
114 |
############################################################################# |
115 |
|
116 |
IFS=" |
117 |
" # space tab nl cr - cr for windows |
118 |
eval $($PERL -V:sitebinexp -V:sitearchexp -V:sitelib -V:vendorarchexp -V:vendorlibexp -V:archlibexp -V:privlibexp) |
119 |
|
120 |
mkdir -p "$DIST"/pm/bin |
121 |
cp "$sitebinexp"/deliantra "$DIST"/pm/bin/ |
122 |
cp -p util/run "$DIST" |
123 |
|
124 |
( |
125 |
exec <util/modules.dep |
126 |
|
127 |
# while read type name; do |
128 |
# if [ "$type" = d ]; then |
129 |
# # not implemented |
130 |
# dir=$(echo "$name" | sed -e s%::%/%g) |
131 |
# for lib in "$sitearchexp" "$sitelib" "$vendorarchexp" "$vendorlibexp" "$archlibexp" "$privlibexp"; do |
132 |
# if [ -e "$lib/auto/$dir/.packlist" ]; then |
133 |
# cat "$lib/auto/$dir/.packlist" |
134 |
# fi |
135 |
# echo "x $lib $dir" |
136 |
# done |
137 |
# elif [ $type = m ]; then |
138 |
# : |
139 |
# else |
140 |
# echo "unknown type $type ($name)" |
141 |
# exit 1 |
142 |
# fi |
143 |
# done |
144 |
mkdir -p "$DIST"/pm |
145 |
|
146 |
export OSDIST="$DIST" |
147 |
[ "$OS" = windows ] && OSDIST=$(cygpath -w "$OSDIST") |
148 |
|
149 |
$PERL -e ' |
150 |
use Config; |
151 |
use File::Glob qw(:glob); |
152 |
use File::Copy; |
153 |
use File::Path; |
154 |
use File::Basename; |
155 |
|
156 |
my @path = do { |
157 |
my %seen; |
158 |
grep !$seen{$_}++, grep length, map $Config{$_}, qw( |
159 |
sitearchexp |
160 |
sitelib |
161 |
vendorarchexp |
162 |
vendorlibexp |
163 |
archlibexp |
164 |
privlibexp |
165 |
) |
166 |
}; |
167 |
|
168 |
while (<>) { |
169 |
s/\015?\012$//; |
170 |
next if /^(#|$)/; |
171 |
s/\.dynob$/.'$SO'/; |
172 |
|
173 |
my $found; |
174 |
for my $lib (@path) { |
175 |
chdir $lib || next; |
176 |
|
177 |
my @glob = File::Glob::bsd_glob $_, 0; # explicit 0 needed |
178 |
|
179 |
if (@glob) { |
180 |
++$found; |
181 |
|
182 |
for (@glob) { |
183 |
if (-d $_) { |
184 |
system "rsync", "-aR", $_, "$ENV{DIST}/pm/."; |
185 |
} else { |
186 |
File::Path::mkpath "$ENV{OSDIST}/pm/" . dirname $_; |
187 |
File::Copy::syscopy "$_", "$ENV{OSDIST}/pm/$_" |
188 |
or die "$ENV{OSDIST}/pm/$_: $!"; |
189 |
|
190 |
if (s/\.pm$//) { |
191 |
$auto = "auto/$_"; |
192 |
|
193 |
for my $glob ("*.'$SO'", "autosplit.ix", "*.al") { |
194 |
for (bsd_glob "$auto/$glob", 0) { |
195 |
File::Path::mkpath "$ENV{OSDIST}/pm/" . dirname $_; |
196 |
File::Copy::syscopy "$_", "$ENV{OSDIST}/pm/$_"; |
197 |
} |
198 |
} |
199 |
} |
200 |
} |
201 |
} |
202 |
|
203 |
last; |
204 |
} |
205 |
} |
206 |
|
207 |
warn "$_: not found\n" |
208 |
unless $found; |
209 |
} |
210 |
' |
211 |
) || exit |
212 |
|
213 |
############################################################################# |
214 |
|
215 |
if [ "$OS" = windows ]; then |
216 |
libdeps() { |
217 |
objdump -p "$1" | awk '/\tDLL Name:/ { print $3 }' | while read lib; do |
218 |
set -- $(type "$lib") |
219 |
case "$3" in |
220 |
/c/WINNT/* | /c/sdk/* ) |
221 |
;; |
222 |
* ) |
223 |
echo "$3" |
224 |
;; |
225 |
esac |
226 |
done |
227 |
} |
228 |
elif [ "$OS" = darwin ]; then |
229 |
libdeps() { |
230 |
otool -L "$1" | perl -ne 'print "$1\n" if m%^\s+(/opt\S+)%' |
231 |
} |
232 |
else |
233 |
libdeps() { |
234 |
ldd "$1" | perl -ne 'print "$1\n" if / => (\S+)/' |
235 |
} |
236 |
fi |
237 |
|
238 |
add_deps() { |
239 |
local so="$1" |
240 |
libdeps "$so" | while read path; do |
241 |
base="$(basename "$path")" |
242 |
if ! [ -e "$base" ]; then |
243 |
cp -p "$path" . |
244 |
chmod 755 "$base" |
245 |
add_deps "$base" |
246 |
fi |
247 |
done |
248 |
} |
249 |
|
250 |
( |
251 |
cd "$DIST" |
252 |
|
253 |
cp -p "$PERL" . |
254 |
|
255 |
if [ "$OS" = windows ]; then |
256 |
cp -p $SYSLIB/libvorbisfile-3.dll $SYSLIB/mikmod.dll $SYSLIB/libpng12-0.dll . |
257 |
cp /root/src/CFPlus/util/splash.bmp . |
258 |
chmod -R u+rwX pm/auto |
259 |
|
260 |
# convert perl to a non-console-app |
261 |
$PERL -MWin32::Exe -e '$e = new Win32::Exe"perl.exe"; $e->set_subsystem_windows; $e->write' |
262 |
|
263 |
else |
264 |
for lib in mikmod vorbisfile; do |
265 |
cp -p $SYSLIB/lib$lib.$LIB0 . |
266 |
chmod 755 lib$lib.$LIB0 |
267 |
done |
268 |
fi |
269 |
|
270 |
for so in $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl; do |
271 |
add_deps "$so" |
272 |
done |
273 |
|
274 |
rm -f pm/auto/POSIX/*.al |
275 |
|
276 |
for lib in \ |
277 |
dl c m rt pthread nsl crypt \ |
278 |
X11 Xext Xau Xdmcp ICE SM Xrandr Xrender Xxf86vm drm GL \ |
279 |
z |
280 |
do |
281 |
rm -f lib"$lib".$LIB0 |
282 |
done |
283 |
|
284 |
if [ "$OS" != windows ]; then |
285 |
# patch braindamaged pango |
286 |
set libpango-1.0.$LIB0 |
287 |
perl -pe 's{/u(?=sr/lib(32)?/pango)}{/\x00}g; s{\Q'$PANGO'\E\x00}{y.t.u\x00}g' <"$1" >"$1~" && mv "$1~" "$1" |
288 |
chmod 755 "$1" |
289 |
fi |
290 |
|
291 |
if [ "$OS" = darwin ]; then |
292 |
# "dll hell" is most severe on os x, because apple |
293 |
# does not generally give a shit for backwards compatibility, |
294 |
# alwayss ships outdated libraries and often provides libraries |
295 |
# of the same name as well-known libs (such as libjpeg), that |
296 |
# of course do something completely different |
297 |
patchlibs() { |
298 |
<"$1" \ |
299 |
perl -0777 -pe ' |
300 |
s%('"/opt/local/lib[^\x00]*/lib"'([^\x00/]+)\.dylib\x00)% |
301 |
my $s = $1; |
302 |
my $r = "libdeliantra-$2.dylib\x00"; |
303 |
(length $r) <= (length $s) |
304 |
or die "lib replacement <$r> larger than <$s>\n"; |
305 |
substr $s, 0, length $r, $r; |
306 |
$s |
307 |
%ge |
308 |
' \ |
309 |
>"$1~" && mv "$1~" "$1" || exit 67 |
310 |
} |
311 |
|
312 |
# patch bundles and pango modules with external dependencies, |
313 |
# should be few, so hardcode(tm) |
314 |
for so in \ |
315 |
pm/auto/BDB/BDB.bundle \ |
316 |
pm/auto/Deliantra/Client/Client.bundle \ |
317 |
*.$LIBEXT |
318 |
do |
319 |
patchlibs "$so" |
320 |
done |
321 |
|
322 |
# now patch and rename all .dylibs |
323 |
for lib in *.$LIB0; do |
324 |
stem="${lib#lib}" |
325 |
stem="${stem%.$LIB0}" |
326 |
patchlibs "$lib" |
327 |
mv "$lib" "libdeliantra-$stem.dylib" |
328 |
done |
329 |
fi |
330 |
|
331 |
[ "$OS" = linux ] && chrpath -d perl # debian perls have an rpath. really. |
332 |
$STRIP $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl |
333 |
) |
334 |
|
335 |
cat >"$DIST".vars <<EOF |
336 |
G_URLADER="$URLADER" |
337 |
G_OS="$OS" |
338 |
G_ARCHNAME="$ARCHNAME" |
339 |
G_ENVVARS="$GENPACK_ENVVARS" |
340 |
G_ARGS="./perl run" |
341 |
EOF |
342 |
|