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

_realname=glsl-optimizer
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r66917.d78c3d2f24
_commit=d78c3d2f249aa870368ad320905bc954c47704f6
pkgrel=1
pkgdesc="C++ library that takes GLSL shaders, does some GPU-independent optimizations on them and outputs GLSL back (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/aras-p/glsl-optimizer"
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')
source=("${_realname}"::"git+https://github.com/aras-p/glsl-optimizer.git#commit=$_commit"
        0002-tests-MinGW-w64-Fix-build.patch
        0003-Win64-long-is-32-bit-use-intptr_t-instead.patch
        0004-tests-MinGW-w64-Use-find_package-OpenGL-in-CMakeList.patch
        0006-CMake-Handle-installation.patch)
sha256sums=('SKIP'
            '8e98f9c630b2d54c1d9c85bee27f4e9eb7b5b233849272dacec94d5bce1b005d'
            '867fad6f9000bfa6cb70bab4a9bf2d533da1e3dbd87c2fddad5c9cd18222ce29'
            'cf1e2ed63f6c77b08d834e3315972ba1fe19b5be5503bfba53fb153d5a4f8362'
            '9c35c74f3a4d5124b78b2fea94087d2d443529f5d0e65f164cc96255b2d2fa82')

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}"/0002-tests-MinGW-w64-Fix-build.patch
  git am --committer-date-is-author-date "${srcdir}"/0003-Win64-long-is-32-bit-use-intptr_t-instead.patch
  git am --committer-date-is-author-date "${srcdir}"/0004-tests-MinGW-w64-Use-find_package-OpenGL-in-CMakeList.patch
  git am --committer-date-is-author-date "${srcdir}"/0006-CMake-Handle-installation.patch
}

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

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

  make
}

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