# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=meld
pkgbase=mingw-w64-${_realname}3
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}3"
pkgver=3.21.0
pkgrel=3
pkgdesc="Visual diff and merge tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://meldmerge.org/"
license=("GPL" "LGPL")
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gtksourceview4"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
         "${MINGW_PACKAGE_PREFIX}-gsettings-desktop-schemas"
         "${MINGW_PACKAGE_PREFIX}-python-gobject")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-itstool"
             'intltool')
install=meld-${CARCH}.install
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        '0001-fixes-for-MinGW-w64-symlinks-and-use-sh-to-spawn.patch')
sha256sums=('b680114d5ab793324549fd58f4eb202d8e280c0633a0b765ede6dfb34160a81b'
            'dd6bab18d62698b442af7addb27f1e8d2166b68605dedc410da86d56d4d4e96c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-fixes-for-MinGW-w64-symlinks-and-use-sh-to-spawn.patch"
}

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

  ${MINGW_PREFIX}/bin/python setup.py build
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py --no-update-icon-cache --no-compile-schemas \
    install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/bin/meld
}
