# Maintainer: Simon Kissane <skissane@gmail.com>

_realname=mtools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.0.49
pkgrel=1
pkgdesc="collection of utilities to access FAT filesystems without mounting them"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
url="https://www.gnu.org/software/mtools"
msys2_references=(
  "cpe: cpe:/a:mtools:mformat"
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.lz{,.sig}
        "0001-nl_langinfo.patch")
sha256sums=('76dfea98d923dfc9806ce34bd1786aa9b5a39d70f56f26c0670a348c664f1d2a'
            'SKIP'
            '999661ece6c41bd0b316426bae7df585972037db0a4de491786f477646749eb6')
validpgpkeys=('51A23D9D7C4DF41AA48FA893E99CF5537790B839')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i $srcdir/0001-nl_langinfo.patch
  autoreconf -fiv
}

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

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make USERLDLIBS=-"liconv"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

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