\label{pkg-mgr-commands}

The following commands will always be available in the ebuild environment, provided by the package
manager. Except where otherwise noted, they may be internal (shell functions or aliases) or external
commands available in \t{PATH}; where this is not specified, ebuilds may not rely upon either
behaviour.

\IFKDEBUILDELSE
{
    \subsubsection{Banned commands}
    \label{banned-commands}

    Some commands are banned in some EAPIs. If a banned command is called, the package manager must
    abort the build process indicating an error.

    \begin{centertable}{Banned commands} \label{banned-commands-table}
    \begin{tabular}{ l l l l }
        \toprule
        \multicolumn{1}{c}{\textbf{EAPI}} &
        \multicolumn{3}{c}{\textbf{Command banned?}} \\
        \multicolumn{1}{c}{} &
        \multicolumn{1}{c}{\textbf{\t{dohard}}} &
        \multicolumn{1}{c}{\textbf{\t{dohtml}}} &
        \multicolumn{1}{c}{\textbf{\t{dosed}}} \\
        \midrule
    \t{0} & No & No & No \\
    \t{1} & No & No & No \\
    \t{kdebuild-1} & Yes & Yes & Yes \\
    \bottomrule
    \end{tabular}
    \end{centertable}
}{
}

\subsubsection{Sandbox commands}
These commands affect the behaviour of the sandbox. Each command takes a single directory as
argument. Ebuilds must not run any of these commands once the current phase function has returned.
\begin{description}
\item[addread] Add a directory to the permitted read list.
\item[addwrite] Add a directory to the permitted write list.
\item[addpredict] Add a directory to the predict list. Any write to a location in this list will be
    denied, but will not trigger access violation messages or abort the build process.
\item[adddeny] Add a directory to the deny list.
\end{description}

\subsubsection{Package manager query commands}
These commands are used to extract information about the host system. Ebuilds must not run any of
these commands in parallel with any other package manager command. Ebuilds must not run any of
these commands once the current phase function has returned.
\begin{description}
\item[has\_version] Takes exactly one package dependency specification as an argument. Returns
    true if a package matching the atom is installed in \t{\$ROOT}, and false otherwise.
\item[best\_version] Takes exactly one package dependency specification as an argument. If a
    matching package is installed, prints the category, package name and version of the highest
    matching version.
\end{description}

\subsubsection{Output commands}
These commands display messages to the user. Unless otherwise stated, the entire argument list is
used as a message, as in the simple invocations of \t{echo}. Ebuilds must not run any of these
commands once the current phase function has returned. Unless otherwise noted, output may be sent to
stdout, stderr or some other appropriate facility.
\begin{description}
\item[einfo] Displays an informational message.
\item[einfon] Displays an informational message without a trailing newline.
\item[elog] Displays an informational message of slightly higher importance. The package
    manager may choose to log \t{elog} messages by default where \t{einfo} messages are not, for
    example.
\item[ewarn] Displays a warning message. Must not go to stdout.
\item[eerror] Displays an error message. Must not go to stdout.
\item[ebegin] Displays an informational message. Should be used when beginning a possibly
    lengthy process, and followed by a call to \t{eend}.
\item[eend] Indicates that the process begun with an \t{ebegin} message has completed. Takes one
    fixed argument, which is a numeric return code, and an optional message in all subsequent
    arguments.  If the first argument is 0, print a success indicator; otherwise, print the message
    followed by a failure indicator.
\end{description}

\subsubsection{Error commands}
These commands are used when an error is detected that will prevent the build process from
completing. Ebuilds must not run any of these commands once the current phase function has returned.
\begin{description}
\item[die] Displays a failure message provided in its first and only argument, and then aborts the
    build process. \t{die} is \e{not} guaranteed to work correctly if called from a subshell
    environment.
\item[assert] Checks the value of the shell's pipe status variable, and if any component is non-zero
    (indicating failure), calls \t{die} with its first argument as a failure message.
\end{description}

\subsubsection{Build commands}
These commands are used during the \t{src\_compile} and \t{src\_install} phases to run the
package's build commands. Ebuilds must not run any of these commands once the current phase function
has returned.

