# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=hlsl2glsl
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r852.14dd189
pkgrel=1
pkgdesc="HLSL to GLSL shader language translator"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/aras-p/hlsl2glslfork'
license=('MIT')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('!strip' 'staticlibs' '!emptydirs')
_commit="14dd189562ea32979ff9b1ac9b047c744393f7bf"
source=("${_realname}"::"git+https://github.com/aras-p/hlsl2glslfork.git#commit=${_commit}"
        0001-CMakeLists.txt-Fixes-and-improvements.patch
        0002-Fix-pool_allocator-compile-guards.patch
        0003-hlsl2glsltest-Change-_MSC_VER-to-_WIN32.patch
        0004-CMake-Handle-installation.patch)
sha256sums=('SKIP'
            'd527524ebe9d381f8970844a31d50f0b4c3844b805408a2aaf4e3c63a0812d12'
            '352784c15bd464df885947fa36fec3ba6cd984e3bbf90be2377764492ef4f709'
            '121c1664931f0ea1d3006c5c0b8415014d1ff597bd5d3ec3b272c6bcf60f4192'
            'a28b97c6782706eeb2cae14e23be86f5e59c25cf5399f3c37f249b5723d020a1')

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

prepare() {
  cd "${srcdir}"/${_realname}
  git am --committer-date-is-author-date "${srcdir}"/0001-CMakeLists.txt-Fixes-and-improvements.patch
  git am --committer-date-is-author-date "${srcdir}"/0002-Fix-pool_allocator-compile-guards.patch
  git am --committer-date-is-author-date "${srcdir}"/0003-hlsl2glsltest-Change-_MSC_VER-to-_WIN32.patch
  git am --committer-date-is-author-date "${srcdir}"/0004-CMake-Handle-installation.patch
}

build() {
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
    ${MINGW_PREFIX}/bin/cmake \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -G"MSYS Makefiles" \
      "${srcdir}"/${_realname}

  make
}

package() {
  cd build-${CARCH}
  make install DESTDIR=${pkgdir}
}
