# Maintainer: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=mhook
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=r7.a159eed
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="An API hooking library (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "git")
options=('strip' 'staticlibs')
license=('custom')
url="https://github.com/SirAnthony/mhook"
source=("${_realname}"::"git+https://github.com/SirAnthony/mhook.git")
sha256sums=('SKIP')

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

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DMHOOK_TESTS=ON \
    ../${_realname}
  make V=1
}

check()
{
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./mhook-tests
}

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

  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/include/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname

  cp libmhook.a ${pkgdir}${MINGW_PREFIX}/lib/
  cp ${srcdir}/${_realname}/${_realname}-lib/${_realname}.h \
    ${pkgdir}${MINGW_PREFIX}/include/
  cp -pf ${srcdir}/${_realname}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname
}
