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

EAPI="4"

inherit linux-mod

DESCRIPTION="Kernel module to create webcamstudio's virtual webcam loopback device"
HOMEPAGE="https://github.com/umlaeute/v4l2loopback"
SRC_URI="https://github.com/umlaeute/v4l2loopback/tarball/v${PV} -> ${P}.tar.gz"

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

DEPEND=""
RDEPEND="${DEPEND}"

S="${WORKDIR}"/umlaeute-v4l2loopback-dd9ea64

pkg_setup() {
	linux-mod_pkg_setup
	CONFIG_CHECK="VIDEO_DEV"
	MODULE_NAMES="webcamstudio(video:)"
	BUILD_TARGETS="all"
}

src_prepare() {
	if use modules; then
		epatch "${FILESDIR}/${P}-webcamstudio.patch"
		sed -e "s:\$(KERNEL_DIR):${KV_DIR}:" \
			-i Makefile || die
		set_arch_to_kernel
	fi
}

src_compile() {
	if use modules; then
		einfo "Compile kernel module"
		mv v4l2loopback.c webcamstudio.c || die
		linux-mod_src_compile
	fi
}

src_install() {
	use modules && linux-mod_src_install
}

pkg_postinst() {
	use modules && linux-mod_pkg_postinst
}