# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer:  Francesco Colista <fcolista@alpinelinux.org>
pkgname=py-sip
_pkgname=sip
pkgver=4.19.7
pkgrel=0
pkgdesc="A tool that makes it easy to create Python bindings for C and C++ libraries"
url="http://www.riverbankcomputing.com/software/sip/"
arch="all"
license="custom:sip"
makedepends="python2-dev python3-dev"
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3 $pkgname-dev"
source="https://sourceforge.net/projects/pyqt/files/$_pkgname/$_pkgname-$pkgver/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir"/$_pkgname-$pkgver

prepare() {
    default_prepare
    cp -r "$builddir" "$srcdir"/python2
    cp -r "$builddir" "$srcdir"/python3
}

build() {
    _build python2
    _build python3
}

_build() {
    local python="$1"
    export PYTHON=$python
    cd "$srcdir"/$python
	local sip_api_major_nr=$(sed -nre 's:^#define SIP_API_MAJOR_NR\s+([0-9]+):\1:p' siplib/sip.h.in)
	$python configure.py
	make CC="${CC:-gcc}" \
		CXX="${CXX:-g++}" \
		CFLAGS="$CFLAGS -fPIC" \
		CXXFLAGS="$CXXFLAGS"
}

package() {
	mkdir -p "$pkgdir"
}

_py2() {
	replaces="$pkgname" 
    _py python2
}

_py3() {
    _py python3
}

_py() {
    local python="$1"
    pkgdesc="$pkgdesc (for $python)"
    install_if="$pkgname=$pkgver-r$pkgrel $python"
    cd "$srcdir/$python"
    make DESTDIR="$pkgdir" install
    mkdir -p "$subpkgdir"/usr/lib
    mv "$pkgdir"/usr/lib/${python}.* "$subpkgdir"/usr/lib/
	install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/custom/${pkgname}/LICENSE
}

sha512sums="0cead34e129d25ee3d908e503a3853289bbfd77c58c563a2046ce7b65bd8f0b318b20af72346cbf4cb7a17e76c9c1374f686b5dabc284d7247897a1648c15f97  sip-4.19.7.tar.gz"
