\chapter{Ebuild-defined Variables}
\label{ebuild-vars}

\note This section describes variables that may or must be defined by ebuilds. For
variables that are passed from the package manager to the ebuild, see section~\ref{ebuild-env-vars}.

\section{Metadata invariance}
\label{metadata-invariance}

All ebuild-defined variables discussed in this chapter must be defined independently of
any system, profile or tree dependent data, and must not vary depending upon the ebuild
phase. In particular, ebuild metadata can and will be generated on a different system from that upon
which the ebuild will be used, and the ebuild must generate identical metadata every time it
is used.

Globally defined ebuild variables without a special meaning must similarly not rely upon
variable data.

\section{Mandatory Ebuild-defined Variables}

All ebuilds must define at least the following variables:

\begin{description}
\item[DESCRIPTION] A short human-readable description of the package's purpose. May be defined by an
    eclass. Must not be empty.
\item[SRC\_URI] A list of source URIs for the package. Valid protocols are \t{http://},
    \t{https://}, \t{ftp://} and \t{mirror://} (see section~\ref{thirdpartymirrors} for mirror behaviour).
    Fetch restricted packages may include URL parts consisting of just a filename. See
    section~\ref{dependencies} for full syntax.
\item[HOMEPAGE] The URI or URIs for a package's homepage, including protocols. May be defined by an
    eclass. See section~\ref{dependencies} for full syntax.
\item[SLOT] The package's slot. Must be a valid slot name, as per section~\ref{slot-names}. May
    be defined by an eclass. Must not be empty.
\item[LICENSE] The package's license. Each text token must correspond to a tree ``licenses/'' entry
    (see section~\ref{licenses-dir}). See section~\ref{dependencies} for full syntax.
    May be defined by an eclass. \label{ebuild-var-LICENSE}
\item[IUSE] The \t{USE} flags used by the ebuild. Historically, \t{USE\_EXPAND} values and \t{ARCH}
    were not included; package managers should support this for backwards compatibility reasons. Ebuilds
    must list only flags used by the ebuild itself. Any eclass that works with \t{USE} flags
    must also set \t{IUSE}, listing only the variables used by that eclass. The package manager is
    responsible for merging these values.

    In EAPIs shown in table~\ref{iuse-defaults-table} as supporting \t{IUSE} defaults, any use flag
    name in \t{IUSE} may be prefixed by at most one of a plus or a minus sign. If such a prefix is
    present, the package manager may use it as a suggestion as to the default value of the use flag
    if no other configuration overrides it.
\item[KEYWORDS] A whitespace separated list of keywords for the ebuild. Each token must be a
    valid keyword name, as per section~\ref{keyword-names}. May include \t{-*}, which
    indicates that the package will only work on explicitly listed archs. May include \t{-arch},
    which indicates that the package will not work on the specified arch. May be empty, which
    indicates uncertain functionality on any architecture. May be defined in an eclass.
\end{description}

If any of these variables are undefined, or if any of these variables are set to invalid values,
the package manager's behaviour is undefined; ideally, an error in one ebuild should not prevent
operations upon other ebuilds or packages.

\IFKDEBUILDELSE
{
    \begin{center}
    \topcaption{EAPIs supporting \t{IUSE} defaults}
    \tablehead{
        \hline
        \multicolumn{1}{c}{\textbf{EAPI}} &
        \multicolumn{1}{c}{\textbf{Supports \t{IUSE} defaults?}} \\
        \hline
        }
    \begin{mpxtabular}{ l l } \label{iuse-defaults-table}
    \t{0} & No \\
    \t{1} & Yes \\
    \t{kdebuild-1} & Yes \\
    \hline
    \end{mpxtabular}
    \end{center}
}
{
    \begin{center}
    \topcaption{EAPIs supporting \t{IUSE} defaults}
    \tablehead{
        \hline
        \multicolumn{1}{c}{\textbf{EAPI}} &
        \multicolumn{1}{c}{\textbf{Supports \t{IUSE} defaults?}} \\
        \hline
        }
    \begin{mpxtabular}{ l l } \label{iuse-defaults-table}
    \t{0} & No \\
    \t{1} & Yes \\
    \hline
    \end{mpxtabular}
    \end{center}
}

\section{Optional Ebuild-defined Variables}

Ebuilds may define any of the following variables:

\begin{description}
\item[S] The path to the temporary build directory, used by \t{src\_compile}, \t{src\_install}
    etc. Defaults to \t{\$\{WORKDIR\}/\$\{P\}}.
\item[DEPEND] See section~\ref{dependencies}.
\item[RDEPEND] See section~\ref{dependencies}. \t{RDEPEND} has special behaviour for its value if
    unset and when used with an eclass. See section~\ref{rdepend-depend} for details.
\item[PDEPEND] See section~\ref{dependencies}.
\IFKDEBUILDELSE
{
    \item[PROVIDE] Zero or more qualified package names of any \e{old style}
        virtuals provided by this package. See section~\ref{dependencies} for full syntax.  In EAPIs
        listed in table~\ref{provide-table} as not supporting \t{PROVIDE}, ebuilds must not set this
        variable and the package manager must reject any ebuild that does so.
        \label{ebuild-var-provide}
}{
    \item[PROVIDE] Zero or more qualified package names of any \e{old style}
        virtuals provided by this package. See section~\ref{dependencies} for full syntax.
        \label{ebuild-var-provide}
}
\item[EAPI] The EAPI. See below for defaults.
\item[RESTRICT] Zero or more behaviour restrictions for this package. See section~\ref{restrict}
    for value meanings and section~\ref{dependencies} for full syntax.
\end{description}

\IFKDEBUILDELSE
{
    \begin{center}
    \topcaption{EAPIs supporting \t{PROVIDE}}
    \tablehead{
        \hline
        \multicolumn{1}{c}{\textbf{EAPI}} &
        \multicolumn{1}{c}{\textbf{Supports \t{PROVIDE}?}} \\
        \hline
    }
    \begin{mpxtabular}{ l l } \label{provide-table}
    \t{0} & Yes \\
    \t{1} & Yes \\
    \t{kdebuild-1} & No \\
    \hline
    \end{mpxtabular}
    \end{center}
}{
}

An empty \t{EAPI} value is equal to \t{0}. Ebuilds must not assume that they will get a particular
one of these two values if they are expecting one of these two values.

The package manager must either pre-set the \t{EAPI} variable to \t{0} or ensure that it is unset
before sourcing the ebuild for metadata generation. When using the ebuild for other purposes, the
package manager must either pre-set \t{EAPI} to the value specified by the ebuild's metadata or
ensure that it is unset.

\IFKDEBUILDELSE
{
    When sourcing an ebuild with file extension \t{kdebuild-1}, the package manager must pre-set the
    \t{EAPI} variable to \t{kdebuild-1}; leaving it empty is not allowed. Ebuilds with this
    extension must not modify the \t{EAPI} variable.
}{
}

If any of these variables are set to invalid values, the package manager's behaviour is undefined;
ideally, an error in one ebuild should not prevent operations upon other ebuilds or packages.

\section{\t{RDEPEND} value}
\label{rdepend-depend}

If \t{RDEPEND} is unset (but not if it is set to an empty string) in an ebuild, the package manager
must set its value to be equal to the value of \t{DEPEND}.

When dealing with eclasses, only values set in the ebuild itself are considered for this behaviour;
any \t{DEPEND} or \t{RDEPEND} set in an eclass does not change the implicit \t{RDEPEND=\$DEPEND} for
the ebuild portion, and any \t{DEPEND} value set in an eclass does not get added to \t{RDEPEND}.

\section{Magic Ebuild-defined Variables}

The following variables must be defined by \t{inherit}, and may be considered to be part
of the ebuild's metadata:

\begin{description}
\item[INHERITED] List of inherited eclass names. This is handled magically by \t{inherit} and
    must not be modified manually.
\item[ECLASS] The current eclass, or unset if there is no current eclass. Again, this is handled
    magically by \t{inherit}.
\end{description}

\note Thus, by extension of section~\ref{metadata-invariance}, \t{inherit} may not be used
    conditionally, except upon constant conditions.

% vim: set filetype=tex fileencoding=utf8 et tw=100 spell spelllang=en :

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "pms"
%%% End:
