how to make a patch

Giorgos Keramidas keramida at
Wed Oct 17 11:14:32 PDT 2007

On 2007-10-16 15:10, "Aryeh M. Friedman" <aryeh.friedman at> wrote:
> I found and fixed a bug in one of the ports how do I make a patch file
> (I only changed one line in one file) and who do I send it to?

If you know precisely the file, you can use diff(1) to generate the
patch file.

Note that patch files for ports have to be constructed in a "special"
way, so that the "make patch" target can find them and apply them

  1. Keep a copy of the patched file around, i.e. at `/tmp/foo.c'

  2. Clean-up the "work" subdirectory of the port, and extract a clean
     version of the port's patched source:

         # cd /usr/ports/editors/foobar
         # rm -fr work
         # make patch

  3. Enter the work/foobar-1.0 build directory of the port, and save the
     original, unpatched file you want to modify at port-build-time:

         # cd work/foobar-1.0
         # cp src/foo.c src/foo.c.orig

  4. Now overwrite the build-tree copy of `foo.c' with the saved copy
     from step 1.

         # cp /tmp/foo.c src/foo.c

  5. Use the diff utility from within the `work/foobar-1.0' tree to
     generate a ports-based patch:

         # pwd
         # diff -u src/foo.c.orig src/foo.c > /tmp/patch-src-foo.c

  6. Now that you have the 'fix' as a patch in /tmp/patch-src-foo.c, you
     can remove the temporary `work' directory of the port, and install
     the patch in `files' as a normal ports-based-patch:

         # cd /usr/ports/editors/foobar
         # rm -fr work
         # cp -i /tmp/patch-src-foo.c files/

     If there's already an existing `patch-src-foo.c' file in `files',
     the last command will prompt you for overwriting the old patch.
     Don't do it.  Just pick a non-conflicting name for the second patch
     which applies on top of `src/foo.c', i.e.:

         # cp -i /tmp/patch-src-foo.c files/patch-src-foo.c-bugfixname

     where `bugfixname' is a tag which can help the port maintainers
     understand why this patchfile is needed.

After you have installed `patch-src-foo.c' in the `files' subdirectory
of the port, you should be able to run:

         # cd /usr/ports/editors/foobar
         # make patch

and your patchfile should be applied automatically.

More information about the freebsd-questions mailing list