My *nix world

Creating a patch file in Linux

In the following I will show (1) how you can compile and install the Gimp GAP package from source code in Linux and (2) creating a patch file in Linux (Gentoo) that will help you to fix an issue found in the former source tree.


Many of you have heard talking about the ubiquitous (Adobe) Photo$hop - the raster graphics editor. It is so popular that in my language (as well as in many other languages) we created even a word for a picture edited in Photo$hop: it's "photo$hopped".

Anyway, the Photo$hop was created only for the M$ Windows/MacOS world so as for the Linux world (and this blog is called My *nix world - and Linux is just a (U)nix-like system, right?) there is no Photo$hop but the free GNU Image Manipulation Program - the GIMP.

With the free GIMP one can obviously edit raster graphics. Today I was interested in doing something unusual: converting a MPEG to an Animated GIF. This task could be accomplished for instance with the aid of the FFmepg tool:

ffmpeg -i input.mpg output.gif

I was just curious if the GIMP can help with this and it looks like it can. There is an extension/plug-in called Gimp Animation Package (shortly gimp-gap) that might just do that. Depending on your OS/Linux distro you may find the gimp-gap package with easy and just install it. If you don't then just grab the GAP 2.6 source code from, compile it and install it.

The problem

Now, in Gentoo (the Linux distro I'm using and cherish for years) one may find the gimp-gap package on some external package overlays (like gentoo-zh or) and try to install it.

I tried and I've got the following error (yeah, shit happens):

texi2html -monolithic -number doc/ffmpeg-doc.texi
Option number is ambiguous (number-footnotes, number-sections)
Try `texi2html --help' for more information.
Makefile:121: recipe for target 'doc/ffmpeg-doc.html' failed
gmake[3]: *** [doc/ffmpeg-doc.html] Error 2

The solution

As a Linux enthusiast and programmer I never surrender. I dig in the source of the problem and usually fix it. So the error message simply tells us that the package builder just called the texi2html conversion script with an ambiguous/unexpected option called `number`. The script version that I have installed implements two distinct parameters: either `number-footnotes` or `number-sections` but not just simple `number`.

So we have to search the source tree to find out where this texi2html is called like that. I just `grep`-ed the source tree and I found the the <build-dir>/gimp-gap-2.6.0/extern_libs/ffmpeg/Makefile file is the source of the problem.

What I did was to find that line and replace the option from the `number` to `number-sections`. I could use the other option (ie. number-footnotes) but I think that `number-section` is what the original developer wanted. Both ways it will compile although the GAP extension will not work 100% the same (I guess). So I edited that Makefile file, compiled the source from where it stopped and everything seemed to work well. So for now we are good but at the next rebuild the original source code will not contain our patch so probably will fail again. Obviously we could just send the patch to the upstream such that other people may use it but that's a completely another story.

The solution is to create a (custom) patch file containing our change and to instruct Gentoo to use it each time it builds this package.

  1. create a folder called /usr/local/portage/{category}/{package-slug} where {category} is the directory which contains your package and package-slug is the root name of your package. In our case the full path of it will be /usr/local/portage/media-plugins/gimp-gap.
  2. in the above folder (1) create two subfolders: files and patch
  3. in the above folder (1) copy the source of the .ebuild file (ie. either from portage source /usr/local/portage/media-plugins/gimp-gap/gimp-gap-2.6.0.ebuild or from some other local overlay copy like /var/lib/layman/gentoo-zh/media-plugins/gimp-gap/gimp-gap-2.6.0.ebuild)
  4. if exists any patch file at the directory mentioned at (3) within its files subdirectory then copy them to your earlier created files folder at (2)
  5. prepare the patch:
    1. fetch, unpack, configure and compile the original .ebuild (ie. /usr/local/portage/media-plugins/gimp-gap/gimp-gap-2.6.0.ebuild)
      1. we expect that it will fail as mentioned earlier
      2. make sure we can find the Makefile at the temporary build path (ie. /var/tmp/portage/media-plugins/gimp-gap-2.6.0/work/gimp-gap-2.6.0/extern_libs/ffmpeg/Makefile)
      3. at this step we have access to the source that we have to change; please note that instead of going through all (5.1) steps you could just fine getting the Makefile file from the source code archive (the from the ffmpeg archive within)
    2. create in the patch directory two new subdirectories: a and b (a will contain the original Makefile and the b will contain the changed one)
    3. create in the a subdirectory the relative path to our Makefile (ie patch/a/gimp-gap-2.6.0/extern_libs/ffmpeg); do the same in b subdirectory
    4. copy the original Makefile file mentioned at (5.2) to both paths created earlier at (5.3)
    5. edit the patch/a/gimp-gap-2.6.0/extern_libs/ffmpeg/Makefile (somewhere around line #121) such that instead the `texi2html -monolithic -number` it should be texi2html -monolithic -number-sections`
    6. create a patch file by comparing the original and the edited Makefile; it will be saved at files/text2html_fix.patch:
      1. git diff patch/a/...../Makefile patch/b/...../Makefile > files/text2html_fix.patch (replace the dots with the path)
    7. edit the .ebuild file from the (3) such that the `src_compile` function looks like this:
src_compile() {
    epatch ${FILESDIR}/extern_lib_fix.patch
    econf --disable-libmpeg3 || die "econf failed"
    sed -i  's/^LDFLAGS = /LDFLAGS = -lm -lpthread /' gap/Makefile
# our patch
    epatch ${FILESDIR}/text2html_fix.patch # insert this line just before emake
# our patch
    emake || die "emake failed"
  1. tell the portage package manager that we changed one of its files (namely the .ebuild file):
    1. ebuild gimp-gap-2.6.0.ebuild digest manifest
  2. clean-up the temporary source unpacked earlier at (5) such that next time we start with a clean source tree:
    1. ebuild gimp-gap-2.6.0.ebuild clean
  3. let's compile again the gimp-gap package; now it should work!

This is just an example of how are we fixing the source code of some library, application or Linux kernel here in the *nix world. When comes to Micro$oft or Photo$hop or any other $$$ thing you usually just pay the dough and let other people do the work for you (and the dough too :)).

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
Creating a patch file in Linux

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Creating a patch file in Linux

Latest posts by Eugen Mihailescu (see all)

Tagged on: ,

Leave a Reply

Your email address will not be published. Required fields are marked *