# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=mypaint-brushes
pkgbase=mingw-w64-${_realname}2
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}2"
pkgver=2.0.2
pkgrel=4
pkgdesc="Brushes for MyPaint 2.0 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mypaint/mypaint-brushes"
msys2_references=(
  'archlinux: mypaint-brushes'
)
license=('spdx:ISC')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/mypaint/mypaint-brushes/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
         0001-change-surfacemap-inputs.patch)
sha256sums=('01032550dd817bb0f8e85d83a632ed2e50bc16e0735630839e6c508f02f800ac'
            'b1fb7930edfee1b96e10d58e81c1c1046ab31bbf97ae747d87ddf4fdbf1cbaf0')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  [[ -d "${srcdir}"/${_realname}-${pkgver} ]] && rm -rf "${srcdir}"/${_realname}-${pkgver}

  tar --exclude=README -xzf ${_realname}-${pkgver}.tar.gz

  cd ${_realname}-${pkgver}

  # https://gitlab.gnome.org/GNOME/gimp/-/issues/14461
  patch -p1 -i "${srcdir}"/0001-change-surfacemap-inputs.patch

  ./autogen.sh
}

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

  "${srcdir}/${_realname}-${pkgver}"/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make -j1 DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/Licenses.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}2/Licenses.md
}
