# Maintainer : Daniel Bermond <dbermond@archlinux.org>
# Maintainer : Santiago Torres-Arias <santiago@archlinux.org>
# Contributor: Matthew Ellison <matt+aur@arroyonetworks.com>

pkgname=pybind11
pkgver=3.0.1
pkgrel=1
pkgdesc='A lightweight header-only library that exposes C++ types in Python and vice versa'
arch=('any')
url='https://pybind11.readthedocs.org/'
license=('BSD-3-Clause')
depends=(
    'python')
makedepends=(
    'boost'
    'cmake'
    'eigen'
    'python-build'
    'python-installer'
    'python-pytest'
    'python-scikit-build-core'
    'python-wheel')
checkdepends=(
    'python-numpy')
source=("https://github.com/pybind/pybind11/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('741633da746b7c738bb71f1854f957b9da660bcd2dce68d71949037f0969d0ca')

build () {
    cd "${pkgname}-${pkgver}"
    python -m build --wheel --no-isolation
    
    # tests
    cmake \
        -G 'Unix Makefiles' \
        -B "${srcdir}/build-tests" \
        -S "${srcdir}/${pkgname}-${pkgver}" \
        -DCMAKE_BUILD_TYPE:STRING='None' \
        -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
        -DDOWNLOAD_CATCH:BOOL='ON' \
        -Wno-dev
    cmake --build "${srcdir}/build-tests"
}

check() {
    make -C build-tests check
}

package() {
    python -m installer --destdir="$pkgdir" "${pkgname}-${pkgver}/dist"/*.whl
    
    local _sitepkgs
    _sitepkgs="$(python -c 'import site; print(site.getsitepackages()[0])')"
    
    install -d -m755 "${pkgdir}/usr/share/licenses/${pkgname}"
    ln -sr "${pkgdir}${_sitepkgs}/pybind11-${pkgver}.dist-info/licenses/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
    
    install -d -m755 "${pkgdir}/usr"/{include,lib/{cmake,pkgconfig}}
    ln -sr "${pkgdir}${_sitepkgs}/pybind11/include/pybind11" "${pkgdir}/usr/include/pybind11"
    ln -sr "${pkgdir}${_sitepkgs}/pybind11/share/cmake/pybind11" "${pkgdir}/usr/lib/cmake/pybind11"
    ln -sr "${pkgdir}${_sitepkgs}/pybind11/share/pkgconfig/pybind11.pc" "${pkgdir}/usr/lib/pkgconfig/pybind11.pc"
}