\begin{description}
\item[econf] Calls the program's \t{./configure} script. This is designed to work with GNU
    Autoconf-generated scripts. Any additional parameters passed to \t{econf} are passed directly
    to \t{./configure}. \t{econf} will look in the current working directory for a configure script
    unless the \t{ECONF\_SOURCE} environment variable is set, in which case it is taken to be the
    directory containing it. \t{econf} must pass the following options to the configure script:
    \begin{itemize}
    \item -{}-prefix must default to \t{/usr} unless overridden by \t{econf}'s caller.
    \item -{}-mandir must be \t{/usr/share/man}
    \item -{}-infodir must be \t{/usr/share/info}
    \item -{}-datadir must be \t{/usr/share}
    \item -{}-sysconfdir must be \t{/etc}
    \item -{}-localstatedir must be \t{/var/lib}
    \item -{}-host must be the value of the \t{CHOST} environment variable.
    \item -{}-libdir must be set according to Algorithm~\ref{alg:econf-libdir}.
    \end{itemize}

    \t{econf} must be implemented internally---that is, as a bash function and not an external
    script. Should any portion of it fail, it must abort the build using \t{die}.

\begin{algorithm}
\caption{econf --libdir logic} \label{alg:econf-libdir}
\begin{algorithmic}[1]
\STATE let prefix=/usr
\IF{the caller specified -{}-prefix=\$p}
    \STATE let prefix=\$p
\ENDIF
\STATE let libdir=
\IF{the ABI environment variable is set}
    \STATE let libvar=LIBDIR\_\$ABI
    \IF{the environment variable named by libvar is set}
        \STATE let libdir=the value of the variable named by libvar
    \ENDIF
\ENDIF
\IF{libdir is non-empty}
    \STATE pass -{}-libdir=\$prefix/\$libdir to configure
\ENDIF
\end{algorithmic}
\end{algorithm}

\item[emake] Calls the \t{\$MAKE} program, or GNU make if the \t{MAKE} variable is unset.  Any
    arguments given are passed directly to the make command, as are the user's chosen \t{MAKEOPTS}\@.
    Arguments given to \t{emake} override user configuration. See also
    section~\ref{guaranteed-system-commands}. \t{emake} must be an external program and cannot be a
    function or alias---it must be callable from e.g. \t{xargs}.
\item[einstall] A shortcut for the command given in Listing~\ref{lst:einstall}. Any arguments given
    to \t{einstall} are passed verbatim to \t{emake}, as shown.

\begin{lstlisting}[caption=einstall command,label=lst:einstall]
emake \
   prefix="${D}"/usr \
   mandir="${D}"/usr/share/man \
   infodir="${D}"/usr/share/info \
   libdir="${D}"/usr/$(get_libdir) \
   "$@" \
   install
\end{lstlisting}

\end{description}

\subsubsection{Installation commands}
These commands are used to install files into the staging area, in cases where the package's \t{make
install} target cannot be used or does not install all needed files. Except where otherwise stated,
all filenames created or modified are relative to the staging directory, given by \t{\$\{D\}}. These
commands must all be external programs and not bash functions or aliases---that is, they must be
callable from \t{xargs}. Ebuilds must not run any of these commands once the current phase function
has returned.

\begin{description}
\item[dobin] Installs the given files into \t{DESTTREE/bin}, where \t{DESTTREE} defaults to
    \t{/usr}. Gives the files mode \t{0755} and ownership \t{root:root}.

\item[doconfd] Installs the given files into /etc/conf.d/.

\item[dodir] Creates the given directories, by default with file mode \t{0755}. This can be overridden
    by setting \t{DIROPTIONS} with the \t{diropts} function.

\item[dodoc] Installs the given files into a subdirectory under \t{/usr/share/doc/\$PF/}. The
    subdirectory is set by the most recent call to \t{docinto}. If \t{docinto} has not
    yet been called, instead installs to the directory \t{/usr/share/doc/\$PF/}.

\item[doexe] Installs the given files into the directory specified by the most recent
    \t{exeinto} call. If \t{exeinto} has not yet been called, behaviour is undefined.

