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 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).

When using inherit, it is best practice to sort the arguments (eclasses) alphabetically. An exception is where the phases exported by an eclass are affected by subsequent arguments. For example, multilib-minimal.eclass mentions in its documentation that it should be inherited last because it overrides most phases.

After inheriting an eclass, its provided functions can be used as normal. Here's an example ebuild, foomatic-0.1-r2.ebuild, which uses three eclasses:

# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2


inherit autotools bash-completion-r1 flag-o-matic

DESCRIPTION="Tool for foo"

KEYWORDS="alpha ~amd64 ~x86 ~x64-macos"


src_prepare() {
	eapply "${FILESDIR}/${P}-gentoo.patch"

src_configure() {
	econf --sysconfdir="${EPREFIX}"/etc/devtodo

src_compile() {
	replace-flags -O? -O1

src_install() {
	dobashcomp "${FILESDIR}/${PN}.bash-completion" ${PN}

Note the inherit immediately after the header.

The autotools eclass (see autotools.eclass) is needed to get the eautoreconf function. The flag-o-matic eclass (see flag-o-matic.eclass) is needed for replace-flags, and the bash-completion-r1 eclass (bash-completion-r1.eclass) is used to handle the bash completion file via dobashcomp.