# Maintainer: 
pkgname=tk
pkgver=8.6.8
pkgrel=0
pkgdesc="GUI toolkit for the Tcl scripting language"
url="http://tcl.sourceforge.net/"
arch="all"
options="!check"  # Requires a running X11 server.
license="TCL"
depends=
depends_dev="tcl-dev libx11-dev libxft-dev fontconfig-dev"
makedepends="$depends_dev libpng-dev"
subpackages="$pkgname-doc $pkgname-dev"
source="http://downloads.sourceforge.net/sourceforge/tcl/$pkgname$pkgver-src.tar.gz
	"

_major=${pkgver%.*}
builddir="$srcdir"/tk${pkgver}/unix

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man
	make
}

package() {
	cd "$builddir"
	export LD_LIBRARY_PATH="$builddir"
	make -j1 INSTALL_ROOT="${pkgdir}" install install-private-headers

	ln -sf wish${_major} "${pkgdir}"/usr/bin/wish
	install -Dm644 ../license.terms \
		${pkgdir}/usr/share/licenses/${pkgname}/LICENSE

	# remove buildroot traces
	find "$pkgdir" -name '*Config.sh' | xargs sed -i -e "s#${srcdir}#/usr/src#"

	# move demos to -doc directory
	mkdir -p "$pkgdir"/usr/share/doc/$pkgname/examples/
	mv "$pkgdir"/usr/lib/tk${_major}/demos/ \
		"$pkgdir"/usr/share/doc/$pkgname/examples/
}

dev() {
	default_dev
	cd $pkgdir
	for i in $(find . -name '*.c' -o -name '*Config.sh'); do
		mkdir -p "$subpkgdir"/${i%/*}
		mv $i "$subpkgdir"/${i%/*}/
	done
}

sha512sums="d0d30637b733fb0b0d38461b6d872934c04af422fcdb7ec41a72331b2529cc94414e6f441f95a98642d69505e4f41469847fedd1cbe58bd08cdd818fcabd1db9  tk8.6.8-src.tar.gz"