# Contributor: Guilherme Felipe da Silva <gfsilva.eng@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=lua-ansicolors
_rockname="${pkgname#lua-}"
pkgver=1.0.2
pkgrel=2
pkgdesc="ANSI terminal color manipulation for Lua"
url="https://github.com/kikito/ansicolors.lua"
license="MIT"
arch="all"
makedepends="luarocks"
options="!check" # Test dependencies not available
source="$_rockname-$pkgver.tar.gz::https://github.com/kikito/$_rockname.lua/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_rockname.lua-$pkgver"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		luarocks-$lver \
			LUA_INCDIR="$(pkg-config --variable=includedir lua$lver)" \
			LUA_LIBDIR="$(pkg-config --variable=libdir lua$lver)" \
			make --tree="./build" \
			--deps-mode=none \
			"$_rockname-${pkgver%??}-1.rockspec"

		rm "./build/lib/luarocks/rocks-$lver/manifest"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	local path; for path in "lib/luarocks/rocks-$lver" "share/lua/$lver"; do
		mkdir -p "$subpkgdir/usr/${path%/*}"
		mv "$builddir/build/$path" "$subpkgdir/usr/$path/"
	done
}

sha512sums="
d7052fc63ec09076c0fa940f506fa06ebd210cf590f35310a21c80062cbf062b6d2607c3f89b8dbb39377793e25ea11f471101913e620a7566957e7ed7efbb04  ansicolors-1.0.2.tar.gz
"
