# Maintainer: Ricky Wu <rickleaf.wu@gmail.com>
# Contributor: ImperatorS79 <fevrier.simon@gmail.com>
# Contributoor: Ray Donnelly <mingw.android@gmail.com>

_realname=luarocks
pkgbase=mingw-w64-lua-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-lua-${_realname}")
pkgver=3.12.2
pkgrel=1
pkgdesc="the package manager for Lua modules (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://luarocks.org"
msys2_references=(
  'archlinux: luarocks'
)
license=("spdx:MIT")
depends=("${MINGW_PACKAGE_PREFIX}-lua"
         "unzip"
         "zip")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
install=${_realname}-${MSYSTEM}.install
source=("https://luarocks.org/releases/${_realname}-${pkgver}.tar.gz"
        "0001-luarocks_msys2_mingw_w64.patch")
sha256sums=('b0e0c85205841ddd7be485f53d6125766d18a81d226588d2366931e9a1484492'
            '48e2e8c9cd1eaf7f18b38c25d474a4cd39dddb88b92152e278d04dffdcda2a90')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-luarocks_msys2_mingw_w64.patch
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./configure --prefix=${MINGW_PREFIX} --lua-version=5.4 --with-lua-interpreter=lua.exe
  make ./build/luarocks ./build/luarocks-admin ./build/config-5.4.lua
  make LUA_VERSION=5.1 LUA_INTERPRETER=lua5.1.exe LUA_INCDIR=${MINGW_PREFIX}/include/lua5.1 ./build/config-5.1.lua
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
  make DESTDIR="$pkgdir" LUA_VERSION=5.1 install-config
}
