CRUX : Home

Home :: Documentation :: Download :: Development :: Community :: Wiki :: Ports :: Bugs :: Links :: About

Back to wiki start page

Categories: Ports

How to patch packages


Danny Rawlins


How and when to use patch.


You know it's time to ditch sed and use patch when you have say 4 or more lines of sed or it is very hard to read. I would still use sed in some cases such as using the system CFLAGS/CXXFLAGS in a static file on those ports that lack a configure script. Note that some packages can use example: ./ CFLAGS="$CFLAGS".

Here is how I use patch and diff.

Once you have your sources extracted cd into the directory and clone it.

$ cp -r foo-1.2.3 foo-1.2.3.orig

Edit the files in foo-1.2.3 only keeping foo-1.2.3.orig as is then make sure you remove any backup files if you got any *~. Now to make a patch type this command.

$ diff -pruN foo-1.2.3.orig foo-1.2.3

That will print it to the console, once you are happy pipe it to a file name.

$ diff -pruN foo-1.2.3.orig foo-1.2.3 > foo-1.2.3-some-change.patch

To place it in a upper level directory do this. Keep adding ../ as needed or use a full path.

$ diff -pruN foo-1.2.3.orig foo-1.2.3 > ../foo-1.2.3-some-change.patch

Now in your Pkgfile you can do this.

patch -p 1 -i $SRC/foo-$version-some-change.patch

Be sure to add foo-$version-some-change.patch to the source array.

After all that you can remove or reverse the patch you just done on foo-1.2.3 and repeat as needed making additional patches. It is best to separate patches for easy maintenance, by grouping similar changes in the one patch.