# Template file for 'python-pyside'
pkgname=python-pyside
version=1.2.2
revision=2
wrksrc="pyside-qt4.8+${version}"
python_versions="2.7 3.4"
hostmakedepends="cmake"
makedepends="python-devel python3.4-devel libshiboken-python-devel
 libshiboken-python3.4-devel qt-devel MesaLib-devel phonon-devel"
depends="python-shiboken"
pycompile_module="PySide"
short_desc="LGPL-licensed Python2 bindings for the Qt4 toolkit"
_short_desc="${short_desc/Python2/Python3.4}"
maintainer="Enno Boland <eb@s01.de>"
homepage="http://www.pyside.org/"
license="LGPL-2.1"
distfiles="https://download.qt.io/official_releases/pyside/pyside-qt4.8+${version}.tar.bz2"
checksum=a1a9df746378efe52211f1a229f77571d1306fb72830bbf73f0d512ed9856ae1

pre_build() {
	# Fix generated pkgconfig file to require the shiboken
	# library suffixed with the correct python version.
	sed -i '/^Requires:/s/shiboken$/&@SHIBOKEN_PYTHON_SUFFIX@/' libpyside/pyside.pc.in
}
do_build() {
	local args= configure_args="
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_TESTS=OFF"

	for pyver in $python_versions; do
		args=
		if [ "$pyver" = "2.7" ]; then
			args="-DPYTHON_SUFFIX=-python2.7"
		fi

		[ ! -d build-${pyver} ] && mkdir build-${pyver}
		pushd build-${pyver}
		cmake .. ${configure_args} ${args}
		make ${makejobs}
		popd
	done
}
do_install() {
	for pyver in $python_versions; do
		cd ${wrksrc}/build-${pyver}
		make DESTDIR=${DESTDIR} install
	done
}
post_install() {
	# Fix conflict between .pc files
	rm -f ${DESTDIR}/usr/lib/pkgconfig/*
	for pyver in $python_versions; do
		vinstall build-${pyver}/libpyside/pyside.pc 644 \
			usr/lib/pkgconfig pyside-python${pyver}.pc
	done
}

libpyside-common-devel_package() {
	replaces="python-pyside-devel<1.2.2_1 python3.4-pyside-devel<1.2.2_1"
	short_desc+=" - common development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake/PySide-${version}/PySideConfig.cmake
		vmove usr/lib/cmake/PySide-${version}/PySideConfigVersion.cmake
		vmove usr/share
	}
}
libpyside-python-devel_package() {
	replaces="python-pyside-devel<1.2.2_1"
	depends="libpyside-common-devel-${version}_${revision}
	 libpyside-python-${version}_${revision}"
	short_desc+=" - shared library (development files)"
	pkg_install() {
		vmove usr/lib/cmake/PySide-${version}/PySideConfig-python2.7.cmake
		vmove usr/lib/pkgconfig/pyside-python2.7.pc
		vmove usr/lib/libpyside-python2.7.so
	}
}
libpyside-python_package() {
	replaces="python-pyside<1.2.2_1"
	short_desc+=" - shared library"
	pkg_install() {
		vmove usr/lib/libpyside-python2.7.so.${version%.*}
		vmove usr/lib/libpyside-python2.7.so.${version}
	}
}
python-pyside-phonon_package() {
	depends="${sourcepkg}-${version}_${revision}"
	short_desc+=" - phonon bindings"
	pkg_install() {
		vmove usr/lib/python2.7/site-packages/PySide/phonon.so
	}
}
libpyside-python3.4-devel_package() {
	replaces="python3.4-pyside-devel<1.2.2_1"
	depends="libpyside-common-devel-${version}_${revision}
	 libpyside-python3.4-${version}_${revision}"
	short_desc="${_short_desc} - shared library (development files)"
	pkg_install() {
		vmove usr/lib/cmake/PySide-${version}/PySideConfig-python3.4.cmake
		vmove usr/lib/pkgconfig/pyside-python3.4.pc
		vmove usr/lib/libpyside-python3.4.so
	}
}
libpyside-python3.4_package() {
	replaces="python3.4-pyside<1.2.2_1"
	short_desc="${_short_desc} - shared library"
	pkg_install() {
		vmove usr/lib/libpyside-python3.4.so.${version%.*}
		vmove usr/lib/libpyside-python3.4.so.${version}
	}
}
python3.4-pyside-phonon_package() {
	depends="python3.4-pyside-${version}_${revision}"
	short_desc="${_short_desc} - phonon bindings"
	pkg_install() {
		vmove usr/lib/python3.4/site-packages/PySide/phonon.so
	}
}
python3.4-pyside_package() {
	depends="python3.4-shiboken"
	pycompile_version="3.4"
	pycompile_module="PySide"
	short_desc="${_short_desc}"
	pkg_install() {
		vmove usr/lib/python3.4
	}
}
