diff options
Diffstat (limited to 'ebuild-writing/using-eclasses/text.xml')
-rw-r--r-- | ebuild-writing/using-eclasses/text.xml | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/ebuild-writing/using-eclasses/text.xml b/ebuild-writing/using-eclasses/text.xml new file mode 100644 index 0000000..171d967 --- /dev/null +++ b/ebuild-writing/using-eclasses/text.xml @@ -0,0 +1,98 @@ +<?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 `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. +</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, *before* any functions. Conditional inherits are +illegal (except where the inheritance criteria are cache-constant -- see `The +Portage Cache`_). +</p> + +<p> +After inheriting an eclass, its provided functions can be used as normal. Here's +<c>devtodo-0.1.18-r2.ebuild</c>, which uses three eclasses: +</p> + +<codesample lang="ebuild"> +# 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() { + make 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 +} +</codesample> + +<p> +Note the <c>inherit</c> immediately after the header. +</p> + +<p> +The <c>eutils</c> eclass (see `eutils.eclass Reference`_) is needed to get the +<c>epatch</c> function. The <c>flag-o-matic</c> eclass (see `flag-o-matic.eclass +Reference`_) is needed for <c>replace-flags</c>, and the <c>bash-completion</c> eclass +(`bash-completion.eclass Reference`_) is used to handle the bash completion file +via <c>dobashcompletion</c> and <c>bash-completion_pkg_postinst</c>. +</p> + +</body> +</section> + +</chapter> +</guide> |