# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3"
pkgname=lua-feedparser
_name=feedparser
pkgver=0.71
pkgrel=0
pkgdesc="A decent RSS and Atom XML feed parser"
url="https://github.com/slact/lua-feedparser"
arch="noarch"
license="BSD"
depends=""
depends_dev=""
makedepends="$depends_dev"
install=""
subpackages="$pkgname-common"

for _i in $_luaversions; do
	makedepends="$makedepends lua${_i}-dev"
	subpackages="$subpackages lua${_i}-$_name:_split${_i/./}"
done

source="lua-feedparser-$pkgver.tar.gz::https://github.com/slact/lua-feedparser/archive/$pkgver.tar.gz"

_builddir="$srcdir"/lua-feedparser-$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	return 0
}

package() {
	cd "$_builddir"
	mkdir -p "$pkgdir"/usr/share/lua/common
	make LUA_DIR="$pkgdir"/usr/share/lua/common install || return 1
}

common() {
	depends=
	mkdir -p "$subpkgdir"
	mv "$pkgdir"/usr "$subpkgdir"/
}

_split() {
	pkgdesc="$pkgdesc for Lua $1"
	depends="lua$1-expat lua-feedparser-common"
	install_if="lua$1 $pkgname=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"/usr/share/lua/$1
	ln -s ../common/feedparser "$subpkgdir"/usr/share/lua/$1/
	ln -s ../common/feedparser.lua "$subpkgdir"/usr/share/lua/$1/
}

for _i in $_luaversions; do
	eval "_split${_i/./}() { _split $_i; }"
done

md5sums="a34ffbcfe3fc6a7d62ccb9e162d1dc85  lua-feedparser-0.71.tar.gz"
sha256sums="053abade5004b057ca10e4adec0f8fc6f299faf3f668ae999c3b6c55784f29f9  lua-feedparser-0.71.tar.gz"
sha512sums="8a65947b5472321fc162ec325c31e4d92e52e6cba6952c01c9941a7596403ed495ee464bfc32f5fdda3c58d33fae3a3b38882f7f22ecc16360c6603cd7ab4d4d  lua-feedparser-0.71.tar.gz"
