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

_realname=libass
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.17.4
pkgrel=2
pkgdesc="A portable library for SSA/ASS subtitles rendering (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/libass/libass'
msys2_references=(
  "cpe: cpe:/a:libass_project:libass"
)
license=('spdx:ISC')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  $([[ "${MSYSTEM}" == "CLANGARM64" ]] || echo "${MINGW_PACKAGE_PREFIX}-nasm")
)
depends=("${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-libunibreak"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz")
source=(https://github.com/libass/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.xz
        "897.patch")
sha256sums=('78f1179b838d025e9c26e8fef33f8092f65611444ffa1bfc0cfac6a33511a05a'
            '24183b78eb6a16180c32f489c4d453b21b766d84b11feabfc4b61f3ec12e6def')

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

  # https://github.com/libass/libass/issues/896
  patch -p1 -i "${srcdir}/897.patch"
}

build() {
  CPPFLAGS+=" -DFRIBIDI_LIB_STATIC" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      --default-library=static \
      -Dcoretext=disabled \
      "build-${MSYSTEM}-static" \
      "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      --default-library=shared \
      -Dcoretext=disabled \
      "build-${MSYSTEM}" \
      "${_realname}-${pkgver}"

  meson compile -C "build-${MSYSTEM}"
}

package() {
  meson install -C "build-${MSYSTEM}-static" --destdir "${pkgdir}"
  meson install -C "build-${MSYSTEM}" --destdir "${pkgdir}"
}
