# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=cairomm
pkgbase=mingw-w64-${_realname}-1.16
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-1.16"
pkgver=1.18.0
pkgrel=2
pkgdesc="C++ bindings to Cairo vector graphics library (V1.16) (mingw-w64)"
url="https://cairographics.org/cairomm/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libsigc++-3.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-boost")
source=("https://www.cairographics.org/releases/${_realname}-${pkgver}.tar.xz")
sha256sums=('b81255394e3ea8e8aa887276d22afa8985fc8daef60692eb2407d23049f03cfb')

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

}

build() {
  local -a _static_flags=(
    -DCAIRO_WIN32_STATIC_BUILD
  )

  local -a _meson_options=(
    --prefix="${MINGW_PREFIX}"
    --wrap-mode=nodownload
    --auto-features=enabled
    -Dmaintainer-mode=false
    -Dbuild-documentation=false
    -Dbuild-examples=true
    -Dbuild-tests=true
  )

  CFLAGS+=" ${_static_flags[@]}" \
  CXXFLAGS+=" ${_static_flags[@]}" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    "${_meson_options[@]}" \
    --default-library=static \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-static"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    "${_meson_options[@]}" \
    --default-library=shared \
    "${_realname}-${pkgver}" \
    "build-${MSYSTEM}-shared"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-shared"
}

check() {
  ${MINGW_PREFIX}/bin/meson.exe test -C "build-${MSYSTEM}-static" || warning "Tests failed"
  ${MINGW_PREFIX}/bin/meson.exe test -C "build-${MSYSTEM}-shared" || warning "Tests failed"
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-static" --destdir "${pkgdir}"
  ${MINGW_PREFIX}/bin/meson.exe install -C "build-${MSYSTEM}-shared" --destdir "${pkgdir}"

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