ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/util/gatherer
Revision: 1.15
Committed: Sat Jan 28 00:03:31 2012 UTC (12 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +17 -10 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/bin/bash
2
3 # this gem of a hack gathers all files 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 EXTRA_EXTRACT=
16
17 umask 022
18
19 if [ "$(uname -s)" = CYGWIN_NT-5.0 ]; then
20 . ~/.setenv
21
22 OS=windows
23 URLADER=windows-x86
24 unset PANGO
25 PERL=/c/perl/bin/perl
26 MAKE=nmake
27 SYSLIB=/c/gtk/bin
28 LIBEXT=dll
29 LIB0=dll
30 SO=dll
31 STRIP=":" # stripping the perl library kills it, and apparently, everythignis always stripped
32 EXTRA_EXTRACT="-MWin32::GUI::SplashScreen"
33
34 # fontconfig apparently ignores env vars and always looks at ./etc/fonts/fonts.conf,
35 # but only if . isn't actually called bin or lib. hope for the best.
36 GENPACK_ENVVARS="FONTCONFIG_PATH=pm/Deliantra/Client/private/resources/fonts FONTCONFIG_FILE=fonts.conf"
37
38 pango-querymodules() {
39 /c/gtk/bin/pango-querymodules # empty output usually
40 }
41
42 elif [ "$(uname -s)" = Darwin ]; then
43 OS=darwin
44 URLADER=darwin-x86
45 PANGO=1.6.0
46 PERL=/opt/local/bin/perl
47 GENPACK_ENVVARS="DYLD_LIBRARY_PATH=."
48
49 SYSLIB=/opt/local/lib
50 LIB0=dylib
51 SO=bundle
52 STRIP="strip -x"
53 elif [ $(arch) = i686 ]; then
54 OS=linux
55 URLADER=linux-x86
56 PANGO=1.5.0
57 PERL=/usr/bin/perl
58 else
59 OS=linux
60 URLADER=linux-amd64
61 PANGO=1.5.0
62 PERL=/usr/bin/perl
63 ARCHNAME=amd64
64 fi
65
66 DISTf="dist/$OS-$ARCHNAME"
67 export DIST="$(pwd)/$DISTf"
68
69 eval $("$PERL" -V:sitebinexp:)
70
71 "$PERL" "$sitebinexp"/perl-libextractor \
72 --perl --core-support --script deliantra $EXTRA_EXTRACT \
73 --runtime-only \
74 --copy "$DISTf" --exedir . --dlldir . --bindir pm/bin --libdir pm
75
76 cat <<EOF >"$DIST"/pango.rc
77 [Pango]
78 ModuleFiles = pango.modules
79 EOF
80
81 (
82 exec 5>"$DIST"/pango.modules
83 pango-querymodules | grep ^/ | while read lib rest; do
84 base=$(basename "$lib")
85 [ "$base" = pango-basic-x.$LIBEXT ] && continue
86 cp -p "$lib" "$DIST"/.
87 echo "./$base $rest" >&5 # using ./ seems to help pango not to rummage around in /usr/lib etc.
88 done
89 )
90
91 #############################################################################
92
93 IFS="
94 " # space tab nl cr - cr for windows
95 eval $($PERL -V:sitebinexp -V:sitearchexp -V:sitelib -V:vendorarchexp -V:vendorlibexp -V:archlibexp -V:privlibexp)
96
97 mkdir -p "$DIST"/pm/bin
98 cp "$sitebinexp"/deliantra "$DIST"/pm/bin/
99 cp -p util/run "$DIST"
100
101 #############################################################################
102
103 if [ "$OS" = windows ]; then
104 libdeps() {
105 objdump -p "$1" | awk '/\tDLL Name:/ { print $3 }' | while read lib; do
106 set -- $(type "$lib")
107 case "$3" in
108 /c/WINNT/* | /c/sdk/* )
109 ;;
110 * )
111 echo "$3"
112 ;;
113 esac
114 done
115 }
116 elif [ "$OS" = darwin ]; then
117 libdeps() {
118 otool -L "$1" | perl -ne 'print "$1\n" if m%^\s+(/opt\S+)%'
119 }
120 else
121 libdeps() {
122 ldd "$1" | perl -ne 'print "$1\n" if / => (\S+)/'
123 }
124 fi
125
126 add_deps() {
127 local so="$1"
128 libdeps "$so" | while read path; do
129 base="$(basename "$path")"
130 if ! [ -e "$base" ]; then
131 cp -p "$path" .
132 chmod 755 "$base"
133 add_deps "$base"
134 fi
135 done
136 }
137
138 (
139 cd "$DIST"
140
141 case "$OS" in
142 windows )
143 cp -p $SYSLIB/libvorbisfile-3.dll $SYSLIB/mikmod.dll $SYSLIB/libpng12-0.dll $SYSLIB/jpeg.dll .
144 cp -p $SYSLIB/jpeg.dll .
145 cp /root/src/CFPlus/util/splash.bmp .
146 chmod -R u+rwX pm/auto
147
148 # convert perl to a non-console-app
149 $PERL -MWin32::Exe -e '$e = new Win32::Exe"perl.exe"; $e->set_subsystem_windows; $e->write'
150 ;;
151 linux )
152 cp -p $SYSLIB/libjpeg.so.62 .
153 ;;
154 esac
155
156 if [ "$OS" != windows ]; then
157 for lib in mikmod vorbisfile; do
158 cp -p $SYSLIB/lib$lib.$LIB0 .
159 chmod 755 lib$lib.$LIB0
160 done
161 fi
162
163 for so in $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl; do
164 add_deps "$so"
165 done
166
167 rm -f pm/auto/POSIX/*.al
168
169 for lib in \
170 dl c m rt pthread nsl crypt \
171 X11 Xext Xau Xdmcp ICE SM Xrandr Xrender Xxf86vm drm GL \
172 z
173 do
174 rm -f lib"$lib".$LIB0
175 done
176
177 if [ "$OS" != windows ]; then
178 # patch braindamaged pango
179
180 if [ "$OS" != darwin ]; then
181 set libpango-1.0.$LIB0
182 perl -pe 's{/u(?=sr/lib(32)?/pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1"
183 else
184 set lib*pango-1.0.0.dylib
185 perl -pe 's{/o(?=pt/local/.../pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1"
186 fi
187 chmod 755 "$1"
188 fi
189
190 if [ "$OS" = darwin ]; then
191 # "dll hell" is most severe on os x, because apple
192 # does not generally give a shit for backwards compatibility,
193 # alwayss ships outdated libraries and often provides libraries
194 # of the same name as well-known libs (such as libjpeg), that
195 # of course do something completely different
196 patchlibs() {
197 <"$1" \
198 perl -0777 -pe '
199 s%('"/opt/local/lib[^\x00]*/lib"'([^\x00/]+)\.dylib\x00)%
200 my $s = $1;
201 my $r = "libdeliantra-$2.dylib\x00";
202 (length $r) <= (length $s)
203 or die "lib replacement <$r> larger than <$s>\n";
204 substr $s, 0, length $r, $r;
205 $s
206 %ge
207 ' \
208 >"$1~" && mv "$1~" "$1" || exit 67
209 }
210
211 # patch bundles and pango modules with external dependencies,
212 # should be few, so hardcode(tm)
213 for so in \
214 pm/auto/BDB/BDB.bundle \
215 pm/auto/Deliantra/Client/Client.bundle \
216 *.$LIBEXT
217 do
218 patchlibs "$so"
219 done
220
221 # now patch and rename all .dylibs
222 for lib in *.$LIB0; do
223 stem="${lib#lib}"
224 stem="${stem%.$LIB0}"
225 patchlibs "$lib"
226 mv "$lib" "libdeliantra-$stem.dylib"
227 done
228 fi
229
230 [ "$OS" = linux ] && chrpath -d perl $(find pm -name "*.so") # debian perls have an rpath, many modules too
231 $STRIP $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl
232
233 : >timidity.cfg
234 )
235
236 cat >"$DIST".vars <<EOF
237 G_URLADER="$URLADER"
238 G_OS="$OS"
239 G_ARCHNAME="$ARCHNAME"
240 G_ENVVARS="$GENPACK_ENVVARS"
241 G_COMMAND="./perl run"
242 EOF
243