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.

eapply was added in EAPI 6. It differs from the previously available epatch in several ways:

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_prepare() {
	eapply "${WORKDIR}/firefox-patches"

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.

	# Fix install location
	# Respect MAKEOPTS #876543

Advanced eapply

This example shows how different patch levels can be applied:

src_prepare() {
	eapply -p2 "${WORKDIR}/${P}-suse-update.patch"
	eapply -p0 "${FILESDIR}/${PV}-no-TIOCGDEV.patch"
	eapply "${FILESDIR}/${PV}-gcc-6.patch"