# Maintainer: Junjie Mao <eternal.n08@gmail.com>

_realname=libart_lgpl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.3.21
pkgrel=4
pkgdesc="Library for high-performance 2D graphics (mingw-w64)"
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: libart-lgpl'
  'cygwin: libart_lgpl_2'
  'cygwin-mingw64: libart_lgpl2'
)
url='https://www.levien.com/libart'
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.bz2"
        "0001-Fix-an-installation-path-bug.patch"
        "0002-aarch64.patch")
sha256sums=('fdc11e74c10fc9ffe4188537e2b370c0abacca7d89021d4d303afdf7fd7476fa'
            '730eca896d981b5c8e6d65e96ceededed6e08068c8b6f29a782d7b56ddae92d6'
            '9b36b95bcdf6c051f6f72c16cf9daf8b92bd376d8311e6bc6ec4f150449b4bcd')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

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

  apply_patch_with_msg \
    0001-Fix-an-installation-path-bug.patch \
    0002-aarch64.patch
}

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

  ../${_realname}-${pkgver}/configure \
     --prefix=${MINGW_PREFIX} \
     --exec-prefix=${MINGW_PREFIX} \
     --build=${MINGW_CHOST} \
     --host=${MINGW_CHOST} \
     --target=${MINGW_CHOST} \
     --enable-static \
     --enable-shared

  cp ../${_realname}-${pkgver}/libart.def libart.def
  make
}

check() {
  # The package ships with some test tools but provides no automatic check mechanisms
  plain "skip"
}

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

  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -f COPYING ]] && install -Dm644 COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  [[ -f AUTHORS ]] && install -Dm644 AUTHORS "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/AUTHORS
  [[ -f NEWS ]] && install -Dm644 NEWS "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/NEWS
}
