src_prepare

Function src_prepare
Purpose Prepare source packages and do any necessary patching or fixes.
Sandbox Enabled
Privilege user
Called for ebuild

Default src_prepare

The default implementation applies the patches listed in the PATCHES variable, followed by any user patches:

src_prepare() {
	if [[ ${PATCHES@a} == *a* ]]; then
		[[ -n ${PATCHES[@]} ]] && eapply -- "${PATCHES[@]}"
	else
		[[ -n ${PATCHES} ]] && eapply -- ${PATCHES}
	fi
	eapply_user
}

Because of the -- separator, every item of PATCHES is treated as a path name, so options for patch cannot be passed through this variable. Call eapply explicitly if you need them, or rebase the patch to the usual patch level:

src_prepare() {
	eapply -p0 "${FILESDIR}"/${P}-foo.patch
	eapply_user
}

In EAPI 7, the -- separator is not used, and items of PATCHES that begin with a hyphen are passed to patch as options instead.

Sample src_prepare

src_prepare() {
	eapply "${FILESDIR}/${PV}/${P}-fix-bogosity.patch"
	eapply "${FILESDIR}/${PV}/${P}-pam.patch"

	eapply_user

	sed -i -e 's/"ispell"/"aspell"/' src/defaults.h || die "Sed failed!"
}

src_prepare processes

The following subsections cover different topics which often occur when writing src_prepare functions.