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

EAPI=5

inherit eutils toolchain-funcs

MY_P="${PN}v${PV/\./}"

DESCRIPTION="Compiler (C++ emitter) with an editor (IDE) that strives for 100% Qbasic and QuickBasic 4.5 compatibility"
HOMEPAGE="http://www.qb64.net"
SRC_URI="http://www.qb64.net/${MY_P}-lnx.tar.gz"

LICENSE="freedist"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="midi"

DEPEND="media-libs/libsdl[X,joystick,video]
	media-libs/sdl-mixer
	media-libs/sdl-image
	media-libs/sdl-net
	media-libs/sdl-ttf
	x11-libs/libX11
	midi? ( media-sound/timidity++ )"
RDEPEND="${DEPEND}"

S="${WORKDIR}/${PN}"

src_prepare() {
	epatch_user

	cp "internal/source/"* "internal/temp" || die 'sources preparation failed'
}

src_compile() {
	my_compile() {
		echo "$(tc-getCXX) $*"
		$(tc-getCXX) $*
	}
	pushd "internal/c" &>/dev/null || die "can not change directory to ${S}/internal/c"
	my_compile "${CFLAGS}" "${LDFLAGS}" libqbx.cpp qbx.cpp -lSDL_mixer -lSDL_ttf -lSDL_net -lSDL_image -lX11 `sdl-config --libs --cflags` -o ${PN} || die "creating executable failed"
	popd &>/dev/null
}

src_install() {
	doexe "internal/c/${PN}"
	insinto "/usr/share/${PN}"
	doins readme.txt audio.txt
	doins -r samples
}