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

_realname=csfml
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
pkgver=3.0.0.rc3
_tag=3.0.0-rc.3
pkgrel=1
pkgdesc="A simple, fast, cross-platform, and object-oriented multimedia API for C (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/SFML/CSFML"
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-sfml")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(https://github.com/SFML/CSFML/archive/${_tag}/${_realname}-${_tag}.tar.gz
        mingw-w64-msys2.patch)
sha256sums=('3de2803549241da5b8cb91fdc55575b6e3427802470eabdef2b789147be761a1'
            '39423ae7a1f080d632f2ae2b01b5c850e9e7e7270629b2f57699c6798a6726f4')

prepare() {
  cd CSFML-${_tag}

  patch -p1 -i ../mingw-w64-msys2.patch
}

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCSFML_LINK_SFML_STATICALLY=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DCSFML_BUILD_DOC=ON \
    -S CSFML-${_tag} \
    -B build-${MSYSTEM}

  cmake --build build-${MSYSTEM}
}

package_csfml() {
  DESTDIR="${pkgdir}" cmake --install build-${MSYSTEM}
  install -Dm644 CSFML-${_tag}/license.md \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  # split docs
  mkdir -p dest${MINGW_PREFIX}/share
  mv "${pkgdir}${MINGW_PREFIX}"/share/CSFML dest${MINGW_PREFIX}/share/CSFML
}

package_csfml-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
