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

inherit flag-o-matic

MY_P="ws-v${PV}"
DESCRIPTION="WideStudio is an integrated development environment(IDE) to build"
HOMEPAGE="http://www.widestudio.org/"
SRC_URI="http://www.widestudio.org/${MY_P}-src.tar.gz"
#SRC_URI="mirror://sourceforge/widestudio/${MY_P}-src.tar.gz"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="X directfb fbcon java jpeg mysql ocaml odbc perl png postgres python ruby"

DEPEND="X? ( virtual/x11 )
	java? ( >=virtual/jdk-1.4.2 )
	jpeg? ( media-libs/jpeg )
	png? ( media-libs/libpng )
	odbc? ( dev-db/unixODBC )
	postgres? ( dev-db/libpq )
	mysql? ( dev-db/mysql )
	python? ( dev-lang/python )
	ruby? ( dev-lang/ruby )
	perl? ( dev-lang/perl )
	ocaml? ( >=dev-lang/ocaml-3.08.2 )"

S="${WORKDIR}/${MY_P/.1/-}1"

src_unpack() {
	unpack ${A}
	cd "${S}"

	sed -i -e "s|^\(WS_INST_DIR =\).*$|\1 /usr|" \
		-e "s|^\(WS_DEFAULT_DIR =\).*$|\1 /opt/ws|" \
		-e "s|-O2|${CFLAGS}|" \
		sys/config/mkflags.linux || die

	if use java; then
		sed -i -e "s|^\(JAVA_HOME =\).*$|\1 $(java-config --jdk-home)|" \
			sys/config/mkflags.linux || die
	fi
}

src_compile() {
	./configure linux || die
	emake || die

	cd "${S}"/src
	if use java; then
		emake java || die
	fi

	if use fbcon; then
		emake devfb || die
	fi

	if use directfb; then
		emake directfb || die
	fi

	if use ocaml; then
		emake ocaml || die
	fi
}

src_install() {
	dodir /opt/ws
	dodir /usr/bin /usr/lib
	make WS_TARGET_DIR="${D}" install || die

	insinto /etc/env.d
	doins "${FILESDIR}"/50widestudio || die
}