\IFKDEBUILDELSE
{
    \item[dohard] Takes two parameters. Creates a hardlink from the second to the first. In EAPIs
    listed in table~\ref{banned-commands-table}, this command is banned as per
    section~\ref{banned-commands}.
}{
    \item[dohard] Takes two parameters. Creates a hardlink from the second to the first.
}

\item[dohtml] Installs the given HTML files into a subdirectory under \t{/usr/share/doc/\$PF/}.
The subdirectory is \t{html} by default, but this can be changed by the \t{\$DOCDESTTREE}
variable. Files to be installed automatically are determined by extension and the default
extensions are \t{png}, \t{gif}, \t{html}, \t{htm}, \t{jpg}, \t{css}, and \t{js}. These default
extensions can be extended or reduced (see below). The options that can be passed to \t{dohtml}
are as follows:
    \begin{description}
    \item{\t{-r}} --- enables recursion into directories.
    \item{\t{-V}} --- enables verbosity.
    \item{\t{-A}} --- adds file type extensions to the default list.
    \item{\t{-a}} --- sets file type extensions to only those specified.
    \item{\t{-f}} --- list of files that are able to be installed.
    \item{\t{-x}} --- list of directories that files will not be installed from(only used in
    conjunction with \t{-r}).
    \item{\t{-p}} --- sets a document prefix for installed files.
    \end{description}

\IFKDEBUILDELSE
{
    In EAPIs listed in table~\ref{banned-commands-table}, this command is banned as
    per section ~\ref{banned-commands}.
}{
}

\item[doinfo] Installs a GNU Info file into the \t{/usr/share/info} area.

\item[doinitd] Installs an initscript into \t{/etc/init.d}.

\item[doins] Takes any number of files as arguments and installs them into \t{\$INSDESTTREE}\@. If
    the first argument is \t{-r}, then operates recursively, descending into any directories given.

\item[dolib] For each argument, installs it into the appropriate library directory as determined by
    Algorithm~\ref{ebuild-libdir}. Any symlinks are installed into the same directory as relative
    links to their original target.

\item[dolib.so] As for dolib. Installs the file with mode \t{0755}.

\item[dolib.a] As for dolib. Installs the file with mode \t{0644}.

\begin{algorithm}
\caption{Determining the library directory} \label{ebuild-libdir}
\begin{algorithmic}[1]
\IF{CONF\_LIBDIR\_OVERRIDE is set in the environment}
    \STATE return CONF\_LIBDIR\_OVERRIDE
\ENDIF
\IF{CONF\_LIBDIR is set in the environment}
    \STATE let LIBDIR\_default=CONF\_LIBDIR
\ELSE
    \STATE let LIBDIR\_default=``lib''
\ENDIF
\IF{ABI is set in the environment}
    \STATE let abi=ABI
\ELSIF{DEFAULT\_ABI is set in the environment}
    \STATE let abi=DEFAULT\_ABI
\ELSE
    \STATE let abi=``default''
\ENDIF
\STATE return the value of LIBDIR\_\$abi
\end{algorithmic}
\end{algorithm}

\item[doman] Installs a man page into the appropriate subdirectory of \t{/usr/share/man} depending
    upon its apparent section suffix.

\item[domo] Installs a \t{.mo} file into the appropriate subdirectory of \t{DESTTREE/share/locale},
    generated by taking the basename of the file, removing the \t{.*} suffix, and appending
    \t{/LC\_MESSAGES}.

\item[dosbin] As \t{dobin}, but installs to \t{DESTTREE/sbin}.

\IFKDEBUILDELSE
{
    \item[dosym] Creates a symbolic link named as for its second parameter, pointing to the first. If
        the directory containing the new link does not exist, creates it if EAPI is listed in
        table~\ref{dosym-table} as making the directory, or aborts the build process otherwise.
}{
    \item[dosym] Creates a symbolic link named as for its second parameter, pointing to the first. If
        the directory containing the new link does not exist, creates it.
}

\item[fowners] Acts as for \t{chown}, but takes paths relative to the image directory.

\item[fperms] Acts as for \t{chmod}, but takes paths relative to the image directory.

\item[newbin] As for \t{dobin}, but takes two parameters. The first is the file to install; the
    second is the new filename under which it will be installed.

