# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=pango
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.48.7
pkgrel=1
pkgdesc="A library for layout and rendering of text (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.pango.org/"
license=('LGPL2.1')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
            "${MINGW_PACKAGE_PREFIX}-meson"
            "${MINGW_PACKAGE_PREFIX}-ninja"
            "${MINGW_PACKAGE_PREFIX}-gi-docgen")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-libthai")
options=('staticlibs' 'strip' 'emptydirs')
source=("https://download.gnome.org/sources/pango/${pkgver:0:4}/${_realname}-${pkgver}.tar.xz"
        "0001-fix-stdio-include.patch")
sha256sums=('28a82f6a6cab60aa3b75a90f04197ead2d311fa8fe8b7bfdf8666e2781d506dc'
            'a8a6dba43f6a3dd7b081b09c292cc9db7dcbffb94f1f5f9b7a4985b290cf1bfe')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-fix-stdio-include.patch"
}

build() {
  cd "${srcdir}"
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --default-library shared \
    --buildtype plain \
    --auto-features=enabled \
    -Dgtk_doc=true \
    -Dxft=disabled \
    --wrap-mode=nofallback \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile

  cd "${srcdir}"
  [[ -d build-static-${MINGW_CHOST} ]] && rm -rf build-static-${MINGW_CHOST}
  mkdir -p build-static-${MINGW_CHOST}
  cd build-static-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --default-library static \
    --buildtype plain \
    --auto-features=enabled \
    -Dgtk_doc=false \
    -Dintrospection=disabled \
    --wrap-mode=nofallback \
    -Dxft=disabled \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

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

  # remove installed tests, no need and they contain the build path which
  # leads to pkgbuild warnings
  rm -Rf "${pkgdir}${MINGW_PREFIX}/share/installed-tests"
  rm -Rf "${pkgdir}${MINGW_PREFIX}/libexec"

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