ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/util/gatherer
Revision: 1.14
Committed: Fri Jan 27 23:13:38 2012 UTC (12 years, 3 months ago) by root
Branch: MAIN
Changes since 1.13: +4 -2 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 --exedir . --dlldir . --bindir pm/bin --libdir pm \
72 --perl --core-support --script deliantra $EXTRA_EXTRACT \
73 --runtime-only \
74 --copy "$DISTf"
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 if [ "$OS" = windows ]; then
142 cp -p $SYSLIB/libvorbisfile-3.dll $SYSLIB/mikmod.dll $SYSLIB/libpng12-0.dll .
143 cp /root/src/CFPlus/util/splash.bmp .
144 chmod -R u+rwX pm/auto
145
146 # convert perl to a non-console-app
147 $PERL -MWin32::Exe -e '$e = new Win32::Exe"perl.exe"; $e->set_subsystem_windows; $e->write'
148
149 else
150 for lib in mikmod vorbisfile; do
151 cp -p $SYSLIB/lib$lib.$LIB0 .
152 chmod 755 lib$lib.$LIB0
153 done
154 fi
155
156 for so in $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl; do
157 add_deps "$so"
158 done
159
160 rm -f pm/auto/POSIX/*.al
161
162 for lib in \
163 dl c m rt pthread nsl crypt \
164 X11 Xext Xau Xdmcp ICE SM Xrandr Xrender Xxf86vm drm GL \
165 z
166 do
167 rm -f lib"$lib".$LIB0
168 done
169
170 if [ "$OS" != windows ]; then
171 # patch braindamaged pango
172
173 if [ "$OS" != darwin ]; then
174 set libpango-1.0.$LIB0
175 perl -pe 's{/u(?=sr/lib(32)?/pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1"
176 else
177 set lib*pango-1.0.0.dylib
178 perl -pe 's{/o(?=pt/local/.../pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1"
179 fi
180 chmod 755 "$1"
181 fi
182
183 if [ "$OS" = darwin ]; then
184 # "dll hell" is most severe on os x, because apple
185 # does not generally give a shit for backwards compatibility,
186 # alwayss ships outdated libraries and often provides libraries
187 # of the same name as well-known libs (such as libjpeg), that
188 # of course do something completely different
189 patchlibs() {
190 <"$1" \
191 perl -0777 -pe '
192 s%('"/opt/local/lib[^\x00]*/lib"'([^\x00/]+)\.dylib\x00)%
193 my $s = $1;
194 my $r = "libdeliantra-$2.dylib\x00";
195 (length $r) <= (length $s)
196 or die "lib replacement <$r> larger than <$s>\n";
197 substr $s, 0, length $r, $r;
198 $s
199 %ge
200 ' \
201 >"$1~" && mv "$1~" "$1" || exit 67
202 }
203
204 # patch bundles and pango modules with external dependencies,
205 # should be few, so hardcode(tm)
206 for so in \
207 pm/auto/BDB/BDB.bundle \
208 pm/auto/Deliantra/Client/Client.bundle \
209 *.$LIBEXT
210 do
211 patchlibs "$so"
212 done
213
214 # now patch and rename all .dylibs
215 for lib in *.$LIB0; do
216 stem="${lib#lib}"
217 stem="${stem%.$LIB0}"
218 patchlibs "$lib"
219 mv "$lib" "libdeliantra-$stem.dylib"
220 done
221 fi
222
223 [ "$OS" = linux ] && chrpath -d perl $(find pm -name "*.so") # debian perls have an rpath, many modules too
224 $STRIP $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl
225
226 : >timidity.cfg
227 )
228
229 cat >"$DIST".vars <<EOF
230 G_URLADER="$URLADER"
231 G_OS="$OS"
232 G_ARCHNAME="$ARCHNAME"
233 G_ENVVARS="$GENPACK_ENVVARS"
234 G_COMMAND="./perl run"
235 EOF
236