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

EAPI=5
inherit eutils git-r3
EGIT_REPO_URI="https://github.com/michaelforney/wld"
DESCRIPTION="A primitive drawing library targeted at Wayland"
HOMEPAGE="https://github.com/michaelforney/wld"
LICENSE="MIT"
SLOT="0"
KEYWORDS=""
IUSE="debug drm static-libs video_cards_intel video_cards_nouveau"
REQUIRED_USE="video_cards_intel? ( drm )
	video_cards_nouveau? ( drm )"
RDEPEND="x11-libs/pixman
	media-libs/fontconfig
	video_cards_intel? ( x11-libs/libdrm[video_cards_intel] )
	video_cards_nouveau? ( x11-libs/libdrm[video_cards_nouveau] )"

sed_config(){
	sed -i -e "$1" config.mk || die "sed_config failed: $1"
}

config_0() {
	sed_config "s/$1\s*=\s*1/$1=0/"
}


src_prepare() {
	sed_config "/^CFLAGS/d"
	sed_config "1aPREFIX=\/usr"
	use debug || config_0 ENABLE_DEBUG
	use static-libs || config_0 ENABLE_STATIC
	use drm || config_0 ENABLE_DRM
	for v in intel nouveau; do
		use video_cards_$v || sed_config "s/^\(DRM_DRIVERS\s*=\)\s*$v/\1/"
	done
	epatch_user
}