Compiling a single tool instead of buildworld

Hello

Is there any official way to build a single tool from FreeBSD source? Due to development I perform on pf(), I need to rebuild pfctl() quite often. Just performing make inside src/sbin/pfctl ends up with missing header files and I assume it is done with the toolchain from the operating system I perform development on, instead of the one from the system being built. Sure, I could do make -DNO_CLEAN buildworld, but this still takes too long.
 
There are two ways to do this. I tend to do make toolchain in the associated source tree to build the toolchain, then run make buildenv. This starts a shell whose $PATH and other variables are set to match the buildworld environment. You can then change to the src/sbin/pfctl directory and use make directly.

Another option is to use the SUBDIR_OVERRIDE variable with make buildworld. This will do the toolchain build plus build your tool in one step. However, it is quite a bit slower if you want to do incremental builds (e.g. fixing warnings, etc.).

All of these work fine with doing cross builds so long as you are consistent in passing the right TARGET value to the toolchain, buildenv, or buildworld targets.
 
For simple changes, on the current architecture when the system tools are adequate and the system version is close to the source version, you can just cd to src/sbin/pfctl and type make. On -CURRENT, there's a temporary bug where you need to add -m .../share/mk to your make invocation. jhb@'s method is much more robust since it doesn't have all these caveats.
 
Back
Top