Ebuild File Format

An ebuild is a bash script which is executed within a special environment. Files should be simple text files with a .ebuild extension.

File Naming Rules

An ebuild should be named in the form name-version.ebuild.

The name section should contain only lowercase non-accented letters, the digits 0-9, hyphens, underscores and plus characters. Uppercase characters are strongly discouraged, but technically valid.

The name must not begin with a hyphen or a plus sign, and must not end in a hyphen followed by anything that could be mistaken for a version.

The version section is more complicated. It consists of one or more numbers separated by full stop (or period, or dot, or decimal point) characters (eg 1.2.3, 20050108). The final number may have a single letter following it (e.g. 1.2b). This letter should not be used to indicate 'beta' status — portage treats 1.2b as being a later version than 1.2 or 1.2a.

There can be a suffix to version indicating the kind of release. In the following table, what portage considers to be the 'lowest' version comes first.

Suffix Meaning
_alpha Alpha release (earliest)
_beta Beta release
_pre Pre release
_rc Release candidate
(no suffix) Normal release
_p Patch release

Any of these suffixes may be followed by a non-zero positive integer.

These suffixes can be chained together and will be processed iteratively. To give some examples (the following list is from lowest version to highest):

No integer part of the version may be longer than 18 digits.

Finally, version may have a Gentoo revision number in the form -r1. The initial Gentoo version should have no revision suffix, the first revision should be -r1, the second -r2 and so on. See Ebuild Revisions. Revision numbers are distinguished from patch releases by revision bumps being changes by Gentoo developers, while patch releases are new releases by upstream (with the exception of snapshots, see below).

Overall, this gives us a filename like libfoo-1.2.5b_pre5-r2.ebuild.

When packaging a snapshot of a source repository, there are two commonly used formats. The first treats the snapshot as a patch to the previous version, and so the ebuild version is in the format $(last-released-version)_pYYYYMMDD. Alternatively, the snapshot may be treated as a pre-release to an upcoming version, usually used when a release is anticipated but not out yet. The format for this is $(upcoming-version)_preYYYYMMDD.

The policy for so-called live ebuilds (see src_unpack-actions) is to use 9999 as the version (or as the last version component).

Ebuild Header

All ebuilds committed to the tree should have a three line header immediately at the start indicating copyright. This must be an exact copy of the contents of $(portageq get_repo_path / gentoo)/header.txt. Ensure that the $Id$ line is not modified manually — will be expanded on staging box. See Git to RSYNC.

# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

Indenting and Whitespace

Indenting in ebuilds must be done with tabs, one tab per indent level. Each tab represents four spaces. Tabs should only be used for indenting, never inside strings.

Avoid trailing whitespace: repoman will warn you about this if your ebuild contains trailing or leading whitespace (whitespace instead of tabs for indentation) when you commit.

Where possible, try to keep lines no wider than 80 positions. A 'position' is generally the same as a character — tabs are four positions wide, and multibyte characters are just one position wide.

Character Set

All ebuilds (and eclasses, metadata files and ChangeLogs) must use the UTF-8 character set. See GLEP 31 for details.