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

setvar _luaversions = ""5.1 5.2 5.3""

setvar pkgname = 'lua-filesystem'
setvar pkgver = '1.6.3'
setvar pkgrel = '0'
setvar pkgdesc = ""Filesystem functions for Lua""
setvar url = ""http://keplerproject.github.io/luafilesystem/""
setvar arch = ""all""
setvar license = ""GPL""
setvar depends = """"
setvar install = ''

setvar makedepends = """"
setvar subpackages = """"
for _i in $_luaversions {
	setvar makedepends = ""$makedepends lua$_i-dev""
	setvar subpackages = ""$subpackages lua$_i-filesystem:split_${_i/./_}""
}
setvar source = ""luafilesystem-$pkgver.tar.gz::https://github.com/keplerproject/luafilesystem/archive/v_${pkgver//./_}.tar.gz""

setvar _sdir = ""$srcdir"/luafilesystem-v_${pkgver//./_}"

proc prepare {
	cd $_sdir
	# apply patches here
	cd $srcdir
	for _i in $_luaversions {
		cp -r $_sdir "$srcdir"/build-$_i
	}
}

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

proc package {
	for _i in $_luaversions {
		cd "$srcdir"/build-$_i
		make LUA_LIBDIR="$pkgdir"/usr/lib/lua/$_i install \
			|| return 1
	}
}

proc _split {
	local d= _ver=$1
	setvar pkgdesc = ""Filesystem functions 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 = ""d0552c7e5a082f5bb2865af63fb9dc95  luafilesystem-1.6.3.tar.gz""
setvar sha256sums = ""5525d2b8ec7774865629a6a29c2f94cb0f7e6787987bf54cd37e011bfb642068  luafilesystem-1.6.3.tar.gz""
setvar sha512sums = ""abfa1b3ac22ed80189560a1a025a7ea21a954defe14e5b539e08f266d180962a691262efc7eb2ddacc2d4aae14d6e356b1a276165b5bed46a13e4d6c61ab99f1  luafilesystem-1.6.3.tar.gz""