# Template build file for 'python-tkinter'.
#
# THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/python"; IT IS SPLITTED TO AVOID
# A CYCLIC DEPENDENCY: python -> tk -> libX11 -> libxcb -> xcb-proto -> python
#
pkgname=python-tkinter
version=2.7.9
revision=2
wrksrc="Python-${version}"
hostmakedepends="pkg-config"
makedepends="
 libffi-devel readline-devel gdbm-devel libressl-devel expat-devel
 sqlite-devel bzip2-devel zlib-devel tk-devel"
pycompile_module="lib-tk"
short_desc="Interpreted, interactive, object-oriented programming language - GUI toolkit for Python2"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://www.python.org"
license="PSF"
distfiles="http://www.python.org/ftp/python/$version/Python-$version.tar.xz"
checksum=90d27e14ea7e03570026850e2e50ba71ad20b7eb31035aada1cf3def8f8d4916

pre_configure() {
	# Ensure that internal copies of expat, libffi and zlib are not used.
	rm -r Modules/expat
	rm -r Modules/_ctypes/libffi*
	rm -r Modules/zlib
}

do_configure() {
	unset GCC CC CXX CPP LD AR AS RANLIB
	if [ "$CROSS_BUILD" ]; then
		mkdir -p host-build
		cd host-build
		env -i PATH=$PATH ../configure
		env -i PATH=$PATH make ${makejobs} python
		mkdir -p ../hostpython
		mv python ../hostpython
		cd ..
		patch -Np0 -i ${FILESDIR}/Python-2.7.6-xcompile.patch
	fi
	./configure ${configure_args} \
		--with-threads --enable-ipv6 --with-signal-module \
		--with-system-ffi --enable-unicode=ucs4 --with-system-expat \
		--with-wctype-functions --enable-shared \
		ac_cv_file__dev_ptc=no ac_cv_file__dev_ptmx=yes \
		ac_cv_have_long_long_format=yes
}

do_build() {
	# Avoid invoking pgen for cross-compiles.
	touch Include/graminit.h Python/graminit.c
	export PATH="$PATH:$wrksrc/hostpython"
	make ${makejobs}
}

do_install() {
	export PATH="$PATH:$wrksrc/hostpython"
	make DESTDIR=${wrksrc}/${pkgname}-${version}-install altinstall

	# We only care for the idle and tk modules.
	vmkdir usr/bin
	vmkdir usr/lib/python2.7/lib-dynload
	if [ -e ${wrksrc}/${pkgname}-${version}-install/usr/lib32 ]; then
		_libdir=lib32
	else
		_libdir=lib
	fi
	mv ${wrksrc}/${pkgname}-${version}-install/usr/bin/idle ${DESTDIR}/usr/bin
	mv ${wrksrc}/${pkgname}-${version}-install/usr/lib/python2.7/idlelib \
		${DESTDIR}/usr/lib/python2.7/
	mv ${wrksrc}/${pkgname}-${version}-install/usr/lib/python2.7/lib-tk \
		${DESTDIR}/usr/lib/python2.7/
	mv ${wrksrc}/${pkgname}-${version}-install/usr/${_libdir}/python2.7/lib-dynload/_tkinter.so \
		${DESTDIR}/usr/lib/python2.7/lib-dynload/
}

idle-python_package() {
	noarch=yes
	depends="python-tkinter>=${version}_${revision}"
	pycompile_module="idlelib"
	short_desc+=" - IDE for Python2 using Tkinter"
	pkg_install() {
		vmove usr/bin/idle
		vmove usr/lib/python2.7/idlelib
		vinstall ${FILESDIR}/idle.xpm 644 usr/share/pixmaps
		vinstall ${FILESDIR}/idle.desktop 644 usr/share/applications
	}
}
