aboutsummaryrefslogtreecommitdiff
blob: 29e5077b28d72e6e5642255f3a1be1e7654a9c32 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?xml version="1.0"?>
<guide self="quickstart/">
<chapter>
<title>Quickstart Ebuild Guide</title>

<body>
<p>
This page provides a <e>very</e> brief introduction to ebuild
writing. It does not attempt to cover many of the details or problems
that will be encountered by developers <d/> rather, it gives some
trivial examples which may be of use when trying to grasp the basic
idea of how ebuilds work.
</p>

<p>
For proper coverage of all the ins and outs, see <uri link="::ebuild-writing"/>.
The <uri link="::general-concepts"/> chapter will also be of use.
</p>

<p>
Note that the examples used here, whilst based upon real tree ebuilds,
have had several parts chopped out, changed and simplified.
</p>
</body>

<section>
<title>First Ebuild</title>

<body>
<p>
We'll start with an ebuild for the <e>Exuberant Ctags</e> utility, a source code
indexing tool. Here's a simplified <c>dev-util/ctags/ctags-5.5.4.ebuild</c> (you
can see real ebuilds in the main tree).
</p>

<codesample lang="ebuild">
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

DESCRIPTION="Exuberant ctags generates tags files for quick source navigation"
HOMEPAGE="http://ctags.sourceforge.net"
SRC_URI="mirror://sourceforge/ctags/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~mips ~sparc ~x86"
IUSE=""

src_compile() {
    econf --with-posix-regex || die "econf failed"
    emake || die "emake failed"
}

src_install() {
    make DESTDIR="${D}" install || die "install failed"

    dodoc FAQ NEWS README
    dohtml EXTENDING.html ctags.html
}
</codesample>
</body>

<subsection>
<title>Basic Format</title>

<body>
<p>
As you can see, ebuilds are just <c>bash</c> scripts that are executed within a
special environment.
</p>

<p>
At the top of the ebuild is a header block. This is present in all ebuilds.
</p>

<p>
Ebuilds are indented using tabs, with each tab representing four places. See
<uri link="::ebuild-writing/file-format"/>.
</p>
</body>
</subsection>

<subsection>
<title>Information Variables</title>

<body>
<p>
Next, there are a series of variables. These tell portage various things about
the ebuild and package in question.
</p>

<p>
The <c>DESCRIPTION</c> variable is set to a <e>short</e> description
of the package and its purpose.
</p>

<p>
The <c>HOMEPAGE</c> is a link to the package's homepage (remember to
include the <c>http://</c> part).
</p>

<p>
The <c>LICENSE</c> is <c>GPL-2</c> (the GNU General Public License version 2).
</p>

<p>
The <c>SRC_URI</c> tells Portage the address to use for downloading
the source tarball. Here, <c>mirror://sourceforge/</c> is a special
notation meaning &quot;any of the Sourceforge mirrors&quot;. The
<c>${P}</c> is a read-only variable set by Portage which is the package's
name and version <d/> in this case, it would be <c>ctags-5.5.4</c>.
</p>

<p>
The <c>SLOT</c> variable tells portage which slot this package installs to. If
you've not seen slots before, either just use <c>&quot;0&quot;</c> or read
<uri link="::general-concepts/slotting"/>.
</p>

<p>
The <c>KEYWORDS</c> variable is set to archs upon which this ebuild has been
tested. We use <c>~</c> keywords for newly written ebuilds <d/> packages are not
committed straight to stable, even if they seem to work. See <uri link="::keywording"/> for
details.
</p>
</body>
</subsection>

<subsection>
<title>Build Functions</title>

<body>
<p>
Next, a function named <c>src_compile</c>. Portage will call this
function when it wants to <e>compile</e> the package. The <c>econf</c>
function is a wrapper for calling <c>./configure</c>, and <c>emake</c>
is a wrapper for <c>make</c>. In both cases, the common <c>|| die
&quot;something went wrong&quot;</c> idiom is used <d/> this is to
ensure that if for some reason an error occurs, portage will stop
rather than trying to continue with the install.
</p>

