# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=5

[[ "${PV}" = *9999* ]] && live=git-r3
inherit toolchain-funcs ${live}

DESCRIPTION="An extended Lua macro preprocessor"
HOMEPAGE="http://stevedonovan.github.io/LuaMacro"
if [[ "${PV}" = *9999* ]] ; then
	EGIT_REPO_URI="https://github.com/stevedonovan/${PN}.git"
	KEYWORDS="-*"
else
	SRC_URI="https://github.com/stevedonovan/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
	KEYWORDS="~amd64"
fi

LICENSE="MIT"
SLOT="0"

IUSE="luajit"

DEPEND="!luajit? ( || ( dev-lang/lua:5.1 >=dev-lang/lua-5.1:0 ) )
	luajit? ( dev-lang/luajit:2 )"
RDEPEND="${DEPEND}
	dev-lua/lpeg"

DOCS=( "readme.md" )

src_install() {
	local lua=lua pkg_config="$(tc-getPKG_CONFIG)" lua_prefix lua_bindir lua_sharedir
	use luajit && lua=luajit

	lua_prefix="$(${pkg_config} --variable prefix ${lua})"
	lua_bindir="$(${pkg_config} --variable INSTALL_BIN ${lua})"
	lua_sharedir="$(${pkg_config} --variable INSTALL_LMOD ${lua})"

	[[ "${lua_bindir}" ]] || lua_bindir="${lua_prefix}/bin"

	exeinto "${lua_bindir}"
	doexe luam

	insinto "${lua_sharedir}"
	doins -r macro
	doins macro.lua
}