How to fix or modify gentoo ebuilds

by Gregor Uhlenheuer on July 22, 2015

Lately I had to fix some gentoo ebuild package - I describe a few possibilities I found how to do that.

Portage user patches

The most convenient way is to use portage’s built-in to inject custom patches just before the build process. All you have to do is to place a .patch file in the appropriate folder in /etc/portage/patches/.

A custom patch for the x11-wm/dwm package should be used like this:

Although I am using the gentoo distribution for many years now I dicovered this great way only a few months ago. But there is a catch as I found yesterday - the user patches will only be applied if the ebuild you are dealing with is prepared to do so.

The ebuild you are using has to invoke the epatch_user command inside its src_prepare function:

Custom portage bashrc

If you are out of luck and the ebuild you are dealing with does not invoke epatch_user on its own like described above there is another possibility to your rescue. In case the ebuild inherits the eutils eclass you can get your patch applied with a custom bashrc used for portage.

Place something along the following in your /etc/portage/bashrc file:

This will inject the epatch_user function call after the src_prepare process on ebuilds that inherit eutils.

Local portage overlay

If the above does not work for you or the changes you want to do involve more than just applying a patch you may want to create a custom overlay to place your own ebuilds into.

First you have to create the necessary directory structure for the to-be-created overlay (i.e. myoverlay):

Now you just have to register the overlay for portage usage - create a local.conf file inside /etc/portage/repos.conf/ directory:

Now you can go ahead and take for example an existing ebuild and do your modifications:

References

This post is tagged with gentoo, linux and portage