# Template file for 'shiboken'
pkgname=shiboken
version=1.2.2
revision=2
wrksrc="shiboken-${version}"
python_versions="2.7 3.4"
hostmakedepends="cmake"
makedepends="python-devel python3.4-devel qt-devel libxml2-devel libxslt-devel"
replaces="python-shiboken<1.2.2_1 python3.4-shiboken<1.2.2_1
 python-shiboken-devel<1.2.2_1 python3.4-shiboken-devel<1.2.2_1"
short_desc="CPython bindings generator for C++ libraries"
maintainer="Enno Boland <eb@s01.de>"
homepage="http://www.pyside.org"
license="LGPL-2.1"
distfiles="https://download.qt.io/official_releases/pyside/shiboken-${version}.tar.bz2"
checksum=7625bbcf1fe313fd910c6b8c9cf49ac5495499f9d00867115a2f1f2a69fce5c4

pre_build() {
	# Fix inconsistent naming of libshiboken.so and ShibokenConfig.cmake
	sed -i "/get_config_var('SOABI')/d" cmake/Modules/FindPython3InterpWithDebug.cmake
}
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"
		else
			args="-DUSE_PYTHON3=yes -DPYTHON3_EXECUTABLE=/usr/bin/python3.4"
		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}/data/shiboken.pc 644 \
			usr/lib/pkgconfig shiboken-python${pyver}.pc
	done
}

libshiboken-common-devel_package() {
	replaces="python-shiboken-devel<1.2.2_1 python3.4-shiboken-devel<1.2.2_1"
	depends="${sourcepkg}-${version}_${revision}"
	short_desc+=" - common development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake/Shiboken-${version}/ShibokenConfig.cmake
		vmove usr/lib/cmake/Shiboken-${version}/ShibokenConfigVersion.cmake
	}
}
libshiboken-python-devel_package() {
	replaces="python-shiboken-devel<1.2.2_1"
	depends="libshiboken-common-devel-${version}_${revision}
	 libshiboken-python-${version}_${revision}"
	short_desc="Python2 shiboken bindings - shared library (development files)"
	pkg_install() {
		vmove usr/lib/cmake/Shiboken-${version}/ShibokenConfig-python2.7.cmake
		vmove usr/lib/pkgconfig/shiboken-python2.7.pc
		vmove usr/lib/libshiboken-python2.7.so
	}
}
libshiboken-python_package() {
	replaces="python-shiboken<1.2.2_1"
	short_desc="Python2 shiboken bindings - shared library"
	pkg_install() {
		vmove usr/lib/libshiboken-python2.7.so.${version%.*}
		vmove usr/lib/libshiboken-python2.7.so.${version}
	}
}
python-shiboken_package() {
	replaces="python-shiboken<1.2.2_1"
	short_desc="Python2 shiboken bindings"
	pkg_install() {
		vmove usr/lib/python2.7/site-packages/shiboken.so
	}
}
libshiboken-python3.4-devel_package() {
	replaces="python3.4-shiboken-devel<1.2.2_1"
	depends="libshiboken-common-devel-${version}_${revision}
	 libshiboken-python3.4-${version}_${revision}"
	short_desc="Python3.4 shiboken bindings - shared library (development files)"
	pkg_install() {
		vmove usr/lib/cmake/Shiboken-${version}/ShibokenConfig-python3.4.cmake
		vmove usr/lib/pkgconfig/shiboken-python3.4.pc
		vmove usr/lib/libshiboken-python3.4.so
	}
}
libshiboken-python3.4_package() {
	replaces="python3.4-shiboken<1.2.2_1"
	short_desc="Python3.4 shiboken bindings - shared library"
	pkg_install() {
		vmove usr/lib/libshiboken-python3.4.so.${version%.*}
		vmove usr/lib/libshiboken-python3.4.so.${version}
	}
}
python3.4-shiboken_package() {
	replaces="python3.4-shiboken<1.2.2_1"
	short_desc="Python3.4 shiboken bindings"
	pkg_install() {
		vmove usr/lib/python3.4/site-packages/shiboken.so
	}
}
