# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=nanovg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=r398.c35e80c
pkgrel=1
pkgdesc="Small antialiased vector graphics rendering library for OpenGL"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/memononen/nanovg"
license=('ZLIB')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-premake")
_commit="c35e80c3fed7445b4e2973fccccc89afd97834cf"
source=("${_realname}"::"git+https://github.com/memononen/nanovg.git#commit=${_commit}")
sha256sums=('SKIP')
options=('staticlibs')

case ${MINGW_CHOST} in
  i686*)
    _mach=x86
    _ctype=release32
  ;;
  x86_64*)
    _mach=x86_64
    _ctype=release64
  ;;
esac

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

build() {
  cd "${srcdir}"
  rm -rf "${MINGW_CHOST}" || true
  cp -rf "${srcdir}/${_realname}" "${srcdir}/${MINGW_CHOST}"
  cd "${srcdir}/${MINGW_CHOST}"
  premake4 gmake --os=windows cc=gcc
  cd build
  make config=${_ctype} nanovg
}

package() {
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/build/libnanovg.a" "${pkgdir}${MINGW_PREFIX}/lib/libnanovg.a" || exit 1
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/LICENSE.txt" || exit 1
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/src/nanovg.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg.h" || exit 1
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/src/nanovg_gl.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg_gl.h" || exit 1
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/src/nanovg_gl_utils.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg_gl_utils.h" || exit 1
  install -v -Dm644 "${srcdir}/$MINGW_CHOST/src/fontstash.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/fontstash.h" || exit 1
}
