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

EAPI=5

inherit eutils games

DESCRIPTION="A side scrolling beat 'em up with a comic book art style"
HOMEPAGE="http://www.shankgame.com/"

SRC_URI="${PN}-linux-update${PV}.tgz"

RESTRICT="fetch bindist"
LICENSE="all-rights-reserved"

SLOT="0"
KEYWORDS="-* ~amd64 ~x86"
IUSE="bundled-libs joystick"

RDEPEND="media-libs/alsa-lib
	virtual/glu
	virtual/opengl
	x11-libs/libICE
	x11-libs/libSM
	x11-libs/libX11
	x11-libs/libXau
	x11-libs/libXdmcp
	x11-libs/libXext
	x11-libs/libXi
	x11-libs/libXmu
	x11-libs/libXt
	x11-libs/libxcb
	!bundled-libs? (
		=media-libs/libsdl-1.2*[joystick?,video]
	)"

	# Needs newer version of fmod w/ libfmodevent64.so, but newer version
	# breaks Bastion (see bug 453748 for newer fmod)
	#>=media-libs/fmod-4.44.04

	# Requires older version that's no longer in portage
	#media-libs/glew

S="${WORKDIR}"

GAMEDIR="${GAMES_PREFIX_OPT}/${PN}"

QA_PREBUILT="${GAMEDIR:1}/bin/*"
QA_PRESTRIPPED="${GAMEDIR:1}/bin/lib32/*
	${GAMEDIR:1}/bin/lib64/*"

pkg_nofetch() {
	einfo "Please buy and download '${SRC_URI}'"
	einfo "and move/link it to '${DISTDIR}'"
	einfo
}

src_install() {
	use amd64 && local BITS=64 || local BITS=32

	# install data
	insinto "${GAMEDIR}"
	doins -r data data-pc

	# install binaries
	exeinto "${GAMEDIR}/bin"
	doexe bin/${PN}-bin${BITS}

	# install libraries
	exeinto "${GAMEDIR}/bin/lib${BITS}"
	doexe bin/lib${BITS}/lib{GLEW,fmod}*
	use bundled-libs && doexe bin/lib${BITS}/lib{SDL,direct,fusion,vga,x86}*

	# install documentation
	dodoc release_notes.txt

	# install shortcuts
	newicon Shank2.xpm ${PN}
	games_make_wrapper "${PN}" "./${PN}-bin${BITS}" "${GAMEDIR}/bin" "${GAMEDIR}/bin/lib${BITS}"
	make_desktop_entry "${PN}" "Shank 2"

	prepgamesdirs
}

pkg_postinst() {
	games_pkg_postinst

	elog "Saved games and settings are stored in:"
	elog "~/.klei/shank2/"
}