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

_realname=fribidi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.10
pkgrel=2
pkgdesc="A Free Implementation of the Unicode Bidirectional Algorithm (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('LGPL')
url="https://github.com/fribidi/fribidi/"
depends=()
options=('strip' '!libtool' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/fribidi/fribidi/archive/v${pkgver}.tar.gz")
sha256sums=('3ebb19c4184ed6dc324d2e291d7465bc6108a20be019f053f33228e07e879c4f')

build() {
  mkdir -p build-${MINGW_CHOST}-static
  cd build-${MINGW_CHOST}-static

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
      --prefix=${MINGW_PREFIX} \
      --buildtype plain \
      --prefix=${MINGW_PREFIX} \
       -Ddocs=false \
       --default-library static \
      ../${_realname}-${pkgver}

  ninja

  cd ..
  mkdir -p build-${MINGW_CHOST}-shared
  cd build-${MINGW_CHOST}-shared

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
      --prefix=${MINGW_PREFIX} \
      --buildtype plain \
      --prefix=${MINGW_PREFIX} \
       -Ddocs=false \
       --default-library shared \
      ../${_realname}-${pkgver}

  ninja
}

check() {
  cd build-${MINGW_CHOST}-shared

  meson test
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}-static
  DESTDIR="${pkgdir}" ninja install

  cd ${srcdir}/build-${MINGW_CHOST}-shared
  DESTDIR="${pkgdir}" ninja install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
