aboutsummaryrefslogtreecommitdiff
blob: e6a53cff0065047eb20b5b88f24bc9bef6279115 (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
<?xml version="1.0"?>
<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/">the eclass reference</uri>
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>
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-2018 Gentoo Foundation
# 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 ~x86-fbsd"

RDEPEND="sys-libs/ncurses:0=
	>=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/">autotools.eclass</uri>) 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/">flag-o-matic.eclass</uri>) is needed for <c>replace-flags</c>, and
the <c>bash-completion-r1</c> eclass (<uri link="::eclass-reference/bash-completion-r1.eclass/">bash-completion-r1.eclass</uri>) is used
to handle the bash completion file via <c>dobashcomp</c>.
</p>

</body>
</section>

</chapter>
</guide>