# Contributor: Oleg A. Khlybov <fougas@mail.ru>

_realname=fgsl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=2
gsl_required=2.7
pkgdesc="Fortran interface to the GNU scientific library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/reinh-bader/fgsl"
msys2_references=(
  'aur: fgsl-git'
)
license=('spdx:GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-fc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=($([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
         "${MINGW_PACKAGE_PREFIX}-gsl>=${gsl_required}")
source=(https://github.com/reinh-bader/fgsl/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('8b6a02912b917e4544fed655b8e925c9b7160a063df57afcb35f064f351f1434')

prepare() {
  cd ${_realname}-${pkgver}

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    export FC=flang
  fi

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX}

  make
}

check() {
  cd build-${MSYSTEM}
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