\item[newconfd] As for \t{doconfd}, but takes two parameters as for \t{newbin}.

\item[newdoc] As above, for \t{dodoc}.

\item[newenvd] As above, for \t{doenvd}.

\item[newexe] As above, for \t{doexe}.

\item[newinitd] As above, for \t{doinitd}.

\item[newins] As above, for \t{doins}.

\item[newman] As above, for \t{doman}.

\item[newsbin] As above, for \t{dosbin}.

\item[keepdir] Creates a directory as for \t{dodir}, and an empty file whose name starts with
    \t{.keep} in that directory to ensure that the directory does not get removed by the
    package manager should it be empty at any point.

\end{description}

\IFKDEBUILDELSE
{
    \begin{centertable}{EAPIs where \t{dosym} makes the directory} \label{dosym-table}
    \begin{tabular}{ l l }
        \toprule
        \multicolumn{1}{c}{\textbf{EAPI}} &
        \multicolumn{1}{c}{\textbf{\t{dosym} makes the directory?}} \\
        \midrule
    \t{0} & Yes \\
    \t{1} & Yes \\
    \t{kdebuild-1} & No \\
    \bottomrule
    \end{tabular}
    \end{centertable}
}{
}

\subsubsection{Commands affecting install destinations}
The following commands are used to set the various destination trees, all relative to \t{\$\{D\}},
used by the above installation commands. They must be shell functions or aliases, due to the need to
set variables read by the above commands. Ebuilds must not run any of these commands once the
current phase function has returned.

\begin{description}

\item[into] Sets the value of \t{DESTTREE} for future invocations of the above utilities.  Creates
the directory under \t{\$\{D\}}, using \t{install -d} with no additional options, if it does not
already exist.

\item[insinto] Sets the value of \t{INSDESTTREE} for future invocations of the above utilities. May
    create the directory, as specified for \t{into}.

\item[exeinto] Sets the install path for \t{doexe} and \t{newexe}. May create the directory, as specified
    for \t{into}.

\item[docinto] Sets the install subdirectory for \t{dodoc} et al. May create the directory, as specified
    for \t{into}.

\item[insopts] Sets the options passed by \t{doins} et al. to the \t{install} command.

\item[diropts] Sets the options passed by \t{dodir} et al. to the \t{install} command.

\item[exeopts] Sets the options passed by \t{doexe} et al. to the \t{install} command.

\item[libopts] Sets the options passed by \t{dolib} et al. to the \t{install} command.

\end{description}

\subsubsection{List Functions}
These functions work on variables containing whitespace-delimited lists (e.g. \t{USE}). Ebuilds must
not run any of these commands once the current phase function has returned. Ebuilds must not call
any function that operates upon \t{USE} to query a value that is not either listed in \t{IUSE}, a
\t{USE\_EXPAND} value or an \t{ARCH} value; package manager behaviour is undefined if such a call
is made.

\begin{description}
\item[use] Returns shell true (0) if the first argument (a \t{USE} flag name) is enabled, false
    otherwise.  If the flag name is prefixed with \t{!}, returns true if the flag is disabled, and
    false if it is enabled.
\item[usev] The same as \t{use}, but also prints the flag name if it is enabled.
\item[useq] Deprecated synonym for \t{use}.
\\
\item[has] Returns shell true (0) if the first argument (a word) is found in the list of subsequent
    arguments, false otherwise.
\item[hasv] The same as \t{has}, but also prints the first argument if found.
\item[hasq] Deprecated synonym for \t{has}.
\\
\item[use\_with] Has one-, two-, and three-argument forms. The first argument is a USE flag name,
    the second a \t{configure} option name (\t{\$opt}), defaulting to the same as the first argument
    if not provided, and the third is a string value (\t{\$value}), defaulting to nothing. If the
    USE flag is set, outputs \t{--with-\$opt=\$value} if the third argument was provided, and
    \t{--with-\$opt} otherwise. If the flag is not set, then it outputs \t{--without-\$opt}.

\item[use\_enable] Works the same as \t{use\_with()}, but outputs \t{--enable-} or \t{--disable-}
instead of \t{--with-} or \t{--without-}.
\end{description}

