# Applying a patch to a port



## Birdy (Apr 4, 2018)

I applied the following patch to x11/sterm and

- copied the /st/patches/*.diff files to /x11/sterm/files/

- in x11/sterm:

```
# make deinstall clean
# make patch
# make
# make install
```

- for non-transparent solarized colors:

```
# make clean
# patch -R < files/transparency.diff
# make
# make install
```

which returned:

```
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
-------------------------------
|--- st/config.def.h 2018-01-19 12:48:07...
|+++ st-transparent.config.def.h 2018-01-19 13:15:25...
-------------------------------
File to patch:
```

Is it serious doctor?


----------



## SirDice (Apr 4, 2018)

You're in the wrong directory, you're trying to apply the patch to the port itself. The patch should be applied to the files in the work/ directory.


----------



## chrbr (Apr 4, 2018)

Dear Birdy,
the best way to apply a patch is described in https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/slow-patch.html in section 4.4. In terms of config.def.h you run `make extract` to extract the port. Then you copy the unmodified config file to config.def.h.orig. Now you apply the changes to config.def.h. Then go to the root of the port which should be /usr/port/x11/sterm and run `make makepatch` which generates a patch file in files/. The next time `make patch` is involved it will apply the patch for you.

There is one pitfall. If there are already patch files in files/ they will be removed by `make makepatch` because there are no matching *.orig files. There are two countermeasures. Either backup the files to somewhere and restore them later. Or copy all files changed my the patching to *.orig to enable re-generation of the patch.

This complicated method survives a `make clean`. If this is not necessary you can also apply the patch once in the work/ directory. This directory is populated after `make extract` which is triggered by `make patch`.


----------



## Birdy (Apr 6, 2018)

Thanks for your replies.


SirDice said:


> You're in the wrong directory, ....



Oh I see... like a cosmetic surgeon making an improvement to the wrong body part.
Luckily the patient, an operating system, can endlessly be resuscitated when subject to a major surgical error.

Maybe I should have chosen the username Victor Frankenstein. 

Scalpel please...


----------



## JMOR (Jul 17, 2021)

chrbr said:


> There is one pitfall. If there are already patch files in files/ they will be removed by `make makepatch` because there are no matching *.orig files. There are two countermeasures. Either backup the files to somewhere and restore them later. Or copy all files changed my the patching to *.orig to enable re-generation of the patch.



I am sorry for necroing this thread, but I just want to add for future reference. `make makepatch` no longer removes the files on file/.

I already test it with another port x11-wm/dwm. The files in file/ are still there after `make makepatch`, and the new patch-* files are just added. Obviously, if one of these new patch files already exist, i.e. one of the source files already is being patched, THAT file is overwritten in file/.

No worries though, the original file being overwritten is saved in work/ by `make makepatch`. It will tell you exactly where it is saved. Just remember to not `make clean` before retrieving the file, if that is your intend.


----------

