aboutsummaryrefslogtreecommitdiff
blob: db41d2528d6661b027901696e01b2bbfa032005b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?xml version="1.0" encoding="UTF-8"?>
<guide self="ebuild-writing/using-eclasses/">
<chapter>
<title>Using Eclasses</title>

<body>
<p>
An eclass is a collection (library) of functions or functionality that is shared
between packages. See <uri link="::eclass-writing/" /> for the full story on what
eclasses can do, how they work and how to write them, and <uri link="::eclass-reference/"/>
for documentation on various commonly used eclasses. This section only explains
how to use an eclass which has already been written.
</p>
</body>

<section>
<title>The <c>inherit</c> Function</title>
<body>

<p>
To use an eclass, it must be 'inherited'. This is done via the <c>inherit</c>
function, which is provided by <c>ebuild.sh</c>. The <c>inherit</c> statement
must come at the top of the ebuild, <e>before</e> any functions.
Conditional inherits are illegal (except where the inheritance criteria are
cache-constant <d/> see <uri link="::general-concepts/portage-cache/"/>).
</p>

<p>
When using <c>inherit</c>, 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, <c>multilib-minimal.eclass</c>
mentions in its
<uri link="::eclass-reference/multilib-minimal.eclass/">documentation</uri>
that it should be inherited last because it overrides most phases.
</p>

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

<codesample lang="ebuild">
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

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

DESCRIPTION="Tool for foo"
HOMEPAGE="https://foomatic.sf.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="alpha ~amd64 ~x86 ~x64-macos"

RDEPEND="sys-libs/ncurses:0=
	&gt;=sys-libs/readline:0="
DEPEND="${RDEPEND}"

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

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

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

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

</codesample>

<p>
Note the <c>inherit</c> immediately after the header.
</p>

<p>
The <c>autotools</c> eclass (see <uri link="::eclass-reference/autotools.eclass/"/>) is needed to get the
<c>eautoreconf</c> function.  The <c>flag-o-matic</c> eclass (see <uri
link="::eclass-reference/flag-o-matic.eclass/"/>) is needed for <c>replace-flags</c>, and
the <c>bash-completion-r1</c> eclass (<uri link="::eclass-reference/bash-completion-r1.eclass/"/>) is used
to handle the bash completion file via <c>dobashcomp</c>.
</p>

</body>
</section>

</chapter>
</guide>