# Maintainer: David Macek <david.macek.0@gmail.com>

# todo check if unix directory is interesting
# todo install docs

_realname=putty
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.73
pkgrel=1
pkgdesc="A free telnet/SSH client (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.chiark.greenend.org.uk/~sgtatham/putty/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=("${MINGW_PACKAGE_PREFIX}-putty-ssh: ssh wrapper for plink")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
source=("https://the.earth.li/~sgtatham/putty/latest/${_realname}-${pkgver}.tar.gz"
        '0002-win7-flags.patch')
sha256sums=('3db0b5403fb41aecd3aa506611366650d927650b6eb3d839ad4dcc782519df1c'
            'e0f068feded891578b516de8e618fc7df4ae4e4d88939b0296f1578738754953')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0002-win7-flags.patch

  mkdir -p "${srcdir}"/${_realname}-build-${CARCH}
  cp -r "${srcdir}"/${_realname}-${pkgver}/* "${srcdir}"/${_realname}-build-${CARCH}
}

build() {
  cd "${srcdir}"/${_realname}-build-${CARCH}

  ./mkfiles.pl
  cd windows
  if [ "${CARCH}" = "x86_64" ]; then
    sed -i 's/x86/amd64/' *.mft
  fi
  make -f Makefile.mgw
}

package() {
  cd "${srcdir}"/${_realname}-build-${CARCH}/windows
  install -D -m644 ../LICENCE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
  for f in putty puttygen pageant plink pscp psftp puttytel
  do
    install -D -m755 ${f}.exe "${pkgdir}"/${MINGW_PREFIX}/bin/${f}.exe
  done
}
