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

_realname=winico
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6
pkgrel=2
pkgdesc="Tk extension for Windows for enhanced icon handling and manipulation of an icon in the Windows taskbar and system tray (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://tktable.sourceforge.io/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-tk")
source=("https://sourceforge.net/projects/tktable/files/${_realname}/${pkgver}/${_realname}${pkgver/./}src.zip"
        001-Fix-GCL_ICON.patch
        002-Fix-pointer-cast.patch)
sha256sums=('aba8a8be3f789fe94af0100b714d4cdbd2428afd79ba42b4a775d8456114e50f'
            '7153ba8646b6f300b2c13aa81d753e41517154d023c2a9b27f2eb0b1314cb5bc'
            'cabb67f8cede2ace408f9a6df51ec4881dbfe5dba2d97d4ad785f72aa8e11b56')

_dllname=libWinico${pkgver}.dll

prepare() {
  cd "${srcdir}/winico-${pkgver}"
  patch -Np1 -i "${srcdir}/001-Fix-GCL_ICON.patch"
  patch -Np1 -i "${srcdir}/002-Fix-pointer-cast.patch"
}

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

  source ${MINGW_PREFIX}/lib/tclConfig.sh
  source ${MINGW_PREFIX}/lib/tkConfig.sh

  ${MINGW_PREFIX}/bin/gcc -shared -o $_dllname -O2 \
    ${srcdir}/winico-${pkgver}/tkwinico.c \
    -DPACKAGE_NAME=\"Winico\" -DPACKAGE_VERSION=\"${pkgver}\" \
    -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 -Wno-implicit-int \
    $TK_STUB_LIB_SPEC $TCL_STUB_LIB_SPEC -lgdi32
}

package() {
  cd "${srcdir}/build-${CARCH}"
  _dst="$pkgdir/$MINGW_PREFIX/lib/winico${pkgver}"
  mkdir -p $_dst
  cp *.dll $_dst
  echo -e "This sofware has been modified by the MSYS2 project.\r\n\r\n" > $_dst/license.terms
  cat ${srcdir}/winico-${pkgver}/license.terms >> $_dst/license.terms
  echo "package ifneeded Winico ${pkgver} [list load [file join \$dir $_dllname]]" > $_dst/pkgIndex.tcl
}
