#!/bin/bash # this gem of a hack gathers all files required by the client for the platform # by deep magic, it works on osx, linux and windows. on MY osx, linux # and windows, that is. STRIP="strip" LIBEXT=so LIB0=so.? SO=so SYSLIB=/usr/lib MAKE=make ARCHNAME=x86 GENPACK_ENVVARS="LD_LIBRARY_PATH=." umask 022 if [ "$(uname -s)" = CYGWIN_NT-5.0 ]; then . ~/.setenv OS=windows URLADER=windows-x86 unset PANGO PERL=/c/perl/bin/perl MAKE=nmake SYSLIB=/c/gtk/bin LIBEXT=dll LIB0=dll SO=dll STRIP=":" # stripping the perl library kills it, and apparently, everythignis always stripped # fontconfig apparently ignores env vars and always looks at ./etc/fonts/fonts.conf, # but only if . isn't actually called bin or lib. hope for the best. GENPACK_ENVVARS="FONTCONFIG_PATH=pm/Deliantra/Client/private/resources/fonts FONTCONFIG_FILE=fonts.conf" pango-querymodules() { /c/gtk/bin/pango-querymodules # empty output usually } elif [ "$(uname -s)" = Darwin ]; then OS=darwin URLADER=darwin-x86 PANGO=1.6.0 PERL=/opt/local/bin/perl GENPACK_ENVVARS="DYLD_LIBRARY_PATH=." SYSLIB=/opt/local/lib LIB0=dylib SO=bundle STRIP="strip -x" elif [ $(arch) = i686 ]; then OS=linux URLADER=linux-x86 PANGO=1.5.0 PERL=/usr/bin/perl else OS=linux URLADER=linux-amd64 PANGO=1.5.0 PERL=/usr/bin/perl ARCHNAME=amd64 fi export DIST="$(pwd)/dist/$OS-$ARCHNAME" eval $($PERL -V:sitebinexp:) "$sitebinexp"/perl-libextractor --exedir . --dlldir . --bindir pm/bin --libdir pm \ --perl --core-support --script deliantra \ --runtime-only --strip \ --copy "$DIST" cat <"$DIST"/pango.rc [Pango] ModuleFiles = pango.modules EOF ( exec 5>"$DIST"/pango.modules pango-querymodules | grep ^/ | while read lib rest; do base=$(basename "$lib") [ "$base" = pango-basic-x.$LIBEXT ] && continue cp -p "$lib" "$DIST"/. echo "./$base $rest" >&5 # using ./ seems to help pango not to rummage around in /usr/lib etc. done ) ############################################################################# IFS=" " # space tab nl cr - cr for windows eval $($PERL -V:sitebinexp -V:sitearchexp -V:sitelib -V:vendorarchexp -V:vendorlibexp -V:archlibexp -V:privlibexp) mkdir -p "$DIST"/pm/bin cp "$sitebinexp"/deliantra "$DIST"/pm/bin/ cp -p util/run "$DIST" ############################################################################# if [ "$OS" = windows ]; then libdeps() { objdump -p "$1" | awk '/\tDLL Name:/ { print $3 }' | while read lib; do set -- $(type "$lib") case "$3" in /c/WINNT/* | /c/sdk/* ) ;; * ) echo "$3" ;; esac done } elif [ "$OS" = darwin ]; then libdeps() { otool -L "$1" | perl -ne 'print "$1\n" if m%^\s+(/opt\S+)%' } else libdeps() { ldd "$1" | perl -ne 'print "$1\n" if / => (\S+)/' } fi add_deps() { local so="$1" libdeps "$so" | while read path; do base="$(basename "$path")" if ! [ -e "$base" ]; then cp -p "$path" . chmod 755 "$base" add_deps "$base" fi done } ( cd "$DIST" if [ "$OS" = windows ]; then cp -p $SYSLIB/libvorbisfile-3.dll $SYSLIB/mikmod.dll $SYSLIB/libpng12-0.dll . cp /root/src/CFPlus/util/splash.bmp . chmod -R u+rwX pm/auto # convert perl to a non-console-app $PERL -MWin32::Exe -e '$e = new Win32::Exe"perl.exe"; $e->set_subsystem_windows; $e->write' else for lib in mikmod vorbisfile; do cp -p $SYSLIB/lib$lib.$LIB0 . chmod 755 lib$lib.$LIB0 done fi for so in $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl; do add_deps "$so" done rm -f pm/auto/POSIX/*.al for lib in \ dl c m rt pthread nsl crypt \ X11 Xext Xau Xdmcp ICE SM Xrandr Xrender Xxf86vm drm GL \ z do rm -f lib"$lib".$LIB0 done if [ "$OS" != windows ]; then # patch braindamaged pango if [ "$OS" != darwin ]; then set libpango-1.0.$LIB0 perl -pe 's{/u(?=sr/lib(32)?/pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1" else set lib*pango-1.0.0.dylib perl -pe 's{/o(?=pt/local/.../pango)}{.\x00}g;' <"$1" >"$1~" && mv "$1~" "$1" fi chmod 755 "$1" fi if [ "$OS" = darwin ]; then # "dll hell" is most severe on os x, because apple # does not generally give a shit for backwards compatibility, # alwayss ships outdated libraries and often provides libraries # of the same name as well-known libs (such as libjpeg), that # of course do something completely different patchlibs() { <"$1" \ perl -0777 -pe ' s%('"/opt/local/lib[^\x00]*/lib"'([^\x00/]+)\.dylib\x00)% my $s = $1; my $r = "libdeliantra-$2.dylib\x00"; (length $r) <= (length $s) or die "lib replacement <$r> larger than <$s>\n"; substr $s, 0, length $r, $r; $s %ge ' \ >"$1~" && mv "$1~" "$1" || exit 67 } # patch bundles and pango modules with external dependencies, # should be few, so hardcode(tm) for so in \ pm/auto/BDB/BDB.bundle \ pm/auto/Deliantra/Client/Client.bundle \ *.$LIBEXT do patchlibs "$so" done # now patch and rename all .dylibs for lib in *.$LIB0; do stem="${lib#lib}" stem="${stem%.$LIB0}" patchlibs "$lib" mv "$lib" "libdeliantra-$stem.dylib" done fi [ "$OS" = linux ] && chrpath -d perl $(find pm -name "*.so") # debian perls have an rpath, many modules too $STRIP $(find . -name "*.$SO" -o -name "*.$LIBEXT" -o -name "*.$LIB0") perl : >timidity.cfg ) cat >"$DIST".vars <