# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=connect
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.105
pkgrel=5
pkgdesc="Make socket connection using SOCKS4/5 and HTTP tunnel (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/gotoh/ssh-connect"
license=('spdx:GPL-2.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-Make-it-relocatable.patch"
        "pathtools.c"
        "pathtools.h")
sha256sums=('96c50fefe7ecf015cf64ba6cec9e421ffd3b18fef809f59961ef9229df528f3e'
            '9b1d2c5314e790379ba9e996e104c8bdef8719e743adb94aef50179d878d4a93'
            'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0'
            '1585ef1b61cf53a2ca27049c11d49e0834683dfda798f03547761375df482a90')

prepare() {
  test ! -d "${startdir}/../mingw-w64-pathtools" || {
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
  } || exit 1

  cd "${srcdir}/ssh-connect-${pkgver}/"

  cp -fHv "${srcdir}"/pathtools.[ch] ./

  patch -p1 -i "${srcdir}/0001-Make-it-relocatable.patch"
}

build() {
  cd "${srcdir}/ssh-connect-${pkgver}"

  test -x ver || printf '#!/bin/sh\n\necho Windows\n' > ver

  PATH=.:$PATH make -j1 rebuild CC=cc
}

package() {
  cd "${srcdir}/ssh-connect-${pkgver}"

  install -d "${pkgdir}${MINGW_PREFIX}/bin/"
  install connect.exe "${pkgdir}${MINGW_PREFIX}/bin/"

  install -d "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
  install doc/manual.html "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
  install doc/manual.txt "${pkgdir}${MINGW_PREFIX}/share/doc/connect/"
}
