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

EAPI=2
if [ "$PV" == "9999" ]; then
	# The package uses AM_SILENT_RULES which is only available in automake
	# 1.11 and later.
	WANT_AUTOMAKE="1.11"
	SRC_URI=""
	EGIT_REPO_URI="git://git.assembla.com/frobtads.git"
	KEYWORDS=""
	inherit autotools git-2
fi
inherit flag-o-matic games

DESCRIPTION="Curses-based interpreter and development tools for TADS 2 and TADS 3 text adventures"
HOMEPAGE="http://www.tads.org/frobtads.htm"
if [ "$PV" != "9999" ]; then
	SRC_URI="http://www.tads.org/frobtads/${P}.tar.gz"
	KEYWORDS="~amd64 ~x86"
fi
LICENSE="TADS2 TADS3"
SLOT="0"
RESTRICT="!tads3compiler? ( test )"
IUSE="debug +tads2compiler +tads3compiler"

DEPEND="sys-libs/ncurses
	net-misc/curl"
RDEPEND="${DEPEND}"

src_unpack() {
	if [ "${PV}" == "9999" ]; then
		git-2_src_unpack
		cd "${S}"
		einfo "Regenerating autotools files..."
		eautoreconf
	else
		base_src_unpack
	fi
}

src_configure() {
	egamesconf \
		$(use_enable debug t3debug) \
		$(use_enable tads2compiler t2-compiler) \
		$(use_enable tads3compiler t3-compiler) \
		|| die "egamesconf failed"
}

src_test() {
	#if use debug; then
	#	emake check || die "TADS 3 compiler test suite failed"
	#fi

	emake sample || die "Failed to build test game"
	./frob -i plain -p samples/sample.t3 <<- END_FROB_TEST
		save
		testsave.sav
		restore
		testsave.sav
	END_FROB_TEST
	[[ $? -eq 0 ]] || die "Failed to run test game"
}

src_install() {
	emake DESTDIR="${D}" install || die "emake install failed"
	dodoc doc/{AUTHORS,BUGS,NEWS,README,SRC_GUIDELINES,THANKS}
	prepgamesdirs
}