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

EAPI=5

inherit eutils linux-info

DESCRIPTION="Psmouse kernel module with support for alpsv1-alpsv6 touchpad"
HOMEPAGE="http://www.dahetral.com/"
SRC_URI="http://www.dahetral.com/public-download/psmouse-alps-dst-${PV}.tbz/at_download/file -> psmouse-alps-dst-${PV}.tbz"
 
S=${ROOT}

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

RDEPEND="sys-kernel/linux-headers"
DEPEND="${RDEPEND}
	sys-kernel/dkms"

pkg_postinst() {
	if [ "${get_running_version}" = "3.0" ]; then
		echo "Patching for a 3.0 LTS kernel..."
		sed -e 's/BTN_TOOL_QUINTTAP/0x148/g' \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/synaptics.c || die "sed failed"
	fi

	if [ "${get_running_version}" = "3.7" ]; then
		echo "Patching for a 3.7 kernel..."
		# Many thanks to figue for the quick patch ;)
		sed -e 's/input_mt_init_slots(dev, 2);/input_mt_init_slots(dev, 2, 0);/g' \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/synaptics.c \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/alps.c \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/elantech.c \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/sentelic.c || die "sed failed"
		sed -e 's/input_mt_init_slots(dev1, 2);/input_mt_init_slots(dev1, 2, 0);/g' \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/synaptics.c \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/alps.c || die "sed failed"
		sed -e 's/input_mt_init_slots(dev, ETP_MAX_FINGERS);/input_mt_init_slots(dev, ETP_MAX_FINGERS, 0);/g' \
		  -i ${S}/usr/src/psmouse-alps-dst-${PV}/src/elantech.c || die "sed failed"
	fi

    dodir ${S}/usr/src/dkms/src
    doins ${S}/usr/src/psmouse-alps-dst-${PV}/src/* ${S}/usr/src/dkms/src
    doins ${S}/usr/src/psmouse-alps-dst-${PV}/dkms.conf ${S}/usr/src/dkms
}