EAPI Usage and Description

The Package Manager Specification (PMS) is a standardization effort to ensure that the ebuild file format, the ebuild repository format (of which the Gentoo repository is Gentoo's main incarnation) as well as behavior of the package managers interacting with these ebuilds is properly written down and agreed upon.

EAPI is a version defined in ebuilds and other package manager related files which informs the package manager about the file syntax and content. It is, in effect, the version of the package manager specification (PMS) that the file adheres to.

This section provides usage and descriptions of the different EAPIs.

Usage of EAPIs

If EAPI is undefined in an ebuild, then EAPI=0 is selected. You should set the EAPI variable, by specifying it at the top of the ebuild:

# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2


When writing new ebuilds developers can choose whathever EAPI they think is the best. Using the features of the latest EAPI is encouraged.




  • doman Language Support

    doman automatically detects language codes and puts it in the appropriate directory.

    doman foo.1
    # will go into /usr/share/man/man1/foo.1
    doman foo.lang.1
    # will go into /usr/share/man/lang/man1/foo.1 with EAPI=2


  • Blockers

    • New Meaning for Old Syntax

      Blockers which use the previously existing ! syntax now have a slightly different meaning. These so-called weak blocks indicate that conflicting packages may be temporarily installed simultaneously. When temporary simultaneous installation of conflicting packages occurs, the installation of a newer package may overwrite any colliding files that belong to an older package which is explicitly blocked. When such file collisions occur, the colliding files cease to belong to the older package, and they remain installed after the older package is eventually uninstalled. The older package is uninstalled only after any newer blocking packages have been merged on top of it.

    • New !! Operator

      A new !! operator for strong blocks is now supported, for use in special cases for which temporary simultaneous installation of conflicting packages should not be allowed. If both weak and strong blocks match a given package, the strong block takes precedence.

  • USE Dependencies

    It is possible to depend on USE-flags of packages.


    • foo[bar] means that package foo must have USE-flag bar enabled
    • foo[bar,baz] means that the package foo must have both the bar and baz USE-flags enabled
    • foo[-bar,baz] means that the package foo must have the bar USE-flag disabled and baz USE-flag enabled
    • foo[bar?] means bar? ( foo[bar] ) !bar? ( foo )
    • foo[!bar?] means bar? ( foo ) !bar? ( foo[-bar] )
    • foo[bar=] means bar? ( foo[bar] ) !bar? ( foo[-bar] )
    • foo[!bar=] means bar? ( foo[-bar] ) !bar? ( foo[bar] )

  • Customization of Output File Names in SRC_URI

    A new syntax is supported which allows customization of the output file name for a given URI. In order to customize the output file name, a given URI should be followed by a "->" operator which, in turn, should be followed by the desired output file name. As usual, all tokens, including the operator and output file name, should be separated by whitespace.


                            -> GoogleEarthLinux-${PV}.bin"


  • New src_prepare Phase Function

    A new src_prepare function is called after the src_unpack function, with cwd initially set to $S.

  • New src_configure Phase Function

    The configure portion of the src_compile function has been split into a separate function which is named src_configure. The src_configure function is called in-between the src_prepare and src_compile functions.

    The default src_configure and src_compile functions in EAPI=2:

    src_configure() {
    	if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
    src_compile() {
    	if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ] ; then
    		emake || die "emake failed"

  • Execution Order of Phase Functions

    • pkg_setup
    • src_unpack
    • src_prepare
    • src_configure
    • src_compile
    • src_test
    • src_install
    • pkg_preinst
    • pkg_postinst
    • pkg_prerm
    • pkg_postrm

  • Default Phase Functions

    The default pkg_nofetch and src_* phase functions are now accessible via a function having a name that begins with default_ and ends with the respective phase function name. For example, a call to a function with the name default_src_compile is equivalent to a call to the default src_compile implementation.

    The default phase functions are:

    • default_pkg_nofetch
    • default_src_unpack
    • default_src_prepare
    • default_src_configure
    • default_src_compile
    • default_src_test

  • Default Phase Function Alias

    A function named "default" is redefined for each phase so that it will call the default_* function corresponding to the current phase. For example, a call to the function named "default" during the src_compile phase is equivalent to a call to the function named default_src_compile.




  • utilities die on their own, unless the nonfatal command is used

    Ebuild functions all die on their own in EAPI=4. In case that this non-zero exit status is expected, you may call nonfatal function [arg,...].


    src_test() {
    	if ! emake check ; then
    		local a
    		eerror "Tests failed. Looking for files for you to add to your bug report..."
    		while IFS='' read -r -d $'\0' a ; do
    			eerror "    ${a}"
    		done < <(find "${S}" -type f '(' -name '*.epicfail' -o -name '*.log' ')' -print0)
    		die "Make check failed"
    src_test() {
    	if ! nonfatal emake check ; then
    		local a
    		eerror "Tests failed. Looking for files for you to add to your bug report..."
    		while IFS='' read -r -d $'\0' a ; do
    			eerror "    ${a}"
    		done < <(find "${S}" -type f '(' -name '*.epicfail' -o -name '*.log' ')' -print0)
    		die "Make check failed"
  • recursive dodoc

    dodoc supports -r as the first argument, which leads dodoc to install the specified documentation directory recursively into the docdir.


    src_install() {
    	dodoc ChangeLog
    	dodoc -r doc/
  • doins symlink supports

    Within EAPI=4, doins supports installing symlinks as symlinks when installing recursively. For older EAPIs, the symlink behaviour is undefined.

  • dosed and dohard are banned

    The dosed and dohard commands are banned in this EAPI.

  • econf adds --disable-dependency-tracking

    Within EAPI=4, econf adds --disable-dependency-tracking to the default configure options.

  • controllable compression via docompress

    To compress files in the destination-folder ${D}, the docompress command may be used in src_install. To control which items should be compressed and which shouldn't be compressed, you may include or exclude directories or plain files. The default inclusion list contains:

    • /usr/share/doc
    • /usr/share/info
    • /usr/share/man
    The default exclusion list contains:
    • /usr/share/doc/${PF}/html
    When a directory is in- or excluded, all files and directories in the given directories shall be added to the corresponding list. If a file is in- or excluded, the file shall be added to the corresponding list (exclusion is stronger than inclusion — if a file is in both lists, the inclusion will be ignored).

    If the first argument of docompress is -x, the items specified will be added to the exclusion list, otherwise they will be added to the inclusion list.


  • use dependencies default

    In addition to the use-deps specified in EAPI=2, a (+) or (-) may be added to the use-dep to define a default-value in case the use-flag does not exist in the given package. The (+) means that this use-flag is assumed to be enabled, (-) the opposite.




  • new pkg_pretend phase

    The new pkg_pretend phase can be used to do sanity checks before the main phase function sequence is run (meaning this phase is executed after the package manager has calculated the dependencies and before installing them). This phase typically checks for a kernel configuration and may eerror and die when needed.


    # Copyright 1999-2019 Gentoo Authors
    # Distributed under the terms of the GNU General Public License v2
    inherit linux-info
    ERROR_FUSE_FS="this is an unrealistic testcase..."
    pkg_pretend() {
    	if use kernel_linux ; then
    		if [[ -e "${ROOT}"/usr/src/linux/.config ]] ; then
    			if kernel_is lt 2 6 30 ; then
  • default src_install is no longer a no-op

    The default src_install function in EAPI=4:

    src_install() {
    	if [[ -f Makefile ]] || [[ -f GNUmakefile]] || [[ -f makefile ]] ; then
    		emake DESTDIR="${D}" install
    	if ! declare -p DOCS >/dev/null 2>&1 ; then
    		local d
    			[[ -s "${d}" ]] && dodoc "${d}"
    	elif declare -p DOCS | grep -q "^declare -a " ; then
    		dodoc "${DOCS[@]}"
    		dodoc ${DOCS}
  • pkg_info for non-installed packages

    The pkg_info function may also be called by the package manager for non-installed packages. Ebuild writers should note that dependencies may not be available.



    The REQUIRED_USE variable contains a list of assertions that must be met by the configuration of USE flags to be valid for this ebuild. In order to be matched, a USE flag in a terminal element must be enabled (or disabled if it has an exclamation mark prefix).



    The REPLACING_VERSIONS variable contains a whitespace-separated list of all versions (PVR) of this package that are being replaced (uninstalled or overwritten) as a result of this install. It is a list, not a single optional value, to handle pathological cases such as installing foo-2:2 to replace foo-2:1 and foo-3:2.

    REPLACING_VERSIONS is valid in pkg_preinst and pkg_postinst. In addition, it may be available in pkg_pretend and pkg_setup, although you should take care to handle binary package creation and installation correctly when using it in these phases.

    The REPLACED_BY_VERSION variable contains the single version (PVR) of this package that is replacing us, if we are being uninstalled as part of an install, or an empty string otherwise. It is valid in pkg_prerm and pkg_postrm.


    The MERGE_TYPE variable contains the type of package that is being merged. Possible values are:

    if building and installing a package from source,
    if installing a binary package,
    if building a binary package without installing it.

  • DOCS

    The DOCS variable is an array or whitespace-separated list of documentation files for the default src_install function to install using dodoc. If undefined, a reasonable default list is used. See the default src_install function above.

  • AA and KV variables are gone

    The AA and KV variables are no longer set in EAPI=4.

  • no more RDEPEND="${DEPEND}"

    When RDEPEND is unset, there will no longer be an automatic assignment of RDEPEND="${DEPEND}".



  • REQUIRED_USE supports new at-most-one-of operator

    The new at-most-one-of operator consists of the string '??', and is satisfied if zero or one (but no more) of its child elements is matched.

  • SLOT supports optional "sub-slot" part

    The SLOT variable may contain an optional sub-slot part that follows the regular slot and is delimited by a / character. The sub-slot must be a valid slot name. The sub-slot is used to represent cases in which an upgrade to a new version of a package with a different sub-slot may require dependent packages to be rebuilt. When the sub-slot part is omitted from the SLOT definition, the package is considered to have an implicit sub-slot which is equal to the regular slot.

  • Slot operators and sub-slots in dependencies

    A slot dependency may contain an optional sub-slot part that follows the regular slot and is delimited by a / character. This can be useful for packages installing pre-built binaries that require a library with a specific soname version which corresponds to the sub-slot. For example:


    Package dependency specifications can use slot operators to clarify what should happen if the slot and/or sub-slot of a runtime dependency changes:

    • :* Indicates that any slot value is acceptable. In addition, for runtime dependencies, indicates that the package specifying the dependency will not break if the package matching the dependency is replaced by a different matching package with a different slot and/or sub-slot.
    • := Indicates that any slot value is acceptable. In addition, for runtime dependencies, indicates that the package specifying the dependency will break unless there is available a package matching the dependency and whose slot and sub-slot are equal to the slot and sub-slot of the best installed version that had matched this dependency at the time when the package specifying this dependency had been installed.
    • :slot= Indicates that only a specific slot value is acceptable, and otherwise behaves identically to the := operator.

    The :slot dependency syntax continues to behave like in EAPI=4 or earlier, i.e. it indicates that only the specific slot value is acceptable, but the package will not break when the version matching the runtime dependency is replaced by a version with a different sub-slot.

    For example:


    means that the package should be rebuilt when foo:2 or >=bar-0.9 are upgraded to versions with different subslots, but that changes in subslots of baz or wombat:0 should be ignored.


  • Profile stable USE forcing and masking

    In profile directories with an EAPI supporting stable masking, new USE configuration files are supported: use.stable.mask, use.stable.force, package.use.stable.mask and package.use.stable.force. These files behave similarly to previously supported USE configuration files, except that they only influence packages that are merged due to a stable keyword.


  • econf adds --disable-silent-rules

    This option will automatically be passed if --disable-silent-rules occurs in the output of configure --help.

  • new* commands can read from standard input

    Standard input is read when the first parameter is - (a hyphen).

  • New option --host-root for {has,best}_version

    This option --host-root will cause the query to apply to the host root instead of ROOT.

  • New doheader helper function

    Installs the given header files into /usr/include/. If option -r is specified, descends recursively into any directories given.

  • New usex helper function

    USAGE: usex <USE flag> [true output] [false output] [true suffix] [false suffix]
    If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
     otherwise echo [false output][false suffix] (defaults to "no").


  • src_test supports parallel tests

    Unlike older EAPIs, the default src_test implementation will not pass the -j1 option to emake.



    During execution of an ebuild phase function (such as pkg_setup or src_unpack), the EBUILD_PHASE_FUNC variable will contain the name of the phase function that is currently executing.


Bash version

Ebuilds can use features of Bash version 4.2 (was 3.2 before).

Ebuild environment

  • Locale settings

    Behaviour of case modification and collation order (LC_CTYPE and LC_COLLATE) are guaranteed to be the same as in the C locale, as far as characters in the ASCII range are concerned.

  • failglob enabled

    For EAPI=6, the failglob option of bash is set in the global scope of ebuilds. If set, failed pattern matches during filename expansion result in an error when the ebuild is being sourced.


  • Update default implementation of src_prepare

    This phase is no longer a no-op, it supports applying patches via the PATCHES variable and applying user patches via eapply_user. The default src_prepare looks like this:

    src_prepare() {
    	if declare -p PATCHES | grep -q "^declare -a "; then
    		[[ -n ${PATCHES[@]} ]] && eapply "${PATCHES[@]}"
    		[[ -n ${PATCHES} ]] && eapply ${PATCHES}

  • New src_install Phase Function

    This phase uses the new einstalldocs function for installation of documentation. The default src_install looks like this:

    src_install() {
    	if [[ -f Makefile ]] || [[ -f GNUmakefile ]] || [[ -f makefile ]]; then
    		emake DESTDIR="${D}" install


  • einstall banned

    The einstall helper has been banned with EAPI=6.

  • dohtml deprecated

    The dohtml helper has been deprecated with EAPI=6.

  • nonfatal die

    When die or assert are called under the nonfatal command and with the -n option, they will not abort the build process but return with an error.

  • eapply support

    The eapply command is a simplified substitute for epatch (from eutils.eclass), implemented in the package manager. The patches from its file or directory arguments are applied using patch -p1, but it accepts patch(1) options from GNU patch to override default behavior.

  • eapply_user support

    The eapply_user command permits the package manager to apply user-provided patches. It must be called from every src_prepare function.

  • econf adds --docdir and --htmldir

    Options --docdir and --htmldir are passed to configure, in addition to the existing options.

  • in_iuse support

    The in_iuse function returns true if the given parameter is available in the ebuilds USE.

  • unpack changes

    • unpack supports relative paths without leading ./ (unpack foo/bar.tar.gz is valid as relative path).

    • unpack supports .txz (xz compressed tarball).

    • unpack matches filename extensions case-insensitively.

  • einstalldocs support

    The einstalldocs function will install the files specified by the DOCS variable (or a default set of files if DOCS is unset) and by the HTML_DOCS variable.

  • get_libdir support

    The get_libdir command outputs the lib* directory basename suitable for the current ABI.



Documents may use the following terms to better describe dependency and installation targets.


    The system that will be running the installed package.


    The system used to build packages. When not cross-compiling, CBUILD == CHOST.


    Used in certain cross-compliations, often empty value.


  • PORTDIR and ECLASSDIR are removed

    PORTDIR and ECLASSDIR are no longer defined and cannot be used in ebuilds to access these directories.

  • DESTTREE and INSDESTTREE are removed

    The unintended exported variables PORTDIR and ECLASSDIR cannot be used in ebuilds to manipulate installation paths. Use into or insinto, respectively, instead.

  • D, ED, ROOT, and EROOT modified

    These variables no longer contain a trailing slash with EAPI=7.

  • BDEPEND addded

    Previously, all build-time tools and libraries went into the DEPEND. Now, built-time dependencies are split into DEPEND and BDEPEND. The difference is simply that BDEPEND are dependencies to be executed on the CBUILD. DEPEND remains for other dependencies, such as libraries, for the CHOST. This improves the cross-compliation support.

  • BROOT added

    BROOT is the absolute path to the root directory, including any prefix, containing build dependencies satisfied by BDEPEND, typically executable build tools.

  • SYSROOT and ESYSROOT added

    SYSROOT is the location of where dependencies in DEPEND are installed. ESYSROOT is SYSROOT with EPREFIX appended.

  • ENV_UNSET added

    A whitespace delimited list of variables to be removed from the build environment.


  • Empty groupings are banned

    Groupings which are empty, such as DEPEND="|| ( ${empty_var} )" will now generate an error. Furthermore, conditions within groupings are more strictly enforced. Eg. REQUIRED_USE="|| ( foo? ( bar ) baz? ( zoinks )" would previously work with USE="-foo -baz" now requires either USE="foo bar" or USE="baz zoinks".


  • package.provided banned

    Profiles may no longer contain a package.provided file with EAPI=7.


  • dohtml banned

    The dohtml helper has been banned with EAPI=7.

  • dolib and libopts banned

    The dolib helper and the associated libopts have been banned with EAPI=7.

  • has_version and best_version changes

    has_version and best_version now support an optional switch to determine which type of dependencies to check.

    • -r (the default) will check runtime dependencies (RDEPEND)

    • -d will check CHOST build-time dependencies (DEPEND)

    • -b will check CBUILD build-time dependencies (BDEPEND)

  • Version manipulation and comparision commands

    EAPI=7 introduced three commands for common version number operations.

    • ver_cut obtains substrings of a version string

    • ver_rs replaces separators in a version string

    • ver_test compares two versions

    See Version and Name Formatting Issues for examples of common uses or an in-depth look

  • New function eqawarn

    The eqawarn helper has been added with EAPI=7. This function is to alert developers to a deprecated feature. Previously, this was contained in eutils eclass which is no longer necessary.

  • New function dostrip

    The dostrip helper has been added with EAPI=7. This function controls whether or not to strip a binary. dostrip -x [file] will exclude a binary from being stripped. Conversely, when combined with RESTRICT=strip, dostrip [file] selects a binary file to be stripped.

  • die and assert changes

    These commands are now safe to use in a subshell and act as if they were called in the main process.

  • nonfatal changes

    The nonfatal command now works for shell functions and subprocesses.

  • domo behaviour changed

    domo (for localizations) now ignores the into directives. This follows similar commands like doinfo and doman.

  • econf changes

    The cross-compilation options --build and --target options to specify CBUILD and CTARGET respectively have been added and are retro-active to all EAPIs. In addition, if the build supports --with-sysroot, the correct value will be passed such that normal and cross-compliations succeed.