# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=winpty
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.3
pkgrel=4
pkgdesc='A Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/rprichard/winpty'
msys2_repository_url='https://github.com/rprichard/winpty'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/rprichard/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz
        https://github.com/rprichard/winpty/commit/1424696a6d6f46702eaf9037d7f8bd80ca98ece1.patch
        001-makefile-mingw-fix.patch)
sha256sums=('093037c39f9c899d79b74d5e15ff74fb59a98c492c5ed621e97e1090c3442865'
            '07a4fff22da7e0dc48bfb11096f2e56c18e5f961a7814a9f2ea82dc3e5fc71a0'
            '1db0a62a9f2db96f51f4d55c012241558fc16d8bf5a4d6c6bad2809e17afffde')

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

  patch -p1 -i "${srcdir}"/001-makefile-mingw-fix.patch

  # https://github.com/rprichard/winpty/commit/1424696a6d6f46702eaf9037d7f8bd80ca98ece1
  # This new function is needed by node-pty
  patch -p1 -i "${srcdir}"/1424696a6d6f46702eaf9037d7f8bd80ca98ece1.patch
}

build() {
  cp -r ${_realname}-${pkgver} build-${MSYSTEM} && cd build-${MSYSTEM}
  
  ./configure  
  make
}

package() {
  cd build-${MSYSTEM}

  make PREFIX="${pkgdir}"${MINGW_PREFIX} install

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