# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
setvar pkgname = 'py-numpy'
setvar _pkgname = 'numpy'
setvar pkgver = '1.13.3'
setvar pkgrel = '0'
setvar pkgdesc = ""Scientific tools for Python""
setvar url = ""http://numpy.scipy.org/""
setvar arch = ""all !s390x""
setvar license = ""BSD""
setvar options = ""!check""
setvar makedepends = ""python2-dev py-setuptools python3-dev
	cython-dev openblas-dev gfortran py-nose""
setvar subpackages = ""$pkgname-dev
	$pkgname-doc
	$pkgname-f2py::noarch
	py2-$_pkgname-f2py:_f2py:noarch
	py3-$_pkgname-f2py:_f2py:noarch
	py2-$_pkgname:_py
	py3-$_pkgname:_py""
setvar source = ""https://github.com/numpy/numpy/releases/download/v$pkgver/$_pkgname-$pkgver.tar.gz
	site.cfg""
setvar builddir = ""$srcdir/$_pkgname-$pkgver""

proc prepare {
	default_prepare
	cp "$srcdir"/site.cfg "$builddir"/
}

proc build {
	export Atlas=None
	setvar LDFLAGS = ""$LDFLAGS -shared""

	cd $builddir
	python2 setup.py build config_fc --fcompiler=gnu95
	python3 setup.py build config_fc --fcompiler=gnu95
}

proc package {
	cd $builddir

	local python; for python in python2 python3 {
		$python setup.py install --prefix=/usr --root="$pkgdir" \
			config_fc --fcompiler=gnu95
	}

	install -D -m 644 doc/f2py/f2py.1 \
		"$pkgdir"/usr/share/man/man1/f2py.1
	install -D -m 644 LICENSE.txt \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

proc dev {
	cd $pkgdir

	# Move tests to -dev subpackage.
	find usr/lib/python* -type d -name tests | while read path {
		mkdir -p "$subpkgdir/$path"
		mv "$path"/* "$subpkgdir/$path"/
	}

	default_dev
}

proc f2py {
	mkdir -p $subpkgdir
}

proc _f2py {
	local pyver="${subpkgname:2:1}"
	local python="python$pyver"

	setvar pkgdesc = ""f2py for numpy (for $python)""
	setvar depends = ""py$pyver-numpy=$pkgver-r$pkgrel $python-dev""
	setvar install_if = ""$pkgname-f2py=$pkgver-r$pkgrel $python""
	test $pyver = 3 || setvar replaces = "$pkgname"

	local dir="$(_pylibdir $python)/site-packages/numpy"

	mkdir -p "$subpkgdir/$dir" "$subpkgdir"/usr/bin
	mv "$pkgdir/$dir"/f2py "$subpkgdir/$dir"/
	mv "$pkgdir"/usr/bin/f2py$pyver "$subpkgdir"/usr/bin/
}

proc _py {
	local pyver="${subpkgname:2:1}"
	local python="python$pyver"

	setvar pkgdesc = ""$pkgdesc $pyver""
	setvar install_if = ""$pkgname=$pkgver-r$pkgrel $python""
	test $pyver = 3 || setvar replaces = "$pkgname"

	local libdir=$(_pylibdir $python)

	mkdir -p "$subpkgdir/$libdir"
	mv "$pkgdir/$libdir"/* "$subpkgdir/$libdir"/
	rmdir -p "$pkgdir/$libdir" 2>/dev/null || true
}

proc _pylibdir {
	$1 -c 'import sysconfig; print(sysconfig.get_path("stdlib"))'
}

setvar sha512sums = ""8af718a4f0204251f34995a5798a4803ae1ad96e6cae5681b1153f0be3ae102a79061a9b11cc404d3b205d7c95dbc8b0aa2d72aa9678185f8a6df877413d199f  numpy-1.13.3.tar.gz
21ca8db304cbbf5949f07702f2a42bb5e5a0d641921e36649555a41b0e48f04e96f53760417823177ac27f6de24b2191e6e1d5f0eb393beafa29f7484e23284f  site.cfg""