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

inherit games

MY_PN="PossibleWorlds"
MY_PNS="psworlds"

DESCRIPTION="Subwar/Wing Commander-style submarine game"
HOMEPAGE="http://possibleworlds.sourceforge.net/"
SRC_URI="mirror://sourceforge/${PN}/${MY_PNS}-src.zip
	mirror://sourceforge/${PN}/${MY_PNS}-media.zip"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86"
IUSE=""
DEPEND=">=libsdl-1.2.0*
	virtual/opengl
	virtual/x11"
#also uses fmod 3.33 (no longer available from the fmod site)
#which comes in psworlds-src.zip

S=${WORKDIR}/${MY_PN}/${MY_PNS}/source

src_compile() {
	#warnings maybe ought to be supressed

	#edit makefile to use user cflags
	sed -i s/"CFLAGS :="/"CFLAGS := ${CFLAGS}"/ ${S}/Makefile \
		|| die "sed cflag edit failed"

	#edit makefile to use a config file in /etc/games
	sed -i s%"possible_config.txt"%"${GAMES_SYSCONFDIR}/possibleworlds.conf"% \
		${S}/psworlds.cpp || die "sed config file edit failed"
	emake || die "emake failed"
}

src_install() {
	cd ${WORKDIR}/${MY_PN}

	#fmod library
	dolib.so fmod/libfmod-3.33.so

	#data directory
	dodir ${GAMES_DATADIR}/${PN}

	#binary into data dir
	exeinto ${GAMES_DATADIR}/${PN}
	newexe ${MY_PNS}/${MY_PNS}-linux ${PN}

	#documentation
	dohtml -r Docs/*
	newdoc README.TXT README
	newdoc MISC.TXT MISC

	#data files
	cd ${MY_PNS}
	cp -r gfx missions objx save sfx "${D}/${GAMES_DATADIR}/${PN}/" \
		|| die "cp data files failed"

	#config file
	insinto ${GAMES_SYSCONFDIR}
	newins possible_config.txt ${PN}.conf

	#gamesy stuff
	games_make_wrapper ${PN} ${GAMES_DATADIR}/${PN}/${PN} ${GAMES_DATADIR}/${PN}
	prepgamesdirs
}