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

inherit games eutils git autotools

EGIT_REPO_URI="git://gitorious.org/crawl/crawl.git"

DESCRIPTION="a fun, free rogue-like game of exploration and
treasure-hunting in dungeons filled with dangerous and unfriendly monsters in a
quest for the mystifyingly fabulous Orb of Zot."
HOMEPAGE="http://crawl-ref.sourceforge.net/"

LICENSE="crawl"
SLOT="0"
KEYWORDS="~x86"
IUSE="tiles"

DEPEND="sys-libs/ncurses
	tiles? ( media-gfx/pngcrush app-arch/advancecomp )"
RDEPEND="sys-libs/ncurses dev-lang/lua \
	>=dev-db/sqlite-3 sys-devel/bison \
	sys-devel/flex sys-libs/zlib \
	dev-util/pkgconfig \
	>=media-libs/sdl-image-1.2 >=media-libs/libsdl-1.2 \
	media-libs/freetype"

S="${WORKDIR}"

src_unpack() {
	git_src_unpack
}

src_compile() {
	cd crawl-ref/source
	if use tiles; then
		emake ARCH= DATADIR=/usr/share/games/crawl-data TILES=y || die "emake failed"
	else
		emake ARCH= DATADIR=/usr/share/games/crawl-data || die "emake failed"
	fi
}

src_install() {
	cd crawl-ref/source
	dogamesbin crawl || die "installing the binary failed"
	dodir ${GAMES_DATADIR}/crawl-data
	dodir ${GAMES_STATEDIR}/crawl-saves
	dodir ${GAMES_DATADIR}/crawl-data/settings
	dodir ${GAMES_DATADIR}/crawl-data/docs
	cp -r dat ${D}${GAMES_DATADIR}/crawl-data
	cd ..
	cp -r docs ${D}${GAMES_DATADIR}/crawl-data
	cp -r settings ${D}${GAMES_DATADIR}/crawl-data
	dodoc CREDITS README.txt
	cd docs
	dodoc crawl_manual.txt
	doman crawl.6

	prepgamesdirs

	fperms 770 "${GAMES_STATEDIR}/crawl-saves" || die "fparms failed"
}