# Maintainer: Giuseppe Borzi <gborzi___AT___ieee___DOT___org>
# Contributor: Alberto Penaforte <apenafor@gmail.com>
# Contributor: Rafał Brzegowy <rafal.brzegowy@yahoo.com>

_realname=spooles
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.2
pkgrel=4
pkgdesc="SParse Object Oriented Linear Equations Solver (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
makedepends=("${MINGW_PACKAGE_PREFIX}-perl")
url="https://www.netlib.org/linalg/spooles"
license=('custom')
source=("http://www.netlib.org/linalg/${_realname}/${_realname}.${pkgver}.tgz"
        spooles.patch
        LICENSE)
sha256sums=('a84559a0e987a1e423055ef4fdf3035d55b65bbe4bf915efaa1a35bef7f8c5dd'
            '58a92b0336f8e2f9b32be9b68f86e02196eb7c075a627fcf828f4f2a2ba1990d'
            'BCC3FC307C8B7FD8259CCA785F1AB6A5203D45EA51C5859D41DEFEA5C0E8820A')
noextract=("${_realname}.${pkgver}.tgz")

prepare() {
  rm -rf "${srcdir}/${_realname}-${pkgver}"
  mkdir "${srcdir}/${_realname}-${pkgver}"
  cd "${srcdir}/${_realname}-${pkgver}"
  tar -xzf "${srcdir}/${_realname}.${pkgver}.tgz"
  patch -Np1 -i "${srcdir}"/spooles.patch
}

build() {
  make lib -C "${srcdir}/${_realname}-${pkgver}"
}

package() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{lib,include/${_realname}}
  cd "${srcdir}/${_realname}-${pkgver}"
  install -Dm644 lib*.a "${pkgdir}${MINGW_PREFIX}/lib"
  install -Dm644 ./MT/src/lib*.a "${pkgdir}${MINGW_PREFIX}/lib"
  for h in *.h; do
    if [ $h != 'MPI.h' ]; then
       cp $h ${pkgdir}${MINGW_PREFIX}/include/spooles
       d=`basename $h .h`
       if [ -d $d ]; then
          mkdir ${pkgdir}${MINGW_PREFIX}/include/spooles/$d
          cp $d/*.h ${pkgdir}${MINGW_PREFIX}/include/spooles/$d
       fi
    fi
  done
  
  # Fix permissions
  cd ${pkgdir}${MINGW_PREFIX}/include/spooles
  chmod -R oug+r *
  install -Dm644 "${srcdir}"/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
