# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-util/bnfc/bnfc-2.4.2.0.ebuild,v 1.4 2014/08/10 21:25:29 slyfox Exp $

# ebuild generated by hackport 0.2.11

EAPI=4

CABAL_FEATURES="bin"
inherit eutils haskell-cabal

MY_PN="BNFC"
MY_P="${MY_PN}-${PV}"

DESCRIPTION="A compiler front-end generator"
HOMEPAGE="http://www.cse.chalmers.se/research/group/Language-technology/BNFC/"
SRC_URI="mirror://hackage/packages/archive/${MY_PN}/${PV}/${MY_P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ppc ~x86"
IUSE=""

RDEPEND=""
DEPEND="${RDEPEND}
		>=dev-haskell/cabal-1.2
		dev-haskell/mtl
		>=dev-lang/ghc-6.10.1"

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

src_prepare() {
	# get rid of haskell98 to be ghc-7.4 compatible
	sed -i ${MY_PN}.cabal -e 's/haskell98,//' || die
	local hs
	find . -type f -name '*.hs' | while read hs; do
		einfo "Mangling $hs"
		sed -i "$hs"\
			-e 's/^import \<Array\>/import Data.Array/g' \
			-e 's/^import \<Directory\>/import System.Directory/g' \
			-e 's/^import \<IO\>/import System.IO/g' \
			-e 's/^import \<Maybe\>/import Data.Maybe/g' \
			-e 's/^import \<Monad\>/import Control.Monad/g' \
			-e 's/^import \<List\>/import Data.List/g' \
			-e 's/^import \<Char\>/import Data.Char/g' \
			-e 's/^import \<System\>\s*$/import System.Exit\nimport System.Environment\n/g' \
			|| die
	done
	epatch "${FILESDIR}"/${P}-mangle-errors.patch # yes, built on top of mangled sources above
}