# Maintainer: Jordan Irwin <antumdeluge@gmail.com>

_realname=wxsvg
_wx_basever=3.2
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-wx${_wx_basever}"
pkgbase="mingw-w64-${_realname}"
pkgver=1.5.25
pkgrel=4
pkgdesc="A C++ library to create, manipulate and render SVG files (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://wxsvg.sourceforge.io/"
license=('spdx:wxWindows')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libexif"
         "${MINGW_PACKAGE_PREFIX}-ffmpeg")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw")
source=("https://downloads.sourceforge.net/project/wxsvg/wxsvg/${pkgver}/wxsvg-${pkgver}.tar.bz2"
        '001-Add-include-of-cstdint.patch'
        "gcc11-fix.patch")
sha256sums=('5bf6ac6831b54bd19aef48cde8fa0572dbb63f30aee9d5323f6be6b3f326534b'
            '70b18ac6499296dc92bd84b8513171e468845eb11fe19d00d3d413719c6a787e'
            'ac7b984f9ce4f051858ada88284545f4373b27a0b1200fe9f646467bd6c9f3bd')
extractdir="${_realname}-${pkgver}"
builddir="build-${MSYSTEM}"

prepare() {
  cd "${srcdir}/${extractdir}"

  # mediadec_ffmpeg.h has a "using namespace std" conflicting with system headers.
  # ideally that would be moved to the cpp files, but the diff is too large
  patch -p1 -i "${srcdir}"/gcc11-fix.patch

  patch -p1 -i "${srcdir}"/001-Add-include-of-cstdint.patch

  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/${builddir}" && cd "${srcdir}/${builddir}"

  ../${extractdir}/configure \
      --prefix=${MINGW_PREFIX} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --build=${MINGW_CHOST} \
      --with-wx-config=${MINGW_PREFIX}/bin/wx-config-${_wx_basever} \
      --enable-shared \
      --enable-static
  make
}

check() {
  cd "${srcdir}/${builddir}"
  make -k check
}

package() {
  cd "${srcdir}/${builddir}"
  make install DESTDIR="${pkgdir}"

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