# 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/swc"
DESCRIPTION="Small Wayland compositor implemented as a library"
HOMEPAGE="https://github.com/michaelforney/swc"
LICENSE="MIT"
SLOT="0"
KEYWORDS=""
IUSE="debug examples static-libs xwayland"
RDEPEND="dev-libs/wld
	x11-libs/libdrm
	dev-libs/libevdev
	dev-libs/libinput
	dev-libs/wayland
	x11-libs/libxkbcommon
	x11-libs/pixman
	xwayland? (
		x11-base/xorg-server[wayland]
		x11-libs/libxcb
	)"

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 xwayland || config_0 ENABLE_XWAYLAND
	epatch_user
}

src_compile() {
	default
	use examples && emake example
}

src_install() {
	default
	use examples && dobin example/wm
}