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 the eclass reference for documentation on various commonly used eclasses. This section only explains how to use an eclass which has already been written.
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 an example ebuild, foomatic-0.1-r2.ebuild
, which
uses four eclasses:
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
EAPI=2
inherit eutils bash-completion flag-o-matic autotools
DESCRIPTION="Tool for foo"
HOMEPAGE="http://foomatic.sf.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="alpha ~amd64 ~x86 ~x86-fbsd"
RDEPEND=">=sys-libs/ncurses-5.2
>=sys-libs/readline-4.1"
DEPEND="${RDEPEND}"
src_prepare() {
epatch "${FILESDIR}/${P}-gentoo.patch"
eautoreconf
}
src_configure() {
econf --sysconfdir=/etc/devtodo
}
src_compile() {
replace-flags -O? -O1
emake || die "emake failed"
}
src_install() {
emake DESTDIR="${D}" install || die "emake install failed"
dodoc AUTHORS ChangeLog README TODO || die "dodoc failed"
dobashcompletion "${FILESDIR}/${PN}.bash-completion" ${PN}
}
Note the inherit
immediately after the header.
The eutils
eclass (see eutils.eclass) is needed to get the
epatch
function. The flag-o-matic
eclass (see flag-o-matic.eclass) is needed for replace-flags
, and
the bash-completion
eclass (bash-completion.eclass) is used
to handle the bash completion file via dobashcompletion
and bash-completion_pkg_postinst
.