# Template file for 'sip'
pkgname=sip
version=4.19.2
revision=2
wrksrc="sip-${version}"
hostmakedepends="python-devel python3-devel"
makedepends="${hostmakedepends}"
short_desc="Python extension module generator for C/C++ libraries"
maintainer="Alessio Sergi <al3hex@gmail.com>"
homepage="http://www.riverbankcomputing.co.uk/software/sip/intro"
license="GPL-2, GPL-3, SIP"
distfiles="${SOURCEFORGE_SITE}/pyqt/sip-${version}.tar.gz"
checksum=432b4aad25254e6997913e33b1ca3cf5fd21d5729a50a3ce2edccbea82c80533

pre_build() {
	mkdir -p sip-${py2_ver}
	mv * sip-${py2_ver} || true
	cp -a sip-${py2_ver} sip-${py3_ver}
}
do_build() {
	for pyver in $py2_ver $py3_ver; do
		if [ "$pyver" != "$py2_ver" ]; then
			pyinc="$py3_inc"
		else
			pyinc="$py2_inc"
		fi

		cd ${wrksrc}/sip-${pyver}
		python${pyver} configure.py \
			CC="${CC}" CFLAGS="${CFLAGS}" CXX="${CXX}" CXXFLAGS="${CXXFLAGS}" \
			LINK="${CXX}" LINK_SHLIB="${CXX}" LFLAGS="${LDFLAGS}" STRIP="" \
			INCDIR="${XBPS_CROSS_BASE}/${pyinc}"
		make ${makejobs}
	done
}
do_install() {
	cd ${wrksrc}/sip-${py2_ver}
	# install sip
	make DESTDIR=${DESTDIR} install -C sipgen
	# install python-sip
	make DESTDIR=${DESTDIR} install -C siplib
	vinstall sipconfig.py 644 $py2_sitelib
	vinstall sipdistutils.py 644 $py2_sitelib

	# install python3-sip
	cd ${wrksrc}/sip-${py3_ver}
	make DESTDIR=${DESTDIR} install -C siplib
	vinstall sipconfig.py 644 $py3_sitelib
	vinstall sipdistutils.py 644 $py3_sitelib
}
post_install() {
	# Remove references to hardening -specs.
	sed -i ${DESTDIR}/usr/lib/python*/site-packages/sipconfig.py \
		-e "s|-specs=/void-packages/common/environment/configure/gccspecs/hardened-cc1||g" \
		-e "s|-specs=/void-packages/common/environment/configure/gccspecs/hardened-ld||g"
}

python-sip_package() {
	lib32disabled=yes
	depends="${sourcepkg}-${version}_${revision} python"
	pycompile_module="sipconfig.py"
	short_desc="Python2 SIP bindings"
	pkg_install() {
		vmove ${py2_sitelib}/sip.so
		vmove ${py2_sitelib}/sipconfig.py
		vmove ${py2_sitelib}/sip.pyi
	}
}
python-sip-devel_package() {
	depends="python-sip-${version}_${revision}"
	pycompile_module="sipdistutils.py"
	short_desc="Python2 SIP bindings - development files"
	pkg_install() {
		vmove ${py2_inc}
		vmove ${py2_sitelib}/sipdistutils.py
	}
}
python3-sip_package() {
	lib32disabled=yes
	replaces="python3.4-sip>=0"
	depends="${sourcepkg}-${version}_${revision} python3"
	pycompile_module="sipconfig.py"
	short_desc="Python3 SIP bindings"
	pkg_install() {
		vmove ${py3_sitelib}/sip.so
		vmove ${py3_sitelib}/sipconfig.py
		vmove ${py3_sitelib}/sip.pyi
	}
}
python3-sip-devel_package() {
	replaces="python3.4-sip-devel>=0"
	depends="python3-sip-${version}_${revision}"
	pycompile_module="sipdistutils.py"
	short_desc="Python3 SIP bindings - development files"
	pkg_install() {
		vmove ${py3_inc}
		vmove ${py3_sitelib}/sipdistutils.py
	}
}
python3.4-sip_package() {
	build_style=meta
	short_desc="Python3.4 SIP bindings (transitional dummy package)"
	depends="python3-sip>=${version}_${revision}"
}
python3.4-sip-devel_package() {
	build_style=meta
	short_desc="Python3.4 SIP bindings - development files (transitional dummy package)"
	depends="python3-sip-devel>=${version}_${revision}"
}
