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

setvar _luaversions = ""5.1 5.2""

setvar pkgname = 'lua-zmq'
setvar pkgver = '1.1_git20130709'
setvar _ver = ${pkgver%_git*}
setvar pkgrel = '2'
setvar pkgdesc = ""Lua zeromq2 binding""
setvar url = ""https://github.com/Neopallium/lua-zmq""
setvar arch = """"
setvar license = ""MIT""
setvar makedepends = ""zeromq-dev cmake""
for _i in $_luaversions {
	setvar makedepends = ""$makedepends lua$_i-dev""
	setvar subpackages = ""$subpackages lua$_i-zmq:split_${_i/./_}""
}
setvar install = """"
setvar source = ""$pkgname-$_ver.tar.gz::https://github.com/Neopallium/lua-zmq/archive/v$_ver.tar.gz
	git-${pkgver##*_git}.patch""

setvar _sdir = ""$srcdir"/lua-zmq-$_ver"

proc prepare {
	local i
	cd $_sdir
	for i in $source {
		case (i) {
		*.patch { msg $i; patch -p1 -i "$srcdir"/$i || return 1}
		}
	}
	for _i in $_luaversions {
		mkdir -p "$srcdir"/build-$_i || return 1
	}
}

proc build {
	for _i in $_luaversions {
		cd "$srcdir"/build-$_i
		msg "build for Lua $_i""
		CFLAGS="$CFLAGS $(pkg-config --cflags lua$_i)"" cmake \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DINSTALL_CMOD=/usr/lib/lua/$_i \
			-DINSTALL_LMOD=/usr/share/lua/$_i \
			$_sdir || return 1
		make || return 1
	}
}

proc package {
	for _i in $_luaversions {
		cd "$srcdir"/build-$_i
		make install DESTDIR="$pkgdir" || 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 = ""lua$_ver-llthreads""
	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 = ""cb4df81b4c884bf97bf6add88fcfa58d  lua-zmq-1.1.tar.gz
e68a07c32d77fbea78165d6ae49027cb  git-20130709.patch""
setvar sha256sums = ""f2bdf3142b744971da4eb8bdb12020a34b62f8ba384be44d8448b4ef05ec3dcc  lua-zmq-1.1.tar.gz
f0266865ac2ebc10e74877686e8536caec88db286408170b22543243235fa608  git-20130709.patch""
setvar sha512sums = ""35d7da6215a96b80ea59b52591082473d2c54bcb9577ae95ead1235de894d5ef226b6c4e3030c327b2b146e07af6b3998d91c5b520dfb35e87c85e958069362d  lua-zmq-1.1.tar.gz
c9080a53b3f6f63a03bc105fc2d49bdf664fccfdcd35414f21972cee30db466744024727418491dbff6ac845186e1b77f684832ccbbf0c209759303ede8150bb  git-20130709.patch""