#!/bin/bash
#
# Copyright 2012 Eugene Wissner <belka.ew@gmail.com>
# Available under the terms of the GNU GPL.
#

NAME="gtk+3"
VERSION="3.6.0"
REVISION="1"

PKG_SOURCEURL='ftp://ftp.gnome.org/mirror/gnome.org/sources/gtk+/$VER_MAJ.$VER_MIN/gtk+-$VERSION.tar.xz'
# Copy only the latest ChangeLog
PKG_DOCFILES=`echo "$PKG_DOCFILES" | sed -e 's/ChangeLog\*/ChangeLog/'`

PKG_PATCH[0]='update-gtk-immodules-3.0'
PKG_PATCH[1]='gtk.xid.nowarningflood.patch'
PKG_PATCH[2]='use_host_triplet_for_gtk_immodules.diff'

. $DLG_ROOT/etc/config
. $DLG_ROOT/lib/dl-base

cflags
prepare
analyzesource

# Do not flood the console or .xsession-errors with "trouble ahead"
# warnings (most noticable when using Firefox and Flash):
applypatch 1 1
# Use /etc/gtk-3.0/$ARCH-slackware-linux instead of /etc/gtk-3.0/ for gtk.immodules
applypatch 2 1

# Regenerate ./configure:
spewdo "cd $PKG_SRCROOT"
libtoolize --copy --force
autoreconf -vif
# Autoconf changes linux to linux-gnu.
# Our host is $ARCH-slackware-linux not $ARCH-slackware-linux-gnu:
spewdo "cd $PKG_SRCROOT/build-aux; sed -i -e 's#linux|linux-gnu|#linux|linux|#' config.sub"

if [ "$DLG_ARCH" == "x86-64" ]; then
	host="x86_64-slackware-linux"
else
	host="i486-slackware-linux"
fi
PKG_CFLAGS="${PKG_CFLAGS} -DHOST='"'"${host}"'"'"

configure --enable-xkb
make imconffiledir=/etc/gtk-3.0/$host

# Thanks to LFS for the tip how to pass the tests
spewdo "rm $PKG_SRCROOT/tests/a11y/pickers.ui"
#makecheck
makeinstall install-strip imconffiledir=/etc/gtk-3.0/$host

spewdo "mv $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/$host/im-multipress.conf $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/im-multipress.conf"
configfile $PKG_SYSCONFDIR/gtk-3.0/im-multipress.conf
spewdo "rm -f $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/$host/*"
if [ -r $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/gtk.immodules ]; then
	spewdo "mv $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/gtk.immodules $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/$host"
fi
# Install a "starter" gtkrc
spewdo "echo 'gtk-theme-name=\"GTK+\"' > $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-3.0/gtkrc"
configfile $PKG_SYSCONFDIR/gtk-3.0/gtkrc

# We need to have separate 32-bit and 64-bit binaries
# for places where we have two copies of the GTK+ package installed.
# (we might have x86_64 and i486 packages on the same system, for example.)
case "$host" in
  s390x*|x86_64*)
   mv $PKG_STAGEROOT$PKG_PREFIX/bin/gtk-query-immodules-3.0{,-64}
   ( cd $PKG_STAGEROOT$PKG_PREFIX/bin
     ln -sf gtk-query-immodules-3.0-64 gtk-query-immodules-3.0
   )
   ;;
  *)
   mv $PKG_STAGEROOT$PKG_PREFIX/bin/gtk-query-immodules-3.0{,-32}
   ( cd $PKG_STAGEROOT$PKG_PREFIX/bin
     ln -sf gtk-query-immodules-3.0-32 gtk-query-immodules-3.0
   )
   ;;
esac

# Install wrappers for the binaries:
findpatch filename ${PKG_PATCH[0]}
spewdo "install -m 0755 -o root -g root $filename $PKG_STAGEROOT$PKG_PREFIX/bin/"

tidydocumentation
analyzebinaries
finalizepackage
packagize
cleanup
