Patching with eapply
The canonical way of applying patches in ebuilds is to use the package
manager's eapply
command, either by calling it explicitly, or by
assigning the PATCHES
variable supported by the default
src_prepare
implementation.
The eapply
command takes one or more regular file or directory paths as
its arguments. Optionally, these can be preceded by GNU patch
options.
--
delimiter indicates the end of options. This is useful if a
filename begins with a hyphen.
-
If an argument is a regular file, it will be applied in the working
directory by calling GNU
patch
with patch level-p1
. Specifying an explicit-pN
option will override the default patch level. -
For a directory,
eapply
applies all patch files with names ending in.diff
or.patch
in that directory, in POSIXbetical order of their names. Any other files in the directory are ignored. Again,-pN
can be used to override the default-p1
patch level. Note thateapply
will not recurse into subdirectories.
eapply
was added in EAPI 6. It differs from the previously available
epatch
in several ways:
-
eapply
will not unpack patches for you. -
The patch level is no longer detected automatically. Patch levels other
than
-p1
must be specified manually. -
When specifying a directory, at least one file with a name ending in
.diff
or.patch
must exist or the command fails.
Basic eapply
In its simplest form, eapply
takes a single filename and applies that
patch. It will automatically die
if the apply fails. The following is
taken from sys-libs/gpm
:
eapply "${FILESDIR}"/${P}-musl.patch
In the following simplified example taken from www-client/firefox
,
a patchset is added to SRC_URI
in order to fetch and unpack it.
eapply
is then called with a directory argument. It applies all patches
found in that directory:
SRC_URI+="https://dev.gentoo.org/~larry/patchsets/${P}-patches-01.tar.xz"
src_prepare() {
eapply "${WORKDIR}/firefox-patches"
eapply_user
}
The Patches chapter gives some guidelines about where patches should be hosted and about their formatting.
The default src_prepare
function will look for a global PATCHES array to apply a list of patches
for you.
PATCHES=(
# Fix install location
"${FILESDIR}/${P}-destdir.patch"
# Respect MAKEOPTS #876543
"${FILESDIR}/${P}-parallel_build.patch"
)