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

_realname=csfml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5
pkgrel=2
pkgdesc="A simple, fast, cross-platform, and object-oriented multimedia API for C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/SFML/CSFML"
license=("zlib")
depends=("${MINGW_PACKAGE_PREFIX}-sfml")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/SFML/CSFML/archive/${pkgver}.tar.gz
        mingw-w64-msys2.patch)
sha256sums=('d49ddfbe9c14dbca60dd524d10bca7922142dc32a07a5dfbbd209cda7caad860'
            'f052dd44659cf50f1645e2a99ce4e9c7f59b8aa2ac7017287394d8a0672011db')

prepare() {
  cd ${srcdir}/CSFML-${pkgver}
  patch -p1 -i ${srcdir}/mingw-w64-msys2.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCSFML_LINK_SFML_STATICALLY=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DCSFML_BUILD_DOC=ON \
    ../CSFML-${pkgver}

  make
  make doc
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/CSFML-${pkgver}/license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
} 
