How do I write a Makefile rule to apply patches using Quilt?

2.2k Views Asked by At

I'm one of the developers of Inkscape. We incorporate a few modified chunks of various free libraries, in our code-base and we'd really like to handle our patches to the software in a more maintainable way.

I've used the Quilt patch tool to apply patches to upstream code in Debian packages, and we have considered using it in the build for Inkscape

i.e.,

  1. Patch all relevant upstream files using Quilt
  2. Compile source

This would allow us to maintain a pristine copy of the upstream library and a separate patch set, which we can then forward upstream.

My problem is that aside from the Debian documentation, I haven't found any examples of how to neatly include Quilt in a Makefile. Can anyone point me to a project that does this?

We currently use Automake, so if there is an elegant way of running a "patch" rule before the main build, that would be great.

1

There are 1 best solutions below

4
Edward On

I can't point you to a project which does that, but I've done that for myself before by creating a new patch (which would be the last one) that creates a file named patched.txt in some convenient spot. The Makefile for a simple project looks like this:

CXX = clang
LDFLAGS += -lstdc++
CXXFLAGS += -Wall -pedantic --std=c++11

all: patched.txt myprog

myprog: myprog.o helper.o

patched.txt: patches/series
    quilt push -a

clean:
    rm *.o barcode 
    quilt pop -a

You may or may not wish to have quilt pop -a as part of the clean target. In other projects, I've created a separate revert target which does only that. I haven't incorporated that into a project which also uses Autotools, but it shouldn't be too hard.

In my case patched.txt is created manually using date >patched.txt so that it's easy to see the date of the patch set.