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

_realname=fgsl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=1
gsl_required=2.4
pkgdesc="Fortran interface to the GNU scientific library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/reinh-bader/fgsl"
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gcc-fortran")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran"
         "${MINGW_PACKAGE_PREFIX}-gsl>=${gsl_required}")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/reinh-bader/fgsl/archive/v${pkgver}.tar.gz
        gsl-2.6-no-undefined.patch)
sha256sums=('6d73d558c889d7ea23e510a436f28618624035e8ffa07692894f10968aa83a4b'
            'b6b248dc4aa514da84ecf81a1de4a33a7e2c73feee0d1fc3d57a82205e721bc4')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/gsl-2.6-no-undefined.patch

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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

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