# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=eigen
pkgbase=mingw-w64-${_realname}3
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}3")
pkgver=5.0.0
pkgrel=1
pkgdesc="Lightweight C++ template library for vector and matrix math (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://eigen.tuxfamily.org/'
msys2_repository_url="https://gitlab.com/libeigen/eigen"
msys2_references=(
  'archlinux: eigen'
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-fc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=("https://gitlab.com/libeigen/eigen/-/archive/${pkgver}/eigen-${pkgver}.tar.bz2"
        'eigen-pkgconfig.patch')
sha256sums=('bc5888a4e8538af18d4734c4266a538c7490200f76bc978b66299600189d51c2'
            '52424a065bb6efd16c954294199fa0dcee5cad1d91a138f1305668a16bbb1604')

prepare() {
  cd "${srcdir}"/eigen-${pkgver}

  patch -Np1 -i "${srcdir}/eigen-pkgconfig.patch"
}

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DEIGEN_BUILD_PKGCONFIG=ON \
    -DEIGEN_BUILD_TESTING=OFF \
    -DEIGEN_BUILD_DEMOS=OFF \
    -S eigen-${pkgver} \
    -B build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM}
}

package() {
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install build-${MSYSTEM}

  install -Dm644 eigen-${pkgver}/COPYING.* -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
