minor change to existing port

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

  1. 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?
  2. 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.
 
  • 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.
 
Last edited by a moderator:
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.
 
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.
 
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:

Code:
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
 
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.
 
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:
Code:
# 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.
 
Last edited by a moderator:
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.
 
Back
Top