# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
setvar _luaversions = ""5.1 5.2 5.3""
setvar pkgname = ""lua-md5""
setvar _name = ""md5""
setvar pkgver = '1.2'
setvar pkgrel = '3'
setvar pkgdesc = ""Basic cryptographic facilities for Lua""
setvar url = ""https://github.com/keplerproject/md5""
setvar arch = ""all""
setvar license = ""MIT""
setvar depends = """"
setvar makedepends = """"
setvar subpackages = """"
for _i in $_luaversions {
	setvar makedepends = ""$makedepends lua$_i-dev""
	setvar subpackages = ""$subpackages lua$_i-md5:split_${_i/./_}""
}
setvar source = ""lua-md5-$pkgver.tar.gz::https://github.com/keplerproject/md5/archive/v$pkgver.tar.gz""

setvar _sdir = ""$srcdir"/md5-$pkgver"
proc prepare {
	cd $_sdir
	sed -i -e "s:^PREFIX.*=.*:PREFIX =/usr:" \
		config || return 1
	rm src/*.o

	for _i in $_luaversions {
		cp -r $_sdir "$srcdir"/build-$_i
		sed -i -e "s/5.1/$_i/" "$srcdir"/build-$_i/config || return 1
	}
}

proc build {
	for _i in $_luaversions {
		cd "$srcdir"/build-$_i
		make CFLAGS="$CFLAGS $(pkg-config --cflags lua$_i)" || return 1
	}
}

proc package {
	for _i in $_luaversions {
		cd "$srcdir"/build-$_i
		make PREFIX="$pkgdir"/usr install
	}
}

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

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

setvar md5sums = ""c166f8a983401802a86655a8c733441e  lua-md5-1.2.tar.gz""
setvar sha256sums = ""3c016da2cf0cfeb5dfdcf3bea82b64935c4faa6eec32ae164c48d870b4583ffa  lua-md5-1.2.tar.gz""
setvar sha512sums = ""1d0925351b4b774581f78147b7dd44df649eec2bc8397db991149feaf1f16c8f26d4b0fce6d8463be656115cebf605339ba8da851bc50d1ae1da8033d4ed564d  lua-md5-1.2.tar.gz""