Gentoo Development Guide
Using Eclasses
An eclass is a collection (library) of functions or functionality that is shared between packages. See Eclass Writing Guide for the full story on what eclasses can do, how they work and how to write them, and Eclass Reference for documentation on various commonly used eclasses. This section only explains how to use an eclass which has already been written.
The inherit Function
To use an eclass, it must be 'inherited'. This is done via the inherit
function, which is provided by ebuild.sh. The inherit statement must
come at the top of the ebuild, before any functions. Conditional inherits are
illegal (except where the inheritance criteria are cache-constant
—
see The Portage Cache).
After inheriting an eclass, its provided functions can be used as normal. Here's
devtodo-0.1.18-r2.ebuild, which uses three eclasses:
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
inherit eutils bash-completion flag-o-matic
DESCRIPTION="A nice command line todo list for developers"
HOMEPAGE="http://swapoff.org/DevTodo"
SRC_URI="http://swapoff.org/files/${PN}/${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="alpha amd64 arm hppa ia64 mips ppc s390 sparc x86 ppc64"
IUSE=""
RDEPEND=">=sys-libs/ncurses-5.2
>=sys-libs/readline-4.1"
DEPEND="${RDEPEND}"
src_unpack() {
unpack ${A}
cd "${S}"
epatch "${FILESDIR}/${P}-gentoo.diff"
}
src_compile() {
einfo "Running autoreconf"
autoreconf -f -i || die "autoreconf failed"
replace-flags -O? -O1
econf --sysconfdir=/etc/devtodo || die "econf failed"
emake || die "emake failed"
}
src_install() {
emake DESTDIR="${D}" install || die "make install failed"
dodoc AUTHORS ChangeLog QuickStart README TODO doc/scripts.sh \
doc/scripts.tcsh doc/todorc.example contrib/tdrec || die "dodoc failed"
dobashcompletion "${FILESDIR}/${PN}.bash-completion" ${PN}
}
pkg_postinst() {
echo
einfo "Because of a conflict with app-misc/tdl, the tdl symbolic link"
einfo "and manual page have been removed."
bash-completion_pkg_postinst
}
Note the inherit immediately after the header.
The eutils eclass (see eutils.eclass Reference) is needed to get the
epatch function. The flag-o-matic eclass (see flag-o-matic.eclass Reference) is needed for replace-flags, and
the bash-completion eclass (bash-completion.eclass Reference) is used
to handle the bash completion file via dobashcompletion and bash-completion_pkg_postinst.