EAPI="4"
ETYPE="sources"
UNIPATCH_STRICTORDER="yes"
K_SECURITY_UNSUPPORTED="1"

inherit kernel-2
detect_version
detect_arch

DESCRIPTION="Full sources including the Gentoo patchset, ureadahead, AUFS3 & BFQ for the ${KV_MAJOR}.${KV_MINOR} kernel tree"
KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~sh ~sparc ~x86"
HOMEPAGE="http://www.asiotec.eu.org/projects-regen2-kernel.html"
IUSE="hardened"

REGEN2_HARDEN_PATCH="regen2-harden-patches-${PV}.tar.xz"
REGEN2_KERNEL_PATCH="regen2-kernel-patches-${PV}.tar.xz"

REGEN2_URI="http://downloads.asiotec.eu.org/regen2/distfiles"
SRC_URI="${KERNEL_URI} ${REGEN2_URI}/${REGEN2_HARDEN_PATCH} ${REGEN2_URI}/${REGEN2_KERNEL_PATCH}"

UNIPATCH_LIST="${DISTDIR}/${REGEN2_KERNEL_PATCH}"
if use hardened; then
	UNIPATCH_LIST="${UNIPATCH_LIST} ${DISTDIR}/${REGEN2_HARDEN_PATCH}"
	UNIPATCH_EXCLUDE="14200_fbcondecor-0.9.6.patch 21003-trace-add-trace-events-for-open.patch"
fi

pkg_postinst() {
	kernel-2_pkg_postinst

	if use hardened; then
		local GRADM_COMPAT="sys-apps/gradm-2.2.2*"

		ewarn
		ewarn "Hardened reGen2 provides three different predefined grsecurity level:"
		ewarn "[server], [workstation], and [virtualization]."
		ewarn
		ewarn "Those who intend to use one of these predefined grsecurity levels"
		ewarn "should read the help associated with the level. Users importing a"
		ewarn "kernel configuration from a kernel prior to ${PN}-2.6.32,"
		ewarn "should review their selected grsecurity/PaX options carefully."
		ewarn
		ewarn "Users of grsecurity's RBAC system must ensure they are using"
		ewarn "${GRADM_COMPAT}, which is compatible with ${PF}."
		ewarn "It is strongly recommended that the following command is issued"
		ewarn "prior to booting a ${PF} kernel for the first time:"
		ewarn
		ewarn "emerge -na =${GRADM_COMPAT}"
		ewarn
	fi

	einfo "For more info on this patchset, and how to report problems, see:"
	einfo "${HOMEPAGE}"
}

pkg_postrm() {
	kernel-2_pkg_postrm
}

pkt_setup() {
	ewarn
	ewarn "${PN} is *not* supported by the Gentoo Kernel Project in any way."
	ewarn "If you need support, please contact the Zen developers directly."
	ewarn "Do *not* open bugs in Gentoo's bugzilla unless you have issues with"
	ewarn "the ebuilds. Thank you."
	ewarn
	ebeep 8
	kernel-2_pkg_setup
}