How can I modify and rebuild a port?

Apologies if this more properly belongs in "Porting new software" or somewhere else.

I want to modify the code in a port and rebuild it. Is there a way to do this? I've (naively) tried modifying the code in the work directory and then doing # make deinstall# make install, but this doesn't work. Thanks for any help.

- Jon
 
If this is an existing port, and there are already existing patches do the following.

# cd $port
# cp -Rp files files.save (if directory files does not exits create it manually)
# make clean
# make extract
# make patch
# cd work/portname

If the file has already an applied patch you see $filename and $filename.orig, else # cp $file $file.orig.
Now make your changes.
# cd $port
# make makepatch

The # make makepatch command creates patch files and store them into the $port/files directory.

If you do now a # make clean patch then your patches should be applied cleanly, else you have your old files.save directory as reference to figure out the reason.
 
% man ports | less +/following

shows the steps. You can extract and patch the port, then make your changes, then either install it (if you feel lucky) or generate patches from the changes you've made and then install it.
 
Thanks - I've successfully tested building the port with some trivial changes. If I make another change after doing a # make build it seems that I have to do a # make clean before building again, because the # make build doesn't seem to know that one of the source files has been updated. Is there a way to get # make build to rebuild only what's necessary?
 
The easy way is to put your changes into a patch in the files/ directory. Then let the port infrastructure handle it for you.
 
# make makepatch doesn't recognize the makepatch target, nor is the makepatch target described in the man page for ports(7) or in /usr/ports/Mk/bsd.port.mk. I'm running 8.1-RELEASE. Do I need to update something, or is there another equivalent target?
 
You need to have a recent ports tree and need to be in the port directory, not somewhere down in work/. Actually, I haven't used makepatch, I just use diff.
 
  • Thanks
Reactions: jtl
Thanks - I was in the wrong directory. It looks like manual patches would be created with# diff -ud old_file new_fileDoes that look correct?
 
If I'm not mistaken these are (roughly) the steps a make install does:

Code:
make fetch         # Fetches the distfile
make extract       # Extracts the distfile into the work directory
make patch         # Patches the files in work with patches in the files directory
make configure     # Runs ./configure in the work directory
make install       # Installs the package
 
SirDice said:
If I'm not mistaken these are (roughly) the steps a make install does:

Code:
make fetch         # Fetches the distfile
make extract       # Extracts the distfile into the work directory
make patch         # Patches the files in work with patches in the files directory
make configure     # Runs ./configure in the work directory
make install       # Installs the package

Before the final
Code:
make install
there's also a
Code:
make build
step. Useful if you just want to verify that a port builds without errors, but don't want to actually install it.
 
jtl said:
Thanks - I've successfully tested building the port with some trivial changes. If I make another change after doing a # make build it seems that I have to do a # make clean before building again, because the # make build doesn't seem to know that one of the source files has been updated. Is there a way to get # make build to rebuild only what's necessary?

You don't have to make clean, just remove a couple of files from /usr/ports/whatever/portname/work

Code:
# rm work/.build_done.portname._usr_local work/.install_done.portname._usr_local
 
ckester said:
Before the final
Code:
make install
there's also a
Code:
make build
step. Useful if you just want to verify that a port builds without errors, but don't want to actually install it.

"build" is the default target, so just cd to the port directory and
# make

The man page link in post #4 shows the whole list of targets leading up to build, in order.
 
Once I've done a # make build, it won't build again, even though I modify the source.

@jalla Thank you - that was exactly what I needed. I can now easily tweak the code and rebuild without doing a # make clean
 
automated editor with diff to patchfile ?

Is there any editor which can be customized to automatically save a modified file in /tmp/ instead of work/, run diff and output patchfile to files/patch-*?
 
Back
Top