<p>
The <c>src_install</c> function is called by portage when it wants
to <e>install</e> the package. A slight subtlety here <d/> rather than
installing straight to the live filesystem, we must install to a
special location which is given by the <c>${D}</c> variable (portage sets
this <d/> see <uri link="::general-concepts/install-destinations"/> and
<uri link="::general-concepts/sandbox"/>).  Again, we check
for errors.
</p>

<note>
The canonical install method is <c>make DESTDIR=&quot;${D}&quot;
install</c>. This will work with any properly written standard
<c>Makefile</c>. If this gives sandbox errors, try <c>einstall</c>
instead. If this still fails, see `src_install`_ for how to do
manual installs.
</note>

<p>
The <c>dodoc</c> and <c>dohtml</c> are helper functions for installing
files into the relevant part of <c>/usr/share/doc</c>.
</p>

<p>
Ebuilds can define other functions (see <uri link="::ebuild-writing/functions"/>).
In all cases, portage provides a reasonable default implementation which quite
often does the 'right thing'. There was no need to define a <c>src_unpack</c>
function here, for example <d/> this function is used to do any unpacking of
tarballs or patching of source files, but the default implementation does
everything we need.
</p>
</body>
</subsection>

</section>

<section>
<title>Ebuild with Dependencies</title>

