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

_realname=ois
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.5.1
pkgrel=1
pkgdesc="Object Oriented Input System (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sourceforge.net/projects/wgois/"
msys2_repository_url="https://github.com/wgois/OIS"
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/wgois/OIS/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-mingw-build.patch)
sha256sums=('614f6ef6d69cf6d84f1b50efff46a6c1acce426933e5f0dcf29862ea8332af73'
            '600b583902062fef5c24cd25e770aba8ac1e513b4643f5a5ceb67e087fd3c144')

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

  patch -p1 -i "${srcdir}"/001-mingw-build.patch
}

build() {
  msg "Build shared version..."
  mkdir -p "${srcdir}"/build-shared-${MSYSTEM} && cd "${srcdir}"/build-shared-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DOIS_BUILD_SHARED_LIBS=ON \
    -DOIS_BUILD_DEMOS=ON \
    ../OIS-${pkgver}
  "${MINGW_PREFIX}"/bin/cmake.exe --build .

  msg "Build static version..."
  mkdir -p "${srcdir}"/build-static-${MSYSTEM} && cd "${srcdir}"/build-static-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DOIS_BUILD_SHARED_LIBS=OFF \
    -DOIS_BUILD_DEMOS=ON \
    ../OIS-${pkgver}
  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}"/build-static-${MSYSTEM}
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  cd "${srcdir}"/build-shared-${MSYSTEM}
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

  install -Dm644 "${srcdir}"/OIS-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md
}
