# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=winfile
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=10.2.0.0
pkgrel=2
pkgdesc="Original Windows File Manager (winfile) with enhancements (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/microsoft/winfile"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip !buildflags)
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-cpp-17.patch")
sha256sums=('441ec49ca6ad3af6abb3169a5f95e84ce00d3e3a9dedaf33f1088f4e4ac32524'
            '98e2043523fc2e989e3483fb3f72fec107dfb579251b1519b92fcbc9a428848e')

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  _apply_patch_with_msg \
    001-cpp-17.patch
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CC=cc CXX=c++ make
}

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

  mkdir -p "${pkgdir}${MINGW_PREFIX}"/bin
  cp winfile.exe "${pkgdir}${MINGW_PREFIX}"/bin/

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