### this file is sourced not run
PKGVER=2.24.32
PKGBUILD=1
PKGARCH=x86_64

# source: post BLFS 7.9 2016-04-29 updated to 2.24.32
TARBALL=gtk+-$PKGVER.tar.xz
MD5SUM=d5742aa42275203a499b59b4c382a784
SRC_URL=http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/$TARBALL
BUNDLE=

# gtk2 2.24.32 has rubbish docs; many details are deleted.
# perhaps to encourage people to move on to gtk3.
# grab the docs from the latest version that still has it good.
OLD_TARBALL=gtk+-2.24.31.tar.xz
OLD_MD5SUM=526a1008586094a2cbb4592fd3f9ee10
OLD_SRC_URL=http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/$OLD_TARBALL

SLACKREQ='atk2 gdk-pixbuf pango cups'
SLACKDESC="gtk2: gtk2 $PKGVER (GTK GUI Toolkit)
gtk2:  
gtk2: The GTK+ 2 package contains libraries used for creating graphical user 
gtk2: interfaces for applications. This is version 2 of GTK+.  
gtk2: 
gtk2: 
gtk2: 
gtk2: 
gtk2: 
gtk2: 
gtk2:
"

DEBUG= # yes to enable debug

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	SRC_URL=$OLD_SRC_URL MD5SUM=$OLD_MD5SUM TARBALL=$OLD_TARBALL &&
	pkg_prepare_default &&
	mv tmp/gtk+-2.24.31 tmp/gtk+-$PKGVER/old-gtk &&

	cd tmp/gtk* &&

	# apply upstream patches
	for p in ../pkg/upstream/*; do
		patch -Np1 -i $p || return 1
	done &&
	
	# restore original gtk2 icon names
	# SFR: http://murga-linux.com/puppy/viewtopic.php?p=847362#847362
	patch -Np1 -i ../pkg/gtk_stock_icons_fix.diff &&
	
	# OpenEmbedded - new gcc FTBFS patch
	patch -Np1 -i ../pkg/strict-prototypes.patch &&

	# OpenEmbedded - feature patches
	patch -Np0 -i ../pkg/toggle-font.diff &&
	patch -Np1 -i ../pkg/xsettings.patch &&

	# step: comments in the patch file
	patch -Np1 -i ../pkg/fix_print_to_file_printer_ignored.patch &&
	
	# BLFS patches
	sed -i 's#l \(gtk-.*\).sgml#& -o \1#' docs/faq/Makefile.in docs/tutorial/Makefile.in
	#sed -i 's#.*@man_#man_#' docs/reference/gtk/Makefile.in && # only needed for 2.24.25 or below
	#sed -i -e 's#pltcheck.sh#$(NULL)#g' gtk/Makefile.in
}

### default pkg_package
### build
pkg_build() {
	export CFLAGS="$CFLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CAST_CHECKS"
	CONFFLAGS="$CONFFLAGS --with-xinput --with-x"

	# we want -g permanently, -O0 when debugging
	CFLAGS="$CFLAGS -g"
	[ $DEBUG ] && CFLAGS="$CFLAGS -O0"
	
	pkg_build_autoconf && pkg_build_slackdesc &&

	# override gtk-doc with old-gtk version, which is way more complete
	rm -rf /usr/share/gtk-doc/html &&
	mkdir /usr/share/gtk-doc/html &&
	mv old-gtk/docs/reference/gdk/html /usr/share/gtk-doc/html/gdk2 &&
	mv old-gtk/docs/reference/gtk/html /usr/share/gtk-doc/html/gtk2 &&
	mv old-gtk/docs/reference/libgail-util/html /usr/share/gtk-doc/html/gail-libgail-util &&
	
	# extra docs
	install -v -m755 -d /usr/share/doc/gtk+-$PKGVER/{faq,tutorial,examples} &&
	cp -v -R docs/faq/html/* /usr/share/doc/gtk+-$PKGVER/faq &&
	cp -v -R docs/tutorial/html/* /usr/share/doc/gtk+-$PKGVER/tutorial &&
	cp -v -R examples/* /usr/share/doc/gtk+-$PKGVER/examples &&
	
	# multilib
	mv -v /usr/bin/gtk-query-immodules-2.0{,-64} &&
	ln -sfv multiarch_wrapper /usr/bin/gtk-query-immodules-2.0 &&
	mv -v /usr/share/gir-1.0/* /usr/share/gir-1.0-64 &&
	rm -r /usr/share/gir-1.0/ &&

	# keep debug symbols in devx
	cd /usr/$LIBDIR &&
	for LIB in \
		libgdk-x11-2.0.so.0.2400.32 \
		libgailutil.so.18.0.1       \
		libgtk-x11-2.0.so.0.2400.32;
	do
		objcopy --only-keep-debug $LIB $LIB.dbg &&
		strip --strip-unneeded $LIB &&
		objcopy --add-gnu-debuglink=$LIB.dbg $LIB || return 1
	done
}
 
