# Maintainer: The MyPaint Team <mypaintopensource@gmail.com>

_realname=libmypaint
_realver=1.5.1
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-mypaint<1.3.0alpha")
pkgver=${_realver/-/}
pkgrel=3
pkgdesc="Brush engine used by MyPaint (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://mypaint.org"
license=("ISC")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-glib2"
             "git")
# autotools are required because several Makefile.am are modified
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-json-c")
options=('strip' '!debug')
source=("https://github.com/mypaint/${_realname}/releases/download/v${_realver}/${_realname}-${_realver}.tar.xz"
        "0001-fix-autoconf.patch")
sha256sums=('aef8150a0c84ce2ff6fb24de8d5ffc564845d006f8bad7ed84ee32ed1dd90c2b'
            '0ba7acddb4962f84ea817a497f41d39dd26f3829db532c056e0705ef751fcf11')

prepare() {
  cd ${_realname}-${_realver}

  # https://github.com/mypaint/libmypaint/issues/178
  patch -p1 -i "${srcdir}/0001-fix-autoconf.patch"

  autoreconf -fiv
}

build() {
  #export GI_SCANNER_DEBUG="save-temps"
  cd "${srcdir}"
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  cp -rf ${_realname}-${_realver} build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  #mkdir -p build-${MINGW_CHOST}
  #cd build-${MINGW_CHOST}


  PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/share/pkgconfig" \
  ./configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${_realver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