\subsubsection{Misc Commands}
The following commands are always available in the ebuild environment, but don't really fit in any
of the above categories. Ebuilds must not run any of these commands once the current phase function
has returned.

\begin{description}
\IFKDEBUILDELSE
{
    \item[dosed] Takes any number of arguments, which can be files or \t{sed} expressions. For each
        argument, if it names, relative to \t{D} a file which exists, then \t{sed} is run with the
        current expression on that file. Otherwise, the current expression is set to the text of the
        argument. The initial value of the expression is \t{s:\$\{D\}::g}. In EAPIs listed in
        table~\ref{banned-commands-table}, this command is banned as per
        section~\ref{banned-commands}.
}{
    \item[dosed] Takes any number of arguments, which can be files or \t{sed} expressions. For each
        argument, if it names, relative to \t{D} a file which exists, then \t{sed} is run with the
        current expression on that file. Otherwise, the current expression is set to the text of the
        argument. The initial value of the expression is \t{s:\$\{D\}::g}.
}

\item[unpack] Unpacks one or more source archives, in order, into the current directory. After
    unpacking, must ensure that all filesystem objects inside the current working directory (but not
    the current working directory itself) have permissions \t{a+r,u+w,go-w} and that all directories
    under the current working directory additionally have permissions \t{a+x}.

    All arguments to \t{unpack} must be either a filename without path, in which case \t{unpack}
    looks in \t{DISTDIR} for the file, or start with the string \t{./}, in which case \t{unpack}
    uses the argument as a path relative to the working directory.

    Must be able to unpack the following file formats, if the relevant binaries are available:
    \begin{itemize}
    \item tar files (\t{*.tar}). Ebuilds must ensure that GNU tar installed.
    \item gzip-compressed tar files (\t{*.tar.gz, *.tgz, *.tar.Z, *.tbz}). Ebuilds must ensure that
    GNU gzip and GNU tar are installed.
    \item bzip2-compressed tar files (\t{*.tar.bz2, *.tbz2, *.tar.bz}). Ebuilds must ensure that
    bzip2 and GNU tar are installed.
    \item zip files (\t{*.zip, *.ZIP, *.jar}). Ebuilds must ensure that Info-ZIP Unzip is installed.
    \item gzip files (\t{*.gz, *.Z, *.z}). Ebuilds must ensure that GNU gzip is installed.
    \item bzip2 files (\t{*.bz, *.bz2}). Ebuilds must ensure that bzip2 is installed.
    \item 7zip files (\t{*.7z, *.7Z}). Ebuilds must ensure that P7ZIP is installed.
    \item rar files (\t{*.rar, *.RAR}). Ebuilds must ensure that RARLAB's unrar is installed.
    \item LHA archives (\t{*.LHA, *.LHa, *.lha, *.lhz}). Ebuilds must ensure that the lha program is
    installed.
    \item ar archives (\t{*.a, *.deb}). Ebuilds must ensure that GNU binutils is installed.
    \item lzma archives (\t{*.lzma}). Ebuilds must ensure that LZMA Utils is installed.
    \end{itemize}
    It is up to the ebuild to ensure that the relevant external utilities are available, whether by
    being in the system set or via dependencies.
\end{description}

\subsubsection{Debug Commands}
The following commands are available for debugging. Normally all of these commands should be no ops;
a package manager may provide a special debug mode where these commands instead do something.
Ebuilds must not run any of these commands once the current phase function has returned.

\begin{description}
\item[debug-print] If in a special debug mode, the arguments should be outputted or recorded using
    some kind of debug logging.
\item[debug-print-function] Calls \t{debug-print} with \t{\$1: entering function} as the first
    argument and the remaining arguments as additional arguments.
\item[debug-print-section] Calls \t{debug-print} with \t{now in section \$*}.
\end{description}

\subsubsection{Reserved Commands and Variables}

Except where documented otherwise, all functions and variables that contain any of the following
strings (ignoring case) are reserved for package manager use and may not be used or relied upon by
ebuilds:

\begin{compactitem}
\item \t{abort}
\item \t{dyn}
\item \t{ebuild}
\item \t{hook}
\item \t{paludis}
\item \t{portage}
\item \t{prep}
\end{compactitem}

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

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