# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

setvar _luaversions = ""5.1 5.2 5.3""
setvar pkgname = 'lua-stringy'
setvar pkgver = '0.4.0'
setvar pkgrel = '5'
setvar pkgdesc = ""Lua string utility library""
setvar url = ""https://github.com/brentp/lua-stringy/""
setvar arch = ""all""
setvar license = ""MIT""
setvar depends = """"
setvar makedepends = """"
setvar install = """"
setvar subpackages = """"
setvar source = ""lua-stringy-$pkgver.tar.gz::https://github.com/brentp/lua-stringy/archive/v$pkgver.tar.gz""

for _v in $_luaversions {
	setvar makedepends = ""$makedepends lua$_v lua$_v-dev""
	setvar subpackages = ""$subpackages lua$_v-stringy:split_${_v/./_}""
}


setvar _builddir = ""$srcdir"/lua-stringy-$pkgver/stringy"
proc prepare {
	local i
	cd $_builddir
	for i in $source {
		case (i) {
		*.patch { msg $i; patch -p2 -i "$srcdir"/$i || return 1}
		}
	}
}

proc build {
	cd $_builddir
	for _v in $_luaversions {
		make CC="${CC:-gcc}" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
			LUA_PC="lua$_v" LUA="lua$_v" || return 1
		mv stringy.so stringy.so.$_v
		make clean
	}
}

proc package {
	local d
	cd $_builddir
	for _v in $_luaversions {
		setvar d = "$pkgdir/usr/lib/lua/$_v"
		mkdir -p $d || return 1
		cp stringy.so.$_v "$d/stringy.so"
	}
}

proc _split {
	local d=usr/lib/lua _ver=$1
	setvar pkgdesc = ""$pkgdesc for Lua $_ver""
	setvar install_if = ""lua$_ver $pkgname=$pkgver-r$pkgrel""
	setvar depends = ''
	mkdir -p "$subpkgdir/$d" || return 1
	mv "$pkgdir/$d/$1" "$subpkgdir/$d"
}

for _v in $_luaversions {
	eval "split_${_v/./_}() { _split $_v; }"
}


setvar md5sums = ""00a3bb395cc91b597df7d7931c226c47  lua-stringy-0.4.0.tar.gz""
setvar sha256sums = ""ec4a97a9d0294b8b2df6b5d94576414c4f29e782c4ef7ac6fcff07cd73757e3c  lua-stringy-0.4.0.tar.gz""
setvar sha512sums = ""909a0d6da308ed97d394b953456446151476a27a122fca503187f13f61a71d94ee3561a179c7d5307db517a31eaaa5b58b53d5abaa6912da3d46fc0dbb3dcc6c  lua-stringy-0.4.0.tar.gz""