# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=osgQtQuick
pkgbase=mingw-w64-${_realname}-git
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}-git" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug-git")
_ver_base=2.0.0
pkgver=2.0.0.r172
pkgrel=4
pkgdesc="OpenSceneGraph QML Modules (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('LGPL')
url="https://github.com/podsvirov/osgqtquick"
makedepends=("make"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-osgQt"
             "${MINGW_PACKAGE_PREFIX}-osgQt-debug"
             "${MINGW_PACKAGE_PREFIX}-qt5")
options=(!strip staticlibs !buildflags)
source=(${_realname}::git+https://github.com/podsvirov/osgqtquick.git#branch=develop)
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "%s.r%s" "${_ver_base}" "$(git rev-list --count HEAD)"
}

build() {
  [[ -d ${srcdir}/release-${MINGW_CHOST} ]] && rm -rf ${srcdir}/release-${MINGW_CHOST}
  mkdir -p ${srcdir}/release-${MINGW_CHOST} && cd ${srcdir}/release-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    ../osgqtquick
  make

  [[ -d ${srcdir}/debug-${MINGW_CHOST} ]] && rm -rf ${srcdir}/debug-${MINGW_CHOST}
  mkdir -p ${srcdir}/debug-${MINGW_CHOST} && cd ${srcdir}/debug-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Debug \
    ../osgqtquick
}

package_osgQtQuick-git() {
  depends=("${MINGW_PACKAGE_PREFIX}-osgQt"
           "${MINGW_PACKAGE_PREFIX}-qt5"
           "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph")
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
  replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-svn)

  cd ${srcdir}/release-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}

package_osgQtQuick-debug-git() {
  depends=("${MINGW_PACKAGE_PREFIX}-osgQt-debug"
           "${MINGW_PACKAGE_PREFIX}-qt5"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-git=${pkgver}"
           "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph-debug")
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-debug" "${MINGW_PACKAGE_PREFIX}-${_realname}-debug-svn")
  replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-debug-svn)

  cd ${srcdir}/debug-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}${MINGW_PREFIX}/include
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfig.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickConfigVersion.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/cmake/osgQtQuick/osgQtQuickTargets.cmake
  rm -rf ${pkgdir}${MINGW_PREFIX}/share/qt5/qml/*/qmldir
}

# 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;
