# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=tolua
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.4
pkgrel=4
pkgdesc="A tool that greatly simplifies the integration of C/C++ code with Lua (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.tecgraf.puc-rio.br/~celes/tolua/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-lua")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=(https://www.tecgraf.puc-rio.br/~celes/tolua/${_realname}-${pkgver}.tar.gz)
sha256sums=('c5a6b701b3ced9a66e7a9881c9d94430f8612040827650abe1aa3c5c3fc95bf2')

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}"  
  cd "${srcdir}/build-${MSYSTEM}"
  sed -i "s|LUA=/usr/local|LUA=${MINGW_PREFIX}|g" config
  make -j1 \
    AR="ar rcu" \
    RANLIB="ranlib" \
    STRIP="strip" \
    CC="${CC}"
}

package(){
  cd "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${pkgdir}"${MINGW_PREFIX}/{bin,lib,include}
  cp bin/*.exe "${pkgdir}"${MINGW_PREFIX}/bin/
  cp lib/*.a "${pkgdir}"${MINGW_PREFIX}/lib/
  cp include/*.h "${pkgdir}"${MINGW_PREFIX}/include/
}
