# minor change to existing port



## noodlefling (Aug 8, 2014)

I'd like to make a change to one line of a port's source code.


What's the best way to trick a port into installing with changed source?  If I do a `make` I can find the line of source code I need to change in the work directory, but if I do another `make` at that point, it doesn't do anything, quite rightly because it's finished.  If I do a  `make clean` it deletes the source code that I modified, which is also logical. So, what's the trick to force a make with the changed code?
What's the actual proper way to make this change?  It's a fix other users could benefit from, but it's not by default a configurable option.  I have limited time and ability to muck with this kind of thing, but I don't object in principle to being helpful.  I'm not in a position to take on the port as its long-term maintainer.  Currently the port has no official maintainer.


----------



## kpa (Aug 8, 2014)

http://www.freebsd.org/doc/en/books/porters-handbook/slow-patch.html


----------



## wblock@ (Aug 8, 2014)

Use `make patch` to extract the distfile and apply any existing patches.
Find the file in the working directory, copy it to _filename_.orig, then modify _filename_.
`cd` back to the port directory and `make makepatch` to generate a new patch.

But do look at the existing section in the Porter's Handbook that @kpa shows.  Configurable options are more work, but also documented in that book.


----------



## noodlefling (Aug 8, 2014)

This is excellent, thanks to both of you.

Unfortunately, I seem to have broken the port.  It won't compile any more, obviously as a result of my messing around with patches.  What's the easiest way to get the port (with the Makefile and everything) back into a pristine state, so I can start over and give it another go?

Apparently `make clean` doesn't restore the pristine state once you've started messing with dangerous things.


----------



## talsamon (Aug 8, 2014)

`portsnap extract portname` -  e.g. `portsnap extract [port]sysutils/lsof[/port]`.


----------



## noodlefling (Aug 8, 2014)

Thanks again.

All this and the "fix" doesn't actually work.  At least I won't have to feel guilty about not making it a config option for everyone.


----------



## kpa (Aug 8, 2014)

Using svn/svnlite for checking out the ports tree makes handling of local changes much easier. This is how you would revert all local changes in a port directory:

`svnlite revert -R .`

The other advantage is the you can create diffs easily:


```
freebsd10 /usr/ports/net/mtr # svnlite diff
Index: Makefile
===================================================================
--- Makefile    (revision 364364)
+++ Makefile    (working copy)
@@ -13,8 +13,8 @@
 
 LICENSE=       GPLv2
 
-OPTIONS_DEFINE=        GLIB IPV6 X11
-OPTIONS_DEFAULT=X11
+OPTIONS_DEFINE=        GLIB IPV6 NEWOPTION X11 
+OPTIONS_DEFAULT=X11 NEWOPTION
 GLIB_DESC=     Build with glib library
 X11_DESC=      Build X11-enabled mtr
```


----------



## talsamon (Aug 8, 2014)

I am no sure, what you now want to do, do you want to restore the port, or want the changes to work? For the second, I think this will do it: copy the tar.gz or tar.bz from /usr/ports/distfile/packagename in another directory, unzip it and change the source. Make a tar.gz or tar.bz from the changed sources and copy it back to /usr/ports/distfile/packagename. Be sure the package name is exact. Save the distinfo file of the port. And do `make makesum` in the port.


----------



## fonz (Aug 8, 2014)

Nope, that's not it.

For starters, distfiles can be removed by tools such as Portmaster or by using commands such as `make distclean`. The changes will be lost and the distinfo will end up being  incorrect. Only do this if you are in control of the upstream source or, in rare cases, if you need to replace the upstream source with your own. And in the latter case, make sure to keep a copy somewhere other than /usr/ports/distfiles.

If you need to make any changes _after_ the upstream distfile has been fetched from an external source, use the patching  method as described by @kpa and @wblock.

One other top tip: if you're about to mess around with a port, first make a copy of its directory by (for example) doing the following before changing anything:

```
# pwd
/usr/ports/category/portname
# cd ..
# cp -Rp portname portname.orig
# cd -
```
That also makes it easier to create patches or to start over again from the original.


----------



## wblock@ (Aug 8, 2014)

Use Subversion to check out ports.  It's not necessary to check out the whole tree, an individual port directory can be checked out alone.  Also, do not combine Subversion and portsnap(8).

Do not use makesum.  The distfile will not be changed by the patch, and messing with the checksums has security implications.


----------

