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

_realname=cglm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.3
pkgrel=1
pkgdesc="OpenGL Mathematics (glm) for C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/recp/cglm"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme")
options=(!strip staticlibs !buildflags)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/recp/cglm/archive/v${pkgver}.tar.gz")
sha256sums=('3a3f935f9f2ed5a8cb6337e421bf6f3a699a72d8cfe26fde1bbb8fde5c1c8aaf')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./autogen.sh
}

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

  ../"${_realname}-${pkgver}"/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST}
  make

  cd "${srcdir}/${_realname}-${pkgver}/docs"
  ${MINGW_PREFIX}/bin/sphinx-build source ${_realname}
}

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/cglm/LICENSE
  install -Dm644 cglm.pc "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/cglm.pc

  cd "${srcdir}/${_realname}-${pkgver}/docs"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/share/doc
  cp -r ${_realname} "${pkgdir}${MINGW_PREFIX}"/share/doc/
}
