# Author: williamjcm <w.jcm59@gmail.com>
# Contributor: mosra <mosra@centrum.cz>
# Based on the AUR PKGBUILD from https://github.com/mosra/magnum-integration and the MSYS2/MinGW PKGBUILD templates

_realname=magnum-integration
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2019.10
pkgrel=1
pkgdesc='Integration libraries for the Magnum C++11/C++14 graphics engine'
arch=('any')
url='https://magnum.graphics/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-magnum>=$pkgver"
         "${MINGW_PACKAGE_PREFIX}-bullet"
         "${MINGW_PACKAGE_PREFIX}-eigen3"
         "${MINGW_PACKAGE_PREFIX}-glm")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja" 'git')
# The .tar.gz / .zip download contains symlinks (.travis.yml), making tar and
# unzip on Windows grumpy because dangling symlinks are created. Could be fixed
# by manually extracting everything except symlinks, but that's hard to
# maintain. Downloading a Git tag works.
source=("${_realname}-${pkgver}"::"git+https://github.com/mosra/magnum-integration.git#tag=v$pkgver")
sha1sums=('SKIP')

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

    declare -a extra_config
    if check_option "debug" "n"; then
        extra_config+=("-DCMAKE_BUILD_TYPE=Release")
    else
        extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
    fi

    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        ${MINGW_PREFIX}/bin/cmake \
            -G'Ninja' \
            -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
            -DWITH_BULLET=ON \
            -DWITH_EIGEN=ON \
            -DWITH_GLM=ON \
            "${extra_config[@]}" \
            ../${_realname}-${pkgver}
    ninja
}

package() {
    cd "${srcdir}"/build-${CARCH}
    DESTDIR="${pkgdir}" ninja install

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