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

_realname=gsl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.8
pkgrel=1
pkgdesc="The GNU Scientific Library (GSL) is a modern numerical library for C and C++ programmers (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnu.org/software/gsl/gsl.html"
msys2_repository_url="https://git.savannah.gnu.org/cgit/gsl.git"
msys2_references=(
  'archlinux: gsl'
)
license=("spdx-GPL-3.0-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://ftp.gnu.org/gnu/gsl/${_realname}-${pkgver}.tar.gz")
sha256sums=('6a99eeed15632c6354895b1dd542ed5a855c0f15d9ad1326c6fe2b2c9e423190')

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

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

  make
}

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

  # Use predefined variables in pkgconfig files (#17541)
  find "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig" -type f -name '*.pc' \
    -exec sed -i -e "s|${MINGW_PREFIX}/include|\${prefix}/include|g" \
    -e "s|${MINGW_PREFIX}/lib|\${prefix}/lib|g" {} \;

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