How to apply a patch to a port

Yasuhiro KIMURA yasu at
Mon Oct 21 20:40:45 UTC 2019

From: "Clay Daniels Jr." <clay.daniels.jr at>
Subject: How to apply a patch to a port
Date: Mon, 21 Oct 2019 15:23:51 -0500

> I have a patch to apply to a port:
> patch-linuxkpi_gplv2_src_linux__page.c
> /usr/ports/graphics/drm-current-kmod
> I've looked at the Handbook Chap 4.4-Patching. Several times...
> This is on a fresh base install of this week's snapshot.
> I have the ports and source installed in the base, but none "made".
> I go to the drm-current-kmod port directory.
> There is no files subdirectory, so I make one.
> I copy the patch to:
> /usr/ports/graphics/drm-current-kmod/files
> Then cd to main port directory, run "make makepatch" like it says in the
> Handbook,
> which creates a /work subdirectory.
> Then I run "make install" (no clean yet) which cannot seem to find my
> patch, and asks for patch:
> I tried giving it the full path but it still did not find it. I am new to
> patching (obviously).
> What am I doing wrong?

Assuming that you don't set WRKDIRPREFIX in /etc/make.conf, take
following steps.

1. cd /usr/ports/graphics/drm-current-kmod
2. make patch
3. cd work/kms-drm-2d2852e
4. patch -p 0 -s -i /path/to/patch/patch-linuxkpi_gplv2_src_linux__page.c
   (You may need to change '-p 0' to '-p 1' or '-p 2' or ...)
5. cd ../..
6. make makepatch
7. make clean

Then new patch file is created under files subdirectory.

Yasuhiro KIMURA

More information about the freebsd-questions mailing list