# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libraqm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.7.1
pkgrel=1
pkgdesc="A library that encapsulates the logic for complex text layout (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/HOST-Oman/libraqm"
depends=("${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz" 
         "${MINGW_PACKAGE_PREFIX}-fribidi")
makedepends=("${MINGW_PACKAGE_PREFIX}-gtk-doc")
license=('MIT')
source=("${_realname}-$pkgver".tar.gz::"https://github.com/HOST-Oman/libraqm/archive/v${pkgver}.tar.gz"
        "libraqm-enable-shared.patch")
sha256sums=('3a80118fde37b8c07d35b0d40465e68190bdbd6e984ca6fe5c8192c521bb076d'
            '9809d2d5a451b8b512cf535bfad5e5ccd0771b285c7475eca5ead75833af8409')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  apply_patch_with_msg libraqm-enable-shared.patch
  ./autogen.sh
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static=yes \
    --enable-shared=yes \
    --enable-fast-install=yes \
    --enable-gtk-doc=yes
  make
}

#tests require chcp 65001

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
