# Template file for 'python-PyQt4'
pkgname=python-PyQt4
version=4.11.2
revision=1
wrksrc="PyQt-x11-gpl-${version}"
maintainer="Dominik Honnef <dominik@honnef.co>"
hostmakedepends="
 python-devel python3.4-devel python-sip-devel python3.4-sip-devel qt-qmake qt-devel"
makedepends="${hostmakedepends}"
depends="python-sip"
replaces="python-PyQt4<4.11.1_2"
license="GPL-2, GPL-3"
homepage="http://www.riverbankcomputing.co.uk/software/pyqt/intro"
short_desc="Python2 bindings for the Qt4 toolkit"
distfiles="${SOURCEFORGE_SITE}/pyqt/PyQt-x11-gpl-${version}.tar.gz"
checksum=05dfc4060d25f81e5d45fb020ad59d21af7dc4c01ace4d2b37f3b49493d03f6e

_do_pyqt_build() {
	local v=$1 tools=${2:-yes} suffix=$3 tools_flag
	[[ "$tools" != "yes" ]] && tools_flag="--no-tools"

	python${v} configure-ng.py \
		--confirm-license --assume-shared $tools_flag \
		CC="${CC}" CFLAGS="${CFLAGS}" CXX="${CXX}" CXXFLAGS="${CXXFLAGS}" \
		LINK="${CXX}" LINK_SHLIB="${CXX}" LFLAGS="${LDFLAGS}" STRIP="" \
		INCDIR="${XBPS_CROSS_BASE}/usr/include/python${v}${suffix}"
	make ${makejobs}
}

post_extract() {
	cp -a ${wrksrc} /tmp/python3.4-PyQt4-build
	mv /tmp/python3.4-PyQt4-build ${wrksrc}
}

pre_build() {
	rm -rf pyuic/uic/port_v3
	cd ${wrksrc}/python3.4-PyQt4-build
	rm -rf pyuic/uic/port_v2
}

do_build() {
	# build python-pyqt4
	_do_pyqt_build 2.7

	# build python3.4-pyqt4
	cd ${wrksrc}/python3.4-PyQt4-build
	_do_pyqt_build 3.4 no "m"
}

do_install() {
	# install python-pyqt4
	make DESTDIR=${DESTDIR} INSTALL_ROOT=${DESTDIR} install

	# install python3.4-pyqt4
	cd ${wrksrc}/python3.4-PyQt4-build
	make DESTDIR=${DESTDIR} INSTALL_ROOT=${DESTDIR} install

	# install doc
	vmkdir usr/share/doc/${pkgname}
	vcopy "doc/html examples" usr/share/doc/${pkgname}
}

post_install() {
	# install pyuic4 wrapper
	vbin ${FILESDIR}/pyuic4
}

python-PyQt4-devel-tools_package() {
	replaces="python-PyQt4<4.11.1_2"
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development tools"
	pkg_install() {
		vmove usr/bin/pylupdate4
		vmove usr/bin/pyrcc4
		vmove usr/bin/pyuic4
	}
}

python-PyQt4-devel_package() {
	replaces="python-PyQt4<4.11.1_2"
	depends="python-sip-devel ${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/share/sip
	}
}

python-PyQt4-doc_package() {
	noarch=yes
	replaces="python-PyQt4<4.11.1_2"
	short_desc+=" - documentation files"
	pkg_install() {
		vmove usr/share/doc
	}
}

python3.4-PyQt4_package() {
	replaces="python3.4-PyQt4<4.11.1_2"
	depends="python3.4-sip"
	short_desc="${short_desc/Python2/Python3.4}"
	pkg_install() {
		vmove usr/lib/python3.4
	}
}
