# Maintainer: Oscar Fuentes <ofv@wanadoo.es>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Based on Arch's PKGBUILD

_realname=tktable
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgnameactual=Tktable
pkgver=2.10
pkgrel=7
pkgdesc="A full-featured 2D table widget for Tk (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://tktable.sourceforge.io/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-tk")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://downloads.sourceforge.net/project/$_realname/$_realname/$pkgver/${_pkgnameactual}${pkgver}.tar.gz"
        001-fix-detect-mingw.patch)
sha256sums=('c335117fa1be45fe4d3032e96fd4b4641fff6a4f8467878608dabed11198a4cb'
            '1decff05ed2e09f62a44e1e6d15e32904f331e83c4e1170f5f1140f7d9f9bb1f')

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

  # For clang
  sed -i "s/-fPIC//g" tclconfig/tcl.m4

  autoreconf -fiv
}

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

  [[ "${MINGW_CHOST}" = 'x86_64-w64-mingw32' ]] && enable64bit='--enable-64bit'
  [[ "${MINGW_CHOST}" = 'aarch64-w64-mingw32' ]] && enable64bit='--enable-64bit'

  CFLAGS+=" -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types" \
  ../${_pkgnameactual}${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    $enable64bit

  make
}

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