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

ETYPE="sources"
K_WANT_GENPATCHES="base extras"
K_GENPATCHES_VER="3"
IUSE="ultra1 reiser4 rr232x"
RDEPEND="${RDEPEND}
	reiser4? ( sys-fs/reiser4progs )"
inherit kernel-2
detect_version
detect_arch

KEYWORDS="amd64 x86"
HOMEPAGE="http://gentoo-wiki.com/HOWTO_Reiser4_With_Gentoo-Sources"

DESCRIPTION="Full sources including the gentoo patchset for the
${KV_MAJOR}.${KV_MINOR} kernel tree and the reiser4 patchset from namesys"
SRC_URI="${KERNEL_URI} ${GENPATCHES_URI} ${ARCH_URI}"

R4V="-3"
R4_URI="ftp://ftp.namesys.com/pub/reiser4-for-${KV_MAJOR}.${KV_MINOR}/${PV}/reiser4-for-${PV}${R4V}.patch.gz"

RR232X_VER="1.03"
RR232X_DATE="060710"
RR232X_URI="http://www.highpoint-tech.com/BIOS_Driver/rr2320/Linux/rr232x-linux-src-${RR232X_VER}-${RR232X_DATE}.tar.gz"

if use reiser4; then
	SRC_URI="${SRC_URI} ${R4_URI}"
	UNIPATCH_LIST="${DISTDIR}/reiser4-for-${PV}${R4V}.patch.gz"
fi

if use rr232x; then
	SRC_URI="${SRC_URI} ${RR232X_URI}"
fi

src_unpack() {
	kernel-2_src_unpack
	if use rr232x; then
		OLD_PWD=${PWD}
		cd ..
		unpack rr232x-linux-src-${RR232X_VER}-${RR232X_DATE}.tar.gz || die "unable to unpack rocket raid drivers"
		cd ${WORKDIR}/rr232x-linux-src-${RR232X_VER}/product/rr232x/linux/ || die "unable to find directory for rr232x driver"
		make patchkernel KERNELDIR=${OLD_PWD} KERNEL_VER="${KV_MAJOR}.${KV_MINOR}" || die "unable to patch kernel with rocket raid driver rr232x"
#/usr/src/linux-${PV}-aylward-${KV_PATCH}
		cd ${OLD_PWD}
	fi
}

pkg_postinst() {
        postinst_sources

 	if use reiser4; then
	        echo

		einfo "For more info on the reiser4 patchset, see:"
		einfo "${HOMEPAGE}"
	fi
}