#!/bin/sh
#
# Copyright 2004,2007, 2008 Dagmar d'Surreal <rivyqntzne@tznvy.pbz>
# Copyright 2005, 2006, 2007, 2008 Scott Harmon
# Copyright 2009 Sasa Ostrouska <saxa@droplinegnome.org>
# Available under the terms of the GNU GPL.
#

NAME="gtk+2"
VERSION="2.18.3"
REVISION="1"

PKG_SOURCEURL='http://download.gnome.org/sources/gtk+/$VER_MAJ.$VER_MIN/gtk+-$VERSION.tar.bz2'

PKG_PATCH[0]="gtk.pnglz.diff"
PKG_PATCH[1]="update-gdk-pixbuf-loaders"
PKG_PATCH[2]="update-gtk-immodules"
PKG_PATCH[3]="gtk+2.csh"
PKG_PATCH[4]="gtk+2.sh"

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

cflags
cxxflags
prepare
applypatch 0 1
 
## Fix for x86_64 (does not hurt the other archs but note that we will start
## using /etc/gtk-2.0/$host instead of /etc/gtk-2.0/ now):
spewdo "cd $PKG_SRCROOT"
spew 3 "Implementing fixes for x86_64"
 sed -i "s/GTK_SYSCONFDIR, \\\"gtk-2\\.0\\\"/GTK_SYSCONFDIR, \\\"gtk-2\\.0\\\", HOST/g" ./gtk/gtkrc.c ./gdk-pixbuf/gdk-pixbuf-io.c
 sed -i 's/sysconfdir)\\"/&      \\\n\t-DHOST=\\\"$(host_triplet)\\\"/g' \
 gdk-pixbuf/Makefile.am \
 gtk/Makefile.am \
 modules/input/Makefile.am

# The original config.{guess,sub} do not work on x86_64
spewdo "cp -p /usr/share/libtool/config.{guess,sub} ."

analyzesource

spewdo "libtoolize --force"
spewdo "autoreconf -vif"

# Autoconf changes linux to linux-gnu.
# Our host is $ARCH-slackware-linux not $ARCH-slackware-linux-gnu:
spewdo "sed -i -e 's#linux|linux-gnu|#linux|linux|#' config.sub"

if [ "$DLG_ARCH" == "x86-64" ]; then
	configure --with-xinput --with-xinput=yes --build=x86_64-slackware-linux
	PKG_ARCH=x86_64
else
	configure --with-xinput --with-xinput=yes --build=i486-slackware-linux
	PKG_ARCH=i486
fi

make

# Check the host value that is passed to the compile to the one in this script:
PKG_HOST="$PKG_ARCH-slackware-linux"
COMPILE_HOST=$(grep 'host_triplet =' gtk/Makefile | sed -e "s/.* = //")
if [ "x$COMPILE_HOST" != "x$PKG_HOST" ]; then
  spew 2 "Host mismatch: compile='$COMPILE_HOST', SlackBuild='$PKG_HOST'"
  exit 1
fi

makeinstall install-strip RUN_QUERY_IMMODULES_TEST=false RUN_QUERY_LOADER_TEST=false

spewdo "createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-2.0/$PKG_HOST"
spewdo "mv $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-2.0/im-multipress.conf $PKG_STAGEROOT$PKG_SYSCONFDIR/gtk-2.0/$PKG_HOST/im-multipress.conf.new"

# 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 "$PKG_HOST" in
  s390x*|x86_64*)
   spewdo "mv $PKG_STAGEROOT/usr/bin/gtk-query-immodules-2.0{,-64}"
   spewdo "mv $PKG_STAGEROOT/usr/bin/gdk-pixbuf-query-loaders{,-64}"
   ( spewdo "cd $PKG_STAGEROOT/usr/bin"
     spewdo "ln -sf gtk-query-immodules-2.0-64 gtk-query-immodules-2.0"
     spewdo "ln -sf gdk-pixbuf-query-loaders-64 gdk-pixbuf-query-loaders"
   )
   ;;
  *)
   spewdo "mv $PKG_STAGEROOT/usr/bin/gtk-query-immodules-2.0{,-32}"
   spewdo "mv $PKG_STAGEROOT/usr/bin/gdk-pixbuf-query-loaders{,-32}"
   ( spewdo "cd $PKG_STAGEROOT/usr/bin"
     spewdo "ln -sf gtk-query-immodules-2.0-32 gtk-query-immodules-2.0"
     spewdo "ln -sf gdk-pixbuf-query-loaders-32 gdk-pixbuf-query-loaders"
   )
   ;;
esac

# Install wrappers for the binaries:
findpatch filename ${PKG_PATCH[1]}
spewdo "install -m 755 $filename $PKG_STAGEROOT/usr/bin/"
findpatch filename ${PKG_PATCH[2]}
spewdo "install -m 755 $filename $PKG_STAGEROOT/usr/bin/"

# Install profile.d files
spewdo "createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d"
findpatch filename ${PKG_PATCH[3]}
spewdo "install -m 755 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d"
findpatch filename ${PKG_PATCH[4]}
spewdo "install -m 755 $filename $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d"

tidydocumentation
analyzebinaries
finalizepackage
packagize
cleanup