<body>
<p>
In the ctags example, we didn't tell portage about any dependencies. As it
happens, that's ok, because ctags only needs a basic toolchain to compile and
run (see <uri link="::general-concepts/dependencies#Implicit System Dependency"/>
for why we don't need to depend upon those explicitly). However, life is rarely
that simple.
</p>

<p>
Here's <c>app-misc/detox/detox-1.1.1.ebuild</c>:
</p>

<codesample lang="ebuild">
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

DESCRIPTION="detox safely removes spaces and strange characters from filenames"
HOMEPAGE="http://detox.sourceforge.net/"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.bz2"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~hppa mips sparc x86"
IUSE=""

DEPEND="dev-libs/popt
    sys-devel/flex
    sys-devel/bison"
RDEPEND="dev-libs/popt"

src_compile() {
    econf --with-popt || die "econf failed"
    emake || die "emake failed"
}

src_install() {
    make DESTDIR="${D}" install || die "install failed"
    dodoc README CHANGES
}
</codesample>

<p>
Again, you can see the ebuild header and the various informational variables. In
<c>SRC_URI</c>, <c>${PN}</c> is used to get the package's
name <e>without</e> the version suffix (there are more of these
variables <d/> see
<uri link="::ebuild-writing/variables#Predefined Read-Only Variables"/>).
</p>

<p>
Again, we define <c>src_compile</c> and <c>src_install</c> functions.
</p>

<p>
The <c>DEPEND</c> and <c>RDEPEND</c> variables are how portage determines which
packages are needed to build and run the package. The <c>DEPEND</c> variable lists
compile-time dependencies, and the <c>RDEPEND</c> lists runtime dependencies. See
<uri link="::general-concepts/dependencies"/> for some more complex examples.
</p>

</body>
</section>

<section>
<title>Ebuild with Patches</title>

<body>
<p>
Often we need to apply patches. This is done in the <c>src_unpack</c> function
using the <c>epatch</c> helper function. To use <c>epatch</c> one must first tell
portage that the <c>eutils</c> eclass (an eclass is like a library) is required --
this is done via <c>inherit eutils</c> at the top of the ebuild. Here's
<c>app-misc/detox/detox-1.1.0.ebuild</c>:
</p>

<codesample lang="ebuild">
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="detox safely removes spaces and strange characters from filenames"
HOMEPAGE="http://detox.sourceforge.net/"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.bz2"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~hppa ~mips ~sparc ~x86"
IUSE=""

DEPEND="dev-libs/popt
    sys-devel/flex
    sys-devel/bison"
RDEPEND="dev-libs/popt"

src_unpack() {
    unpack ${A}
    cd "${S}"

    epatch "${FILESDIR}"/${P}-destdir.patch
    epatch "${FILESDIR}"/${P}-parallel_build.patch
}

src_compile() {
    econf --with-popt || die "econf failed"
    emake || die "emake failed"
}

src_install() {
    make DESTDIR="${D}" install || die "install failed"
    dodoc README CHANGES
}
</codesample>

<p>
Note the <c>${FILESDIR}/${P}-destdir.patch</c> <d/> this refers to
<c>detox-1.1.0-destdir.patch</c>, which lives in the <c>files/</c>
subdirectory in the portage tree. Larger patch files must go on the
mirrors rather than in <c>files/</c> <d/> see `Basic epatch Usage`_.
</p>

</body>
</section>

<section>
<title>Ebuild with USE Flags</title>

<body>
<p>
Now for some <c>USE</c> flags. Here's <c>dev-libs/libiconv/libiconv-1.9.2.ebuild</c>, a
replacement iconv for <c>libc</c> implementations which don't have their own.
</p>

<codesample lang="ebuild">
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

DESCRIPTION="GNU charset conversion library for libc which doesn't implement it"
SRC_URI="ftp://ftp.gnu.org/pub/gnu/libiconv/${P}.tar.gz"
HOMEPAGE="http://www.gnu.org/software/libiconv/"

SLOT="0"
LICENSE="LGPL-2.1"
KEYWORDS="~amd64 ~ppc ~sparc ~x86"
IUSE="nls"

DEPEND="virtual/libc
    !sys-libs/glibc"

src_compile() {
    econf $(use_enable nls) || die "econf failed"
    emake || die
}

src_install() {
    make DESTDIR="${D}" install || die "install failed"
}
</codesample>

<p>
Note the <c>IUSE</c> variable. This lists all (non-special) use flags that are used
by the ebuild. This is used for the <c>emerge -pv</c> output, amongst other things.
</p>

<p>
The package's <c>./configure</c> script takes the usual <c>--enable-nls</c> or
<c>--disable-nls</c> argument. We use the <c>use_enable</c> utility function to
generate this automatically (see `Query Functions Reference`_).
</p>

<p>
Another more complicated example, this time based upon
<c>mail-client/sylpheed/sylpheed-1.0.4.ebuild</c>:
</p>

<codesample lang="ebuild">
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="A lightweight email client and newsreader"
HOMEPAGE="http://sylpheed.good-day.net/"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.bz2"

LICENSE="GPL-2"
KEYWORDS="alpha amd64 hppa ia64 ppc ppc64 sparc x86"
SLOT="0"

IUSE="crypt gnome imlib ipv6 ldap nls pda ssl xface"

DEPEND="=x11-libs/gtk+-1.2*
    nls? ( >=sys-devel/gettext-0.12.1 )
    crypt? ( >=app-crypt/gpgme-0.4.5 )
    gnome? ( media-libs/gdk-pixbuf )
    imlib? ( media-libs/imlib )
    ldap? ( >=net-nds/openldap-2.0.11 )
    pda? ( app-pda/jpilot )
    ssl? ( dev-libs/openssl )
    xface? ( >=media-libs/compface-1.4 )"
RDEPEND="${DEPEND}
    app-misc/mime-types
    x11-misc/shared-mime-info"

src_unpack() {
    unpack ${A}
    cd "${S}"

    epatch "${FILESDIR}"/${PN}-namespace.diff
    epatch "${FILESDIR}"/${PN}-procmime.diff
}

src_compile() {

    econf \
        $(use_enable nls) \
        $(use_enable ssl) \
        $(use_enable crypt gpgme) \
        $(use_enable pda jpilot) \
        $(use_enable ldap) \
        $(use_enable ipv6) \
        $(use_enable imlib) \
        $(use_enable gnome gdk-pixbuf) \
        $(use_enable xface compface) \
        || die

    emake || die
}

src_install() {
    einstall || die "einstall failed"
    dodir /usr/share/pixmaps
    insinto /usr/share/pixmaps
    doins *.png

    if use gnome ; then
        dodir /usr/share/gnome/apps/Internet
        insinto /usr/share/gnome/apps/Internet
        doins sylpheed.desktop
    fi

    dodoc [A-Z][A-Z]* ChangeLog*
}
</codesample>

<p>
Note the optional dependencies. Some of the <c>use_enable</c> lines use the
two-argument version <d/> this is helpful when the USE flag name does not exactly
match the <c>./configure</c> argument.
</p>
</body>
</section>

</chapter>
</guide>