ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/util/gatherer
Revision: 1.5
Committed: Fri Dec 30 10:59:00 2011 UTC (12 years, 4 months ago) by root
Branch: MAIN
Changes since 1.4: +13 -6 lines
Log Message:
*** empty log message ***

File Contents

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