# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=tclx
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=8.6.3
pkgrel=1
pkgdesc="Extends Tcl by providing new operating system interface commands, extended file control and many other (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://tclx.sourceforge.io/"
msys2_repository_url="https://github.com/flightaware/tclx"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-tcl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/flightaware/tclx/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        '001-fix-detect-mingw.patch')
sha256sums=('4707d895fb213f9db02944fdd676acea3e8cb946f1c04b0cead5ea71a4893b10'
            '5018594a4889c41fcb1a669f29b971dff19759c0fb2d8939bb495bb3715dbf08')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-detect-mingw.patch
}

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

  CFLAGS="-DUSE_INTERP_ERRORLINE $CFLAGS" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --with-tcl="/${MSYSTEM}/lib/" \
    --enable-64bit

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/license.terms "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/license.terms
}
