# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=asmjit
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.r562.ga3199e8
pkgrel=1
pkgdesc="Machine code generation for C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: asmjit-git'
)
url="https://asmjit.com"
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
_commit="a3199e8857792cd10b7589ff5d58343d2c9008ea"
source=(${_realname}-git::"git+https://github.com/asmjit/asmjit.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}-git"
  echo '0.0.r'"$(git rev-list --count "${_commit}")"'.g'"$(git describe --all --long "${_commit}" | sed 's/^.*-g\(.*\)/\1/')"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_STANDARD=11 \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-git

  cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" cmake --install .
}
